@node-minify/run 7.0.0 → 8.0.0-beta.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.
@@ -0,0 +1,19 @@
1
+ import { MinifierOptions } from '@node-minify/types';
2
+
3
+ /*!
4
+ * node-minify
5
+ * Copyright(c) 2011-2022 Rodolphe Stoclin
6
+ * MIT Licensed
7
+ */
8
+
9
+ /**
10
+ * Run the command line with spawn.
11
+ *
12
+ * @param {Array} args
13
+ * @param {String} data
14
+ * @param {Object} settings
15
+ * @param {Function} callback
16
+ */
17
+ declare const runCommandLine: ({ args, data, settings, callback }: MinifierOptions) => any;
18
+
19
+ export { runCommandLine };
package/dist/index.js ADDED
@@ -0,0 +1,88 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+
25
+ // src/index.ts
26
+ var src_exports = {};
27
+ __export(src_exports, {
28
+ runCommandLine: () => runCommandLine
29
+ });
30
+ module.exports = __toCommonJS(src_exports);
31
+ var import_child_process = __toESM(require("child_process"));
32
+ var runCommandLine = ({ args, data, settings, callback }) => {
33
+ if (settings && settings.sync) {
34
+ return runSync({ settings, data, args, callback });
35
+ }
36
+ return runAsync({ data, args, callback });
37
+ };
38
+ var runAsync = ({ data, args, callback }) => {
39
+ let stdout = "";
40
+ let stderr = "";
41
+ const child = import_child_process.default.spawn("java", args, {
42
+ stdio: "pipe"
43
+ });
44
+ child.on("error", console.log.bind(console, "child"));
45
+ child.stdin.on("error", console.log.bind(console, "child.stdin"));
46
+ child.stdout.on("error", console.log.bind(console, "child.stdout"));
47
+ child.stderr.on("error", console.log.bind(console, "child.stderr"));
48
+ child.on("exit", (code) => {
49
+ if (code !== 0) {
50
+ return callback && callback(new Error(stderr));
51
+ }
52
+ return callback && callback(null, stdout);
53
+ });
54
+ child.stdout.on("data", (chunk) => {
55
+ stdout += chunk;
56
+ });
57
+ child.stderr.on("data", (chunk) => {
58
+ stderr += chunk;
59
+ });
60
+ child.stdin.end(data);
61
+ };
62
+ var runSync = ({ settings, data, args, callback }) => {
63
+ try {
64
+ const child = import_child_process.default.spawnSync("java", args, {
65
+ input: data,
66
+ stdio: "pipe",
67
+ maxBuffer: settings && settings.buffer
68
+ });
69
+ const stdout = child.stdout.toString();
70
+ const stderr = child.stderr.toString();
71
+ const code = child.status;
72
+ if (code !== 0) {
73
+ return callback && callback(new Error(stderr));
74
+ }
75
+ return callback && callback(null, stdout);
76
+ } catch (err) {
77
+ return callback && callback(err);
78
+ }
79
+ };
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ runCommandLine
83
+ });
84
+ /*!
85
+ * node-minify
86
+ * Copyright(c) 2011-2022 Rodolphe Stoclin
87
+ * MIT Licensed
88
+ */
package/dist/index.mjs ADDED
@@ -0,0 +1,58 @@
1
+ // src/index.ts
2
+ import childProcess from "child_process";
3
+ var runCommandLine = ({ args, data, settings, callback }) => {
4
+ if (settings && settings.sync) {
5
+ return runSync({ settings, data, args, callback });
6
+ }
7
+ return runAsync({ data, args, callback });
8
+ };
9
+ var runAsync = ({ data, args, callback }) => {
10
+ let stdout = "";
11
+ let stderr = "";
12
+ const child = childProcess.spawn("java", args, {
13
+ stdio: "pipe"
14
+ });
15
+ child.on("error", console.log.bind(console, "child"));
16
+ child.stdin.on("error", console.log.bind(console, "child.stdin"));
17
+ child.stdout.on("error", console.log.bind(console, "child.stdout"));
18
+ child.stderr.on("error", console.log.bind(console, "child.stderr"));
19
+ child.on("exit", (code) => {
20
+ if (code !== 0) {
21
+ return callback && callback(new Error(stderr));
22
+ }
23
+ return callback && callback(null, stdout);
24
+ });
25
+ child.stdout.on("data", (chunk) => {
26
+ stdout += chunk;
27
+ });
28
+ child.stderr.on("data", (chunk) => {
29
+ stderr += chunk;
30
+ });
31
+ child.stdin.end(data);
32
+ };
33
+ var runSync = ({ settings, data, args, callback }) => {
34
+ try {
35
+ const child = childProcess.spawnSync("java", args, {
36
+ input: data,
37
+ stdio: "pipe",
38
+ maxBuffer: settings && settings.buffer
39
+ });
40
+ const stdout = child.stdout.toString();
41
+ const stderr = child.stderr.toString();
42
+ const code = child.status;
43
+ if (code !== 0) {
44
+ return callback && callback(new Error(stderr));
45
+ }
46
+ return callback && callback(null, stdout);
47
+ } catch (err) {
48
+ return callback && callback(err);
49
+ }
50
+ };
51
+ export {
52
+ runCommandLine
53
+ };
54
+ /*!
55
+ * node-minify
56
+ * Copyright(c) 2011-2022 Rodolphe Stoclin
57
+ * MIT Licensed
58
+ */
package/package.json CHANGED
@@ -1,25 +1,33 @@
1
1
  {
2
2
  "name": "@node-minify/run",
3
- "version": "7.0.0",
3
+ "version": "8.0.0-beta.0",
4
4
  "description": "exec commands for @node-minify",
5
5
  "keywords": [
6
6
  "compressor",
7
7
  "minify",
8
- "minifier"
8
+ "minifier",
9
+ "run"
9
10
  ],
10
11
  "author": "Rodolphe Stoclin <srodolphe@gmail.com>",
11
12
  "homepage": "https://github.com/srod/node-minify/tree/master/packages/run#readme",
12
13
  "license": "MIT",
13
- "main": "lib/run.js",
14
14
  "engines": {
15
15
  "node": ">=14.0.0"
16
16
  },
17
17
  "directories": {
18
- "lib": "lib",
18
+ "lib": "dist",
19
19
  "test": "__tests__"
20
20
  },
21
+ "main": "./dist/index.js",
22
+ "module": "./dist/index.mjs",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ "require": "./dist/index.js",
26
+ "import": "./dist/index.mjs",
27
+ "types": "./dist/index.d.ts"
28
+ },
21
29
  "files": [
22
- "lib"
30
+ "dist/**/*"
23
31
  ],
24
32
  "publishConfig": {
25
33
  "access": "public"
@@ -31,5 +39,13 @@
31
39
  "bugs": {
32
40
  "url": "https://github.com/srod/node-minify/issues"
33
41
  },
34
- "gitHead": "8b5bda6f1ac9fe7180006f2a19ec3253e8fff4ec"
42
+ "scripts": {
43
+ "clean": "pnpm dlx rimraf dist",
44
+ "build": "npm run clean && tsup src/index.ts --format cjs,esm --dts --clean",
45
+ "prepublishOnly": "npm run build"
46
+ },
47
+ "devDependencies": {
48
+ "@node-minify/types": "8.0.0-beta.0"
49
+ },
50
+ "gitHead": "0507c6190577e1939997a8231b07952ba167a780"
35
51
  }
package/lib/run.js DELETED
@@ -1,131 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.runCommandLine = void 0;
7
-
8
- var _child_process = _interopRequireDefault(require("child_process"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- /*!
13
- * node-minify
14
- * Copyright(c) 2011-2022 Rodolphe Stoclin
15
- * MIT Licensed
16
- */
17
-
18
- /**
19
- * Module dependencies.
20
- */
21
-
22
- /**
23
- * Run the command line with spawn.
24
- *
25
- * @param {Array} args
26
- * @param {String} data
27
- * @param {Object} settings
28
- * @param {Function} callback
29
- */
30
- const runCommandLine = ({
31
- args,
32
- data,
33
- settings,
34
- callback
35
- }) => {
36
- if (settings.sync) {
37
- return runSync({
38
- settings,
39
- data,
40
- args,
41
- callback
42
- });
43
- }
44
-
45
- return runAsync({
46
- data,
47
- args,
48
- callback
49
- });
50
- };
51
- /**
52
- * Exec command as async.
53
- *
54
- * @param {String} data
55
- * @param {Array} args
56
- * @param {Function} callback
57
- */
58
-
59
-
60
- exports.runCommandLine = runCommandLine;
61
-
62
- const runAsync = ({
63
- data,
64
- args,
65
- callback
66
- }) => {
67
- let stdout = '';
68
- let stderr = '';
69
-
70
- const child = _child_process.default.spawn('java', args, {
71
- stdio: 'pipe'
72
- });
73
-
74
- child.on('error', console.log.bind(console, 'child'));
75
- child.stdin.on('error', console.log.bind(console, 'child.stdin'));
76
- child.stdout.on('error', console.log.bind(console, 'child.stdout'));
77
- child.stderr.on('error', console.log.bind(console, 'child.stderr'));
78
- child.on('exit', code => {
79
- if (code !== 0) {
80
- return callback(new Error(stderr));
81
- }
82
-
83
- return callback(null, stdout);
84
- });
85
- child.stdout.on('data', chunk => {
86
- stdout += chunk;
87
- });
88
- child.stderr.on('data', chunk => {
89
- stderr += chunk;
90
- });
91
- child.stdin.end(data);
92
- };
93
- /**
94
- * Exec command as sync.
95
- *
96
- * @param {Object} settings
97
- * @param {String} data
98
- * @param {Array} args
99
- * @param {Function} callback
100
- */
101
-
102
-
103
- const runSync = ({
104
- settings,
105
- data,
106
- args,
107
- callback
108
- }) => {
109
- try {
110
- const child = _child_process.default.spawnSync('java', args, {
111
- input: data,
112
- stdio: 'pipe',
113
- maxBuffer: settings.buffer
114
- });
115
-
116
- const stdout = child.stdout.toString();
117
- const stderr = child.stderr.toString();
118
- const code = child.status;
119
-
120
- if (code !== 0) {
121
- return callback(new Error(stderr));
122
- }
123
-
124
- return callback(null, stdout);
125
- } catch (err) {
126
- return callback(err);
127
- }
128
- };
129
- /**
130
- * Expose `runCommandLine()`.
131
- */