Skip to content

Commit 52a827f

Browse files
authored
Merge pull request #2793 from srod/develop
Release: merge develop into main
2 parents b9a6565 + cc5fd76 commit 52a827f

File tree

100 files changed

+4802
-648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+4802
-648
lines changed

.changeset/allow-empty-output.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@node-minify/types": minor
3+
"@node-minify/utils": minor
4+
"@node-minify/cli": minor
5+
---
6+
7+
feat: add `allowEmptyOutput` option to skip writing empty output files
8+
9+
When minifiers produce empty output (e.g., CSS files with only comments), the new `allowEmptyOutput` option allows gracefully skipping the file write instead of throwing a validation error. Also adds `--allow-empty-output` CLI flag.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@node-minify/utils": patch
3+
"@node-minify/action": patch
4+
---
5+
6+
fix: improve gzip size stream handling in utils
7+
fix: ensure action build fails if type definitions copy fails
8+
docs: add documentation for action inputs and java-version migration

.changeset/fluffy-eagles-sing.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@node-minify/utils": minor
3+
"@node-minify/benchmark": minor
4+
"@node-minify/docs": patch
5+
---
6+
7+
feat: add `getFilesizeGzippedRaw` utility and update benchmark defaults
8+
feat(action): launch `@node-minify/action` GitHub Action
Lines changed: 73 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,94 @@
1-
# node-minify GitHub Action
1+
# node-minify GitHub Action (DEPRECATED)
22

3-
Minify JavaScript, CSS, and HTML files in your CI/CD pipeline with detailed reporting.
3+
> **This action is deprecated.** Please use the new bundled action instead:
4+
>
5+
> ```yaml
6+
> - uses: srod/node-minify@v1
7+
> ```
48
5-
## Usage
9+
The new action includes:
10+
- Bundled dependencies (faster startup)
11+
- PR comment reporting
12+
- File annotations
13+
- Benchmark comparison
14+
- Threshold enforcement
15+
- More compressor options
616
7-
### Basic Example
17+
## Migration
18+
19+
Replace:
820
921
```yaml
10-
- name: Minify JavaScript
11-
uses: srod/node-minify/.github/actions/node-minify@main
22+
- uses: srod/node-minify/.github/actions/node-minify@main
23+
with:
24+
input: "src/app.js"
25+
output: "dist/app.min.js"
26+
compressor: "terser"
27+
```
28+
29+
With:
30+
31+
```yaml
32+
- uses: srod/node-minify@v1
1233
with:
1334
input: "src/app.js"
1435
output: "dist/app.min.js"
1536
compressor: "terser"
1637
```
1738
18-
### With All Options
39+
### Removed Inputs
40+
41+
The following inputs are **not supported** in the new action and must be removed from your workflow YAML:
42+
43+
| Removed Input | Migration Guide |
44+
|---------------|-----------------|
45+
| `include-gzip` | Gzip sizes are now always included in the output. No action needed. |
46+
| `java-version` | Use `actions/setup-java@v4` before running the action (see example below). |
47+
48+
#### Java Compressors Migration
49+
50+
If you use `gcc` or `yui` compressors that require Java:
51+
52+
**Before (deprecated):**
53+
```yaml
54+
- uses: srod/node-minify/.github/actions/node-minify@main
55+
with:
56+
compressor: gcc
57+
java-version: "17"
58+
```
59+
60+
**After:**
61+
```yaml
62+
- uses: actions/setup-java@v4
63+
with:
64+
distribution: 'temurin'
65+
java-version: '17'
66+
67+
- uses: srod/node-minify@v1
68+
with:
69+
compressor: gcc
70+
```
71+
72+
See [packages/action/README.md](../../../packages/action/README.md) for full documentation.
73+
74+
---
75+
76+
## Legacy Documentation
77+
78+
The following documentation is for the deprecated composite action.
79+
80+
### Basic Example
1981
2082
```yaml
21-
- name: Minify with full options
22-
id: minify
83+
- name: Minify JavaScript
2384
uses: srod/node-minify/.github/actions/node-minify@main
2485
with:
2586
input: "src/app.js"
2687
output: "dist/app.min.js"
27-
compressor: "esbuild"
28-
type: "js"
29-
options: '{"minify": true}'
30-
report-summary: "true"
31-
include-gzip: "true"
32-
33-
- name: Show results
34-
run: |
35-
echo "Reduction: ${{ steps.minify.outputs.reduction-percent }}%"
88+
compressor: "terser"
3689
```
3790
38-
## Inputs
91+
### Inputs
3992
4093
| Input | Description | Required | Default |
4194
|-------|-------------|----------|---------|
@@ -48,30 +101,7 @@ Minify JavaScript, CSS, and HTML files in your CI/CD pipeline with detailed repo
48101
| `include-gzip` | Include gzip sizes | No | `true` |
49102
| `java-version` | Java version for gcc/yui | No | - |
50103
51-
### Available Compressors
52-
53-
**JavaScript (no Java required):**
54-
- `terser` (recommended)
55-
- `esbuild` (fastest)
56-
- `swc`
57-
- `oxc`
58-
- `uglify-js`
59-
60-
**CSS (no Java required):**
61-
- `lightningcss` (recommended)
62-
- `clean-css`
63-
- `cssnano`
64-
- `csso`
65-
- `esbuild`
66-
67-
**HTML:**
68-
- `html-minifier`
69-
70-
**Requires Java:**
71-
- `gcc` (Google Closure Compiler)
72-
- `yui` (deprecated)
73-
74-
## Outputs
104+
### Outputs
75105
76106
| Output | Description |
77107
|--------|-------------|
@@ -84,49 +114,6 @@ Minify JavaScript, CSS, and HTML files in your CI/CD pipeline with detailed repo
84114
| `gzip-size-formatted` | Gzipped size formatted |
85115
| `time-ms` | Compression time in milliseconds |
86116
87-
## Examples
88-
89-
### CSS Minification
90-
91-
```yaml
92-
- name: Minify CSS
93-
uses: srod/node-minify/.github/actions/node-minify@main
94-
with:
95-
input: "src/styles.css"
96-
output: "dist/styles.min.css"
97-
compressor: "lightningcss"
98-
type: "css"
99-
```
100-
101-
### Using Google Closure Compiler
102-
103-
```yaml
104-
- name: Setup Java
105-
uses: actions/setup-java@v4
106-
with:
107-
distribution: "temurin"
108-
java-version: "17"
109-
110-
- name: Minify with GCC
111-
uses: srod/node-minify/.github/actions/node-minify@main
112-
with:
113-
input: "src/app.js"
114-
output: "dist/app.min.js"
115-
compressor: "gcc"
116-
options: '{"compilation_level": "ADVANCED_OPTIMIZATIONS"}'
117-
```
118-
119-
### HTML Minification
120-
121-
```yaml
122-
- name: Minify HTML
123-
uses: srod/node-minify/.github/actions/node-minify@main
124-
with:
125-
input: "src/index.html"
126-
output: "dist/index.html"
127-
compressor: "html-minifier"
128-
```
129-
130117
## License
131118
132119
MIT

.github/actions/node-minify/action.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: "node-minify"
2-
description: "Minify JavaScript, CSS, and HTML files with detailed reporting"
1+
name: "node-minify (deprecated)"
2+
description: "DEPRECATED: Use srod/node-minify@v1 instead. This composite action will be removed in a future release."
33
author: "srod"
44
branding:
55
icon: "minimize-2"
6-
color: "green"
6+
color: "gray"
77

88
inputs:
99
input:
@@ -20,7 +20,7 @@ inputs:
2020
description: "Output file path"
2121
required: true
2222
type:
23-
description: "File type: js or css (required for esbuild, lightningcss, yui)"
23+
description: "File type: js or css (required for esbuild, yui)"
2424
required: false
2525
options:
2626
description: "Compressor-specific options (JSON string)"
@@ -67,15 +67,18 @@ outputs:
6767
runs:
6868
using: "composite"
6969
steps:
70-
# Setup Java for gcc/yui compressors (auto-setup with default if java-version not specified)
70+
- name: Deprecation warning
71+
shell: bash
72+
run: |
73+
echo "::warning::This action (.github/actions/node-minify) is DEPRECATED. Please migrate to 'uses: srod/node-minify@v1' for the new bundled action with more features (PR comments, annotations, benchmarking)."
74+
7175
- name: Setup Java (for gcc/yui)
7276
if: contains(fromJSON('["gcc", "google-closure-compiler", "yui"]'), inputs.compressor)
7377
uses: actions/setup-java@v4
7478
with:
7579
distribution: "temurin"
7680
java-version: ${{ inputs.java-version || '17' }}
7781

78-
# Warn about deprecated yui compressor
7982
- name: Deprecation warning (yui)
8083
if: inputs.compressor == 'yui'
8184
shell: bash
@@ -85,7 +88,7 @@ runs:
8588
- name: Setup Bun
8689
uses: oven-sh/setup-bun@v2
8790
with:
88-
bun-version: "1.3.5"
91+
bun-version: "1.3.6"
8992

9093
- name: Install dependencies
9194
shell: bash
@@ -121,7 +124,7 @@ runs:
121124
shell: bash
122125
run: |
123126
cat >> $GITHUB_STEP_SUMMARY << EOF
124-
## 📦 node-minify Results
127+
## node-minify Results
125128
126129
| Metric | Value |
127130
|--------|-------|
@@ -134,4 +137,6 @@ runs:
134137
| **Gzip Size** | ${{ steps.minify.outputs.gzip-size-formatted }} |
135138
| **Time** | ${{ steps.minify.outputs.time-ms }}ms |
136139
140+
> **Note:** This action is deprecated. Please migrate to \`uses: srod/node-minify@v1\` for enhanced features.
141+
137142
EOF

.github/actions/node-minify/minify.ts

Lines changed: 5 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,10 @@ import { appendFileSync, existsSync } from "node:fs";
22
import { stat } from "node:fs/promises";
33
import { resolve } from "node:path";
44
import { minify } from "@node-minify/core";
5-
import { getFilesizeGzippedInBytes } from "@node-minify/utils";
6-
7-
const KNOWN_COMPRESSOR_EXPORTS: Record<string, string> = {
8-
esbuild: "esbuild",
9-
"google-closure-compiler": "gcc",
10-
gcc: "gcc",
11-
oxc: "oxc",
12-
swc: "swc",
13-
terser: "terser",
14-
"uglify-js": "uglifyJs",
15-
"babel-minify": "babelMinify",
16-
"uglify-es": "uglifyEs",
17-
yui: "yui",
18-
"clean-css": "cleanCss",
19-
cssnano: "cssnano",
20-
csso: "csso",
21-
lightningcss: "lightningCss",
22-
crass: "crass",
23-
sqwish: "sqwish",
24-
"html-minifier": "htmlMinifier",
25-
jsonminify: "jsonMinify",
26-
imagemin: "imagemin",
27-
sharp: "sharp",
28-
svgo: "svgo",
29-
"no-compress": "noCompress",
30-
};
31-
32-
/**
33-
* Resolves a compressor function from the @node-minify/{name} package and returns it with a label.
34-
*
35-
* @param name - Compressor package identifier (e.g., "terser", "esbuild"); used to import @node-minify/{name}
36-
* @returns An object containing `compressor` (the resolved compressor function) and `label` (the provided name)
37-
* @throws Error if the package does not export a usable compressor function
38-
*/
39-
async function resolveCompressor(
40-
name: string
41-
): Promise<{ compressor: unknown; label: string }> {
42-
const packageName = `@node-minify/${name}`;
43-
const mod = (await import(packageName)) as Record<string, unknown>;
44-
45-
const knownExport = KNOWN_COMPRESSOR_EXPORTS[name];
46-
if (knownExport && typeof mod[knownExport] === "function") {
47-
return { compressor: mod[knownExport], label: name };
48-
}
49-
50-
if (typeof mod.default === "function") {
51-
return { compressor: mod.default, label: name };
52-
}
53-
54-
for (const value of Object.values(mod)) {
55-
if (typeof value === "function") {
56-
return { compressor: value, label: name };
57-
}
58-
}
59-
60-
throw new Error(
61-
`Package '${packageName}' doesn't export a valid compressor function.`
62-
);
63-
}
5+
import {
6+
getFilesizeGzippedInBytes,
7+
resolveCompressor,
8+
} from "@node-minify/utils";
649

6510
interface ActionResult {
6611
originalSize: number;
@@ -164,9 +109,7 @@ async function run(): Promise<void> {
164109

165110
console.log(`Minifying ${inputFile} with ${label}...`);
166111

167-
const requiresType = ["esbuild", "lightningcss", "yui"].includes(
168-
compressorName
169-
);
112+
const requiresType = ["esbuild", "yui"].includes(compressorName);
170113
if (requiresType && !fileType) {
171114
console.error(
172115
`::error::Compressor '${compressorName}' requires the 'type' input (js or css)`

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Setup Bun
3030
uses: oven-sh/setup-bun@v2
3131
with:
32-
bun-version: "1.3.5"
32+
bun-version: "1.3.6"
3333

3434
- name: Setup Node.js
3535
uses: actions/setup-node@v6

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: 📦 Setup Bun
2828
uses: oven-sh/setup-bun@v2
2929
with:
30-
bun-version: "1.3.5"
30+
bun-version: "1.3.6"
3131

3232
- name: ⚙️ Setup Node
3333
uses: actions/setup-node@v6

0 commit comments

Comments
 (0)