google-closure-compiler 20250412.0.0-nightly → 20250413.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/README.md +5 -30
- package/cli.js +3 -4
- package/externs/browser/decorators.js +276 -0
- package/externs/browser/deprecated.js +58 -0
- package/externs/browser/es6_proxy.js +143 -0
- package/externs/browser/fetchapi.js +449 -0
- package/externs/browser/fido.js +94 -0
- package/externs/browser/flash.js +226 -0
- package/externs/browser/gecko_css.js +126 -0
- package/externs/browser/gecko_dom.js +479 -0
- package/externs/browser/gecko_event.js +86 -0
- package/externs/browser/gecko_xml.js +73 -0
- package/externs/browser/google_legacy.js +31 -0
- package/externs/browser/html5.js +6647 -0
- package/externs/browser/ie_css.js +270 -0
- package/externs/browser/ie_dom.js +1232 -0
- package/externs/browser/ie_event.js +310 -0
- package/externs/browser/ie_vml.js +77 -0
- package/externs/browser/intersection_observer.js +178 -0
- package/externs/browser/intl.js +602 -0
- package/externs/browser/iphone.js +204 -0
- package/externs/browser/mediakeys.js +305 -0
- package/externs/browser/mediasource.js +155 -0
- package/externs/browser/nonstandard_anim_timing.js +97 -0
- package/externs/browser/nonstandard_audio.js +82 -0
- package/externs/browser/nonstandard_console.js +75 -0
- package/externs/browser/nonstandard_fileapi.js +1066 -0
- package/externs/browser/nonstandard_indexeddb.js +78 -0
- package/externs/browser/nonstandard_navigation_timing.js +38 -0
- package/externs/browser/nonstandard_selection.js +80 -0
- package/externs/browser/page_visibility.js +28 -0
- package/externs/browser/streamsapi.js +593 -0
- package/externs/browser/svg.js +10016 -0
- package/externs/browser/url.js +202 -0
- package/externs/browser/v8.js +134 -0
- package/externs/browser/w3c_abort.js +89 -0
- package/externs/browser/w3c_anim_timing.js +49 -0
- package/externs/browser/w3c_aria_mixin.js +286 -0
- package/externs/browser/w3c_audio.js +1660 -0
- package/externs/browser/w3c_batterystatus.js +85 -0
- package/externs/browser/w3c_clipboard.js +74 -0
- package/externs/browser/w3c_clipboardevent.js +47 -0
- package/externs/browser/w3c_composition_event.js +93 -0
- package/externs/browser/w3c_css.js +3790 -0
- package/externs/browser/w3c_css3d.js +199 -0
- package/externs/browser/w3c_device_sensor_event.js +122 -0
- package/externs/browser/w3c_dom1.js +1160 -0
- package/externs/browser/w3c_dom2.js +3151 -0
- package/externs/browser/w3c_dom3.js +555 -0
- package/externs/browser/w3c_dom4.js +289 -0
- package/externs/browser/w3c_elementtraversal.js +116 -0
- package/externs/browser/w3c_event.js +607 -0
- package/externs/browser/w3c_event3.js +77 -0
- package/externs/browser/w3c_eventsource.js +110 -0
- package/externs/browser/w3c_fileapi.js +302 -0
- package/externs/browser/w3c_gamepad.js +113 -0
- package/externs/browser/w3c_geolocation.js +130 -0
- package/externs/browser/w3c_geometry1.js +899 -0
- package/externs/browser/w3c_indexeddb.js +771 -0
- package/externs/browser/w3c_keyboardlock.js +47 -0
- package/externs/browser/w3c_mediacapabilities.js +206 -0
- package/externs/browser/w3c_midi.js +301 -0
- package/externs/browser/w3c_navigation.js +72 -0
- package/externs/browser/w3c_navigation_timing.js +437 -0
- package/externs/browser/w3c_netinfo.js +85 -0
- package/externs/browser/w3c_payment_request.js +401 -0
- package/externs/browser/w3c_permissions.js +112 -0
- package/externs/browser/w3c_permissions_policy.js +78 -0
- package/externs/browser/w3c_pointer_events.js +163 -0
- package/externs/browser/w3c_pointerlock.js +63 -0
- package/externs/browser/w3c_range.js +284 -0
- package/externs/browser/w3c_referrer_policy.js +36 -0
- package/externs/browser/w3c_requestidlecallback.js +76 -0
- package/externs/browser/w3c_rtc.js +3882 -0
- package/externs/browser/w3c_screen_orientation.js +53 -0
- package/externs/browser/w3c_screen_wake_lock.js +58 -0
- package/externs/browser/w3c_selection.js +209 -0
- package/externs/browser/w3c_selectors.js +113 -0
- package/externs/browser/w3c_serviceworker.js +739 -0
- package/externs/browser/w3c_speech.js +426 -0
- package/externs/browser/w3c_touch_event.js +296 -0
- package/externs/browser/w3c_trusted_types.js +142 -0
- package/externs/browser/w3c_vibration.js +38 -0
- package/externs/browser/w3c_webcodecs.js +1473 -0
- package/externs/browser/w3c_webcrypto.js +839 -0
- package/externs/browser/w3c_worklets.js +54 -0
- package/externs/browser/w3c_xml.js +533 -0
- package/externs/browser/web_animations.js +452 -0
- package/externs/browser/web_app_manifest.js +50 -0
- package/externs/browser/webassembly.js +223 -0
- package/externs/browser/webgl.js +3409 -0
- package/externs/browser/webgl2.js +2727 -0
- package/externs/browser/webgl2_compute.js +1609 -0
- package/externs/browser/webkit_css.js +456 -0
- package/externs/browser/webkit_dom.js +118 -0
- package/externs/browser/webkit_event.js +46 -0
- package/externs/browser/webkit_notifications.js +258 -0
- package/externs/browser/webkit_usercontent.js +55 -0
- package/externs/browser/weblocksapi.js +125 -0
- package/externs/browser/webstorage.js +171 -0
- package/externs/browser/whatwg_bitmap_context.js +37 -0
- package/externs/browser/whatwg_console.js +152 -0
- package/externs/browser/whatwg_encoding.js +99 -0
- package/externs/browser/whatwg_file_system.js +296 -0
- package/externs/browser/wicg_attribution_reporting.js +42 -0
- package/externs/browser/wicg_compression_stream.js +60 -0
- package/externs/browser/wicg_constructable_stylesheets.js +60 -0
- package/externs/browser/wicg_entries.js +169 -0
- package/externs/browser/wicg_file_handling.js +41 -0
- package/externs/browser/wicg_file_system_access.js +191 -0
- package/externs/browser/wicg_floc.js +41 -0
- package/externs/browser/wicg_ink.js +89 -0
- package/externs/browser/wicg_resizeobserver.js +100 -0
- package/externs/browser/wicg_scheduler.js +62 -0
- package/externs/browser/wicg_trust_token.js +89 -0
- package/externs/browser/wicg_uach.js +100 -0
- package/externs/browser/window.js +190 -0
- package/externs/es3.js +2716 -0
- package/externs/es5.js +284 -0
- package/externs/es6.js +2554 -0
- package/externs/es6_collections.js +323 -0
- package/index.js +13 -16
- package/lib/grunt/index.js +71 -92
- package/lib/grunt/vinyl-stream.js +12 -18
- package/lib/gulp/concat-to-json.js +30 -18
- package/lib/gulp/index.js +174 -181
- package/lib/gulp/json-to-vinyl.js +8 -8
- package/lib/node/{closure-compiler.js → index.js} +27 -51
- package/lib/utils.js +16 -14
- package/package.json +19 -16
- package/lib/logger.js +0 -89
|
@@ -21,30 +21,42 @@
|
|
|
21
21
|
* @author Chad Killingsworth (chadkillingsworth@gmail.com)
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
import path from 'node:path';
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} src
|
|
28
|
+
* @param {string=} path
|
|
29
|
+
* @param {string=} sourceMap
|
|
30
|
+
* @return {{
|
|
31
|
+
* src: string,
|
|
32
|
+
* path: string|undefined,
|
|
33
|
+
* sourceMap: string|undefined,
|
|
34
|
+
* }}
|
|
35
|
+
*/
|
|
36
|
+
const json_file = (src, path, sourceMap) => {
|
|
37
|
+
return {
|
|
38
|
+
src: src,
|
|
39
|
+
...(path !== undefined ? {path} : undefined),
|
|
40
|
+
...(sourceMap !== undefined ? {sourceMap} : undefined),
|
|
29
41
|
};
|
|
30
|
-
|
|
31
|
-
if (path) {
|
|
32
|
-
filejson.path = path;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (source_map) {
|
|
36
|
-
filejson.sourceMap = source_map;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return filejson;
|
|
40
|
-
}
|
|
42
|
+
};
|
|
41
43
|
|
|
42
44
|
/**
|
|
43
|
-
* @param {Array
|
|
45
|
+
* @param {!Array<!{
|
|
46
|
+
* src: string,
|
|
47
|
+
* path: string|undefined,
|
|
48
|
+
* sourceMap: string|undefined,
|
|
49
|
+
* }>} files
|
|
44
50
|
* @return {string}
|
|
45
51
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
export default (files) => {
|
|
53
|
+
/**
|
|
54
|
+
* @type {!Array<!{
|
|
55
|
+
* src: string,
|
|
56
|
+
* path: string|undefined,
|
|
57
|
+
* sourceMap: string|undefined,
|
|
58
|
+
* }>}
|
|
59
|
+
*/
|
|
48
60
|
const jsonFiles = [];
|
|
49
61
|
for (let i = 0; i < files.length; i++) {
|
|
50
62
|
jsonFiles.push(
|
package/lib/gulp/index.js
CHANGED
|
@@ -26,7 +26,26 @@
|
|
|
26
26
|
* @author Chad Killingsworth (chadkillingsworth@gmail.com)
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
import stream from 'node:stream';
|
|
30
|
+
import {createRequire} from 'node:module';
|
|
31
|
+
import chalk from 'chalk';
|
|
32
|
+
import File from 'vinyl';
|
|
33
|
+
import applySourceMap from 'vinyl-sourcemaps-apply';
|
|
34
|
+
|
|
35
|
+
import filesToJson from './concat-to-json.js';
|
|
36
|
+
import jsonToVinyl from './json-to-vinyl.js';
|
|
37
|
+
import Compiler from '../node/index.js';
|
|
38
|
+
import {getNativeImagePath, getFirstSupportedPlatform} from '../utils.js';
|
|
39
|
+
|
|
40
|
+
const require = createRequire(import.meta.url);
|
|
41
|
+
const PLUGIN_NAME = 'gulp-google-closure-compiler';
|
|
42
|
+
|
|
43
|
+
let gulpLog;
|
|
44
|
+
try {
|
|
45
|
+
gulpLog = require('gulp-util').log;
|
|
46
|
+
} catch(e) {
|
|
47
|
+
gulpLog = console;
|
|
48
|
+
}
|
|
30
49
|
|
|
31
50
|
/**
|
|
32
51
|
* Rethrow an error with a custom message.
|
|
@@ -35,221 +54,195 @@
|
|
|
35
54
|
class CustomError extends Error {
|
|
36
55
|
constructor(plugin, message) {
|
|
37
56
|
if (message instanceof Error) {
|
|
38
|
-
super(`Error in ${plugin}
|
|
39
|
-
this.original = message;
|
|
40
|
-
// Compose both the current stack and the original stack
|
|
41
|
-
this.stack = `${this.stack.split('\n').slice(0,2).join('\n')}\n${message.stack}`;
|
|
57
|
+
super(`Error in ${plugin}`, {cause: message});
|
|
42
58
|
} else {
|
|
43
59
|
super(`${plugin}: ${message}`);
|
|
44
60
|
}
|
|
45
61
|
}
|
|
46
62
|
}
|
|
47
63
|
|
|
48
|
-
|
|
49
|
-
* @param {Object<string,string>} initOptions
|
|
50
|
-
* @return {function(Object<string,string>|Array<string>):Object}
|
|
51
|
-
*/
|
|
52
|
-
module.exports = function(initOptions) {
|
|
53
|
-
const filesToJson = require('./concat-to-json');
|
|
54
|
-
const jsonToVinyl = require('./json-to-vinyl');
|
|
55
|
-
const stream = require('stream');
|
|
56
|
-
const {getNativeImagePath, getFirstSupportedPlatform} = require('../utils');
|
|
57
|
-
/** @const */
|
|
58
|
-
const PLUGIN_NAME = 'gulp-google-closure-compiler';
|
|
59
|
-
|
|
60
|
-
const applySourceMap = require('vinyl-sourcemaps-apply');
|
|
61
|
-
const chalk = require('chalk');
|
|
62
|
-
const File = require('vinyl');
|
|
63
|
-
|
|
64
|
-
const extraCommandArguments = initOptions ? initOptions.extraArguments : undefined;
|
|
65
|
-
|
|
66
|
-
let PluginError;
|
|
64
|
+
const PluginError = (() => {
|
|
67
65
|
try {
|
|
68
|
-
|
|
69
|
-
} catch
|
|
70
|
-
|
|
66
|
+
return require('gulp-util').PluginError;
|
|
67
|
+
} catch {
|
|
68
|
+
return CustomError;
|
|
71
69
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
})();
|
|
71
|
+
|
|
72
|
+
class CompilationStream extends stream.Transform {
|
|
73
|
+
constructor(compilationOptions, pluginOptions = {}) {
|
|
74
|
+
super({objectMode: true});
|
|
75
|
+
this.compilationOptions_ = compilationOptions;
|
|
76
|
+
this.streamMode_ = pluginOptions.streamMode || 'BOTH';
|
|
77
|
+
this.logger_ = pluginOptions.logger || gulpLog;
|
|
78
|
+
this.PLUGIN_NAME_ = pluginOptions.pluginName || PLUGIN_NAME;
|
|
79
|
+
this.extraCommandArgs_ = pluginOptions.extraCommandArguments || [];
|
|
80
|
+
|
|
81
|
+
this.fileList_ = [];
|
|
82
|
+
this._streamInputRequired = pluginOptions.requireStreamInput !== false;
|
|
83
|
+
|
|
84
|
+
let platforms = (pluginOptions && pluginOptions.platform) || ['native', 'java'];
|
|
85
|
+
if (!Array.isArray(platforms)) {
|
|
86
|
+
platforms = [platforms];
|
|
87
|
+
}
|
|
88
|
+
this.platform = getFirstSupportedPlatform(platforms);
|
|
78
89
|
}
|
|
79
90
|
|
|
80
|
-
|
|
81
|
-
|
|
91
|
+
src() {
|
|
92
|
+
this._streamInputRequired = false;
|
|
93
|
+
process.nextTick(() => {
|
|
94
|
+
const stdInStream = new stream.Readable({ read: function() {
|
|
95
|
+
return new File();
|
|
96
|
+
}});
|
|
97
|
+
stdInStream.pipe(this);
|
|
98
|
+
stdInStream.push(null);
|
|
99
|
+
});
|
|
100
|
+
return this;
|
|
82
101
|
}
|
|
83
102
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this.compilationOptions_ = compilationOptions;
|
|
90
|
-
this.streamMode_ = pluginOptions.streamMode || 'BOTH';
|
|
91
|
-
this.logger_ = pluginOptions.logger || gulpLog;
|
|
92
|
-
this.PLUGIN_NAME_ = pluginOptions.pluginName || PLUGIN_NAME;
|
|
93
|
-
|
|
94
|
-
this.fileList_ = [];
|
|
95
|
-
this._streamInputRequired = pluginOptions.requireStreamInput !== false;
|
|
96
|
-
|
|
97
|
-
let platforms = (pluginOptions && pluginOptions.platform) || ['native', 'java'];
|
|
98
|
-
if (!Array.isArray(platforms)) {
|
|
99
|
-
platforms = [platforms];
|
|
100
|
-
}
|
|
101
|
-
this.platform = getFirstSupportedPlatform(platforms);
|
|
103
|
+
_transform(file, enc, cb) {
|
|
104
|
+
// ignore empty files
|
|
105
|
+
if (!file || file.isNull()) {
|
|
106
|
+
cb();
|
|
107
|
+
return;
|
|
102
108
|
}
|
|
103
109
|
|
|
104
|
-
|
|
105
|
-
this.
|
|
106
|
-
|
|
107
|
-
const stdInStream = new stream.Readable({ read: function() {
|
|
108
|
-
return new File();
|
|
109
|
-
}});
|
|
110
|
-
stdInStream.pipe(this);
|
|
111
|
-
stdInStream.push(null);
|
|
112
|
-
});
|
|
113
|
-
return this;
|
|
110
|
+
if (file.isStream()) {
|
|
111
|
+
cb(new PluginError(this.PLUGIN_NAME_, 'Streaming not supported'));
|
|
112
|
+
return;
|
|
114
113
|
}
|
|
115
114
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
cb();
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
115
|
+
this.fileList_.push(file);
|
|
116
|
+
cb();
|
|
117
|
+
}
|
|
122
118
|
|
|
123
|
-
|
|
124
|
-
|
|
119
|
+
async _flush(cb) {
|
|
120
|
+
let jsonFiles;
|
|
121
|
+
if (this.fileList_.length > 0) {
|
|
122
|
+
// Input files are present. Convert them to a JSON encoded string
|
|
123
|
+
jsonFiles = filesToJson(this.fileList_);
|
|
124
|
+
} else {
|
|
125
|
+
// If files in the stream were required, no compilation needed here.
|
|
126
|
+
if (this._streamInputRequired) {
|
|
127
|
+
this.push(null);
|
|
125
128
|
cb();
|
|
126
129
|
return;
|
|
127
130
|
}
|
|
128
131
|
|
|
129
|
-
|
|
130
|
-
|
|
132
|
+
// The compiler will always expect something on standard-in. So pass it an empty
|
|
133
|
+
// list if no files were piped into this plugin.
|
|
134
|
+
jsonFiles = [];
|
|
131
135
|
}
|
|
136
|
+
const compiler = new Compiler(this.compilationOptions_, this.extraCommandArgs_);
|
|
137
|
+
if (this.platform === 'native') {
|
|
138
|
+
compiler.JAR_PATH = null;
|
|
139
|
+
compiler.javaPath = getNativeImagePath();
|
|
140
|
+
}
|
|
141
|
+
let stdOutData = '';
|
|
142
|
+
let stdErrData = '';
|
|
143
|
+
|
|
144
|
+
// Add the gulp-specific argument so the compiler will understand the JSON encoded input
|
|
145
|
+
// for gulp, the stream mode will be 'BOTH', but when invoked from grunt, we only use
|
|
146
|
+
// a stream mode of 'IN'
|
|
147
|
+
compiler.commandArguments.push('--json_streams', this.streamMode_);
|
|
148
|
+
const compilerProcess = compiler.run();
|
|
149
|
+
|
|
150
|
+
compilerProcess.stdout.on('data', (data) => {
|
|
151
|
+
stdOutData += data;
|
|
152
|
+
});
|
|
153
|
+
compilerProcess.stderr.on('data', (data) => {
|
|
154
|
+
stdErrData += data;
|
|
155
|
+
});
|
|
156
|
+
// Error events occur when there was a problem spawning the compiler process
|
|
157
|
+
compilerProcess.on('error', async (err) => {
|
|
158
|
+
this.emit('error', new PluginError(this.PLUGIN_NAME_,
|
|
159
|
+
`Process spawn error. Is java in the path?\n${err.message}`));
|
|
160
|
+
cb();
|
|
161
|
+
});
|
|
162
|
+
compilerProcess.stdin.on('error', (err) => {
|
|
163
|
+
stdErrData += `Error writing to stdin of the compiler. ${err.message}`;
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const compileExecComplete = Promise.all([
|
|
167
|
+
new Promise((resolve) => compilerProcess.on('close', resolve)),
|
|
168
|
+
new Promise((resolve) => compilerProcess.stdout.on('end', resolve)),
|
|
169
|
+
new Promise((resolve) => compilerProcess.stderr.on('end', resolve))
|
|
170
|
+
]);
|
|
171
|
+
|
|
172
|
+
const stdInStream = new stream.Readable({ read: function() {}});
|
|
173
|
+
stdInStream.pipe(compilerProcess.stdin);
|
|
174
|
+
await new Promise((resolve) => {
|
|
175
|
+
process.nextTick(() => {
|
|
176
|
+
stdInStream.push(JSON.stringify(jsonFiles));
|
|
177
|
+
stdInStream.push(null);
|
|
178
|
+
resolve();
|
|
179
|
+
});
|
|
180
|
+
});
|
|
132
181
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
this.
|
|
182
|
+
try {
|
|
183
|
+
const [code] = await compileExecComplete;
|
|
184
|
+
|
|
185
|
+
// If present, standard output will be a string of JSON encoded files.
|
|
186
|
+
// Convert these back to vinyl
|
|
187
|
+
let outputFiles = [];
|
|
188
|
+
if (stdOutData.trim().length > 0) {
|
|
189
|
+
if (code !== 0) {
|
|
190
|
+
this.emit('error', new PluginError(this.PLUGIN_NAME_, `Compiler error.\n${stdOutData}\n${stdErrData}`));
|
|
142
191
|
cb();
|
|
143
192
|
return;
|
|
144
193
|
}
|
|
145
194
|
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
compiler.JAR_PATH = null;
|
|
154
|
-
compiler.javaPath = getNativeImagePath();
|
|
155
|
-
}
|
|
156
|
-
let stdOutData = '';
|
|
157
|
-
let stdErrData = '';
|
|
158
|
-
|
|
159
|
-
// Add the gulp-specific argument so the compiler will understand the JSON encoded input
|
|
160
|
-
// for gulp, the stream mode will be 'BOTH', but when invoked from grunt, we only use
|
|
161
|
-
// a stream mode of 'IN'
|
|
162
|
-
compiler.commandArguments.push('--json_streams', this.streamMode_);
|
|
163
|
-
const compilerProcess = compiler.run();
|
|
164
|
-
|
|
165
|
-
compilerProcess.stdout.on('data', data => {
|
|
166
|
-
stdOutData += data;
|
|
167
|
-
});
|
|
168
|
-
compilerProcess.stderr.on('data', data => {
|
|
169
|
-
stdErrData += data;
|
|
170
|
-
});
|
|
171
|
-
// Error events occur when there was a problem spawning the compiler process
|
|
172
|
-
compilerProcess.on('error', err => {
|
|
173
|
-
this.emit('error', new PluginError(this.PLUGIN_NAME_,
|
|
174
|
-
'Process spawn error. Is java in the path?\n' + err.message));
|
|
175
|
-
cb();
|
|
176
|
-
});
|
|
177
|
-
compilerProcess.stdin.on('error', err => {
|
|
178
|
-
stdErrData += `Error writing to stdin of the compiler. ${err.message}`;
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
Promise.all([
|
|
182
|
-
new Promise(resolve => compilerProcess.on('close', resolve)),
|
|
183
|
-
new Promise(resolve => compilerProcess.stdout.on('end', resolve)),
|
|
184
|
-
new Promise(resolve => compilerProcess.stderr.on('end', resolve))
|
|
185
|
-
]).then(results => {
|
|
186
|
-
const code = results[0];
|
|
187
|
-
|
|
188
|
-
// If present, standard output will be a string of JSON encoded files.
|
|
189
|
-
// Convert these back to vinyl
|
|
190
|
-
let outputFiles = [];
|
|
191
|
-
if (stdOutData.trim().length > 0) {
|
|
192
|
-
if (code !== 0) {
|
|
193
|
-
this.emit('error', new PluginError(this.PLUGIN_NAME_, 'Compiler error.\n' + stdOutData + '\n' + stdErrData));
|
|
194
|
-
cb();
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// stdOutData = stdOutData.substr(stdOutData.indexOf('{'));
|
|
199
|
-
try {
|
|
200
|
-
outputFiles = JSON.parse(stdOutData);
|
|
201
|
-
} catch (e) {
|
|
202
|
-
this.emit('error', new PluginError(this.PLUGIN_NAME_, 'Error parsing json encoded files'));
|
|
203
|
-
cb();
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
195
|
+
// stdOutData = stdOutData.substr(stdOutData.indexOf('{'));
|
|
196
|
+
try {
|
|
197
|
+
outputFiles = JSON.parse(stdOutData);
|
|
198
|
+
} catch (e) {
|
|
199
|
+
this.emit('error', new PluginError(this.PLUGIN_NAME_, 'Error parsing json encoded files'));
|
|
200
|
+
cb();
|
|
201
|
+
return;
|
|
206
202
|
}
|
|
203
|
+
}
|
|
207
204
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
const stdInStream = new stream.Readable({ read: function() {}});
|
|
216
|
-
stdInStream.pipe(compilerProcess.stdin);
|
|
217
|
-
process.nextTick(() => {
|
|
218
|
-
stdInStream.push(JSON.stringify(jsonFiles));
|
|
219
|
-
stdInStream.push(null);
|
|
220
|
-
});
|
|
205
|
+
this._compilationComplete(code, outputFiles, stdErrData);
|
|
206
|
+
cb();
|
|
207
|
+
} catch (err) {
|
|
208
|
+
this.emit('error', new PluginError(this.PLUGIN_NAME_, err, { showStack: true }));
|
|
209
|
+
cb();
|
|
221
210
|
}
|
|
211
|
+
}
|
|
222
212
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
213
|
+
/**
|
|
214
|
+
* @param {number} exitCode
|
|
215
|
+
* @param {string} compiledJs
|
|
216
|
+
* @param {string} errors
|
|
217
|
+
* @private
|
|
218
|
+
*/
|
|
219
|
+
_compilationComplete(exitCode, compiledJs, errors) {
|
|
220
|
+
// standard error will contain compilation warnings, log those
|
|
221
|
+
if (errors && errors.trim().length > 0) {
|
|
222
|
+
const logger = this.logger_.warn ? this.logger_.warn : this.logger_;
|
|
223
|
+
logger(`${chalk.yellow(this.PLUGIN_NAME_)}: ${errors}`);
|
|
224
|
+
}
|
|
235
225
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
226
|
+
// non-zero exit means a compilation error
|
|
227
|
+
if (exitCode !== 0) {
|
|
228
|
+
this.emit('error', new PluginError(this.PLUGIN_NAME_, 'Compilation errors occurred'));
|
|
229
|
+
}
|
|
240
230
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
231
|
+
// If present, standard output will be a string of JSON encoded files.
|
|
232
|
+
// Convert these back to vinyl
|
|
233
|
+
const outputFiles = jsonToVinyl(compiledJs);
|
|
244
234
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
this.push(outputFiles[i]);
|
|
235
|
+
for (let i = 0; i < outputFiles.length; i++) {
|
|
236
|
+
if (outputFiles[i].sourceMap) {
|
|
237
|
+
applySourceMap(outputFiles[i], outputFiles[i].sourceMap);
|
|
250
238
|
}
|
|
239
|
+
this.push(outputFiles[i]);
|
|
251
240
|
}
|
|
252
241
|
}
|
|
242
|
+
}
|
|
253
243
|
|
|
254
|
-
|
|
255
|
-
}
|
|
244
|
+
/**
|
|
245
|
+
* @param {Object<string,string>} initOptions
|
|
246
|
+
* @return {function(Object<string,string>|Array<string>):Object}
|
|
247
|
+
*/
|
|
248
|
+
export default (compilationOptions, pluginOptions) => new CompilationStream(compilationOptions, pluginOptions);
|
|
@@ -20,16 +20,17 @@
|
|
|
20
20
|
*
|
|
21
21
|
* @author Chad Killingsworth (chadkillingsworth@gmail.com)
|
|
22
22
|
*/
|
|
23
|
-
|
|
24
|
-
'use strict';
|
|
25
|
-
|
|
26
|
-
const File = require('vinyl');
|
|
23
|
+
import File from 'vinyl';
|
|
27
24
|
|
|
28
25
|
/**
|
|
29
|
-
* @param {
|
|
30
|
-
*
|
|
26
|
+
* @param {!Array<!{
|
|
27
|
+
* path: string,
|
|
28
|
+
* src: string,
|
|
29
|
+
* sourceMap: (string|undefined)
|
|
30
|
+
* }>} fileList array of file objects
|
|
31
|
+
* @return {!Array<!File>}
|
|
31
32
|
*/
|
|
32
|
-
|
|
33
|
+
export default (fileList) => {
|
|
33
34
|
let outputFiles = [];
|
|
34
35
|
for (let i = 0; i < fileList.length; i++) {
|
|
35
36
|
const file = new File({
|
|
@@ -44,4 +45,3 @@ module.exports = fileList => {
|
|
|
44
45
|
|
|
45
46
|
return outputFiles;
|
|
46
47
|
};
|
|
47
|
-
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
*
|
|
21
21
|
* @author Chad Killingsworth (chadkillingsworth@gmail.com)
|
|
22
22
|
*/
|
|
23
|
+
import {spawn} from 'node:child_process';
|
|
24
|
+
import compilerPath from 'google-closure-compiler-java';
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const path = require('path');
|
|
29
|
-
const contribPath = path.resolve(__dirname, '../../contrib');
|
|
26
|
+
/**
|
|
27
|
+
* @type {string}
|
|
28
|
+
*/
|
|
29
|
+
export const javaPath = 'java';
|
|
30
30
|
|
|
31
|
-
class Compiler {
|
|
31
|
+
export default class Compiler {
|
|
32
32
|
/**
|
|
33
33
|
* @param {Object<string,string>|Array<string>} args
|
|
34
34
|
* @param {Array<String>=} extraCommandArgs
|
|
@@ -36,13 +36,11 @@ class Compiler {
|
|
|
36
36
|
constructor(args, extraCommandArgs) {
|
|
37
37
|
this.commandArguments = [];
|
|
38
38
|
this.extraCommandArgs = extraCommandArgs;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.JAR_PATH = Compiler.JAR_PATH;
|
|
42
|
-
}
|
|
39
|
+
this.JAR_PATH = compilerPath;
|
|
40
|
+
this.javaPath = javaPath;
|
|
43
41
|
|
|
44
42
|
if (Array.isArray(args)) {
|
|
45
|
-
this.commandArguments
|
|
43
|
+
this.commandArguments.push(...args);
|
|
46
44
|
} else {
|
|
47
45
|
for (let key in args) {
|
|
48
46
|
if (Array.isArray(args[key])) {
|
|
@@ -56,15 +54,18 @@ class Compiler {
|
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
56
|
}
|
|
57
|
+
|
|
58
|
+
/** @type {function(...*)|null} */
|
|
59
|
+
this.logger = null;
|
|
60
|
+
|
|
61
|
+
/** @type {Object<string, string>} */
|
|
62
|
+
this.spawnOptions = undefined;
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
/**
|
|
62
|
-
* @param {function(number, string, string)=} callback
|
|
63
|
-
* @return {child_process.ChildProcess}
|
|
64
|
-
*/
|
|
65
|
+
/** @param {function(number, string, string)=} callback */
|
|
65
66
|
run(callback) {
|
|
66
67
|
if (this.JAR_PATH) {
|
|
67
|
-
this.commandArguments.unshift('-jar',
|
|
68
|
+
this.commandArguments.unshift('-jar', this.JAR_PATH);
|
|
68
69
|
if (this.extraCommandArgs) {
|
|
69
70
|
this.commandArguments.unshift(...this.extraCommandArgs);
|
|
70
71
|
}
|
|
@@ -80,22 +81,22 @@ class Compiler {
|
|
|
80
81
|
if (callback) {
|
|
81
82
|
if (compileProcess.stdout) {
|
|
82
83
|
compileProcess.stdout.setEncoding('utf8');
|
|
83
|
-
compileProcess.stdout.on('data', data => {
|
|
84
|
+
compileProcess.stdout.on('data', (data) => {
|
|
84
85
|
stdOutData += data;
|
|
85
86
|
});
|
|
86
|
-
compileProcess.stdout.on('error', err => {
|
|
87
|
+
compileProcess.stdout.on('error', (err) => {
|
|
87
88
|
stdErrData += err.toString();
|
|
88
89
|
});
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
if (compileProcess.stderr) {
|
|
92
93
|
compileProcess.stderr.setEncoding('utf8');
|
|
93
|
-
compileProcess.stderr.on('data', data => {
|
|
94
|
+
compileProcess.stderr.on('data', (data) => {
|
|
94
95
|
stdErrData += data;
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
compileProcess.on('close', code => {
|
|
99
|
+
compileProcess.on('close', (code) => {
|
|
99
100
|
if (code !== 0) {
|
|
100
101
|
stdErrData = this.prependFullCommand(stdErrData);
|
|
101
102
|
}
|
|
@@ -103,7 +104,7 @@ class Compiler {
|
|
|
103
104
|
callback(code, stdOutData, stdErrData);
|
|
104
105
|
});
|
|
105
106
|
|
|
106
|
-
compileProcess.on('error', err => {
|
|
107
|
+
compileProcess.on('error', (err) => {
|
|
107
108
|
callback(1, stdOutData,
|
|
108
109
|
this.prependFullCommand('Process spawn error. Is java in the path?\n' + err.message));
|
|
109
110
|
});
|
|
@@ -117,7 +118,7 @@ class Compiler {
|
|
|
117
118
|
* @return {string}
|
|
118
119
|
*/
|
|
119
120
|
getFullCommand() {
|
|
120
|
-
return this.javaPath
|
|
121
|
+
return `${this.javaPath} ${this.commandArguments.join(' ')}`;
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
/**
|
|
@@ -125,7 +126,7 @@ class Compiler {
|
|
|
125
126
|
* @return {string}
|
|
126
127
|
*/
|
|
127
128
|
prependFullCommand(msg) {
|
|
128
|
-
return this.getFullCommand()
|
|
129
|
+
return `${this.getFullCommand()}\n\n${msg}\n\n`;
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
/**
|
|
@@ -134,7 +135,7 @@ class Compiler {
|
|
|
134
135
|
* @return {string}
|
|
135
136
|
*/
|
|
136
137
|
formatArgument(key, val) {
|
|
137
|
-
let normalizedKey = key.replace(/[A-Z]/g, match => `_${match.toLowerCase()}`);
|
|
138
|
+
let normalizedKey = key.replace(/[A-Z]/g, (match) => `_${match.toLowerCase()}`);
|
|
138
139
|
normalizedKey = normalizedKey.replace(/^--/, '');
|
|
139
140
|
|
|
140
141
|
if (val === undefined || val === null) {
|
|
@@ -143,29 +144,4 @@ class Compiler {
|
|
|
143
144
|
|
|
144
145
|
return `--${normalizedKey}=${val}`;
|
|
145
146
|
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* @const
|
|
150
|
-
* @type {string}
|
|
151
|
-
*/
|
|
152
|
-
Compiler.JAR_PATH = compilerPath;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* @type {string}
|
|
156
|
-
*/
|
|
157
|
-
Compiler.prototype.javaPath = 'java';
|
|
158
|
-
|
|
159
|
-
/** @type {function(...*)|null} */
|
|
160
|
-
Compiler.prototype.logger = null;
|
|
161
|
-
|
|
162
|
-
/** @type {Object<string, string>} */
|
|
163
|
-
Compiler.prototype.spawnOptions = undefined;
|
|
164
|
-
|
|
165
|
-
/** @type {string} */
|
|
166
|
-
Compiler.COMPILER_PATH = compilerPath;
|
|
167
|
-
|
|
168
|
-
/** @type {string} */
|
|
169
|
-
Compiler.CONTRIB_PATH = contribPath;
|
|
170
|
-
|
|
171
|
-
module.exports = Compiler;
|
|
147
|
+
};
|