@node-minify/google-closure-compiler 6.4.0 → 7.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.
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
 
3
- var _googleClosureCompiler = _interopRequireDefault(require("google-closure-compiler"));
3
+ var _googleClosureCompilerJava = _interopRequireDefault(require("google-closure-compiler-java"));
4
4
 
5
5
  var _utils = require("@node-minify/utils");
6
6
 
7
+ var _run = require("@node-minify/run");
8
+
7
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
10
 
9
11
  /*!
@@ -15,13 +17,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
15
17
  /**
16
18
  * Module dependencies.
17
19
  */
18
-
19
- /**
20
- * Module variables.
21
- */
22
- const ClosureCompiler = _googleClosureCompiler.default.jsCompiler; // the allowed flags, taken from https://github.com/google/closure-compiler
23
-
24
- const allowedFlags = ['angularPass', 'applyInputSourceMaps', 'assumeFunctionWrapper', 'checksOnly', 'compilationLevel', 'createSourceMap', 'dartPass', 'defines', 'env', 'externs', 'exportLocalPropertyDefinitions', 'generateExports', 'languageIn', 'languageOut', 'newTypeInf', 'outputWrapper', 'polymerVersion', 'preserveTypeAnnotations', 'processCommonJsModules', 'renamePrefixNamespace', 'rewritePolyfills', 'useTypesForOptimization', 'warningLevel'];
20
+ // the allowed flags, taken from https://github.com/google/closure-compiler/wiki/Flags-and-Options
21
+ 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'];
25
22
  /**
26
23
  * Run Google Closure Compiler.
27
24
  *
@@ -37,45 +34,34 @@ const minifyGCC = ({
37
34
  index
38
35
  }) => {
39
36
  const options = applyOptions({}, settings.options);
40
- const gcc = new ClosureCompiler(options);
41
- const contentMinified = gcc.run([{
42
- src: content
43
- }], (exitCode, stdOut, stdErr) => {
44
- if (exitCode > 0 && callback) {
45
- return callback(stdErr);
37
+ return (0, _run.runCommandLine)({
38
+ args: gccCommand(options),
39
+ data: content,
40
+ settings,
41
+ callback: (err, content) => {
42
+ if (err) {
43
+ if (callback) {
44
+ return callback(err);
45
+ } else {
46
+ throw err;
47
+ }
48
+ }
49
+
50
+ if (!settings.content) {
51
+ _utils.utils.writeFile({
52
+ file: settings.output,
53
+ content,
54
+ index
55
+ });
56
+ }
57
+
58
+ if (callback) {
59
+ return callback(null, content);
60
+ }
61
+
62
+ return content;
46
63
  }
47
64
  });
48
-
49
- if (!settings.content) {
50
- _utils.utils.writeFile({
51
- file: settings.output,
52
- content: contentMinified.compiledCode,
53
- index
54
- });
55
- }
56
- /**
57
- * Write GCC sourceMap
58
- * If the createSourceMap option is passed we'll write the sourceMap file
59
- * If createSourceMap is a boolean we'll append .map to the settings.output file path
60
- * otherwise use createSourceMap as the file path.
61
- */
62
-
63
-
64
- if (settings.options.createSourceMap) {
65
- const sourceMapOutput = typeof settings.options.createSourceMap === 'boolean' ? settings.output + '.map' : settings.options.createSourceMap;
66
-
67
- _utils.utils.writeFile({
68
- file: sourceMapOutput,
69
- content: contentMinified.sourceMap,
70
- index
71
- });
72
- }
73
-
74
- if (callback) {
75
- return callback(null, contentMinified.compiledCode);
76
- }
77
-
78
- return contentMinified.compiledCode;
79
65
  };
80
66
  /**
81
67
  * Adds any valid options passed in the options parameters to the flags parameter and returns the flags object.
@@ -93,6 +79,14 @@ const applyOptions = (flags, options) => {
93
79
  Object.keys(options).filter(option => allowedFlags.indexOf(option) > -1).forEach(option => flags[option] = options[option]);
94
80
  return flags;
95
81
  };
82
+ /**
83
+ * GCC command line.
84
+ */
85
+
86
+
87
+ const gccCommand = options => {
88
+ return ['-jar', _googleClosureCompilerJava.default].concat(_utils.utils.buildArgs(options || {}));
89
+ };
96
90
  /**
97
91
  * Expose `minifyGCC()`.
98
92
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-minify/google-closure-compiler",
3
- "version": "6.4.0",
3
+ "version": "7.0.0",
4
4
  "description": "google closure compiler plugin for @node-minify",
5
5
  "keywords": [
6
6
  "compressor",
@@ -14,7 +14,7 @@
14
14
  "license": "MIT",
15
15
  "main": "lib/google-closure-compiler.js",
16
16
  "engines": {
17
- "node": ">=12.0.0"
17
+ "node": ">=14.0.0"
18
18
  },
19
19
  "directories": {
20
20
  "lib": "lib",
@@ -34,8 +34,8 @@
34
34
  "url": "https://github.com/srod/node-minify/issues"
35
35
  },
36
36
  "dependencies": {
37
- "@node-minify/utils": "^6.4.0",
38
- "google-closure-compiler": "20200719.0.0"
37
+ "@node-minify/utils": "^7.0.0",
38
+ "google-closure-compiler-java": "20220719.0.0"
39
39
  },
40
- "gitHead": "d529747a661487597e9be510d3d9e2df1bc0f556"
40
+ "gitHead": "8b5bda6f1ac9fe7180006f2a19ec3253e8fff4ec"
41
41
  }