@jsenv/core 27.0.0-alpha.41 → 27.0.0-alpha.44
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/package.json +2 -2
- package/src/build/build.js +3 -3
- package/src/omega/kitchen.js +48 -18
- package/src/omega/url_graph/url_info_transformations.js +2 -2
- package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +2 -2
- package/src/plugins/plugins.js +2 -2
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js +39 -77
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +62 -81
- package/src/plugins/{url_references → url_analysis}/css/css_urls.js +5 -12
- package/src/plugins/{url_references → url_analysis}/html/html_urls.js +2 -2
- package/src/plugins/{url_references → url_analysis}/js/js_urls.js +29 -5
- package/src/plugins/{url_references → url_analysis}/jsenv_plugin_url_analysis.js +0 -0
- package/src/plugins/{url_references → url_analysis}/webmanifest/webmanifest_urls.js +0 -0
- package/src/plugins/url_references/jsenv_plugin_imports_analysis.js +0 -46
- package/src/plugins/url_references/jsenv_plugin_url_references.js +0 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "27.0.0-alpha.
|
|
3
|
+
"version": "27.0.0-alpha.44",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@jsenv/node-esm-resolution": "0.0.6",
|
|
69
69
|
"@jsenv/server": "12.6.1",
|
|
70
70
|
"@jsenv/uneval": "1.6.0",
|
|
71
|
-
"@jsenv/utils": "1.6.
|
|
71
|
+
"@jsenv/utils": "1.6.2",
|
|
72
72
|
"construct-style-sheets-polyfill": "3.1.0",
|
|
73
73
|
"cssnano": "5.1.7",
|
|
74
74
|
"cssnano-preset-default": "5.2.7",
|
package/src/build/build.js
CHANGED
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
stringifyHtmlAst,
|
|
31
31
|
} from "@jsenv/utils/html_ast/html_ast.js"
|
|
32
32
|
|
|
33
|
-
import {
|
|
33
|
+
import { jsenvPluginUrlAnalysis } from "../plugins/url_analysis/jsenv_plugin_url_analysis.js"
|
|
34
34
|
import { jsenvPluginInline } from "../plugins/inline/jsenv_plugin_inline.js"
|
|
35
35
|
import { jsenvPluginAsJsClassic } from "../plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js"
|
|
36
36
|
import { createUrlGraph } from "../omega/url_graph.js"
|
|
@@ -339,7 +339,7 @@ ${Object.keys(rawGraph.urlInfos).join("\n")}`,
|
|
|
339
339
|
sourcemapsRelativeSources: true,
|
|
340
340
|
runtimeCompat,
|
|
341
341
|
plugins: [
|
|
342
|
-
|
|
342
|
+
jsenvPluginUrlAnalysis(),
|
|
343
343
|
jsenvPluginAsJsClassic({
|
|
344
344
|
systemJsInjection: true,
|
|
345
345
|
}),
|
|
@@ -862,7 +862,7 @@ const applyUrlVersioning = async ({
|
|
|
862
862
|
sourcemaps,
|
|
863
863
|
runtimeCompat,
|
|
864
864
|
plugins: [
|
|
865
|
-
|
|
865
|
+
jsenvPluginUrlAnalysis(),
|
|
866
866
|
jsenvPluginInline({
|
|
867
867
|
fetchInlineUrls: false,
|
|
868
868
|
analyzeConvertedScripts: true, // to be able to version their urls
|
package/src/omega/kitchen.js
CHANGED
|
@@ -80,17 +80,25 @@ export const createKitchen = ({
|
|
|
80
80
|
integrity,
|
|
81
81
|
crossorigin,
|
|
82
82
|
specifier,
|
|
83
|
+
specifierStart,
|
|
84
|
+
specifierEnd,
|
|
85
|
+
specifierLine,
|
|
86
|
+
specifierColumn,
|
|
83
87
|
baseUrl,
|
|
84
88
|
isOriginalPosition,
|
|
85
|
-
line,
|
|
86
|
-
column,
|
|
87
89
|
external = false,
|
|
88
90
|
isInline = false,
|
|
89
91
|
injected = false,
|
|
90
92
|
isRessourceHint = false,
|
|
91
93
|
content,
|
|
92
94
|
contentType,
|
|
95
|
+
assert,
|
|
96
|
+
assertNode,
|
|
97
|
+
typePropertyNode,
|
|
93
98
|
}) => {
|
|
99
|
+
if (typeof specifier !== "string") {
|
|
100
|
+
throw new TypeError(`"specifier" must be a string, got ${specifier}`)
|
|
101
|
+
}
|
|
94
102
|
return {
|
|
95
103
|
original: null,
|
|
96
104
|
prev: null,
|
|
@@ -108,10 +116,12 @@ export const createKitchen = ({
|
|
|
108
116
|
integrity,
|
|
109
117
|
crossorigin,
|
|
110
118
|
specifier,
|
|
119
|
+
specifierStart,
|
|
120
|
+
specifierEnd,
|
|
121
|
+
specifierLine,
|
|
122
|
+
specifierColumn,
|
|
111
123
|
baseUrl,
|
|
112
124
|
isOriginalPosition,
|
|
113
|
-
line,
|
|
114
|
-
column,
|
|
115
125
|
external,
|
|
116
126
|
isInline,
|
|
117
127
|
injected,
|
|
@@ -120,6 +130,9 @@ export const createKitchen = ({
|
|
|
120
130
|
content,
|
|
121
131
|
contentType,
|
|
122
132
|
timing: {},
|
|
133
|
+
assert,
|
|
134
|
+
assertNode,
|
|
135
|
+
typePropertyNode,
|
|
123
136
|
}
|
|
124
137
|
}
|
|
125
138
|
const mutateReference = (reference, newReference) => {
|
|
@@ -228,19 +241,27 @@ export const createKitchen = ({
|
|
|
228
241
|
sourcemapUrlInfo.type = "sourcemap"
|
|
229
242
|
return [sourcemapReference, sourcemapUrlInfo]
|
|
230
243
|
},
|
|
231
|
-
foundSourcemap: ({
|
|
244
|
+
foundSourcemap: ({
|
|
245
|
+
urlInfo,
|
|
246
|
+
type,
|
|
247
|
+
specifier,
|
|
248
|
+
specifierLine,
|
|
249
|
+
specifierColumn,
|
|
250
|
+
}) => {
|
|
232
251
|
const sourcemapReference = createReference({
|
|
233
252
|
trace: stringifyUrlSite(
|
|
234
253
|
adjustUrlSite(urlInfo, {
|
|
235
254
|
urlGraph,
|
|
236
255
|
url: urlInfo.url,
|
|
237
|
-
line,
|
|
238
|
-
column,
|
|
256
|
+
line: specifierLine,
|
|
257
|
+
column: specifierColumn,
|
|
239
258
|
}),
|
|
240
259
|
),
|
|
241
260
|
type,
|
|
242
261
|
parentUrl: urlInfo.url,
|
|
243
262
|
specifier,
|
|
263
|
+
specifierLine,
|
|
264
|
+
specifierColumn,
|
|
244
265
|
})
|
|
245
266
|
const sourcemapUrlInfo = resolveReference(sourcemapReference)
|
|
246
267
|
sourcemapUrlInfo.type = "sourcemap"
|
|
@@ -341,14 +362,14 @@ export const createKitchen = ({
|
|
|
341
362
|
clientRuntimeCompat = runtimeCompat,
|
|
342
363
|
cookDuringCook = cook,
|
|
343
364
|
}) => {
|
|
365
|
+
baseContext.isSupportedOnCurrentClients = (feature) => {
|
|
366
|
+
return RUNTIME_COMPAT.isSupported(clientRuntimeCompat, feature)
|
|
367
|
+
}
|
|
344
368
|
const context = {
|
|
345
369
|
...baseContext,
|
|
346
370
|
reference,
|
|
347
371
|
outDirectoryUrl,
|
|
348
372
|
clientRuntimeCompat,
|
|
349
|
-
isSupportedOnCurrentClients: (feature) => {
|
|
350
|
-
return RUNTIME_COMPAT.isSupported(clientRuntimeCompat, feature)
|
|
351
|
-
},
|
|
352
373
|
cook: (params) => {
|
|
353
374
|
return cookDuringCook({
|
|
354
375
|
outDirectoryUrl,
|
|
@@ -397,20 +418,20 @@ export const createKitchen = ({
|
|
|
397
418
|
}
|
|
398
419
|
return reference.generatedSpecifier
|
|
399
420
|
},
|
|
400
|
-
found: ({
|
|
421
|
+
found: ({ specifierLine, specifierColumn, ...rest }) => {
|
|
401
422
|
const trace = stringifyUrlSite(
|
|
402
423
|
adjustUrlSite(urlInfo, {
|
|
403
424
|
urlGraph,
|
|
404
425
|
url: urlInfo.url,
|
|
405
|
-
line,
|
|
406
|
-
column,
|
|
426
|
+
line: specifierLine,
|
|
427
|
+
column: specifierColumn,
|
|
407
428
|
}),
|
|
408
429
|
)
|
|
409
430
|
// console.log(trace)
|
|
410
431
|
return addReference({
|
|
411
432
|
trace,
|
|
412
|
-
|
|
413
|
-
|
|
433
|
+
specifierLine,
|
|
434
|
+
specifierColumn,
|
|
414
435
|
...rest,
|
|
415
436
|
})
|
|
416
437
|
},
|
|
@@ -460,7 +481,14 @@ export const createKitchen = ({
|
|
|
460
481
|
},
|
|
461
482
|
becomesInline: (
|
|
462
483
|
reference,
|
|
463
|
-
{
|
|
484
|
+
{
|
|
485
|
+
isOriginalPosition,
|
|
486
|
+
specifier,
|
|
487
|
+
specifierLine,
|
|
488
|
+
specifierColumn,
|
|
489
|
+
contentType,
|
|
490
|
+
content,
|
|
491
|
+
},
|
|
464
492
|
) => {
|
|
465
493
|
const parentUrl = isOriginalPosition
|
|
466
494
|
? urlInfo.url
|
|
@@ -472,12 +500,14 @@ export const createKitchen = ({
|
|
|
472
500
|
trace: stringifyUrlSite({
|
|
473
501
|
url: parentUrl,
|
|
474
502
|
content: parentContent,
|
|
475
|
-
line,
|
|
476
|
-
column,
|
|
503
|
+
line: specifierLine,
|
|
504
|
+
column: specifierColumn,
|
|
477
505
|
}),
|
|
478
506
|
isOriginalPosition,
|
|
479
507
|
isInline: true,
|
|
480
508
|
specifier,
|
|
509
|
+
specifierLine,
|
|
510
|
+
specifierColumn,
|
|
481
511
|
contentType,
|
|
482
512
|
content,
|
|
483
513
|
})
|
|
@@ -85,9 +85,9 @@ export const createUrlInfoTransformer = ({
|
|
|
85
85
|
const [sourcemapReference, sourcemapUrlInfo] = foundSourcemap({
|
|
86
86
|
urlInfo,
|
|
87
87
|
type,
|
|
88
|
-
line,
|
|
89
|
-
column,
|
|
90
88
|
specifier,
|
|
89
|
+
specifierLine: line,
|
|
90
|
+
specifierColumn: column,
|
|
91
91
|
})
|
|
92
92
|
try {
|
|
93
93
|
await context.cook({
|
|
@@ -33,10 +33,10 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
33
33
|
urlIsInsideOf(rootDirectoryUrl, jsenvRootDirectoryUrl)
|
|
34
34
|
const htmlSupervisorSetupFileUrl = preferSourceFiles
|
|
35
35
|
? new URL("./client/html_supervisor_setup.js", import.meta.url).href
|
|
36
|
-
: new URL("./dist/html_supervisor_setup.js", jsenvRootDirectoryUrl)
|
|
36
|
+
: new URL("./dist/html_supervisor_setup.js", jsenvRootDirectoryUrl).href
|
|
37
37
|
const htmlSupervisorInstallerFileUrl = preferSourceFiles
|
|
38
38
|
? new URL("./client/html_supervisor_installer.js", import.meta.url).href
|
|
39
|
-
: new URL("./dist/html_supervisor_installer.js", jsenvRootDirectoryUrl)
|
|
39
|
+
: new URL("./dist/html_supervisor_installer.js", jsenvRootDirectoryUrl).href
|
|
40
40
|
|
|
41
41
|
return {
|
|
42
42
|
name: "jsenv:html_supervisor",
|
package/src/plugins/plugins.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsenvPluginUrlAnalysis } from "../plugins/url_analysis/jsenv_plugin_url_analysis.js"
|
|
2
2
|
import { jsenvPluginLeadingSlash } from "./leading_slash/jsenv_plugin_leading_slash.js"
|
|
3
3
|
import { jsenvPluginImportmap } from "./importmap/jsenv_plugin_importmap.js"
|
|
4
4
|
import { jsenvPluginUrlResolution } from "./url_resolution/jsenv_plugin_url_resolution.js"
|
|
@@ -43,7 +43,7 @@ export const getCorePlugins = ({
|
|
|
43
43
|
nodeEsmResolution = {}
|
|
44
44
|
}
|
|
45
45
|
return [
|
|
46
|
-
|
|
46
|
+
jsenvPluginUrlAnalysis(),
|
|
47
47
|
jsenvPluginTranspilation(transpilation),
|
|
48
48
|
...(htmlSupervisor
|
|
49
49
|
? [
|
package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js
CHANGED
|
@@ -1,93 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
3
|
-
import { parseJsUrls } from "@jsenv/core/packages/utils/js_ast/parse_js_urls.js"
|
|
1
|
+
import { injectQueryParams } from "@jsenv/utils/urls/url_utils.js"
|
|
4
2
|
|
|
5
3
|
export const jsenvPluginWorkersTypeModuleAsClassic = ({
|
|
6
4
|
generateJsClassicFilename,
|
|
7
5
|
}) => {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let serviceWorkerTypeModuleIsSupported
|
|
12
|
-
let sharedWorkerTypeModuleIsSupported
|
|
13
|
-
const jsUrls = parseJsUrls({
|
|
14
|
-
js: urlInfo.content,
|
|
15
|
-
url: (urlInfo.data && urlInfo.data.rawUrl) || urlInfo.url,
|
|
16
|
-
isJsModule: urlInfo.type === "js_module",
|
|
17
|
-
})
|
|
18
|
-
jsUrls.forEach((jsUrlMention) => {
|
|
19
|
-
if (jsUrlMention.expectedType !== "js_module") {
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
if (jsUrlMention.expectedSubtype === "worker") {
|
|
23
|
-
if (workerTypeModuleIsSupported === undefined) {
|
|
24
|
-
workerTypeModuleIsSupported =
|
|
25
|
-
context.isSupportedOnCurrentClients("worker_type_module")
|
|
26
|
-
}
|
|
27
|
-
if (workerTypeModuleIsSupported) {
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
toUpdate.push(jsUrlMention)
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
if (jsUrlMention.expectedSubtype === "service_worker") {
|
|
34
|
-
if (serviceWorkerTypeModuleIsSupported === undefined) {
|
|
35
|
-
serviceWorkerTypeModuleIsSupported =
|
|
36
|
-
context.isSupportedOnCurrentClients("service_worker_type_module")
|
|
37
|
-
}
|
|
38
|
-
if (serviceWorkerTypeModuleIsSupported) {
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
toUpdate.push(jsUrlMention)
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
if (jsUrlMention.expectedSubtype === "shared_worker") {
|
|
45
|
-
if (sharedWorkerTypeModuleIsSupported === undefined) {
|
|
46
|
-
sharedWorkerTypeModuleIsSupported =
|
|
47
|
-
context.isSupportedOnCurrentClients("shared_worker_type_module")
|
|
48
|
-
}
|
|
49
|
-
if (sharedWorkerTypeModuleIsSupported) {
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
toUpdate.push(jsUrlMention)
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
if (toUpdate.length === 0) {
|
|
57
|
-
return null
|
|
58
|
-
}
|
|
59
|
-
const magicSource = createMagicSource(urlInfo.content)
|
|
60
|
-
toUpdate.forEach((jsUrlMention) => {
|
|
61
|
-
const reference = context.referenceUtils.findByGeneratedSpecifier(
|
|
62
|
-
JSON.stringify(jsUrlMention.specifier),
|
|
63
|
-
)
|
|
64
|
-
const [newReference] = context.referenceUtils.update(reference, {
|
|
65
|
-
expectedType: "js_classic",
|
|
66
|
-
specifier: injectQueryParamsIntoSpecifier(reference.specifier, {
|
|
67
|
-
as_js_classic: "",
|
|
68
|
-
}),
|
|
69
|
-
filename: generateJsClassicFilename(reference.url),
|
|
70
|
-
})
|
|
71
|
-
magicSource.replace({
|
|
72
|
-
start: jsUrlMention.start,
|
|
73
|
-
end: jsUrlMention.end,
|
|
74
|
-
replacement: newReference.generatedSpecifier,
|
|
75
|
-
})
|
|
6
|
+
const updateReference = (reference) => {
|
|
7
|
+
reference.filename = generateJsClassicFilename(reference.url)
|
|
8
|
+
reference.mutation = (magicSource) => {
|
|
76
9
|
magicSource.replace({
|
|
77
|
-
start:
|
|
78
|
-
end:
|
|
10
|
+
start: reference.typePropertyNode.value.start,
|
|
11
|
+
end: reference.typePropertyNode.value.end,
|
|
79
12
|
replacement: JSON.stringify("classic"),
|
|
80
13
|
})
|
|
14
|
+
}
|
|
15
|
+
reference.expectedType = "js_classic"
|
|
16
|
+
return injectQueryParams(reference.url, {
|
|
17
|
+
as_js_classic: "",
|
|
81
18
|
})
|
|
82
|
-
return magicSource.toContentAndSourcemap()
|
|
83
19
|
}
|
|
84
20
|
|
|
85
21
|
return {
|
|
86
22
|
name: "jsenv:workers_type_module_as_classic",
|
|
87
23
|
appliesDuring: "*",
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
24
|
+
normalizeUrl: {
|
|
25
|
+
js_url_specifier: (reference, context) => {
|
|
26
|
+
if (reference.expectedType !== "js_module") {
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
if (reference.expectedSubtype === "worker") {
|
|
30
|
+
if (context.isSupportedOnCurrentClients("worker_type_module")) {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
return updateReference(reference)
|
|
34
|
+
}
|
|
35
|
+
if (reference.expectedSubtype === "service_worker") {
|
|
36
|
+
if (
|
|
37
|
+
context.isSupportedOnCurrentClients("service_worker_type_module")
|
|
38
|
+
) {
|
|
39
|
+
return null
|
|
40
|
+
}
|
|
41
|
+
return updateReference(reference)
|
|
42
|
+
}
|
|
43
|
+
if (reference.expectedSubtype === "shared_worker") {
|
|
44
|
+
if (
|
|
45
|
+
context.isSupportedOnCurrentClients("shared_worker_type_module")
|
|
46
|
+
) {
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
return updateReference(reference)
|
|
50
|
+
}
|
|
51
|
+
return null
|
|
52
|
+
},
|
|
91
53
|
},
|
|
92
54
|
}
|
|
93
55
|
}
|
|
@@ -1,61 +1,79 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Jsenv wont touch code where "specifier" or "type" is dynamic (see code below)
|
|
3
|
+
* ```js
|
|
4
|
+
* const file = "./style.css"
|
|
5
|
+
* const type = "css"
|
|
6
|
+
* import(file, { assert: { type }})
|
|
7
|
+
* ```
|
|
8
|
+
* Jsenv could throw an error when it knows some browsers in runtimeCompat
|
|
9
|
+
* do not support import assertions
|
|
10
|
+
* But for now (as it is simpler) we let the browser throw the error
|
|
11
|
+
*/
|
|
12
|
+
|
|
1
13
|
import { urlToFilename } from "@jsenv/filesystem"
|
|
2
14
|
|
|
3
|
-
import {
|
|
4
|
-
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
5
|
-
import { injectQueryParamsIntoSpecifier } from "@jsenv/utils/urls/url_utils.js"
|
|
15
|
+
import { injectQueryParams } from "@jsenv/utils/urls/url_utils.js"
|
|
6
16
|
import { JS_QUOTES } from "@jsenv/utils/string/js_quotes.js"
|
|
7
17
|
|
|
8
18
|
import { fetchOriginalUrlInfo } from "../fetch_original_url_info.js"
|
|
9
19
|
|
|
10
20
|
export const jsenvPluginImportAssertions = () => {
|
|
21
|
+
const updateReference = (reference, searchParam) => {
|
|
22
|
+
reference.expectedType = "js_module"
|
|
23
|
+
reference.filename = `${urlToFilename(reference.url)}.js`
|
|
24
|
+
reference.mutation = (magicSource) => {
|
|
25
|
+
magicSource.remove({
|
|
26
|
+
start: reference.assertNode.start,
|
|
27
|
+
end: reference.assertNode.end,
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return injectQueryParams(reference.url, {
|
|
32
|
+
[searchParam]: "",
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
11
36
|
const importAssertions = {
|
|
12
37
|
name: "jsenv:import_assertions",
|
|
13
38
|
appliesDuring: "*",
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (urlInfo.data.usesImportAssertion === false) {
|
|
39
|
+
normalizeUrl: {
|
|
40
|
+
js_import_export: (reference, context) => {
|
|
41
|
+
if (!reference.assert) {
|
|
18
42
|
return null
|
|
19
43
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
44
|
+
// during build always replace import assertions with the js:
|
|
45
|
+
// - avoid rollup to see import assertions
|
|
46
|
+
// We would have to tell rollup to ignore import with assertion
|
|
47
|
+
// - means rollup can bundle more js file together
|
|
48
|
+
// - means url versioning can work for css inlined in js
|
|
49
|
+
if (reference.assert.type === "json") {
|
|
50
|
+
if (
|
|
51
|
+
context.scenario !== "build" &&
|
|
52
|
+
context.isSupportedOnCurrentClients("import_type_json")
|
|
53
|
+
) {
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
56
|
+
return updateReference(reference, "as_json_module")
|
|
23
57
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const assertType = importAssertion.assert.type
|
|
31
|
-
if (!importTypesToTranspile.includes(assertType)) {
|
|
32
|
-
return
|
|
58
|
+
if (reference.assert.type === "css") {
|
|
59
|
+
if (
|
|
60
|
+
context.scenario !== "build" &&
|
|
61
|
+
context.isSupportedOnCurrentClients("import_type_css")
|
|
62
|
+
) {
|
|
63
|
+
return null
|
|
33
64
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
filename: `${urlToFilename(reference.url)}.js`,
|
|
47
|
-
})
|
|
48
|
-
magicSource.replace({
|
|
49
|
-
start: importAssertion.specifierStart,
|
|
50
|
-
end: importAssertion.specifierEnd,
|
|
51
|
-
replacement: newReference.generatedSpecifier,
|
|
52
|
-
})
|
|
53
|
-
magicSource.remove({
|
|
54
|
-
start: importAssertion.assertNode.start,
|
|
55
|
-
end: importAssertion.assertNode.end,
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
return magicSource.toContentAndSourcemap()
|
|
65
|
+
return updateReference(reference, "as_css_module")
|
|
66
|
+
}
|
|
67
|
+
if (reference.assert.type === "text") {
|
|
68
|
+
if (
|
|
69
|
+
context.scenario !== "build" &&
|
|
70
|
+
context.isSupportedOnCurrentClients("import_type_text")
|
|
71
|
+
) {
|
|
72
|
+
return null
|
|
73
|
+
}
|
|
74
|
+
return updateReference(reference, "as_text_module")
|
|
75
|
+
}
|
|
76
|
+
return null
|
|
59
77
|
},
|
|
60
78
|
},
|
|
61
79
|
}
|
|
@@ -161,40 +179,3 @@ export default inlineContent.text`,
|
|
|
161
179
|
|
|
162
180
|
return [asJsonModule, asCssModule, asTextModule]
|
|
163
181
|
}
|
|
164
|
-
|
|
165
|
-
const importAsInfos = {
|
|
166
|
-
json: {
|
|
167
|
-
searchParam: "as_json_module",
|
|
168
|
-
},
|
|
169
|
-
css: {
|
|
170
|
-
searchParam: "as_css_module",
|
|
171
|
-
},
|
|
172
|
-
text: {
|
|
173
|
-
searchParam: "as_text_module",
|
|
174
|
-
},
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const getImportTypesToTranspile = ({
|
|
178
|
-
scenario,
|
|
179
|
-
isSupportedOnCurrentClients,
|
|
180
|
-
}) => {
|
|
181
|
-
// during build always replace import assertions with the js:
|
|
182
|
-
// - avoid rollup to see import assertions
|
|
183
|
-
// We would have to tell rollup to ignore import with assertion
|
|
184
|
-
// - means rollup can bundle more js file together
|
|
185
|
-
// - means url versioning can work for css inlined in js
|
|
186
|
-
if (scenario === "build") {
|
|
187
|
-
return ["json", "css", "text"]
|
|
188
|
-
}
|
|
189
|
-
const importTypes = []
|
|
190
|
-
if (!isSupportedOnCurrentClients("import_type_json")) {
|
|
191
|
-
importTypes.push("json")
|
|
192
|
-
}
|
|
193
|
-
if (!isSupportedOnCurrentClients("import_type_css")) {
|
|
194
|
-
importTypes.push("css")
|
|
195
|
-
}
|
|
196
|
-
if (!isSupportedOnCurrentClients("import_type_text")) {
|
|
197
|
-
importTypes.push("text")
|
|
198
|
-
}
|
|
199
|
-
return importTypes
|
|
200
|
-
}
|
|
@@ -13,21 +13,14 @@ export const parseAndTransformCssUrls = async (urlInfo, context) => {
|
|
|
13
13
|
sourcemaps: false,
|
|
14
14
|
plugins: [
|
|
15
15
|
postCssPluginUrlVisitor({
|
|
16
|
-
urlVisitor: ({
|
|
17
|
-
declarationNode,
|
|
18
|
-
type,
|
|
19
|
-
specifier,
|
|
20
|
-
line,
|
|
21
|
-
column,
|
|
22
|
-
start,
|
|
23
|
-
end,
|
|
24
|
-
}) => {
|
|
16
|
+
urlVisitor: ({ type, specifier, line, column, start, end }) => {
|
|
25
17
|
const [reference] = context.referenceUtils.found({
|
|
26
|
-
node: declarationNode,
|
|
27
18
|
type: `css_${type}`,
|
|
28
19
|
specifier,
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
specifierStart: start,
|
|
21
|
+
specifierEnd: end,
|
|
22
|
+
specifierLine: line,
|
|
23
|
+
specifierColumn: column,
|
|
31
24
|
})
|
|
32
25
|
actions.push(async () => {
|
|
33
26
|
magicSource.replace({
|
|
@@ -39,11 +39,11 @@ export const parseAndTransformHtmlUrls = async (urlInfo, context) => {
|
|
|
39
39
|
const [reference] = referenceUtils.found({
|
|
40
40
|
type,
|
|
41
41
|
expectedType,
|
|
42
|
-
line,
|
|
43
|
-
column,
|
|
44
42
|
originalLine,
|
|
45
43
|
originalColumn,
|
|
46
44
|
specifier,
|
|
45
|
+
specifierLine: line,
|
|
46
|
+
specifierColumn: column,
|
|
47
47
|
isRessourceHint,
|
|
48
48
|
})
|
|
49
49
|
actions.push(async () => {
|
|
@@ -12,15 +12,32 @@ export const parseAndTransformJsUrls = async (urlInfo, context) => {
|
|
|
12
12
|
const { rootDirectoryUrl, referenceUtils } = context
|
|
13
13
|
const actions = []
|
|
14
14
|
const magicSource = createMagicSource(urlInfo.content)
|
|
15
|
+
urlInfo.data.usesImport = false
|
|
16
|
+
urlInfo.data.usesExport = false
|
|
17
|
+
urlInfo.data.usesImportAssertion = false
|
|
15
18
|
jsMentions.forEach((jsMention) => {
|
|
19
|
+
if (jsMention.assert) {
|
|
20
|
+
urlInfo.data.usesImportAssertion = true
|
|
21
|
+
}
|
|
22
|
+
if (
|
|
23
|
+
jsMention.subtype === "import_static" ||
|
|
24
|
+
jsMention.subtype === "import_dynamic"
|
|
25
|
+
) {
|
|
26
|
+
urlInfo.data.usesImport = true
|
|
27
|
+
}
|
|
28
|
+
if (jsMention.subtype === "export") {
|
|
29
|
+
urlInfo.data.usesExport = true
|
|
30
|
+
}
|
|
16
31
|
const [reference] = referenceUtils.found({
|
|
17
32
|
type: jsMention.type,
|
|
18
33
|
subtype: jsMention.subtype,
|
|
19
34
|
expectedType: jsMention.expectedType,
|
|
20
35
|
expectedSubtype: jsMention.expectedSubtype || urlInfo.subtype,
|
|
21
|
-
line: jsMention.line,
|
|
22
|
-
column: jsMention.column,
|
|
23
36
|
specifier: jsMention.specifier,
|
|
37
|
+
specifierStart: jsMention.specifierStart,
|
|
38
|
+
specifierEnd: jsMention.specifierEnd,
|
|
39
|
+
specifierLine: jsMention.specifierLine,
|
|
40
|
+
specifierColumn: jsMention.specifierColumn,
|
|
24
41
|
data: jsMention.data,
|
|
25
42
|
baseUrl: {
|
|
26
43
|
"StringLiteral": jsMention.baseUrl,
|
|
@@ -29,15 +46,22 @@ export const parseAndTransformJsUrls = async (urlInfo, context) => {
|
|
|
29
46
|
"context.meta.url": urlInfo.url,
|
|
30
47
|
"document.currentScript.src": urlInfo.url,
|
|
31
48
|
}[jsMention.baseUrlType],
|
|
49
|
+
assert: jsMention.assert,
|
|
50
|
+
assertNode: jsMention.assertNode,
|
|
51
|
+
typePropertyNode: jsMention.typePropertyNode,
|
|
32
52
|
})
|
|
33
53
|
actions.push(async () => {
|
|
34
54
|
magicSource.replace({
|
|
35
|
-
start: jsMention.
|
|
36
|
-
end: jsMention.
|
|
55
|
+
start: jsMention.specifierStart,
|
|
56
|
+
end: jsMention.specifierEnd,
|
|
37
57
|
replacement: await referenceUtils.readGeneratedSpecifier(reference),
|
|
38
58
|
})
|
|
59
|
+
if (reference.mutation) {
|
|
60
|
+
reference.mutation(magicSource)
|
|
61
|
+
}
|
|
39
62
|
})
|
|
40
63
|
})
|
|
41
64
|
await Promise.all(actions.map((action) => action()))
|
|
42
|
-
|
|
65
|
+
const { content, sourcemap } = magicSource.toContentAndSourcemap()
|
|
66
|
+
return { content, sourcemap }
|
|
43
67
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { parseJsModuleImports } from "@jsenv/utils/js_ast/parse_js_module_imports.js"
|
|
2
|
-
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
3
|
-
|
|
4
|
-
export const jsenvPluginImportsAnalysis = () => {
|
|
5
|
-
return {
|
|
6
|
-
name: "jsenv:imports_analysis",
|
|
7
|
-
appliesDuring: "*",
|
|
8
|
-
transformUrlContent: {
|
|
9
|
-
js_module: async (urlInfo, context) => {
|
|
10
|
-
const [imports, exports] = await parseJsModuleImports({
|
|
11
|
-
js: urlInfo.content,
|
|
12
|
-
url: (urlInfo.data && urlInfo.data.rawUrl) || urlInfo.url,
|
|
13
|
-
})
|
|
14
|
-
const actions = []
|
|
15
|
-
const magicSource = createMagicSource(urlInfo.content)
|
|
16
|
-
urlInfo.data.usesImport = imports.length > 0
|
|
17
|
-
urlInfo.data.usesExport = exports.length > 0
|
|
18
|
-
urlInfo.data.usesImportAssertion = imports.some(
|
|
19
|
-
(importInfo) => typeof importInfo.usesAssert,
|
|
20
|
-
)
|
|
21
|
-
imports.forEach((importInfo) => {
|
|
22
|
-
const [reference] = context.referenceUtils.found({
|
|
23
|
-
type: "js_import_export",
|
|
24
|
-
subtype: importInfo.subtype,
|
|
25
|
-
expectedType: importInfo.expectedType, // can be json for import assertions
|
|
26
|
-
expectedSubtype: urlInfo.subtype,
|
|
27
|
-
line: importInfo.specifierLine,
|
|
28
|
-
column: importInfo.specifierColumn,
|
|
29
|
-
specifier: importInfo.specifier,
|
|
30
|
-
})
|
|
31
|
-
actions.push(async () => {
|
|
32
|
-
magicSource.replace({
|
|
33
|
-
start: importInfo.specifierStart,
|
|
34
|
-
end: importInfo.specifierEnd,
|
|
35
|
-
replacement: await context.referenceUtils.readGeneratedSpecifier(
|
|
36
|
-
reference,
|
|
37
|
-
),
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
await Promise.all(actions.map((action) => action()))
|
|
42
|
-
return magicSource.toContentAndSourcemap()
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { jsenvPluginImportsAnalysis } from "./jsenv_plugin_imports_analysis.js"
|
|
2
|
-
import { jsenvPluginUrlAnalysis } from "./jsenv_plugin_url_analysis.js"
|
|
3
|
-
|
|
4
|
-
export const jsenvPluginUrlReferences = () => {
|
|
5
|
-
return [jsenvPluginImportsAnalysis(), jsenvPluginUrlAnalysis()]
|
|
6
|
-
}
|