@node-minify/run 9.0.1 → 10.0.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 +52 -5
- package/dist/index.d.ts +33 -7
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -96
- package/dist/index.js.map +1 -1
- package/package.json +19 -17
- package/dist/index.d.mts +0 -11
- package/dist/index.mjs +0 -64
- package/dist/index.mjs.map +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -6,14 +6,61 @@
|
|
|
6
6
|
<br>
|
|
7
7
|
<a href="https://npmjs.org/package/@node-minify/run"><img src="https://img.shields.io/npm/v/@node-minify/run.svg"></a>
|
|
8
8
|
<a href="https://npmjs.org/package/@node-minify/run"><img src="https://img.shields.io/npm/dm/@node-minify/run.svg"></a>
|
|
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%
|
|
10
|
-
<a href="https://codecov.io/gh/srod/node-minify"><img src="https://codecov.io/gh/srod/node-minify/branch/
|
|
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>
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
|
-
# run
|
|
13
|
+
# @node-minify/run
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Command execution wrapper for Java-based compressors in [`node-minify`](https://github.com/srod/node-minify).
|
|
16
|
+
|
|
17
|
+
This package provides utilities to spawn Java processes for compressors like YUI Compressor and Google Closure Compiler.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @node-minify/run
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { runCommandLine } from '@node-minify/run';
|
|
29
|
+
|
|
30
|
+
const result = await runCommandLine({
|
|
31
|
+
args: ['-jar', 'path/to/compiler.jar'],
|
|
32
|
+
data: 'var foo = 1;'
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
console.log(result); // Minified output
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## API
|
|
39
|
+
|
|
40
|
+
### `runCommandLine(params)`
|
|
41
|
+
|
|
42
|
+
Executes a Java command with the provided arguments and pipes data to stdin.
|
|
43
|
+
|
|
44
|
+
#### Parameters
|
|
45
|
+
|
|
46
|
+
| Name | Type | Description |
|
|
47
|
+
|------|------|-------------|
|
|
48
|
+
| `params.args` | `string[]` | Command line arguments for the Java process |
|
|
49
|
+
| `params.data` | `string` | Content to minify (piped to stdin) |
|
|
50
|
+
|
|
51
|
+
#### Returns
|
|
52
|
+
|
|
53
|
+
`Promise<string>` - The minified content from stdout.
|
|
54
|
+
|
|
55
|
+
#### Throws
|
|
56
|
+
|
|
57
|
+
- `Error` if the Java process exits with a non-zero code
|
|
58
|
+
- `Error` if there's a process spawn error
|
|
59
|
+
|
|
60
|
+
## Requirements
|
|
61
|
+
|
|
62
|
+
- Java Runtime Environment (JRE) must be installed and available in PATH
|
|
16
63
|
|
|
17
64
|
## License
|
|
18
65
|
|
|
19
|
-
[MIT](https://github.com/srod/node-minify/blob/
|
|
66
|
+
[MIT](https://github.com/srod/node-minify/blob/main/LICENSE)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/index.d.ts
|
|
3
2
|
/*!
|
|
4
3
|
* node-minify
|
|
5
|
-
* Copyright(c) 2011-
|
|
4
|
+
* Copyright(c) 2011-2025 Rodolphe Stoclin
|
|
6
5
|
* MIT Licensed
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
type RunCommandLineParams = {
|
|
8
|
+
args: string[];
|
|
9
|
+
data: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Run the command line with spawn.
|
|
13
|
+
* @param args - Command line arguments for the Java process
|
|
14
|
+
* @param data - Data to minify (piped to stdin)
|
|
15
|
+
* @returns Promise with minified content from stdout
|
|
16
|
+
*/
|
|
17
|
+
declare function runCommandLine({
|
|
18
|
+
args,
|
|
19
|
+
data
|
|
20
|
+
}: RunCommandLineParams): Promise<string>;
|
|
21
|
+
type RunParams = {
|
|
22
|
+
data: string;
|
|
23
|
+
args: string[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Execute command with Java process.
|
|
27
|
+
* @param data - Data to minify (piped to stdin)
|
|
28
|
+
* @param args - Command line arguments
|
|
29
|
+
* @returns Promise with minified content from stdout
|
|
30
|
+
*/
|
|
31
|
+
declare function run({
|
|
32
|
+
data,
|
|
33
|
+
args
|
|
34
|
+
}: RunParams): Promise<string>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { RunCommandLineParams, run, runCommandLine };
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;AAQA;AAWA;;;AAGG,KAdS,oBAAA,GAcT;EAAuB,IAAA,EAAA,MAAA,EAAA;EAAO,IAAA,EAAA,MAAA;AAEhC,CAAA;AAaD;;;;;;iBAlBsB,cAAA;;;GAGnB,uBAAuB;KAIrB,SAAA;;;;;;;;;;iBAWiB,GAAA;;;GAAoB,YAAY"}
|
package/dist/index.js
CHANGED
|
@@ -1,99 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
import childProcess from "node:child_process";
|
|
29
2
|
|
|
30
|
-
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
33
|
-
runCommandLine: () => runCommandLine
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(src_exports);
|
|
36
|
-
var import_node_child_process = __toESM(require("child_process"));
|
|
37
|
-
var runCommandLine = ({
|
|
38
|
-
args,
|
|
39
|
-
data,
|
|
40
|
-
settings,
|
|
41
|
-
callback
|
|
42
|
-
}) => {
|
|
43
|
-
if (settings?.sync) {
|
|
44
|
-
return runSync({ settings, data, args, callback });
|
|
45
|
-
}
|
|
46
|
-
return runAsync({ data, args, callback });
|
|
47
|
-
};
|
|
48
|
-
var runAsync = ({ data, args, callback }) => {
|
|
49
|
-
let stdout = "";
|
|
50
|
-
let stderr = "";
|
|
51
|
-
const child = import_node_child_process.default.spawn("java", args, {
|
|
52
|
-
stdio: "pipe"
|
|
53
|
-
});
|
|
54
|
-
child.on("error", console.log.bind(console, "child"));
|
|
55
|
-
child.stdin.on("error", console.log.bind(console, "child.stdin"));
|
|
56
|
-
child.stdout.on("error", console.log.bind(console, "child.stdout"));
|
|
57
|
-
child.stderr.on("error", console.log.bind(console, "child.stderr"));
|
|
58
|
-
child.on("exit", (code) => {
|
|
59
|
-
if (code !== 0) {
|
|
60
|
-
return callback?.(new Error(stderr));
|
|
61
|
-
}
|
|
62
|
-
return callback?.(null, stdout);
|
|
63
|
-
});
|
|
64
|
-
child.stdout.on("data", (chunk) => {
|
|
65
|
-
stdout += chunk;
|
|
66
|
-
});
|
|
67
|
-
child.stderr.on("data", (chunk) => {
|
|
68
|
-
stderr += chunk;
|
|
69
|
-
});
|
|
70
|
-
child.stdin.end(data);
|
|
71
|
-
};
|
|
72
|
-
var runSync = ({ settings, data, args, callback }) => {
|
|
73
|
-
try {
|
|
74
|
-
const child = import_node_child_process.default.spawnSync("java", args, {
|
|
75
|
-
input: data,
|
|
76
|
-
stdio: "pipe",
|
|
77
|
-
maxBuffer: settings?.buffer
|
|
78
|
-
});
|
|
79
|
-
const stdout = child.stdout.toString();
|
|
80
|
-
const stderr = child.stderr.toString();
|
|
81
|
-
const code = child.status;
|
|
82
|
-
if (code !== 0) {
|
|
83
|
-
return callback?.(new Error(stderr));
|
|
84
|
-
}
|
|
85
|
-
return callback?.(null, stdout);
|
|
86
|
-
} catch (err) {
|
|
87
|
-
return callback?.(err);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
-
0 && (module.exports = {
|
|
92
|
-
runCommandLine
|
|
93
|
-
});
|
|
3
|
+
//#region src/index.ts
|
|
94
4
|
/*!
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
5
|
+
* node-minify
|
|
6
|
+
* Copyright(c) 2011-2025 Rodolphe Stoclin
|
|
7
|
+
* MIT Licensed
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Run the command line with spawn.
|
|
11
|
+
* @param args - Command line arguments for the Java process
|
|
12
|
+
* @param data - Data to minify (piped to stdin)
|
|
13
|
+
* @returns Promise with minified content from stdout
|
|
14
|
+
*/
|
|
15
|
+
async function runCommandLine({ args, data }) {
|
|
16
|
+
return run({
|
|
17
|
+
data,
|
|
18
|
+
args
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Execute command with Java process.
|
|
23
|
+
* @param data - Data to minify (piped to stdin)
|
|
24
|
+
* @param args - Command line arguments
|
|
25
|
+
* @returns Promise with minified content from stdout
|
|
26
|
+
*/
|
|
27
|
+
async function run({ data, args }) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
let stdout = "";
|
|
30
|
+
let stderr = "";
|
|
31
|
+
const child = childProcess.spawn("java", args, { stdio: "pipe" });
|
|
32
|
+
const handleError = (source) => (error) => {
|
|
33
|
+
console.error(`Error in ${source}:`, error);
|
|
34
|
+
};
|
|
35
|
+
child.on("error", (error) => {
|
|
36
|
+
handleError("child")(error);
|
|
37
|
+
reject(/* @__PURE__ */ new Error(`Process error: ${error.message}`));
|
|
38
|
+
});
|
|
39
|
+
child.stdin?.on("error", handleError("child.stdin"));
|
|
40
|
+
child.stdout?.on("error", handleError("child.stdout"));
|
|
41
|
+
child.stderr?.on("error", handleError("child.stderr"));
|
|
42
|
+
child.on("exit", (code) => {
|
|
43
|
+
if (code !== 0) {
|
|
44
|
+
reject(new Error(stderr || `Process exited with code ${code}`));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
resolve(stdout);
|
|
48
|
+
});
|
|
49
|
+
child.stdout?.on("data", (chunk) => {
|
|
50
|
+
stdout += chunk;
|
|
51
|
+
});
|
|
52
|
+
child.stderr?.on("data", (chunk) => {
|
|
53
|
+
stderr += chunk;
|
|
54
|
+
});
|
|
55
|
+
child.stdin?.end(data);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { run, runCommandLine };
|
|
99
61
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport childProcess from \"node:child_process\";\n\nexport type RunCommandLineParams = {\n args: string[];\n data: string;\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 * @returns Promise with minified content from stdout\n */\nexport async function runCommandLine({\n args,\n data,\n}: RunCommandLineParams): Promise<string> {\n return run({ data, args });\n}\n\ntype RunParams = {\n data: string;\n args: string[];\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 * @returns Promise with minified content from stdout\n */\nexport async function run({ data, args }: RunParams): Promise<string> {\n return new Promise((resolve, reject) => {\n let stdout = \"\";\n let stderr = \"\";\n\n const child = childProcess.spawn(\"java\", args, {\n stdio: \"pipe\",\n });\n\n const handleError = (source: string) => (error: Error) => {\n console.error(`Error in ${source}:`, error);\n };\n\n child.on(\"error\", (error) => {\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 (code !== 0) {\n reject(new Error(stderr || `Process exited with code ${code}`));\n return;\n }\n\n resolve(stdout);\n });\n\n child.stdout?.on(\"data\", (chunk: Buffer) => {\n stdout += chunk;\n });\n\n child.stderr?.on(\"data\", (chunk: Buffer) => {\n stderr += chunk;\n });\n\n child.stdin?.end(data);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;AAmBA,eAAsB,eAAe,EACjC,MACA,QACsC;AACtC,QAAO,IAAI;EAAE;EAAM;EAAM,CAAC;;;;;;;;AAc9B,eAAsB,IAAI,EAAE,MAAM,QAAoC;AAClE,QAAO,IAAI,SAAS,SAAS,WAAW;EACpC,IAAI,SAAS;EACb,IAAI,SAAS;EAEb,MAAM,QAAQ,aAAa,MAAM,QAAQ,MAAM,EAC3C,OAAO,QACV,CAAC;EAEF,MAAM,eAAe,YAAoB,UAAiB;AACtD,WAAQ,MAAM,YAAY,OAAO,IAAI,MAAM;;AAG/C,QAAM,GAAG,UAAU,UAAU;AACzB,eAAY,QAAQ,CAAC,MAAM;AAC3B,0BAAO,IAAI,MAAM,kBAAkB,MAAM,UAAU,CAAC;IACtD;AAEF,QAAM,OAAO,GAAG,SAAS,YAAY,cAAc,CAAC;AACpD,QAAM,QAAQ,GAAG,SAAS,YAAY,eAAe,CAAC;AACtD,QAAM,QAAQ,GAAG,SAAS,YAAY,eAAe,CAAC;AAEtD,QAAM,GAAG,SAAS,SAAwB;AACtC,OAAI,SAAS,GAAG;AACZ,WAAO,IAAI,MAAM,UAAU,4BAA4B,OAAO,CAAC;AAC/D;;AAGJ,WAAQ,OAAO;IACjB;AAEF,QAAM,QAAQ,GAAG,SAAS,UAAkB;AACxC,aAAU;IACZ;AAEF,QAAM,QAAQ,GAAG,SAAS,UAAkB;AACxC,aAAU;IACZ;AAEF,QAAM,OAAO,IAAI,KAAK;GACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-minify/run",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "exec commands for @node-minify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compressor",
|
|
@@ -9,25 +9,23 @@
|
|
|
9
9
|
"run"
|
|
10
10
|
],
|
|
11
11
|
"author": "Rodolphe Stoclin <srodolphe@gmail.com>",
|
|
12
|
-
"homepage": "https://github.com/srod/node-minify/tree/
|
|
12
|
+
"homepage": "https://github.com/srod/node-minify/tree/main/packages/run#readme",
|
|
13
13
|
"license": "MIT",
|
|
14
|
+
"type": "module",
|
|
14
15
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
16
|
+
"node": ">=20.0.0"
|
|
16
17
|
},
|
|
17
18
|
"directories": {
|
|
18
19
|
"lib": "dist",
|
|
19
20
|
"test": "__tests__"
|
|
20
21
|
},
|
|
21
|
-
"main": "./dist/index.js",
|
|
22
|
-
"module": "./dist/index.mjs",
|
|
23
22
|
"types": "./dist/index.d.ts",
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
24
|
"exports": {
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"import": "./dist/index.mjs",
|
|
28
|
-
"require": "./dist/index.js"
|
|
29
|
-
}
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
30
27
|
},
|
|
28
|
+
"sideEffects": false,
|
|
31
29
|
"files": [
|
|
32
30
|
"dist/**/*"
|
|
33
31
|
],
|
|
@@ -41,15 +39,19 @@
|
|
|
41
39
|
"bugs": {
|
|
42
40
|
"url": "https://github.com/srod/node-minify/issues"
|
|
43
41
|
},
|
|
44
|
-
"devDependencies": {
|
|
45
|
-
"@node-minify/types": "9.0.0"
|
|
46
|
-
},
|
|
47
42
|
"scripts": {
|
|
48
|
-
"
|
|
49
|
-
"
|
|
43
|
+
"build": "tsdown src/index.ts",
|
|
44
|
+
"check-exports": "attw --pack . --profile esm-only",
|
|
45
|
+
"format:check": "biome check .",
|
|
50
46
|
"lint": "biome lint .",
|
|
47
|
+
"prepublishOnly": "bun run build",
|
|
51
48
|
"test": "vitest run",
|
|
52
49
|
"test:ci": "vitest run --coverage",
|
|
53
|
-
"test:watch": "vitest"
|
|
50
|
+
"test:watch": "vitest",
|
|
51
|
+
"typecheck": "tsc --noEmit",
|
|
52
|
+
"dev": "tsdown src/index.ts --watch"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@node-minify/types": "workspace:*"
|
|
54
56
|
}
|
|
55
|
-
}
|
|
57
|
+
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { MinifierOptions } from '@node-minify/types';
|
|
2
|
-
|
|
3
|
-
/*!
|
|
4
|
-
* node-minify
|
|
5
|
-
* Copyright(c) 2011-2024 Rodolphe Stoclin
|
|
6
|
-
* MIT Licensed
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
declare const runCommandLine: ({ args, data, settings, callback, }: MinifierOptions) => void;
|
|
10
|
-
|
|
11
|
-
export { runCommandLine };
|
package/dist/index.mjs
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import childProcess from "node:child_process";
|
|
3
|
-
var runCommandLine = ({
|
|
4
|
-
args,
|
|
5
|
-
data,
|
|
6
|
-
settings,
|
|
7
|
-
callback
|
|
8
|
-
}) => {
|
|
9
|
-
if (settings?.sync) {
|
|
10
|
-
return runSync({ settings, data, args, callback });
|
|
11
|
-
}
|
|
12
|
-
return runAsync({ data, args, callback });
|
|
13
|
-
};
|
|
14
|
-
var runAsync = ({ data, args, callback }) => {
|
|
15
|
-
let stdout = "";
|
|
16
|
-
let stderr = "";
|
|
17
|
-
const child = childProcess.spawn("java", args, {
|
|
18
|
-
stdio: "pipe"
|
|
19
|
-
});
|
|
20
|
-
child.on("error", console.log.bind(console, "child"));
|
|
21
|
-
child.stdin.on("error", console.log.bind(console, "child.stdin"));
|
|
22
|
-
child.stdout.on("error", console.log.bind(console, "child.stdout"));
|
|
23
|
-
child.stderr.on("error", console.log.bind(console, "child.stderr"));
|
|
24
|
-
child.on("exit", (code) => {
|
|
25
|
-
if (code !== 0) {
|
|
26
|
-
return callback?.(new Error(stderr));
|
|
27
|
-
}
|
|
28
|
-
return callback?.(null, stdout);
|
|
29
|
-
});
|
|
30
|
-
child.stdout.on("data", (chunk) => {
|
|
31
|
-
stdout += chunk;
|
|
32
|
-
});
|
|
33
|
-
child.stderr.on("data", (chunk) => {
|
|
34
|
-
stderr += chunk;
|
|
35
|
-
});
|
|
36
|
-
child.stdin.end(data);
|
|
37
|
-
};
|
|
38
|
-
var runSync = ({ settings, data, args, callback }) => {
|
|
39
|
-
try {
|
|
40
|
-
const child = childProcess.spawnSync("java", args, {
|
|
41
|
-
input: data,
|
|
42
|
-
stdio: "pipe",
|
|
43
|
-
maxBuffer: settings?.buffer
|
|
44
|
-
});
|
|
45
|
-
const stdout = child.stdout.toString();
|
|
46
|
-
const stderr = child.stderr.toString();
|
|
47
|
-
const code = child.status;
|
|
48
|
-
if (code !== 0) {
|
|
49
|
-
return callback?.(new Error(stderr));
|
|
50
|
-
}
|
|
51
|
-
return callback?.(null, stdout);
|
|
52
|
-
} catch (err) {
|
|
53
|
-
return callback?.(err);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
export {
|
|
57
|
-
runCommandLine
|
|
58
|
-
};
|
|
59
|
-
/*!
|
|
60
|
-
* node-minify
|
|
61
|
-
* Copyright(c) 2011-2024 Rodolphe Stoclin
|
|
62
|
-
* MIT Licensed
|
|
63
|
-
*/
|
|
64
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2024 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport childProcess from \"node:child_process\";\nimport type { MinifierOptions } from \"@node-minify/types\";\n\n/**\n * Run the command line with spawn.\n * @param args Arguments\n * @param data Data to minify\n * @param settings Settings\n * @param callback Callback\n * @returns Minified content\n */\nconst runCommandLine = ({\n args,\n data,\n settings,\n callback,\n}: MinifierOptions) => {\n if (settings?.sync) {\n return runSync({ settings, data, args, callback });\n }\n\n return runAsync({ data, args, callback });\n};\n\n/**\n * Exec command as async.\n * @param data Data to minify\n * @param args Arguments\n * @param callback Callback\n * @returns Minified content\n */\nconst runAsync = ({ data, args, callback }: MinifierOptions) => {\n let stdout = \"\";\n let stderr = \"\";\n\n const child = childProcess.spawn(\"java\", args, {\n stdio: \"pipe\",\n });\n\n child.on(\"error\", console.log.bind(console, \"child\"));\n child.stdin.on(\"error\", console.log.bind(console, \"child.stdin\"));\n child.stdout.on(\"error\", console.log.bind(console, \"child.stdout\"));\n child.stderr.on(\"error\", console.log.bind(console, \"child.stderr\"));\n\n child.on(\"exit\", (code) => {\n if (code !== 0) {\n return callback?.(new Error(stderr));\n }\n\n return callback?.(null, stdout);\n });\n\n child.stdout.on(\"data\", (chunk) => {\n stdout += chunk;\n });\n child.stderr.on(\"data\", (chunk) => {\n stderr += chunk;\n });\n\n child.stdin.end(data);\n};\n\n/**\n * Exec command as sync.\n *\n * @param settings Settings\n * @param data Data to minify\n * @param args Arguments\n * @param callback Callback\n * @returns Minified content\n */\nconst runSync = ({ settings, data, args, callback }: MinifierOptions) => {\n try {\n const child = childProcess.spawnSync(\"java\", args, {\n input: data,\n stdio: \"pipe\",\n maxBuffer: settings?.buffer,\n });\n const stdout = child.stdout.toString();\n const stderr = child.stderr.toString();\n const code = child.status;\n\n if (code !== 0) {\n return callback?.(new Error(stderr));\n }\n\n return callback?.(null, stdout);\n } catch (err: unknown) {\n return callback?.(err);\n }\n};\n\n/**\n * Expose `runCommandLine()`.\n */\nexport { runCommandLine };\n"],"mappings":";AASA,OAAO,kBAAkB;AAWzB,IAAM,iBAAiB,CAAC;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,MAAuB;AACnB,MAAI,UAAU,MAAM;AAChB,WAAO,QAAQ,EAAE,UAAU,MAAM,MAAM,SAAS,CAAC;AAAA,EACrD;AAEA,SAAO,SAAS,EAAE,MAAM,MAAM,SAAS,CAAC;AAC5C;AASA,IAAM,WAAW,CAAC,EAAE,MAAM,MAAM,SAAS,MAAuB;AAC5D,MAAI,SAAS;AACb,MAAI,SAAS;AAEb,QAAM,QAAQ,aAAa,MAAM,QAAQ,MAAM;AAAA,IAC3C,OAAO;AAAA,EACX,CAAC;AAED,QAAM,GAAG,SAAS,QAAQ,IAAI,KAAK,SAAS,OAAO,CAAC;AACpD,QAAM,MAAM,GAAG,SAAS,QAAQ,IAAI,KAAK,SAAS,aAAa,CAAC;AAChE,QAAM,OAAO,GAAG,SAAS,QAAQ,IAAI,KAAK,SAAS,cAAc,CAAC;AAClE,QAAM,OAAO,GAAG,SAAS,QAAQ,IAAI,KAAK,SAAS,cAAc,CAAC;AAElE,QAAM,GAAG,QAAQ,CAAC,SAAS;AACvB,QAAI,SAAS,GAAG;AACZ,aAAO,WAAW,IAAI,MAAM,MAAM,CAAC;AAAA,IACvC;AAEA,WAAO,WAAW,MAAM,MAAM;AAAA,EAClC,CAAC;AAED,QAAM,OAAO,GAAG,QAAQ,CAAC,UAAU;AAC/B,cAAU;AAAA,EACd,CAAC;AACD,QAAM,OAAO,GAAG,QAAQ,CAAC,UAAU;AAC/B,cAAU;AAAA,EACd,CAAC;AAED,QAAM,MAAM,IAAI,IAAI;AACxB;AAWA,IAAM,UAAU,CAAC,EAAE,UAAU,MAAM,MAAM,SAAS,MAAuB;AACrE,MAAI;AACA,UAAM,QAAQ,aAAa,UAAU,QAAQ,MAAM;AAAA,MAC/C,OAAO;AAAA,MACP,OAAO;AAAA,MACP,WAAW,UAAU;AAAA,IACzB,CAAC;AACD,UAAM,SAAS,MAAM,OAAO,SAAS;AACrC,UAAM,SAAS,MAAM,OAAO,SAAS;AACrC,UAAM,OAAO,MAAM;AAEnB,QAAI,SAAS,GAAG;AACZ,aAAO,WAAW,IAAI,MAAM,MAAM,CAAC;AAAA,IACvC;AAEA,WAAO,WAAW,MAAM,MAAM;AAAA,EAClC,SAAS,KAAc;AACnB,WAAO,WAAW,GAAG;AAAA,EACzB;AACJ;","names":[]}
|