@node-minify/google-closure-compiler 6.1.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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Rodolphe Stoclin
3
+ Copyright (c) 2022 Rodolphe Stoclin
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,33 +1,30 @@
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
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
+ var _run = require("@node-minify/run");
8
8
 
9
- /*!
10
- * node-minify
11
- * Copyright(c) 2011-2020 Rodolphe Stoclin
12
- * MIT Licensed
13
- */
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
10
 
15
- /**
16
- * Module dependencies.
11
+ /*!
12
+ * node-minify
13
+ * Copyright(c) 2011-2022 Rodolphe Stoclin
14
+ * MIT Licensed
17
15
  */
18
16
 
19
- /**
20
- * Module variables.
17
+ /**
18
+ * Module dependencies.
21
19
  */
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'];
25
- /**
26
- * Run Google Closure Compiler.
27
- *
28
- * @param {Object} settings
29
- * @param {String} content
30
- * @param {Function} callback
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'];
22
+ /**
23
+ * Run Google Closure Compiler.
24
+ *
25
+ * @param {Object} settings
26
+ * @param {String} content
27
+ * @param {Function} callback
31
28
  */
32
29
 
33
30
  const minifyGCC = ({
@@ -37,51 +34,40 @@ 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
- /**
81
- * Adds any valid options passed in the options parameters to the flags parameter and returns the flags object.
82
- * @param {Object} flags
83
- * @param {Object} options
84
- * @returns {Object} flags
66
+ /**
67
+ * Adds any valid options passed in the options parameters to the flags parameter and returns the flags object.
68
+ * @param {Object} flags
69
+ * @param {Object} options
70
+ * @returns {Object} flags
85
71
  */
86
72
 
87
73
 
@@ -93,8 +79,16 @@ 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
  };
96
- /**
97
- * Expose `minifyGCC()`.
82
+ /**
83
+ * GCC command line.
84
+ */
85
+
86
+
87
+ const gccCommand = options => {
88
+ return ['-jar', _googleClosureCompilerJava.default].concat(_utils.utils.buildArgs(options || {}));
89
+ };
90
+ /**
91
+ * Expose `minifyGCC()`.
98
92
  */
99
93
 
100
94
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-minify/google-closure-compiler",
3
- "version": "6.1.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": ">=10.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.1.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": "9140d008f49b5ab36f167250097f0a094a5af061"
40
+ "gitHead": "8b5bda6f1ac9fe7180006f2a19ec3253e8fff4ec"
41
41
  }