@jsenv/core 25.1.1 → 25.3.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.
Files changed (57) hide show
  1. package/dist/browser_runtime/browser_runtime_91c5a3b8.js.map +2 -2
  2. package/dist/build_manifest.js +4 -4
  3. package/dist/compile_proxy/asset-manifest.json +2 -2
  4. package/dist/compile_proxy/{compile_proxy_e3b0c442_809f35f7.js.map → compile_proxy.html__inline__20_809f35f7.js.map} +0 -0
  5. package/dist/compile_proxy/{compile_proxy_7ad5faa6.html → compile_proxy_8dfaee51.html} +3 -4
  6. package/dist/redirector/asset-manifest.json +2 -2
  7. package/dist/redirector/{redirector_e3b0c442_e391410e.js.map → redirector.html__inline__15_e391410e.js.map} +0 -0
  8. package/dist/redirector/{redirector_eb92e8a7.html → redirector_3e9a97b9.html} +3 -4
  9. package/dist/toolbar/asset-manifest.json +1 -1
  10. package/dist/toolbar/{toolbar_f7b8a263.html → toolbar_361afb84.html} +2 -3
  11. package/dist/toolbar_injector/asset-manifest.json +2 -2
  12. package/dist/toolbar_injector/{toolbar_injector_49e4756e.js → toolbar_injector_fac1e995.js} +2 -2
  13. package/dist/toolbar_injector/{toolbar_injector_49e4756e.js.map → toolbar_injector_fac1e995.js.map} +2 -2
  14. package/package.json +13 -9
  15. package/readme.md +73 -79
  16. package/src/buildProject.js +21 -13
  17. package/src/commonJsToJavaScriptModule.js +8 -7
  18. package/src/dev_server.js +2 -0
  19. package/src/execute.js +2 -0
  20. package/src/executeTestPlan.js +4 -1
  21. package/src/internal/building/buildUsingRollup.js +4 -2
  22. package/src/internal/building/build_stats.js +3 -0
  23. package/src/internal/building/build_url_generator.js +153 -0
  24. package/src/internal/building/css/parseCssRessource.js +32 -26
  25. package/src/internal/building/html/parseHtmlRessource.js +93 -68
  26. package/src/internal/building/js/parseJsRessource.js +4 -7
  27. package/src/internal/building/parseRessource.js +3 -0
  28. package/src/internal/building/ressource_builder.js +64 -62
  29. package/src/internal/building/ressource_builder_util.js +17 -5
  30. package/src/internal/building/rollup_plugin_jsenv.js +259 -189
  31. package/src/internal/building/url_fetcher.js +16 -7
  32. package/src/internal/building/url_loader.js +1 -5
  33. package/src/internal/building/url_versioning.js +0 -173
  34. package/src/internal/compiling/babel_plugin_import_metadata.js +7 -11
  35. package/src/internal/compiling/babel_plugin_proxy_external_imports.js +31 -0
  36. package/src/internal/compiling/compile-directory/compile-asset.js +8 -4
  37. package/src/internal/compiling/compile-directory/getOrGenerateCompiledFile.js +43 -8
  38. package/src/internal/compiling/compile-directory/updateMeta.js +4 -8
  39. package/src/internal/compiling/compile-directory/validateCache.js +1 -2
  40. package/src/internal/compiling/compileFile.js +22 -10
  41. package/src/internal/compiling/createCompiledFileService.js +22 -24
  42. package/src/internal/compiling/html_source_file_service.js +9 -9
  43. package/src/internal/compiling/js-compilation-service/babelHelper.js +10 -13
  44. package/src/internal/compiling/js-compilation-service/babel_plugin_babel_helpers_as_jsenv_imports.js +4 -2
  45. package/src/internal/compiling/js-compilation-service/jsenvTransform.js +16 -7
  46. package/src/internal/compiling/js-compilation-service/transformJs.js +9 -5
  47. package/src/internal/compiling/jsenvCompilerForHtml.js +226 -184
  48. package/src/internal/compiling/jsenvCompilerForJavaScript.js +15 -11
  49. package/src/internal/compiling/startCompileServer.js +79 -19
  50. package/src/internal/compiling/transformResultToCompilationResult.js +47 -25
  51. package/src/internal/executing/executePlan.js +2 -0
  52. package/src/internal/fetchUrl.js +3 -2
  53. package/src/internal/jsenv_remote_directory.js +156 -0
  54. package/src/internal/origin_directory_converter.js +62 -0
  55. package/src/internal/response_validation.js +11 -24
  56. package/src/internal/sourceMappingURLUtils.js +10 -0
  57. package/src/internal/url_conversion.js +1 -0
@@ -17,6 +17,8 @@ Or be sure to also reference this url somewhere in the html file like
17
17
  */
18
18
 
19
19
  import { urlToFilename, urlToRelativeUrl, resolveUrl } from "@jsenv/filesystem"
20
+ import { applyAlgoToRepresentationData } from "@jsenv/integrity"
21
+
20
22
 
21
23
  import {
22
24
  parseHtmlString,
@@ -32,6 +34,7 @@ import {
32
34
  stringifySrcset,
33
35
  getHtmlNodeLocation,
34
36
  removeHtmlNode,
37
+ addHtmlNodeAttribute,
35
38
  } from "@jsenv/core/src/internal/compiling/compileHtml.js"
36
39
  import {
37
40
  getJavaScriptSourceMappingUrl,
@@ -172,20 +175,21 @@ const regularScriptSrcVisitor = (
172
175
  if (!srcAttribute) {
173
176
  return null
174
177
  }
175
-
178
+ const integrityAttribute = getHtmlNodeAttributeByName(script, "integrity")
179
+ const integrity = integrityAttribute ? integrityAttribute.value : ""
176
180
  const remoteScriptReference = notifyReferenceFound({
177
181
  referenceLabel: "html script",
178
182
  contentTypeExpected: "application/javascript",
179
183
  ressourceSpecifier: srcAttribute.value,
184
+ integrity,
185
+ ...crossoriginFromHtmlNode(script),
180
186
  ...referenceLocationFromHtmlNode(script, "src"),
181
187
  })
182
188
  return ({ getUrlRelativeToImporter }) => {
183
189
  const ressource = remoteScriptReference.ressource
184
-
185
190
  if (ressource.isExternal) {
186
191
  return
187
192
  }
188
-
189
193
  if (shouldInline({ ressource, htmlNode: script })) {
190
194
  removeHtmlNodeAttribute(script, srcAttribute)
191
195
  const { bufferAfterBuild } = ressource
@@ -200,14 +204,19 @@ const regularScriptSrcVisitor = (
200
204
  const sourcemapInlineUrl = urlToRelativeUrl(sourcemapBuildUrl, htmlUrl)
201
205
  jsString = setJavaScriptSourceMappingUrl(jsString, sourcemapInlineUrl)
202
206
  }
203
-
204
207
  setHtmlNodeText(script, jsString)
205
208
  remoteScriptReference.inlinedCallback()
206
209
  return
207
210
  }
208
-
209
211
  const urlRelativeToImporter = getUrlRelativeToImporter(ressource)
210
212
  srcAttribute.value = urlRelativeToImporter
213
+ if (integrityAttribute) {
214
+ const base64Value = applyAlgoToRepresentationData(
215
+ "sha256",
216
+ ressource.bufferAfterBuild,
217
+ )
218
+ integrityAttribute.value = `sha256-${base64Value}`
219
+ }
211
220
  }
212
221
  }
213
222
 
@@ -233,7 +242,6 @@ const regularScriptTextNodeVisitor = (
233
242
  if (!textNode) {
234
243
  return null
235
244
  }
236
-
237
245
  const scriptId = getIdForInlineHtmlNode(script, scripts)
238
246
  const ressourceSpecifier = `${urlToFilename(
239
247
  htmlRessource.url,
@@ -265,25 +273,25 @@ const moduleScriptSrcVisitor = (script, { format, notifyReferenceFound }) => {
265
273
  if (!srcAttribute) {
266
274
  return null
267
275
  }
268
-
276
+ const integrityAttribute = getHtmlNodeAttributeByName(script, "integrity")
277
+ const integrity = integrityAttribute ? integrityAttribute.value : ""
269
278
  const remoteScriptReference = notifyReferenceFound({
270
279
  referenceLabel: "html module script",
271
280
  contentTypeExpected: "application/javascript",
272
281
  ressourceSpecifier: srcAttribute.value,
282
+ integrity,
283
+ ...crossoriginFromHtmlNode(script),
273
284
  ...referenceLocationFromHtmlNode(script, "src"),
274
285
  isJsModule: true,
275
286
  })
276
287
  return ({ getUrlRelativeToImporter }) => {
277
288
  const { ressource } = remoteScriptReference
278
-
279
289
  if (format === "systemjs") {
280
290
  removeHtmlNodeAttribute(script, typeAttribute)
281
291
  }
282
-
283
292
  if (ressource.isExternal) {
284
293
  return
285
294
  }
286
-
287
295
  if (shouldInline({ ressource, htmlNode: script })) {
288
296
  // here put a warning if we cannot inline importmap because it would mess
289
297
  // the remapping (note that it's feasible) but not yet supported
@@ -298,15 +306,20 @@ const moduleScriptSrcVisitor = (script, { format, notifyReferenceFound }) => {
298
306
  // with these assumptions we can force the sourcemap url
299
307
  const sourcemapUrl = `${ressource.buildRelativeUrl}.map`
300
308
  jsString = setJavaScriptSourceMappingUrl(jsString, sourcemapUrl)
301
-
302
309
  setHtmlNodeText(script, jsString)
303
310
  remoteScriptReference.inlinedCallback()
304
311
  return
305
312
  }
306
-
307
313
  const urlRelativeToImporter = getUrlRelativeToImporter(ressource)
308
314
  const relativeUrlNotation = ensureRelativeUrlNotation(urlRelativeToImporter)
309
315
  srcAttribute.value = relativeUrlNotation
316
+ if (integrityAttribute) {
317
+ const base64Value = applyAlgoToRepresentationData(
318
+ "sha256",
319
+ ressource.bufferAfterBuild,
320
+ )
321
+ integrityAttribute.value = `sha256-${base64Value}`
322
+ }
310
323
  }
311
324
  }
312
325
 
@@ -331,7 +344,6 @@ const moduleScriptTextNodeVisitor = (
331
344
  if (!textNode) {
332
345
  return null
333
346
  }
334
-
335
347
  const scriptId = getIdForInlineHtmlNode(script, scripts)
336
348
  const ressourceSpecifier = `${urlToFilename(
337
349
  htmlRessource.url,
@@ -371,24 +383,24 @@ const importmapScriptSrcVisitor = (
371
383
  if (!srcAttribute) {
372
384
  return null
373
385
  }
374
-
386
+ const integrityAttribute = getHtmlNodeAttributeByName(script, "integrity")
387
+ const integrity = integrityAttribute ? integrityAttribute.value : ""
375
388
  const importmapReference = notifyReferenceFound({
376
389
  referenceLabel: "html importmap",
377
390
  contentTypeExpected: "application/importmap+json",
378
391
  ressourceSpecifier: srcAttribute.value,
392
+ integrity,
393
+ ...crossoriginFromHtmlNode(script),
379
394
  ...referenceLocationFromHtmlNode(script, "src"),
380
395
  })
381
396
  return ({ getUrlRelativeToImporter }) => {
382
397
  const { ressource } = importmapReference
383
-
384
398
  if (format === "systemjs") {
385
399
  typeAttribute.value = "systemjs-importmap"
386
400
  }
387
-
388
401
  if (ressource.isExternal) {
389
402
  return
390
403
  }
391
-
392
404
  if (
393
405
  // for esmodule we always inline the importmap
394
406
  // as it's the only thing supported by Chrome
@@ -402,22 +414,22 @@ const importmapScriptSrcVisitor = (
402
414
  // here put a warning if we cannot inline importmap because it would mess
403
415
  // the remapping (note that it's feasible) but not yet supported
404
416
  const { bufferAfterBuild } = ressource
405
-
406
417
  const importmapString = String(bufferAfterBuild)
407
- replaceHtmlNode(
408
- script,
409
- `<script>
410
- ${importmapString}</script>`,
411
- {
412
- attributesToIgnore: ["src"],
413
- },
414
- )
418
+ removeHtmlNodeAttribute(script, srcAttribute)
419
+ setHtmlNodeText(script, importmapString)
420
+ removeHtmlNodeAttribute(script, integrityAttribute)
415
421
  importmapReference.inlinedCallback()
416
422
  return
417
423
  }
418
-
419
424
  const urlRelativeToImporter = getUrlRelativeToImporter(ressource)
420
425
  srcAttribute.value = urlRelativeToImporter
426
+ if (integrityAttribute) {
427
+ const base64Value = applyAlgoToRepresentationData(
428
+ "sha256",
429
+ ressource.bufferAfterBuild,
430
+ )
431
+ integrityAttribute.value = `sha256-${base64Value}`
432
+ }
421
433
  }
422
434
  }
423
435
 
@@ -442,7 +454,6 @@ const importmapScriptTextNodeVisitor = (
442
454
  if (!textNode) {
443
455
  return null
444
456
  }
445
-
446
457
  const importmapScriptId = getIdForInlineHtmlNode(script, scripts)
447
458
  const importmapReference = notifyReferenceFound({
448
459
  referenceLabel: "html inline importmap",
@@ -459,7 +470,6 @@ const importmapScriptTextNodeVisitor = (
459
470
  if (format === "systemjs") {
460
471
  typeAttribute.value = "systemjs-importmap"
461
472
  }
462
-
463
473
  const { bufferAfterBuild } = importmapReference.ressource
464
474
  textNode.value = bufferAfterBuild
465
475
  }
@@ -481,38 +491,34 @@ const linkStylesheetHrefVisitor = (
481
491
  if (relAttribute.value !== "stylesheet") {
482
492
  return null
483
493
  }
484
-
494
+ const integrityAttribute = getHtmlNodeAttributeByName(link, "integrity")
495
+ const integrity = integrityAttribute ? integrityAttribute.value : ""
485
496
  const cssReference = notifyReferenceFound({
486
497
  referenceLabel: "html stylesheet link",
487
498
  contentTypeExpected: "text/css",
488
499
  ressourceSpecifier: hrefAttribute.value,
500
+ integrity,
501
+ ...crossoriginFromHtmlNode(link),
489
502
  ...referenceLocationFromHtmlNode(link, "href"),
490
503
  })
491
- return async ({
492
- getUrlRelativeToImporter,
493
- precomputeBuildRelativeUrl,
494
- buildDirectoryUrl,
495
- }) => {
504
+ return async ({ getUrlRelativeToImporter, buildDirectoryUrl }) => {
496
505
  const { ressource } = cssReference
497
-
498
506
  if (ressource.isExternal) {
499
507
  return
500
508
  }
501
-
502
509
  if (shouldInline({ ressource, htmlNode: link })) {
503
510
  const { bufferAfterBuild } = ressource
504
511
  let code = String(bufferAfterBuild)
505
512
  const { buildRelativeUrl } = ressource
506
513
  const cssBuildUrl = resolveUrl(buildRelativeUrl, buildDirectoryUrl)
507
- const htmlUrl = resolveUrl(
508
- precomputeBuildRelativeUrl(htmlRessource),
514
+ const htmlBuildUrl = resolveUrl(
515
+ htmlRessource.buildRelativeUrlWithoutHash,
509
516
  buildDirectoryUrl,
510
517
  )
511
-
512
518
  const moveResult = await moveCssUrls({
513
519
  code,
514
520
  from: cssBuildUrl,
515
- to: htmlUrl,
521
+ to: htmlBuildUrl,
516
522
  // moveCssUrls will change the css source code
517
523
  // Ideally we should update the sourcemap referenced by css
518
524
  // to target the one after css urls are moved.
@@ -523,24 +529,38 @@ const linkStylesheetHrefVisitor = (
523
529
  sourcemapMethod: null,
524
530
  })
525
531
  code = moveResult.code
526
-
527
532
  const sourcemapRelativeUrl = getCssSourceMappingUrl(code)
528
533
  if (sourcemapRelativeUrl) {
529
534
  const cssBuildUrl = resolveUrl(buildRelativeUrl, buildDirectoryUrl)
530
535
  const sourcemapBuildUrl = resolveUrl(sourcemapRelativeUrl, cssBuildUrl)
531
- const sourcemapInlineUrl = urlToRelativeUrl(sourcemapBuildUrl, htmlUrl)
536
+ const sourcemapInlineUrl = urlToRelativeUrl(
537
+ sourcemapBuildUrl,
538
+ htmlBuildUrl,
539
+ )
532
540
  code = setCssSourceMappingUrl(code, sourcemapInlineUrl)
533
541
  }
534
-
535
542
  replaceHtmlNode(link, `<style>${code}</style>`, {
536
- attributesToIgnore: ["href", "rel", "as", "crossorigin", "type"],
543
+ attributesToIgnore: [
544
+ "href",
545
+ "rel",
546
+ "as",
547
+ "crossorigin",
548
+ "type",
549
+ "integrity",
550
+ ],
537
551
  })
538
552
  cssReference.inlinedCallback()
539
553
  return
540
554
  }
541
-
542
555
  const urlRelativeToImporter = getUrlRelativeToImporter(ressource)
543
556
  hrefAttribute.value = urlRelativeToImporter
557
+ if (integrityAttribute) {
558
+ const base64Value = applyAlgoToRepresentationData(
559
+ "sha256",
560
+ ressource.bufferAfterBuild,
561
+ )
562
+ integrityAttribute.value = `sha256-${base64Value}`
563
+ }
544
564
  }
545
565
  }
546
566
 
@@ -552,7 +572,6 @@ const linkHrefVisitor = (
552
572
  if (!hrefAttribute) {
553
573
  return null
554
574
  }
555
-
556
575
  const href = hrefAttribute.value
557
576
  const relAttribute = getHtmlNodeAttributeByName(link, "rel")
558
577
  const rel = relAttribute ? relAttribute.value : undefined
@@ -563,7 +582,6 @@ const linkHrefVisitor = (
563
582
  "preload",
564
583
  "modulepreload",
565
584
  ].includes(rel)
566
-
567
585
  let contentTypeExpected
568
586
  const typeAttribute = getHtmlNodeAttributeByName(link, "type")
569
587
  const type = typeAttribute ? typeAttribute.value : ""
@@ -576,19 +594,21 @@ const linkHrefVisitor = (
576
594
  contentTypeExpected = "application/javascript"
577
595
  isJsModule = true
578
596
  }
579
-
597
+ const integrityAttribute = getHtmlNodeAttributeByName(link, "integrity")
598
+ const integrity = integrityAttribute ? integrityAttribute.value : ""
580
599
  const linkReference = notifyReferenceFound({
581
600
  referenceLabel: rel ? `html ${rel} link href` : `html link href`,
582
601
  isRessourceHint,
583
602
  contentTypeExpected,
584
603
  ressourceSpecifier: href,
604
+ integrity,
605
+ ...crossoriginFromHtmlNode(link),
585
606
  ...referenceLocationFromHtmlNode(link, "href"),
586
607
  urlVersioningDisabled: contentTypeExpected === "application/manifest+json",
587
608
  isJsModule,
588
609
  })
589
610
  return ({ getUrlRelativeToImporter }) => {
590
611
  const { ressource } = linkReference
591
-
592
612
  if (isRessourceHint) {
593
613
  if (isReferencedOnlyByRessourceHint(ressource)) {
594
614
  ressourceHintNeverUsedCallback({
@@ -600,36 +620,34 @@ const linkHrefVisitor = (
600
620
  // we could remove the HTML node but better keep it untouched and let user decide what to do
601
621
  return
602
622
  }
603
-
604
623
  ressource.inlinedCallbacks.push(() => {
605
624
  removeHtmlNode(link)
606
625
  })
607
626
  }
608
-
609
627
  if (ressource.isExternal) {
610
628
  return
611
629
  }
612
-
613
630
  if (format === "systemjs" && rel === "modulepreload") {
614
631
  const urlRelativeToImporter = getUrlRelativeToImporter(ressource)
615
- replaceHtmlNode(
616
- link,
617
- `<link rel="preload" href="${urlRelativeToImporter}" as="script" />`,
618
- )
632
+ relAttribute.value = "preload"
633
+ hrefAttribute.value = urlRelativeToImporter
634
+ addHtmlNodeAttribute(link, { name: "as", value: "script" })
619
635
  return
620
636
  }
621
-
622
637
  if (shouldInline({ ressource, htmlNode: link })) {
623
- replaceHtmlNode(
624
- link,
625
- `<link href="${getRessourceAsBase64Url(ressource)}" />`,
626
- )
638
+ removeHtmlNode(link)
627
639
  linkReference.inlinedCallback()
628
640
  return
629
641
  }
630
-
631
642
  const urlRelativeToImporter = getUrlRelativeToImporter(ressource)
632
643
  hrefAttribute.value = urlRelativeToImporter
644
+ if (integrityAttribute) {
645
+ const base64Value = applyAlgoToRepresentationData(
646
+ "sha256",
647
+ ressource.bufferAfterBuild,
648
+ )
649
+ integrityAttribute.value = `sha256-${base64Value}`
650
+ }
633
651
  }
634
652
  }
635
653
 
@@ -643,7 +661,6 @@ const styleTextNodeVisitor = (
643
661
  if (!textNode) {
644
662
  return null
645
663
  }
646
-
647
664
  const styleId = getIdForInlineHtmlNode(style, styles)
648
665
  const inlineStyleReference = notifyReferenceFound({
649
666
  referenceLabel: "html style",
@@ -667,10 +684,10 @@ const imgSrcVisitor = (img, { notifyReferenceFound }) => {
667
684
  if (!srcAttribute) {
668
685
  return null
669
686
  }
670
-
671
687
  const srcReference = notifyReferenceFound({
672
688
  referenceLabel: "html img src",
673
689
  ressourceSpecifier: srcAttribute.value,
690
+ ...crossoriginFromHtmlNode(img),
674
691
  ...referenceLocationFromHtmlNode(img, "src"),
675
692
  })
676
693
  return ({ getUrlRelativeToImporter }) => {
@@ -688,19 +705,18 @@ const srcsetVisitor = (htmlNode, { notifyReferenceFound }) => {
688
705
  if (!srcsetAttribute) {
689
706
  return null
690
707
  }
691
-
692
708
  const srcsetParts = parseSrcset(srcsetAttribute.value)
693
709
  const srcsetPartsReferences = srcsetParts.map(({ specifier }, index) =>
694
710
  notifyReferenceFound({
695
711
  referenceLabel: `html srcset ${index}`,
696
712
  ressourceSpecifier: specifier,
713
+ ...crossoriginFromHtmlNode(htmlNode),
697
714
  ...referenceLocationFromHtmlNode(htmlNode, "srcset"),
698
715
  }),
699
716
  )
700
717
  if (srcsetParts.length === 0) {
701
718
  return null
702
719
  }
703
-
704
720
  return ({ getUrlRelativeToImporter }) => {
705
721
  srcsetParts.forEach((srcsetPart, index) => {
706
722
  const reference = srcsetPartsReferences[index]
@@ -721,12 +737,12 @@ const sourceSrcVisitor = (source, { notifyReferenceFound }) => {
721
737
  if (!srcAttribute) {
722
738
  return null
723
739
  }
724
-
725
740
  const typeAttribute = getHtmlNodeAttributeByName(source, "type")
726
741
  const srcReference = notifyReferenceFound({
727
742
  referenceLabel: "html source",
728
743
  contentTypeExpected: typeAttribute ? typeAttribute.value : undefined,
729
744
  ressourceSpecifier: srcAttribute.value,
745
+ ...crossoriginFromHtmlNode(source),
730
746
  ...referenceLocationFromHtmlNode(source, "src"),
731
747
  })
732
748
  return ({ getUrlRelativeToImporter }) => {
@@ -751,6 +767,15 @@ const referenceToUrl = ({ reference, htmlNode, getUrlRelativeToImporter }) => {
751
767
  return getUrlRelativeToImporter(ressource)
752
768
  }
753
769
 
770
+ const crossoriginFromHtmlNode = (htmlNode) => {
771
+ const crossOriginAttribute = getHtmlNodeAttributeByName(
772
+ htmlNode,
773
+ "crossorigin",
774
+ )
775
+ const crossorigin = crossOriginAttribute ? crossOriginAttribute.value : ""
776
+ return { crossorigin }
777
+ }
778
+
754
779
  const referenceLocationFromHtmlNode = (htmlNode, htmlAttributeName) => {
755
780
  const locInfo = getHtmlNodeLocation(htmlNode, htmlAttributeName)
756
781
  return locInfo
@@ -1,6 +1,7 @@
1
1
  import { urlToFilename, resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem"
2
2
 
3
3
  import {
4
+ generateSourcemapUrl,
4
5
  getJavaScriptSourceMappingUrl,
5
6
  setJavaScriptSourceMappingUrl,
6
7
  } from "@jsenv/core/src/internal/sourceMappingURLUtils.js"
@@ -32,7 +33,7 @@ export const parseJsRessource = async (
32
33
  sourcemapReference = notifyReferenceFound({
33
34
  referenceLabel: "js sourcemapping comment",
34
35
  contentType: "application/octet-stream",
35
- ressourceSpecifier: `${urlToFilename(jsUrl)}.map`,
36
+ ressourceSpecifier: urlToRelativeUrl(generateSourcemapUrl(jsUrl), jsUrl),
36
37
  isPlaceholder: true,
37
38
  isSourcemap: true,
38
39
  })
@@ -40,7 +41,6 @@ export const parseJsRessource = async (
40
41
 
41
42
  return async ({ buildDirectoryUrl }) => {
42
43
  const sourcemapRessource = sourcemapReference.ressource
43
-
44
44
  let code
45
45
  let map
46
46
  if (!sourcemapRessource.isPlaceholder) {
@@ -92,15 +92,12 @@ export const parseJsRessource = async (
92
92
  jsRessource.buildRelativeUrl,
93
93
  buildDirectoryUrl,
94
94
  )
95
- const sourcemapPrecomputedBuildUrl = resolveUrl(
96
- `${urlToFilename(jsBuildUrl)}.map`,
97
- jsBuildUrl,
98
- )
95
+ const sourcemapPrecomputedBuildUrl = generateSourcemapUrl(jsBuildUrl)
99
96
  map.file = urlToFilename(jsBuildUrl)
100
97
  if (map.sources) {
101
98
  map.sources = map.sources.map((source) => {
102
99
  const sourceUrl = resolveUrl(source, jsUrl)
103
- const sourceOriginalUrl = asOriginalUrl(sourceUrl)
100
+ const sourceOriginalUrl = asOriginalUrl(sourceUrl) || sourceUrl
104
101
  const sourceUrlRelativeToSourceMap = urlToRelativeUrl(
105
102
  sourceOriginalUrl,
106
103
  sourcemapPrecomputedBuildUrl,
@@ -27,6 +27,7 @@ export const parseRessource = async (
27
27
  notifiers,
28
28
  {
29
29
  projectDirectoryUrl,
30
+ jsenvRemoteDirectory,
30
31
  format,
31
32
  systemJsUrl,
32
33
  asProjectUrl,
@@ -125,6 +126,7 @@ export const parseRessource = async (
125
126
 
126
127
  if (contentType === "text/css") {
127
128
  return parseCssRessource(ressource, notifiers, {
129
+ jsenvRemoteDirectory,
128
130
  asProjectUrl,
129
131
  asOriginalUrl,
130
132
  asOriginalServerUrl,
@@ -156,6 +158,7 @@ export const parseRessource = async (
156
158
  ) {
157
159
  return parseJsRessource(ressource, notifiers, {
158
160
  projectDirectoryUrl,
161
+ jsenvRemoteDirectory,
159
162
  asProjectUrl,
160
163
  asOriginalUrl,
161
164
  asOriginalServerUrl,