@node-minify/google-closure-compiler 9.0.1 → 10.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 +1 -1
- package/README.md +7 -8
- package/dist/index.d.ts +156 -9
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -92
- package/dist/index.js.map +1 -1
- package/package.json +24 -22
- package/dist/index.d.mts +0 -14
- package/dist/index.mjs +0 -81
- package/dist/index.mjs.map +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
<br>
|
|
7
7
|
<a href="https://npmjs.org/package/@node-minify/google-closure-compiler"><img src="https://img.shields.io/npm/v/@node-minify/google-closure-compiler.svg"></a>
|
|
8
8
|
<a href="https://npmjs.org/package/@node-minify/google-closure-compiler"><img src="https://img.shields.io/npm/dm/@node-minify/google-closure-compiler.svg"></a>
|
|
9
|
-
<a href="https://github.com/srod/node-minify/actions"><img alt="Build Status" src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fsrod%2Fnode-minify%2Fbadge%3Fref%
|
|
10
|
-
<a href="https://codecov.io/gh/srod/node-minify"><img src="https://codecov.io/gh/srod/node-minify/branch/
|
|
9
|
+
<a href="https://github.com/srod/node-minify/actions"><img alt="Build Status" src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fsrod%2Fnode-minify%2Fbadge%3Fref%3Dmain&style=flat" /></a>
|
|
10
|
+
<a href="https://codecov.io/gh/srod/node-minify"><img src="https://codecov.io/gh/srod/node-minify/branch/main/graph/badge.svg"></a>
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
13
|
# google-closure-compiler
|
|
@@ -25,14 +25,13 @@ npm install @node-minify/core @node-minify/google-closure-compiler
|
|
|
25
25
|
## Usage
|
|
26
26
|
|
|
27
27
|
```js
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
import { minify } from '@node-minify/core';
|
|
29
|
+
import { gcc } from '@node-minify/google-closure-compiler';
|
|
30
30
|
|
|
31
|
-
minify({
|
|
31
|
+
await minify({
|
|
32
32
|
compressor: gcc,
|
|
33
33
|
input: 'foo.js',
|
|
34
|
-
output: 'bar.js'
|
|
35
|
-
callback: function (err, min) {}
|
|
34
|
+
output: 'bar.js'
|
|
36
35
|
});
|
|
37
36
|
```
|
|
38
37
|
|
|
@@ -42,4 +41,4 @@ Visit https://node-minify.2clics.net/compressors/gcc.html for full documentation
|
|
|
42
41
|
|
|
43
42
|
## License
|
|
44
43
|
|
|
45
|
-
[MIT](https://github.com/srod/node-minify/blob/
|
|
44
|
+
[MIT](https://github.com/srod/node-minify/blob/main/LICENSE)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,161 @@
|
|
|
1
|
-
|
|
1
|
+
//#region ../types/src/types.d.ts
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* Copyright(c) 2011-2024 Rodolphe Stoclin
|
|
6
|
-
* MIT Licensed
|
|
3
|
+
/**
|
|
4
|
+
* Result returned by a compressor function.
|
|
7
5
|
*/
|
|
6
|
+
type CompressorResult = {
|
|
7
|
+
code: string;
|
|
8
|
+
map?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Base options that all compressors can accept.
|
|
12
|
+
* Specific compressors may extend this with their own options.
|
|
13
|
+
*/
|
|
14
|
+
type CompressorOptions = Record<string, unknown>;
|
|
15
|
+
/**
|
|
16
|
+
* A compressor function that minifies content.
|
|
17
|
+
* @param args - The minifier options including settings and content
|
|
18
|
+
* @returns A promise resolving to the compression result
|
|
19
|
+
*/
|
|
20
|
+
type Compressor<TOptions extends CompressorOptions = CompressorOptions> = (args: MinifierOptions<TOptions>) => Promise<CompressorResult>;
|
|
21
|
+
/**
|
|
22
|
+
* File type for compressors that support multiple types (e.g., YUI).
|
|
23
|
+
*/
|
|
24
|
+
type FileType = "js" | "css";
|
|
25
|
+
/**
|
|
26
|
+
* User-facing settings for the minify function.
|
|
27
|
+
* This is what users pass when calling minify().
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { minify } from '@node-minify/core';
|
|
32
|
+
* import { terser } from '@node-minify/terser';
|
|
33
|
+
*
|
|
34
|
+
* await minify({
|
|
35
|
+
* compressor: terser,
|
|
36
|
+
* input: 'src/*.js',
|
|
37
|
+
* output: 'dist/bundle.min.js',
|
|
38
|
+
* options: { mangle: true }
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
type Settings<TOptions extends CompressorOptions = CompressorOptions> = {
|
|
43
|
+
/**
|
|
44
|
+
* The compressor function to use for minification.
|
|
45
|
+
*/
|
|
46
|
+
compressor: Compressor<TOptions>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Optional label for the compressor (used in logging).
|
|
50
|
+
*/
|
|
51
|
+
compressorLabel?: string;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Content to minify (for in-memory minification).
|
|
55
|
+
* If provided, input/output are not required.
|
|
56
|
+
*/
|
|
57
|
+
content?: string;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Input file path(s) or glob pattern.
|
|
61
|
+
* Can be a single file, array of files, or wildcard pattern.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* - 'src/app.js'
|
|
65
|
+
* - ['src/a.js', 'src/b.js']
|
|
66
|
+
* - 'src/**\/*.js'
|
|
67
|
+
*/
|
|
68
|
+
input?: string | string[];
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Output file path.
|
|
72
|
+
* Use $1 as placeholder for input filename in multi-file scenarios.
|
|
73
|
+
* Can be a single file, array of files, or pattern with $1.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* - 'dist/bundle.min.js'
|
|
77
|
+
* - ['file1.min.js', 'file2.min.js']
|
|
78
|
+
* - '$1.min.js' (creates app.min.js from app.js)
|
|
79
|
+
*/
|
|
80
|
+
output?: string | string[];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Compressor-specific options.
|
|
84
|
+
* See individual compressor documentation for available options.
|
|
85
|
+
*/
|
|
86
|
+
options?: TOptions;
|
|
8
87
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
88
|
+
/**
|
|
89
|
+
* CLI option string (used by CLI only).
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
option?: string;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Buffer size for file operations (in bytes).
|
|
96
|
+
* @default 1024000 (1MB)
|
|
97
|
+
*/
|
|
98
|
+
buffer?: number;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* File type for compressors that support multiple types.
|
|
102
|
+
* Required for YUI compressor.
|
|
103
|
+
*/
|
|
104
|
+
type?: FileType;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Suppress console output.
|
|
108
|
+
* @default false
|
|
109
|
+
*/
|
|
110
|
+
silence?: boolean;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Public folder to prepend to input paths.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* With publicFolder: 'public/js/' and input: 'app.js',
|
|
117
|
+
* the actual path becomes 'public/js/app.js'
|
|
118
|
+
*/
|
|
119
|
+
publicFolder?: string;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Replace files in place instead of creating new output files.
|
|
123
|
+
* @default false
|
|
124
|
+
*/
|
|
125
|
+
replaceInPlace?: boolean;
|
|
12
126
|
};
|
|
127
|
+
/**
|
|
128
|
+
* Options passed to compressor functions internally.
|
|
129
|
+
* This is what compressors receive, not what users pass.
|
|
130
|
+
*/
|
|
131
|
+
type MinifierOptions<TOptions extends CompressorOptions = CompressorOptions> = {
|
|
132
|
+
/**
|
|
133
|
+
* The full settings object.
|
|
134
|
+
*/
|
|
135
|
+
settings: Settings<TOptions>;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The content to minify.
|
|
139
|
+
*/
|
|
140
|
+
content?: string;
|
|
13
141
|
|
|
14
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Index of current file when processing multiple files.
|
|
144
|
+
*/
|
|
145
|
+
index?: number;
|
|
146
|
+
};
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/index.d.ts
|
|
149
|
+
/**
|
|
150
|
+
* Run Google Closure Compiler.
|
|
151
|
+
* @param settings - GCC options
|
|
152
|
+
* @param content - Content to minify
|
|
153
|
+
* @returns Minified content
|
|
154
|
+
*/
|
|
155
|
+
declare function gcc({
|
|
156
|
+
settings,
|
|
157
|
+
content
|
|
158
|
+
}: MinifierOptions): Promise<CompressorResult>;
|
|
159
|
+
//#endregion
|
|
160
|
+
export { gcc };
|
|
161
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["CompressorReturnType","CompressorResult","CompressorOptions","Record","Compressor","TOptions","MinifierOptions","Promise","FileType","Settings","Result","MinifyOptions"],"sources":["../../types/src/types.d.ts","../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * The return type of a compressor function.\n * @deprecated Use `CompressorResult` instead. Will be removed in v11.\n */\nexport type CompressorReturnType = string;\n\n/**\n * Result returned by a compressor function.\n */\nexport type CompressorResult = {\n code: string;\n map?: string;\n};\n\n/**\n * Base options that all compressors can accept.\n * Specific compressors may extend this with their own options.\n */\nexport type CompressorOptions = Record<string, unknown>;\n\n/**\n * A compressor function that minifies content.\n * @param args - The minifier options including settings and content\n * @returns A promise resolving to the compression result\n */\nexport type Compressor<TOptions extends CompressorOptions = CompressorOptions> =\n (args: MinifierOptions<TOptions>) => Promise<CompressorResult>;\n\n/**\n * File type for compressors that support multiple types (e.g., YUI).\n */\nexport type FileType = \"js\" | \"css\";\n\n/**\n * User-facing settings for the minify function.\n * This is what users pass when calling minify().\n *\n * @example\n * ```ts\n * import { minify } from '@node-minify/core';\n * import { terser } from '@node-minify/terser';\n *\n * await minify({\n * compressor: terser,\n * input: 'src/*.js',\n * output: 'dist/bundle.min.js',\n * options: { mangle: true }\n * });\n * ```\n */\nexport type Settings<TOptions extends CompressorOptions = CompressorOptions> = {\n /**\n * The compressor function to use for minification.\n */\n compressor: Compressor<TOptions>;\n\n /**\n * Optional label for the compressor (used in logging).\n */\n compressorLabel?: string;\n\n /**\n * Content to minify (for in-memory minification).\n * If provided, input/output are not required.\n */\n content?: string;\n\n /**\n * Input file path(s) or glob pattern.\n * Can be a single file, array of files, or wildcard pattern.\n *\n * @example\n * - 'src/app.js'\n * - ['src/a.js', 'src/b.js']\n * - 'src/**\\/*.js'\n */\n input?: string | string[];\n\n /**\n * Output file path.\n * Use $1 as placeholder for input filename in multi-file scenarios.\n * Can be a single file, array of files, or pattern with $1.\n *\n * @example\n * - 'dist/bundle.min.js'\n * - ['file1.min.js', 'file2.min.js']\n * - '$1.min.js' (creates app.min.js from app.js)\n */\n output?: string | string[];\n\n /**\n * Compressor-specific options.\n * See individual compressor documentation for available options.\n */\n options?: TOptions;\n\n /**\n * CLI option string (used by CLI only).\n * @internal\n */\n option?: string;\n\n /**\n * Buffer size for file operations (in bytes).\n * @default 1024000 (1MB)\n */\n buffer?: number;\n\n /**\n * File type for compressors that support multiple types.\n * Required for YUI compressor.\n */\n type?: FileType;\n\n /**\n * Suppress console output.\n * @default false\n */\n silence?: boolean;\n\n /**\n * Public folder to prepend to input paths.\n *\n * @example\n * With publicFolder: 'public/js/' and input: 'app.js',\n * the actual path becomes 'public/js/app.js'\n */\n publicFolder?: string;\n\n /**\n * Replace files in place instead of creating new output files.\n * @default false\n */\n replaceInPlace?: boolean;\n};\n\n/**\n * Options passed to compressor functions internally.\n * This is what compressors receive, not what users pass.\n */\nexport type MinifierOptions<\n TOptions extends CompressorOptions = CompressorOptions,\n> = {\n /**\n * The full settings object.\n */\n settings: Settings<TOptions>;\n\n /**\n * The content to minify.\n */\n content?: string;\n\n /**\n * Index of current file when processing multiple files.\n */\n index?: number;\n};\n\n/**\n * Result returned after compression (used by CLI).\n */\nexport type Result = {\n /**\n * Label of the compressor used.\n */\n compressorLabel: string;\n\n /**\n * Size of minified content (formatted string, e.g., \"1.5 KB\").\n */\n size: string;\n\n /**\n * Gzipped size of minified content (formatted string).\n */\n sizeGzip: string;\n};\n\n/**\n * Type alias for user convenience.\n * @deprecated Use `Settings` instead. Will be removed in v11.\n */\nexport type MinifyOptions<\n TOptions extends CompressorOptions = CompressorOptions,\n> = Settings<TOptions>;\n"],"mappings":";;AAwDA;;;AAI2BK,KA7CfJ,gBAAAA,GA6CeI;EAAXD,IAAAA,EAAAA,MAAAA;EAwCFC,GAAAA,CAAAA,EAAAA,MAAAA;CAkBHG;AA4BX;;;;AAMcC,KAhIFP,iBAAAA,GAAoBC,MAgIlBM,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;;;;AChHd;;AAEI,KDXQL,UCWR,CAAA,iBDXoCF,iBCWpC,GDXwDA,iBCWxD,CAAA,GACD,CAAA,IAAA,EDXQI,eCWR,CDXwBD,QCWxB,CAAA,EAAA,GDXsCE,OCWtC,CDX8CN,gBCW9C,CAAA;;;;KDNSO,QAAAA;;;;;;;;;;;;;;;;;;KAmBAC,0BAA0BP,oBAAoBA;;;;cAI1CE,WAAWC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAwCbA;;;;;;;;;;;;;;;;;;SAkBHG;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BCF,iCACSJ,oBAAoBA;;;;YAK3BO,SAASJ;;;;;;;;;;;;;;;;;;;AAnHvB;AAmBYI,iBChBU,GAAA,CDgBFJ;EAAAA,QAAA;EAAA;AAAA,CAAA,ECbjB,eDaiB,CAAA,ECbC,ODaD,CCbS,gBDaT,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,95 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
1
|
+
import { runCommandLine } from "@node-minify/run";
|
|
2
|
+
import { buildArgs, toBuildArgsOptions } from "@node-minify/utils";
|
|
3
|
+
import compilerPath from "google-closure-compiler-java";
|
|
24
4
|
|
|
25
|
-
|
|
26
|
-
var import_run = require("@node-minify/run");
|
|
27
|
-
var import_utils = require("@node-minify/utils");
|
|
28
|
-
var import_google_closure_compiler_java = __toESM(require("google-closure-compiler-java"));
|
|
29
|
-
var allowedFlags = [
|
|
30
|
-
"angular_pass",
|
|
31
|
-
"assume_function_wrapper",
|
|
32
|
-
"checks_only",
|
|
33
|
-
"compilation_level",
|
|
34
|
-
"create_source_map",
|
|
35
|
-
"define",
|
|
36
|
-
"env",
|
|
37
|
-
"externs",
|
|
38
|
-
"export_local_property_definitions",
|
|
39
|
-
"generate_exports",
|
|
40
|
-
"language_in",
|
|
41
|
-
"language_out",
|
|
42
|
-
"output_wrapper",
|
|
43
|
-
"polymer_version",
|
|
44
|
-
"process_common_js_modules",
|
|
45
|
-
"rename_prefix_namespace",
|
|
46
|
-
"rewrite_polyfills",
|
|
47
|
-
"use_types_for_optimization",
|
|
48
|
-
"warning_level"
|
|
49
|
-
];
|
|
50
|
-
var minifyGCC = ({ settings, content, callback, index }) => {
|
|
51
|
-
const options = applyOptions({}, settings?.options ?? {});
|
|
52
|
-
return (0, import_run.runCommandLine)({
|
|
53
|
-
args: gccCommand(options),
|
|
54
|
-
data: content,
|
|
55
|
-
settings,
|
|
56
|
-
callback: (err, content2) => {
|
|
57
|
-
if (err) {
|
|
58
|
-
if (callback) {
|
|
59
|
-
return callback(err);
|
|
60
|
-
}
|
|
61
|
-
throw err;
|
|
62
|
-
}
|
|
63
|
-
if (settings && !settings.content && settings.output) {
|
|
64
|
-
import_utils.utils.writeFile({ file: settings.output, content: content2, index });
|
|
65
|
-
}
|
|
66
|
-
if (callback) {
|
|
67
|
-
return callback(null, content2);
|
|
68
|
-
}
|
|
69
|
-
return content2;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
var applyOptions = (flags, options) => {
|
|
74
|
-
if (!options || Object.keys(options).length === 0) {
|
|
75
|
-
return flags;
|
|
76
|
-
}
|
|
77
|
-
Object.keys(options).filter((option) => allowedFlags.indexOf(option) > -1).forEach((option) => {
|
|
78
|
-
const value = options[option];
|
|
79
|
-
if (typeof value === "boolean" || typeof value === "object" && !Array.isArray(value)) {
|
|
80
|
-
flags[option] = value;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
return flags;
|
|
84
|
-
};
|
|
85
|
-
var gccCommand = (options) => {
|
|
86
|
-
return ["-jar", import_google_closure_compiler_java.default].concat(import_utils.utils.buildArgs(options ?? {}));
|
|
87
|
-
};
|
|
88
|
-
minifyGCC.default = minifyGCC;
|
|
89
|
-
module.exports = minifyGCC;
|
|
5
|
+
//#region src/index.ts
|
|
90
6
|
/*!
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
7
|
+
* node-minify
|
|
8
|
+
* Copyright(c) 2011-2025 Rodolphe Stoclin
|
|
9
|
+
* MIT Licensed
|
|
10
|
+
*/
|
|
11
|
+
const allowedFlags = [
|
|
12
|
+
"angular_pass",
|
|
13
|
+
"assume_function_wrapper",
|
|
14
|
+
"checks_only",
|
|
15
|
+
"compilation_level",
|
|
16
|
+
"create_source_map",
|
|
17
|
+
"define",
|
|
18
|
+
"env",
|
|
19
|
+
"externs",
|
|
20
|
+
"export_local_property_definitions",
|
|
21
|
+
"generate_exports",
|
|
22
|
+
"language_in",
|
|
23
|
+
"language_out",
|
|
24
|
+
"output_wrapper",
|
|
25
|
+
"polymer_version",
|
|
26
|
+
"process_common_js_modules",
|
|
27
|
+
"rename_prefix_namespace",
|
|
28
|
+
"rewrite_polyfills",
|
|
29
|
+
"use_types_for_optimization",
|
|
30
|
+
"warning_level"
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* Run Google Closure Compiler.
|
|
34
|
+
* @param settings - GCC options
|
|
35
|
+
* @param content - Content to minify
|
|
36
|
+
* @returns Minified content
|
|
37
|
+
*/
|
|
38
|
+
async function gcc({ settings, content }) {
|
|
39
|
+
const result = await runCommandLine({
|
|
40
|
+
args: gccCommand(applyOptions({}, settings?.options ?? {})),
|
|
41
|
+
data: content
|
|
42
|
+
});
|
|
43
|
+
if (typeof result !== "string") throw new Error("Google Closure Compiler failed: empty result");
|
|
44
|
+
return { code: result };
|
|
45
|
+
}
|
|
46
|
+
function applyOptions(flags, options) {
|
|
47
|
+
if (!options || Object.keys(options).length === 0) return flags;
|
|
48
|
+
Object.keys(options).filter((option) => allowedFlags.indexOf(option) > -1).forEach((option) => {
|
|
49
|
+
const value = options[option];
|
|
50
|
+
if (typeof value === "boolean" || typeof value === "object" && !Array.isArray(value)) flags[option] = value;
|
|
51
|
+
});
|
|
52
|
+
return flags;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* GCC command line.
|
|
56
|
+
* @param options the options to pass to GCC
|
|
57
|
+
* @returns the command line arguments to pass to GCC
|
|
58
|
+
*/
|
|
59
|
+
function gccCommand(options) {
|
|
60
|
+
return ["-jar", compilerPath].concat(buildArgs(toBuildArgsOptions(options)));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { gcc };
|
|
95
65
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { runCommandLine } from \"@node-minify/run\";\nimport type { CompressorResult, MinifierOptions } from \"@node-minify/types\";\nimport { buildArgs, toBuildArgsOptions } from \"@node-minify/utils\";\nimport compilerPath from \"google-closure-compiler-java\";\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 * @param settings - GCC options\n * @param content - Content to minify\n * @returns Minified content\n */\nexport async function gcc({\n settings,\n content,\n}: MinifierOptions): Promise<CompressorResult> {\n const options = applyOptions({}, settings?.options ?? {});\n\n const result = await runCommandLine({\n args: gccCommand(options),\n data: content as string,\n });\n\n if (typeof result !== \"string\") {\n throw new Error(\"Google Closure Compiler failed: empty result\");\n }\n\n return { code: result };\n}\n\n/**\n * Adds any valid options passed in the options parameters to the flags parameter and returns the flags object.\n * @param flags the flags object to add options to\n * @param options the options object to add to the flags object\n * @returns the flags object with the options added\n */\ntype Flags = {\n [key: string]: boolean | Record<string, unknown>;\n};\nfunction applyOptions(flags: Flags, options?: Record<string, unknown>): Flags {\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) => {\n const value = options[option];\n if (\n typeof value === \"boolean\" ||\n (typeof value === \"object\" && !Array.isArray(value))\n ) {\n flags[option] = value as boolean | Record<string, unknown>;\n }\n });\n return flags;\n}\n\n/**\n * GCC command line.\n * @param options the options to pass to GCC\n * @returns the command line arguments to pass to GCC\n */\n\nfunction gccCommand(options: Record<string, unknown>) {\n return [\"-jar\", compilerPath].concat(\n buildArgs(toBuildArgsOptions(options))\n );\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAM,eAAe;CACjB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACH;;;;;;;AAQD,eAAsB,IAAI,EACtB,UACA,WAC2C;CAG3C,MAAM,SAAS,MAAM,eAAe;EAChC,MAAM,WAHM,aAAa,EAAE,EAAE,UAAU,WAAW,EAAE,CAAC,CAG5B;EACzB,MAAM;EACT,CAAC;AAEF,KAAI,OAAO,WAAW,SAClB,OAAM,IAAI,MAAM,+CAA+C;AAGnE,QAAO,EAAE,MAAM,QAAQ;;AAY3B,SAAS,aAAa,OAAc,SAA0C;AAC1E,KAAI,CAAC,WAAW,OAAO,KAAK,QAAQ,CAAC,WAAW,EAC5C,QAAO;AAEX,QAAO,KAAK,QAAQ,CACf,QAAQ,WAAW,aAAa,QAAQ,OAAO,GAAG,GAAG,CACrD,SAAS,WAAW;EACjB,MAAM,QAAQ,QAAQ;AACtB,MACI,OAAO,UAAU,aAChB,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,MAAM,CAEnD,OAAM,UAAU;GAEtB;AACN,QAAO;;;;;;;AASX,SAAS,WAAW,SAAkC;AAClD,QAAO,CAAC,QAAQ,aAAa,CAAC,OAC1B,UAAU,mBAAmB,QAAQ,CAAC,CACzC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-minify/google-closure-compiler",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "google closure compiler plugin for @node-minify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compressor",
|
|
@@ -10,25 +10,23 @@
|
|
|
10
10
|
"google closure compiler"
|
|
11
11
|
],
|
|
12
12
|
"author": "Rodolphe Stoclin <srodolphe@gmail.com>",
|
|
13
|
-
"homepage": "https://github.com/srod/node-minify/tree/
|
|
13
|
+
"homepage": "https://github.com/srod/node-minify/tree/main/packages/google-closure-compiler#readme",
|
|
14
14
|
"license": "MIT",
|
|
15
|
+
"type": "module",
|
|
15
16
|
"engines": {
|
|
16
|
-
"node": ">=
|
|
17
|
+
"node": ">=20.0.0"
|
|
17
18
|
},
|
|
18
19
|
"directories": {
|
|
19
20
|
"lib": "dist",
|
|
20
21
|
"test": "__tests__"
|
|
21
22
|
},
|
|
22
|
-
"main": "./dist/index.js",
|
|
23
|
-
"module": "./dist/index.mjs",
|
|
24
23
|
"types": "./dist/index.d.ts",
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
25
|
"exports": {
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
"import": "./dist/index.mjs",
|
|
29
|
-
"require": "./dist/index.js"
|
|
30
|
-
}
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
31
28
|
},
|
|
29
|
+
"sideEffects": false,
|
|
32
30
|
"files": [
|
|
33
31
|
"dist/**/*"
|
|
34
32
|
],
|
|
@@ -42,20 +40,24 @@
|
|
|
42
40
|
"bugs": {
|
|
43
41
|
"url": "https://github.com/srod/node-minify/issues"
|
|
44
42
|
},
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"google-closure-compiler-java": "20231112.0.0",
|
|
47
|
-
"@node-minify/run": "9.0.1",
|
|
48
|
-
"@node-minify/utils": "9.0.1"
|
|
49
|
-
},
|
|
50
|
-
"devDependencies": {
|
|
51
|
-
"@node-minify/types": "9.0.0"
|
|
52
|
-
},
|
|
53
43
|
"scripts": {
|
|
54
|
-
"
|
|
55
|
-
"
|
|
44
|
+
"build": "tsdown src/index.ts",
|
|
45
|
+
"check-exports": "attw --pack . --profile esm-only",
|
|
46
|
+
"format:check": "biome check .",
|
|
56
47
|
"lint": "biome lint .",
|
|
48
|
+
"prepublishOnly": "bun run build",
|
|
57
49
|
"test": "vitest run",
|
|
58
50
|
"test:ci": "vitest run --coverage",
|
|
59
|
-
"test:watch": "vitest"
|
|
51
|
+
"test:watch": "vitest",
|
|
52
|
+
"typecheck": "tsc --noEmit",
|
|
53
|
+
"dev": "tsdown src/index.ts --watch"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@node-minify/run": "workspace:*",
|
|
57
|
+
"@node-minify/utils": "workspace:*",
|
|
58
|
+
"google-closure-compiler-java": "20240317.0.0"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@node-minify/types": "workspace:*"
|
|
60
62
|
}
|
|
61
|
-
}
|
|
63
|
+
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { MinifierOptions } from '@node-minify/types';
|
|
2
|
-
|
|
3
|
-
/*!
|
|
4
|
-
* node-minify
|
|
5
|
-
* Copyright(c) 2011-2024 Rodolphe Stoclin
|
|
6
|
-
* MIT Licensed
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
declare const minifyGCC: {
|
|
10
|
-
({ settings, content, callback, index }: MinifierOptions): void;
|
|
11
|
-
default: any;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export { minifyGCC as default };
|
package/dist/index.mjs
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
// src/index.ts
|
|
7
|
-
import { runCommandLine } from "@node-minify/run";
|
|
8
|
-
import { utils } from "@node-minify/utils";
|
|
9
|
-
import compilerPath from "google-closure-compiler-java";
|
|
10
|
-
var require_src = __commonJS({
|
|
11
|
-
"src/index.ts"(exports, module) {
|
|
12
|
-
var allowedFlags = [
|
|
13
|
-
"angular_pass",
|
|
14
|
-
"assume_function_wrapper",
|
|
15
|
-
"checks_only",
|
|
16
|
-
"compilation_level",
|
|
17
|
-
"create_source_map",
|
|
18
|
-
"define",
|
|
19
|
-
"env",
|
|
20
|
-
"externs",
|
|
21
|
-
"export_local_property_definitions",
|
|
22
|
-
"generate_exports",
|
|
23
|
-
"language_in",
|
|
24
|
-
"language_out",
|
|
25
|
-
"output_wrapper",
|
|
26
|
-
"polymer_version",
|
|
27
|
-
"process_common_js_modules",
|
|
28
|
-
"rename_prefix_namespace",
|
|
29
|
-
"rewrite_polyfills",
|
|
30
|
-
"use_types_for_optimization",
|
|
31
|
-
"warning_level"
|
|
32
|
-
];
|
|
33
|
-
var minifyGCC = ({ settings, content, callback, index }) => {
|
|
34
|
-
const options = applyOptions({}, settings?.options ?? {});
|
|
35
|
-
return runCommandLine({
|
|
36
|
-
args: gccCommand(options),
|
|
37
|
-
data: content,
|
|
38
|
-
settings,
|
|
39
|
-
callback: (err, content2) => {
|
|
40
|
-
if (err) {
|
|
41
|
-
if (callback) {
|
|
42
|
-
return callback(err);
|
|
43
|
-
}
|
|
44
|
-
throw err;
|
|
45
|
-
}
|
|
46
|
-
if (settings && !settings.content && settings.output) {
|
|
47
|
-
utils.writeFile({ file: settings.output, content: content2, index });
|
|
48
|
-
}
|
|
49
|
-
if (callback) {
|
|
50
|
-
return callback(null, content2);
|
|
51
|
-
}
|
|
52
|
-
return content2;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
var applyOptions = (flags, options) => {
|
|
57
|
-
if (!options || Object.keys(options).length === 0) {
|
|
58
|
-
return flags;
|
|
59
|
-
}
|
|
60
|
-
Object.keys(options).filter((option) => allowedFlags.indexOf(option) > -1).forEach((option) => {
|
|
61
|
-
const value = options[option];
|
|
62
|
-
if (typeof value === "boolean" || typeof value === "object" && !Array.isArray(value)) {
|
|
63
|
-
flags[option] = value;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return flags;
|
|
67
|
-
};
|
|
68
|
-
var gccCommand = (options) => {
|
|
69
|
-
return ["-jar", compilerPath].concat(utils.buildArgs(options ?? {}));
|
|
70
|
-
};
|
|
71
|
-
minifyGCC.default = minifyGCC;
|
|
72
|
-
module.exports = minifyGCC;
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
export default require_src();
|
|
76
|
-
/*!
|
|
77
|
-
* node-minify
|
|
78
|
-
* Copyright(c) 2011-2024 Rodolphe Stoclin
|
|
79
|
-
* MIT Licensed
|
|
80
|
-
*/
|
|
81
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2024 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport { runCommandLine } from \"@node-minify/run\";\nimport type {\n MinifierOptions,\n Options,\n OptionsPossible,\n} from \"@node-minify/types\";\nimport { utils } from \"@node-minify/utils\";\nimport compilerPath from \"google-closure-compiler-java\";\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 * @param settings GCC options\n * @param content Content to minify\n * @param callback Callback\n * @param index Index of current file in array\n * @returns Minified content\n */\nconst minifyGCC = ({ settings, content, callback, index }: MinifierOptions) => {\n const options = applyOptions({}, settings?.options ?? {});\n return runCommandLine({\n args: gccCommand(options),\n data: content,\n settings,\n callback: (err: unknown, content?: string) => {\n if (err) {\n if (callback) {\n return callback(err);\n }\n throw err;\n }\n if (settings && !settings.content && settings.output) {\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/**\n * Adds any valid options passed in the options parameters to the flags parameter and returns the flags object.\n * @param flags the flags object to add options to\n * @param options the options object to add to the flags object\n * @returns the flags object with the options added\n */\ntype Flags = {\n [key: string]: boolean | Record<string, OptionsPossible>;\n};\nconst applyOptions = (flags: Flags, options?: Options): Flags => {\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) => {\n const value = options[option];\n if (\n typeof value === \"boolean\" ||\n (typeof value === \"object\" && !Array.isArray(value))\n ) {\n flags[option] = value as\n | boolean\n | Record<string, OptionsPossible>;\n }\n });\n return flags;\n};\n\n/**\n * GCC command line.\n * @param options the options to pass to GCC\n * @returns the command line arguments to pass to GCC\n */\n\nconst gccCommand = (options: Record<string, OptionsPossible>) => {\n return [\"-jar\", compilerPath].concat(utils.buildArgs(options ?? {}));\n};\n\n/**\n * Expose `minifyGCC()`.\n */\nminifyGCC.default = minifyGCC;\nexport = minifyGCC;\n"],"mappings":";;;;;;AASA,SAAS,sBAAsB;AAM/B,SAAS,aAAa;AACtB,OAAO,kBAAkB;AAhBzB;AAAA;AAmBA,QAAM,eAAe;AAAA,MACjB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ;AAUA,QAAM,YAAY,CAAC,EAAE,UAAU,SAAS,UAAU,MAAM,MAAuB;AAC3E,YAAM,UAAU,aAAa,CAAC,GAAG,UAAU,WAAW,CAAC,CAAC;AACxD,aAAO,eAAe;AAAA,QAClB,MAAM,WAAW,OAAO;AAAA,QACxB,MAAM;AAAA,QACN;AAAA,QACA,UAAU,CAAC,KAAcA,aAAqB;AAC1C,cAAI,KAAK;AACL,gBAAI,UAAU;AACV,qBAAO,SAAS,GAAG;AAAA,YACvB;AACA,kBAAM;AAAA,UACV;AACA,cAAI,YAAY,CAAC,SAAS,WAAW,SAAS,QAAQ;AAClD,kBAAM,UAAU,EAAE,MAAM,SAAS,QAAQ,SAAAA,UAAS,MAAM,CAAC;AAAA,UAC7D;AACA,cAAI,UAAU;AACV,mBAAO,SAAS,MAAMA,QAAO;AAAA,UACjC;AACA,iBAAOA;AAAA,QACX;AAAA,MACJ,CAAC;AAAA,IACL;AAWA,QAAM,eAAe,CAAC,OAAc,YAA6B;AAC7D,UAAI,CAAC,WAAW,OAAO,KAAK,OAAO,EAAE,WAAW,GAAG;AAC/C,eAAO;AAAA,MACX;AACA,aAAO,KAAK,OAAO,EACd,OAAO,CAAC,WAAW,aAAa,QAAQ,MAAM,IAAI,EAAE,EACpD,QAAQ,CAAC,WAAW;AACjB,cAAM,QAAQ,QAAQ,MAAM;AAC5B,YACI,OAAO,UAAU,aAChB,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,GACpD;AACE,gBAAM,MAAM,IAAI;AAAA,QAGpB;AAAA,MACJ,CAAC;AACL,aAAO;AAAA,IACX;AAQA,QAAM,aAAa,CAAC,YAA6C;AAC7D,aAAO,CAAC,QAAQ,YAAY,EAAE,OAAO,MAAM,UAAU,WAAW,CAAC,CAAC,CAAC;AAAA,IACvE;AAKA,cAAU,UAAU;AACpB,qBAAS;AAAA;AAAA;","names":["content"]}
|