esbuild 0.11.14 → 0.11.18
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/install.js +2 -1
- package/lib/main.d.ts +14 -1
- package/lib/main.js +246 -146
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -20,7 +20,7 @@ const path = require("path");
|
|
|
20
20
|
const zlib = require("zlib");
|
|
21
21
|
const https = require("https");
|
|
22
22
|
const child_process = require("child_process");
|
|
23
|
-
const version = "0.11.
|
|
23
|
+
const version = "0.11.18";
|
|
24
24
|
const binPath = path.join(__dirname, "bin", "esbuild");
|
|
25
25
|
async function installBinaryFromPackage(name, fromPath, toPath) {
|
|
26
26
|
const cachePath = getCachePath(name);
|
|
@@ -235,6 +235,7 @@ const knownUnixlikePackages = {
|
|
|
235
235
|
"darwin x64 LE": "esbuild-darwin-64",
|
|
236
236
|
"freebsd arm64 LE": "esbuild-freebsd-arm64",
|
|
237
237
|
"freebsd x64 LE": "esbuild-freebsd-64",
|
|
238
|
+
"openbsd x64 LE": "esbuild-openbsd-64",
|
|
238
239
|
"linux arm LE": "esbuild-linux-arm",
|
|
239
240
|
"linux arm64 LE": "esbuild-linux-arm64",
|
|
240
241
|
"linux ia32 LE": "esbuild-linux-32",
|
package/lib/main.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export type Platform = 'browser' | 'node' | 'neutral';
|
|
2
2
|
export type Format = 'iife' | 'cjs' | 'esm';
|
|
3
3
|
export type Loader = 'js' | 'jsx' | 'ts' | 'tsx' | 'css' | 'json' | 'text' | 'base64' | 'file' | 'dataurl' | 'binary' | 'default';
|
|
4
|
-
export type LogLevel = 'debug' | 'info' | 'warning' | 'error' | 'silent';
|
|
4
|
+
export type LogLevel = 'verbose' | 'debug' | 'info' | 'warning' | 'error' | 'silent';
|
|
5
5
|
export type Charset = 'ascii' | 'utf8';
|
|
6
6
|
export type TreeShaking = true | 'ignore-annotations';
|
|
7
7
|
|
|
8
8
|
interface CommonOptions {
|
|
9
9
|
sourcemap?: boolean | 'inline' | 'external' | 'both';
|
|
10
|
+
legalComments?: 'none' | 'inline' | 'eof' | 'linked' | 'external';
|
|
10
11
|
sourceRoot?: string;
|
|
11
12
|
sourcesContent?: boolean;
|
|
12
13
|
|
|
@@ -78,6 +79,7 @@ export interface StdinOptions {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
export interface Message {
|
|
82
|
+
pluginName: string;
|
|
81
83
|
text: string;
|
|
82
84
|
location: Location | null;
|
|
83
85
|
notes: Note[];
|
|
@@ -118,6 +120,7 @@ export interface BuildIncremental extends BuildResult {
|
|
|
118
120
|
}
|
|
119
121
|
|
|
120
122
|
export interface BuildResult {
|
|
123
|
+
errors: Message[];
|
|
121
124
|
warnings: Message[];
|
|
122
125
|
outputFiles?: OutputFile[]; // Only when "write: false"
|
|
123
126
|
rebuild?: BuildInvalidate; // Only when "incremental: true"
|
|
@@ -186,12 +189,21 @@ export interface Plugin {
|
|
|
186
189
|
|
|
187
190
|
export interface PluginBuild {
|
|
188
191
|
initialOptions: BuildOptions;
|
|
192
|
+
onStart(callback: () =>
|
|
193
|
+
(OnStartResult | null | void | Promise<OnStartResult | null | void>)): void;
|
|
194
|
+
onEnd(callback: (result: BuildResult) =>
|
|
195
|
+
(void | Promise<void>)): void;
|
|
189
196
|
onResolve(options: OnResolveOptions, callback: (args: OnResolveArgs) =>
|
|
190
197
|
(OnResolveResult | null | undefined | Promise<OnResolveResult | null | undefined>)): void;
|
|
191
198
|
onLoad(options: OnLoadOptions, callback: (args: OnLoadArgs) =>
|
|
192
199
|
(OnLoadResult | null | undefined | Promise<OnLoadResult | null | undefined>)): void;
|
|
193
200
|
}
|
|
194
201
|
|
|
202
|
+
export interface OnStartResult {
|
|
203
|
+
errors?: PartialMessage[];
|
|
204
|
+
warnings?: PartialMessage[];
|
|
205
|
+
}
|
|
206
|
+
|
|
195
207
|
export interface OnResolveOptions {
|
|
196
208
|
filter: RegExp;
|
|
197
209
|
namespace?: string;
|
|
@@ -261,6 +273,7 @@ export interface OnLoadResult {
|
|
|
261
273
|
}
|
|
262
274
|
|
|
263
275
|
export interface PartialMessage {
|
|
276
|
+
pluginName?: string;
|
|
264
277
|
text?: string;
|
|
265
278
|
location?: Partial<Location> | null;
|
|
266
279
|
notes?: PartialNote[];
|
package/lib/main.js
CHANGED
|
@@ -259,6 +259,7 @@ function pushLogFlags(flags, options, keys, isTTY2, logLevelDefault) {
|
|
|
259
259
|
flags.push(`--log-limit=${logLimit || 0}`);
|
|
260
260
|
}
|
|
261
261
|
function pushCommonFlags(flags, options, keys) {
|
|
262
|
+
let legalComments = getFlag(options, keys, "legalComments", mustBeString);
|
|
262
263
|
let sourceRoot = getFlag(options, keys, "sourceRoot", mustBeString);
|
|
263
264
|
let sourcesContent = getFlag(options, keys, "sourcesContent", mustBeBoolean);
|
|
264
265
|
let target = getFlag(options, keys, "target", mustBeStringOrArray);
|
|
@@ -275,6 +276,8 @@ function pushCommonFlags(flags, options, keys) {
|
|
|
275
276
|
let define = getFlag(options, keys, "define", mustBeObject);
|
|
276
277
|
let pure = getFlag(options, keys, "pure", mustBeArray);
|
|
277
278
|
let keepNames = getFlag(options, keys, "keepNames", mustBeBoolean);
|
|
279
|
+
if (legalComments)
|
|
280
|
+
flags.push(`--legal-comments=${legalComments}`);
|
|
278
281
|
if (sourceRoot !== void 0)
|
|
279
282
|
flags.push(`--source-root=${sourceRoot}`);
|
|
280
283
|
if (sourcesContent !== void 0)
|
|
@@ -619,6 +622,14 @@ function createChannel(streamIn) {
|
|
|
619
622
|
sendResponse(id, {});
|
|
620
623
|
break;
|
|
621
624
|
}
|
|
625
|
+
case "start": {
|
|
626
|
+
let callback = pluginCallbacks.get(request.key);
|
|
627
|
+
if (!callback)
|
|
628
|
+
sendResponse(id, {});
|
|
629
|
+
else
|
|
630
|
+
sendResponse(id, await callback(request));
|
|
631
|
+
break;
|
|
632
|
+
}
|
|
622
633
|
case "resolve": {
|
|
623
634
|
let callback = pluginCallbacks.get(request.key);
|
|
624
635
|
if (!callback)
|
|
@@ -664,7 +675,7 @@ function createChannel(streamIn) {
|
|
|
664
675
|
throw new Error(`Invalid command: ` + request.command);
|
|
665
676
|
}
|
|
666
677
|
} catch (e) {
|
|
667
|
-
sendResponse(id, {errors: [extractErrorMessageV8(e, streamIn, null, void 0)]});
|
|
678
|
+
sendResponse(id, {errors: [extractErrorMessageV8(e, streamIn, null, void 0, "")]});
|
|
668
679
|
}
|
|
669
680
|
};
|
|
670
681
|
let isFirstPacket = true;
|
|
@@ -672,8 +683,8 @@ function createChannel(streamIn) {
|
|
|
672
683
|
if (isFirstPacket) {
|
|
673
684
|
isFirstPacket = false;
|
|
674
685
|
let binaryVersion = String.fromCharCode(...bytes);
|
|
675
|
-
if (binaryVersion !== "0.11.
|
|
676
|
-
throw new Error(`Cannot start service: Host version "${"0.11.
|
|
686
|
+
if (binaryVersion !== "0.11.18") {
|
|
687
|
+
throw new Error(`Cannot start service: Host version "${"0.11.18"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
|
|
677
688
|
}
|
|
678
689
|
return;
|
|
679
690
|
}
|
|
@@ -690,6 +701,8 @@ function createChannel(streamIn) {
|
|
|
690
701
|
}
|
|
691
702
|
};
|
|
692
703
|
let handlePlugins = async (initialOptions, plugins, buildKey, stash) => {
|
|
704
|
+
let onStartCallbacks = [];
|
|
705
|
+
let onEndCallbacks = [];
|
|
693
706
|
let onResolveCallbacks = {};
|
|
694
707
|
let onLoadCallbacks = {};
|
|
695
708
|
let nextCallbackID = 0;
|
|
@@ -701,55 +714,92 @@ function createChannel(streamIn) {
|
|
|
701
714
|
if (typeof item !== "object")
|
|
702
715
|
throw new Error(`Plugin at index ${i} must be an object`);
|
|
703
716
|
let name = getFlag(item, keys, "name", mustBeString);
|
|
704
|
-
let setup = getFlag(item, keys, "setup", mustBeFunction);
|
|
705
717
|
if (typeof name !== "string" || name === "")
|
|
706
718
|
throw new Error(`Plugin at index ${i} is missing a name`);
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
name
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
719
|
+
try {
|
|
720
|
+
let setup = getFlag(item, keys, "setup", mustBeFunction);
|
|
721
|
+
if (typeof setup !== "function")
|
|
722
|
+
throw new Error(`Plugin is missing a setup function`);
|
|
723
|
+
checkForInvalidFlags(item, keys, `on plugin ${JSON.stringify(name)}`);
|
|
724
|
+
let plugin = {
|
|
725
|
+
name,
|
|
726
|
+
onResolve: [],
|
|
727
|
+
onLoad: []
|
|
728
|
+
};
|
|
729
|
+
i++;
|
|
730
|
+
let promise = setup({
|
|
731
|
+
initialOptions,
|
|
732
|
+
onStart(callback2) {
|
|
733
|
+
let registeredText = `This error came from the "onStart" callback registered here`;
|
|
734
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onStart");
|
|
735
|
+
onStartCallbacks.push({name, callback: callback2, note: registeredNote});
|
|
736
|
+
},
|
|
737
|
+
onEnd(callback2) {
|
|
738
|
+
let registeredText = `This error came from the "onEnd" callback registered here`;
|
|
739
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onEnd");
|
|
740
|
+
onEndCallbacks.push({name, callback: callback2, note: registeredNote});
|
|
741
|
+
},
|
|
742
|
+
onResolve(options, callback2) {
|
|
743
|
+
let registeredText = `This error came from the "onResolve" callback registered here`;
|
|
744
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onResolve");
|
|
745
|
+
let keys2 = {};
|
|
746
|
+
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
|
747
|
+
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
748
|
+
checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${JSON.stringify(name)}`);
|
|
749
|
+
if (filter == null)
|
|
750
|
+
throw new Error(`onResolve() call is missing a filter`);
|
|
751
|
+
let id = nextCallbackID++;
|
|
752
|
+
onResolveCallbacks[id] = {name, callback: callback2, note: registeredNote};
|
|
753
|
+
plugin.onResolve.push({id, filter: filter.source, namespace: namespace || ""});
|
|
754
|
+
},
|
|
755
|
+
onLoad(options, callback2) {
|
|
756
|
+
let registeredText = `This error came from the "onLoad" callback registered here`;
|
|
757
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onLoad");
|
|
758
|
+
let keys2 = {};
|
|
759
|
+
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
|
760
|
+
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
761
|
+
checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${JSON.stringify(name)}`);
|
|
762
|
+
if (filter == null)
|
|
763
|
+
throw new Error(`onLoad() call is missing a filter`);
|
|
764
|
+
let id = nextCallbackID++;
|
|
765
|
+
onLoadCallbacks[id] = {name, callback: callback2, note: registeredNote};
|
|
766
|
+
plugin.onLoad.push({id, filter: filter.source, namespace: namespace || ""});
|
|
767
|
+
}
|
|
768
|
+
});
|
|
769
|
+
if (promise)
|
|
770
|
+
await promise;
|
|
771
|
+
requestPlugins.push(plugin);
|
|
772
|
+
} catch (e) {
|
|
773
|
+
return {ok: false, error: e, pluginName: name};
|
|
774
|
+
}
|
|
748
775
|
}
|
|
749
776
|
const callback = async (request) => {
|
|
750
777
|
switch (request.command) {
|
|
778
|
+
case "start": {
|
|
779
|
+
let response = {errors: [], warnings: []};
|
|
780
|
+
await Promise.all(onStartCallbacks.map(async ({name, callback: callback2, note}) => {
|
|
781
|
+
try {
|
|
782
|
+
let result = await callback2();
|
|
783
|
+
if (result != null) {
|
|
784
|
+
if (typeof result !== "object")
|
|
785
|
+
throw new Error(`Expected onStart() callback in plugin ${JSON.stringify(name)} to return an object`);
|
|
786
|
+
let keys = {};
|
|
787
|
+
let errors = getFlag(result, keys, "errors", mustBeArray);
|
|
788
|
+
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
789
|
+
checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${JSON.stringify(name)}`);
|
|
790
|
+
if (errors != null)
|
|
791
|
+
response.errors.push(...sanitizeMessages(errors, "errors", stash, name));
|
|
792
|
+
if (warnings != null)
|
|
793
|
+
response.warnings.push(...sanitizeMessages(warnings, "warnings", stash, name));
|
|
794
|
+
}
|
|
795
|
+
} catch (e) {
|
|
796
|
+
response.errors.push(extractErrorMessageV8(e, streamIn, stash, note && note(), name));
|
|
797
|
+
}
|
|
798
|
+
}));
|
|
799
|
+
return response;
|
|
800
|
+
}
|
|
751
801
|
case "resolve": {
|
|
752
|
-
let response = {}, name, callback2, note;
|
|
802
|
+
let response = {}, name = "", callback2, note;
|
|
753
803
|
for (let id of request.ids) {
|
|
754
804
|
try {
|
|
755
805
|
({name, callback: callback2, note} = onResolveCallbacks[id]);
|
|
@@ -787,9 +837,9 @@ function createChannel(streamIn) {
|
|
|
787
837
|
if (pluginData != null)
|
|
788
838
|
response.pluginData = stash.store(pluginData);
|
|
789
839
|
if (errors != null)
|
|
790
|
-
response.errors = sanitizeMessages(errors, "errors", stash);
|
|
840
|
+
response.errors = sanitizeMessages(errors, "errors", stash, name);
|
|
791
841
|
if (warnings != null)
|
|
792
|
-
response.warnings = sanitizeMessages(warnings, "warnings", stash);
|
|
842
|
+
response.warnings = sanitizeMessages(warnings, "warnings", stash, name);
|
|
793
843
|
if (watchFiles != null)
|
|
794
844
|
response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
|
795
845
|
if (watchDirs != null)
|
|
@@ -797,13 +847,13 @@ function createChannel(streamIn) {
|
|
|
797
847
|
break;
|
|
798
848
|
}
|
|
799
849
|
} catch (e) {
|
|
800
|
-
return {id, errors: [extractErrorMessageV8(e, streamIn, stash, note && note())]};
|
|
850
|
+
return {id, errors: [extractErrorMessageV8(e, streamIn, stash, note && note(), name)]};
|
|
801
851
|
}
|
|
802
852
|
}
|
|
803
853
|
return response;
|
|
804
854
|
}
|
|
805
855
|
case "load": {
|
|
806
|
-
let response = {}, name, callback2, note;
|
|
856
|
+
let response = {}, name = "", callback2, note;
|
|
807
857
|
for (let id of request.ids) {
|
|
808
858
|
try {
|
|
809
859
|
({name, callback: callback2, note} = onLoadCallbacks[id]);
|
|
@@ -840,9 +890,9 @@ function createChannel(streamIn) {
|
|
|
840
890
|
if (loader != null)
|
|
841
891
|
response.loader = loader;
|
|
842
892
|
if (errors != null)
|
|
843
|
-
response.errors = sanitizeMessages(errors, "errors", stash);
|
|
893
|
+
response.errors = sanitizeMessages(errors, "errors", stash, name);
|
|
844
894
|
if (warnings != null)
|
|
845
|
-
response.warnings = sanitizeMessages(warnings, "warnings", stash);
|
|
895
|
+
response.warnings = sanitizeMessages(warnings, "warnings", stash, name);
|
|
846
896
|
if (watchFiles != null)
|
|
847
897
|
response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
|
848
898
|
if (watchDirs != null)
|
|
@@ -850,7 +900,7 @@ function createChannel(streamIn) {
|
|
|
850
900
|
break;
|
|
851
901
|
}
|
|
852
902
|
} catch (e) {
|
|
853
|
-
return {id, errors: [extractErrorMessageV8(e, streamIn, stash, note && note())]};
|
|
903
|
+
return {id, errors: [extractErrorMessageV8(e, streamIn, stash, note && note(), name)]};
|
|
854
904
|
}
|
|
855
905
|
}
|
|
856
906
|
return response;
|
|
@@ -859,17 +909,36 @@ function createChannel(streamIn) {
|
|
|
859
909
|
throw new Error(`Invalid command: ` + request.command);
|
|
860
910
|
}
|
|
861
911
|
};
|
|
912
|
+
let runOnEndCallbacks = (result, done) => done();
|
|
913
|
+
if (onEndCallbacks.length > 0) {
|
|
914
|
+
runOnEndCallbacks = (result, done) => {
|
|
915
|
+
(async () => {
|
|
916
|
+
for (const {name, callback: callback2, note} of onEndCallbacks) {
|
|
917
|
+
try {
|
|
918
|
+
await callback2(result);
|
|
919
|
+
} catch (e) {
|
|
920
|
+
result.errors.push(extractErrorMessageV8(e, streamIn, stash, note && note(), name));
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
})().then(done);
|
|
924
|
+
};
|
|
925
|
+
}
|
|
862
926
|
let refCount = 0;
|
|
863
|
-
return
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
927
|
+
return {
|
|
928
|
+
ok: true,
|
|
929
|
+
requestPlugins,
|
|
930
|
+
runOnEndCallbacks,
|
|
931
|
+
pluginRefs: {
|
|
932
|
+
ref() {
|
|
933
|
+
if (++refCount === 1)
|
|
934
|
+
pluginCallbacks.set(buildKey, callback);
|
|
935
|
+
},
|
|
936
|
+
unref() {
|
|
937
|
+
if (--refCount === 0)
|
|
938
|
+
pluginCallbacks.delete(buildKey);
|
|
939
|
+
}
|
|
871
940
|
}
|
|
872
|
-
}
|
|
941
|
+
};
|
|
873
942
|
};
|
|
874
943
|
let buildServeData = (refs, options, request) => {
|
|
875
944
|
let keys = {};
|
|
@@ -923,13 +992,13 @@ function createChannel(streamIn) {
|
|
|
923
992
|
plugins = value;
|
|
924
993
|
}
|
|
925
994
|
}
|
|
926
|
-
let handleError = (e) => {
|
|
995
|
+
let handleError = (e, pluginName) => {
|
|
927
996
|
let flags = [];
|
|
928
997
|
try {
|
|
929
998
|
pushLogFlags(flags, options, {}, isTTY2, buildLogLevelDefault);
|
|
930
999
|
} catch (e2) {
|
|
931
1000
|
}
|
|
932
|
-
const error = extractErrorMessageV8(e, streamIn, details, void 0);
|
|
1001
|
+
const error = extractErrorMessageV8(e, streamIn, details, void 0, pluginName);
|
|
933
1002
|
sendRequest(refs, {command: "error", flags, error}, () => {
|
|
934
1003
|
error.detail = details.load(error.detail);
|
|
935
1004
|
callback(failureErrorWithLog("Build failed", [error], []), null);
|
|
@@ -937,23 +1006,35 @@ function createChannel(streamIn) {
|
|
|
937
1006
|
};
|
|
938
1007
|
if (plugins && plugins.length > 0) {
|
|
939
1008
|
if (streamIn.isSync)
|
|
940
|
-
return handleError(new Error("Cannot use plugins in synchronous API calls"));
|
|
941
|
-
handlePlugins(options, plugins, key, details).then((
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1009
|
+
return handleError(new Error("Cannot use plugins in synchronous API calls"), "");
|
|
1010
|
+
handlePlugins(options, plugins, key, details).then((result) => {
|
|
1011
|
+
if (!result.ok) {
|
|
1012
|
+
handleError(result.error, result.pluginName);
|
|
1013
|
+
} else {
|
|
1014
|
+
try {
|
|
1015
|
+
buildOrServeContinue(__objSpread(__objSpread({}, args), {
|
|
1016
|
+
key,
|
|
1017
|
+
details,
|
|
1018
|
+
requestPlugins: result.requestPlugins,
|
|
1019
|
+
runOnEndCallbacks: result.runOnEndCallbacks,
|
|
1020
|
+
pluginRefs: result.pluginRefs
|
|
1021
|
+
}));
|
|
1022
|
+
} catch (e) {
|
|
1023
|
+
handleError(e, "");
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
}, (e) => handleError(e, ""));
|
|
947
1027
|
} else {
|
|
948
1028
|
try {
|
|
949
1029
|
buildOrServeContinue(__objSpread(__objSpread({}, args), {
|
|
950
1030
|
key,
|
|
951
1031
|
details,
|
|
952
1032
|
requestPlugins: null,
|
|
1033
|
+
runOnEndCallbacks: (result, done) => done(),
|
|
953
1034
|
pluginRefs: null
|
|
954
1035
|
}));
|
|
955
1036
|
} catch (e) {
|
|
956
|
-
handleError(e);
|
|
1037
|
+
handleError(e, "");
|
|
957
1038
|
}
|
|
958
1039
|
}
|
|
959
1040
|
};
|
|
@@ -968,6 +1049,7 @@ function createChannel(streamIn) {
|
|
|
968
1049
|
key,
|
|
969
1050
|
details,
|
|
970
1051
|
requestPlugins,
|
|
1052
|
+
runOnEndCallbacks,
|
|
971
1053
|
pluginRefs
|
|
972
1054
|
}) => {
|
|
973
1055
|
const refs = {
|
|
@@ -1006,8 +1088,7 @@ function createChannel(streamIn) {
|
|
|
1006
1088
|
stdinResolveDir,
|
|
1007
1089
|
absWorkingDir: absWorkingDir || defaultWD2,
|
|
1008
1090
|
incremental,
|
|
1009
|
-
nodePaths
|
|
1010
|
-
hasOnRebuild: !!(watch && watch.onRebuild)
|
|
1091
|
+
nodePaths
|
|
1011
1092
|
};
|
|
1012
1093
|
if (requestPlugins)
|
|
1013
1094
|
request.plugins = requestPlugins;
|
|
@@ -1023,74 +1104,90 @@ function createChannel(streamIn) {
|
|
|
1023
1104
|
console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, ""));
|
|
1024
1105
|
};
|
|
1025
1106
|
let buildResponseToResult = (response, callback2) => {
|
|
1026
|
-
let
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
let result = {warnings};
|
|
1107
|
+
let result = {
|
|
1108
|
+
errors: replaceDetailsInMessages(response.errors, details),
|
|
1109
|
+
warnings: replaceDetailsInMessages(response.warnings, details)
|
|
1110
|
+
};
|
|
1031
1111
|
copyResponseToResult(response, result);
|
|
1032
|
-
|
|
1033
|
-
if (
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1112
|
+
runOnEndCallbacks(result, () => {
|
|
1113
|
+
if (result.errors.length > 0) {
|
|
1114
|
+
return callback2(failureErrorWithLog("Build failed", result.errors, result.warnings), null);
|
|
1115
|
+
}
|
|
1116
|
+
if (response.rebuildID !== void 0) {
|
|
1117
|
+
if (!rebuild) {
|
|
1118
|
+
let isDisposed = false;
|
|
1119
|
+
rebuild = () => new Promise((resolve, reject) => {
|
|
1120
|
+
if (isDisposed || isClosed)
|
|
1121
|
+
throw new Error("Cannot rebuild");
|
|
1122
|
+
sendRequest(refs, {command: "rebuild", rebuildID: response.rebuildID}, (error2, response2) => {
|
|
1123
|
+
if (error2) {
|
|
1124
|
+
const message = {pluginName: "", text: error2, location: null, notes: [], detail: void 0};
|
|
1125
|
+
return callback2(failureErrorWithLog("Build failed", [message], []), null);
|
|
1126
|
+
}
|
|
1127
|
+
buildResponseToResult(response2, (error3, result3) => {
|
|
1128
|
+
if (error3)
|
|
1129
|
+
reject(error3);
|
|
1130
|
+
else
|
|
1131
|
+
resolve(result3);
|
|
1132
|
+
});
|
|
1046
1133
|
});
|
|
1047
1134
|
});
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
}
|
|
1135
|
+
refs.ref();
|
|
1136
|
+
rebuild.dispose = () => {
|
|
1137
|
+
if (isDisposed)
|
|
1138
|
+
return;
|
|
1139
|
+
isDisposed = true;
|
|
1140
|
+
sendRequest(refs, {command: "rebuild-dispose", rebuildID: response.rebuildID}, () => {
|
|
1141
|
+
});
|
|
1142
|
+
refs.unref();
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
result.rebuild = rebuild;
|
|
1058
1146
|
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1147
|
+
if (response.watchID !== void 0) {
|
|
1148
|
+
if (!stop) {
|
|
1149
|
+
let isStopped = false;
|
|
1150
|
+
refs.ref();
|
|
1151
|
+
stop = () => {
|
|
1152
|
+
if (isStopped)
|
|
1153
|
+
return;
|
|
1154
|
+
isStopped = true;
|
|
1155
|
+
watchCallbacks.delete(response.watchID);
|
|
1156
|
+
sendRequest(refs, {command: "watch-stop", watchID: response.watchID}, () => {
|
|
1157
|
+
});
|
|
1158
|
+
refs.unref();
|
|
1159
|
+
};
|
|
1160
|
+
if (watch) {
|
|
1161
|
+
watchCallbacks.set(response.watchID, (serviceStopError, watchResponse) => {
|
|
1162
|
+
if (serviceStopError) {
|
|
1163
|
+
if (watch.onRebuild)
|
|
1164
|
+
watch.onRebuild(serviceStopError, null);
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
let result2 = {
|
|
1168
|
+
errors: replaceDetailsInMessages(watchResponse.errors, details),
|
|
1169
|
+
warnings: replaceDetailsInMessages(watchResponse.warnings, details)
|
|
1170
|
+
};
|
|
1171
|
+
copyResponseToResult(watchResponse, result2);
|
|
1172
|
+
runOnEndCallbacks(result2, () => {
|
|
1173
|
+
if (result2.errors.length > 0) {
|
|
1174
|
+
if (watch.onRebuild)
|
|
1175
|
+
watch.onRebuild(failureErrorWithLog("Build failed", result2.errors, result2.warnings), null);
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1178
|
+
if (watchResponse.rebuildID !== void 0)
|
|
1179
|
+
result2.rebuild = rebuild;
|
|
1180
|
+
result2.stop = stop;
|
|
1181
|
+
if (watch.onRebuild)
|
|
1182
|
+
watch.onRebuild(null, result2);
|
|
1183
|
+
});
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1089
1186
|
}
|
|
1187
|
+
result.stop = stop;
|
|
1090
1188
|
}
|
|
1091
|
-
result
|
|
1092
|
-
}
|
|
1093
|
-
return callback2(null, result);
|
|
1189
|
+
callback2(null, result);
|
|
1190
|
+
});
|
|
1094
1191
|
};
|
|
1095
1192
|
if (write && streamIn.isBrowser)
|
|
1096
1193
|
throw new Error(`Cannot enable "write" in the browser`);
|
|
@@ -1174,7 +1271,7 @@ function createChannel(streamIn) {
|
|
|
1174
1271
|
pushLogFlags(flags, options, {}, isTTY2, transformLogLevelDefault);
|
|
1175
1272
|
} catch (e2) {
|
|
1176
1273
|
}
|
|
1177
|
-
const error = extractErrorMessageV8(e, streamIn, details, void 0);
|
|
1274
|
+
const error = extractErrorMessageV8(e, streamIn, details, void 0, "");
|
|
1178
1275
|
sendRequest(refs, {command: "error", flags, error}, () => {
|
|
1179
1276
|
error.detail = details.load(error.detail);
|
|
1180
1277
|
callback(failureErrorWithLog("Transform failed", [error], []), null);
|
|
@@ -1188,7 +1285,7 @@ function createChannel(streamIn) {
|
|
|
1188
1285
|
start(null);
|
|
1189
1286
|
};
|
|
1190
1287
|
let formatMessages2 = ({callName, refs, messages, options, callback}) => {
|
|
1191
|
-
let result = sanitizeMessages(messages, "messages", null);
|
|
1288
|
+
let result = sanitizeMessages(messages, "messages", null, "");
|
|
1192
1289
|
if (!options)
|
|
1193
1290
|
throw new Error(`Missing second argument in ${callName}() call`);
|
|
1194
1291
|
let keys = {};
|
|
@@ -1260,7 +1357,7 @@ function extractCallerV8(e, streamIn, ident) {
|
|
|
1260
1357
|
}
|
|
1261
1358
|
};
|
|
1262
1359
|
}
|
|
1263
|
-
function extractErrorMessageV8(e, streamIn, stash, note) {
|
|
1360
|
+
function extractErrorMessageV8(e, streamIn, stash, note, pluginName) {
|
|
1264
1361
|
let text = "Internal error";
|
|
1265
1362
|
let location = null;
|
|
1266
1363
|
try {
|
|
@@ -1271,7 +1368,7 @@ function extractErrorMessageV8(e, streamIn, stash, note) {
|
|
|
1271
1368
|
location = parseStackLinesV8(streamIn, (e.stack + "").split("\n"), "");
|
|
1272
1369
|
} catch (e2) {
|
|
1273
1370
|
}
|
|
1274
|
-
return {text, location, notes: note ? [note] : [], detail: stash ? stash.store(e) : -1};
|
|
1371
|
+
return {pluginName, text, location, notes: note ? [note] : [], detail: stash ? stash.store(e) : -1};
|
|
1275
1372
|
}
|
|
1276
1373
|
function parseStackLinesV8(streamIn, lines, ident) {
|
|
1277
1374
|
let at = " at ";
|
|
@@ -1328,8 +1425,9 @@ function failureErrorWithLog(text, errors, warnings) {
|
|
|
1328
1425
|
return `
|
|
1329
1426
|
error: ${e.text}`;
|
|
1330
1427
|
let {file, line, column} = e.location;
|
|
1428
|
+
let pluginText = e.pluginName ? `[plugin: ${e.pluginName}] ` : "";
|
|
1331
1429
|
return `
|
|
1332
|
-
${file}:${line}:${column}: error: ${e.text}`;
|
|
1430
|
+
${file}:${line}:${column}: error: ${pluginText}${e.text}`;
|
|
1333
1431
|
}).join("");
|
|
1334
1432
|
let error = new Error(`${text}${summary}`);
|
|
1335
1433
|
error.errors = errors;
|
|
@@ -1364,11 +1462,12 @@ function sanitizeLocation(location, where) {
|
|
|
1364
1462
|
suggestion: suggestion || ""
|
|
1365
1463
|
};
|
|
1366
1464
|
}
|
|
1367
|
-
function sanitizeMessages(messages, property, stash) {
|
|
1465
|
+
function sanitizeMessages(messages, property, stash, fallbackPluginName) {
|
|
1368
1466
|
let messagesClone = [];
|
|
1369
1467
|
let index = 0;
|
|
1370
1468
|
for (const message of messages) {
|
|
1371
1469
|
let keys = {};
|
|
1470
|
+
let pluginName = getFlag(message, keys, "pluginName", mustBeString);
|
|
1372
1471
|
let text = getFlag(message, keys, "text", mustBeString);
|
|
1373
1472
|
let location = getFlag(message, keys, "location", mustBeObjectOrNull);
|
|
1374
1473
|
let notes = getFlag(message, keys, "notes", mustBeArray);
|
|
@@ -1389,6 +1488,7 @@ function sanitizeMessages(messages, property, stash) {
|
|
|
1389
1488
|
}
|
|
1390
1489
|
}
|
|
1391
1490
|
messagesClone.push({
|
|
1491
|
+
pluginName: pluginName || fallbackPluginName,
|
|
1392
1492
|
text: text || "",
|
|
1393
1493
|
location: sanitizeLocation(location, where),
|
|
1394
1494
|
notes: notesClone,
|
|
@@ -1497,7 +1597,7 @@ var fsAsync = {
|
|
|
1497
1597
|
}
|
|
1498
1598
|
}
|
|
1499
1599
|
};
|
|
1500
|
-
var version = "0.11.
|
|
1600
|
+
var version = "0.11.18";
|
|
1501
1601
|
var build = (options) => ensureServiceIsRunning().build(options);
|
|
1502
1602
|
var serve = (serveOptions, buildOptions) => ensureServiceIsRunning().serve(serveOptions, buildOptions);
|
|
1503
1603
|
var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
|
|
@@ -1585,7 +1685,7 @@ var ensureServiceIsRunning = () => {
|
|
|
1585
1685
|
if (longLivedService)
|
|
1586
1686
|
return longLivedService;
|
|
1587
1687
|
let [command, args] = esbuildCommandAndArgs();
|
|
1588
|
-
let child = child_process.spawn(command, args.concat(`--service=${"0.11.
|
|
1688
|
+
let child = child_process.spawn(command, args.concat(`--service=${"0.11.18"}`, "--ping"), {
|
|
1589
1689
|
windowsHide: true,
|
|
1590
1690
|
stdio: ["pipe", "pipe", "inherit"],
|
|
1591
1691
|
cwd: defaultWD
|
|
@@ -1683,7 +1783,7 @@ var runServiceSync = (callback) => {
|
|
|
1683
1783
|
isBrowser: false
|
|
1684
1784
|
});
|
|
1685
1785
|
callback(service);
|
|
1686
|
-
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.11.
|
|
1786
|
+
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.11.18"}`), {
|
|
1687
1787
|
cwd: defaultWD,
|
|
1688
1788
|
windowsHide: true,
|
|
1689
1789
|
input: stdin,
|
|
@@ -1708,7 +1808,7 @@ var startWorkerThreadService = (worker_threads2) => {
|
|
|
1708
1808
|
let fakeBuildError = (text) => {
|
|
1709
1809
|
let error = new Error(`Build failed with 1 error:
|
|
1710
1810
|
error: ${text}`);
|
|
1711
|
-
let errors = [{text, location: null, notes: [], detail: void 0}];
|
|
1811
|
+
let errors = [{pluginName: "", text, location: null, notes: [], detail: void 0}];
|
|
1712
1812
|
error.errors = errors;
|
|
1713
1813
|
error.warnings = [];
|
|
1714
1814
|
return error;
|