@jsenv/core 25.0.0 → 25.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser_runtime/browser_runtime_91c5a3b8.js.map +2 -2
- package/dist/build_manifest.js +4 -4
- package/dist/compile_proxy/asset-manifest.json +2 -2
- package/dist/compile_proxy/{compile_proxy_e3b0c442_809f35f7.js.map → compile_proxy.html__inline__20_809f35f7.js.map} +0 -0
- package/dist/compile_proxy/{compile_proxy_7ad5faa6.html → compile_proxy_8dfaee51.html} +3 -4
- package/dist/redirector/asset-manifest.json +2 -2
- package/dist/redirector/{redirector_e3b0c442_e391410e.js.map → redirector.html__inline__15_e391410e.js.map} +0 -0
- package/dist/redirector/{redirector_eb92e8a7.html → redirector_3e9a97b9.html} +3 -4
- package/dist/toolbar/asset-manifest.json +1 -1
- package/dist/toolbar/{toolbar_f7b8a263.html → toolbar_361afb84.html} +2 -3
- package/dist/toolbar_injector/asset-manifest.json +2 -2
- package/dist/toolbar_injector/{toolbar_injector_49e4756e.js → toolbar_injector_fac1e995.js} +2 -2
- package/dist/toolbar_injector/{toolbar_injector_49e4756e.js.map → toolbar_injector_fac1e995.js.map} +2 -2
- package/package.json +8 -8
- package/readme.md +61 -52
- package/src/buildProject.js +21 -13
- package/src/commonJsToJavaScriptModule.js +8 -7
- package/src/execute.js +2 -0
- package/src/executeTestPlan.js +14 -0
- package/src/internal/building/buildUsingRollup.js +4 -2
- package/src/internal/building/build_stats.js +3 -0
- package/src/internal/building/build_url_generator.js +153 -0
- package/src/internal/building/css/parseCssRessource.js +32 -26
- package/src/internal/building/html/parseHtmlRessource.js +109 -91
- package/src/internal/building/js/parseJsRessource.js +5 -13
- package/src/internal/building/parseRessource.js +3 -0
- package/src/internal/building/ressource_builder.js +72 -64
- package/src/internal/building/ressource_builder_util.js +17 -5
- package/src/internal/building/rollup_plugin_jsenv.js +262 -189
- package/src/internal/building/url_fetcher.js +16 -7
- package/src/internal/building/url_loader.js +1 -5
- package/src/internal/building/url_versioning.js +0 -173
- package/src/internal/compiling/babel_plugin_import_metadata.js +7 -11
- package/src/internal/compiling/babel_plugin_proxy_external_imports.js +31 -0
- package/src/internal/compiling/compile-directory/compile-asset.js +8 -4
- package/src/internal/compiling/compile-directory/getOrGenerateCompiledFile.js +43 -8
- package/src/internal/compiling/compile-directory/updateMeta.js +2 -8
- package/src/internal/compiling/compile-directory/validateCache.js +1 -2
- package/src/internal/compiling/compileFile.js +22 -10
- package/src/internal/compiling/compileHtml.js +15 -28
- package/src/internal/compiling/createCompiledFileService.js +22 -24
- package/src/internal/compiling/html_source_file_service.js +18 -19
- package/src/internal/compiling/js-compilation-service/jsenvTransform.js +14 -4
- package/src/internal/compiling/js-compilation-service/transformJs.js +9 -5
- package/src/internal/compiling/jsenvCompilerForHtml.js +534 -263
- package/src/internal/compiling/jsenvCompilerForJavaScript.js +15 -11
- package/src/internal/compiling/startCompileServer.js +83 -20
- package/src/internal/compiling/transformResultToCompilationResult.js +47 -25
- package/src/internal/executing/executePlan.js +2 -0
- package/src/internal/fetchUrl.js +3 -2
- package/src/internal/integrity/integrity_algorithms.js +26 -0
- package/src/internal/integrity/integrity_parsing.js +50 -0
- package/src/internal/integrity/integrity_update.js +23 -0
- package/src/internal/integrity/integrity_validation.js +49 -0
- package/src/internal/jsenvCoreDirectoryUrl.js +2 -0
- package/src/internal/jsenv_remote_directory.js +156 -0
- package/src/internal/origin_directory_converter.js +62 -0
- package/src/internal/response_validation.js +11 -24
- package/src/internal/sourceMappingURLUtils.js +10 -0
- package/src/internal/url_conversion.js +1 -0
|
@@ -30,6 +30,8 @@ import { jsenvHelpersDirectoryInfo } from "@jsenv/core/src/internal/jsenvInterna
|
|
|
30
30
|
import { createImportResolverForNode } from "@jsenv/core/src/internal/import-resolution/import-resolver-node.js"
|
|
31
31
|
import { createImportResolverForImportmap } from "@jsenv/core/src/internal/import-resolution/import-resolver-importmap.js"
|
|
32
32
|
import { getDefaultImportmap } from "@jsenv/core/src/internal/import-resolution/importmap_default.js"
|
|
33
|
+
import { createJsenvRemoteDirectory } from "@jsenv/core/src/internal/jsenv_remote_directory.js"
|
|
34
|
+
import { setUrlSearchParamsDescriptor } from "@jsenv/core/src/internal/url_utils.js"
|
|
33
35
|
|
|
34
36
|
import {
|
|
35
37
|
formatBuildStartLog,
|
|
@@ -44,10 +46,8 @@ import {
|
|
|
44
46
|
createRessourceBuilder,
|
|
45
47
|
referenceToCodeForRollup,
|
|
46
48
|
} from "./ressource_builder.js"
|
|
47
|
-
|
|
48
|
-
import { createUrlVersioner } from "./url_versioning.js"
|
|
49
|
+
import { createBuildUrlGenerator } from "./build_url_generator.js"
|
|
49
50
|
import { visitImportReferences } from "./import_references.js"
|
|
50
|
-
|
|
51
51
|
import { createBuildStats } from "./build_stats.js"
|
|
52
52
|
|
|
53
53
|
export const createRollupPlugins = async ({
|
|
@@ -58,6 +58,7 @@ export const createRollupPlugins = async ({
|
|
|
58
58
|
entryPoints,
|
|
59
59
|
compileServerOrigin,
|
|
60
60
|
compileDirectoryRelativeUrl,
|
|
61
|
+
jsenvDirectoryRelativeUrl,
|
|
61
62
|
buildDirectoryUrl,
|
|
62
63
|
|
|
63
64
|
urlMappings,
|
|
@@ -65,8 +66,8 @@ export const createRollupPlugins = async ({
|
|
|
65
66
|
importMapFileRelativeUrl,
|
|
66
67
|
importDefaultExtension,
|
|
67
68
|
externalImportSpecifiers,
|
|
68
|
-
externalImportUrlPatterns,
|
|
69
69
|
importPaths,
|
|
70
|
+
preservedUrls,
|
|
70
71
|
workers,
|
|
71
72
|
serviceWorkers,
|
|
72
73
|
serviceWorkerFinalizer,
|
|
@@ -90,6 +91,12 @@ export const createRollupPlugins = async ({
|
|
|
90
91
|
minifyCssOptions,
|
|
91
92
|
minifyHtmlOptions,
|
|
92
93
|
}) => {
|
|
94
|
+
const jsenvRemoteDirectory = createJsenvRemoteDirectory({
|
|
95
|
+
projectDirectoryUrl,
|
|
96
|
+
jsenvDirectoryRelativeUrl,
|
|
97
|
+
preservedUrls,
|
|
98
|
+
})
|
|
99
|
+
|
|
93
100
|
const urlImporterMap = {}
|
|
94
101
|
const inlineModuleScripts = {}
|
|
95
102
|
const jsModulesFromEntry = {}
|
|
@@ -133,6 +140,7 @@ export const createRollupPlugins = async ({
|
|
|
133
140
|
const rollupGetModuleInfo = (id) => _rollupGetModuleInfo(id)
|
|
134
141
|
|
|
135
142
|
const {
|
|
143
|
+
compileServerOriginForRollup,
|
|
136
144
|
asRollupUrl,
|
|
137
145
|
asProjectUrl,
|
|
138
146
|
asServerUrl,
|
|
@@ -147,13 +155,14 @@ export const createRollupPlugins = async ({
|
|
|
147
155
|
urlMappings,
|
|
148
156
|
})
|
|
149
157
|
|
|
150
|
-
const
|
|
158
|
+
const buildUrlGenerator = createBuildUrlGenerator({
|
|
151
159
|
entryPointUrls,
|
|
152
160
|
asOriginalUrl,
|
|
153
161
|
lineBreakNormalization,
|
|
154
162
|
})
|
|
155
163
|
|
|
156
164
|
const urlFetcher = createUrlFetcher({
|
|
165
|
+
jsenvRemoteDirectory,
|
|
157
166
|
asOriginalUrl,
|
|
158
167
|
asProjectUrl,
|
|
159
168
|
applyUrlMappings,
|
|
@@ -168,19 +177,18 @@ export const createRollupPlugins = async ({
|
|
|
168
177
|
urlCustomLoaders,
|
|
169
178
|
allowJson: acceptsJsonContentType({ node, format }),
|
|
170
179
|
urlImporterMap,
|
|
171
|
-
jsConcatenation,
|
|
172
180
|
|
|
173
|
-
asServerUrl,
|
|
174
181
|
asProjectUrl,
|
|
175
182
|
asOriginalUrl,
|
|
176
183
|
|
|
177
184
|
urlFetcher,
|
|
178
185
|
})
|
|
179
186
|
|
|
180
|
-
const
|
|
181
|
-
externalImportUrlPatterns,
|
|
187
|
+
const urlMetaGetter = createUrlMetaGetter({
|
|
182
188
|
projectDirectoryUrl,
|
|
183
|
-
|
|
189
|
+
jsenvRemoteDirectory,
|
|
190
|
+
preservedUrls,
|
|
191
|
+
})
|
|
184
192
|
|
|
185
193
|
// Object mapping project relative urls to build relative urls
|
|
186
194
|
let buildMappings = {}
|
|
@@ -256,11 +264,12 @@ export const createRollupPlugins = async ({
|
|
|
256
264
|
async renderChunk(code, chunk) {
|
|
257
265
|
let map = chunk.map
|
|
258
266
|
const result = await transformJs({
|
|
259
|
-
|
|
267
|
+
projectDirectoryUrl,
|
|
268
|
+
jsenvRemoteDirectory,
|
|
260
269
|
url: chunk.facadeModuleId
|
|
261
270
|
? asOriginalUrl(chunk.facadeModuleId)
|
|
262
271
|
: resolveUrl(chunk.fileName, buildDirectoryUrl),
|
|
263
|
-
|
|
272
|
+
code,
|
|
264
273
|
babelPluginMap: {
|
|
265
274
|
"transform-async-to-promises":
|
|
266
275
|
babelPluginMap["transform-async-to-promises"],
|
|
@@ -530,6 +539,7 @@ export const createRollupPlugins = async ({
|
|
|
530
539
|
format,
|
|
531
540
|
systemJsUrl,
|
|
532
541
|
projectDirectoryUrl,
|
|
542
|
+
jsenvRemoteDirectory,
|
|
533
543
|
asProjectUrl,
|
|
534
544
|
asOriginalUrl,
|
|
535
545
|
asOriginalServerUrl,
|
|
@@ -557,7 +567,10 @@ export const createRollupPlugins = async ({
|
|
|
557
567
|
urlToCompiledServerUrl: (url) => {
|
|
558
568
|
return asCompiledServerUrl(url)
|
|
559
569
|
},
|
|
560
|
-
urlToHumanUrl: (
|
|
570
|
+
urlToHumanUrl: (
|
|
571
|
+
url,
|
|
572
|
+
{ showCompiledHint = false, preferRelativeUrls = false } = {},
|
|
573
|
+
) => {
|
|
561
574
|
if (
|
|
562
575
|
!url.startsWith("http:") &&
|
|
563
576
|
!url.startsWith("https:") &&
|
|
@@ -565,7 +578,22 @@ export const createRollupPlugins = async ({
|
|
|
565
578
|
) {
|
|
566
579
|
return url
|
|
567
580
|
}
|
|
568
|
-
|
|
581
|
+
const originalUrl = asOriginalUrl(url)
|
|
582
|
+
const isCompiled = urlIsInsideOf(url, compileServerOrigin)
|
|
583
|
+
const originalRelativeUrl = urlToRelativeUrl(
|
|
584
|
+
originalUrl,
|
|
585
|
+
projectDirectoryUrl,
|
|
586
|
+
)
|
|
587
|
+
if (showCompiledHint && isCompiled) {
|
|
588
|
+
if (preferRelativeUrls) {
|
|
589
|
+
return `${originalRelativeUrl}[compiled]`
|
|
590
|
+
}
|
|
591
|
+
return `${originalUrl}[compiled]`
|
|
592
|
+
}
|
|
593
|
+
if (preferRelativeUrls) {
|
|
594
|
+
return originalRelativeUrl
|
|
595
|
+
}
|
|
596
|
+
return originalUrl
|
|
569
597
|
},
|
|
570
598
|
resolveRessourceUrl: ({
|
|
571
599
|
ressourceSpecifier,
|
|
@@ -573,87 +601,85 @@ export const createRollupPlugins = async ({
|
|
|
573
601
|
// isRessourceHint,
|
|
574
602
|
ressourceImporter,
|
|
575
603
|
}) => {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
)
|
|
585
|
-
const jsModuleUrl = resolveUrl(
|
|
586
|
-
ressourceSpecifier,
|
|
587
|
-
importerCompiledUrl,
|
|
588
|
-
)
|
|
589
|
-
return jsModuleUrl
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
let ressourceUrl
|
|
593
|
-
if (
|
|
594
|
-
ressourceImporter.isEntryPoint &&
|
|
595
|
-
!ressourceImporter.isJsModule
|
|
596
|
-
) {
|
|
597
|
-
// Entry point (likely html, unlikely css) is referecing a ressource
|
|
598
|
-
// when importmap, parse the original importmap ressource
|
|
599
|
-
if (ressourceSpecifier.endsWith(".importmap")) {
|
|
600
|
-
ressourceUrl = resolveUrl(
|
|
601
|
-
ressourceSpecifier,
|
|
604
|
+
const getRessourceUrl = () => {
|
|
605
|
+
// Entry point is not a JS module and references a js module (html referencing js)
|
|
606
|
+
if (
|
|
607
|
+
ressourceImporter.isEntryPoint &&
|
|
608
|
+
!ressourceImporter.isJsModule &&
|
|
609
|
+
isJsModule
|
|
610
|
+
) {
|
|
611
|
+
const importerCompiledUrl = asCompiledServerUrl(
|
|
602
612
|
ressourceImporter.url,
|
|
603
613
|
)
|
|
604
|
-
|
|
614
|
+
const jsModuleUrl = resolveUrl(
|
|
615
|
+
ressourceSpecifier,
|
|
616
|
+
importerCompiledUrl,
|
|
617
|
+
)
|
|
618
|
+
return jsModuleUrl
|
|
619
|
+
}
|
|
620
|
+
// Entry point (likely html, unlikely css) is referecing a ressource
|
|
621
|
+
// In this situation:
|
|
622
|
+
// - when importmap is referenced: parse the original importmap ressource
|
|
623
|
+
// - other ressource: force compilation (because the HTML url is the original url)
|
|
624
|
+
if (
|
|
625
|
+
ressourceImporter.isEntryPoint &&
|
|
626
|
+
!ressourceImporter.isJsModule
|
|
627
|
+
) {
|
|
628
|
+
if (ressourceSpecifier.endsWith(".importmap")) {
|
|
629
|
+
const importmapUrl = resolveUrl(
|
|
630
|
+
ressourceSpecifier,
|
|
631
|
+
ressourceImporter.url,
|
|
632
|
+
)
|
|
633
|
+
return importmapUrl
|
|
634
|
+
}
|
|
605
635
|
const importerCompiled = asCompiledServerUrl(
|
|
606
636
|
ressourceImporter.url,
|
|
607
637
|
)
|
|
608
|
-
|
|
638
|
+
const ressourceCompiledUrl = resolveUrl(
|
|
639
|
+
ressourceSpecifier,
|
|
640
|
+
importerCompiled,
|
|
641
|
+
)
|
|
642
|
+
return ressourceCompiledUrl
|
|
609
643
|
}
|
|
610
|
-
|
|
611
|
-
ressourceUrl = resolveUrl(
|
|
644
|
+
const ressourceCompiledUrl = resolveUrl(
|
|
612
645
|
ressourceSpecifier,
|
|
613
646
|
ressourceImporter.url,
|
|
614
647
|
)
|
|
648
|
+
return ressourceCompiledUrl
|
|
615
649
|
}
|
|
650
|
+
const ressourceUrl = getRessourceUrl()
|
|
651
|
+
const resolutionResult = { url: ressourceUrl }
|
|
652
|
+
const ressourceOriginalUrl =
|
|
653
|
+
asOriginalUrl(ressourceUrl) || ressourceUrl
|
|
616
654
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
// and ignore them and console.info/debug about remote url (https, http, ...)
|
|
620
|
-
const projectUrl = asProjectUrl(ressourceUrl)
|
|
621
|
-
if (!projectUrl) {
|
|
622
|
-
return {
|
|
623
|
-
isExternal: true,
|
|
624
|
-
url: ressourceUrl,
|
|
625
|
-
}
|
|
655
|
+
if (!urlIsInsideOf(ressourceUrl, compileServerOrigin)) {
|
|
656
|
+
resolutionResult.isCrossOrigin = true
|
|
626
657
|
}
|
|
627
658
|
|
|
628
|
-
const
|
|
629
|
-
if (
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
if (serviceWorkerUrls.includes(originalUrl)) {
|
|
637
|
-
return {
|
|
638
|
-
isServiceWorker: true,
|
|
639
|
-
isJsModule: true,
|
|
640
|
-
url: ressourceUrl,
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
if (classicWorkerUrls.includes(originalUrl)) {
|
|
644
|
-
return {
|
|
645
|
-
isWorker: true,
|
|
646
|
-
url: ressourceUrl,
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
if (classicServiceWorkerUrls.includes(originalUrl)) {
|
|
650
|
-
return {
|
|
651
|
-
isServiceWorker: true,
|
|
652
|
-
url: ressourceUrl,
|
|
653
|
-
}
|
|
659
|
+
const urlMeta = urlMetaGetter(ressourceOriginalUrl)
|
|
660
|
+
if (urlMeta.preserve) {
|
|
661
|
+
resolutionResult.isExternal = true
|
|
662
|
+
} else if (jsenvRemoteDirectory.isRemoteUrl(ressourceOriginalUrl)) {
|
|
663
|
+
const fileUrl =
|
|
664
|
+
jsenvRemoteDirectory.fileUrlFromRemoteUrl(ressourceOriginalUrl)
|
|
665
|
+
const compiledFileUrl = asCompiledServerUrl(fileUrl)
|
|
666
|
+
resolutionResult.url = compiledFileUrl
|
|
654
667
|
}
|
|
655
668
|
|
|
656
|
-
|
|
669
|
+
if (workerUrls.includes(ressourceOriginalUrl)) {
|
|
670
|
+
resolutionResult.isWorker = true
|
|
671
|
+
resolutionResult.isJsModule = true
|
|
672
|
+
} else if (serviceWorkerUrls.includes(ressourceOriginalUrl)) {
|
|
673
|
+
resolutionResult.isServiceWorker = true
|
|
674
|
+
resolutionResult.isJsModule = true
|
|
675
|
+
} else if (classicWorkerUrls.includes(ressourceOriginalUrl)) {
|
|
676
|
+
resolutionResult.isWorker = true
|
|
677
|
+
} else if (
|
|
678
|
+
classicServiceWorkerUrls.includes(ressourceOriginalUrl)
|
|
679
|
+
) {
|
|
680
|
+
resolutionResult.isServiceWorker = true
|
|
681
|
+
}
|
|
682
|
+
return resolutionResult
|
|
657
683
|
},
|
|
658
684
|
onJsModule: ({ ressource, jsModuleUrl, jsModuleIsInline }) => {
|
|
659
685
|
// we want to emit chunk only when ressource is referenced by something else than rollup
|
|
@@ -663,7 +689,6 @@ export const createRollupPlugins = async ({
|
|
|
663
689
|
) {
|
|
664
690
|
return null
|
|
665
691
|
}
|
|
666
|
-
|
|
667
692
|
if (ressource.isEntryPoint) {
|
|
668
693
|
} else {
|
|
669
694
|
const importerUrl = resolveUrl(
|
|
@@ -679,40 +704,48 @@ export const createRollupPlugins = async ({
|
|
|
679
704
|
if (jsModuleIsInline) {
|
|
680
705
|
inlineModuleScripts[jsModuleUrl] = ressource
|
|
681
706
|
urlCustomLoaders[jsModuleUrl] = async () => {
|
|
707
|
+
const url = asOriginalUrl(jsModuleUrl) // transformJs expect a file:// url
|
|
708
|
+
let code = String(ressource.bufferBeforeBuild)
|
|
682
709
|
const transformResult = await transformJs({
|
|
683
|
-
code: String(
|
|
684
|
-
inlineModuleScripts[jsModuleUrl].bufferBeforeBuild,
|
|
685
|
-
),
|
|
686
|
-
url: asOriginalUrl(jsModuleUrl), // transformJs expect a file:// url
|
|
687
710
|
projectDirectoryUrl,
|
|
711
|
+
jsenvRemoteDirectory,
|
|
712
|
+
url,
|
|
688
713
|
babelPluginMap,
|
|
689
714
|
// moduleOutFormat: format // we are compiling for rollup output must be "esmodule"
|
|
690
715
|
// we compile for rollup, let top level await untouched
|
|
691
716
|
// it will be converted, if needed, during "renderChunk" hook
|
|
692
717
|
topLevelAwait: "ignore",
|
|
718
|
+
// if we put babel helpers, rollup might try to share them and a file
|
|
719
|
+
// might try to import from an inline script resulting in 404.
|
|
720
|
+
babelHelpersInjectionAsImport: false,
|
|
721
|
+
code,
|
|
693
722
|
})
|
|
694
|
-
let code = transformResult.code
|
|
695
|
-
let map = transformResult.map
|
|
696
723
|
return {
|
|
697
|
-
code,
|
|
698
|
-
map,
|
|
724
|
+
code: transformResult.code,
|
|
725
|
+
map: transformResult.map,
|
|
699
726
|
}
|
|
700
727
|
}
|
|
701
728
|
}
|
|
702
729
|
}
|
|
703
|
-
|
|
704
|
-
const
|
|
730
|
+
const fileName = ressource.buildRelativeUrlWithoutHash
|
|
731
|
+
const name = urlToBasename(resolveUrl(fileName, "file://"))
|
|
705
732
|
const rollupReferenceId = emitChunk({
|
|
706
733
|
id: jsModuleUrl,
|
|
707
|
-
name
|
|
734
|
+
name,
|
|
735
|
+
...(useImportMapToMaximizeCacheReuse && !ressource.isInline
|
|
736
|
+
? { fileName }
|
|
737
|
+
: {}),
|
|
708
738
|
})
|
|
709
739
|
return {
|
|
710
740
|
rollupReferenceId,
|
|
711
|
-
fileName
|
|
741
|
+
fileName:
|
|
742
|
+
useImportMapToMaximizeCacheReuse && !ressource.isInline
|
|
743
|
+
? fileName
|
|
744
|
+
: name,
|
|
712
745
|
}
|
|
713
746
|
},
|
|
714
747
|
onAsset: ({ ressource }) => {
|
|
715
|
-
const fileName = ressource.
|
|
748
|
+
const fileName = ressource.buildRelativeUrlWithoutHash
|
|
716
749
|
const rollupReferenceId = emitAsset({
|
|
717
750
|
fileName,
|
|
718
751
|
})
|
|
@@ -727,7 +760,7 @@ export const createRollupPlugins = async ({
|
|
|
727
760
|
ressource.bufferAfterBuild,
|
|
728
761
|
)
|
|
729
762
|
},
|
|
730
|
-
|
|
763
|
+
buildUrlGenerator,
|
|
731
764
|
},
|
|
732
765
|
)
|
|
733
766
|
|
|
@@ -819,13 +852,13 @@ export const createRollupPlugins = async ({
|
|
|
819
852
|
return asRollupUrl(specifier)
|
|
820
853
|
}
|
|
821
854
|
|
|
822
|
-
const
|
|
855
|
+
const specifierUrl = await importResolver.resolveImport(
|
|
823
856
|
specifier,
|
|
824
857
|
importerUrl,
|
|
825
858
|
)
|
|
826
|
-
const existingImporter = urlImporterMap[
|
|
859
|
+
const existingImporter = urlImporterMap[specifierUrl]
|
|
827
860
|
if (!existingImporter) {
|
|
828
|
-
urlImporterMap[
|
|
861
|
+
urlImporterMap[specifierUrl] = importAssertionInfo
|
|
829
862
|
? {
|
|
830
863
|
url: importerUrl,
|
|
831
864
|
column: importAssertionInfo.column,
|
|
@@ -839,37 +872,41 @@ export const createRollupPlugins = async ({
|
|
|
839
872
|
line: undefined,
|
|
840
873
|
}
|
|
841
874
|
}
|
|
842
|
-
|
|
843
875
|
// keep external url intact
|
|
844
|
-
const
|
|
845
|
-
if (!
|
|
876
|
+
const specifierProjectUrl = asProjectUrl(specifierUrl)
|
|
877
|
+
if (!specifierProjectUrl) {
|
|
846
878
|
onExternal({
|
|
847
879
|
specifier,
|
|
848
880
|
reason: `outside project directory`,
|
|
849
881
|
})
|
|
850
882
|
return { id: specifier, external: true }
|
|
851
883
|
}
|
|
852
|
-
|
|
853
|
-
|
|
884
|
+
const specifierOriginalUrl = asOriginalUrl(specifierProjectUrl)
|
|
885
|
+
const urlMeta = urlMetaGetter(specifierOriginalUrl)
|
|
886
|
+
if (urlMeta.preserve) {
|
|
887
|
+
if (urlMeta.remote) {
|
|
888
|
+
specifier =
|
|
889
|
+
jsenvRemoteDirectory.remoteUrlFromFileUrl(specifierOriginalUrl)
|
|
890
|
+
}
|
|
854
891
|
onExternal({
|
|
855
892
|
specifier,
|
|
856
|
-
reason: `matches "
|
|
893
|
+
reason: `matches "preservedUrls"`,
|
|
857
894
|
})
|
|
858
895
|
return { id: specifier, external: true }
|
|
859
896
|
}
|
|
860
|
-
|
|
861
897
|
// const rollupId = urlToRollupId(importUrl, { projectDirectoryUrl, compileServerOrigin })
|
|
862
898
|
// logger.debug(`${specifier} imported by ${importer} resolved to ${importUrl}`)
|
|
863
|
-
|
|
899
|
+
const specifierRollupUrl = asRollupUrl(specifierUrl)
|
|
900
|
+
return specifierRollupUrl
|
|
864
901
|
},
|
|
865
902
|
|
|
866
903
|
resolveFileUrl: ({ referenceId, fileName }) => {
|
|
867
904
|
ressourcesReferencedByJs.push(fileName)
|
|
868
|
-
const
|
|
905
|
+
const getAssetRelativeUrl = () => {
|
|
869
906
|
const ressource = ressourceBuilder.findRessource((ressource) => {
|
|
870
907
|
return ressource.rollupReferenceId === referenceId
|
|
871
908
|
})
|
|
872
|
-
ressource.
|
|
909
|
+
ressource.buildRelativeUrlWithoutHash = fileName
|
|
873
910
|
const buildRelativeUrl = ressource.buildRelativeUrl
|
|
874
911
|
return buildRelativeUrl
|
|
875
912
|
}
|
|
@@ -877,16 +914,16 @@ export const createRollupPlugins = async ({
|
|
|
877
914
|
if (!node && useImportMapToMaximizeCacheReuse && urlVersioning) {
|
|
878
915
|
return `window.__resolveImportUrl__("./${fileName}", import.meta.url)`
|
|
879
916
|
}
|
|
880
|
-
return `new URL("${
|
|
917
|
+
return `new URL("${getAssetRelativeUrl()}", import.meta.url)`
|
|
881
918
|
}
|
|
882
919
|
if (format === "systemjs") {
|
|
883
920
|
return `new URL(System.resolve("./${fileName}", module.meta.url))`
|
|
884
921
|
}
|
|
885
922
|
if (format === "global") {
|
|
886
|
-
return `new URL("${
|
|
923
|
+
return `new URL("${getAssetRelativeUrl()}", document.currentScript && document.currentScript.src || document.baseURI)`
|
|
887
924
|
}
|
|
888
925
|
if (format === "commonjs") {
|
|
889
|
-
return `new URL("${
|
|
926
|
+
return `new URL("${getAssetRelativeUrl()}", "file:///" + __filename.replace(/\\/g, "/"))`
|
|
890
927
|
}
|
|
891
928
|
return null
|
|
892
929
|
},
|
|
@@ -900,37 +937,62 @@ export const createRollupPlugins = async ({
|
|
|
900
937
|
if (rollupUrl === EMPTY_CHUNK_URL) {
|
|
901
938
|
return ""
|
|
902
939
|
}
|
|
903
|
-
|
|
904
940
|
let url = asServerUrl(rollupUrl)
|
|
905
|
-
|
|
906
|
-
const loadResult = await buildOperation.withSignal((signal) => {
|
|
907
|
-
return urlLoader.loadUrl(rollupUrl, {
|
|
908
|
-
signal,
|
|
909
|
-
logger,
|
|
910
|
-
})
|
|
911
|
-
})
|
|
912
|
-
|
|
913
|
-
if (loadResult.url) url = loadResult.url
|
|
914
|
-
const code = loadResult.code
|
|
915
|
-
const map = loadResult.map
|
|
916
|
-
|
|
917
941
|
// Jsenv helpers are injected as import statements to provide code like babel helpers
|
|
918
942
|
// For now we just compute the information that the target file is a jsenv helper
|
|
919
943
|
// without doing anything special with "targetIsJsenvHelperFile" information
|
|
944
|
+
const projectUrl = asProjectUrl(rollupUrl)
|
|
920
945
|
const originalUrl = asOriginalUrl(rollupUrl)
|
|
921
946
|
const isJsenvHelperFile = urlIsInsideOf(
|
|
922
947
|
originalUrl,
|
|
923
948
|
jsenvHelpersDirectoryInfo.url,
|
|
924
949
|
)
|
|
925
950
|
// const isEntryPoint = entryPointUrls[originalUrl]
|
|
926
|
-
|
|
951
|
+
const loadResult = await buildOperation.withSignal((signal) => {
|
|
952
|
+
let urlToLoad
|
|
953
|
+
const jsModuleRessource = ressourceBuilder.findRessource(
|
|
954
|
+
(ressource) => ressource.url === url,
|
|
955
|
+
)
|
|
956
|
+
if (
|
|
957
|
+
jsModuleRessource &&
|
|
958
|
+
jsModuleRessource.firstStrongReference &&
|
|
959
|
+
jsModuleRessource.firstStrongReference.integrity
|
|
960
|
+
) {
|
|
961
|
+
urlToLoad = setUrlSearchParamsDescriptor(url, {
|
|
962
|
+
integrity: jsModuleRessource.firstStrongReference.integrity,
|
|
963
|
+
})
|
|
964
|
+
urlImporterMap[urlToLoad] = urlImporterMap[url]
|
|
965
|
+
} else {
|
|
966
|
+
urlToLoad = url
|
|
967
|
+
}
|
|
968
|
+
return urlLoader.loadUrl(urlToLoad, {
|
|
969
|
+
signal,
|
|
970
|
+
logger,
|
|
971
|
+
})
|
|
972
|
+
})
|
|
973
|
+
// if (loadResult.url) url = loadResult.url
|
|
974
|
+
const code = loadResult.code
|
|
975
|
+
const map = loadResult.map
|
|
976
|
+
if (jsenvRemoteDirectory.isFileUrlForRemoteUrl(originalUrl)) {
|
|
977
|
+
map.sources.forEach((source, index) => {
|
|
978
|
+
if (jsenvRemoteDirectory.isRemoteUrl(source)) {
|
|
979
|
+
const sourceFileUrl =
|
|
980
|
+
jsenvRemoteDirectory.fileUrlFromRemoteUrl(source)
|
|
981
|
+
const sourceRelativeUrl = urlToRelativeUrl(
|
|
982
|
+
sourceFileUrl,
|
|
983
|
+
projectUrl,
|
|
984
|
+
)
|
|
985
|
+
map.sources[index] = sourceRelativeUrl
|
|
986
|
+
}
|
|
987
|
+
})
|
|
988
|
+
}
|
|
927
989
|
const importer = urlImporterMap[url]
|
|
928
990
|
// Inform ressource builder that this js module exists
|
|
929
991
|
// It can only be a js module and happens when:
|
|
930
992
|
// - entry point (html) references js
|
|
931
993
|
// - js is referenced by static or dynamic imports
|
|
932
994
|
// For import assertions, the imported ressource (css,json,...)
|
|
933
|
-
// is
|
|
995
|
+
// is already converted to a js module
|
|
934
996
|
ressourceBuilder.createReferenceFoundByRollup({
|
|
935
997
|
contentTypeExpected: "application/javascript",
|
|
936
998
|
referenceLabel: "static or dynamic import",
|
|
@@ -940,10 +1002,9 @@ export const createRollupPlugins = async ({
|
|
|
940
1002
|
ressourceSpecifier: url,
|
|
941
1003
|
isJsenvHelperFile,
|
|
942
1004
|
contentType: "application/javascript",
|
|
943
|
-
bufferBeforeBuild: Buffer.from(code),
|
|
944
1005
|
isJsModule: true,
|
|
1006
|
+
bufferBeforeBuild: Buffer.from(code),
|
|
945
1007
|
})
|
|
946
|
-
|
|
947
1008
|
return {
|
|
948
1009
|
code,
|
|
949
1010
|
map,
|
|
@@ -960,7 +1021,6 @@ export const createRollupPlugins = async ({
|
|
|
960
1021
|
})
|
|
961
1022
|
// const moduleInfo = this.getModuleInfo(id)
|
|
962
1023
|
const url = asServerUrl(id)
|
|
963
|
-
|
|
964
1024
|
const mutations = []
|
|
965
1025
|
await visitImportReferences({
|
|
966
1026
|
ast,
|
|
@@ -1200,7 +1260,6 @@ export const createRollupPlugins = async ({
|
|
|
1200
1260
|
code = magicString.toString()
|
|
1201
1261
|
map = magicString.generateMap({ hires: true })
|
|
1202
1262
|
}
|
|
1203
|
-
|
|
1204
1263
|
return { code, map }
|
|
1205
1264
|
},
|
|
1206
1265
|
|
|
@@ -1228,6 +1287,9 @@ export const createRollupPlugins = async ({
|
|
|
1228
1287
|
return entryPoints
|
|
1229
1288
|
}
|
|
1230
1289
|
outputOptions.chunkFileNames = (chunkInfo) => {
|
|
1290
|
+
// maybe we should find ressource from ressource builder and return
|
|
1291
|
+
// the buildRelativeUrlPattern?
|
|
1292
|
+
|
|
1231
1293
|
// const originalUrl = asOriginalUrl(chunkInfo.facadeModuleId)
|
|
1232
1294
|
// const basename = urlToBasename(originalUrl)
|
|
1233
1295
|
if (useImportMapToMaximizeCacheReuse) {
|
|
@@ -1245,30 +1307,41 @@ export const createRollupPlugins = async ({
|
|
|
1245
1307
|
: `[name]${outputExtension}`
|
|
1246
1308
|
}
|
|
1247
1309
|
|
|
1310
|
+
const getStringAfter = (string, substring) => {
|
|
1311
|
+
const index = string.indexOf(substring)
|
|
1312
|
+
if (index === -1) return ""
|
|
1313
|
+
return string.slice(index + substring.length)
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1248
1316
|
// rollup does not expects to have http dependency in the mix: fix them
|
|
1249
1317
|
outputOptions.sourcemapPathTransform = (relativePath, sourcemapPath) => {
|
|
1250
1318
|
const sourcemapUrl = fileSystemPathToUrl(sourcemapPath)
|
|
1251
|
-
const url = relativePathToUrl(relativePath, sourcemapUrl)
|
|
1252
|
-
const serverUrl = asServerUrl(url)
|
|
1253
|
-
const finalUrl =
|
|
1254
|
-
urlFetcher.getUrlBeforeRedirection(serverUrl) || serverUrl
|
|
1255
|
-
const projectUrl = asProjectUrl(finalUrl)
|
|
1256
|
-
|
|
1257
|
-
if (projectUrl) {
|
|
1258
|
-
relativePath = urlToRelativeUrl(projectUrl, sourcemapUrl)
|
|
1259
|
-
return relativePath
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
return finalUrl
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
const relativePathToUrl = (relativePath, sourcemapUrl) => {
|
|
1266
|
-
const rollupUrl = resolveUrl(relativePath, sourcemapUrl)
|
|
1267
1319
|
// here relativePath contains a protocol
|
|
1268
1320
|
// because rollup don't work with url but with filesystem paths
|
|
1269
1321
|
// let fix it below
|
|
1270
|
-
const
|
|
1271
|
-
|
|
1322
|
+
const sourceRollupUrlRaw = resolveUrl(relativePath, sourcemapUrl)
|
|
1323
|
+
const afterOrigin =
|
|
1324
|
+
getStringAfter(sourceRollupUrlRaw, "http:/jsenv.com") ||
|
|
1325
|
+
getStringAfter(sourceRollupUrlRaw, "https:/jsenv.com")
|
|
1326
|
+
const sourceRollupUrl = afterOrigin
|
|
1327
|
+
? `${compileServerOriginForRollup}${afterOrigin}`
|
|
1328
|
+
: sourceRollupUrlRaw
|
|
1329
|
+
|
|
1330
|
+
const sourceServerUrl = asServerUrl(sourceRollupUrl)
|
|
1331
|
+
const sourceUrl =
|
|
1332
|
+
urlFetcher.getUrlBeforeRedirection(sourceServerUrl) || sourceServerUrl
|
|
1333
|
+
const sourceProjectUrl = asProjectUrl(sourceUrl)
|
|
1334
|
+
|
|
1335
|
+
if (jsenvRemoteDirectory.isFileUrlForRemoteUrl(sourceProjectUrl)) {
|
|
1336
|
+
const remoteUrl =
|
|
1337
|
+
jsenvRemoteDirectory.remoteUrlFromFileUrl(sourceProjectUrl)
|
|
1338
|
+
return remoteUrl
|
|
1339
|
+
}
|
|
1340
|
+
if (sourceProjectUrl) {
|
|
1341
|
+
relativePath = urlToRelativeUrl(sourceProjectUrl, sourcemapUrl)
|
|
1342
|
+
return relativePath
|
|
1343
|
+
}
|
|
1344
|
+
return sourceUrl
|
|
1272
1345
|
}
|
|
1273
1346
|
|
|
1274
1347
|
return outputOptions
|
|
@@ -1379,26 +1452,34 @@ export const createRollupPlugins = async ({
|
|
|
1379
1452
|
// }
|
|
1380
1453
|
} else {
|
|
1381
1454
|
const originalProjectUrl = asOriginalUrl(ressourceUrl)
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1455
|
+
if (jsenvRemoteDirectory.isFileUrlForRemoteUrl(originalProjectUrl)) {
|
|
1456
|
+
const remoteUrl =
|
|
1457
|
+
jsenvRemoteDirectory.remoteUrlFromFileUrl(originalProjectUrl)
|
|
1458
|
+
buildMappings[remoteUrl] = jsRessource.buildRelativeUrl
|
|
1459
|
+
} else {
|
|
1460
|
+
const originalProjectRelativeUrl = urlToRelativeUrl(
|
|
1461
|
+
originalProjectUrl,
|
|
1462
|
+
projectDirectoryUrl,
|
|
1463
|
+
)
|
|
1464
|
+
buildMappings[originalProjectRelativeUrl] =
|
|
1465
|
+
jsRessource.buildRelativeUrl
|
|
1466
|
+
}
|
|
1388
1467
|
}
|
|
1389
|
-
ressourceMappings[jsRessource.
|
|
1468
|
+
ressourceMappings[jsRessource.buildRelativeUrlWithoutHash] =
|
|
1469
|
+
jsRessource.buildRelativeUrl
|
|
1390
1470
|
})
|
|
1391
1471
|
// wait for asset build relative urls
|
|
1392
1472
|
// to ensure the importmap will contain remappings for them
|
|
1393
1473
|
// (not sure this is required anymore)
|
|
1394
1474
|
await Promise.all(
|
|
1395
|
-
ressourcesReferencedByJs.map(async (
|
|
1475
|
+
ressourcesReferencedByJs.map(async (ressourceFileName) => {
|
|
1396
1476
|
const ressource = ressourceBuilder.findRessource((ressource) => {
|
|
1397
|
-
return ressource.
|
|
1477
|
+
return ressource.buildRelativeUrlWithoutHash === ressourceFileName
|
|
1398
1478
|
})
|
|
1399
1479
|
if (ressource && !ressource.isJsModule) {
|
|
1400
1480
|
await ressource.getReadyPromise()
|
|
1401
|
-
ressourceMappings[
|
|
1481
|
+
ressourceMappings[ressource.buildRelativeUrlWithoutHash] =
|
|
1482
|
+
ressource.buildRelativeUrl
|
|
1402
1483
|
}
|
|
1403
1484
|
}),
|
|
1404
1485
|
)
|
|
@@ -1423,7 +1504,7 @@ export const createRollupPlugins = async ({
|
|
|
1423
1504
|
const assetRessource = ressourceBuilder.findRessource(
|
|
1424
1505
|
(ressource) =>
|
|
1425
1506
|
// happens for import.meta.url pattern
|
|
1426
|
-
ressource.
|
|
1507
|
+
ressource.buildRelativeUrlWithoutHash === fileName ||
|
|
1427
1508
|
// happens for sourcemap
|
|
1428
1509
|
ressource.relativeUrl === fileName,
|
|
1429
1510
|
)
|
|
@@ -1452,7 +1533,8 @@ export const createRollupPlugins = async ({
|
|
|
1452
1533
|
// in case sourcemap is mutated, we must not trust rollup but the asset builder source instead
|
|
1453
1534
|
rollupFileInfo.source = assetRessource.bufferAfterBuild
|
|
1454
1535
|
assetBuild[buildRelativeUrl] = rollupFileInfo
|
|
1455
|
-
ressourceMappings[assetRessource.
|
|
1536
|
+
ressourceMappings[assetRessource.buildRelativeUrlWithoutHash] =
|
|
1537
|
+
buildRelativeUrl
|
|
1456
1538
|
if (assetRessource.bufferBeforeBuild) {
|
|
1457
1539
|
const originalProjectUrl = asOriginalUrl(assetRessource.url)
|
|
1458
1540
|
const originalProjectRelativeUrl = urlToRelativeUrl(
|
|
@@ -1643,26 +1725,6 @@ const prepareEntryPoints = async (
|
|
|
1643
1725
|
return entryPointsPrepared
|
|
1644
1726
|
}
|
|
1645
1727
|
|
|
1646
|
-
const fixRollupUrl = (rollupUrl) => {
|
|
1647
|
-
// fix rollup not supporting source being http
|
|
1648
|
-
const httpIndex = rollupUrl.indexOf(`http:/`, 1)
|
|
1649
|
-
if (httpIndex > -1) {
|
|
1650
|
-
return `http://${rollupUrl.slice(httpIndex + `http:/`.length)}`
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
const httpsIndex = rollupUrl.indexOf("https:/", 1)
|
|
1654
|
-
if (httpsIndex > -1) {
|
|
1655
|
-
return `https://${rollupUrl.slice(httpsIndex + `https:/`.length)}`
|
|
1656
|
-
}
|
|
1657
|
-
|
|
1658
|
-
const fileIndex = rollupUrl.indexOf("file:", 1)
|
|
1659
|
-
if (fileIndex > -1) {
|
|
1660
|
-
return `file://${rollupUrl.slice(fileIndex + `file:`.length)}`
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
return rollupUrl
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
1728
|
const normalizeRollupResolveReturnValue = (resolveReturnValue) => {
|
|
1667
1729
|
if (resolveReturnValue === null) {
|
|
1668
1730
|
return { id: null, external: true }
|
|
@@ -1674,25 +1736,36 @@ const normalizeRollupResolveReturnValue = (resolveReturnValue) => {
|
|
|
1674
1736
|
return resolveReturnValue
|
|
1675
1737
|
}
|
|
1676
1738
|
|
|
1677
|
-
const
|
|
1678
|
-
externalImportUrlPatterns,
|
|
1739
|
+
const createUrlMetaGetter = ({
|
|
1679
1740
|
projectDirectoryUrl,
|
|
1680
|
-
|
|
1681
|
-
|
|
1741
|
+
jsenvRemoteDirectory,
|
|
1742
|
+
preservedUrls,
|
|
1743
|
+
}) => {
|
|
1744
|
+
const preservedFileUrls = {}
|
|
1745
|
+
const remoteFileUrls = {}
|
|
1746
|
+
Object.keys(preservedUrls).forEach((pattern) => {
|
|
1747
|
+
if (jsenvRemoteDirectory.isRemoteUrl(pattern)) {
|
|
1748
|
+
const fileUrlPattern = jsenvRemoteDirectory.fileUrlFromRemoteUrl(pattern)
|
|
1749
|
+
preservedFileUrls[fileUrlPattern] = preservedUrls[pattern]
|
|
1750
|
+
remoteFileUrls[fileUrlPattern] = true
|
|
1751
|
+
}
|
|
1752
|
+
})
|
|
1753
|
+
const structuredMetaMap = normalizeStructuredMetaMap(
|
|
1682
1754
|
{
|
|
1683
|
-
|
|
1684
|
-
...
|
|
1685
|
-
|
|
1755
|
+
preserve: {
|
|
1756
|
+
...preservedUrls,
|
|
1757
|
+
...preservedFileUrls,
|
|
1686
1758
|
},
|
|
1759
|
+
remote: remoteFileUrls,
|
|
1687
1760
|
},
|
|
1688
1761
|
projectDirectoryUrl,
|
|
1689
1762
|
)
|
|
1690
1763
|
return (url) => {
|
|
1691
1764
|
const meta = urlToMeta({
|
|
1692
1765
|
url,
|
|
1693
|
-
structuredMetaMap
|
|
1766
|
+
structuredMetaMap,
|
|
1694
1767
|
})
|
|
1695
|
-
return
|
|
1768
|
+
return meta
|
|
1696
1769
|
}
|
|
1697
1770
|
}
|
|
1698
1771
|
|