@jsenv/core 27.0.0-alpha.84 → 27.0.0-alpha.85
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/event_source_client.js +3 -3
- package/dist/js/s.js +2 -2
- package/dist/main.js +355 -380
- package/dist/s.js +2 -2
- package/dist/s.js.map +1 -1
- package/package.json +5 -2
- package/src/build/build.js +1 -4
- package/src/build/inject_global_version_mappings.js +3 -3
- package/src/build/resync_ressource_hints.js +17 -18
- package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +3 -3
- package/src/omega/kitchen.js +2 -0
- package/src/plugins/autoreload/dev_sse/client/reload.js +6 -3
- package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +3 -3
- package/src/plugins/bundling/css/bundle_css.js +1 -2
- package/src/plugins/bundling/js_module/bundle_js_module.js +85 -66
- package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +1 -1
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +3 -3
- package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +62 -74
- package/src/plugins/import_meta_hot/html_hot_dependencies.js +9 -15
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +1 -2
- package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +1 -1
- package/src/plugins/importmap/jsenv_plugin_importmap.js +24 -25
- package/src/plugins/inject_globals/inject_globals.js +3 -3
- package/src/plugins/inline/jsenv_plugin_html_inline_content.js +39 -41
- package/src/plugins/inline/jsenv_plugin_js_inline_content.js +1 -1
- package/src/plugins/minification/css/minify_css.js +1 -1
- package/src/plugins/transpilation/as_js_classic/client/s.js +2 -2
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +2 -2
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +41 -63
- package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +2 -3
- package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +2 -2
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +1 -1
- package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +2 -2
- package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +2 -2
- package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +1 -1
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +1 -1
- package/src/plugins/url_analysis/css/css_urls.js +1 -2
- package/src/plugins/url_analysis/html/html_urls.js +98 -113
- package/src/plugins/url_analysis/js/js_urls.js +1 -1
- package/src/test/coverage/empty_coverage_factory.js +1 -1
package/dist/main.js
CHANGED
|
@@ -6,24 +6,16 @@ import { urlToRelativeUrl, generateInlineContentUrl, ensurePathnameTrailingSlash
|
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
7
|
import { workerData, Worker } from "node:worker_threads";
|
|
8
8
|
import { URL_META } from "@jsenv/url-meta";
|
|
9
|
-
import { parseHtmlString, stringifyHtmlAst,
|
|
10
|
-
import { htmlAttributeSrcSet } from "@jsenv/utils/src/html_ast/html_attribute_src_set.js";
|
|
9
|
+
import { parseHtmlString, stringifyHtmlAst, visitHtmlNodes, getHtmlNodeAttribute, setHtmlNodeAttributes, parseSrcSet, getHtmlNodePosition, getHtmlNodeAttributePosition, applyPostCss, postCssPluginUrlVisitor, parseJsUrls, findHtmlNode, getHtmlNodeText, removeHtmlNode, setHtmlNodeText, analyzeScriptNode, applyBabelPlugins, injectScriptNodeAsEarlyAsPossible, createHtmlNode, removeHtmlNodeText, transpileWithParcel, injectJsImport, minifyWithParcel, analyzeLinkNode } from "@jsenv/ast";
|
|
11
10
|
import { createMagicSource, composeTwoSourcemaps, sourcemapConverter, SOURCEMAP, generateSourcemapFileUrl, generateSourcemapDataUrl } from "@jsenv/sourcemap";
|
|
12
|
-
import { applyPostCss } from "@jsenv/utils/src/css_ast/apply_post_css.js";
|
|
13
|
-
import { postCssPluginUrlVisitor } from "@jsenv/utils/src/css_ast/postcss_plugin_url_visitor.js";
|
|
14
|
-
import { parseJsUrls } from "@jsenv/utils/src/js_ast/parse_js_urls.js";
|
|
15
11
|
import { resolveImport, normalizeImportMap, composeTwoImportMaps } from "@jsenv/importmap";
|
|
16
12
|
import { applyNodeEsmResolution, defaultLookupPackageScope, defaultReadPackageJson, readCustomConditionsFromProcessArgs, applyFileSystemMagicResolution, getExtensionsToTry } from "@jsenv/node-esm-resolution";
|
|
17
13
|
import { statSync, realpathSync, readdirSync, readFileSync, existsSync } from "node:fs";
|
|
18
14
|
import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js";
|
|
19
15
|
import { JS_QUOTES } from "@jsenv/utils/src/string/js_quotes.js";
|
|
20
|
-
import { applyBabelPlugins } from "@jsenv/utils/src/js_ast/apply_babel_plugins.js";
|
|
21
|
-
import { transpileWithParcel, minifyWithParcel } from "@jsenv/utils/src/css_ast/parcel_css.js";
|
|
22
16
|
import { createRequire } from "node:module";
|
|
23
17
|
import babelParser from "@babel/parser";
|
|
24
18
|
import { findHighestVersion } from "@jsenv/utils/src/semantic_versioning/highest_version.js";
|
|
25
|
-
import { injectImport } from "@jsenv/utils/src/js_ast/babel_utils.js";
|
|
26
|
-
import { applyRollupPlugins } from "@jsenv/utils/src/js_ast/apply_rollup_plugins.js";
|
|
27
19
|
import { validateResponseIntegrity } from "@jsenv/integrity";
|
|
28
20
|
import { convertFileSystemErrorToResponseProperties } from "@jsenv/server/src/internal/convertFileSystemErrorToResponseProperties.js";
|
|
29
21
|
import { memoizeByFirstArgument } from "@jsenv/utils/src/memoize/memoize_by_first_argument.js";
|
|
@@ -115,9 +107,14 @@ const parseAndTransformHtmlUrls = async (urlInfo, context) => {
|
|
|
115
107
|
column,
|
|
116
108
|
originalLine,
|
|
117
109
|
originalColumn,
|
|
118
|
-
|
|
119
|
-
|
|
110
|
+
node,
|
|
111
|
+
attributeName,
|
|
112
|
+
specifier
|
|
120
113
|
}) => {
|
|
114
|
+
const {
|
|
115
|
+
crossorigin,
|
|
116
|
+
integrity
|
|
117
|
+
} = readFetchMetas(node);
|
|
121
118
|
const isRessourceHint = ["preconnect", "dns-prefetch", "prefetch", "preload", "modulepreload"].includes(subtype);
|
|
122
119
|
const [reference] = referenceUtils.found({
|
|
123
120
|
type,
|
|
@@ -127,10 +124,14 @@ const parseAndTransformHtmlUrls = async (urlInfo, context) => {
|
|
|
127
124
|
specifier,
|
|
128
125
|
specifierLine: line,
|
|
129
126
|
specifierColumn: column,
|
|
130
|
-
isRessourceHint
|
|
127
|
+
isRessourceHint,
|
|
128
|
+
crossorigin,
|
|
129
|
+
integrity
|
|
131
130
|
});
|
|
132
131
|
actions.push(async () => {
|
|
133
|
-
|
|
132
|
+
setHtmlNodeAttributes(node, {
|
|
133
|
+
[attributeName]: await referenceUtils.readGeneratedSpecifier(reference)
|
|
134
|
+
});
|
|
134
135
|
});
|
|
135
136
|
}
|
|
136
137
|
});
|
|
@@ -144,6 +145,24 @@ const parseAndTransformHtmlUrls = async (urlInfo, context) => {
|
|
|
144
145
|
content: stringifyHtmlAst(htmlAst)
|
|
145
146
|
};
|
|
146
147
|
};
|
|
148
|
+
const crossOriginCompatibleTagNames = ["script", "link", "img", "source"];
|
|
149
|
+
const integrityCompatibleTagNames = ["script", "link", "img", "source"];
|
|
150
|
+
|
|
151
|
+
const readFetchMetas = node => {
|
|
152
|
+
const meta = {};
|
|
153
|
+
|
|
154
|
+
if (crossOriginCompatibleTagNames.includes(node.nodeName)) {
|
|
155
|
+
const crossorigin = getHtmlNodeAttribute(node, "crossorigin") !== undefined;
|
|
156
|
+
meta.crossorigin = crossorigin;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (integrityCompatibleTagNames.includes(node.nodeName)) {
|
|
160
|
+
const integrity = getHtmlNodeAttribute(node, "integrity");
|
|
161
|
+
meta.integrity = integrity;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return meta;
|
|
165
|
+
};
|
|
147
166
|
|
|
148
167
|
const visitHtmlUrls = ({
|
|
149
168
|
url,
|
|
@@ -155,18 +174,18 @@ const visitHtmlUrls = ({
|
|
|
155
174
|
subtype,
|
|
156
175
|
expectedType,
|
|
157
176
|
node,
|
|
158
|
-
|
|
177
|
+
attributeName,
|
|
159
178
|
specifier
|
|
160
179
|
}) => {
|
|
161
|
-
const generatedFromInlineContent =
|
|
180
|
+
const generatedFromInlineContent = getHtmlNodeAttribute(node, "generated-from-inline-content") !== undefined;
|
|
162
181
|
let position;
|
|
163
182
|
|
|
164
183
|
if (generatedFromInlineContent) {
|
|
165
184
|
// when generated from inline content,
|
|
166
185
|
// line, column is not "src" nor "generated-from-src" but "original-position"
|
|
167
|
-
position =
|
|
186
|
+
position = getHtmlNodePosition(node);
|
|
168
187
|
} else {
|
|
169
|
-
position =
|
|
188
|
+
position = getHtmlNodeAttributePosition(node, attributeName);
|
|
170
189
|
}
|
|
171
190
|
|
|
172
191
|
const {
|
|
@@ -182,19 +201,68 @@ const visitHtmlUrls = ({
|
|
|
182
201
|
column,
|
|
183
202
|
// originalLine, originalColumn
|
|
184
203
|
specifier,
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
// srcGeneratedFromInlineContent
|
|
188
|
-
...readFetchMetas(node)
|
|
204
|
+
node,
|
|
205
|
+
attributeName
|
|
189
206
|
});
|
|
190
207
|
};
|
|
191
208
|
|
|
192
|
-
const
|
|
209
|
+
const visitAttributeAsUrlSpecifier = ({
|
|
210
|
+
node,
|
|
211
|
+
attributeName,
|
|
212
|
+
...rest
|
|
213
|
+
}) => {
|
|
214
|
+
const value = getHtmlNodeAttribute(node, attributeName);
|
|
215
|
+
|
|
216
|
+
if (value) {
|
|
217
|
+
const generatedBy = getHtmlNodeAttribute(node, "generated-by");
|
|
218
|
+
|
|
219
|
+
if (generatedBy !== undefined) {
|
|
220
|
+
// during build the importmap is inlined
|
|
221
|
+
// and shoud not be considered as a dependency anymore
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
addDependency({ ...rest,
|
|
226
|
+
node,
|
|
227
|
+
attributeName,
|
|
228
|
+
specifier: attributeName === "generated-from-src" || attributeName === "generated-from-href" ? new URL(value, url).href : value
|
|
229
|
+
});
|
|
230
|
+
} else if (attributeName === "src") {
|
|
231
|
+
visitAttributeAsUrlSpecifier({ ...rest,
|
|
232
|
+
node,
|
|
233
|
+
attributeName: "generated-from-src"
|
|
234
|
+
});
|
|
235
|
+
} else if (attributeName === "href") {
|
|
236
|
+
visitAttributeAsUrlSpecifier({ ...rest,
|
|
237
|
+
node,
|
|
238
|
+
attributeName: "generated-from-href"
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const visitSrcset = ({
|
|
244
|
+
type,
|
|
245
|
+
node
|
|
246
|
+
}) => {
|
|
247
|
+
const srcset = getHtmlNodeAttribute(node, "srcset");
|
|
248
|
+
|
|
249
|
+
if (srcset) {
|
|
250
|
+
const srcCandidates = parseSrcSet(srcset);
|
|
251
|
+
srcCandidates.forEach(srcCandidate => {
|
|
252
|
+
addDependency({
|
|
253
|
+
type,
|
|
254
|
+
node,
|
|
255
|
+
attributeName: "srcset",
|
|
256
|
+
specifier: srcCandidate.specifier
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
visitHtmlNodes(htmlAst, {
|
|
193
263
|
link: node => {
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
const typeAttribute = getHtmlNodeAttributeByName(node, "type");
|
|
197
|
-
const type = typeAttribute ? typeAttribute.value : undefined;
|
|
264
|
+
const rel = getHtmlNodeAttribute(node, "rel");
|
|
265
|
+
const type = getHtmlNodeAttribute(node, "type");
|
|
198
266
|
visitAttributeAsUrlSpecifier({
|
|
199
267
|
type: "link_href",
|
|
200
268
|
subtype: rel,
|
|
@@ -210,15 +278,16 @@ const visitHtmlUrls = ({
|
|
|
210
278
|
},
|
|
211
279
|
// style: () => {},
|
|
212
280
|
script: node => {
|
|
213
|
-
const
|
|
281
|
+
const type = getHtmlNodeAttribute(node, "type");
|
|
282
|
+
const expectedType = {
|
|
283
|
+
"undefined": "js_classic",
|
|
284
|
+
"text/javascript": "js_classic",
|
|
285
|
+
"module": "js_module",
|
|
286
|
+
"importmap": "importmap"
|
|
287
|
+
}[type];
|
|
214
288
|
visitAttributeAsUrlSpecifier({
|
|
215
289
|
type: "script_src",
|
|
216
|
-
expectedType
|
|
217
|
-
"undefined": "js_classic",
|
|
218
|
-
"text/javascript": "js_classic",
|
|
219
|
-
"module": "js_module",
|
|
220
|
-
"importmap": "importmap"
|
|
221
|
-
}[typeAttributeNode ? typeAttributeNode.value : undefined],
|
|
290
|
+
expectedType,
|
|
222
291
|
node,
|
|
223
292
|
attributeName: "src"
|
|
224
293
|
});
|
|
@@ -274,102 +343,9 @@ const visitHtmlUrls = ({
|
|
|
274
343
|
attributeName: "href"
|
|
275
344
|
});
|
|
276
345
|
}
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
const visitAttributeAsUrlSpecifier = ({
|
|
280
|
-
type,
|
|
281
|
-
subtype,
|
|
282
|
-
expectedType,
|
|
283
|
-
node,
|
|
284
|
-
attributeName
|
|
285
|
-
}) => {
|
|
286
|
-
const attribute = getHtmlNodeAttributeByName(node, attributeName);
|
|
287
|
-
const value = attribute ? attribute.value : undefined;
|
|
288
|
-
|
|
289
|
-
if (value) {
|
|
290
|
-
const generatedBy = getHtmlNodeAttributeByName(node, "generated-by");
|
|
291
|
-
|
|
292
|
-
if (generatedBy) {
|
|
293
|
-
// during build the importmap is inlined
|
|
294
|
-
// and shoud not be considered as a dependency anymore
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
addDependency({
|
|
299
|
-
type,
|
|
300
|
-
subtype,
|
|
301
|
-
expectedType,
|
|
302
|
-
node,
|
|
303
|
-
attribute,
|
|
304
|
-
specifier: attributeName === "generated-from-src" || attributeName === "generated-from-href" ? new URL(value, url).href : value
|
|
305
|
-
});
|
|
306
|
-
} else if (attributeName === "src") {
|
|
307
|
-
visitAttributeAsUrlSpecifier({
|
|
308
|
-
type,
|
|
309
|
-
subtype,
|
|
310
|
-
expectedType,
|
|
311
|
-
node,
|
|
312
|
-
attributeName: "generated-from-src"
|
|
313
|
-
});
|
|
314
|
-
} else if (attributeName === "href") {
|
|
315
|
-
visitAttributeAsUrlSpecifier({
|
|
316
|
-
type,
|
|
317
|
-
subtype,
|
|
318
|
-
expectedType,
|
|
319
|
-
node,
|
|
320
|
-
attributeName: "generated-from-href"
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
const visitSrcset = ({
|
|
326
|
-
type,
|
|
327
|
-
node
|
|
328
|
-
}) => {
|
|
329
|
-
const srcsetAttribute = getHtmlNodeAttributeByName(node, "srcset");
|
|
330
|
-
const srcset = srcsetAttribute ? srcsetAttribute.value : undefined;
|
|
331
|
-
|
|
332
|
-
if (srcset) {
|
|
333
|
-
const srcCandidates = htmlAttributeSrcSet.parse(srcset);
|
|
334
|
-
srcCandidates.forEach(srcCandidate => {
|
|
335
|
-
addDependency({
|
|
336
|
-
type,
|
|
337
|
-
node,
|
|
338
|
-
attribute: srcsetAttribute,
|
|
339
|
-
specifier: srcCandidate.specifier
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
visitHtmlAst(htmlAst, node => {
|
|
346
|
-
const visitor = visitors[node.nodeName];
|
|
347
|
-
|
|
348
|
-
if (visitor) {
|
|
349
|
-
visitor(node);
|
|
350
|
-
}
|
|
351
346
|
});
|
|
352
347
|
};
|
|
353
348
|
|
|
354
|
-
const crossOriginCompatibleTagNames = ["script", "link", "img", "source"];
|
|
355
|
-
const integrityCompatibleTagNames = ["script", "link", "img", "source"];
|
|
356
|
-
|
|
357
|
-
const readFetchMetas = node => {
|
|
358
|
-
const meta = {};
|
|
359
|
-
|
|
360
|
-
if (crossOriginCompatibleTagNames.includes(node.nodeName)) {
|
|
361
|
-
const crossoriginAttribute = getHtmlNodeAttributeByName(node, "crossorigin");
|
|
362
|
-
meta.crossorigin = crossoriginAttribute ? crossoriginAttribute.value : undefined;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
if (integrityCompatibleTagNames.includes(node.nodeName)) {
|
|
366
|
-
const integrityAttribute = getHtmlNodeAttributeByName(node, "integrity");
|
|
367
|
-
meta.integrity = integrityAttribute ? integrityAttribute.value : undefined;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
return meta;
|
|
371
|
-
};
|
|
372
|
-
|
|
373
349
|
/*
|
|
374
350
|
* https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/css/src/CSSTransformer.js
|
|
375
351
|
*/
|
|
@@ -745,14 +721,14 @@ const jsenvPluginImportmap = () => {
|
|
|
745
721
|
transformUrlContent: {
|
|
746
722
|
html: async (htmlUrlInfo, context) => {
|
|
747
723
|
const htmlAst = parseHtmlString(htmlUrlInfo.content);
|
|
748
|
-
const importmap =
|
|
724
|
+
const importmap = findHtmlNode(htmlAst, node => {
|
|
749
725
|
if (node.nodeName !== "script") {
|
|
750
726
|
return false;
|
|
751
727
|
}
|
|
752
728
|
|
|
753
|
-
const
|
|
729
|
+
const type = getHtmlNodeAttribute(node, "type");
|
|
754
730
|
|
|
755
|
-
if (
|
|
731
|
+
if (type === undefined || type !== "importmap") {
|
|
756
732
|
return false;
|
|
757
733
|
}
|
|
758
734
|
|
|
@@ -771,7 +747,7 @@ const jsenvPluginImportmap = () => {
|
|
|
771
747
|
lineEnd,
|
|
772
748
|
columnEnd,
|
|
773
749
|
isOriginal
|
|
774
|
-
} =
|
|
750
|
+
} = getHtmlNodePosition(importmap, {
|
|
775
751
|
preferOriginal: true
|
|
776
752
|
});
|
|
777
753
|
const inlineImportmapUrl = generateInlineContentUrl({
|
|
@@ -794,9 +770,9 @@ const jsenvPluginImportmap = () => {
|
|
|
794
770
|
await context.cook(inlineImportmapUrlInfo, {
|
|
795
771
|
reference: inlineImportmapReference
|
|
796
772
|
});
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
773
|
+
setHtmlNodeText(importmap, inlineImportmapUrlInfo.content);
|
|
774
|
+
setHtmlNodeAttributes(importmap, {
|
|
775
|
+
"generated-by": "jsenv:importmap"
|
|
800
776
|
});
|
|
801
777
|
onHtmlImportmapParsed(JSON.parse(inlineImportmapUrlInfo.content), htmlUrlInfo.url);
|
|
802
778
|
};
|
|
@@ -813,11 +789,11 @@ const jsenvPluginImportmap = () => {
|
|
|
813
789
|
reference: importmapReference
|
|
814
790
|
});
|
|
815
791
|
onHtmlImportmapParsed(JSON.parse(importmapUrlInfo.content), htmlUrlInfo.url);
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
792
|
+
setHtmlNodeText(importmap, importmapUrlInfo.content);
|
|
793
|
+
setHtmlNodeAttributes(importmap, {
|
|
794
|
+
"src": undefined,
|
|
795
|
+
"generated-by": "jsenv:importmap",
|
|
796
|
+
"generated-from-src": src
|
|
821
797
|
});
|
|
822
798
|
const {
|
|
823
799
|
line,
|
|
@@ -825,7 +801,7 @@ const jsenvPluginImportmap = () => {
|
|
|
825
801
|
lineEnd,
|
|
826
802
|
columnEnd,
|
|
827
803
|
isOriginal
|
|
828
|
-
} =
|
|
804
|
+
} = getHtmlNodePosition(importmap, {
|
|
829
805
|
preferOriginal: true
|
|
830
806
|
});
|
|
831
807
|
const inlineImportmapUrl = generateInlineContentUrl({
|
|
@@ -846,16 +822,15 @@ const jsenvPluginImportmap = () => {
|
|
|
846
822
|
});
|
|
847
823
|
};
|
|
848
824
|
|
|
849
|
-
const
|
|
850
|
-
const src = srcAttribute ? srcAttribute.value : undefined;
|
|
825
|
+
const src = getHtmlNodeAttribute(importmap, "src");
|
|
851
826
|
|
|
852
827
|
if (src) {
|
|
853
828
|
await handleImportmapWithSrc(importmap, src);
|
|
854
829
|
} else {
|
|
855
|
-
const
|
|
830
|
+
const htmlNodeText = getHtmlNodeText(importmap);
|
|
856
831
|
|
|
857
|
-
if (
|
|
858
|
-
await handleInlineImportmap(importmap,
|
|
832
|
+
if (htmlNodeText) {
|
|
833
|
+
await handleInlineImportmap(importmap, htmlNodeText);
|
|
859
834
|
}
|
|
860
835
|
} // once this plugin knows the importmap, it will use it
|
|
861
836
|
// to map imports. These import specifiers will be normalized
|
|
@@ -1104,7 +1079,7 @@ const jsenvPluginUrlVersion = () => {
|
|
|
1104
1079
|
const jsenvPluginFileUrls = ({
|
|
1105
1080
|
magicExtensions = ["inherit", ".js"],
|
|
1106
1081
|
magicDirectoryIndex = true,
|
|
1107
|
-
|
|
1082
|
+
preserveSymlinks = false,
|
|
1108
1083
|
directoryReferenceAllowed = false
|
|
1109
1084
|
}) => {
|
|
1110
1085
|
return [{
|
|
@@ -1159,7 +1134,7 @@ const jsenvPluginFileUrls = ({
|
|
|
1159
1134
|
if (foundADirectory && directoryReferenceAllowed) {
|
|
1160
1135
|
reference.data.foundADirectory = true;
|
|
1161
1136
|
const directoryFacadeUrl = urlObject.href;
|
|
1162
|
-
const directoryUrlRaw =
|
|
1137
|
+
const directoryUrlRaw = preserveSymlinks ? directoryFacadeUrl : resolveSymlink(directoryFacadeUrl);
|
|
1163
1138
|
const directoryUrl = `${directoryUrlRaw}${search}${hash}`;
|
|
1164
1139
|
return directoryUrl;
|
|
1165
1140
|
}
|
|
@@ -1178,7 +1153,7 @@ const jsenvPluginFileUrls = ({
|
|
|
1178
1153
|
|
|
1179
1154
|
reference.data.foundADirectory = filesystemResolution.isDirectory;
|
|
1180
1155
|
const fileFacadeUrl = filesystemResolution.url;
|
|
1181
|
-
const fileUrlRaw =
|
|
1156
|
+
const fileUrlRaw = preserveSymlinks ? fileFacadeUrl : resolveSymlink(fileFacadeUrl);
|
|
1182
1157
|
const fileUrl = `${fileUrlRaw}${search}${hash}`;
|
|
1183
1158
|
return fileUrl;
|
|
1184
1159
|
}
|
|
@@ -1298,13 +1273,9 @@ const jsenvPluginHtmlInlineContent = ({
|
|
|
1298
1273
|
const actions = [];
|
|
1299
1274
|
|
|
1300
1275
|
const handleInlineStyle = node => {
|
|
1301
|
-
|
|
1302
|
-
return;
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
const textNode = getHtmlNodeTextNode(node);
|
|
1276
|
+
const htmlNodeText = getHtmlNodeText(node);
|
|
1306
1277
|
|
|
1307
|
-
if (!
|
|
1278
|
+
if (!htmlNodeText) {
|
|
1308
1279
|
return;
|
|
1309
1280
|
}
|
|
1310
1281
|
|
|
@@ -1315,7 +1286,7 @@ const jsenvPluginHtmlInlineContent = ({
|
|
|
1315
1286
|
lineEnd,
|
|
1316
1287
|
columnEnd,
|
|
1317
1288
|
isOriginal
|
|
1318
|
-
} =
|
|
1289
|
+
} = getHtmlNodePosition(node, {
|
|
1319
1290
|
preferOriginal: true
|
|
1320
1291
|
});
|
|
1321
1292
|
const inlineStyleUrl = generateInlineContentUrl({
|
|
@@ -1337,55 +1308,47 @@ const jsenvPluginHtmlInlineContent = ({
|
|
|
1337
1308
|
specifierColumn: column,
|
|
1338
1309
|
specifier: inlineStyleUrl,
|
|
1339
1310
|
contentType: "text/css",
|
|
1340
|
-
content:
|
|
1311
|
+
content: htmlNodeText
|
|
1341
1312
|
});
|
|
1342
1313
|
await context.cook(inlineStyleUrlInfo, {
|
|
1343
1314
|
reference: inlineStyleReference
|
|
1344
1315
|
});
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1316
|
+
setHtmlNodeText(node, inlineStyleUrlInfo.content);
|
|
1317
|
+
setHtmlNodeAttributes(node, {
|
|
1318
|
+
"generated-by": "jsenv:html_inline_content"
|
|
1348
1319
|
});
|
|
1349
1320
|
});
|
|
1350
1321
|
};
|
|
1351
1322
|
|
|
1352
1323
|
const handleInlineScript = node => {
|
|
1353
|
-
|
|
1354
|
-
return;
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
const textNode = getHtmlNodeTextNode(node);
|
|
1324
|
+
const htmlNodeText = getHtmlNodeText(node);
|
|
1358
1325
|
|
|
1359
|
-
if (!
|
|
1326
|
+
if (!htmlNodeText) {
|
|
1360
1327
|
return;
|
|
1361
1328
|
} // If the inline script was already handled by an other plugin, ignore it
|
|
1362
1329
|
// - we want to preserve inline scripts generated by html supervisor during dev
|
|
1363
1330
|
// - we want to avoid cooking twice a script during build
|
|
1364
1331
|
|
|
1365
1332
|
|
|
1366
|
-
const generatedBy =
|
|
1333
|
+
const generatedBy = getHtmlNodeAttribute(node, "generated-by");
|
|
1367
1334
|
|
|
1368
|
-
if (generatedBy) {
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
return;
|
|
1372
|
-
}
|
|
1373
|
-
}
|
|
1335
|
+
if (generatedBy === "jsenv:as_js_classic_html" && !analyzeConvertedScripts) {
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1374
1338
|
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
}
|
|
1339
|
+
if (generatedBy === "jsenv:html_supervisor") {
|
|
1340
|
+
return;
|
|
1378
1341
|
}
|
|
1379
1342
|
|
|
1380
1343
|
actions.push(async () => {
|
|
1381
|
-
const scriptCategory =
|
|
1344
|
+
const scriptCategory = analyzeScriptNode(node);
|
|
1382
1345
|
const {
|
|
1383
1346
|
line,
|
|
1384
1347
|
column,
|
|
1385
1348
|
lineEnd,
|
|
1386
1349
|
columnEnd,
|
|
1387
1350
|
isOriginal
|
|
1388
|
-
} =
|
|
1351
|
+
} = getHtmlNodePosition(node, {
|
|
1389
1352
|
preferOriginal: true
|
|
1390
1353
|
}); // from MDN about [type] attribute:
|
|
1391
1354
|
// "Any other value: The embedded content is treated as a data block
|
|
@@ -1421,21 +1384,25 @@ const jsenvPluginHtmlInlineContent = ({
|
|
|
1421
1384
|
isOriginalPosition: isOriginal,
|
|
1422
1385
|
specifier: inlineScriptUrl,
|
|
1423
1386
|
contentType,
|
|
1424
|
-
content:
|
|
1387
|
+
content: htmlNodeText
|
|
1425
1388
|
});
|
|
1426
1389
|
await context.cook(inlineScriptUrlInfo, {
|
|
1427
1390
|
reference: inlineScriptReference
|
|
1428
1391
|
});
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1392
|
+
setHtmlNodeText(node, inlineScriptUrlInfo.content);
|
|
1393
|
+
setHtmlNodeAttributes(node, {
|
|
1394
|
+
"generated-by": "jsenv:html_inline_content"
|
|
1432
1395
|
});
|
|
1433
1396
|
});
|
|
1434
1397
|
};
|
|
1435
1398
|
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1399
|
+
visitHtmlNodes(htmlAst, {
|
|
1400
|
+
style: node => {
|
|
1401
|
+
handleInlineStyle(node);
|
|
1402
|
+
},
|
|
1403
|
+
script: node => {
|
|
1404
|
+
handleInlineScript(node);
|
|
1405
|
+
}
|
|
1439
1406
|
});
|
|
1440
1407
|
|
|
1441
1408
|
if (actions.length === 0) {
|
|
@@ -1975,15 +1942,15 @@ const jsenvPluginHtmlSupervisor = ({
|
|
|
1975
1942
|
const htmlAst = parseHtmlString(content);
|
|
1976
1943
|
const scriptsToSupervise = [];
|
|
1977
1944
|
|
|
1978
|
-
const handleInlineScript = (node,
|
|
1979
|
-
const scriptCategory =
|
|
1945
|
+
const handleInlineScript = (node, htmlNodeText) => {
|
|
1946
|
+
const scriptCategory = analyzeScriptNode(node);
|
|
1980
1947
|
const {
|
|
1981
1948
|
line,
|
|
1982
1949
|
column,
|
|
1983
1950
|
lineEnd,
|
|
1984
1951
|
columnEnd,
|
|
1985
1952
|
isOriginal
|
|
1986
|
-
} =
|
|
1953
|
+
} = getHtmlNodePosition(node, {
|
|
1987
1954
|
preferOriginal: true
|
|
1988
1955
|
});
|
|
1989
1956
|
let inlineScriptUrl = generateInlineContentUrl({
|
|
@@ -2005,7 +1972,7 @@ const jsenvPluginHtmlSupervisor = ({
|
|
|
2005
1972
|
specifierColumn: column,
|
|
2006
1973
|
specifier: inlineScriptUrl,
|
|
2007
1974
|
contentType: "text/javascript",
|
|
2008
|
-
content:
|
|
1975
|
+
content: htmlNodeText
|
|
2009
1976
|
});
|
|
2010
1977
|
removeHtmlNodeText(node);
|
|
2011
1978
|
scriptsToSupervise.push({
|
|
@@ -2016,21 +1983,19 @@ const jsenvPluginHtmlSupervisor = ({
|
|
|
2016
1983
|
});
|
|
2017
1984
|
};
|
|
2018
1985
|
|
|
2019
|
-
const handleScriptWithSrc = (node,
|
|
2020
|
-
const scriptCategory =
|
|
2021
|
-
const
|
|
2022
|
-
const
|
|
2023
|
-
const
|
|
2024
|
-
const
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
const async = asyncAttribute ? asyncAttribute.value : undefined;
|
|
2029
|
-
removeHtmlNodeAttributeByName(node, "src");
|
|
1986
|
+
const handleScriptWithSrc = (node, src) => {
|
|
1987
|
+
const scriptCategory = analyzeScriptNode(node);
|
|
1988
|
+
const integrity = getHtmlNodeAttribute(node, "integrity");
|
|
1989
|
+
const crossorigin = getHtmlNodeAttribute(node, "crossorigin") !== undefined;
|
|
1990
|
+
const defer = getHtmlNodeAttribute(node, "defer") !== undefined;
|
|
1991
|
+
const async = getHtmlNodeAttribute(node, "async") !== undefined;
|
|
1992
|
+
setHtmlNodeAttributes(node, {
|
|
1993
|
+
src: undefined
|
|
1994
|
+
});
|
|
2030
1995
|
scriptsToSupervise.push({
|
|
2031
1996
|
node,
|
|
2032
1997
|
type: scriptCategory,
|
|
2033
|
-
src
|
|
1998
|
+
src,
|
|
2034
1999
|
defer,
|
|
2035
2000
|
async,
|
|
2036
2001
|
integrity,
|
|
@@ -2038,41 +2003,39 @@ const jsenvPluginHtmlSupervisor = ({
|
|
|
2038
2003
|
});
|
|
2039
2004
|
};
|
|
2040
2005
|
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
}
|
|
2045
|
-
|
|
2046
|
-
const scriptCategory = parseScriptNode(node);
|
|
2006
|
+
visitHtmlNodes(htmlAst, {
|
|
2007
|
+
script: node => {
|
|
2008
|
+
const scriptCategory = analyzeScriptNode(node);
|
|
2047
2009
|
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2010
|
+
if (scriptCategory !== "classic" && scriptCategory !== "module") {
|
|
2011
|
+
return;
|
|
2012
|
+
}
|
|
2051
2013
|
|
|
2052
|
-
|
|
2014
|
+
const injectedBy = getHtmlNodeAttribute(node, "injected-by");
|
|
2053
2015
|
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2016
|
+
if (injectedBy !== undefined) {
|
|
2017
|
+
return;
|
|
2018
|
+
}
|
|
2057
2019
|
|
|
2058
|
-
|
|
2020
|
+
const noHtmlSupervisor = getHtmlNodeAttribute(node, "no-html-supervisor");
|
|
2059
2021
|
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2022
|
+
if (noHtmlSupervisor !== undefined) {
|
|
2023
|
+
return;
|
|
2024
|
+
}
|
|
2063
2025
|
|
|
2064
|
-
|
|
2026
|
+
const htmlNodeText = getHtmlNodeText(node);
|
|
2065
2027
|
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2028
|
+
if (htmlNodeText) {
|
|
2029
|
+
handleInlineScript(node, htmlNodeText);
|
|
2030
|
+
return;
|
|
2031
|
+
}
|
|
2070
2032
|
|
|
2071
|
-
|
|
2033
|
+
const src = getHtmlNodeAttribute(node, "src");
|
|
2072
2034
|
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2035
|
+
if (src) {
|
|
2036
|
+
handleScriptWithSrc(node, src);
|
|
2037
|
+
return;
|
|
2038
|
+
}
|
|
2076
2039
|
}
|
|
2077
2040
|
});
|
|
2078
2041
|
const [htmlSupervisorInstallerFileReference] = referenceUtils.inject({
|
|
@@ -2080,7 +2043,7 @@ const jsenvPluginHtmlSupervisor = ({
|
|
|
2080
2043
|
expectedType: "js_module",
|
|
2081
2044
|
specifier: htmlSupervisorInstallerFileUrl
|
|
2082
2045
|
});
|
|
2083
|
-
|
|
2046
|
+
injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
|
|
2084
2047
|
"tagName": "script",
|
|
2085
2048
|
"type": "module",
|
|
2086
2049
|
"textContent": `
|
|
@@ -2096,7 +2059,7 @@ const jsenvPluginHtmlSupervisor = ({
|
|
|
2096
2059
|
expectedType: "js_classic",
|
|
2097
2060
|
specifier: htmlSupervisorSetupFileUrl
|
|
2098
2061
|
});
|
|
2099
|
-
|
|
2062
|
+
injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
|
|
2100
2063
|
"tagName": "script",
|
|
2101
2064
|
"src": htmlSupervisorSetupFileReference.generatedSpecifier,
|
|
2102
2065
|
"injected-by": "jsenv:html_supervisor"
|
|
@@ -2111,20 +2074,24 @@ const jsenvPluginHtmlSupervisor = ({
|
|
|
2111
2074
|
integrity,
|
|
2112
2075
|
crossorigin
|
|
2113
2076
|
}) => {
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2077
|
+
setHtmlNodeText(node, generateCodeToSuperviseScript({
|
|
2078
|
+
type,
|
|
2079
|
+
src,
|
|
2080
|
+
isInline,
|
|
2081
|
+
defer,
|
|
2082
|
+
async,
|
|
2083
|
+
integrity,
|
|
2084
|
+
crossorigin,
|
|
2085
|
+
htmlSupervisorInstallerSpecifier: htmlSupervisorInstallerFileReference.generatedSpecifier
|
|
2086
|
+
}));
|
|
2087
|
+
setHtmlNodeAttributes(node, {
|
|
2088
|
+
"generated-by": "jsenv:html_supervisor",
|
|
2089
|
+
...(src ? {
|
|
2090
|
+
"generated-from-src": src
|
|
2091
|
+
} : {}),
|
|
2092
|
+
...(isInline ? {
|
|
2093
|
+
"generated-from-inline-content": ""
|
|
2094
|
+
} : {})
|
|
2128
2095
|
});
|
|
2129
2096
|
});
|
|
2130
2097
|
const htmlModified = stringifyHtmlAst(htmlAst);
|
|
@@ -2739,12 +2706,7 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
2739
2706
|
const classicScriptNodes = [];
|
|
2740
2707
|
|
|
2741
2708
|
const visitLinkNodes = node => {
|
|
2742
|
-
|
|
2743
|
-
return;
|
|
2744
|
-
}
|
|
2745
|
-
|
|
2746
|
-
const relAttribute = getHtmlNodeAttributeByName(node, "rel");
|
|
2747
|
-
const rel = relAttribute ? relAttribute.value : undefined;
|
|
2709
|
+
const rel = getHtmlNodeAttribute(node, "rel");
|
|
2748
2710
|
|
|
2749
2711
|
if (rel === "modulepreload") {
|
|
2750
2712
|
modulePreloadNodes.push(node);
|
|
@@ -2752,8 +2714,7 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
2752
2714
|
}
|
|
2753
2715
|
|
|
2754
2716
|
if (rel === "preload") {
|
|
2755
|
-
const
|
|
2756
|
-
const asValue = asAttribute ? asAttribute.value : undefined;
|
|
2717
|
+
const asValue = getHtmlNodeAttribute(node, "as");
|
|
2757
2718
|
|
|
2758
2719
|
if (asValue === "script") {
|
|
2759
2720
|
preloadAsScriptNodes.push(node);
|
|
@@ -2764,12 +2725,7 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
2764
2725
|
};
|
|
2765
2726
|
|
|
2766
2727
|
const visitScriptNodes = node => {
|
|
2767
|
-
|
|
2768
|
-
return;
|
|
2769
|
-
}
|
|
2770
|
-
|
|
2771
|
-
const typeAttribute = getHtmlNodeAttributeByName(node, "type");
|
|
2772
|
-
const type = typeAttribute ? typeAttribute.value : undefined;
|
|
2728
|
+
const type = getHtmlNodeAttribute(node, "type");
|
|
2773
2729
|
|
|
2774
2730
|
if (type === "module") {
|
|
2775
2731
|
moduleScriptNodes.push(node);
|
|
@@ -2782,9 +2738,13 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
2782
2738
|
}
|
|
2783
2739
|
};
|
|
2784
2740
|
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2741
|
+
visitHtmlNodes(htmlAst, {
|
|
2742
|
+
link: node => {
|
|
2743
|
+
visitLinkNodes(node);
|
|
2744
|
+
},
|
|
2745
|
+
script: node => {
|
|
2746
|
+
visitScriptNodes(node);
|
|
2747
|
+
}
|
|
2788
2748
|
});
|
|
2789
2749
|
const actions = [];
|
|
2790
2750
|
const jsModuleUrls = [];
|
|
@@ -2826,10 +2786,10 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
2826
2786
|
};
|
|
2827
2787
|
|
|
2828
2788
|
classicScriptNodes.forEach(classicScriptNode => {
|
|
2829
|
-
const
|
|
2789
|
+
const src = getHtmlNodeAttribute(classicScriptNode, "src");
|
|
2830
2790
|
|
|
2831
|
-
if (
|
|
2832
|
-
const reference = urlInfo.references.find(ref => ref.generatedSpecifier ===
|
|
2791
|
+
if (src !== undefined) {
|
|
2792
|
+
const reference = urlInfo.references.find(ref => ref.generatedSpecifier === src && ref.type === "script_src");
|
|
2833
2793
|
const urlObject = new URL(reference.url);
|
|
2834
2794
|
|
|
2835
2795
|
if (urlObject.searchParams.has("as_js_classic")) {
|
|
@@ -2848,10 +2808,10 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
2848
2808
|
}
|
|
2849
2809
|
});
|
|
2850
2810
|
moduleScriptNodes.forEach(moduleScriptNode => {
|
|
2851
|
-
const
|
|
2811
|
+
const src = getHtmlNodeAttribute(moduleScriptNode, "src");
|
|
2852
2812
|
|
|
2853
|
-
if (
|
|
2854
|
-
const reference = urlInfo.references.find(ref => ref.generatedSpecifier ===
|
|
2813
|
+
if (src !== undefined) {
|
|
2814
|
+
const reference = urlInfo.references.find(ref => ref.generatedSpecifier === src && ref.type === "script_src" && ref.expectedType === "js_module");
|
|
2855
2815
|
jsModuleUrls.push(reference.url);
|
|
2856
2816
|
|
|
2857
2817
|
if (shouldTransformScriptTypeModule) {
|
|
@@ -2859,8 +2819,10 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
2859
2819
|
const [newReference] = await getReferenceAsJsClassic(reference, {
|
|
2860
2820
|
cookIt: true
|
|
2861
2821
|
});
|
|
2862
|
-
|
|
2863
|
-
|
|
2822
|
+
setHtmlNodeAttributes(moduleScriptNode, {
|
|
2823
|
+
type: undefined,
|
|
2824
|
+
src: newReference.generatedSpecifier
|
|
2825
|
+
});
|
|
2864
2826
|
});
|
|
2865
2827
|
}
|
|
2866
2828
|
|
|
@@ -2868,7 +2830,7 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
2868
2830
|
}
|
|
2869
2831
|
|
|
2870
2832
|
if (shouldTransformScriptTypeModule) {
|
|
2871
|
-
const
|
|
2833
|
+
const htmlNodeText = getHtmlNodeText(moduleScriptNode);
|
|
2872
2834
|
actions.push(async () => {
|
|
2873
2835
|
const {
|
|
2874
2836
|
line,
|
|
@@ -2876,7 +2838,7 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
2876
2838
|
lineEnd,
|
|
2877
2839
|
columnEnd,
|
|
2878
2840
|
isOriginal
|
|
2879
|
-
} =
|
|
2841
|
+
} = getHtmlNodePosition(moduleScriptNode, {
|
|
2880
2842
|
preferOriginal: true
|
|
2881
2843
|
});
|
|
2882
2844
|
let inlineScriptUrl = generateInlineContentUrl({
|
|
@@ -2899,15 +2861,15 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
2899
2861
|
specifierColumn: column,
|
|
2900
2862
|
specifier: inlineScriptUrl,
|
|
2901
2863
|
contentType: "text/javascript",
|
|
2902
|
-
content:
|
|
2864
|
+
content: htmlNodeText
|
|
2903
2865
|
});
|
|
2904
2866
|
const [, newUrlInfo] = await getReferenceAsJsClassic(inlineReference, {
|
|
2905
2867
|
cookIt: true
|
|
2906
2868
|
});
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2869
|
+
setHtmlNodeText(moduleScriptNode, newUrlInfo.content);
|
|
2870
|
+
setHtmlNodeAttributes(moduleScriptNode, {
|
|
2871
|
+
"type": undefined,
|
|
2872
|
+
"generated-by": "jsenv:as_js_classic_html"
|
|
2911
2873
|
});
|
|
2912
2874
|
});
|
|
2913
2875
|
}
|
|
@@ -2915,8 +2877,7 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
2915
2877
|
|
|
2916
2878
|
if (shouldTransformScriptTypeModule) {
|
|
2917
2879
|
preloadAsScriptNodes.forEach(preloadAsScriptNode => {
|
|
2918
|
-
const
|
|
2919
|
-
const href = hrefAttribute.value;
|
|
2880
|
+
const href = getHtmlNodeAttribute(preloadAsScriptNode, "href");
|
|
2920
2881
|
const reference = urlInfo.references.find(ref => ref.generatedSpecifier === href && ref.type === "link_href" && ref.expectedType === undefined);
|
|
2921
2882
|
const expectedScriptType = jsModuleUrls.includes(reference.url) ? "module" : "classic";
|
|
2922
2883
|
|
|
@@ -2931,16 +2892,15 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
2931
2892
|
[newReference] = await getReferenceAsJsClassic(reference);
|
|
2932
2893
|
}
|
|
2933
2894
|
|
|
2934
|
-
|
|
2935
|
-
href: newReference.generatedSpecifier
|
|
2895
|
+
setHtmlNodeAttributes(preloadAsScriptNode, {
|
|
2896
|
+
href: newReference.generatedSpecifier,
|
|
2897
|
+
crossorigin: undefined
|
|
2936
2898
|
});
|
|
2937
|
-
removeHtmlNodeAttributeByName(preloadAsScriptNode, "crossorigin");
|
|
2938
2899
|
});
|
|
2939
2900
|
}
|
|
2940
2901
|
});
|
|
2941
2902
|
modulePreloadNodes.forEach(modulePreloadNode => {
|
|
2942
|
-
const
|
|
2943
|
-
const href = hrefAttribute.value;
|
|
2903
|
+
const href = getHtmlNodeAttribute(modulePreloadNode, "href");
|
|
2944
2904
|
const reference = urlInfo.references.find(ref => ref.generatedSpecifier === href && ref.type === "link_href" && ref.expectedType === "js_module");
|
|
2945
2905
|
actions.push(async () => {
|
|
2946
2906
|
let newReference;
|
|
@@ -2951,7 +2911,7 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
2951
2911
|
[newReference] = await getReferenceAsJsClassic(reference);
|
|
2952
2912
|
}
|
|
2953
2913
|
|
|
2954
|
-
|
|
2914
|
+
setHtmlNodeAttributes(modulePreloadNode, {
|
|
2955
2915
|
rel: "preload",
|
|
2956
2916
|
as: "script",
|
|
2957
2917
|
href: newReference.generatedSpecifier
|
|
@@ -2975,7 +2935,7 @@ const jsenvPluginAsJsClassicHtml = ({
|
|
|
2975
2935
|
expectedType: "js_classic",
|
|
2976
2936
|
specifier: systemJsClientFileUrl
|
|
2977
2937
|
});
|
|
2978
|
-
|
|
2938
|
+
injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
|
|
2979
2939
|
"tagName": "script",
|
|
2980
2940
|
"src": systemJsReference.generatedSpecifier,
|
|
2981
2941
|
"injected-by": "jsenv:as_js_classic_html"
|
|
@@ -4054,7 +4014,7 @@ const babelPluginBabelHelpersAsJsenvImports = (babel, {
|
|
|
4054
4014
|
}
|
|
4055
4015
|
|
|
4056
4016
|
const babelHelperImportSpecifier = getBabelHelperFileUrl(name);
|
|
4057
|
-
const helper =
|
|
4017
|
+
const helper = injectJsImport({
|
|
4058
4018
|
programPath: file.path,
|
|
4059
4019
|
from: getImportSpecifier(babelHelperImportSpecifier),
|
|
4060
4020
|
nameHint: `_${name}`,
|
|
@@ -4157,7 +4117,7 @@ const babelPluginNewStylesheetAsJsenvImport = (babel, {
|
|
|
4157
4117
|
});
|
|
4158
4118
|
|
|
4159
4119
|
if (usesNewStylesheet) {
|
|
4160
|
-
|
|
4120
|
+
injectJsImport({
|
|
4161
4121
|
programPath,
|
|
4162
4122
|
from: getImportSpecifier(newStylesheetClientFileUrl),
|
|
4163
4123
|
sideEffect: true
|
|
@@ -4222,7 +4182,7 @@ const babelPluginGlobalThisAsJsenvImport = (babel, {
|
|
|
4222
4182
|
} = path; // we should do this once, tree shaking will remote it but still
|
|
4223
4183
|
|
|
4224
4184
|
if (node.name === "globalThis") {
|
|
4225
|
-
|
|
4185
|
+
injectJsImport({
|
|
4226
4186
|
programPath: path.scope.getProgramParent().path,
|
|
4227
4187
|
from: getImportSpecifier(globalThisClientFileUrl),
|
|
4228
4188
|
sideEffect: true
|
|
@@ -4256,7 +4216,7 @@ const babelPluginRegeneratorRuntimeAsJsenvImport = (babel, {
|
|
|
4256
4216
|
} = path;
|
|
4257
4217
|
|
|
4258
4218
|
if (node.name === "regeneratorRuntime") {
|
|
4259
|
-
|
|
4219
|
+
injectJsImport({
|
|
4260
4220
|
programPath: path.scope.getProgramParent().path,
|
|
4261
4221
|
from: getImportSpecifier(regeneratorRuntimeClientFileUrl),
|
|
4262
4222
|
sideEffect: true
|
|
@@ -4750,71 +4710,6 @@ const bundleJsModule = async ({
|
|
|
4750
4710
|
});
|
|
4751
4711
|
return jsModuleBundleUrlInfos;
|
|
4752
4712
|
};
|
|
4753
|
-
const buildWithRollup = async ({
|
|
4754
|
-
signal,
|
|
4755
|
-
logger,
|
|
4756
|
-
rootDirectoryUrl,
|
|
4757
|
-
buildDirectoryUrl,
|
|
4758
|
-
urlGraph,
|
|
4759
|
-
jsModuleUrlInfos,
|
|
4760
|
-
runtimeCompat,
|
|
4761
|
-
sourcemaps,
|
|
4762
|
-
include,
|
|
4763
|
-
babelHelpersChunk
|
|
4764
|
-
}) => {
|
|
4765
|
-
const resultRef = {
|
|
4766
|
-
current: null
|
|
4767
|
-
};
|
|
4768
|
-
|
|
4769
|
-
try {
|
|
4770
|
-
await applyRollupPlugins({
|
|
4771
|
-
rollupPlugins: [rollupPluginJsenv({
|
|
4772
|
-
signal,
|
|
4773
|
-
logger,
|
|
4774
|
-
rootDirectoryUrl,
|
|
4775
|
-
buildDirectoryUrl,
|
|
4776
|
-
urlGraph,
|
|
4777
|
-
jsModuleUrlInfos,
|
|
4778
|
-
runtimeCompat,
|
|
4779
|
-
sourcemaps,
|
|
4780
|
-
include,
|
|
4781
|
-
babelHelpersChunk,
|
|
4782
|
-
resultRef
|
|
4783
|
-
})],
|
|
4784
|
-
inputOptions: {
|
|
4785
|
-
input: [],
|
|
4786
|
-
onwarn: warning => {
|
|
4787
|
-
if (warning.code === "CIRCULAR_DEPENDENCY") {
|
|
4788
|
-
return;
|
|
4789
|
-
}
|
|
4790
|
-
|
|
4791
|
-
if (warning.code === "THIS_IS_UNDEFINED" && pathToFileURL(warning.id).href === globalThisClientFileUrl) {
|
|
4792
|
-
return;
|
|
4793
|
-
}
|
|
4794
|
-
|
|
4795
|
-
if (warning.code === "EVAL") {
|
|
4796
|
-
// ideally we should disable only for jsenv files
|
|
4797
|
-
return;
|
|
4798
|
-
}
|
|
4799
|
-
|
|
4800
|
-
logger.warn(String(warning));
|
|
4801
|
-
}
|
|
4802
|
-
}
|
|
4803
|
-
});
|
|
4804
|
-
return resultRef.current;
|
|
4805
|
-
} catch (e) {
|
|
4806
|
-
if (e.code === "MISSING_EXPORT") {
|
|
4807
|
-
const detailedMessage = createDetailedMessage(e.message, {
|
|
4808
|
-
frame: e.frame
|
|
4809
|
-
});
|
|
4810
|
-
throw new Error(detailedMessage, {
|
|
4811
|
-
cause: e
|
|
4812
|
-
});
|
|
4813
|
-
}
|
|
4814
|
-
|
|
4815
|
-
throw e;
|
|
4816
|
-
}
|
|
4817
|
-
};
|
|
4818
4713
|
|
|
4819
4714
|
const rollupPluginJsenv = ({
|
|
4820
4715
|
// logger,
|
|
@@ -5040,6 +4935,91 @@ const rollupPluginJsenv = ({
|
|
|
5040
4935
|
};
|
|
5041
4936
|
};
|
|
5042
4937
|
|
|
4938
|
+
const buildWithRollup = async ({
|
|
4939
|
+
signal,
|
|
4940
|
+
logger,
|
|
4941
|
+
rootDirectoryUrl,
|
|
4942
|
+
buildDirectoryUrl,
|
|
4943
|
+
urlGraph,
|
|
4944
|
+
jsModuleUrlInfos,
|
|
4945
|
+
runtimeCompat,
|
|
4946
|
+
sourcemaps,
|
|
4947
|
+
include,
|
|
4948
|
+
babelHelpersChunk
|
|
4949
|
+
}) => {
|
|
4950
|
+
const resultRef = {
|
|
4951
|
+
current: null
|
|
4952
|
+
};
|
|
4953
|
+
|
|
4954
|
+
try {
|
|
4955
|
+
await applyRollupPlugins({
|
|
4956
|
+
rollupPlugins: [rollupPluginJsenv({
|
|
4957
|
+
signal,
|
|
4958
|
+
logger,
|
|
4959
|
+
rootDirectoryUrl,
|
|
4960
|
+
buildDirectoryUrl,
|
|
4961
|
+
urlGraph,
|
|
4962
|
+
jsModuleUrlInfos,
|
|
4963
|
+
runtimeCompat,
|
|
4964
|
+
sourcemaps,
|
|
4965
|
+
include,
|
|
4966
|
+
babelHelpersChunk,
|
|
4967
|
+
resultRef
|
|
4968
|
+
})],
|
|
4969
|
+
inputOptions: {
|
|
4970
|
+
input: [],
|
|
4971
|
+
onwarn: warning => {
|
|
4972
|
+
if (warning.code === "CIRCULAR_DEPENDENCY") {
|
|
4973
|
+
return;
|
|
4974
|
+
}
|
|
4975
|
+
|
|
4976
|
+
if (warning.code === "THIS_IS_UNDEFINED" && pathToFileURL(warning.id).href === globalThisClientFileUrl) {
|
|
4977
|
+
return;
|
|
4978
|
+
}
|
|
4979
|
+
|
|
4980
|
+
if (warning.code === "EVAL") {
|
|
4981
|
+
// ideally we should disable only for jsenv files
|
|
4982
|
+
return;
|
|
4983
|
+
}
|
|
4984
|
+
|
|
4985
|
+
logger.warn(String(warning));
|
|
4986
|
+
}
|
|
4987
|
+
}
|
|
4988
|
+
});
|
|
4989
|
+
return resultRef.current;
|
|
4990
|
+
} catch (e) {
|
|
4991
|
+
if (e.code === "MISSING_EXPORT") {
|
|
4992
|
+
const detailedMessage = createDetailedMessage(e.message, {
|
|
4993
|
+
frame: e.frame
|
|
4994
|
+
});
|
|
4995
|
+
throw new Error(detailedMessage, {
|
|
4996
|
+
cause: e
|
|
4997
|
+
});
|
|
4998
|
+
}
|
|
4999
|
+
|
|
5000
|
+
throw e;
|
|
5001
|
+
}
|
|
5002
|
+
};
|
|
5003
|
+
|
|
5004
|
+
const applyRollupPlugins = async ({
|
|
5005
|
+
rollupPlugins,
|
|
5006
|
+
inputOptions = {},
|
|
5007
|
+
outputOptions = {}
|
|
5008
|
+
}) => {
|
|
5009
|
+
const {
|
|
5010
|
+
rollup
|
|
5011
|
+
} = await import("rollup");
|
|
5012
|
+
const {
|
|
5013
|
+
importAssertions
|
|
5014
|
+
} = await import("acorn-import-assertions");
|
|
5015
|
+
const rollupReturnValue = await rollup({ ...inputOptions,
|
|
5016
|
+
plugins: rollupPlugins,
|
|
5017
|
+
acornInjectPlugins: [importAssertions, ...(inputOptions.acornInjectPlugins || [])]
|
|
5018
|
+
});
|
|
5019
|
+
const rollupOutputArray = await rollupReturnValue.generate(outputOptions);
|
|
5020
|
+
return rollupOutputArray;
|
|
5021
|
+
};
|
|
5022
|
+
|
|
5043
5023
|
const willBeInsideJsDirectory = ({
|
|
5044
5024
|
chunkInfo,
|
|
5045
5025
|
fileUrlConverter,
|
|
@@ -5282,8 +5262,7 @@ const collectHotDataFromHtmlAst = htmlAst => {
|
|
|
5282
5262
|
attributeName,
|
|
5283
5263
|
hotAccepted
|
|
5284
5264
|
}) => {
|
|
5285
|
-
const
|
|
5286
|
-
const value = attribute ? attribute.value : undefined;
|
|
5265
|
+
const value = getHtmlNodeAttribute(node, attributeName);
|
|
5287
5266
|
|
|
5288
5267
|
if (value) {
|
|
5289
5268
|
onSpecifier({
|
|
@@ -5330,11 +5309,10 @@ const collectHotDataFromHtmlAst = htmlAst => {
|
|
|
5330
5309
|
}
|
|
5331
5310
|
|
|
5332
5311
|
if (nodeNamesWithSrcset.includes(node.nodeName)) {
|
|
5333
|
-
const
|
|
5334
|
-
const srcset = srcsetAttribute ? srcsetAttribute.value : undefined;
|
|
5312
|
+
const srcset = getHtmlNodeAttribute(node, "srcset");
|
|
5335
5313
|
|
|
5336
5314
|
if (srcset) {
|
|
5337
|
-
const srcCandidates =
|
|
5315
|
+
const srcCandidates = parseSrcSet(srcset);
|
|
5338
5316
|
srcCandidates.forEach(srcCandidate => {
|
|
5339
5317
|
onSpecifier({
|
|
5340
5318
|
node,
|
|
@@ -5375,15 +5353,15 @@ const nodeNamesWithSrcset = ["img", "source"];
|
|
|
5375
5353
|
|
|
5376
5354
|
const getNodeContext = node => {
|
|
5377
5355
|
const context = {};
|
|
5378
|
-
const
|
|
5356
|
+
const hotAccept = getHtmlNodeAttribute(node, "hot-accept");
|
|
5379
5357
|
|
|
5380
|
-
if (
|
|
5358
|
+
if (hotAccept !== undefined) {
|
|
5381
5359
|
context.hotAccepted = true;
|
|
5382
5360
|
}
|
|
5383
5361
|
|
|
5384
|
-
const
|
|
5362
|
+
const hotDecline = getHtmlNodeAttribute(node, "hot-decline");
|
|
5385
5363
|
|
|
5386
|
-
if (
|
|
5364
|
+
if (hotDecline !== undefined) {
|
|
5387
5365
|
context.hotAccepted = false;
|
|
5388
5366
|
}
|
|
5389
5367
|
|
|
@@ -5396,7 +5374,7 @@ const htmlNodeCanHotReload = node => {
|
|
|
5396
5374
|
isStylesheet,
|
|
5397
5375
|
isRessourceHint,
|
|
5398
5376
|
rel
|
|
5399
|
-
} =
|
|
5377
|
+
} = analyzeLinkNode(node);
|
|
5400
5378
|
|
|
5401
5379
|
if (isStylesheet) {
|
|
5402
5380
|
// stylesheets can be hot replaced by default
|
|
@@ -5696,7 +5674,7 @@ const jsenvPluginDevSSEClient = () => {
|
|
|
5696
5674
|
expectedType: "js_module",
|
|
5697
5675
|
specifier: eventSourceClientFileUrl
|
|
5698
5676
|
});
|
|
5699
|
-
|
|
5677
|
+
injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
|
|
5700
5678
|
"tagName": "script",
|
|
5701
5679
|
"type": "module",
|
|
5702
5680
|
"src": eventSourceClientReference.generatedSpecifier,
|
|
@@ -7803,6 +7781,8 @@ const memoizeCook = cook => {
|
|
|
7803
7781
|
const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
|
|
7804
7782
|
if (reference.shouldHandle) {
|
|
7805
7783
|
urlInfo.shouldHandle = true;
|
|
7784
|
+
} else {
|
|
7785
|
+
urlInfo.shouldHandle = false;
|
|
7806
7786
|
}
|
|
7807
7787
|
|
|
7808
7788
|
urlInfo.originalUrl = urlInfo.originalUrl || reference.url;
|
|
@@ -12366,7 +12346,7 @@ const injectors = {
|
|
|
12366
12346
|
const htmlAst = parseHtmlString(urlInfo.content, {
|
|
12367
12347
|
storeOriginalPositions: false
|
|
12368
12348
|
});
|
|
12369
|
-
|
|
12349
|
+
injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
|
|
12370
12350
|
"tagName": "script",
|
|
12371
12351
|
"textContent": generateClientCodeForVersionMappings(versionMappings, {
|
|
12372
12352
|
globalName: "window"
|
|
@@ -12494,15 +12474,12 @@ const resyncRessourceHints = async ({
|
|
|
12494
12474
|
});
|
|
12495
12475
|
const actions = [];
|
|
12496
12476
|
|
|
12497
|
-
const visitLinkWithHref = (linkNode,
|
|
12498
|
-
const href = hrefAttribute.value;
|
|
12499
|
-
|
|
12477
|
+
const visitLinkWithHref = (linkNode, href) => {
|
|
12500
12478
|
if (!href || href.startsWith("data:")) {
|
|
12501
12479
|
return;
|
|
12502
12480
|
}
|
|
12503
12481
|
|
|
12504
|
-
const
|
|
12505
|
-
const rel = relAttribute ? relAttribute.value : undefined;
|
|
12482
|
+
const rel = getHtmlNodeAttribute(linkNode, "rel");
|
|
12506
12483
|
const isRessourceHint = ["preconnect", "dns-prefetch", "prefetch", "preload", "modulepreload"].includes(rel);
|
|
12507
12484
|
|
|
12508
12485
|
if (!isRessourceHint) {
|
|
@@ -12546,22 +12523,20 @@ const resyncRessourceHints = async ({
|
|
|
12546
12523
|
}
|
|
12547
12524
|
|
|
12548
12525
|
actions.push(() => {
|
|
12549
|
-
|
|
12526
|
+
setHtmlNodeAttributes(linkNode, {
|
|
12527
|
+
href: urlInfo.data.buildUrlSpecifier
|
|
12528
|
+
});
|
|
12550
12529
|
});
|
|
12551
12530
|
};
|
|
12552
12531
|
|
|
12553
|
-
|
|
12554
|
-
|
|
12555
|
-
|
|
12556
|
-
}
|
|
12557
|
-
|
|
12558
|
-
const hrefAttribute = getHtmlNodeAttributeByName(node, "href");
|
|
12532
|
+
visitHtmlNodes(htmlAst, {
|
|
12533
|
+
link: node => {
|
|
12534
|
+
const href = getHtmlNodeAttribute(node, "href");
|
|
12559
12535
|
|
|
12560
|
-
|
|
12561
|
-
|
|
12536
|
+
if (href !== undefined) {
|
|
12537
|
+
visitLinkWithHref(node, href);
|
|
12538
|
+
}
|
|
12562
12539
|
}
|
|
12563
|
-
|
|
12564
|
-
visitLinkWithHref(node, hrefAttribute);
|
|
12565
12540
|
});
|
|
12566
12541
|
|
|
12567
12542
|
if (actions.length) {
|
|
@@ -14205,7 +14180,7 @@ const globalInjectorOnHtml = async (urlInfo, globals) => {
|
|
|
14205
14180
|
globals,
|
|
14206
14181
|
isWebWorker: false
|
|
14207
14182
|
});
|
|
14208
|
-
|
|
14183
|
+
injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
|
|
14209
14184
|
"tagName": "script",
|
|
14210
14185
|
"textContent": clientCode,
|
|
14211
14186
|
"injected-by": "jsenv:inject_globals"
|