@jsenv/core 24.6.5 → 25.0.0-alpha.3

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 (83) hide show
  1. package/dist/browser_runtime/asset-manifest.json +2 -1
  2. package/dist/browser_runtime/{browser_runtime-bb0e3aa4.js → browser_runtime_91c5a3b8.js} +137 -26
  3. package/dist/browser_runtime/browser_runtime_91c5a3b8.js.map +1089 -0
  4. package/dist/build_manifest.js +6 -6
  5. package/dist/compile_proxy/asset-manifest.json +2 -1
  6. package/dist/compile_proxy/{compile_proxy-6eb67db4.html → compile_proxy_7ad5faa6.html} +119 -26
  7. package/dist/compile_proxy/{compile_proxy.html__inline__20-9e168143.js.map → compile_proxy_e3b0c442_809f35f7.js.map} +6 -6
  8. package/dist/event_source_client/asset-manifest.json +2 -1
  9. package/dist/event_source_client/{event_source_client-9f14c8b9.js → event_source_client_80644aee.js} +2 -2
  10. package/dist/event_source_client/{event_source_client-9f14c8b9.js.map → event_source_client_80644aee.js.map} +4 -3
  11. package/dist/redirector/asset-manifest.json +2 -1
  12. package/dist/redirector/{redirector.html__inline__15-3a34a156.js.map → redirector_e3b0c442_e391410e.js.map} +6 -6
  13. package/dist/redirector/{redirector-b6ad84bf.html → redirector_eb92e8a7.html} +119 -26
  14. package/dist/toolbar/asset-manifest.json +11 -10
  15. package/dist/toolbar/assets/{compilation.css-209d68b4.map → compilation.css_e37c747b.map} +1 -1
  16. package/dist/toolbar/assets/{eventsource.css-38cd0a36.map → eventsource.css_c0c71e7b.map} +1 -1
  17. package/dist/toolbar/assets/{execution.css-0ebe522f.map → execution.css_f3377c10.map} +1 -1
  18. package/dist/toolbar/assets/{focus.css-3f9c156d.map → focus.css_896f3e45.map} +1 -1
  19. package/dist/toolbar/assets/{light-theme.css-78b19a80.map → light-theme.css_72a60fa3.map} +1 -1
  20. package/dist/toolbar/assets/{overflow-menu.css-d9688a1c.map → overflow-menu.css_2859d519.map} +1 -1
  21. package/dist/toolbar/assets/{settings.css-2b81b245.map → settings.css_61548139.map} +1 -1
  22. package/dist/toolbar/assets/{toolbar.main.css-846920e9.map → toolbar.main.css_269d7ce2.map} +9 -9
  23. package/dist/toolbar/assets/{tooltip.css-03395ee6.map → tooltip.css_a94a8bdd.map} +1 -1
  24. package/dist/toolbar/{toolbar.main-a5ef2c60.js.map → toolbar.main2_6c1b3d82.js.map} +8 -8
  25. package/dist/toolbar/{toolbar-1fbf8dcb.html → toolbar_04ba410c.html} +129 -36
  26. package/dist/toolbar_injector/asset-manifest.json +3 -2
  27. package/dist/toolbar_injector/assets/{jsenv-logo-188b9ca6.svg → jsenv-logo_188b9ca6.svg} +0 -0
  28. package/dist/toolbar_injector/{toolbar_injector-997dbaa0.js → toolbar_injector_4a48bc53.js} +3 -3
  29. package/dist/toolbar_injector/{toolbar_injector-997dbaa0.js.map → toolbar_injector_4a48bc53.js.map} +2 -2
  30. package/package.json +5 -4
  31. package/readme.md +24 -91
  32. package/src/buildProject.js +51 -27
  33. package/src/dev_server.js +8 -2
  34. package/src/execute.js +7 -1
  35. package/src/executeTestPlan.js +17 -0
  36. package/src/internal/browser_feature_detection/browser_feature_detection.js +18 -25
  37. package/src/internal/browser_runtime/browser_runtime.js +2 -2
  38. package/src/internal/browser_runtime/createBrowserRuntime.js +1 -1
  39. package/src/internal/browser_runtime/displayErrorInDocument.js +2 -0
  40. package/src/internal/browser_runtime/displayErrorNotification.js +1 -1
  41. package/src/internal/building/buildUsingRollup.js +12 -15
  42. package/src/internal/building/build_logs.js +2 -2
  43. package/src/internal/building/build_stats.js +11 -1
  44. package/src/internal/building/html/parseHtmlRessource.js +2 -26
  45. package/src/internal/building/js/parseJsRessource.js +3 -2
  46. package/src/internal/building/json_module.js +11 -0
  47. package/src/internal/building/parseRessource.js +1 -1
  48. package/src/internal/building/ressource_builder.js +210 -216
  49. package/src/internal/building/rollup_plugin_jsenv.js +554 -378
  50. package/src/internal/building/url_loader.js +8 -145
  51. package/src/internal/building/url_versioning.js +220 -0
  52. package/src/internal/compiling/compileHtml.js +8 -1
  53. package/src/internal/compiling/createCompiledFileService.js +28 -40
  54. package/src/internal/compiling/html_source_file_service.js +66 -51
  55. package/src/internal/compiling/js-compilation-service/babel_plugin_systemjs_prepend.js +23 -0
  56. package/src/internal/compiling/js-compilation-service/jsenvTransform.js +16 -12
  57. package/src/internal/compiling/js-compilation-service/transformJs.js +2 -0
  58. package/src/internal/compiling/jsenvCompilerForHtml.js +43 -44
  59. package/src/internal/compiling/jsenvCompilerForImportmap.js +15 -76
  60. package/src/internal/compiling/jsenvCompilerForJavaScript.js +9 -0
  61. package/src/internal/compiling/startCompileServer.js +29 -5
  62. package/src/internal/dev_server/event_source_client/livereload_preference.js +1 -1
  63. package/src/internal/dev_server/toolbar/compilation/toolbar.compilation.js +9 -9
  64. package/src/internal/executing/executePlan.js +6 -0
  65. package/src/internal/generateGroupMap/{jsenvBabelPluginCompatMap.js → babel_plugins_compatibility.js} +0 -0
  66. package/src/internal/generateGroupMap/{featuresCompatMap.js → features_compatibility.js} +9 -1
  67. package/src/internal/generateGroupMap/generateGroupMap.js +6 -35
  68. package/src/internal/generateGroupMap/one_runtime_compat.js +9 -12
  69. package/src/internal/generateGroupMap/runtime_compat.js +10 -15
  70. package/src/internal/generateGroupMap/runtime_compat_composition.js +2 -2
  71. package/src/internal/generateGroupMap/shake_babel_plugin_map.js +21 -0
  72. package/src/internal/import-resolution/importmap_default.js +52 -0
  73. package/src/internal/node_feature_detection/node_feature_detection.js +25 -19
  74. package/src/internal/runtime/s.js +101 -6
  75. package/src/internal/unevalException.js +1 -1
  76. package/src/jsenvServiceWorkerFinalizer.js +12 -17
  77. package/dist/browser_runtime/browser_runtime-bb0e3aa4.js.map +0 -1067
  78. package/src/internal/building/asset_url_versioning.js +0 -50
  79. package/src/internal/building/rollup_build_sourcemap.js +0 -54
  80. package/src/internal/building/url-versioning.js +0 -96
  81. package/src/internal/generateGroupMap/jsenvPluginCompatMap.js +0 -1
  82. package/src/internal/import-resolution/importmap-default.js +0 -34
  83. package/src/internal/renderNamePattern.js +0 -6
@@ -1,39 +1,34 @@
1
+ import { featuresCompatMap } from "./features_compatibility.js"
1
2
  import { createOneRuntimeCompat } from "./one_runtime_compat.js"
2
3
 
3
- export const createRuntimeCompat = ({
4
- runtimeSupport,
5
- pluginMap,
6
- pluginCompatMap,
7
- }) => {
4
+ export const createRuntimeCompat = ({ runtimeSupport, featureNames }) => {
8
5
  const minRuntimeVersions = {}
9
- const pluginRequiredNameArray = []
6
+ const missingFeatureNames = []
10
7
  const runtimeNames = Object.keys(runtimeSupport)
11
8
  if (runtimeNames.length === 0) {
12
9
  // when runtimes are unknown, everything is required
13
- Object.keys(pluginMap).forEach((pluginName) => {
14
- pluginRequiredNameArray.push(pluginName)
15
- })
10
+ missingFeatureNames.push(...featureNames)
16
11
  } else {
17
12
  runtimeNames.forEach((runtimeName) => {
18
13
  const runtimeVersion = runtimeSupport[runtimeName]
19
14
  const oneRuntimeCompat = createOneRuntimeCompat({
20
15
  runtimeName,
21
16
  runtimeVersion,
22
- pluginMap,
23
- pluginCompatMap,
17
+ featureNames,
18
+ featuresCompatMap,
24
19
  })
25
20
 
26
21
  minRuntimeVersions[runtimeName] = oneRuntimeCompat.minRuntimeVersion
27
- oneRuntimeCompat.pluginRequiredNameArray.forEach((babelPluginName) => {
28
- if (!pluginRequiredNameArray.includes(babelPluginName)) {
29
- pluginRequiredNameArray.push(babelPluginName)
22
+ oneRuntimeCompat.missingFeatureNames.forEach((missingFeatureName) => {
23
+ if (!missingFeatureNames.includes(missingFeatureName)) {
24
+ missingFeatureNames.push(missingFeatureName)
30
25
  }
31
26
  })
32
27
  })
33
28
  }
34
29
 
35
30
  return {
36
- pluginRequiredNameArray,
31
+ missingFeatureNames,
37
32
  minRuntimeVersions,
38
33
  }
39
34
  }
@@ -31,7 +31,7 @@ const sortObjectKeys = (object) => {
31
31
 
32
32
  // export const composeRuntimeCompat = (...runtimeCompats) => {
33
33
  // return runtimeCompats.reduce(runtimeCompatComposer, {
34
- // pluginRequiredNameArray: [],
34
+ // missingFeatureNames: [],
35
35
  // runtimeCompatMap: {},
36
36
  // })
37
37
  // }
@@ -60,7 +60,7 @@ const sortObjectKeys = (object) => {
60
60
  // }
61
61
 
62
62
  // const runtimeCompatComposer = compositionMappingToStrictReducer({
63
- // pluginRequiredNameArray: (
63
+ // missingFeatureNames: (
64
64
  // babelPluginNamesPrevious,
65
65
  // babelPluginNamesCurrent,
66
66
  // ) => {
@@ -0,0 +1,21 @@
1
+ export const shakeBabelPluginMap = ({
2
+ babelPluginMap,
3
+ missingFeatureNames,
4
+ }) => {
5
+ const babelPluginMapForGroup = {}
6
+ missingFeatureNames.forEach((featureName) => {
7
+ const babelPlugin = babelPluginMap[featureName]
8
+ if (babelPlugin) {
9
+ babelPluginMapForGroup[featureName] = babelPlugin
10
+ }
11
+ })
12
+ Object.keys(babelPluginMap).forEach((key) => {
13
+ if (key.startsWith("syntax-")) {
14
+ babelPluginMapForGroup[key] = babelPluginMap[key]
15
+ }
16
+ if (key === "transform-replace-expressions") {
17
+ babelPluginMapForGroup[key] = babelPluginMap[key]
18
+ }
19
+ })
20
+ return babelPluginMapForGroup
21
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * allows the following:
3
+ *
4
+ * import "@jsenv/core/helpers/regenerator-runtime/regenerator-runtime.js"
5
+ * -> searches a file inside @jsenv/core/*
6
+ *
7
+ */
8
+
9
+ import { urlToRelativeUrl, urlIsInsideOf, resolveUrl } from "@jsenv/filesystem"
10
+
11
+ import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js"
12
+
13
+ export const getDefaultImportmap = (
14
+ url,
15
+ { projectDirectoryUrl, compileDirectoryUrl },
16
+ ) => {
17
+ const jsenvCoreDirectoryRelativeUrl = urlToRelativeUrl(
18
+ jsenvCoreDirectoryUrl,
19
+ projectDirectoryUrl,
20
+ )
21
+
22
+ let jsenvCoreUrl
23
+ if (compileDirectoryUrl && urlIsInsideOf(url, compileDirectoryUrl)) {
24
+ jsenvCoreUrl = resolveUrl(
25
+ jsenvCoreDirectoryRelativeUrl,
26
+ compileDirectoryUrl,
27
+ )
28
+ } else {
29
+ jsenvCoreUrl = jsenvCoreDirectoryUrl
30
+ }
31
+
32
+ const importmap = {
33
+ imports: {
34
+ "@jsenv/core/": makeRelativeMapping(jsenvCoreUrl, url),
35
+ },
36
+ }
37
+ return importmap
38
+ }
39
+
40
+ // this function just here to ensure relative urls starts with './'
41
+ // so that importmap do not consider them as bare specifiers
42
+ const makeRelativeMapping = (url, baseUrl) => {
43
+ const relativeUrl = urlToRelativeUrl(url, baseUrl)
44
+
45
+ if (urlIsInsideOf(url, baseUrl)) {
46
+ if (relativeUrl.startsWith("../")) return relativeUrl
47
+ if (relativeUrl.startsWith("./")) return relativeUrl
48
+ return `./${relativeUrl}`
49
+ }
50
+
51
+ return relativeUrl
52
+ }
@@ -34,7 +34,7 @@ export const scanNodeRuntimeFeatures = async ({
34
34
  featuresReport,
35
35
  failFastOnFeatureDetection: true,
36
36
  })
37
- const pluginRequiredNameArray = pluginRequiredNamesFromGroupInfo(groupInfo, {
37
+ const missingFeatureNames = adjustMissingFeatureNames(groupInfo, {
38
38
  featuresReport,
39
39
  coverageHandledFromOutside,
40
40
  })
@@ -43,14 +43,14 @@ export const scanNodeRuntimeFeatures = async ({
43
43
  // node native resolution will not auto add extension
44
44
  !importDefaultExtension &&
45
45
  customCompilerPatterns.length === 0 &&
46
- pluginRequiredNameArray.length === 0 &&
46
+ missingFeatureNames.length === 0 &&
47
47
  featuresReport.dynamicImport &&
48
48
  featuresReport.topLevelAwait
49
49
 
50
50
  return {
51
51
  canAvoidCompilation,
52
52
  featuresReport,
53
- pluginRequiredNameArray,
53
+ missingFeatureNames,
54
54
  compileId,
55
55
  importDefaultExtension,
56
56
  node,
@@ -84,28 +84,34 @@ const importJson = async (url) => {
84
84
  return object
85
85
  }
86
86
 
87
- const pluginRequiredNamesFromGroupInfo = (
87
+ const adjustMissingFeatureNames = (
88
88
  groupInfo,
89
89
  { coverageHandledFromOutside },
90
90
  ) => {
91
- const { pluginRequiredNameArray } = groupInfo
92
- const requiredPluginNames = pluginRequiredNameArray.slice()
93
- const markPluginAsSupported = (name) => {
94
- const index = requiredPluginNames.indexOf(name)
91
+ const { missingFeatureNames } = groupInfo
92
+ const missingFeatureNamesCopy = missingFeatureNames.slice()
93
+ const markAsSupported = (name) => {
94
+ const index = missingFeatureNamesCopy.indexOf(name)
95
95
  if (index > -1) {
96
- requiredPluginNames.splice(index, 1)
96
+ missingFeatureNamesCopy.splice(index, 1)
97
97
  }
98
98
  }
99
-
100
99
  if (coverageHandledFromOutside) {
101
- markPluginAsSupported("transform-instrument")
100
+ markAsSupported("transform-instrument")
102
101
  }
103
- // CSS import assertions and constructable stylesheet are not supported by Node.js
104
- // but we assume they are not used for code executed in Node.js
105
- // Without this check code executed on Node.js would always be compiled
106
- // because import assertions and constructable stylesheet are enabled by default
107
- markPluginAsSupported("transform-import-assertions")
108
- markPluginAsSupported("new-stylesheet-as-jsenv-import")
109
-
110
- return requiredPluginNames
102
+ // Jsenv enable some features because they are standard and we can expect code to use them.
103
+ // At the time of writing this, these features are not available in latest Node.js.
104
+ // Some feature are also browser specific.
105
+ // To avoid compiling code for Node.js these feaure are marked as supported.
106
+ // It means code written to be execute in Node.js should not use these features
107
+ // because jsenv ignore them (it won't try to "polyfill" them)
108
+ markAsSupported("module")
109
+ markAsSupported("importmap")
110
+ markAsSupported("transform-import-assertions")
111
+ markAsSupported("import_assertion_type_json")
112
+ markAsSupported("import_assertion_type_css")
113
+ markAsSupported("new-stylesheet-as-jsenv-import")
114
+ markAsSupported("worker_type_module")
115
+ markAsSupported("worker_importmap")
116
+ return missingFeatureNamesCopy
111
117
  }
@@ -497,6 +497,8 @@
497
497
 
498
498
  var importMapPromise = Promise.resolve();
499
499
  var importMap = { imports: {}, scopes: {}, depcache: {}, integrity: {} };
500
+ systemJSPrototype.importMap = importMap;
501
+ systemJSPrototype.baseUrl = baseUrl;
500
502
 
501
503
  // Scripts are processed immediately, on the first System.import, and on DOMReady.
502
504
  // Import map scripts are processed only once (by being marked) and in order for each phase.
@@ -552,6 +554,7 @@
552
554
  return fetchPromise;
553
555
  }).then(function (text) {
554
556
  extendImportMap(importMap, text, script.src || baseUrl);
557
+ return importMap
555
558
  });
556
559
  }
557
560
  });
@@ -566,6 +569,7 @@
566
569
  }
567
570
  resolveAndComposeImportMap(newMap, newMapUrl, importMap);
568
571
  }
572
+ System.extendImportMap = extendImportMap
569
573
 
570
574
  /*
571
575
  * Script instantiation loading
@@ -719,23 +723,33 @@
719
723
  * Supports loading System.register in workers
720
724
  */
721
725
 
722
- if (hasSelf && typeof importScripts === 'function')
726
+ if (hasSelf && typeof importScripts === 'function') {
723
727
  systemJSPrototype.instantiate = function (url) {
724
728
  var loader = this;
725
- return Promise.resolve().then(function () {
726
- importScripts(url);
729
+ return self.fetch(url, {
730
+ credentials: 'same-origin',
731
+ }).then(function (response) {
732
+ if (!response.ok) {
733
+ throw Error(errMsg(7, [response.status, response.statusText, url].join(', ') ));
734
+ }
735
+ return response.text()
736
+ }).then(function (source) {
737
+ if (source.indexOf('//# sourceURL=') < 0) source += '\n//# sourceURL=' + url;
738
+ (0, eval)(source);
727
739
  return loader.getRegister(url);
728
- });
740
+ })
729
741
  };
742
+ }
730
743
 
731
744
  }());
732
745
 
733
746
  (function(){
734
747
  var envGlobal = typeof self !== 'undefined' ? self : global;
735
748
  var System = envGlobal.System;
736
- var register = System.register;
737
- var registerRegistry = Object.create(null)
738
749
 
750
+ var registerRegistry = Object.create(null)
751
+ var register = System.register;
752
+ System.registerRegistry = registerRegistry;
739
753
  System.register = function (name, deps, declare) {
740
754
  if (typeof name !== 'string') return register.apply(this, arguments);
741
755
  var define = [deps, declare];
@@ -765,4 +779,85 @@
765
779
  var result = registerRegistry[url] || register;
766
780
  return result;
767
781
  };
782
+ }());
783
+
784
+ (function () {
785
+ // worker or service worker
786
+ if (typeof WorkerGlobalScope === 'function' && self instanceof WorkerGlobalScope) {
787
+ var importMapFromParentPromise = new Promise((resolve) => {
788
+ var importmapMessageCallback = function (e) {
789
+ if (e.data === "__importmap_init__") {
790
+ self.removeEventListener("message", importmapMessageCallback)
791
+ e.ports[0].onmessage = (message) => {
792
+ resolve(message.data)
793
+ }
794
+ e.ports[0].postMessage('__importmap_request__')
795
+ }
796
+ };
797
+ self.addEventListener("message", importmapMessageCallback)
798
+ })
799
+ // var prepareImport = System.prepareImport
800
+ System.prepareImport = function () {
801
+ return importMapFromParentPromise.then(function (importmap) {
802
+ System.extendImportMap(System.importMap, JSON.stringify(importmap), System.baseUrl)
803
+ })
804
+ }
805
+
806
+ // auto import first register
807
+ var messageEvents = []
808
+ var messageCallback = (event) => {
809
+ messageEvents.push(event)
810
+ }
811
+ self.addEventListener('message', messageCallback)
812
+ var register = System.register;
813
+ System.register = function(deps, declare) {
814
+ System.register = register;
815
+ System.registerRegistry[self.location.href] = [deps, declare];
816
+ System.import(self.location.href).then(() => {
817
+ self.removeEventListener('message', messageCallback)
818
+ messageEvents.forEach((messageEvent) => {
819
+ self.dispatchEvent(messageEvent)
820
+ })
821
+ messageEvents = null
822
+ })
823
+ }
824
+ }
825
+ else if (typeof window === 'object') {
826
+ var WorkerConstructor = window.Worker;
827
+ if (typeof WorkerConstructor === 'function') {
828
+ window.Worker = function (url, options) {
829
+ var worker = new WorkerConstructor(url, options);
830
+ var importmapChannel = new MessageChannel();
831
+ importmapChannel.port1.onmessage = function (message) {
832
+ System.prepareImport().then(function (importmap) {
833
+ message.target.postMessage(importmap);
834
+ });
835
+ }
836
+ worker.postMessage('__importmap_init__', [importmapChannel.port2]);
837
+ return worker
838
+ }
839
+ }
840
+
841
+ var serviceWorker = navigator.serviceWorker;
842
+ if (serviceWorker) {
843
+ var register = serviceWorker.register;
844
+ serviceWorker.register = function(url, options) {
845
+ var registrationPromise = register.call(this, url, options);
846
+ registrationPromise.then(function(registration) {
847
+ var installing = registration.installing;
848
+ var waiting = registration.waiting;
849
+ var active = registration.active;
850
+ var worker = installing || waiting || active;
851
+ var importmapChannel = new MessageChannel();
852
+ importmapChannel.port1.onmessage = function (message) {
853
+ System.prepareImport().then(function (importmap) {
854
+ message.target.postMessage(importmap)
855
+ });
856
+ }
857
+ worker.postMessage('__importmap_init__', [importmapChannel.port2]);
858
+ })
859
+ return registrationPromise
860
+ }
861
+ }
862
+ }
768
863
  }());
@@ -1,7 +1,7 @@
1
1
  import { uneval } from "@jsenv/uneval"
2
2
 
3
3
  export const unevalException = (value) => {
4
- if (value.hasOwnProperty("toString")) {
4
+ if (value && value.hasOwnProperty("toString")) {
5
5
  delete value.toString
6
6
  }
7
7
  return uneval(value, { ignoreSymbols: true })
@@ -1,23 +1,17 @@
1
1
  import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem"
2
2
 
3
- import { generateContentHash } from "./internal/building/url-versioning.js"
3
+ import { generateContentHash } from "./internal/building/url_versioning.js"
4
4
 
5
5
  export const jsenvServiceWorkerFinalizer = (
6
6
  code,
7
- {
8
- serviceWorkerBuildRelativeUrl,
9
- buildManifest,
10
- rollupBuild,
11
- lineBreakNormalization,
12
- },
7
+ { serviceWorkerBuildRelativeUrl, buildFileContents, lineBreakNormalization },
13
8
  ) => {
14
9
  const generatedUrlsConfig = {}
15
- Object.keys(buildManifest).forEach((projectRelativeUrl) => {
16
- if (projectRelativeUrl.endsWith(".map")) {
10
+ Object.keys(buildFileContents).forEach((buildRelativeUrl) => {
11
+ if (buildRelativeUrl.endsWith(".map")) {
17
12
  return
18
13
  }
19
14
 
20
- const buildRelativeUrl = buildManifest[projectRelativeUrl]
21
15
  const buildUrl = resolveUrl(buildRelativeUrl, "file://")
22
16
  const serviceWorkerBuildUrl = resolveUrl(
23
17
  serviceWorkerBuildRelativeUrl,
@@ -32,7 +26,7 @@ export const jsenvServiceWorkerFinalizer = (
32
26
  return
33
27
  }
34
28
  const versioned = fileNameContainsHash(buildRelativeUrl)
35
- const rollupFile = rollupBuild[buildRelativeUrl]
29
+ const buildFileContent = buildFileContents[buildRelativeUrl]
36
30
 
37
31
  generatedUrlsConfig[urlRelativeToServiceWorker] = {
38
32
  versioned,
@@ -42,19 +36,20 @@ export const jsenvServiceWorkerFinalizer = (
42
36
  // when url is not versioned we compute a "version" for that url anyway
43
37
  // so that service worker source still changes and navigator
44
38
  // detect there is a change
45
- version: generateContentHash(
46
- rollupFile.type === "chunk" ? rollupFile.code : rollupFile.source,
47
- { lineBreakNormalization },
48
- ),
39
+ version: generateContentHash(buildFileContent, {
40
+ lineBreakNormalization,
41
+ }),
49
42
  }),
50
43
  }
51
44
  })
45
+ // TODO: ideally should use magic string to prepend code
46
+ // but it means composing 2 source maps, something not already available in jsenv codebase
52
47
 
53
48
  return `
54
- self.generatedUrlsConfig = ${JSON.stringify(generatedUrlsConfig, null, " ")}
49
+ self.generatedUrlsConfig = ${JSON.stringify(generatedUrlsConfig, null, " ")};
55
50
  ${code}
56
51
  `
57
52
  }
58
53
 
59
54
  const fileNameContainsHash = (fileName) =>
60
- /-[a-z0-9]{8,}(\..*?)?$/.test(fileName)
55
+ /_[a-z0-9]{8,}(\..*?)?$/.test(fileName)