@jsenv/core 22.4.0 → 23.0.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 (106) hide show
  1. package/dist/jsenv_browser_system.js +331 -256
  2. package/dist/jsenv_browser_system.js.map +55 -33
  3. package/dist/jsenv_compile_proxy.js +186 -108
  4. package/dist/jsenv_compile_proxy.js.map +48 -42
  5. package/dist/jsenv_exploring_redirector.js +148 -71
  6. package/dist/jsenv_exploring_redirector.js.map +26 -20
  7. package/dist/jsenv_toolbar.js +215 -104
  8. package/dist/jsenv_toolbar.js.map +39 -26
  9. package/helpers/new_stylesheet/new_stylesheet.js +411 -0
  10. package/{LICENSE → license} +0 -0
  11. package/main.js +8 -7
  12. package/package.json +23 -19
  13. package/readme.md +9 -6
  14. package/src/buildProject.js +3 -7
  15. package/src/execute.js +23 -10
  16. package/src/executeTestPlan.js +0 -4
  17. package/src/importUsingChildProcess.js +36 -32
  18. package/src/internal/{babel-plugin-replace-expressions.js → babel_plugin_replace_expressions.js} +0 -0
  19. package/src/internal/{babel-plugin-transform-import-meta.js → babel_plugin_transform_import_meta.js} +0 -0
  20. package/src/internal/browser-launcher/executeHtmlFile.js +6 -8
  21. package/src/internal/browser-launcher/jsenv-browser-system.js +3 -0
  22. package/src/internal/building/asset_url_versioning.js +5 -9
  23. package/src/internal/building/buildServiceWorker.js +6 -13
  24. package/src/internal/building/buildUsingRollup.js +41 -4
  25. package/src/internal/building/build_logs.js +11 -0
  26. package/src/internal/building/build_stats.js +7 -1
  27. package/src/internal/building/createJsenvRollupPlugin.js +402 -297
  28. package/src/internal/building/css/parseCssRessource.js +67 -71
  29. package/src/internal/building/css/parseCssUrls.js +2 -2
  30. package/src/internal/building/css/{postcss-urlhash-plugin.js → postcss_plugin_url_visitor.js} +43 -21
  31. package/src/internal/building/css/replaceCssUrls.js +17 -14
  32. package/src/internal/building/css_module.js +47 -0
  33. package/src/internal/building/html/parseHtmlRessource.js +44 -43
  34. package/src/internal/building/import_references.js +81 -0
  35. package/src/internal/building/importmap/parseImportmapRessource.js +5 -2
  36. package/src/internal/building/js/minifyJs.js +30 -3
  37. package/src/internal/building/js/parseJsRessource.js +70 -77
  38. package/src/internal/building/json/parseJsonRessource.js +3 -2
  39. package/src/internal/building/parseRessource.js +11 -8
  40. package/src/internal/building/parsing.utils.js +4 -15
  41. package/src/internal/building/ressource_builder.js +142 -114
  42. package/src/internal/building/ressource_builder_util.js +31 -18
  43. package/src/internal/building/{fetchSourcemap.js → sourcemap_loader.js} +29 -27
  44. package/src/internal/building/svg/parseSvgRessource.js +7 -3
  45. package/src/internal/building/url-versioning.js +2 -1
  46. package/src/internal/building/url_fetcher.js +79 -0
  47. package/src/internal/building/url_loader.js +267 -0
  48. package/src/internal/building/url_trace.js +1 -1
  49. package/src/internal/building/webmanifest/parseWebmanifestRessource.js +9 -4
  50. package/src/internal/compiling/{js-compilation-service/ensureGlobalThisImportBabelPlugin.js → babel_plugin_global_this_as_jsenv_import.js} +4 -2
  51. package/src/internal/compiling/babel_plugin_import_assertions.js +100 -0
  52. package/src/internal/compiling/babel_plugin_new_stylesheet_as_jsenv_import.js +109 -0
  53. package/src/internal/compiling/babel_plugin_transform_import_specifier.js +86 -0
  54. package/src/internal/compiling/babel_plugins.js +2 -0
  55. package/src/internal/compiling/createCompiledFileService.js +46 -15
  56. package/src/internal/compiling/html_source_file_service.js +2 -2
  57. package/src/internal/compiling/js-compilation-service/{transformBabelHelperToImportBabelPlugin.js → babel_plugin_babel_helpers_as_jsenv_imports.js} +1 -1
  58. package/src/internal/compiling/js-compilation-service/{ensureRegeneratorRuntimeImportBabelPlugin.js → babel_plugin_regenerator_runtime_as_jsenv_import.js} +1 -1
  59. package/src/internal/compiling/js-compilation-service/jsenvTransform.js +7 -16
  60. package/src/internal/compiling/js-compilation-service/transformJs.js +0 -2
  61. package/src/internal/compiling/jsenvCompilerForHtml.js +2 -7
  62. package/src/internal/compiling/rollup_plugin_commonjs_named_exports.js +2 -2
  63. package/src/internal/compiling/startCompileServer.js +11 -4
  64. package/src/internal/escapeTemplateStringSpecialCharacters.js +20 -0
  65. package/src/internal/executing/coverage/{babel-plugin-instrument.js → babel_plugin_instrument.js} +17 -6
  66. package/src/internal/executing/coverage/relativeUrlToEmptyCoverage.js +1 -1
  67. package/src/internal/executing/executeConcurrently.js +5 -3
  68. package/src/internal/executing/executePlan.js +16 -2
  69. package/src/internal/executing/generateFileExecutionSteps.js +2 -1
  70. package/src/internal/executing/launchAndExecute.js +43 -69
  71. package/src/internal/executing/writeLog.js +25 -18
  72. package/src/internal/exploring/exploring.css +2 -1
  73. package/src/internal/exploring/exploring.redirector.js +0 -1
  74. package/src/internal/generateGroupMap/generateGroupMap.js +14 -10
  75. package/src/internal/generateGroupMap/jsenvBabelPluginCompatMap.js +30 -0
  76. package/src/internal/generateGroupMap/jsenvPluginCompatMap.js +0 -6
  77. package/src/internal/generateGroupMap/one_runtime_compat.js +9 -38
  78. package/src/internal/generateGroupMap/runtime_compat.js +9 -24
  79. package/src/internal/generateGroupMap/runtime_compat_composition.js +2 -12
  80. package/src/internal/generateGroupMap/runtime_support.js +53 -0
  81. package/src/internal/jsenvInternalFiles.js +0 -1
  82. package/src/internal/node-launcher/createControllableNodeProcess.js +2 -3
  83. package/src/internal/response_validation.js +143 -0
  84. package/src/internal/runtime/createBrowserRuntime/createBrowserRuntime.js +8 -3
  85. package/src/internal/runtime/createBrowserRuntime/createBrowserSystem.js +165 -25
  86. package/src/internal/runtime/createBrowserRuntime/displayErrorInDocument.js +7 -6
  87. package/src/internal/runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js +124 -68
  88. package/src/internal/runtime/createNodeRuntime/createNodeRuntime.js +8 -86
  89. package/src/internal/runtime/createNodeRuntime/createNodeSystem.js +53 -9
  90. package/src/internal/runtime/createNodeRuntime/scanNodeRuntimeFeatures.js +115 -0
  91. package/src/internal/runtime/module-registration.js +86 -136
  92. package/src/internal/runtime/resolveGroup.js +2 -3
  93. package/src/internal/toolbar/compilation/toolbar.compilation.js +15 -17
  94. package/src/internal/toolbar/eventsource/toolbar.eventsource.js +35 -8
  95. package/src/internal/toolbar/toolbar.main.js +7 -4
  96. package/src/internal/url_utils.js +33 -0
  97. package/src/internal/url_utils.test.js +39 -0
  98. package/src/jsonToJavaScriptModule.js +12 -0
  99. package/src/launchBrowser.js +50 -34
  100. package/src/launchNode.js +6 -3
  101. package/src/requireUsingChildProcess.js +36 -32
  102. package/src/startExploring.js +25 -11
  103. package/src/internal/building/transformImportMetaUrlReferences.js +0 -71
  104. package/src/internal/runtime/resolveBrowserGroup.js +0 -5
  105. package/src/internal/runtime/resolveNodeGroup.js +0 -5
  106. package/src/internal/validateResponseStatusIsOk.js +0 -91
@@ -1346,7 +1346,7 @@
1346
1346
  // fallback to this polyfill (or even use an existing polyfill would be better)
1347
1347
  // https://github.com/github/fetch/blob/master/fetch.js
1348
1348
 
1349
- function _await$b(value, then, direct) {
1349
+ function _await$c(value, then, direct) {
1350
1350
  if (direct) {
1351
1351
  return then ? then(value) : value;
1352
1352
  }
@@ -1358,7 +1358,7 @@
1358
1358
  return then ? value.then(then) : value;
1359
1359
  }
1360
1360
 
1361
- function _async$b(f) {
1361
+ function _async$c(f) {
1362
1362
  return function () {
1363
1363
  for (var args = [], i = 0; i < arguments.length; i++) {
1364
1364
  args[i] = arguments[i];
@@ -1385,7 +1385,7 @@
1385
1385
  }
1386
1386
  }
1387
1387
 
1388
- var fetchUsingXHR = _async$b(function (url) {
1388
+ var fetchUsingXHR = _async$c(function (url) {
1389
1389
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
1390
1390
  _ref$cancellationToke = _ref.cancellationToken,
1391
1391
  cancellationToken = _ref$cancellationToke === void 0 ? createCancellationToken() : _ref$cancellationToke,
@@ -1468,7 +1468,7 @@
1468
1468
  }
1469
1469
 
1470
1470
  xhr.send(body);
1471
- return _await$b(headersPromise, function () {
1471
+ return _await$c(headersPromise, function () {
1472
1472
  // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseURL
1473
1473
  var responseUrl = "responseURL" in xhr ? xhr.responseURL : headers["x-request-url"];
1474
1474
  var responseStatus = xhr.status;
@@ -1476,7 +1476,7 @@
1476
1476
  var responseHeaders = getHeadersFromXHR(xhr);
1477
1477
 
1478
1478
  var readBody = function readBody() {
1479
- return _await$b(bodyPromise, function () {
1479
+ return _await$c(bodyPromise, function () {
1480
1480
  var status = xhr.status; // in Chrome on file:/// URLs, status is 0
1481
1481
 
1482
1482
  if (status === 0) {
@@ -1512,7 +1512,7 @@
1512
1512
  return _call$1(text, JSON.parse);
1513
1513
  };
1514
1514
 
1515
- var blob = _async$b(function () {
1515
+ var blob = _async$c(function () {
1516
1516
  if (!hasBlob) {
1517
1517
  throw new Error("blob not supported");
1518
1518
  }
@@ -1549,7 +1549,7 @@
1549
1549
  });
1550
1550
  };
1551
1551
 
1552
- var formData = _async$b(function () {
1552
+ var formData = _async$c(function () {
1553
1553
  if (!hasFormData) {
1554
1554
  throw new Error("formData not supported");
1555
1555
  }
@@ -1730,7 +1730,7 @@
1730
1730
  return form;
1731
1731
  };
1732
1732
 
1733
- var blobToArrayBuffer = _async$b(function (blob) {
1733
+ var blobToArrayBuffer = _async$c(function (blob) {
1734
1734
  var reader = new FileReader();
1735
1735
  var promise = fileReaderReady(reader);
1736
1736
  reader.readAsArrayBuffer(blob);
@@ -1781,7 +1781,7 @@
1781
1781
 
1782
1782
  var _excluded = ["cancellationToken", "mode"];
1783
1783
 
1784
- function _await$a(value, then, direct) {
1784
+ function _await$b(value, then, direct) {
1785
1785
  if (direct) {
1786
1786
  return then ? then(value) : value;
1787
1787
  }
@@ -1793,7 +1793,7 @@
1793
1793
  return then ? value.then(then) : value;
1794
1794
  }
1795
1795
 
1796
- var fetchNative = _async$a(function (url) {
1796
+ var fetchNative = _async$b(function (url) {
1797
1797
 
1798
1798
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1799
1799
 
@@ -1811,7 +1811,7 @@
1811
1811
  });
1812
1812
  var response;
1813
1813
  return _continue$3(_catch$5(function () {
1814
- return _await$a(window.fetch(url, _objectSpread2({
1814
+ return _await$b(window.fetch(url, _objectSpread2({
1815
1815
  signal: abortController.signal,
1816
1816
  mode: mode
1817
1817
  }, options)), function (_window$fetch) {
@@ -1874,7 +1874,7 @@
1874
1874
  return value && value.then ? value.then(then) : then(value);
1875
1875
  }
1876
1876
 
1877
- function _async$a(f) {
1877
+ function _async$b(f) {
1878
1878
  return function () {
1879
1879
  for (var args = [], i = 0; i < arguments.length; i++) {
1880
1880
  args[i] = arguments[i];
@@ -2078,7 +2078,7 @@
2078
2078
  return url;
2079
2079
  };
2080
2080
 
2081
- function _await$9(value, then, direct) {
2081
+ function _await$a(value, then, direct) {
2082
2082
  if (direct) {
2083
2083
  return then ? then(value) : value;
2084
2084
  }
@@ -2090,21 +2090,7 @@
2090
2090
  return then ? value.then(then) : value;
2091
2091
  }
2092
2092
 
2093
- function _catch$4(body, recover) {
2094
- try {
2095
- var result = body();
2096
- } catch (e) {
2097
- return recover(e);
2098
- }
2099
-
2100
- if (result && result.then) {
2101
- return result.then(void 0, recover);
2102
- }
2103
-
2104
- return result;
2105
- }
2106
-
2107
- function _invoke$5(body, then) {
2093
+ function _invoke$6(body, then) {
2108
2094
  var result = body();
2109
2095
 
2110
2096
  if (result && result.then) {
@@ -2114,11 +2100,7 @@
2114
2100
  return then(result);
2115
2101
  }
2116
2102
 
2117
- function _continue$2(value, then) {
2118
- return value && value.then ? value.then(then) : then(value);
2119
- }
2120
-
2121
- function _async$9(f) {
2103
+ function _async$a(f) {
2122
2104
  return function () {
2123
2105
  for (var args = [], i = 0; i < arguments.length; i++) {
2124
2106
  args[i] = arguments[i];
@@ -2131,175 +2113,60 @@
2131
2113
  }
2132
2114
  };
2133
2115
  }
2134
-
2135
- var fromFunctionReturningNamespace = function fromFunctionReturningNamespace(fn, data) {
2136
- return fromFunctionReturningRegisteredModule(function () {
2137
- // should we compute the namespace here
2138
- // or as it is done below, defer to execute ?
2139
- // I think defer to execute is better
2140
- return [[], function (_export) {
2141
- return {
2142
- execute: function execute() {
2143
- var namespace = fn();
2144
-
2145
- _export(namespace);
2146
- }
2147
- };
2148
- }];
2149
- }, data);
2150
- };
2151
-
2152
- var fromFunctionReturningRegisteredModule = function fromFunctionReturningRegisteredModule(fn, data) {
2153
- try {
2154
- return fn();
2155
- } catch (error) {
2156
- if (error.name === "SyntaxError") {
2157
- throw new Error(createDetailedMessage("Syntax error in module.", _objectSpread2({
2158
- "syntax error stack": error.stack
2159
- }, getModuleDetails(data))));
2160
- }
2161
-
2162
- throw new Error(createDetailedMessage("Module instantiation error.", _objectSpread2(_defineProperty({}, "instantiation error stack", error.stack), getModuleDetails(data))));
2163
- }
2164
- };
2165
-
2166
- var fromUrl = _async$9(function (_ref) {
2116
+ var getJavaScriptModuleResponseError = _async$a(function (response, _ref) {
2117
+ var _exit = false;
2167
2118
  var url = _ref.url,
2168
2119
  importerUrl = _ref.importerUrl,
2169
- fetchSource = _ref.fetchSource,
2170
- instantiateJavaScript = _ref.instantiateJavaScript,
2171
2120
  compileServerOrigin = _ref.compileServerOrigin,
2172
- compileDirectoryRelativeUrl = _ref.compileDirectoryRelativeUrl;
2173
- var moduleResponse;
2174
- return _continue$2(_catch$4(function () {
2175
- return _await$9(fetchSource(url, {
2176
- importerUrl: importerUrl
2177
- }), function (_fetchSource) {
2178
- moduleResponse = _fetchSource;
2179
-
2180
- if (moduleResponse.status === 404) {
2181
- throw new Error(createDetailedMessage("Module file cannot be found.", getModuleDetails({
2182
- url: url,
2183
- importerUrl: importerUrl,
2184
- compileServerOrigin: compileServerOrigin,
2185
- compileDirectoryRelativeUrl: compileDirectoryRelativeUrl,
2186
- notFound: true
2187
- })));
2188
- }
2189
- });
2190
- }, function (e) {
2191
- e.code = "NETWORK_FAILURE";
2192
- throw e;
2193
- }), function (_result) {
2194
- var contentType = moduleResponse.headers["content-type"] || "";
2195
- return _invoke$5(function () {
2196
- if (moduleResponse.status === 500 && contentType === "application/json") {
2197
- return _await$9(moduleResponse.json(), function (bodyAsJson) {
2198
- if (bodyAsJson.message && bodyAsJson.filename && "columnNumber" in bodyAsJson) {
2199
- var error = new Error(createDetailedMessage("Module file cannot be parsed.", _objectSpread2(_defineProperty({}, "parsing error message", bodyAsJson.message), getModuleDetails({
2200
- url: url,
2201
- importerUrl: importerUrl,
2202
- compileServerOrigin: compileServerOrigin,
2203
- compileDirectoryRelativeUrl: compileDirectoryRelativeUrl
2204
- }))));
2205
- error.parsingError = bodyAsJson;
2206
- throw error;
2207
- }
2208
- });
2209
- }
2210
- }, function (_result2) {
2211
- var _exit3 = false;
2212
-
2213
- if (moduleResponse.status < 200 || moduleResponse.status >= 300) {
2214
- var _objectSpread4;
2215
-
2216
- throw new Error(createDetailedMessage("Module file response status is unexpected.", _objectSpread2((_objectSpread4 = {}, _defineProperty(_objectSpread4, "status", moduleResponse.status), _defineProperty(_objectSpread4, "allowed status", "200 to 299"), _defineProperty(_objectSpread4, "statusText", moduleResponse.statusText), _objectSpread4), getModuleDetails({
2217
- url: url,
2218
- importerUrl: importerUrl,
2219
- compileServerOrigin: compileServerOrigin,
2220
- compileDirectoryRelativeUrl: compileDirectoryRelativeUrl
2221
- }))));
2222
- } // don't forget to keep in sync with loadModule in createJsenvRollupPlugin.js
2223
-
2224
-
2225
- return _invoke$5(function () {
2226
- if (contentType === "application/javascript" || contentType === "text/javascript") {
2227
- return _await$9(moduleResponse.text(), function (bodyAsText) {
2228
- _exit3 = true;
2229
- return fromFunctionReturningRegisteredModule(function () {
2230
- return instantiateJavaScript(bodyAsText, moduleResponse.url);
2231
- }, {
2232
- url: moduleResponse.url,
2233
- importerUrl: importerUrl,
2234
- compileServerOrigin: compileServerOrigin,
2235
- compileDirectoryRelativeUrl: compileDirectoryRelativeUrl
2236
- });
2237
- });
2238
- }
2239
- }, function (_result3) {
2240
- var _exit4 = false;
2241
- if (_exit3) return _result3;
2242
- return _invoke$5(function () {
2243
- if (contentType === "application/json" || contentType.endsWith("+json")) {
2244
- return _await$9(moduleResponse.json(), function (bodyAsJson) {
2245
- _exit4 = true;
2246
- return fromFunctionReturningNamespace(function () {
2247
- return {
2248
- default: bodyAsJson
2249
- };
2250
- }, {
2251
- url: moduleResponse.url,
2252
- importerUrl: importerUrl,
2253
- compileServerOrigin: compileServerOrigin,
2254
- compileDirectoryRelativeUrl: compileDirectoryRelativeUrl
2255
- });
2256
- });
2257
- }
2258
- }, function (_result4) {
2259
- if (_exit4) return _result4;
2260
-
2261
- if (contentType) {
2262
- console.warn(createDetailedMessage("Ressource content-type is unusual", _objectSpread2(_objectSpread2({
2263
- "content-type": contentType,
2264
- "allowed content-type": ["application/javascript", "application/json"]
2265
- }, getModuleDetails({
2266
- url: url,
2267
- importerUrl: importerUrl,
2268
- compileServerOrigin: compileServerOrigin,
2269
- compileDirectoryRelativeUrl: compileDirectoryRelativeUrl
2270
- })), {}, {
2271
- "suggestion": "Prefer import.meta.url as documented in https://github.com/jsenv/jsenv-core/blob/master/docs/building/readme.md#How-to-reference-js-assets"
2272
- })));
2273
- } else {
2274
- console.warn("Ressource content-type is missing", _objectSpread2({
2275
- "allowed content-type": ["application/javascript", "application/json"]
2276
- }, getModuleDetails({
2277
- url: url,
2278
- importerUrl: importerUrl,
2279
- compileServerOrigin: compileServerOrigin,
2280
- compileDirectoryRelativeUrl: compileDirectoryRelativeUrl
2281
- })));
2282
- }
2121
+ compileDirectoryRelativeUrl = _ref.compileDirectoryRelativeUrl,
2122
+ jsonContentTypeAccepted = _ref.jsonContentTypeAccepted;
2283
2123
 
2284
- return fromFunctionReturningNamespace(function () {
2285
- return {
2286
- default: moduleResponse.url
2287
- };
2288
- }, {
2289
- url: moduleResponse.url,
2124
+ if (response.status === 404) {
2125
+ return new Error(createDetailedMessage("JavaScript module file cannot be found", getModuleDetails({
2126
+ url: url,
2127
+ importerUrl: importerUrl,
2128
+ compileServerOrigin: compileServerOrigin,
2129
+ compileDirectoryRelativeUrl: compileDirectoryRelativeUrl,
2130
+ notFound: true
2131
+ })));
2132
+ }
2133
+
2134
+ var contentType = response.headers["content-type"] || "";
2135
+ return _invoke$6(function () {
2136
+ if (response.status === 500 && contentType === "application/json") {
2137
+ return _await$a(response.json(), function (bodyAsJson) {
2138
+ if (bodyAsJson.message && bodyAsJson.filename && "columnNumber" in bodyAsJson) {
2139
+ var error = new Error(createDetailedMessage("JavaScript module file cannot be parsed", _objectSpread2(_defineProperty({}, "parsing error message", bodyAsJson.message), getModuleDetails({
2140
+ url: url,
2290
2141
  importerUrl: importerUrl,
2291
2142
  compileServerOrigin: compileServerOrigin,
2292
2143
  compileDirectoryRelativeUrl: compileDirectoryRelativeUrl
2293
- });
2294
- });
2144
+ }))));
2145
+ error.parsingError = bodyAsJson;
2146
+ _exit = true;
2147
+ return error;
2148
+ }
2295
2149
  });
2296
- });
2297
- });
2298
- }); // const textToBase64 =
2299
- // typeof window === "object"
2300
- // ? (text) => window.btoa(window.unescape(window.encodeURIComponent(text)))
2301
- // : (text) => Buffer.from(text, "utf8").toString("base64")
2150
+ }
2151
+ }, function (_result) {
2152
+ var _objectSpread3;
2302
2153
 
2154
+ if (_exit) return _result;
2155
+ return response.status < 200 || response.status >= 300 ? new Error(createDetailedMessage("JavaScript module file response status is unexpected", _objectSpread2((_objectSpread3 = {}, _defineProperty(_objectSpread3, "status", response.status), _defineProperty(_objectSpread3, "allowed status", "200 to 299"), _defineProperty(_objectSpread3, "statusText", response.statusText), _objectSpread3), getModuleDetails({
2156
+ url: url,
2157
+ importerUrl: importerUrl,
2158
+ compileServerOrigin: compileServerOrigin,
2159
+ compileDirectoryRelativeUrl: compileDirectoryRelativeUrl
2160
+ })))) : jsonContentTypeAccepted && (contentType === "application/json" || contentType.endsWith("+json")) ? null : contentType !== "application/javascript" && contentType !== "text/javascript" ? new Error(createDetailedMessage("Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of \"".concat(contentType, "\". Strict MIME type checking is enforced for module scripts per HTML spec."), _objectSpread2(_objectSpread2({}, getModuleDetails({
2161
+ url: url,
2162
+ importerUrl: importerUrl,
2163
+ compileServerOrigin: compileServerOrigin,
2164
+ compileDirectoryRelativeUrl: compileDirectoryRelativeUrl
2165
+ })), {}, {
2166
+ suggestion: "Use import.meta.url or import assertions as documented in https://github.com/jsenv/jsenv-core/blob/master/docs/building/readme.md#How-to-reference-assets"
2167
+ }))) : null;
2168
+ });
2169
+ });
2303
2170
  var getModuleDetails = function getModuleDetails(_ref2) {
2304
2171
  var url = _ref2.url,
2305
2172
  importerUrl = _ref2.importerUrl,
@@ -2322,7 +2189,6 @@
2322
2189
  } : {}), {}, _defineProperty({}, "file url", url), importerUrl ? _defineProperty({}, "imported by", importerRelativeUrl || importerUrl) : {});
2323
2190
  return details;
2324
2191
  };
2325
-
2326
2192
  var tryToFindProjectRelativeUrl = function tryToFindProjectRelativeUrl(url, _ref5) {
2327
2193
  var compileServerOrigin = _ref5.compileServerOrigin,
2328
2194
  compileDirectoryRelativeUrl = _ref5.compileDirectoryRelativeUrl;
@@ -2347,7 +2213,10 @@
2347
2213
 
2348
2214
  var afterCompileDirectory = afterOrigin.slice(compileDirectoryRelativeUrl.length);
2349
2215
  return afterCompileDirectory;
2350
- };
2216
+ }; // const textToBase64 =
2217
+ // typeof window === "object"
2218
+ // ? (text) => window.btoa(window.unescape(window.encodeURIComponent(text)))
2219
+ // : (text) => Buffer.from(text, "utf8").toString("base64")
2351
2220
 
2352
2221
  var applyDefaultExtension = function applyDefaultExtension(specifier, importer) {
2353
2222
  if (!importer) {
@@ -2394,7 +2263,7 @@
2394
2263
  return extension;
2395
2264
  };
2396
2265
 
2397
- function _await$8(value, then, direct) {
2266
+ function _await$9(value, then, direct) {
2398
2267
  if (direct) {
2399
2268
  return then ? then(value) : value;
2400
2269
  }
@@ -2447,7 +2316,7 @@
2447
2316
  });
2448
2317
  };
2449
2318
 
2450
- return _await$8({
2319
+ return _await$9({
2451
2320
  resolveImport: _resolveImport
2452
2321
  });
2453
2322
  };
@@ -2491,7 +2360,7 @@
2491
2360
  return finalizer(false, result);
2492
2361
  }
2493
2362
 
2494
- function _async$8(f) {
2363
+ function _async$9(f) {
2495
2364
  return function () {
2496
2365
  for (var args = [], i = 0; i < arguments.length; i++) {
2497
2366
  args[i] = arguments[i];
@@ -2505,14 +2374,14 @@
2505
2374
  };
2506
2375
  }
2507
2376
 
2508
- var measureAsyncFnPerf = performance$1 ? _async$8(function (fn, name) {
2377
+ var measureAsyncFnPerf = performance$1 ? _async$9(function (fn, name) {
2509
2378
  var perfMarkStartName = "".concat(name, "_start");
2510
2379
  performance$1.mark(perfMarkStartName);
2511
2380
  return _finallyRethrows(fn, function (_wasThrown, _result) {
2512
2381
  performance$1.measure(name, perfMarkStartName);
2513
2382
  return _rethrow(_wasThrown, _result);
2514
2383
  });
2515
- }) : _async$8(function (fn) {
2384
+ }) : _async$9(function (fn) {
2516
2385
  return fn();
2517
2386
  });
2518
2387
 
@@ -3203,27 +3072,59 @@
3203
3072
  };
3204
3073
  })();
3205
3074
 
3206
- var valueInstall = function valueInstall(object, name, value) {
3207
- var has = (name in object);
3208
- var previous = object[name];
3209
- object[name] = value;
3075
+ function _await$8(value, then, direct) {
3076
+ if (direct) {
3077
+ return then ? then(value) : value;
3078
+ }
3079
+
3080
+ if (!value || !value.then) {
3081
+ value = Promise.resolve(value);
3082
+ }
3083
+
3084
+ return then ? value.then(then) : value;
3085
+ }
3086
+
3087
+ function _catch$4(body, recover) {
3088
+ try {
3089
+ var result = body();
3090
+ } catch (e) {
3091
+ return recover(e);
3092
+ }
3093
+
3094
+ if (result && result.then) {
3095
+ return result.then(void 0, recover);
3096
+ }
3097
+
3098
+ return result;
3099
+ }
3100
+
3101
+ function _invoke$5(body, then) {
3102
+ var result = body();
3103
+
3104
+ if (result && result.then) {
3105
+ return result.then(then);
3106
+ }
3107
+
3108
+ return then(result);
3109
+ }
3110
+
3111
+ function _async$8(f) {
3210
3112
  return function () {
3211
- if (has) {
3212
- object[name] = previous;
3213
- } else {
3214
- delete object[name];
3113
+ for (var args = [], i = 0; i < arguments.length; i++) {
3114
+ args[i] = arguments[i];
3215
3115
  }
3216
- };
3217
- };
3218
3116
 
3219
- var evalSource = function evalSource(code, href) {
3220
- // eslint-disable-next-line no-eval
3221
- return window.eval(appendSourceURL$1(code, href));
3222
- };
3117
+ try {
3118
+ return Promise.resolve(f.apply(this, args));
3119
+ } catch (e) {
3120
+ return Promise.reject(e);
3121
+ }
3122
+ };
3123
+ }
3223
3124
 
3224
- var appendSourceURL$1 = function appendSourceURL(code, sourceURL) {
3225
- return "".concat(code, "\n", "//#", " sourceURL=").concat(sourceURL);
3226
- };
3125
+ function _continue$2(value, then) {
3126
+ return value && value.then ? value.then(then) : then(value);
3127
+ }
3227
3128
 
3228
3129
  var createBrowserSystem = function createBrowserSystem(_ref) {
3229
3130
  var compileServerOrigin = _ref.compileServerOrigin,
@@ -3243,27 +3144,59 @@
3243
3144
  };
3244
3145
 
3245
3146
  browserSystem.resolve = _resolve;
3147
+ var instantiate = browserSystem.instantiate;
3148
+ browserSystem.instantiate = _async$8(function (url, importerUrl) {
3149
+ var _exit = false;
3246
3150
 
3247
- browserSystem.instantiate = function (url, importerUrl) {
3248
- return fromUrl({
3249
- url: url,
3250
- importerUrl: importerUrl,
3251
- fetchSource: fetchSource,
3252
- instantiateJavaScript: function instantiateJavaScript(source, responseUrl) {
3253
- var uninstallSystemGlobal = valueInstall(window, "System", browserSystem);
3151
+ var _this = this;
3254
3152
 
3255
- try {
3256
- evalSource(source, responseUrl);
3257
- } finally {
3258
- uninstallSystemGlobal();
3259
- }
3153
+ var _extractImportTypeFro = extractImportTypeFromUrl(url),
3154
+ importType = _extractImportTypeFro.importType,
3155
+ urlWithoutImportType = _extractImportTypeFro.urlWithoutImportType;
3260
3156
 
3261
- return browserSystem.getRegister();
3262
- },
3263
- compileServerOrigin: compileServerOrigin,
3264
- compileDirectoryRelativeUrl: compileDirectoryRelativeUrl
3157
+ return _invoke$5(function () {
3158
+ if (importType === "json") {
3159
+ return _await$8(instantiateAsJsonModule(urlWithoutImportType, {
3160
+ loader: _this,
3161
+ fetchSource: fetchSource
3162
+ }), function (jsonModule) {
3163
+ _exit = true;
3164
+ return jsonModule;
3165
+ });
3166
+ }
3167
+ }, function (_result) {
3168
+ var _exit2 = false;
3169
+ if (_exit) return _result;
3170
+ return _invoke$5(function () {
3171
+ if (importType === "css") {
3172
+ return _await$8(instantiateAsCssModule(urlWithoutImportType, {
3173
+ importerUrl: importerUrl,
3174
+ compileDirectoryRelativeUrl: compileDirectoryRelativeUrl,
3175
+ loader: _this,
3176
+ fetchSource: fetchSource
3177
+ }), function (cssModule) {
3178
+ _exit2 = true;
3179
+ return cssModule;
3180
+ });
3181
+ }
3182
+ }, function (_result2) {
3183
+ return _exit2 ? _result2 : _catch$4(function () {
3184
+ return _await$8(instantiate.call(_this, url, importerUrl));
3185
+ }, function (e) {
3186
+ return _await$8(createDetailedInstantiateError({
3187
+ instantiateError: e,
3188
+ url: url,
3189
+ importerUrl: importerUrl,
3190
+ compileServerOrigin: compileServerOrigin,
3191
+ compileDirectoryRelativeUrl: compileDirectoryRelativeUrl,
3192
+ fetchSource: fetchSource
3193
+ }), function (jsenvError) {
3194
+ throw jsenvError;
3195
+ });
3196
+ });
3197
+ });
3265
3198
  });
3266
- };
3199
+ });
3267
3200
 
3268
3201
  browserSystem.createContext = function (importerUrl) {
3269
3202
  return {
@@ -3277,6 +3210,140 @@
3277
3210
  return browserSystem;
3278
3211
  };
3279
3212
 
3213
+ var extractImportTypeFromUrl = function extractImportTypeFromUrl(url) {
3214
+ var urlObject = new URL(url);
3215
+ var search = urlObject.search;
3216
+ var searchParams = new URLSearchParams(search);
3217
+ var importType = searchParams.get("import_type");
3218
+
3219
+ if (!importType) {
3220
+ return {};
3221
+ }
3222
+
3223
+ searchParams.delete("import_type");
3224
+ urlObject.search = String(searchParams);
3225
+ return {
3226
+ importType: importType,
3227
+ urlWithoutImportType: urlObject.href
3228
+ };
3229
+ };
3230
+
3231
+ var instantiateAsJsonModule = _async$8(function (url, _ref2) {
3232
+ var loader = _ref2.loader,
3233
+ fetchSource = _ref2.fetchSource;
3234
+ return _await$8(fetchSource(url, {
3235
+ contentTypeExpected: "application/json"
3236
+ }), function (response) {
3237
+ return _await$8(response.json(), function (json) {
3238
+ window.System.register([], function (_export) {
3239
+ return {
3240
+ execute: function execute() {
3241
+ _export("default", json);
3242
+ }
3243
+ };
3244
+ });
3245
+ return loader.getRegister(url);
3246
+ });
3247
+ });
3248
+ });
3249
+
3250
+ var instantiateAsCssModule = _async$8(function (url, _ref3) {
3251
+ var importerUrl = _ref3.importerUrl,
3252
+ compileDirectoryRelativeUrl = _ref3.compileDirectoryRelativeUrl,
3253
+ loader = _ref3.loader,
3254
+ fetchSource = _ref3.fetchSource;
3255
+ return _await$8(fetchSource(url, {
3256
+ contentTypeExpected: "text/css"
3257
+ }), function (response) {
3258
+ return _await$8(response.text(), function (cssText) {
3259
+ var cssTextWithBaseUrl = cssWithBaseUrl({
3260
+ cssText: cssText,
3261
+ cssUrl: url,
3262
+ baseUrl: importerUrl
3263
+ });
3264
+ window.System.register([], function (_export) {
3265
+ return {
3266
+ execute: function execute() {
3267
+ var sheet = new CSSStyleSheet();
3268
+ sheet.replaceSync(cssTextWithBaseUrl);
3269
+
3270
+ _export("default", sheet);
3271
+ }
3272
+ };
3273
+ }); // There is a logic inside "toolbar.eventsource.js" which is reloading
3274
+ // all link rel="stylesheet" when file ending with ".css" are modified
3275
+ // But here it would not work because we have to replace the css in
3276
+ // the adopted stylsheet + all module importing this css module
3277
+ // should be reinstantiated
3278
+ // -> store a livereload callback forcing whole page reload
3279
+
3280
+ var compileDirectoryServerUrl = "".concat(window.location.origin, "/").concat(compileDirectoryRelativeUrl);
3281
+ var originalFileRelativeUrl = response.url.slice(compileDirectoryServerUrl.length);
3282
+
3283
+ window.__jsenv__.livereloadingCallbacks[originalFileRelativeUrl] = function (_ref4) {
3284
+ var reloadPage = _ref4.reloadPage;
3285
+ reloadPage();
3286
+ };
3287
+
3288
+ return loader.getRegister(url);
3289
+ });
3290
+ });
3291
+ }); // CSSStyleSheet accepts a "baseUrl" parameter
3292
+ // as documented in https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/CSSStyleSheet#parameters
3293
+ // Unfortunately the polyfill do not seems to implement it
3294
+ // So we reuse "systemjs" strategy from https://github.com/systemjs/systemjs/blob/98609dbeef01ec62447e4b21449ce47e55f818bd/src/extras/module-types.js#L37
3295
+
3296
+
3297
+ var cssWithBaseUrl = function cssWithBaseUrl(_ref5) {
3298
+ var cssUrl = _ref5.cssUrl,
3299
+ cssText = _ref5.cssText,
3300
+ baseUrl = _ref5.baseUrl;
3301
+ var cssDirectoryUrl = new URL("./", cssUrl).href;
3302
+ var baseDirectoryUrl = new URL("./", baseUrl).href;
3303
+
3304
+ if (cssDirectoryUrl === baseDirectoryUrl) {
3305
+ return cssText;
3306
+ }
3307
+
3308
+ var cssTextRelocated = cssText.replace(/url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g, function (match, quotes, relUrl1, relUrl2) {
3309
+ var absoluteUrl = new URL(relUrl1 || relUrl2, cssUrl).href;
3310
+ return "url(".concat(quotes).concat(absoluteUrl).concat(quotes, ")");
3311
+ });
3312
+ return cssTextRelocated;
3313
+ };
3314
+
3315
+ var createDetailedInstantiateError = _async$8(function (_ref6) {
3316
+ var _exit3 = false;
3317
+ var instantiateError = _ref6.instantiateError,
3318
+ url = _ref6.url,
3319
+ importerUrl = _ref6.importerUrl,
3320
+ compileServerOrigin = _ref6.compileServerOrigin,
3321
+ compileDirectoryRelativeUrl = _ref6.compileDirectoryRelativeUrl,
3322
+ fetchSource = _ref6.fetchSource;
3323
+ var response;
3324
+ return _continue$2(_catch$4(function () {
3325
+ return _await$8(fetchSource(url, {
3326
+ importerUrl: importerUrl,
3327
+ contentTypeExpected: "application/javascript"
3328
+ }), function (_fetchSource) {
3329
+ response = _fetchSource;
3330
+ });
3331
+ }, function (e) {
3332
+ e.code = "NETWORK_FAILURE";
3333
+ _exit3 = true;
3334
+ return e;
3335
+ }), function (_result3) {
3336
+ return _exit3 ? _result3 : _await$8(getJavaScriptModuleResponseError(response, {
3337
+ url: url,
3338
+ importerUrl: importerUrl,
3339
+ compileServerOrigin: compileServerOrigin,
3340
+ compileDirectoryRelativeUrl: compileDirectoryRelativeUrl
3341
+ }), function (jsModuleResponseError) {
3342
+ return jsModuleResponseError || instantiateError;
3343
+ });
3344
+ });
3345
+ });
3346
+
3280
3347
  var displayErrorInDocument = function displayErrorInDocument(error) {
3281
3348
  var title = "An error occured";
3282
3349
  var theme;
@@ -3291,7 +3358,7 @@
3291
3358
  message = errorToHTML(error);
3292
3359
  }
3293
3360
 
3294
- var css = "\n .jsenv-console {\n background: rgba(0, 0, 0, 0.8);\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n display: flex;\n flex-direction: column;\n align-items: center\n z-index: 1000;\n width: 100%;\n box-sizing: border-box;\n padding: 1em;\n }\n\n .jsenv-console h1 {\n color: red;\n display: flex;\n align-items: center;\n }\n\n #button-close-jsenv-console {\n margin-left: 10px;\n }\n\n .jsenv-console pre {\n overflow: auto;\n max-width: 70em;\n /* avoid scrollbar to hide the text behind it */\n padding: 20px;\n }\n\n .jsenv-console pre[data-theme=\"dark\"] {\n background: transparent;\n border: 1px solid black;\n }\n\n .jsenv-console pre[data-theme=\"light\"] {\n background: #1E1E1E;\n border: 1px solid white;\n color: #EEEEEE;\n }\n\n .jsenv-console pre[data-theme=\"light\"] a {\n color: inherit;\n }\n ";
3361
+ var css = "\n .jsenv-console {\n background: rgba(0, 0, 0, 0.95);\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n align-items: center;\n z-index: 1000;\n box-sizing: border-box;\n padding: 1em;\n }\n\n .jsenv-console h1 {\n color: red;\n display: flex;\n align-items: center;\n }\n\n #button-close-jsenv-console {\n margin-left: 10px;\n }\n\n .jsenv-console pre {\n overflow: auto;\n max-width: 70em;\n /* avoid scrollbar to hide the text behind it */\n padding: 20px;\n }\n\n .jsenv-console pre[data-theme=\"dark\"] {\n background: #111;\n border: 1px solid #333;\n color: #eee;\n }\n\n .jsenv-console pre[data-theme=\"light\"] {\n background: #1E1E1E;\n border: 1px solid white;\n color: #EEEEEE;\n }\n\n .jsenv-console pre a {\n color: inherit;\n }\n ";
3295
3362
  var html = "\n <style type=\"text/css\">".concat(css, "></style>\n <div class=\"jsenv-console\">\n <h1>").concat(title, " <button id=\"button-close-jsenv-console\">X</button></h1>\n <pre data-theme=\"").concat(theme, "\">").concat(message, "</pre>\n </div>\n ");
3296
3363
  var removeJsenvConsole = appendHMTLInside(html, document.body);
3297
3364
 
@@ -3641,22 +3708,26 @@
3641
3708
  outDirectoryRelativeUrl = _ref.outDirectoryRelativeUrl,
3642
3709
  compileId = _ref.compileId;
3643
3710
 
3644
- var fetchSource = function fetchSource(url) {
3711
+ var fetchSource = function fetchSource(url, _ref2) {
3712
+ var contentTypeExpected = _ref2.contentTypeExpected;
3645
3713
  return fetchUrl(url, {
3646
- credentials: "same-origin"
3714
+ credentials: "same-origin",
3715
+ contentTypeExpected: contentTypeExpected
3647
3716
  });
3648
3717
  };
3649
3718
 
3650
3719
  var fetchJson = _async$6(function (url) {
3651
- return _await$6(fetchSource(url), function (response) {
3720
+ return _await$6(fetchSource(url, {
3721
+ contentTypeExpected: "application/json"
3722
+ }), function (response) {
3652
3723
  return _await$6(response.json());
3653
3724
  });
3654
3725
  });
3655
3726
 
3656
3727
  var outDirectoryUrl = "".concat(compileServerOrigin, "/").concat(outDirectoryRelativeUrl);
3657
3728
  var envUrl = String(new URL("env.json", outDirectoryUrl));
3658
- return _await$6(fetchJson(envUrl), function (_ref2) {
3659
- var importDefaultExtension = _ref2.importDefaultExtension;
3729
+ return _await$6(fetchJson(envUrl), function (_ref3) {
3730
+ var importDefaultExtension = _ref3.importDefaultExtension;
3660
3731
  var compileDirectoryRelativeUrl = "".concat(outDirectoryRelativeUrl).concat(compileId, "/"); // if there is an importmap in the document we use it instead of fetching.
3661
3732
  // systemjs style with systemjs-importmap
3662
3733
 
@@ -3669,7 +3740,9 @@
3669
3740
  return _invoke$4(function () {
3670
3741
  if (importmapScript.src) {
3671
3742
  importMapUrl = importmapScript.src;
3672
- return _await$6(fetchSource(importMapUrl), function (importmapFileResponse) {
3743
+ return _await$6(fetchSource(importMapUrl, {
3744
+ contentTypeExpected: "application/importmap+json"
3745
+ }), function (importmapFileResponse) {
3673
3746
  var _temp = importmapFileResponse.status === 404;
3674
3747
 
3675
3748
  return _await$6(_temp ? {} : importmapFileResponse.json(), function (_importmapFileRespons) {
@@ -3705,22 +3778,22 @@
3705
3778
  });
3706
3779
 
3707
3780
  var executeFile = _async$6(function (specifier) {
3708
- var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
3709
- _ref3$transferableNam = _ref3.transferableNamespace,
3710
- transferableNamespace = _ref3$transferableNam === void 0 ? false : _ref3$transferableNam,
3711
- _ref3$errorExposureIn = _ref3.errorExposureInConsole,
3712
- errorExposureInConsole = _ref3$errorExposureIn === void 0 ? true : _ref3$errorExposureIn,
3713
- _ref3$errorExposureIn2 = _ref3.errorExposureInNotification,
3714
- errorExposureInNotification = _ref3$errorExposureIn2 === void 0 ? false : _ref3$errorExposureIn2,
3715
- _ref3$errorExposureIn3 = _ref3.errorExposureInDocument,
3716
- errorExposureInDocument = _ref3$errorExposureIn3 === void 0 ? true : _ref3$errorExposureIn3,
3717
- _ref3$executionExposu = _ref3.executionExposureOnWindow,
3718
- executionExposureOnWindow = _ref3$executionExposu === void 0 ? false : _ref3$executionExposu,
3719
- _ref3$errorTransform = _ref3.errorTransform,
3720
- errorTransform = _ref3$errorTransform === void 0 ? function (error) {
3781
+ var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
3782
+ _ref4$transferableNam = _ref4.transferableNamespace,
3783
+ transferableNamespace = _ref4$transferableNam === void 0 ? false : _ref4$transferableNam,
3784
+ _ref4$errorExposureIn = _ref4.errorExposureInConsole,
3785
+ errorExposureInConsole = _ref4$errorExposureIn === void 0 ? true : _ref4$errorExposureIn,
3786
+ _ref4$errorExposureIn2 = _ref4.errorExposureInNotification,
3787
+ errorExposureInNotification = _ref4$errorExposureIn2 === void 0 ? false : _ref4$errorExposureIn2,
3788
+ _ref4$errorExposureIn3 = _ref4.errorExposureInDocument,
3789
+ errorExposureInDocument = _ref4$errorExposureIn3 === void 0 ? true : _ref4$errorExposureIn3,
3790
+ _ref4$executionExposu = _ref4.executionExposureOnWindow,
3791
+ executionExposureOnWindow = _ref4$executionExposu === void 0 ? false : _ref4$executionExposu,
3792
+ _ref4$errorTransform = _ref4.errorTransform,
3793
+ errorTransform = _ref4$errorTransform === void 0 ? function (error) {
3721
3794
  return error;
3722
- } : _ref3$errorTransform,
3723
- measurePerformance = _ref3.measurePerformance;
3795
+ } : _ref4$errorTransform,
3796
+ measurePerformance = _ref4.measurePerformance;
3724
3797
 
3725
3798
  return _await$6(memoizedCreateBrowserSystem({
3726
3799
  compileServerOrigin: compileServerOrigin,
@@ -5096,7 +5169,9 @@
5096
5169
  });
5097
5170
  });
5098
5171
  }));
5172
+ var livereloadingCallbacks = {};
5099
5173
  window.__jsenv__ = {
5174
+ livereloadingCallbacks: livereloadingCallbacks,
5100
5175
  executionResultPromise: executionResultPromise,
5101
5176
  executeFileUsingDynamicImport: executeFileUsingDynamicImport,
5102
5177
  executeFileUsingSystemJs: executeFileUsingSystemJs