html-minifier-next 8.4.0 → 8.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/cli.js +45 -13
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -36,13 +36,13 @@ Use `npx html-minifier-next --help` to check all available options:
|
|
|
36
36
|
| `--input-dir <dir>`, `-I <dir>` | Specify an input directory | `--input-dir=src` |
|
|
37
37
|
| `--ignore-dir <patterns>`, `-X <patterns>` | Exclude directories—relative to input directory—from processing (comma-separated, overrides config file setting) | `--ignore-dir=libs`, `--ignore-dir=libs,vendor,node_modules` |
|
|
38
38
|
| `--output-dir <dir>`, `-O <dir>` | Specify an output directory | `--output-dir=dist` |
|
|
39
|
-
| `--workers <n>`, `-w <n>` | Number of worker threads for multi-file runs; defaults to half the available cores
|
|
39
|
+
| `--workers <n>`, `-w <n>` | Number of worker threads for multi-file runs; defaults to half the available cores (at most 6) for runs large enough to justify them | `--workers=4` |
|
|
40
40
|
| `--input <file>`, `-i <file>` | Specify input file (alternative to positional argument; pair with `--output` for file output) | `npx html-minifier-next -i input.html -o output.html` |
|
|
41
41
|
| `--output <file>`, `-o <file>` | Specify output file (reads from `--input` file argument or STDIN; outputs to STDOUT if not specified) | File to file: `npx html-minifier-next input.html -o output.html`<br>File to file (explicit): `npx html-minifier-next -i input.html -o output.html`<br>Pipe to file: `cat input.html \| npx html-minifier-next -o output.html`<br>File to STDOUT: `npx html-minifier-next input.html` |
|
|
42
42
|
| `--file-ext <extensions>`, `-f <extensions>` | Specify file extension(s) to process (comma-separated, overrides config file setting); defaults to `html,htm,shtml,shtm`; use `*` for all files | `--file-ext=html,php`, `--file-ext='*'` |
|
|
43
43
|
| `--preset <name>`, `-p <name>` | Use a preset configuration (conservative or comprehensive) | `--preset=conservative` |
|
|
44
44
|
| `--config-file <file>`, `-c <file>` | Use a configuration file (defaults to html-minifier-next.config.json in the working directory, if present) | `--config-file=path/to/config.json` |
|
|
45
|
-
| `--verbose`, `-v` | Show detailed processing information (active options, file statistics, and minifier warnings) | `npx html-minifier-next --input-dir=src --output-dir=dist --verbose --collapse-whitespace` |
|
|
45
|
+
| `--verbose`, `-v` | Show detailed processing information (active options, worker thread count, file statistics, and minifier warnings) | `npx html-minifier-next --input-dir=src --output-dir=dist --verbose --collapse-whitespace` |
|
|
46
46
|
| `--dry`, `-d` | Dry run: Process and report statistics without writing output | `npx html-minifier-next input.html --dry --collapse-whitespace` |
|
|
47
47
|
|
|
48
48
|
### Configuration file
|
package/cli.js
CHANGED
|
@@ -197,7 +197,7 @@ Object.entries(optionDefinitions).forEach(function ([key, { description, descrip
|
|
|
197
197
|
});
|
|
198
198
|
program.option('-i --input <file>', 'Specify input file (alternative to positional argument; pair with `--output` for output)');
|
|
199
199
|
program.option('-o --output <file>', 'Specify output file (reads from `--input` file argument or STDIN; outputs to STDOUT if not specified)');
|
|
200
|
-
program.option('-v --verbose', 'Show detailed processing information');
|
|
200
|
+
program.option('-v --verbose', 'Show detailed processing information (active options, worker thread count, file statistics, and minifier warnings)');
|
|
201
201
|
program.option('-d --dry', 'Dry run: Process and report statistics without writing output');
|
|
202
202
|
program.addHelpText('after', '\nBoolean options support a `--no-<flag>` form to disable them, overriding a preset or config file (e.g., `--preset=comprehensive --no-collapse-whitespace`).');
|
|
203
203
|
|
|
@@ -312,7 +312,7 @@ program.option('-z, --zero', 'Minify all HTML files in the current folder and it
|
|
|
312
312
|
program.option('-I --input-dir <dir>', 'Specify an input directory');
|
|
313
313
|
program.option('-X --ignore-dir <patterns>', 'Exclude directories—relative to input directory—from processing (comma-separated, overrides config file setting)');
|
|
314
314
|
program.option('-O --output-dir <dir>', 'Specify an output directory');
|
|
315
|
-
program.option('-w --workers <n>', 'Number of worker threads for multi-file runs; defaults to half the available cores
|
|
315
|
+
program.option('-w --workers <n>', 'Number of worker threads for multi-file runs; defaults to half the available cores (at most 6) for runs large enough to justify them', parseValidInt('workers'));
|
|
316
316
|
program.option('-f --file-ext <extensions>', 'Specify file extension(s) to process (comma-separated, overrides config file setting); defaults to `html,htm,shtml,shtm`; use `*` for all files');
|
|
317
317
|
program.option('-p --preset <name>', `Use a preset configuration (${getPresetNames().join(', ')})`);
|
|
318
318
|
program.option('-c --config-file <file>', 'Use a configuration file (defaults to html-minifier-next.config.json in the working directory, if present)');
|
|
@@ -543,19 +543,29 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
543
543
|
return { originalSize, minifiedSize, saved, sign, percentage };
|
|
544
544
|
}
|
|
545
545
|
|
|
546
|
-
//
|
|
547
|
-
//
|
|
546
|
+
// A run with many files earns back each worker’s isolate/JIT startup cost. A smaller
|
|
547
|
+
// run can do so too when it carries enough bytes to share out, which a file count
|
|
548
|
+
// alone cannot see.
|
|
548
549
|
const FILES_PER_RUN_MIN = 128;
|
|
550
|
+
const PARALLEL_BYTES_MIN = 2 * 1024 * 1024;
|
|
549
551
|
// Each worker warms up its own JIT, so the useful count tops out well short of the cores
|
|
550
552
|
const WORKERS_MAX = 6;
|
|
551
553
|
|
|
552
554
|
/**
|
|
553
555
|
* A pool for this run, or `null` where one wouldn’t pay or wouldn’t work—in which case
|
|
554
556
|
* the caller minifies in process exactly as before
|
|
555
|
-
* @param {
|
|
557
|
+
* @param {string[]} files
|
|
556
558
|
*/
|
|
557
|
-
async function createPool(
|
|
559
|
+
async function createPool(files) {
|
|
560
|
+
const fileCount = files.length;
|
|
558
561
|
const requested = programOptions.workers;
|
|
562
|
+
const isVerbose = Boolean(programOptions.verbose || programOptions.dry);
|
|
563
|
+
// Whether the run went wide is worth saying, since the default weighs the file
|
|
564
|
+
// count and the bytes there are to share out, neither of which the caller sees
|
|
565
|
+
const inProcess = () => {
|
|
566
|
+
if (isVerbose) console.error('Worker threads: none (minifying in process)');
|
|
567
|
+
return null;
|
|
568
|
+
};
|
|
559
569
|
// `availableParallelism` reports what this process may actually use, which under a
|
|
560
570
|
// CPU affinity mask—a container, commonly—is less than the machine’s core count
|
|
561
571
|
const isDefault = requested === undefined;
|
|
@@ -565,8 +575,21 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
565
575
|
|
|
566
576
|
// The file count only decides the default; asking for workers outright is the
|
|
567
577
|
// caller’s judgment to make, whatever the run looks like
|
|
568
|
-
if (size <= 1
|
|
569
|
-
return
|
|
578
|
+
if (size <= 1) {
|
|
579
|
+
return inProcess();
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
if (isDefault && fileCount < FILES_PER_RUN_MIN) {
|
|
583
|
+
// `stat()` is cheaper than starting workers and is only needed for a run that
|
|
584
|
+
// would otherwise stay in-process. A failed stat leaves normal file processing
|
|
585
|
+
// to report the read error with its usual filename and wording.
|
|
586
|
+
const sizes = await Promise.all(files.map(file => fs.promises.stat(file).then(stat => stat.size, () => 0)));
|
|
587
|
+
// No single file is split across workers, so the largest one sets a floor no
|
|
588
|
+
// pool can beat; what the rest carry is the work there is to share out
|
|
589
|
+
const parallelBytes = sizes.reduce((sum, byteSize) => sum + byteSize, 0) - Math.max(0, ...sizes);
|
|
590
|
+
if (parallelBytes < PARALLEL_BYTES_MIN) {
|
|
591
|
+
return inProcess();
|
|
592
|
+
}
|
|
570
593
|
}
|
|
571
594
|
|
|
572
595
|
// `log` is a closure over this process’s console and is rebuilt inside the worker;
|
|
@@ -575,22 +598,31 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
575
598
|
try {
|
|
576
599
|
structuredClone(options);
|
|
577
600
|
} catch {
|
|
578
|
-
return
|
|
601
|
+
return inProcess();
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// A pool this small has nothing to share out and still pays for its workers, so an
|
|
605
|
+
// explicit request for them lands in process as `--workers=1` does
|
|
606
|
+
const poolSize = Math.min(size, fileCount);
|
|
607
|
+
if (poolSize <= 1) {
|
|
608
|
+
return inProcess();
|
|
579
609
|
}
|
|
580
610
|
|
|
581
611
|
try {
|
|
582
612
|
const { createFilePool } = await import('./src/lib/file-pool.js');
|
|
583
|
-
|
|
613
|
+
const pool = createFilePool({
|
|
584
614
|
options,
|
|
585
|
-
size:
|
|
615
|
+
size: poolSize,
|
|
586
616
|
// `log` is only set when the run asks for diagnostics
|
|
587
617
|
onLog: log
|
|
588
618
|
? (/** @type {string} */ message, /** @type {boolean} */ isError, /** @type {string} */ file) =>
|
|
589
619
|
createLog(path.relative(process.cwd(), file))(isError ? new Error(message) : message)
|
|
590
620
|
: undefined
|
|
591
621
|
});
|
|
622
|
+
if (isVerbose) console.error(`Worker threads: ${poolSize}`);
|
|
623
|
+
return pool;
|
|
592
624
|
} catch {
|
|
593
|
-
return
|
|
625
|
+
return inProcess();
|
|
594
626
|
}
|
|
595
627
|
}
|
|
596
628
|
|
|
@@ -891,7 +923,7 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
891
923
|
}
|
|
892
924
|
};
|
|
893
925
|
|
|
894
|
-
const pool = await createPool(list
|
|
926
|
+
const pool = await createPool(list);
|
|
895
927
|
if (pool) {
|
|
896
928
|
try {
|
|
897
929
|
await Promise.all(list.map(async (inputFile, idx) => {
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"bugs": "https://github.com/j9t/html-minifier-next/issues",
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"commander": "^15.0.0",
|
|
10
|
-
"entities": "^8.
|
|
10
|
+
"entities": "^8.1.0",
|
|
11
11
|
"lightningcss": "^1.33.0",
|
|
12
12
|
"svgo": "^4.1.0",
|
|
13
13
|
"terser": "^5.51.2"
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@commitlint/cli": "^21.2.2",
|
|
18
18
|
"@eslint/js": "^10.0.1",
|
|
19
|
-
"@swc/core": "^1.16.
|
|
20
|
-
"@types/node": "^26.
|
|
19
|
+
"@swc/core": "^1.16.2",
|
|
20
|
+
"@types/node": "^26.5.0",
|
|
21
21
|
"eslint": "^10.10.0",
|
|
22
22
|
"globals": "^17.12.0",
|
|
23
23
|
"typescript": "^7.0.2",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
},
|
|
96
96
|
"type": "module",
|
|
97
97
|
"types": "dist/types/htmlminifier.d.ts",
|
|
98
|
-
"version": "8.4.
|
|
98
|
+
"version": "8.4.1"
|
|
99
99
|
}
|