@node-minify/run
Advanced tools
| {"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"} |
| {"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"} |
+33
-7
@@ -1,11 +0,37 @@ | ||
| import { MinifierOptions } from '@node-minify/types'; | ||
| //#region src/index.d.ts | ||
| /*! | ||
| * node-minify | ||
| * Copyright(c) 2011-2024 Rodolphe Stoclin | ||
| * Copyright(c) 2011-2025 Rodolphe Stoclin | ||
| * MIT Licensed | ||
| */ | ||
| declare const runCommandLine: ({ args, data, settings, callback, }: MinifierOptions) => void; | ||
| export { runCommandLine }; | ||
| type RunCommandLineParams = { | ||
| args: string[]; | ||
| data: string; | ||
| }; | ||
| /** | ||
| * Run the command line with spawn. | ||
| * @param args - Command line arguments for the Java process | ||
| * @param data - Data to minify (piped to stdin) | ||
| * @returns Promise with minified content from stdout | ||
| */ | ||
| declare function runCommandLine({ | ||
| args, | ||
| data | ||
| }: RunCommandLineParams): Promise<string>; | ||
| type RunParams = { | ||
| data: string; | ||
| args: string[]; | ||
| }; | ||
| /** | ||
| * Execute command with Java process. | ||
| * @param data - Data to minify (piped to stdin) | ||
| * @param args - Command line arguments | ||
| * @returns Promise with minified content from stdout | ||
| */ | ||
| declare function run({ | ||
| data, | ||
| args | ||
| }: RunParams): Promise<string>; | ||
| //#endregion | ||
| export { RunCommandLineParams, run, runCommandLine }; | ||
| //# sourceMappingURL=index.d.ts.map |
+59
-61
@@ -1,63 +0,61 @@ | ||
| // src/index.ts | ||
| import childProcess from "node:child_process"; | ||
| var runCommandLine = ({ | ||
| args, | ||
| data, | ||
| settings, | ||
| callback | ||
| }) => { | ||
| if (settings?.sync) { | ||
| return runSync({ settings, data, args, callback }); | ||
| } | ||
| return runAsync({ data, args, callback }); | ||
| }; | ||
| var runAsync = ({ data, args, callback }) => { | ||
| let stdout = ""; | ||
| let stderr = ""; | ||
| const child = childProcess.spawn("java", args, { | ||
| stdio: "pipe" | ||
| }); | ||
| child.on("error", console.log.bind(console, "child")); | ||
| child.stdin.on("error", console.log.bind(console, "child.stdin")); | ||
| child.stdout.on("error", console.log.bind(console, "child.stdout")); | ||
| child.stderr.on("error", console.log.bind(console, "child.stderr")); | ||
| child.on("exit", (code) => { | ||
| if (code !== 0) { | ||
| return callback?.(new Error(stderr)); | ||
| } | ||
| return callback?.(null, stdout); | ||
| }); | ||
| child.stdout.on("data", (chunk) => { | ||
| stdout += chunk; | ||
| }); | ||
| child.stderr.on("data", (chunk) => { | ||
| stderr += chunk; | ||
| }); | ||
| child.stdin.end(data); | ||
| }; | ||
| var runSync = ({ settings, data, args, callback }) => { | ||
| try { | ||
| const child = childProcess.spawnSync("java", args, { | ||
| input: data, | ||
| stdio: "pipe", | ||
| maxBuffer: settings?.buffer | ||
| }); | ||
| const stdout = child.stdout.toString(); | ||
| const stderr = child.stderr.toString(); | ||
| const code = child.status; | ||
| if (code !== 0) { | ||
| return callback?.(new Error(stderr)); | ||
| } | ||
| return callback?.(null, stdout); | ||
| } catch (err) { | ||
| return callback?.(err); | ||
| } | ||
| }; | ||
| export { | ||
| runCommandLine | ||
| }; | ||
| //#region src/index.ts | ||
| /*! | ||
| * node-minify | ||
| * Copyright(c) 2011-2024 Rodolphe Stoclin | ||
| * MIT Licensed | ||
| */ | ||
| * node-minify | ||
| * Copyright(c) 2011-2025 Rodolphe Stoclin | ||
| * MIT Licensed | ||
| */ | ||
| /** | ||
| * Run the command line with spawn. | ||
| * @param args - Command line arguments for the Java process | ||
| * @param data - Data to minify (piped to stdin) | ||
| * @returns Promise with minified content from stdout | ||
| */ | ||
| async function runCommandLine({ args, data }) { | ||
| return run({ | ||
| data, | ||
| args | ||
| }); | ||
| } | ||
| /** | ||
| * Execute command with Java process. | ||
| * @param data - Data to minify (piped to stdin) | ||
| * @param args - Command line arguments | ||
| * @returns Promise with minified content from stdout | ||
| */ | ||
| async function run({ data, args }) { | ||
| return new Promise((resolve, reject) => { | ||
| let stdout = ""; | ||
| let stderr = ""; | ||
| const child = childProcess.spawn("java", args, { stdio: "pipe" }); | ||
| const handleError = (source) => (error) => { | ||
| console.error(`Error in ${source}:`, error); | ||
| }; | ||
| child.on("error", (error) => { | ||
| handleError("child")(error); | ||
| reject(/* @__PURE__ */ new Error(`Process error: ${error.message}`)); | ||
| }); | ||
| child.stdin?.on("error", handleError("child.stdin")); | ||
| child.stdout?.on("error", handleError("child.stdout")); | ||
| child.stderr?.on("error", handleError("child.stderr")); | ||
| child.on("exit", (code) => { | ||
| if (code !== 0) { | ||
| reject(new Error(stderr || `Process exited with code ${code}`)); | ||
| return; | ||
| } | ||
| resolve(stdout); | ||
| }); | ||
| child.stdout?.on("data", (chunk) => { | ||
| stdout += chunk; | ||
| }); | ||
| child.stderr?.on("data", (chunk) => { | ||
| stderr += chunk; | ||
| }); | ||
| child.stdin?.end(data); | ||
| }); | ||
| } | ||
| //#endregion | ||
| export { run, runCommandLine }; | ||
| //# sourceMappingURL=index.js.map |
+1
-1
| MIT License | ||
| Copyright (c) 2024 Rodolphe Stoclin | ||
| Copyright (c) 2025 Rodolphe Stoclin | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
+12
-11
| { | ||
| "name": "@node-minify/run", | ||
| "version": "10.0.0-next.0", | ||
| "version": "10.0.0", | ||
| "description": "exec commands for @node-minify", | ||
@@ -16,3 +16,3 @@ "keywords": [ | ||
| "engines": { | ||
| "node": ">=22.0.0" | ||
| "node": ">=20.0.0" | ||
| }, | ||
@@ -23,10 +23,9 @@ "directories": { | ||
| }, | ||
| "main": "./dist/index.cjs", | ||
| "types": "./dist/index.d.ts", | ||
| "main": "./dist/index.js", | ||
| "exports": { | ||
| "./package.json": "./package.json", | ||
| ".": { | ||
| "import": "./dist/index.js", | ||
| "default": "./dist/index.cjs" | ||
| } | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| }, | ||
| "sideEffects": false, | ||
| "files": [ | ||
@@ -46,4 +45,4 @@ "dist/**/*" | ||
| "scripts": { | ||
| "build": "tsup src/index.ts --format cjs,esm --dts --clean && bunx fix-tsup-cjs", | ||
| "check-exports": "attw --pack .", | ||
| "build": "tsdown src/index.ts", | ||
| "check-exports": "attw --pack . --profile esm-only", | ||
| "format:check": "biome check .", | ||
@@ -54,3 +53,5 @@ "lint": "biome lint .", | ||
| "test:ci": "vitest run --coverage", | ||
| "test:watch": "vitest" | ||
| "test:watch": "vitest", | ||
| "typecheck": "tsc --noEmit", | ||
| "dev": "tsdown src/index.ts --watch" | ||
| }, | ||
@@ -57,0 +58,0 @@ "devDependencies": { |
+52
-5
@@ -9,12 +9,59 @@ <p align="center"><img src="/static/node-minify.svg" width="348" alt="node-minify"></p> | ||
| <a href="https://npmjs.org/package/@node-minify/run"><img src="https://img.shields.io/npm/dm/@node-minify/run.svg"></a> | ||
| <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%3Ddevelop&style=flat" /></a> | ||
| <a href="https://codecov.io/gh/srod/node-minify"><img src="https://codecov.io/gh/srod/node-minify/branch/develop/graph/badge.svg"></a> | ||
| <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> | ||
| <a href="https://codecov.io/gh/srod/node-minify"><img src="https://codecov.io/gh/srod/node-minify/branch/main/graph/badge.svg"></a> | ||
| </p> | ||
| # run | ||
| # @node-minify/run | ||
| `run` is parts of [`node-minify`](https://github.com/srod/node-minify). | ||
| Command execution wrapper for Java-based compressors in [`node-minify`](https://github.com/srod/node-minify). | ||
| This package provides utilities to spawn Java processes for compressors like YUI Compressor and Google Closure Compiler. | ||
| ## Installation | ||
| ```bash | ||
| npm install @node-minify/run | ||
| ``` | ||
| ## Usage | ||
| ```ts | ||
| import { runCommandLine } from '@node-minify/run'; | ||
| const result = await runCommandLine({ | ||
| args: ['-jar', 'path/to/compiler.jar'], | ||
| data: 'var foo = 1;' | ||
| }); | ||
| console.log(result); // Minified output | ||
| ``` | ||
| ## API | ||
| ### `runCommandLine(params)` | ||
| Executes a Java command with the provided arguments and pipes data to stdin. | ||
| #### Parameters | ||
| | Name | Type | Description | | ||
| |------|------|-------------| | ||
| | `params.args` | `string[]` | Command line arguments for the Java process | | ||
| | `params.data` | `string` | Content to minify (piped to stdin) | | ||
| #### Returns | ||
| `Promise<string>` - The minified content from stdout. | ||
| #### Throws | ||
| - `Error` if the Java process exits with a non-zero code | ||
| - `Error` if there's a process spawn error | ||
| ## Requirements | ||
| - Java Runtime Environment (JRE) must be installed and available in PATH | ||
| ## License | ||
| [MIT](https://github.com/srod/node-minify/blob/develop/LICENSE) | ||
| [MIT](https://github.com/srod/node-minify/blob/main/LICENSE) |
-105
| "use strict"; | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
| // If the importer is in node compatibility mode or this is not an ESM | ||
| // file that has been converted to a CommonJS file using a Babel- | ||
| // compatible transform (i.e. "__esModule" has not been set), then set | ||
| // "default" to the CommonJS "module.exports" for node compatibility. | ||
| isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
| mod | ||
| )); | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // src/index.ts | ||
| var src_exports = {}; | ||
| __export(src_exports, { | ||
| runCommandLine: () => runCommandLine | ||
| }); | ||
| module.exports = __toCommonJS(src_exports); | ||
| var import_node_child_process = __toESM(require("child_process"), 1); | ||
| var runCommandLine = ({ | ||
| args, | ||
| data, | ||
| settings, | ||
| callback | ||
| }) => { | ||
| if (settings?.sync) { | ||
| return runSync({ settings, data, args, callback }); | ||
| } | ||
| return runAsync({ data, args, callback }); | ||
| }; | ||
| var runAsync = ({ data, args, callback }) => { | ||
| let stdout = ""; | ||
| let stderr = ""; | ||
| const child = import_node_child_process.default.spawn("java", args, { | ||
| stdio: "pipe" | ||
| }); | ||
| child.on("error", console.log.bind(console, "child")); | ||
| child.stdin.on("error", console.log.bind(console, "child.stdin")); | ||
| child.stdout.on("error", console.log.bind(console, "child.stdout")); | ||
| child.stderr.on("error", console.log.bind(console, "child.stderr")); | ||
| child.on("exit", (code) => { | ||
| if (code !== 0) { | ||
| return callback?.(new Error(stderr)); | ||
| } | ||
| return callback?.(null, stdout); | ||
| }); | ||
| child.stdout.on("data", (chunk) => { | ||
| stdout += chunk; | ||
| }); | ||
| child.stderr.on("data", (chunk) => { | ||
| stderr += chunk; | ||
| }); | ||
| child.stdin.end(data); | ||
| }; | ||
| var runSync = ({ settings, data, args, callback }) => { | ||
| try { | ||
| const child = import_node_child_process.default.spawnSync("java", args, { | ||
| input: data, | ||
| stdio: "pipe", | ||
| maxBuffer: settings?.buffer | ||
| }); | ||
| const stdout = child.stdout.toString(); | ||
| const stderr = child.stderr.toString(); | ||
| const code = child.status; | ||
| if (code !== 0) { | ||
| return callback?.(new Error(stderr)); | ||
| } | ||
| return callback?.(null, stdout); | ||
| } catch (err) { | ||
| return callback?.(err); | ||
| } | ||
| }; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| runCommandLine | ||
| }); | ||
| /*! | ||
| * node-minify | ||
| * Copyright(c) 2011-2024 Rodolphe Stoclin | ||
| * MIT Licensed | ||
| */ | ||
| // fix-cjs-exports | ||
| if (module.exports.default) { | ||
| Object.assign(module.exports.default, module.exports); | ||
| module.exports = module.exports.default; | ||
| delete module.exports.default; | ||
| } |
| import { MinifierOptions } from '@node-minify/types'; | ||
| /*! | ||
| * node-minify | ||
| * Copyright(c) 2011-2024 Rodolphe Stoclin | ||
| * MIT Licensed | ||
| */ | ||
| declare const runCommandLine: ({ args, data, settings, callback, }: MinifierOptions) => void; | ||
| export { runCommandLine }; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
10258
15.14%0
-100%67
235%1
-50%94
-45.98%