@node-minify/google-closure-compiler 6.4.0 → 7.1.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,11 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _googleClosureCompiler = _interopRequireDefault(require("google-closure-compiler"));
4
-
3
+ var _googleClosureCompilerJava = _interopRequireDefault(require("google-closure-compiler-java"));
5
4
  var _utils = require("@node-minify/utils");
6
-
5
+ var _run = require("@node-minify/run");
7
6
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
-
9
7
  /*!
10
8
  * node-minify
11
9
  * Copyright(c) 2011-2022 Rodolphe Stoclin
@@ -16,12 +14,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
16
14
  * Module dependencies.
17
15
  */
18
16
 
19
- /**
20
- * Module variables.
21
- */
22
- const ClosureCompiler = _googleClosureCompiler.default.jsCompiler; // the allowed flags, taken from https://github.com/google/closure-compiler
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'];
23
19
 
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'];
25
20
  /**
26
21
  * Run Google Closure Compiler.
27
22
  *
@@ -29,7 +24,6 @@ const allowedFlags = ['angularPass', 'applyInputSourceMaps', 'assumeFunctionWrap
29
24
  * @param {String} content
30
25
  * @param {Function} callback
31
26
  */
32
-
33
27
  const minifyGCC = ({
34
28
  settings,
35
29
  content,
@@ -37,65 +31,56 @@ const minifyGCC = ({
37
31
  index
38
32
  }) => {
39
33
  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);
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;
46
57
  }
47
58
  });
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
59
  };
60
+
80
61
  /**
81
62
  * Adds any valid options passed in the options parameters to the flags parameter and returns the flags object.
82
63
  * @param {Object} flags
83
64
  * @param {Object} options
84
65
  * @returns {Object} flags
85
66
  */
86
-
87
-
88
67
  const applyOptions = (flags, options) => {
89
68
  if (!options || Object.keys(options).length === 0) {
90
69
  return flags;
91
70
  }
92
-
93
71
  Object.keys(options).filter(option => allowedFlags.indexOf(option) > -1).forEach(option => flags[option] = options[option]);
94
72
  return flags;
95
73
  };
74
+
96
75
  /**
97
- * Expose `minifyGCC()`.
76
+ * GCC command line.
98
77
  */
99
78
 
79
+ const gccCommand = options => {
80
+ return ['-jar', _googleClosureCompilerJava.default].concat(_utils.utils.buildArgs(options || {}));
81
+ };
100
82
 
83
+ /**
84
+ * Expose `minifyGCC()`.
85
+ */
101
86
  module.exports = minifyGCC;
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.1.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,9 @@
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/run": "^7.1.0",
38
+ "@node-minify/utils": "^7.1.0",
39
+ "google-closure-compiler-java": "20221102.0.1"
39
40
  },
40
- "gitHead": "d529747a661487597e9be510d3d9e2df1bc0f556"
41
+ "gitHead": "94cef2d5d653c3bddc3e603b4e25c135b0b6f4b3"
41
42
  }