@node-minify/run 10.1.1 → 10.3.0
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/LICENSE +1 -1
- package/README.md +4 -4
- package/dist/index.d.ts +15 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +50 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
<p align="center"><img src="/static/node-minify.svg" width="348" alt="node-minify"></p>
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/srod/node-minify/main/static/node-minify.svg" width="348" alt="node-minify"></p>
|
|
2
2
|
|
|
3
3
|
<p align="center">A very light minifier Node.js module.</p>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<br>
|
|
7
|
-
<a href="https://npmjs.org/package/@node-minify/run"><img src="https://img.shields.io/npm/v/@node-minify/run.svg"></a>
|
|
8
|
-
<a href="https://npmjs.org/package/@node-minify/run"><img src="https://img.shields.io/npm/dm/@node-minify/run.svg"></a>
|
|
7
|
+
<a href="https://npmjs.org/package/@node-minify/run"><img src="https://img.shields.io/npm/v/@node-minify/run.svg" alt="npm version"></a>
|
|
8
|
+
<a href="https://npmjs.org/package/@node-minify/run"><img src="https://img.shields.io/npm/dm/@node-minify/run.svg" alt="npm downloads"></a>
|
|
9
9
|
<a href="https://github.com/srod/node-minify/actions"><img alt="Build Status" src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fsrod%2Fnode-minify%2Fbadge%3Fref%3Dmain&style=flat" /></a>
|
|
10
|
-
<a href="https://codecov.io/gh/srod/node-minify"><img src="https://codecov.io/gh/srod/node-minify/branch/main/graph/badge.svg"></a>
|
|
10
|
+
<a href="https://codecov.io/gh/srod/node-minify"><img src="https://codecov.io/gh/srod/node-minify/branch/main/graph/badge.svg" alt="code coverage"></a>
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
13
|
# @node-minify/run
|
package/dist/index.d.ts
CHANGED
|
@@ -1,36 +1,48 @@
|
|
|
1
1
|
//#region src/index.d.ts
|
|
2
2
|
/*!
|
|
3
3
|
* node-minify
|
|
4
|
-
* Copyright(c) 2011-
|
|
4
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
5
5
|
* MIT Licensed
|
|
6
6
|
*/
|
|
7
7
|
type RunCommandLineParams = {
|
|
8
8
|
args: string[];
|
|
9
9
|
data: string;
|
|
10
|
+
maxBuffer?: number;
|
|
11
|
+
timeout?: number;
|
|
10
12
|
};
|
|
11
13
|
/**
|
|
12
14
|
* Run the command line with spawn.
|
|
13
15
|
* @param args - Command line arguments for the Java process
|
|
14
16
|
* @param data - Data to minify (piped to stdin)
|
|
17
|
+
* @param maxBuffer - Optional buffer limit in bytes. Defaults to 1024 * 1024 (1MB).
|
|
18
|
+
* @param timeout - Optional timeout in milliseconds. Process will be killed if it exceeds this limit.
|
|
15
19
|
* @returns Promise with minified content from stdout
|
|
16
20
|
*/
|
|
17
21
|
declare function runCommandLine({
|
|
18
22
|
args,
|
|
19
|
-
data
|
|
23
|
+
data,
|
|
24
|
+
maxBuffer,
|
|
25
|
+
timeout
|
|
20
26
|
}: RunCommandLineParams): Promise<string>;
|
|
21
27
|
type RunParams = {
|
|
22
28
|
data: string;
|
|
23
29
|
args: string[];
|
|
30
|
+
maxBuffer?: number;
|
|
31
|
+
timeout?: number;
|
|
24
32
|
};
|
|
25
33
|
/**
|
|
26
34
|
* Execute command with Java process.
|
|
27
35
|
* @param data - Data to minify (piped to stdin)
|
|
28
36
|
* @param args - Command line arguments
|
|
37
|
+
* @param maxBuffer - Optional buffer limit in bytes. Defaults to 1024 * 1024 (1MB).
|
|
38
|
+
* @param timeout - Optional timeout in milliseconds. Process will be killed if it exceeds this limit.
|
|
29
39
|
* @returns Promise with minified content from stdout
|
|
30
40
|
*/
|
|
31
41
|
declare function run({
|
|
32
42
|
data,
|
|
33
|
-
args
|
|
43
|
+
args,
|
|
44
|
+
maxBuffer,
|
|
45
|
+
timeout
|
|
34
46
|
}: RunParams): Promise<string>;
|
|
35
47
|
//#endregion
|
|
36
48
|
export { RunCommandLineParams, run, runCommandLine };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;AAQA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;AAQA;AAeA;;;AAGI,KAlBQ,oBAAA,GAkBR;EACA,IAAA,EAAA,MAAA,EAAA;EACD,IAAA,EAAA,MAAA;EAAuB,SAAA,CAAA,EAAA,MAAA;EAAO,OAAA,CAAA,EAAA,MAAA;AAEhC,CAAA;AAiBD;;;;;;;;iBAxBsB,cAAA;;;;;GAKnB,uBAAuB;KAIrB,SAAA;;;;;;;;;;;;;;iBAeiB,GAAA;;;;;GAKnB,YAAY"}
|
package/dist/index.js
CHANGED
|
@@ -3,36 +3,55 @@ import childProcess from "node:child_process";
|
|
|
3
3
|
//#region src/index.ts
|
|
4
4
|
/*!
|
|
5
5
|
* node-minify
|
|
6
|
-
* Copyright(c) 2011-
|
|
6
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
7
7
|
* MIT Licensed
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
10
10
|
* Run the command line with spawn.
|
|
11
11
|
* @param args - Command line arguments for the Java process
|
|
12
12
|
* @param data - Data to minify (piped to stdin)
|
|
13
|
+
* @param maxBuffer - Optional buffer limit in bytes. Defaults to 1024 * 1024 (1MB).
|
|
14
|
+
* @param timeout - Optional timeout in milliseconds. Process will be killed if it exceeds this limit.
|
|
13
15
|
* @returns Promise with minified content from stdout
|
|
14
16
|
*/
|
|
15
|
-
async function runCommandLine({ args, data }) {
|
|
17
|
+
async function runCommandLine({ args, data, maxBuffer, timeout }) {
|
|
16
18
|
return run({
|
|
17
19
|
data,
|
|
18
|
-
args
|
|
20
|
+
args,
|
|
21
|
+
maxBuffer,
|
|
22
|
+
timeout
|
|
19
23
|
});
|
|
20
24
|
}
|
|
21
25
|
/**
|
|
22
26
|
* Execute command with Java process.
|
|
23
27
|
* @param data - Data to minify (piped to stdin)
|
|
24
28
|
* @param args - Command line arguments
|
|
29
|
+
* @param maxBuffer - Optional buffer limit in bytes. Defaults to 1024 * 1024 (1MB).
|
|
30
|
+
* @param timeout - Optional timeout in milliseconds. Process will be killed if it exceeds this limit.
|
|
25
31
|
* @returns Promise with minified content from stdout
|
|
26
32
|
*/
|
|
27
|
-
async function run({ data, args }) {
|
|
33
|
+
async function run({ data, args, maxBuffer = 1024 * 1024, timeout }) {
|
|
28
34
|
return new Promise((resolve, reject) => {
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
const stdoutChunks = [];
|
|
36
|
+
const stderrChunks = [];
|
|
37
|
+
let stdoutLength = 0;
|
|
38
|
+
let stderrLength = 0;
|
|
39
|
+
let timeoutId;
|
|
40
|
+
let settled = false;
|
|
31
41
|
const child = childProcess.spawn("java", args, { stdio: "pipe" });
|
|
42
|
+
if (timeout) timeoutId = setTimeout(() => {
|
|
43
|
+
if (settled || child.killed) return;
|
|
44
|
+
settled = true;
|
|
45
|
+
child.kill();
|
|
46
|
+
reject(/* @__PURE__ */ new Error(`Process timed out after ${timeout}ms`));
|
|
47
|
+
}, timeout);
|
|
32
48
|
const handleError = (source) => (error) => {
|
|
33
49
|
console.error(`Error in ${source}:`, error);
|
|
34
50
|
};
|
|
35
51
|
child.on("error", (error) => {
|
|
52
|
+
if (settled) return;
|
|
53
|
+
settled = true;
|
|
54
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
36
55
|
handleError("child")(error);
|
|
37
56
|
reject(/* @__PURE__ */ new Error(`Process error: ${error.message}`));
|
|
38
57
|
});
|
|
@@ -40,17 +59,39 @@ async function run({ data, args }) {
|
|
|
40
59
|
child.stdout?.on("error", handleError("child.stdout"));
|
|
41
60
|
child.stderr?.on("error", handleError("child.stderr"));
|
|
42
61
|
child.on("exit", (code) => {
|
|
62
|
+
if (settled) return;
|
|
63
|
+
settled = true;
|
|
64
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
65
|
+
const stderr = Buffer.concat(stderrChunks).toString("utf8");
|
|
43
66
|
if (code !== 0) {
|
|
44
67
|
reject(new Error(stderr || `Process exited with code ${code}`));
|
|
45
68
|
return;
|
|
46
69
|
}
|
|
47
|
-
resolve(
|
|
70
|
+
resolve(Buffer.concat(stdoutChunks).toString("utf8"));
|
|
48
71
|
});
|
|
49
72
|
child.stdout?.on("data", (chunk) => {
|
|
50
|
-
|
|
73
|
+
stdoutChunks.push(chunk);
|
|
74
|
+
stdoutLength += chunk.length;
|
|
75
|
+
if (maxBuffer > 0 && stdoutLength > maxBuffer) {
|
|
76
|
+
if (settled) return;
|
|
77
|
+
settled = true;
|
|
78
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
79
|
+
child.kill();
|
|
80
|
+
reject(/* @__PURE__ */ new Error("stdout maxBuffer exceeded"));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
51
83
|
});
|
|
52
84
|
child.stderr?.on("data", (chunk) => {
|
|
53
|
-
|
|
85
|
+
stderrChunks.push(chunk);
|
|
86
|
+
stderrLength += chunk.length;
|
|
87
|
+
if (maxBuffer > 0 && stderrLength > maxBuffer) {
|
|
88
|
+
if (settled) return;
|
|
89
|
+
settled = true;
|
|
90
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
91
|
+
child.kill();
|
|
92
|
+
reject(/* @__PURE__ */ new Error("stderr maxBuffer exceeded"));
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
54
95
|
});
|
|
55
96
|
child.stdin?.end(data);
|
|
56
97
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-
|
|
1
|
+
{"version":3,"file":"index.js","names":["stdoutChunks: Buffer[]","stderrChunks: Buffer[]","timeoutId: NodeJS.Timeout | undefined"],"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport childProcess from \"node:child_process\";\n\nexport type RunCommandLineParams = {\n args: string[];\n data: string;\n maxBuffer?: number;\n timeout?: number;\n};\n\n/**\n * Run the command line with spawn.\n * @param args - Command line arguments for the Java process\n * @param data - Data to minify (piped to stdin)\n * @param maxBuffer - Optional buffer limit in bytes. Defaults to 1024 * 1024 (1MB).\n * @param timeout - Optional timeout in milliseconds. Process will be killed if it exceeds this limit.\n * @returns Promise with minified content from stdout\n */\nexport async function runCommandLine({\n args,\n data,\n maxBuffer,\n timeout,\n}: RunCommandLineParams): Promise<string> {\n return run({ data, args, maxBuffer, timeout });\n}\n\ntype RunParams = {\n data: string;\n args: string[];\n maxBuffer?: number;\n timeout?: number;\n};\n\n/**\n * Execute command with Java process.\n * @param data - Data to minify (piped to stdin)\n * @param args - Command line arguments\n * @param maxBuffer - Optional buffer limit in bytes. Defaults to 1024 * 1024 (1MB).\n * @param timeout - Optional timeout in milliseconds. Process will be killed if it exceeds this limit.\n * @returns Promise with minified content from stdout\n */\nexport async function run({\n data,\n args,\n maxBuffer = 1024 * 1024,\n timeout,\n}: RunParams): Promise<string> {\n return new Promise((resolve, reject) => {\n const stdoutChunks: Buffer[] = [];\n const stderrChunks: Buffer[] = [];\n let stdoutLength = 0;\n let stderrLength = 0;\n let timeoutId: NodeJS.Timeout | undefined;\n let settled = false;\n\n const child = childProcess.spawn(\"java\", args, {\n stdio: \"pipe\",\n });\n\n if (timeout) {\n timeoutId = setTimeout(() => {\n if (settled || child.killed) return;\n settled = true;\n child.kill();\n reject(new Error(`Process timed out after ${timeout}ms`));\n }, timeout);\n }\n\n const handleError = (source: string) => (error: Error) => {\n console.error(`Error in ${source}:`, error);\n };\n\n child.on(\"error\", (error) => {\n if (settled) return;\n settled = true;\n if (timeoutId) clearTimeout(timeoutId);\n handleError(\"child\")(error);\n reject(new Error(`Process error: ${error.message}`));\n });\n\n child.stdin?.on(\"error\", handleError(\"child.stdin\"));\n child.stdout?.on(\"error\", handleError(\"child.stdout\"));\n child.stderr?.on(\"error\", handleError(\"child.stderr\"));\n\n child.on(\"exit\", (code: number | null) => {\n if (settled) return;\n settled = true;\n if (timeoutId) clearTimeout(timeoutId);\n const stderr = Buffer.concat(stderrChunks).toString(\"utf8\");\n if (code !== 0) {\n reject(new Error(stderr || `Process exited with code ${code}`));\n return;\n }\n\n resolve(Buffer.concat(stdoutChunks).toString(\"utf8\"));\n });\n\n child.stdout?.on(\"data\", (chunk: Buffer) => {\n stdoutChunks.push(chunk);\n stdoutLength += chunk.length;\n\n if (maxBuffer > 0 && stdoutLength > maxBuffer) {\n if (settled) return;\n settled = true;\n if (timeoutId) clearTimeout(timeoutId);\n child.kill();\n reject(new Error(\"stdout maxBuffer exceeded\"));\n return;\n }\n });\n\n child.stderr?.on(\"data\", (chunk: Buffer) => {\n stderrChunks.push(chunk);\n stderrLength += chunk.length;\n\n if (maxBuffer > 0 && stderrLength > maxBuffer) {\n if (settled) return;\n settled = true;\n if (timeoutId) clearTimeout(timeoutId);\n child.kill();\n reject(new Error(\"stderr maxBuffer exceeded\"));\n return;\n }\n });\n\n child.stdin?.end(data);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuBA,eAAsB,eAAe,EACjC,MACA,MACA,WACA,WACsC;AACtC,QAAO,IAAI;EAAE;EAAM;EAAM;EAAW;EAAS,CAAC;;;;;;;;;;AAkBlD,eAAsB,IAAI,EACtB,MACA,MACA,YAAY,OAAO,MACnB,WAC2B;AAC3B,QAAO,IAAI,SAAS,SAAS,WAAW;EACpC,MAAMA,eAAyB,EAAE;EACjC,MAAMC,eAAyB,EAAE;EACjC,IAAI,eAAe;EACnB,IAAI,eAAe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,SAAS,UAAkB;AACxC,gBAAa,KAAK,MAAM;AACxB,mBAAgB,MAAM;AAEtB,OAAI,YAAY,KAAK,eAAe,WAAW;AAC3C,QAAI,QAAS;AACb,cAAU;AACV,QAAI,UAAW,cAAa,UAAU;AACtC,UAAM,MAAM;AACZ,2BAAO,IAAI,MAAM,4BAA4B,CAAC;AAC9C;;IAEN;AAEF,QAAM,OAAO,IAAI,KAAK;GACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-minify/run",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.3.0",
|
|
4
4
|
"description": "exec commands for @node-minify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compressor",
|
|
@@ -52,6 +52,6 @@
|
|
|
52
52
|
"dev": "tsdown src/index.ts --watch"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@node-minify/types": "10.
|
|
55
|
+
"@node-minify/types": "10.3.0"
|
|
56
56
|
}
|
|
57
57
|
}
|