@node-minify/google-closure-compiler 7.1.0 → 8.0.1-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.
- package/dist/index.d.ts +18 -0
- package/dist/index.js +97 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +69 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +22 -7
- package/lib/google-closure-compiler.js +0 -86
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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 Google Closure Compiler.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} settings
|
|
13
|
+
* @param {String} content
|
|
14
|
+
* @param {Function} callback
|
|
15
|
+
*/
|
|
16
|
+
declare const minifyGCC: ({ settings, content, callback, index }: MinifierOptions) => any;
|
|
17
|
+
|
|
18
|
+
export { minifyGCC as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
default: () => src_default
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(src_exports);
|
|
31
|
+
var import_google_closure_compiler_java = __toESM(require("google-closure-compiler-java"));
|
|
32
|
+
var import_utils = require("@node-minify/utils");
|
|
33
|
+
var import_run = require("@node-minify/run");
|
|
34
|
+
var allowedFlags = [
|
|
35
|
+
"angular_pass",
|
|
36
|
+
"assume_function_wrapper",
|
|
37
|
+
"checks_only",
|
|
38
|
+
"compilation_level",
|
|
39
|
+
"create_source_map",
|
|
40
|
+
"define",
|
|
41
|
+
"env",
|
|
42
|
+
"externs",
|
|
43
|
+
"export_local_property_definitions",
|
|
44
|
+
"generate_exports",
|
|
45
|
+
"language_in",
|
|
46
|
+
"language_out",
|
|
47
|
+
"output_wrapper",
|
|
48
|
+
"polymer_version",
|
|
49
|
+
"process_common_js_modules",
|
|
50
|
+
"rename_prefix_namespace",
|
|
51
|
+
"rewrite_polyfills",
|
|
52
|
+
"use_types_for_optimization",
|
|
53
|
+
"warning_level"
|
|
54
|
+
];
|
|
55
|
+
var minifyGCC = ({ settings, content, callback, index }) => {
|
|
56
|
+
const options = applyOptions({}, settings && settings.options || {});
|
|
57
|
+
return (0, import_run.runCommandLine)({
|
|
58
|
+
args: gccCommand(options),
|
|
59
|
+
data: content,
|
|
60
|
+
settings,
|
|
61
|
+
callback: (err, content2) => {
|
|
62
|
+
if (err) {
|
|
63
|
+
if (callback) {
|
|
64
|
+
return callback(err);
|
|
65
|
+
} else {
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (settings && !settings.content) {
|
|
70
|
+
import_utils.utils.writeFile({ file: settings.output, content: content2, index });
|
|
71
|
+
}
|
|
72
|
+
if (callback) {
|
|
73
|
+
return callback(null, content2);
|
|
74
|
+
}
|
|
75
|
+
return content2;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
var applyOptions = (flags, options) => {
|
|
80
|
+
if (!options || Object.keys(options).length === 0) {
|
|
81
|
+
return flags;
|
|
82
|
+
}
|
|
83
|
+
Object.keys(options).filter((option) => allowedFlags.indexOf(option) > -1).forEach((option) => flags[option] = options[option]);
|
|
84
|
+
return flags;
|
|
85
|
+
};
|
|
86
|
+
var gccCommand = (options) => {
|
|
87
|
+
return ["-jar", import_google_closure_compiler_java.default].concat(import_utils.utils.buildArgs(options || {}));
|
|
88
|
+
};
|
|
89
|
+
var src_default = minifyGCC;
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {});
|
|
92
|
+
/*!
|
|
93
|
+
* node-minify
|
|
94
|
+
* Copyright(c) 2011-2022 Rodolphe Stoclin
|
|
95
|
+
* MIT Licensed
|
|
96
|
+
*/
|
|
97
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2022 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport compilerPath from 'google-closure-compiler-java';\nimport { utils } from '@node-minify/utils';\nimport { runCommandLine } from '@node-minify/run';\nimport { MinifierOptions, Options, Dictionary } from '@node-minify/types';\n\n// interface Options2 {\n// [Key: string]: string;\n// }\n\n// interface Settings {\n// options: Options;\n// content: string;\n// output: string;\n// sync: boolean;\n// buffer: number;\n// }\n\n// interface MinifierOptions {\n// settings: Settings;\n// content: string;\n// callback: Function;\n// index: number;\n// }\n\n// the allowed flags, taken from https://github.com/google/closure-compiler/wiki/Flags-and-Options\nconst allowedFlags = [\n 'angular_pass',\n 'assume_function_wrapper',\n 'checks_only',\n 'compilation_level',\n 'create_source_map',\n 'define',\n 'env',\n 'externs',\n 'export_local_property_definitions',\n 'generate_exports',\n 'language_in',\n 'language_out',\n 'output_wrapper',\n 'polymer_version',\n 'process_common_js_modules',\n 'rename_prefix_namespace',\n 'rewrite_polyfills',\n 'use_types_for_optimization',\n 'warning_level'\n];\n\n/**\n * Run Google Closure Compiler.\n *\n * @param {Object} settings\n * @param {String} content\n * @param {Function} callback\n */\nconst minifyGCC = ({ settings, content, callback, index }: MinifierOptions) => {\n const options = applyOptions({}, (settings && settings.options) || {});\n return runCommandLine({\n args: gccCommand(options),\n data: content,\n settings,\n callback: (err: Error, content: string) => {\n if (err) {\n if (callback) {\n return callback(err);\n } else {\n throw err;\n }\n }\n if (settings && !settings.content) {\n utils.writeFile({ file: settings.output, content, index });\n }\n if (callback) {\n return callback(null, content);\n }\n return content;\n }\n });\n};\n\n// interface Dictionary<T> {\n// [Key: string]: T;\n// }\n\n/**\n * Adds any valid options passed in the options parameters to the flags parameter and returns the flags object.\n * @param {Object} flags\n * @param {Object} options\n * @returns {Object} flags\n */\nconst applyOptions = (flags: Dictionary<string>, options: Options) => {\n if (!options || Object.keys(options).length === 0) {\n return flags;\n }\n Object.keys(options)\n .filter(option => allowedFlags.indexOf(option) > -1)\n .forEach(option => (flags[option] = options[option]));\n return flags;\n};\n\n/**\n * GCC command line.\n */\n\nconst gccCommand = (options: {}) => {\n return ['-jar', compilerPath].concat(utils.buildArgs(options || {}));\n};\n\n/**\n * Expose `minifyGCC()`.\n */\nexport default minifyGCC;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,0CAAyB;AACzB,mBAAsB;AACtB,iBAA+B;AAuB/B,IAAM,eAAe;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AASA,IAAM,YAAY,CAAC,EAAE,UAAU,SAAS,UAAU,MAAM,MAAuB;AAC7E,QAAM,UAAU,aAAa,CAAC,GAAI,YAAY,SAAS,WAAY,CAAC,CAAC;AACrE,aAAO,2BAAe;AAAA,IACpB,MAAM,WAAW,OAAO;AAAA,IACxB,MAAM;AAAA,IACN;AAAA,IACA,UAAU,CAAC,KAAYA,aAAoB;AACzC,UAAI,KAAK;AACP,YAAI,UAAU;AACZ,iBAAO,SAAS,GAAG;AAAA,QACrB,OAAO;AACL,gBAAM;AAAA,QACR;AAAA,MACF;AACA,UAAI,YAAY,CAAC,SAAS,SAAS;AACjC,2BAAM,UAAU,EAAE,MAAM,SAAS,QAAQ,SAAAA,UAAS,MAAM,CAAC;AAAA,MAC3D;AACA,UAAI,UAAU;AACZ,eAAO,SAAS,MAAMA,QAAO;AAAA,MAC/B;AACA,aAAOA;AAAA,IACT;AAAA,EACF,CAAC;AACH;AAYA,IAAM,eAAe,CAAC,OAA2B,YAAqB;AACpE,MAAI,CAAC,WAAW,OAAO,KAAK,OAAO,EAAE,WAAW,GAAG;AACjD,WAAO;AAAA,EACT;AACA,SAAO,KAAK,OAAO,EAChB,OAAO,YAAU,aAAa,QAAQ,MAAM,IAAI,EAAE,EAClD,QAAQ,YAAW,MAAM,UAAU,QAAQ,OAAQ;AACtD,SAAO;AACT;AAMA,IAAM,aAAa,CAAC,YAAgB;AAClC,SAAO,CAAC,QAAQ,oCAAAC,OAAY,EAAE,OAAO,mBAAM,UAAU,WAAW,CAAC,CAAC,CAAC;AACrE;AAKA,IAAO,cAAQ;","names":["content","compilerPath"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import compilerPath from "google-closure-compiler-java";
|
|
3
|
+
import { utils } from "@node-minify/utils";
|
|
4
|
+
import { runCommandLine } from "@node-minify/run";
|
|
5
|
+
var allowedFlags = [
|
|
6
|
+
"angular_pass",
|
|
7
|
+
"assume_function_wrapper",
|
|
8
|
+
"checks_only",
|
|
9
|
+
"compilation_level",
|
|
10
|
+
"create_source_map",
|
|
11
|
+
"define",
|
|
12
|
+
"env",
|
|
13
|
+
"externs",
|
|
14
|
+
"export_local_property_definitions",
|
|
15
|
+
"generate_exports",
|
|
16
|
+
"language_in",
|
|
17
|
+
"language_out",
|
|
18
|
+
"output_wrapper",
|
|
19
|
+
"polymer_version",
|
|
20
|
+
"process_common_js_modules",
|
|
21
|
+
"rename_prefix_namespace",
|
|
22
|
+
"rewrite_polyfills",
|
|
23
|
+
"use_types_for_optimization",
|
|
24
|
+
"warning_level"
|
|
25
|
+
];
|
|
26
|
+
var minifyGCC = ({ settings, content, callback, index }) => {
|
|
27
|
+
const options = applyOptions({}, settings && settings.options || {});
|
|
28
|
+
return runCommandLine({
|
|
29
|
+
args: gccCommand(options),
|
|
30
|
+
data: content,
|
|
31
|
+
settings,
|
|
32
|
+
callback: (err, content2) => {
|
|
33
|
+
if (err) {
|
|
34
|
+
if (callback) {
|
|
35
|
+
return callback(err);
|
|
36
|
+
} else {
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (settings && !settings.content) {
|
|
41
|
+
utils.writeFile({ file: settings.output, content: content2, index });
|
|
42
|
+
}
|
|
43
|
+
if (callback) {
|
|
44
|
+
return callback(null, content2);
|
|
45
|
+
}
|
|
46
|
+
return content2;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
var applyOptions = (flags, options) => {
|
|
51
|
+
if (!options || Object.keys(options).length === 0) {
|
|
52
|
+
return flags;
|
|
53
|
+
}
|
|
54
|
+
Object.keys(options).filter((option) => allowedFlags.indexOf(option) > -1).forEach((option) => flags[option] = options[option]);
|
|
55
|
+
return flags;
|
|
56
|
+
};
|
|
57
|
+
var gccCommand = (options) => {
|
|
58
|
+
return ["-jar", compilerPath].concat(utils.buildArgs(options || {}));
|
|
59
|
+
};
|
|
60
|
+
var src_default = minifyGCC;
|
|
61
|
+
export {
|
|
62
|
+
src_default as default
|
|
63
|
+
};
|
|
64
|
+
/*!
|
|
65
|
+
* node-minify
|
|
66
|
+
* Copyright(c) 2011-2022 Rodolphe Stoclin
|
|
67
|
+
* MIT Licensed
|
|
68
|
+
*/
|
|
69
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2022 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport compilerPath from 'google-closure-compiler-java';\nimport { utils } from '@node-minify/utils';\nimport { runCommandLine } from '@node-minify/run';\nimport { MinifierOptions, Options, Dictionary } from '@node-minify/types';\n\n// interface Options2 {\n// [Key: string]: string;\n// }\n\n// interface Settings {\n// options: Options;\n// content: string;\n// output: string;\n// sync: boolean;\n// buffer: number;\n// }\n\n// interface MinifierOptions {\n// settings: Settings;\n// content: string;\n// callback: Function;\n// index: number;\n// }\n\n// the allowed flags, taken from https://github.com/google/closure-compiler/wiki/Flags-and-Options\nconst allowedFlags = [\n 'angular_pass',\n 'assume_function_wrapper',\n 'checks_only',\n 'compilation_level',\n 'create_source_map',\n 'define',\n 'env',\n 'externs',\n 'export_local_property_definitions',\n 'generate_exports',\n 'language_in',\n 'language_out',\n 'output_wrapper',\n 'polymer_version',\n 'process_common_js_modules',\n 'rename_prefix_namespace',\n 'rewrite_polyfills',\n 'use_types_for_optimization',\n 'warning_level'\n];\n\n/**\n * Run Google Closure Compiler.\n *\n * @param {Object} settings\n * @param {String} content\n * @param {Function} callback\n */\nconst minifyGCC = ({ settings, content, callback, index }: MinifierOptions) => {\n const options = applyOptions({}, (settings && settings.options) || {});\n return runCommandLine({\n args: gccCommand(options),\n data: content,\n settings,\n callback: (err: Error, content: string) => {\n if (err) {\n if (callback) {\n return callback(err);\n } else {\n throw err;\n }\n }\n if (settings && !settings.content) {\n utils.writeFile({ file: settings.output, content, index });\n }\n if (callback) {\n return callback(null, content);\n }\n return content;\n }\n });\n};\n\n// interface Dictionary<T> {\n// [Key: string]: T;\n// }\n\n/**\n * Adds any valid options passed in the options parameters to the flags parameter and returns the flags object.\n * @param {Object} flags\n * @param {Object} options\n * @returns {Object} flags\n */\nconst applyOptions = (flags: Dictionary<string>, options: Options) => {\n if (!options || Object.keys(options).length === 0) {\n return flags;\n }\n Object.keys(options)\n .filter(option => allowedFlags.indexOf(option) > -1)\n .forEach(option => (flags[option] = options[option]));\n return flags;\n};\n\n/**\n * GCC command line.\n */\n\nconst gccCommand = (options: {}) => {\n return ['-jar', compilerPath].concat(utils.buildArgs(options || {}));\n};\n\n/**\n * Expose `minifyGCC()`.\n */\nexport default minifyGCC;\n"],"mappings":";AASA,OAAO,kBAAkB;AACzB,SAAS,aAAa;AACtB,SAAS,sBAAsB;AAuB/B,IAAM,eAAe;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AASA,IAAM,YAAY,CAAC,EAAE,UAAU,SAAS,UAAU,MAAM,MAAuB;AAC7E,QAAM,UAAU,aAAa,CAAC,GAAI,YAAY,SAAS,WAAY,CAAC,CAAC;AACrE,SAAO,eAAe;AAAA,IACpB,MAAM,WAAW,OAAO;AAAA,IACxB,MAAM;AAAA,IACN;AAAA,IACA,UAAU,CAAC,KAAYA,aAAoB;AACzC,UAAI,KAAK;AACP,YAAI,UAAU;AACZ,iBAAO,SAAS,GAAG;AAAA,QACrB,OAAO;AACL,gBAAM;AAAA,QACR;AAAA,MACF;AACA,UAAI,YAAY,CAAC,SAAS,SAAS;AACjC,cAAM,UAAU,EAAE,MAAM,SAAS,QAAQ,SAAAA,UAAS,MAAM,CAAC;AAAA,MAC3D;AACA,UAAI,UAAU;AACZ,eAAO,SAAS,MAAMA,QAAO;AAAA,MAC/B;AACA,aAAOA;AAAA,IACT;AAAA,EACF,CAAC;AACH;AAYA,IAAM,eAAe,CAAC,OAA2B,YAAqB;AACpE,MAAI,CAAC,WAAW,OAAO,KAAK,OAAO,EAAE,WAAW,GAAG;AACjD,WAAO;AAAA,EACT;AACA,SAAO,KAAK,OAAO,EAChB,OAAO,YAAU,aAAa,QAAQ,MAAM,IAAI,EAAE,EAClD,QAAQ,YAAW,MAAM,UAAU,QAAQ,OAAQ;AACtD,SAAO;AACT;AAMA,IAAM,aAAa,CAAC,YAAgB;AAClC,SAAO,CAAC,QAAQ,YAAY,EAAE,OAAO,MAAM,UAAU,WAAW,CAAC,CAAC,CAAC;AACrE;AAKA,IAAO,cAAQ;","names":["content"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-minify/google-closure-compiler",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.1-beta.0",
|
|
4
4
|
"description": "google closure compiler plugin for @node-minify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compressor",
|
|
@@ -12,16 +12,23 @@
|
|
|
12
12
|
"author": "Rodolphe Stoclin <srodolphe@gmail.com>",
|
|
13
13
|
"homepage": "https://github.com/srod/node-minify/tree/master/packages/google-closure-compiler#readme",
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"main": "lib/google-closure-compiler.js",
|
|
16
15
|
"engines": {
|
|
17
16
|
"node": ">=14.0.0"
|
|
18
17
|
},
|
|
19
18
|
"directories": {
|
|
20
|
-
"lib": "
|
|
19
|
+
"lib": "dist",
|
|
21
20
|
"test": "__tests__"
|
|
22
21
|
},
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"module": "./dist/index.mjs",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
"require": "./dist/index.js",
|
|
27
|
+
"import": "./dist/index.mjs",
|
|
28
|
+
"types": "./dist/index.d.ts"
|
|
29
|
+
},
|
|
23
30
|
"files": [
|
|
24
|
-
"
|
|
31
|
+
"dist/**/*"
|
|
25
32
|
],
|
|
26
33
|
"publishConfig": {
|
|
27
34
|
"access": "public"
|
|
@@ -33,10 +40,18 @@
|
|
|
33
40
|
"bugs": {
|
|
34
41
|
"url": "https://github.com/srod/node-minify/issues"
|
|
35
42
|
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"clean": "pnpm dlx rimraf dist",
|
|
45
|
+
"build": "npm run clean && tsup src/index.ts --format cjs,esm --dts --clean --sourcemap",
|
|
46
|
+
"prepublishOnly": "npm run build"
|
|
47
|
+
},
|
|
36
48
|
"dependencies": {
|
|
37
|
-
"@node-minify/run": "
|
|
38
|
-
"@node-minify/utils": "
|
|
49
|
+
"@node-minify/run": "8.0.1-beta.0",
|
|
50
|
+
"@node-minify/utils": "8.0.1-beta.0",
|
|
39
51
|
"google-closure-compiler-java": "20221102.0.1"
|
|
40
52
|
},
|
|
41
|
-
"
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@node-minify/types": "8.0.1-beta.0"
|
|
55
|
+
},
|
|
56
|
+
"gitHead": "35a8a41ec86a11cbec05d8a7db9113475ece2cef"
|
|
42
57
|
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _googleClosureCompilerJava = _interopRequireDefault(require("google-closure-compiler-java"));
|
|
4
|
-
var _utils = require("@node-minify/utils");
|
|
5
|
-
var _run = require("@node-minify/run");
|
|
6
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
|
-
/*!
|
|
8
|
-
* node-minify
|
|
9
|
-
* Copyright(c) 2011-2022 Rodolphe Stoclin
|
|
10
|
-
* MIT Licensed
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Module dependencies.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
// the allowed flags, taken from https://github.com/google/closure-compiler/wiki/Flags-and-Options
|
|
18
|
-
const allowedFlags = ['angular_pass', 'assume_function_wrapper', 'checks_only', 'compilation_level', 'create_source_map', 'define', 'env', 'externs', 'export_local_property_definitions', 'generate_exports', 'language_in', 'language_out', 'output_wrapper', 'polymer_version', 'process_common_js_modules', 'rename_prefix_namespace', 'rewrite_polyfills', 'use_types_for_optimization', 'warning_level'];
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Run Google Closure Compiler.
|
|
22
|
-
*
|
|
23
|
-
* @param {Object} settings
|
|
24
|
-
* @param {String} content
|
|
25
|
-
* @param {Function} callback
|
|
26
|
-
*/
|
|
27
|
-
const minifyGCC = ({
|
|
28
|
-
settings,
|
|
29
|
-
content,
|
|
30
|
-
callback,
|
|
31
|
-
index
|
|
32
|
-
}) => {
|
|
33
|
-
const options = applyOptions({}, settings.options);
|
|
34
|
-
return (0, _run.runCommandLine)({
|
|
35
|
-
args: gccCommand(options),
|
|
36
|
-
data: content,
|
|
37
|
-
settings,
|
|
38
|
-
callback: (err, content) => {
|
|
39
|
-
if (err) {
|
|
40
|
-
if (callback) {
|
|
41
|
-
return callback(err);
|
|
42
|
-
} else {
|
|
43
|
-
throw err;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (!settings.content) {
|
|
47
|
-
_utils.utils.writeFile({
|
|
48
|
-
file: settings.output,
|
|
49
|
-
content,
|
|
50
|
-
index
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
if (callback) {
|
|
54
|
-
return callback(null, content);
|
|
55
|
-
}
|
|
56
|
-
return content;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Adds any valid options passed in the options parameters to the flags parameter and returns the flags object.
|
|
63
|
-
* @param {Object} flags
|
|
64
|
-
* @param {Object} options
|
|
65
|
-
* @returns {Object} flags
|
|
66
|
-
*/
|
|
67
|
-
const applyOptions = (flags, options) => {
|
|
68
|
-
if (!options || Object.keys(options).length === 0) {
|
|
69
|
-
return flags;
|
|
70
|
-
}
|
|
71
|
-
Object.keys(options).filter(option => allowedFlags.indexOf(option) > -1).forEach(option => flags[option] = options[option]);
|
|
72
|
-
return flags;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* GCC command line.
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
const gccCommand = options => {
|
|
80
|
-
return ['-jar', _googleClosureCompilerJava.default].concat(_utils.utils.buildArgs(options || {}));
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Expose `minifyGCC()`.
|
|
85
|
-
*/
|
|
86
|
-
module.exports = minifyGCC;
|