@jsenv/core 30.3.6 → 30.3.8
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/dist/js/babel_plugin_transform_modules_systemjs.cjs +392 -0
- package/dist/main.js +92 -38
- package/package.json +2 -2
- package/src/build/build.js +1 -1
- package/src/kitchen/kitchen.js +4 -1
- package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +1 -1
- package/src/plugins/import_meta_hot/html_hot_dependencies.js +1 -1
- package/src/plugins/importmap/jsenv_plugin_importmap.js +1 -1
- package/src/plugins/inline/jsenv_plugin_html_inline_content.js +37 -6
- package/src/plugins/inline/jsenv_plugin_inline_query_param.js +2 -1
- package/src/plugins/ribbon/jsenv_plugin_ribbon.js +1 -1
- package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +1 -1
- package/src/plugins/server_events/server_events_dispatcher.js +11 -2
- package/src/plugins/supervisor/jsenv_plugin_supervisor.js +3 -2
- package/src/plugins/transpilation/as_js_classic/babel_plugin_transform_modules_systemjs.cjs +608 -0
- package/src/plugins/transpilation/as_js_classic/convert_js_module_to_js_classic.js +31 -1
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +0 -13
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_conversion.js +1 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +3 -3
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_library.js +1 -0
- package/src/plugins/url_analysis/html/html_urls.js +2 -2
- package/src/plugins/url_analysis/jsenv_plugin_reference_expected_types.js +1 -1
- package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +2 -1
package/dist/main.js
CHANGED
|
@@ -6905,13 +6905,18 @@ const createServerEventsDispatcher = () => {
|
|
|
6905
6905
|
const firstClient = clients.shift();
|
|
6906
6906
|
firstClient.close();
|
|
6907
6907
|
}
|
|
6908
|
-
|
|
6909
|
-
client.close();
|
|
6908
|
+
const removeClient = () => {
|
|
6910
6909
|
const index = clients.indexOf(client);
|
|
6911
6910
|
if (index > -1) {
|
|
6912
6911
|
clients.splice(index, 1);
|
|
6913
6912
|
}
|
|
6914
6913
|
};
|
|
6914
|
+
client.onclose = () => {
|
|
6915
|
+
removeClient();
|
|
6916
|
+
};
|
|
6917
|
+
return () => {
|
|
6918
|
+
client.close();
|
|
6919
|
+
};
|
|
6915
6920
|
};
|
|
6916
6921
|
return {
|
|
6917
6922
|
addWebsocket: (websocket, request) => {
|
|
@@ -6946,6 +6951,10 @@ const createServerEventsDispatcher = () => {
|
|
|
6946
6951
|
client.sendEvent({
|
|
6947
6952
|
type: "welcome"
|
|
6948
6953
|
});
|
|
6954
|
+
websocket.onclose = () => {
|
|
6955
|
+
client.onclose();
|
|
6956
|
+
};
|
|
6957
|
+
client.onclose = () => {};
|
|
6949
6958
|
return addClient(client);
|
|
6950
6959
|
},
|
|
6951
6960
|
// we could add "addEventSource" and let clients connect using
|
|
@@ -9056,12 +9065,15 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
9056
9065
|
await urlInfoTransformer.applyIntermediateTransformations(urlInfo, transformReturnValue);
|
|
9057
9066
|
});
|
|
9058
9067
|
} catch (error) {
|
|
9059
|
-
|
|
9068
|
+
urlGraph.updateReferences(urlInfo, references); // ensure reference are updated even in case of error
|
|
9069
|
+
const transformError = createTransformUrlContentError({
|
|
9060
9070
|
pluginController,
|
|
9061
9071
|
reference: context.reference,
|
|
9062
9072
|
urlInfo,
|
|
9063
9073
|
error
|
|
9064
9074
|
});
|
|
9075
|
+
urlInfo.error = transformError;
|
|
9076
|
+
throw transformError;
|
|
9065
9077
|
}
|
|
9066
9078
|
// after "transform" all references from originalContent
|
|
9067
9079
|
// and the one injected by plugin are known
|
|
@@ -9651,7 +9663,7 @@ const jsenvPluginReferenceExpectedTypes = () => {
|
|
|
9651
9663
|
name: "jsenv:reference_expected_types",
|
|
9652
9664
|
appliesDuring: "*",
|
|
9653
9665
|
redirectUrl: {
|
|
9654
|
-
|
|
9666
|
+
script: redirectJsUrls,
|
|
9655
9667
|
js_url: redirectJsUrls,
|
|
9656
9668
|
js_import: redirectJsUrls
|
|
9657
9669
|
}
|
|
@@ -9860,7 +9872,7 @@ const visitHtmlUrls = ({
|
|
|
9860
9872
|
return;
|
|
9861
9873
|
}
|
|
9862
9874
|
visitAttributeAsUrlSpecifier({
|
|
9863
|
-
type: "
|
|
9875
|
+
type: "script",
|
|
9864
9876
|
subtype: type,
|
|
9865
9877
|
expectedType: type,
|
|
9866
9878
|
node,
|
|
@@ -9945,7 +9957,7 @@ const decideLinkExpectedType = (linkMention, mentions) => {
|
|
|
9945
9957
|
return "css";
|
|
9946
9958
|
}
|
|
9947
9959
|
if (as === "script") {
|
|
9948
|
-
const firstScriptOnThisUrl = mentions.find(mentionCandidate => mentionCandidate.url === linkMention.url && mentionCandidate.type === "
|
|
9960
|
+
const firstScriptOnThisUrl = mentions.find(mentionCandidate => mentionCandidate.url === linkMention.url && mentionCandidate.type === "script");
|
|
9949
9961
|
if (firstScriptOnThisUrl) {
|
|
9950
9962
|
return firstScriptOnThisUrl.expectedType;
|
|
9951
9963
|
}
|
|
@@ -10176,6 +10188,28 @@ const findOriginalDirectoryReference = (urlInfo, context) => {
|
|
|
10176
10188
|
const jsenvPluginHtmlInlineContent = ({
|
|
10177
10189
|
analyzeConvertedScripts
|
|
10178
10190
|
}) => {
|
|
10191
|
+
const cookInlineContent = async ({
|
|
10192
|
+
context,
|
|
10193
|
+
inlineContentUrlInfo,
|
|
10194
|
+
inlineContentReference
|
|
10195
|
+
}) => {
|
|
10196
|
+
try {
|
|
10197
|
+
await context.cook(inlineContentUrlInfo, {
|
|
10198
|
+
reference: inlineContentReference
|
|
10199
|
+
});
|
|
10200
|
+
} catch (e) {
|
|
10201
|
+
if (e.code === "PARSE_ERROR") {
|
|
10202
|
+
// When something like <style> or <script> contains syntax error
|
|
10203
|
+
// the HTML in itself it still valid
|
|
10204
|
+
// keep the syntax error and continue with the HTML
|
|
10205
|
+
const messageStart = inlineContentUrlInfo.type === "css" ? `Syntax error on css declared inside <style>` : `Syntax error on js declared inside <script>`;
|
|
10206
|
+
context.logger.error(`${messageStart}: ${e.cause.reasonCode}
|
|
10207
|
+
${e.traceMessage}`);
|
|
10208
|
+
} else {
|
|
10209
|
+
throw e;
|
|
10210
|
+
}
|
|
10211
|
+
}
|
|
10212
|
+
};
|
|
10179
10213
|
return {
|
|
10180
10214
|
name: "jsenv:html_inline_content",
|
|
10181
10215
|
appliesDuring: "*",
|
|
@@ -10210,7 +10244,7 @@ const jsenvPluginHtmlInlineContent = ({
|
|
|
10210
10244
|
const debug = getHtmlNodeAttribute(styleNode, "jsenv-debug") !== undefined;
|
|
10211
10245
|
const [inlineStyleReference, inlineStyleUrlInfo] = context.referenceUtils.foundInline({
|
|
10212
10246
|
node: styleNode,
|
|
10213
|
-
type: "
|
|
10247
|
+
type: "style",
|
|
10214
10248
|
expectedType: "css",
|
|
10215
10249
|
isOriginalPosition: isOriginal,
|
|
10216
10250
|
// we remove 1 to the line because imagine the following html:
|
|
@@ -10224,8 +10258,10 @@ const jsenvPluginHtmlInlineContent = ({
|
|
|
10224
10258
|
debug
|
|
10225
10259
|
});
|
|
10226
10260
|
actions.push(async () => {
|
|
10227
|
-
await
|
|
10228
|
-
|
|
10261
|
+
await cookInlineContent({
|
|
10262
|
+
context,
|
|
10263
|
+
inlineContentUrlInfo: inlineStyleUrlInfo,
|
|
10264
|
+
inlineContentReference: inlineStyleReference
|
|
10229
10265
|
});
|
|
10230
10266
|
});
|
|
10231
10267
|
mutations.push(() => {
|
|
@@ -10274,7 +10310,7 @@ const jsenvPluginHtmlInlineContent = ({
|
|
|
10274
10310
|
const debug = getHtmlNodeAttribute(scriptNode, "jsenv-debug") !== undefined;
|
|
10275
10311
|
const [inlineScriptReference, inlineScriptUrlInfo] = context.referenceUtils.foundInline({
|
|
10276
10312
|
node: scriptNode,
|
|
10277
|
-
type: "
|
|
10313
|
+
type: "script",
|
|
10278
10314
|
expectedType: type,
|
|
10279
10315
|
// we remove 1 to the line because imagine the following html:
|
|
10280
10316
|
// <script>console.log('ok')</script>
|
|
@@ -10288,8 +10324,10 @@ const jsenvPluginHtmlInlineContent = ({
|
|
|
10288
10324
|
debug
|
|
10289
10325
|
});
|
|
10290
10326
|
actions.push(async () => {
|
|
10291
|
-
await
|
|
10292
|
-
|
|
10327
|
+
await cookInlineContent({
|
|
10328
|
+
context,
|
|
10329
|
+
inlineContentUrlInfo: inlineScriptUrlInfo,
|
|
10330
|
+
inlineContentReference: inlineScriptReference
|
|
10293
10331
|
});
|
|
10294
10332
|
});
|
|
10295
10333
|
mutations.push(() => {
|
|
@@ -10814,7 +10852,8 @@ const jsenvPluginInlineQueryParam = () => {
|
|
|
10814
10852
|
// this should be done during dev and postbuild but not build
|
|
10815
10853
|
// so that the bundled file gets inlined and not the entry point
|
|
10816
10854
|
"link_href": () => null,
|
|
10817
|
-
"
|
|
10855
|
+
"style": () => null,
|
|
10856
|
+
"script": () => null,
|
|
10818
10857
|
// if the referenced url is a worker we could use
|
|
10819
10858
|
// https://www.oreilly.com/library/view/web-workers/9781449322120/ch04.html
|
|
10820
10859
|
// but maybe we should rather use ?object_url
|
|
@@ -14470,7 +14509,21 @@ function default_1({
|
|
|
14470
14509
|
};
|
|
14471
14510
|
}
|
|
14472
14511
|
|
|
14512
|
+
/*
|
|
14513
|
+
* When systemjs format is used by babel, it will generated UID based on
|
|
14514
|
+
* the import specifier:
|
|
14515
|
+
* https://github.com/babel/babel/blob/97d1967826077f15e766778c0d64711399e9a72a/packages/babel-plugin-transform-modules-systemjs/src/index.ts#L498
|
|
14516
|
+
* But at this stage import specifier are absolute file urls
|
|
14517
|
+
* So without minification these specifier are long and dependent
|
|
14518
|
+
* on where the files are on the filesystem.
|
|
14519
|
+
* This can be mitigated by minification that will rename them.
|
|
14520
|
+
* But to fix this issue once and for all I have copy-pasted
|
|
14521
|
+
* "@babel/plugin-transform-modules-systemjs" to introduce
|
|
14522
|
+
* "generateIdentifierHint" options and prevent that from hapenning
|
|
14523
|
+
*/
|
|
14524
|
+
const TRANSFORM_MODULES_SYSTEMJS_PATH = fileURLToPath(new URL("./js/babel_plugin_transform_modules_systemjs.cjs", import.meta.url));
|
|
14473
14525
|
const convertJsModuleToJsClassic = async ({
|
|
14526
|
+
rootDirectoryUrl,
|
|
14474
14527
|
systemJsInjection,
|
|
14475
14528
|
systemJsClientFileUrl,
|
|
14476
14529
|
urlInfo,
|
|
@@ -14495,7 +14548,16 @@ const convertJsModuleToJsClassic = async ({
|
|
|
14495
14548
|
babelPlugins: [...(jsClassicFormat === "system" ? [
|
|
14496
14549
|
// proposal-dynamic-import required with systemjs for babel8:
|
|
14497
14550
|
// https://github.com/babel/babel/issues/10746
|
|
14498
|
-
requireFromJsenv("@babel/plugin-proposal-dynamic-import"),
|
|
14551
|
+
requireFromJsenv("@babel/plugin-proposal-dynamic-import"), [
|
|
14552
|
+
// eslint-disable-next-line import/no-dynamic-require
|
|
14553
|
+
requireFromJsenv(TRANSFORM_MODULES_SYSTEMJS_PATH), {
|
|
14554
|
+
generateIdentifierHint: key => {
|
|
14555
|
+
if (key.startsWith("file://")) {
|
|
14556
|
+
return urlToRelativeUrl(key, rootDirectoryUrl);
|
|
14557
|
+
}
|
|
14558
|
+
return key;
|
|
14559
|
+
}
|
|
14560
|
+
}], [default_1, {
|
|
14499
14561
|
asyncAwait: false,
|
|
14500
14562
|
// already handled + we might not needs it at all
|
|
14501
14563
|
topLevelAwait: "return"
|
|
@@ -14629,6 +14691,7 @@ const jsenvPluginAsJsClassicConversion = ({
|
|
|
14629
14691
|
content,
|
|
14630
14692
|
sourcemap
|
|
14631
14693
|
} = await convertJsModuleToJsClassic({
|
|
14694
|
+
rootDirectoryUrl: context.rootDirectoryUrl,
|
|
14632
14695
|
systemJsInjection,
|
|
14633
14696
|
systemJsClientFileUrl,
|
|
14634
14697
|
urlInfo,
|
|
@@ -14675,7 +14738,7 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
14675
14738
|
}
|
|
14676
14739
|
return null;
|
|
14677
14740
|
},
|
|
14678
|
-
|
|
14741
|
+
script: (reference, context) => {
|
|
14679
14742
|
if (context.systemJsTranspilation && reference.expectedType === "js_module") {
|
|
14680
14743
|
return turnIntoJsClassicProxy(reference);
|
|
14681
14744
|
}
|
|
@@ -14732,7 +14795,7 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
14732
14795
|
}
|
|
14733
14796
|
const src = getHtmlNodeAttribute(node, "src");
|
|
14734
14797
|
if (src) {
|
|
14735
|
-
const reference = context.referenceUtils.find(ref => ref.generatedSpecifier === src && ref.type === "
|
|
14798
|
+
const reference = context.referenceUtils.find(ref => ref.generatedSpecifier === src && ref.type === "script" && ref.subtype === "js_module");
|
|
14736
14799
|
if (!reference) {
|
|
14737
14800
|
return;
|
|
14738
14801
|
}
|
|
@@ -14803,7 +14866,7 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
14803
14866
|
});
|
|
14804
14867
|
}
|
|
14805
14868
|
const [systemJsReference, systemJsUrlInfo] = context.referenceUtils.inject({
|
|
14806
|
-
type: "
|
|
14869
|
+
type: "script",
|
|
14807
14870
|
expectedType: "js_classic",
|
|
14808
14871
|
isInline: true,
|
|
14809
14872
|
contentType: "text/javascript",
|
|
@@ -14973,6 +15036,7 @@ const jsenvPluginAsJsClassicLibrary = ({
|
|
|
14973
15036
|
content,
|
|
14974
15037
|
sourcemap
|
|
14975
15038
|
} = await convertJsModuleToJsClassic({
|
|
15039
|
+
rootDirectoryUrl: context.rootDirectoryUrl,
|
|
14976
15040
|
systemJsInjection,
|
|
14977
15041
|
systemJsClientFileUrl,
|
|
14978
15042
|
urlInfo,
|
|
@@ -14991,18 +15055,6 @@ const jsenvPluginAsJsClassicLibrary = ({
|
|
|
14991
15055
|
};
|
|
14992
15056
|
};
|
|
14993
15057
|
|
|
14994
|
-
/*
|
|
14995
|
-
* Something to keep in mind:
|
|
14996
|
-
* When systemjs format is used by babel, it will generated UID based on
|
|
14997
|
-
* the import specifier:
|
|
14998
|
-
* https://github.com/babel/babel/blob/97d1967826077f15e766778c0d64711399e9a72a/packages/babel-plugin-transform-modules-systemjs/src/index.ts#L498
|
|
14999
|
-
* But at this stage import specifier are absolute file urls
|
|
15000
|
-
* So without minification these specifier are long and dependent
|
|
15001
|
-
* on where the files are on the filesystem.
|
|
15002
|
-
* This is mitigated by minification that will shorten them
|
|
15003
|
-
* But ideally babel should not generate this in the first place
|
|
15004
|
-
* and prefer to unique identifier based solely on the specifier basename for instance
|
|
15005
|
-
*/
|
|
15006
15058
|
const jsenvPluginAsJsClassic = ({
|
|
15007
15059
|
jsClassicLibrary,
|
|
15008
15060
|
jsClassicFallback,
|
|
@@ -15739,7 +15791,7 @@ const jsenvPluginImportmap = () => {
|
|
|
15739
15791
|
columnEnd
|
|
15740
15792
|
});
|
|
15741
15793
|
const [inlineImportmapReference, inlineImportmapUrlInfo] = context.referenceUtils.foundInline({
|
|
15742
|
-
type: "
|
|
15794
|
+
type: "script",
|
|
15743
15795
|
isOriginalPosition: isOriginal,
|
|
15744
15796
|
specifierLine: line - 1,
|
|
15745
15797
|
specifierColumn: column,
|
|
@@ -16874,7 +16926,8 @@ const addRelationshipWithPackageJson = ({
|
|
|
16874
16926
|
* - "http_request"
|
|
16875
16927
|
* - "entry_point"
|
|
16876
16928
|
* - "link_href"
|
|
16877
|
-
* - "
|
|
16929
|
+
* - "style"
|
|
16930
|
+
* - "script"
|
|
16878
16931
|
* - "a_href"
|
|
16879
16932
|
* - "iframe_src
|
|
16880
16933
|
* - "img_src"
|
|
@@ -17411,7 +17464,8 @@ const jsenvPluginSupervisor = ({
|
|
|
17411
17464
|
columnEnd
|
|
17412
17465
|
});
|
|
17413
17466
|
const [inlineScriptReference] = context.referenceUtils.foundInline({
|
|
17414
|
-
type: "
|
|
17467
|
+
type: "script",
|
|
17468
|
+
subtype: "inline",
|
|
17415
17469
|
expectedType: type,
|
|
17416
17470
|
isOriginalPosition: isOriginal,
|
|
17417
17471
|
specifierLine: line - 1,
|
|
@@ -17484,7 +17538,7 @@ const jsenvPluginSupervisor = ({
|
|
|
17484
17538
|
specifier: scriptTypeModuleSupervisorFileUrl
|
|
17485
17539
|
});
|
|
17486
17540
|
const [supervisorFileReference] = context.referenceUtils.inject({
|
|
17487
|
-
type: "
|
|
17541
|
+
type: "script",
|
|
17488
17542
|
expectedType: "js_classic",
|
|
17489
17543
|
specifier: supervisorFileUrl
|
|
17490
17544
|
});
|
|
@@ -19464,7 +19518,7 @@ const htmlNodeCanHotReload = node => {
|
|
|
19464
19518
|
return rel === "icon";
|
|
19465
19519
|
}
|
|
19466
19520
|
return [
|
|
19467
|
-
// "
|
|
19521
|
+
// "script", // script cannot hot reload
|
|
19468
19522
|
"a",
|
|
19469
19523
|
// Iframe will have their own event source client
|
|
19470
19524
|
// and can hot reload independently
|
|
@@ -19723,7 +19777,7 @@ const jsenvPluginAutoreloadClient = () => {
|
|
|
19723
19777
|
html: (htmlUrlInfo, context) => {
|
|
19724
19778
|
const htmlAst = parseHtmlString(htmlUrlInfo.content);
|
|
19725
19779
|
const [autoreloadClientReference] = context.referenceUtils.inject({
|
|
19726
|
-
type: "
|
|
19780
|
+
type: "script",
|
|
19727
19781
|
subtype: "js_module",
|
|
19728
19782
|
expectedType: "js_module",
|
|
19729
19783
|
specifier: autoreloadClientFileUrl
|
|
@@ -20078,7 +20132,7 @@ const jsenvPluginRibbon = ({
|
|
|
20078
20132
|
}
|
|
20079
20133
|
const htmlAst = parseHtmlString(urlInfo.content);
|
|
20080
20134
|
const [ribbonClientFileReference] = context.referenceUtils.inject({
|
|
20081
|
-
type: "
|
|
20135
|
+
type: "script",
|
|
20082
20136
|
subtype: "js_module",
|
|
20083
20137
|
expectedType: "js_module",
|
|
20084
20138
|
specifier: ribbonClientFileUrl.href
|
|
@@ -21088,7 +21142,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
21088
21142
|
const dependentUrlInfo = rawGraph.getUrlInfo(dependent);
|
|
21089
21143
|
for (const reference of dependentUrlInfo.references) {
|
|
21090
21144
|
if (reference.url === referencedUrlInfo.url) {
|
|
21091
|
-
willAlreadyBeBundled = reference.subtype === "import_dynamic" || reference.type === "
|
|
21145
|
+
willAlreadyBeBundled = reference.subtype === "import_dynamic" || reference.type === "script";
|
|
21092
21146
|
}
|
|
21093
21147
|
}
|
|
21094
21148
|
}
|
|
@@ -22036,7 +22090,7 @@ const jsenvPluginServerEventsClientInjection = () => {
|
|
|
22036
22090
|
html: (htmlUrlInfo, context) => {
|
|
22037
22091
|
const htmlAst = parseHtmlString(htmlUrlInfo.content);
|
|
22038
22092
|
const [serverEventsClientFileReference] = context.referenceUtils.inject({
|
|
22039
|
-
type: "
|
|
22093
|
+
type: "script",
|
|
22040
22094
|
subtype: "js_module",
|
|
22041
22095
|
expectedType: "js_module",
|
|
22042
22096
|
specifier: serverEventsClientFileUrl
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "30.3.
|
|
3
|
+
"version": "30.3.8",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"@c88/v8-coverage": "0.1.1",
|
|
68
68
|
"@financial-times/polyfill-useragent-normaliser": "1.10.2",
|
|
69
69
|
"@jsenv/abort": "4.2.4",
|
|
70
|
-
"@jsenv/ast": "3.0.
|
|
70
|
+
"@jsenv/ast": "3.0.2",
|
|
71
71
|
"@jsenv/babel-plugins": "1.1.3",
|
|
72
72
|
"@jsenv/plugin-bundling": "1.1.2",
|
|
73
73
|
"@jsenv/filesystem": "4.1.9",
|
package/src/build/build.js
CHANGED
package/src/kitchen/kitchen.js
CHANGED
|
@@ -593,12 +593,15 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
593
593
|
},
|
|
594
594
|
)
|
|
595
595
|
} catch (error) {
|
|
596
|
-
|
|
596
|
+
urlGraph.updateReferences(urlInfo, references) // ensure reference are updated even in case of error
|
|
597
|
+
const transformError = createTransformUrlContentError({
|
|
597
598
|
pluginController,
|
|
598
599
|
reference: context.reference,
|
|
599
600
|
urlInfo,
|
|
600
601
|
error,
|
|
601
602
|
})
|
|
603
|
+
urlInfo.error = transformError
|
|
604
|
+
throw transformError
|
|
602
605
|
}
|
|
603
606
|
// after "transform" all references from originalContent
|
|
604
607
|
// and the one injected by plugin are known
|
|
@@ -18,7 +18,7 @@ export const jsenvPluginAutoreloadClient = () => {
|
|
|
18
18
|
html: (htmlUrlInfo, context) => {
|
|
19
19
|
const htmlAst = parseHtmlString(htmlUrlInfo.content)
|
|
20
20
|
const [autoreloadClientReference] = context.referenceUtils.inject({
|
|
21
|
-
type: "
|
|
21
|
+
type: "script",
|
|
22
22
|
subtype: "js_module",
|
|
23
23
|
expectedType: "js_module",
|
|
24
24
|
specifier: autoreloadClientFileUrl,
|
|
@@ -130,7 +130,7 @@ const htmlNodeCanHotReload = (node) => {
|
|
|
130
130
|
return rel === "icon"
|
|
131
131
|
}
|
|
132
132
|
return [
|
|
133
|
-
// "
|
|
133
|
+
// "script", // script cannot hot reload
|
|
134
134
|
"a",
|
|
135
135
|
// Iframe will have their own event source client
|
|
136
136
|
// and can hot reload independently
|
|
@@ -121,7 +121,7 @@ export const jsenvPluginImportmap = () => {
|
|
|
121
121
|
})
|
|
122
122
|
const [inlineImportmapReference, inlineImportmapUrlInfo] =
|
|
123
123
|
context.referenceUtils.foundInline({
|
|
124
|
-
type: "
|
|
124
|
+
type: "script",
|
|
125
125
|
isOriginalPosition: isOriginal,
|
|
126
126
|
specifierLine: line - 1,
|
|
127
127
|
specifierColumn: column,
|
|
@@ -13,6 +13,33 @@ import {
|
|
|
13
13
|
import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"
|
|
14
14
|
|
|
15
15
|
export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
16
|
+
const cookInlineContent = async ({
|
|
17
|
+
context,
|
|
18
|
+
inlineContentUrlInfo,
|
|
19
|
+
inlineContentReference,
|
|
20
|
+
}) => {
|
|
21
|
+
try {
|
|
22
|
+
await context.cook(inlineContentUrlInfo, {
|
|
23
|
+
reference: inlineContentReference,
|
|
24
|
+
})
|
|
25
|
+
} catch (e) {
|
|
26
|
+
if (e.code === "PARSE_ERROR") {
|
|
27
|
+
// When something like <style> or <script> contains syntax error
|
|
28
|
+
// the HTML in itself it still valid
|
|
29
|
+
// keep the syntax error and continue with the HTML
|
|
30
|
+
const messageStart =
|
|
31
|
+
inlineContentUrlInfo.type === "css"
|
|
32
|
+
? `Syntax error on css declared inside <style>`
|
|
33
|
+
: `Syntax error on js declared inside <script>`
|
|
34
|
+
|
|
35
|
+
context.logger.error(`${messageStart}: ${e.cause.reasonCode}
|
|
36
|
+
${e.traceMessage}`)
|
|
37
|
+
} else {
|
|
38
|
+
throw e
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
16
43
|
return {
|
|
17
44
|
name: "jsenv:html_inline_content",
|
|
18
45
|
appliesDuring: "*",
|
|
@@ -44,7 +71,7 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
|
44
71
|
const [inlineStyleReference, inlineStyleUrlInfo] =
|
|
45
72
|
context.referenceUtils.foundInline({
|
|
46
73
|
node: styleNode,
|
|
47
|
-
type: "
|
|
74
|
+
type: "style",
|
|
48
75
|
expectedType: "css",
|
|
49
76
|
isOriginalPosition: isOriginal,
|
|
50
77
|
// we remove 1 to the line because imagine the following html:
|
|
@@ -58,8 +85,10 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
|
58
85
|
debug,
|
|
59
86
|
})
|
|
60
87
|
actions.push(async () => {
|
|
61
|
-
await
|
|
62
|
-
|
|
88
|
+
await cookInlineContent({
|
|
89
|
+
context,
|
|
90
|
+
inlineContentUrlInfo: inlineStyleUrlInfo,
|
|
91
|
+
inlineContentReference: inlineStyleReference,
|
|
63
92
|
})
|
|
64
93
|
})
|
|
65
94
|
mutations.push(() => {
|
|
@@ -113,7 +142,7 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
|
113
142
|
const [inlineScriptReference, inlineScriptUrlInfo] =
|
|
114
143
|
context.referenceUtils.foundInline({
|
|
115
144
|
node: scriptNode,
|
|
116
|
-
type: "
|
|
145
|
+
type: "script",
|
|
117
146
|
expectedType: type,
|
|
118
147
|
// we remove 1 to the line because imagine the following html:
|
|
119
148
|
// <script>console.log('ok')</script>
|
|
@@ -127,8 +156,10 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
|
127
156
|
debug,
|
|
128
157
|
})
|
|
129
158
|
actions.push(async () => {
|
|
130
|
-
await
|
|
131
|
-
|
|
159
|
+
await cookInlineContent({
|
|
160
|
+
context,
|
|
161
|
+
inlineContentUrlInfo: inlineScriptUrlInfo,
|
|
162
|
+
inlineContentReference: inlineScriptReference,
|
|
132
163
|
})
|
|
133
164
|
})
|
|
134
165
|
mutations.push(() => {
|
|
@@ -9,7 +9,8 @@ export const jsenvPluginInlineQueryParam = () => {
|
|
|
9
9
|
// this should be done during dev and postbuild but not build
|
|
10
10
|
// so that the bundled file gets inlined and not the entry point
|
|
11
11
|
"link_href": () => null,
|
|
12
|
-
"
|
|
12
|
+
"style": () => null,
|
|
13
|
+
"script": () => null,
|
|
13
14
|
// if the referenced url is a worker we could use
|
|
14
15
|
// https://www.oreilly.com/library/view/web-workers/9781449322120/ch04.html
|
|
15
16
|
// but maybe we should rather use ?object_url
|
|
@@ -37,7 +37,7 @@ export const jsenvPluginRibbon = ({
|
|
|
37
37
|
}
|
|
38
38
|
const htmlAst = parseHtmlString(urlInfo.content)
|
|
39
39
|
const [ribbonClientFileReference] = context.referenceUtils.inject({
|
|
40
|
-
type: "
|
|
40
|
+
type: "script",
|
|
41
41
|
subtype: "js_module",
|
|
42
42
|
expectedType: "js_module",
|
|
43
43
|
specifier: ribbonClientFileUrl.href,
|
|
@@ -24,7 +24,7 @@ export const jsenvPluginServerEventsClientInjection = () => {
|
|
|
24
24
|
const htmlAst = parseHtmlString(htmlUrlInfo.content)
|
|
25
25
|
const [serverEventsClientFileReference] = context.referenceUtils.inject(
|
|
26
26
|
{
|
|
27
|
-
type: "
|
|
27
|
+
type: "script",
|
|
28
28
|
subtype: "js_module",
|
|
29
29
|
expectedType: "js_module",
|
|
30
30
|
specifier: serverEventsClientFileUrl,
|
|
@@ -8,13 +8,18 @@ export const createServerEventsDispatcher = () => {
|
|
|
8
8
|
const firstClient = clients.shift()
|
|
9
9
|
firstClient.close()
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
client.close()
|
|
11
|
+
const removeClient = () => {
|
|
13
12
|
const index = clients.indexOf(client)
|
|
14
13
|
if (index > -1) {
|
|
15
14
|
clients.splice(index, 1)
|
|
16
15
|
}
|
|
17
16
|
}
|
|
17
|
+
client.onclose = () => {
|
|
18
|
+
removeClient(client)
|
|
19
|
+
}
|
|
20
|
+
return () => {
|
|
21
|
+
client.close()
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
return {
|
|
@@ -48,6 +53,10 @@ export const createServerEventsDispatcher = () => {
|
|
|
48
53
|
},
|
|
49
54
|
}
|
|
50
55
|
client.sendEvent({ type: "welcome" })
|
|
56
|
+
websocket.onclose = () => {
|
|
57
|
+
client.onclose()
|
|
58
|
+
}
|
|
59
|
+
client.onclose = () => {}
|
|
51
60
|
return addClient(client)
|
|
52
61
|
},
|
|
53
62
|
// we could add "addEventSource" and let clients connect using
|
|
@@ -232,7 +232,8 @@ export const jsenvPluginSupervisor = ({
|
|
|
232
232
|
columnEnd,
|
|
233
233
|
})
|
|
234
234
|
const [inlineScriptReference] = context.referenceUtils.foundInline({
|
|
235
|
-
type: "
|
|
235
|
+
type: "script",
|
|
236
|
+
subtype: "inline",
|
|
236
237
|
expectedType: type,
|
|
237
238
|
isOriginalPosition: isOriginal,
|
|
238
239
|
specifierLine: line - 1,
|
|
@@ -307,7 +308,7 @@ export const jsenvPluginSupervisor = ({
|
|
|
307
308
|
specifier: scriptTypeModuleSupervisorFileUrl,
|
|
308
309
|
})
|
|
309
310
|
const [supervisorFileReference] = context.referenceUtils.inject({
|
|
310
|
-
type: "
|
|
311
|
+
type: "script",
|
|
311
312
|
expectedType: "js_classic",
|
|
312
313
|
specifier: supervisorFileUrl,
|
|
313
314
|
})
|