@jsenv/core 29.7.1 → 29.8.1

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 (47) hide show
  1. package/README.md +9 -12
  2. package/dist/babel_helpers/checkInRHS/checkInRHS.js +6 -0
  3. package/dist/babel_helpers/createClass/createClass.js +2 -1
  4. package/dist/babel_helpers/defineProperty/defineProperty.js +2 -0
  5. package/dist/babel_helpers/regeneratorRuntime/regeneratorRuntime.js +38 -21
  6. package/dist/js/s.js +2 -2
  7. package/dist/js/s.js.map +3 -3
  8. package/dist/js/ws.js +29 -8
  9. package/dist/main.js +431 -178
  10. package/package.json +6 -6
  11. package/src/build/build.js +12 -9
  12. package/src/dev/file_service.js +4 -7
  13. package/src/dev/start_dev_server.js +0 -1
  14. package/src/kitchen/compat/{features_compats.js → features_compatibility.js} +4 -1
  15. package/src/kitchen/compat/runtime_compat.js +3 -3
  16. package/src/kitchen/kitchen.js +18 -9
  17. package/src/kitchen/url_graph/url_info_transformations.js +1 -0
  18. package/src/kitchen/url_specifier_encoding.js +2 -2
  19. package/src/plugins/bundling/js_module/bundle_js_modules.js +5 -3
  20. package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +1 -1
  21. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +3 -3
  22. package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +1 -1
  23. package/src/plugins/importmap/jsenv_plugin_importmap.js +2 -2
  24. package/src/plugins/plugin_controller.js +70 -71
  25. package/src/plugins/ribbon/jsenv_plugin_ribbon.js +1 -1
  26. package/src/plugins/supervisor/jsenv_plugin_supervisor.js +1 -1
  27. package/src/plugins/toolbar/jsenv_plugin_toolbar.js +1 -1
  28. package/src/plugins/transpilation/as_js_classic/client/s.js +1 -1
  29. package/src/plugins/transpilation/as_js_classic/convert_js_module_to_js_classic.js +2 -0
  30. package/src/plugins/transpilation/as_js_classic/helpers/babel_plugin_transform_import_meta_resolve.js +26 -0
  31. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_conversion.js +5 -11
  32. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +2 -2
  33. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_library.js +3 -3
  34. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_workers.js +1 -1
  35. package/src/plugins/transpilation/as_js_module/convert_js_classic_to_js_module.js +45 -0
  36. package/src/plugins/transpilation/as_js_module/jsenv_plugin_as_js_module.js +78 -0
  37. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +2 -2
  38. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +11 -11
  39. package/src/plugins/transpilation/jsenv_plugin_import_meta_resolve.js +52 -0
  40. package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +16 -13
  41. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +5 -0
  42. package/src/plugins/url_analysis/html/html_urls.js +1 -1
  43. package/src/plugins/url_analysis/js/js_urls.js +1 -0
  44. package/src/plugins/url_analysis/jsenv_plugin_reference_expected_types.js +4 -2
  45. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +1 -1
  46. package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +3 -3
  47. package/src/plugins/url_resolution/node_esm_resolver.js +2 -2
package/dist/main.js CHANGED
@@ -8363,7 +8363,7 @@ const analyzeImportDeclaration = (node, {
8363
8363
  const specifierNode = node.source;
8364
8364
  const assertionInfo = extractImportAssertionsInfo(node);
8365
8365
  onUrl({
8366
- type: "js_import_export",
8366
+ type: "js_import",
8367
8367
  subtype: "import_static",
8368
8368
  specifier: specifierNode.value,
8369
8369
  specifierStart: specifierNode.start,
@@ -8383,7 +8383,7 @@ const analyzeImportExpression = (node, {
8383
8383
  }
8384
8384
  const assertionInfo = extractImportAssertionsInfo(node);
8385
8385
  onUrl({
8386
- type: "js_import_export",
8386
+ type: "js_import",
8387
8387
  subtype: "import_dynamic",
8388
8388
  specifier: specifierNode.value,
8389
8389
  specifierStart: specifierNode.start,
@@ -8407,7 +8407,7 @@ const analyzeExportNamedDeclaration = (node, {
8407
8407
  return;
8408
8408
  }
8409
8409
  onUrl({
8410
- type: "js_import_export",
8410
+ type: "js_import",
8411
8411
  subtype: "export_named",
8412
8412
  specifier: specifierNode.value,
8413
8413
  specifierStart: specifierNode.start,
@@ -8421,7 +8421,7 @@ const analyzeExportAllDeclaration = (node, {
8421
8421
  }) => {
8422
8422
  const specifierNode = node.source;
8423
8423
  onUrl({
8424
- type: "js_import_export",
8424
+ type: "js_import",
8425
8425
  subtype: "export_all",
8426
8426
  specifier: specifierNode.value,
8427
8427
  specifierStart: specifierNode.start,
@@ -8499,6 +8499,27 @@ const extractImportAssertionsInfo = node => {
8499
8499
  };
8500
8500
  };
8501
8501
 
8502
+ const isImportMetaResolveCall = node => {
8503
+ return node.type === "CallExpression" && node.callee.type === "MemberExpression" && node.callee.object.type === "MetaProperty" && node.callee.property.type === "Identifier" && node.callee.property.name === "resolve";
8504
+ };
8505
+ const analyzeImportMetaResolveCall = (node, {
8506
+ onUrl
8507
+ }) => {
8508
+ const firstArg = node.arguments[0];
8509
+ if (firstArg && isStringLiteralNode(firstArg)) {
8510
+ onUrl({
8511
+ node,
8512
+ type: "js_import",
8513
+ subtype: "import_meta_resolve",
8514
+ specifier: firstArg.value,
8515
+ specifierStart: firstArg.start,
8516
+ specifierEnd: firstArg.end,
8517
+ specifierLine: firstArg.loc.start.line,
8518
+ specifierColumn: firstArg.loc.start.column
8519
+ });
8520
+ }
8521
+ };
8522
+
8502
8523
  const isNewUrlCall = node => {
8503
8524
  return node.type === "NewExpression" && node.callee.type === "Identifier" && node.callee.name === "URL";
8504
8525
  };
@@ -8514,7 +8535,7 @@ const analyzeNewUrlCall = (node, {
8514
8535
  if (urlType === "StringLiteral") {
8515
8536
  const specifierNode = firstArgNode;
8516
8537
  onUrl({
8517
- type: "js_url_specifier",
8538
+ type: "js_url",
8518
8539
  subtype: "new_url_first_arg",
8519
8540
  specifier: specifierNode.value,
8520
8541
  specifierStart: specifierNode.start,
@@ -8544,7 +8565,7 @@ const analyzeNewUrlCall = (node, {
8544
8565
  // we can understand the first argument
8545
8566
  const specifierNode = firstArgNode;
8546
8567
  onUrl({
8547
- type: "js_url_specifier",
8568
+ type: "js_url",
8548
8569
  subtype: "new_url_first_arg",
8549
8570
  specifier: specifierNode.value,
8550
8571
  specifierStart: specifierNode.start,
@@ -8558,7 +8579,7 @@ const analyzeNewUrlCall = (node, {
8558
8579
  if (baseUrlType === "StringLiteral") {
8559
8580
  const specifierNode = secondArgNode;
8560
8581
  onUrl({
8561
- type: "js_url_specifier",
8582
+ type: "js_url",
8562
8583
  subtype: "new_url_second_arg",
8563
8584
  specifier: specifierNode.value,
8564
8585
  specifierStart: specifierNode.start,
@@ -8720,7 +8741,7 @@ const analyzeWorkerCallArguments = (node, {
8720
8741
  if (isStringLiteralNode(firstArgNode)) {
8721
8742
  const specifierNode = firstArgNode;
8722
8743
  onUrl({
8723
- type: "js_url_specifier",
8744
+ type: "js_url",
8724
8745
  subtype: referenceSubtype,
8725
8746
  expectedType,
8726
8747
  expectedSubtype,
@@ -8745,6 +8766,20 @@ const analyzeWorkerCallArguments = (node, {
8745
8766
  onUrl(mention);
8746
8767
  }
8747
8768
  });
8769
+ return;
8770
+ }
8771
+ if (isJsModule && isImportMetaResolveCall(firstArgNode)) {
8772
+ analyzeImportMetaResolveCall(firstArgNode, {
8773
+ onUrl: mention => {
8774
+ Object.assign(mention, {
8775
+ expectedType,
8776
+ expectedSubtype,
8777
+ typePropertyNode
8778
+ });
8779
+ onUrl(mention);
8780
+ }
8781
+ });
8782
+ return;
8748
8783
  }
8749
8784
  };
8750
8785
 
@@ -8762,7 +8797,7 @@ const analyzeImportScriptCalls = (node, {
8762
8797
  if (isStringLiteralNode(arg)) {
8763
8798
  const specifierNode = arg;
8764
8799
  onUrl({
8765
- type: "js_url_specifier",
8800
+ type: "js_url",
8766
8801
  subtype: "self_import_scripts_arg",
8767
8802
  expectedType: "js_classic",
8768
8803
  specifier: specifierNode.value,
@@ -8807,7 +8842,7 @@ const analyzeSystemRegisterDeps = (node, {
8807
8842
  if (isStringLiteralNode(element)) {
8808
8843
  const specifierNode = element;
8809
8844
  onUrl({
8810
- type: "js_url_specifier",
8845
+ type: "js_url",
8811
8846
  subtype: "system_register_arg",
8812
8847
  expectedType: "js_classic",
8813
8848
  specifier: specifierNode.value,
@@ -8835,7 +8870,7 @@ const analyzeSystemImportCall = (node, {
8835
8870
  if (isStringLiteralNode(firstArgNode)) {
8836
8871
  const specifierNode = firstArgNode;
8837
8872
  onUrl({
8838
- type: "js_url_specifier",
8873
+ type: "js_url",
8839
8874
  subtype: "system_import_arg",
8840
8875
  expectedType: "js_classic",
8841
8876
  specifier: specifierNode.value,
@@ -8846,6 +8881,32 @@ const analyzeSystemImportCall = (node, {
8846
8881
  });
8847
8882
  }
8848
8883
  };
8884
+ const isSystemResolveCall = node => {
8885
+ const callee = node.callee;
8886
+ return callee.type === "MemberExpression" && callee.object.type === "MemberExpression" && callee.object.object.type === "Identifier" &&
8887
+ // because of minification we can't assume _context.
8888
+ // so anything matching "*.meta.resolve()"
8889
+ // will be assumed to be the equivalent to "meta.resolve()"
8890
+ // callee.object.object.name === "_context" &&
8891
+ callee.object.property.type === "Identifier" && callee.object.property.name === "meta" && callee.property.type === "Identifier" && callee.property.name === "resolve";
8892
+ };
8893
+ const analyzeSystemResolveCall = (node, {
8894
+ onUrl
8895
+ }) => {
8896
+ const firstArgNode = node.arguments[0];
8897
+ if (isStringLiteralNode(firstArgNode)) {
8898
+ const specifierNode = firstArgNode;
8899
+ onUrl({
8900
+ type: "js_url",
8901
+ subtype: "system_resolve_arg",
8902
+ specifier: specifierNode.value,
8903
+ specifierStart: specifierNode.start,
8904
+ specifierEnd: specifierNode.end,
8905
+ specifierLine: specifierNode.loc.start.line,
8906
+ specifierColumn: specifierNode.loc.start.column
8907
+ });
8908
+ }
8909
+ };
8849
8910
 
8850
8911
  const parseJsUrls = async ({
8851
8912
  js,
@@ -8884,6 +8945,12 @@ const parseJsUrls = async ({
8884
8945
  });
8885
8946
  },
8886
8947
  CallExpression: node => {
8948
+ if (isJsModule && isImportMetaResolveCall(node)) {
8949
+ analyzeImportMetaResolveCall(node, {
8950
+ onUrl
8951
+ });
8952
+ return;
8953
+ }
8887
8954
  if (isServiceWorkerRegisterCall(node)) {
8888
8955
  analyzeServiceWorkerRegisterCall(node, {
8889
8956
  isJsModule,
@@ -8909,6 +8976,12 @@ const parseJsUrls = async ({
8909
8976
  });
8910
8977
  return;
8911
8978
  }
8979
+ if (!isJsModule && isSystemResolveCall(node)) {
8980
+ analyzeSystemResolveCall(node, {
8981
+ onUrl
8982
+ });
8983
+ return;
8984
+ }
8912
8985
  },
8913
8986
  NewExpression: (node, ancestors) => {
8914
8987
  if (isNewWorkerCall(node)) {
@@ -8970,11 +9043,11 @@ const urlSpecifierEncoding = {
8970
9043
  }
8971
9044
  };
8972
9045
  const formatters = {
8973
- "js_import_export": {
9046
+ "js_import": {
8974
9047
  encode: JSON.stringify,
8975
9048
  decode: JSON.parse
8976
9049
  },
8977
- "js_url_specifier": {
9050
+ "js_url": {
8978
9051
  encode: JSON.stringify,
8979
9052
  decode: JSON.parse
8980
9053
  },
@@ -9277,23 +9350,30 @@ const HOOK_NAMES = ["init", "serve",
9277
9350
  "cooked", "augmentResponse",
9278
9351
  // is called only during dev/tests
9279
9352
  "destroy"];
9280
- const createPluginController = ({
9281
- plugins,
9282
- scenarios
9283
- }) => {
9284
- const flatPlugins = flattenAndFilterPlugins(plugins, {
9285
- scenarios
9286
- });
9353
+ const createPluginController = kitchenContext => {
9354
+ const plugins = [];
9287
9355
  // precompute a list of hooks per hookName for one major reason:
9288
9356
  // - When debugging, there is less iteration
9289
9357
  // also it should increase perf as there is less work to do
9290
-
9291
9358
  const hookGroups = {};
9292
9359
  const addPlugin = (plugin, {
9293
9360
  position = "start"
9294
9361
  }) => {
9362
+ if (plugin === null || typeof plugin !== "object") {
9363
+ throw new TypeError(`plugin must be objects, got ${plugin}`);
9364
+ }
9365
+ if (!testAppliesDuring(plugin) || !initPlugin(plugin)) {
9366
+ if (plugin.destroy) {
9367
+ plugin.destroy();
9368
+ }
9369
+ return;
9370
+ }
9371
+ if (!plugin.name) {
9372
+ plugin.name = "anonymous";
9373
+ }
9374
+ plugins.push(plugin);
9295
9375
  Object.keys(plugin).forEach(key => {
9296
- if (key === "name" || key === "appliesDuring" || key === "serverEvents") {
9376
+ if (key === "name" || key === "appliesDuring" || key === "init" || key === "serverEvents") {
9297
9377
  return;
9298
9378
  }
9299
9379
  const isHook = HOOK_NAMES.includes(key);
@@ -9317,6 +9397,52 @@ const createPluginController = ({
9317
9397
  }
9318
9398
  });
9319
9399
  };
9400
+ const testAppliesDuring = plugin => {
9401
+ const {
9402
+ appliesDuring
9403
+ } = plugin;
9404
+ if (appliesDuring === undefined) {
9405
+ // console.debug(`"appliesDuring" is undefined on ${pluginEntry.name}`)
9406
+ return true;
9407
+ }
9408
+ if (appliesDuring === "*") {
9409
+ return true;
9410
+ }
9411
+ if (typeof appliesDuring === "string") {
9412
+ if (appliesDuring !== "dev" && appliesDuring !== "build") {
9413
+ throw new TypeError(`"appliesDuring" must be "dev" or "build", got ${appliesDuring}`);
9414
+ }
9415
+ if (kitchenContext[appliesDuring]) {
9416
+ return true;
9417
+ }
9418
+ return false;
9419
+ }
9420
+ if (typeof appliesDuring === "object") {
9421
+ for (const key of Object.keys(appliesDuring)) {
9422
+ if (!appliesDuring[key] && kitchenContext[key]) {
9423
+ return false;
9424
+ }
9425
+ if (appliesDuring[key] && kitchenContext[key]) {
9426
+ return true;
9427
+ }
9428
+ }
9429
+ // throw new Error(`"appliesDuring" is empty`)
9430
+ return false;
9431
+ }
9432
+ throw new TypeError(`"appliesDuring" must be an object or a string, got ${appliesDuring}`);
9433
+ };
9434
+ const initPlugin = plugin => {
9435
+ if (plugin.init) {
9436
+ const initReturnValue = plugin.init(kitchenContext);
9437
+ if (initReturnValue === false) {
9438
+ return false;
9439
+ }
9440
+ if (typeof initReturnValue === "function" && !plugin.destroy) {
9441
+ plugin.destroy = initReturnValue;
9442
+ }
9443
+ }
9444
+ return true;
9445
+ };
9320
9446
  const pushPlugin = plugin => {
9321
9447
  addPlugin(plugin, {
9322
9448
  position: "start"
@@ -9327,9 +9453,6 @@ const createPluginController = ({
9327
9453
  position: "end"
9328
9454
  });
9329
9455
  };
9330
- flatPlugins.forEach(plugin => {
9331
- pushPlugin(plugin);
9332
- });
9333
9456
  let lastPluginUsed = null;
9334
9457
  let currentPlugin = null;
9335
9458
  let currentHookName = null;
@@ -9436,7 +9559,7 @@ const createPluginController = ({
9436
9559
  });
9437
9560
  };
9438
9561
  return {
9439
- plugins: flatPlugins,
9562
+ plugins,
9440
9563
  pushPlugin,
9441
9564
  unshiftPlugin,
9442
9565
  getHookFunction,
@@ -9451,68 +9574,6 @@ const createPluginController = ({
9451
9574
  getCurrentHookName: () => currentHookName
9452
9575
  };
9453
9576
  };
9454
- const flattenAndFilterPlugins = (plugins, {
9455
- scenarios
9456
- }) => {
9457
- const flatPlugins = [];
9458
- const visitPluginEntry = pluginEntry => {
9459
- if (Array.isArray(pluginEntry)) {
9460
- pluginEntry.forEach(value => visitPluginEntry(value));
9461
- return;
9462
- }
9463
- if (typeof pluginEntry === "object" && pluginEntry !== null) {
9464
- if (!pluginEntry.name) {
9465
- pluginEntry.name = "anonymous";
9466
- }
9467
- const {
9468
- appliesDuring
9469
- } = pluginEntry;
9470
- if (appliesDuring === undefined) {
9471
- // console.debug(`"appliesDuring" is undefined on ${pluginEntry.name}`)
9472
- flatPlugins.push(pluginEntry);
9473
- return;
9474
- }
9475
- if (appliesDuring === "*") {
9476
- flatPlugins.push(pluginEntry);
9477
- return;
9478
- }
9479
- if (typeof appliesDuring === "string") {
9480
- if (!["dev", "build"].includes(appliesDuring)) {
9481
- throw new Error(`"appliesDuring" must be "dev" or "build", got ${appliesDuring}`);
9482
- }
9483
- if (scenarios[appliesDuring]) {
9484
- flatPlugins.push(pluginEntry);
9485
- return;
9486
- }
9487
- return;
9488
- }
9489
- if (typeof appliesDuring !== "object") {
9490
- throw new Error(`"appliesDuring" must be an object or a string, got ${appliesDuring}`);
9491
- }
9492
- let applies;
9493
- for (const key of Object.keys(appliesDuring)) {
9494
- if (!appliesDuring[key] && scenarios[key]) {
9495
- applies = false;
9496
- break;
9497
- }
9498
- if (appliesDuring[key] && scenarios[key]) {
9499
- applies = true;
9500
- }
9501
- }
9502
- if (applies) {
9503
- flatPlugins.push(pluginEntry);
9504
- return;
9505
- }
9506
- if (pluginEntry.destroy) {
9507
- pluginEntry.destroy();
9508
- }
9509
- return;
9510
- }
9511
- throw new Error(`plugin must be objects, got ${pluginEntry}`);
9512
- };
9513
- plugins.forEach(plugin => visitPluginEntry(plugin));
9514
- return flatPlugins;
9515
- };
9516
9577
  const getHookFunction = (hook,
9517
9578
  // can be undefined, reference, or urlInfo
9518
9579
  info = {}) => {
@@ -9651,6 +9712,7 @@ const createUrlInfoTransformer = ({
9651
9712
  // during build it's urlInfo.url to be inside the build
9652
9713
  // but otherwise it's generatedUrl to be inside .jsenv/ directory
9653
9714
  const generatedUrlObject = new URL(urlInfo.generatedUrl);
9715
+ generatedUrlObject.searchParams.delete("as_js_module");
9654
9716
  generatedUrlObject.searchParams.delete("as_js_classic");
9655
9717
  generatedUrlObject.searchParams.delete("as_js_classic_library");
9656
9718
  const urlForSourcemap = generatedUrlObject.href;
@@ -9872,7 +9934,7 @@ const findHighestVersion = (...values) => {
9872
9934
  });
9873
9935
  };
9874
9936
 
9875
- const featureCompats = {
9937
+ const featuresCompatMap = {
9876
9938
  script_type_module: {
9877
9939
  edge: "16",
9878
9940
  firefox: "60",
@@ -9903,6 +9965,9 @@ const featureCompats = {
9903
9965
  safari: "11.1",
9904
9966
  samsung: "9.2"
9905
9967
  },
9968
+ import_meta_resolve: {
9969
+ chrome: "107"
9970
+ },
9906
9971
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
9907
9972
  import_dynamic: {
9908
9973
  android: "8",
@@ -10029,7 +10094,7 @@ const featureCompats = {
10029
10094
  };
10030
10095
 
10031
10096
  const RUNTIME_COMPAT = {
10032
- featureCompats,
10097
+ featuresCompatMap,
10033
10098
  add: (originalRuntimeCompat, feature) => {
10034
10099
  const featureCompat = getFeatureCompat(feature);
10035
10100
  const runtimeCompat = {
@@ -10058,7 +10123,7 @@ const RUNTIME_COMPAT = {
10058
10123
  };
10059
10124
  const getFeatureCompat = feature => {
10060
10125
  if (typeof feature === "string") {
10061
- const compat = featureCompats[feature];
10126
+ const compat = featuresCompatMap[feature];
10062
10127
  if (!compat) {
10063
10128
  throw new Error(`"${feature}" feature is unknown`);
10064
10129
  }
@@ -10460,14 +10525,15 @@ const createKitchen = ({
10460
10525
  signal,
10461
10526
  logLevel,
10462
10527
  rootDirectoryUrl,
10463
- scenarios,
10528
+ dev = false,
10529
+ build = false,
10464
10530
  runtimeCompat,
10465
10531
  // during dev/test clientRuntimeCompat is a single runtime
10466
10532
  // during build clientRuntimeCompat is runtimeCompat
10467
10533
  clientRuntimeCompat = runtimeCompat,
10468
10534
  urlGraph,
10469
10535
  plugins,
10470
- sourcemaps = scenarios.dev ? "inline" : "none",
10536
+ sourcemaps = dev ? "inline" : "none",
10471
10537
  // "programmatic" and "file" also allowed
10472
10538
  sourcemapsSourcesProtocol,
10473
10539
  sourcemapsSourcesContent,
@@ -10478,16 +10544,13 @@ const createKitchen = ({
10478
10544
  const logger = createLogger({
10479
10545
  logLevel
10480
10546
  });
10481
- const pluginController = createPluginController({
10482
- plugins,
10483
- scenarios
10484
- });
10485
10547
  const kitchenContext = {
10486
10548
  signal,
10487
10549
  logger,
10488
10550
  rootDirectoryUrl,
10489
10551
  urlGraph,
10490
- scenarios,
10552
+ dev,
10553
+ build,
10491
10554
  runtimeCompat,
10492
10555
  clientRuntimeCompat,
10493
10556
  isSupportedOnCurrentClients: feature => {
@@ -10499,7 +10562,17 @@ const createKitchen = ({
10499
10562
  sourcemaps,
10500
10563
  outDirectoryUrl
10501
10564
  };
10502
- pluginController.callHooks("init", kitchenContext);
10565
+ const pluginController = createPluginController(kitchenContext);
10566
+ const pushPlugins = plugins => {
10567
+ plugins.forEach(pluginEntry => {
10568
+ if (Array.isArray(pluginEntry)) {
10569
+ pushPlugins(pluginEntry);
10570
+ } else {
10571
+ pluginController.pushPlugin(pluginEntry);
10572
+ }
10573
+ });
10574
+ };
10575
+ pushPlugins(plugins);
10503
10576
  const createReference = ({
10504
10577
  data = {},
10505
10578
  node,
@@ -11164,7 +11237,7 @@ const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
11164
11237
  column: reference.specifierColumn
11165
11238
  };
11166
11239
  urlInfo.contentType = reference.contentType;
11167
- urlInfo.originalContent = context.scenarios.build ? urlInfo.originalContent === undefined ? reference.content : urlInfo.originalContent : reference.content;
11240
+ urlInfo.originalContent = context.build ? urlInfo.originalContent === undefined ? reference.content : urlInfo.originalContent : reference.content;
11168
11241
  urlInfo.content = reference.content;
11169
11242
  }
11170
11243
  };
@@ -11527,10 +11600,12 @@ const jsenvPluginReferenceExpectedTypes = () => {
11527
11600
  reference.expectedType = "js_classic";
11528
11601
  } else if (searchParams.has("as_js_classic") || searchParams.has("as_js_classic_library")) {
11529
11602
  reference.expectedType = "js_classic";
11603
+ } else if (searchParams.has("as_js_module")) {
11604
+ reference.expectedType = "js_module";
11530
11605
  } else if (searchParams.has("js_module")) {
11531
11606
  searchParams.delete("js_module");
11532
11607
  reference.expectedType = "js_module";
11533
- } else if (reference.type === "js_url_specifier" && reference.expectedType === undefined && CONTENT_TYPE.fromUrlExtension(reference.url) === "text/javascript") {
11608
+ } else if (reference.type === "js_url" && reference.expectedType === undefined && CONTENT_TYPE.fromUrlExtension(reference.url) === "text/javascript") {
11534
11609
  // by default, js referenced by new URL is considered as "js_module"
11535
11610
  // in case this is not desired code must use "?js_classic" like
11536
11611
  // new URL('./file.js?js_classic', import.meta.url)
@@ -11553,7 +11628,7 @@ const jsenvPluginReferenceExpectedTypes = () => {
11553
11628
  appliesDuring: "*",
11554
11629
  redirectUrl: {
11555
11630
  script_src: redirectJsUrls,
11556
- js_url_specifier: redirectJsUrls
11631
+ js_url: redirectJsUrls
11557
11632
  }
11558
11633
  };
11559
11634
  };
@@ -11562,7 +11637,7 @@ const parseAndTransformHtmlUrls = async (urlInfo, context) => {
11562
11637
  const url = urlInfo.originalUrl;
11563
11638
  const content = urlInfo.content;
11564
11639
  const htmlAst = parseHtmlString(content, {
11565
- storeOriginalPositions: context.scenarios.dev
11640
+ storeOriginalPositions: context.dev
11566
11641
  });
11567
11642
  const mentions = visitHtmlUrls({
11568
11643
  url,
@@ -11909,6 +11984,7 @@ const parseAndTransformJsUrls = async (urlInfo, context) => {
11909
11984
  urlInfo.data.usesImport = true;
11910
11985
  }
11911
11986
  const [reference] = context.referenceUtils.found({
11987
+ node: jsMention.node,
11912
11988
  type: jsMention.type,
11913
11989
  subtype: jsMention.subtype,
11914
11990
  expectedType: jsMention.expectedType,
@@ -12010,7 +12086,7 @@ const jsenvPluginUrlAnalysis = ({
12010
12086
  // so that urls must be kept intact
12011
12087
  // However for js import specifiers they have a different meaning and we want
12012
12088
  // to resolve them (https://nodejs.org/api/packages.html#imports for instance)
12013
- reference.type !== "js_import_export") {
12089
+ reference.type !== "js_import") {
12014
12090
  reference.shouldHandle = false;
12015
12091
  return;
12016
12092
  }
@@ -12807,6 +12883,27 @@ const generateExpressionAst = (expression, options) => {
12807
12883
  return ast;
12808
12884
  };
12809
12885
 
12886
+ const babelPluginTransformImportMetaResolve = () => {
12887
+ return {
12888
+ name: "transform-import-meta-resolve",
12889
+ visitor: {
12890
+ Program: programPath => {
12891
+ programPath.traverse({
12892
+ MemberExpression: path => {
12893
+ const node = path.node;
12894
+ if (node.object.type === "MetaProperty" && node.object.property.name === "meta" && node.property.name === "resolve") {
12895
+ const firstArg = node.arguments[0];
12896
+ if (firstArg && firstArg.type === "StringLiteral") {
12897
+ path.replaceWithSourceString(`new URL(${firstArg.value}, document.currentScript.src).href`);
12898
+ }
12899
+ }
12900
+ }
12901
+ });
12902
+ }
12903
+ }
12904
+ };
12905
+ };
12906
+
12810
12907
  // eslint-disable-next-line import/no-default-export
12811
12908
  var helpers_string_1 = '// A type of promise-like that resolves synchronously and supports only one observer\nexport const _Pact = /*#__PURE__*/(function() {\n\tfunction _Pact() {}\n\t_Pact.prototype.then = function(onFulfilled, onRejected) {\n\t\tconst result = new _Pact();\n\t\tconst state = this.s;\n\t\tif (state) {\n\t\t\tconst callback = state & 1 ? onFulfilled : onRejected;\n\t\t\tif (callback) {\n\t\t\t\ttry {\n\t\t\t\t\t_settle(result, 1, callback(this.v));\n\t\t\t\t} catch (e) {\n\t\t\t\t\t_settle(result, 2, e);\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t} else {\n\t\t\t\treturn this;\n\t\t\t}\n\t\t}\n\t\tthis.o = function(_this) {\n\t\t\ttry {\n\t\t\t\tconst value = _this.v;\n\t\t\t\tif (_this.s & 1) {\n\t\t\t\t\t_settle(result, 1, onFulfilled ? onFulfilled(value) : value);\n\t\t\t\t} else if (onRejected) {\n\t\t\t\t\t_settle(result, 1, onRejected(value));\n\t\t\t\t} else {\n\t\t\t\t\t_settle(result, 2, value);\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\t_settle(result, 2, e);\n\t\t\t}\n\t\t};\n\t\treturn result;\n\t}\n\treturn _Pact;\n})();\n\n// Settles a pact synchronously\nexport function _settle(pact, state, value) {\n\tif (!pact.s) {\n\t\tif (value instanceof _Pact) {\n\t\t\tif (value.s) {\n\t\t\t\tif (state & 1) {\n\t\t\t\t\tstate = value.s;\n\t\t\t\t}\n\t\t\t\tvalue = value.v;\n\t\t\t} else {\n\t\t\t\tvalue.o = _settle.bind(null, pact, state);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (value && value.then) {\n\t\t\tvalue.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));\n\t\t\treturn;\n\t\t}\n\t\tpact.s = state;\n\t\tpact.v = value;\n\t\tconst observer = pact.o;\n\t\tif (observer) {\n\t\t\tobserver(pact);\n\t\t}\n\t}\n}\n\nexport function _isSettledPact(thenable) {\n\treturn thenable instanceof _Pact && thenable.s & 1;\n}\n\n// Converts argument to a function that always returns a Promise\nexport function _async(f) {\n\treturn function() {\n\t\tfor (var args = [], i = 0; i < arguments.length; i++) {\n\t\t\targs[i] = arguments[i];\n\t\t}\n\t\ttry {\n\t\t\treturn Promise.resolve(f.apply(this, args));\n\t\t} catch(e) {\n\t\t\treturn Promise.reject(e);\n\t\t}\n\t}\n}\n\n// Awaits on a value that may or may not be a Promise (equivalent to the await keyword in ES2015, with continuations passed explicitly)\nexport function _await(value, then, direct) {\n\tif (direct) {\n\t\treturn then ? then(value) : value;\n\t}\n\tif (!value || !value.then) {\n\t\tvalue = Promise.resolve(value);\n\t}\n\treturn then ? value.then(then) : value;\n}\n\n// Awaits on a value that may or may not be a Promise, then ignores it\nexport function _awaitIgnored(value, direct) {\n\tif (!direct) {\n\t\treturn value && value.then ? value.then(_empty) : Promise.resolve();\n\t}\n}\n\n// Proceeds after a value has resolved, or proceeds immediately if the value is not thenable\nexport function _continue(value, then) {\n\treturn value && value.then ? value.then(then) : then(value);\n}\n\n// Proceeds after a value has resolved, or proceeds immediately if the value is not thenable\nexport function _continueIgnored(value) {\n\tif (value && value.then) {\n\t\treturn value.then(_empty);\n\t}\n}\n\n// Asynchronously iterate through an object that has a length property, passing the index as the first argument to the callback (even as the length property changes)\nexport function _forTo(array, body, check) {\n\tvar i = -1, pact, reject;\n\tfunction _cycle(result) {\n\t\ttry {\n\t\t\twhile (++i < array.length && (!check || !check())) {\n\t\t\t\tresult = body(i);\n\t\t\t\tif (result && result.then) {\n\t\t\t\t\tif (_isSettledPact(result)) {\n\t\t\t\t\t\tresult = result.v;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2)));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pact) {\n\t\t\t\t_settle(pact, 1, result);\n\t\t\t} else {\n\t\t\t\tpact = result;\n\t\t\t}\n\t\t} catch (e) {\n\t\t\t_settle(pact || (pact = new _Pact()), 2, e);\n\t\t}\n\t}\n\t_cycle();\n\treturn pact;\n}\n\n// Asynchronously iterate through an object\'s properties (including properties inherited from the prototype)\n// Uses a snapshot of the object\'s properties\nexport function _forIn(target, body, check) {\n\tvar keys = [];\n\tfor (var key in target) {\n\t\tkeys.push(key);\n\t}\n\treturn _forTo(keys, function(i) { return body(keys[i]); }, check);\n}\n\n// Asynchronously iterate through an object\'s own properties (excluding properties inherited from the prototype)\n// Uses a snapshot of the object\'s properties\nexport function _forOwn(target, body, check) {\n\tvar keys = [];\n\tfor (var key in target) {\n\t\tif (Object.prototype.hasOwnProperty.call(target, key)) {\n\t\t\tkeys.push(key);\n\t\t}\n\t}\n\treturn _forTo(keys, function(i) { return body(keys[i]); }, check);\n}\n\nexport const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";\n\n// Asynchronously iterate through an object\'s values\n// Uses for...of if the runtime supports it, otherwise iterates until length on a copy\nexport function _forOf(target, body, check) {\n\tif (typeof target[_iteratorSymbol] === "function") {\n\t\tvar iterator = target[_iteratorSymbol](), step, pact, reject;\n\t\tfunction _cycle(result) {\n\t\t\ttry {\n\t\t\t\twhile (!(step = iterator.next()).done && (!check || !check())) {\n\t\t\t\t\tresult = body(step.value);\n\t\t\t\t\tif (result && result.then) {\n\t\t\t\t\t\tif (_isSettledPact(result)) {\n\t\t\t\t\t\t\tresult = result.v;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tresult.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2)));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (pact) {\n\t\t\t\t\t_settle(pact, 1, result);\n\t\t\t\t} else {\n\t\t\t\t\tpact = result;\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\t_settle(pact || (pact = new _Pact()), 2, e);\n\t\t\t}\n\t\t}\n\t\t_cycle();\n\t\tif (iterator.return) {\n\t\t\tvar _fixup = function(value) {\n\t\t\t\ttry {\n\t\t\t\t\tif (!step.done) {\n\t\t\t\t\t\titerator.return();\n\t\t\t\t\t}\n\t\t\t\t} catch(e) {\n\t\t\t\t}\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\tif (pact && pact.then) {\n\t\t\t\treturn pact.then(_fixup, function(e) {\n\t\t\t\t\tthrow _fixup(e);\n\t\t\t\t});\n\t\t\t}\n\t\t\t_fixup();\n\t\t}\n\t\treturn pact;\n\t}\n\t// No support for Symbol.iterator\n\tif (!("length" in target)) {\n\t\tthrow new TypeError("Object is not iterable");\n\t}\n\t// Handle live collections properly\n\tvar values = [];\n\tfor (var i = 0; i < target.length; i++) {\n\t\tvalues.push(target[i]);\n\t}\n\treturn _forTo(values, function(i) { return body(values[i]); }, check);\n}\n\nexport const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";\n\n// Asynchronously iterate on a value using it\'s async iterator if present, or its synchronous iterator if missing\nexport function _forAwaitOf(target, body, check) {\n\tif (typeof target[_asyncIteratorSymbol] === "function") {\n\t\tvar pact = new _Pact();\n\t\tvar iterator = target[_asyncIteratorSymbol]();\n\t\titerator.next().then(_resumeAfterNext).then(void 0, _reject);\n\t\treturn pact;\n\t\tfunction _resumeAfterBody(result) {\n\t\t\tif (check && check()) {\n\t\t\t\treturn _settle(pact, 1, iterator.return ? iterator.return().then(function() { return result; }) : result);\n\t\t\t}\n\t\t\titerator.next().then(_resumeAfterNext).then(void 0, _reject);\n\t\t}\n\t\tfunction _resumeAfterNext(step) {\n\t\t\tif (step.done) {\n\t\t\t\t_settle(pact, 1);\n\t\t\t} else {\n\t\t\t\tPromise.resolve(body(step.value)).then(_resumeAfterBody).then(void 0, _reject);\n\t\t\t}\n\t\t}\n\t\tfunction _reject(error) {\n\t\t\t_settle(pact, 2, iterator.return ? iterator.return().then(function() { return error; }) : error);\n\t\t}\n\t}\n\treturn Promise.resolve(_forOf(target, function(value) { return Promise.resolve(value).then(body); }, check));\n}\n\n// Asynchronously implement a generic for loop\nexport function _for(test, update, body) {\n\tvar stage;\n\tfor (;;) {\n\t\tvar shouldContinue = test();\n\t\tif (_isSettledPact(shouldContinue)) {\n\t\t\tshouldContinue = shouldContinue.v;\n\t\t}\n\t\tif (!shouldContinue) {\n\t\t\treturn result;\n\t\t}\n\t\tif (shouldContinue.then) {\n\t\t\tstage = 0;\n\t\t\tbreak;\n\t\t}\n\t\tvar result = body();\n\t\tif (result && result.then) {\n\t\t\tif (_isSettledPact(result)) {\n\t\t\t\tresult = result.s;\n\t\t\t} else {\n\t\t\t\tstage = 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (update) {\n\t\t\tvar updateValue = update();\n\t\t\tif (updateValue && updateValue.then && !_isSettledPact(updateValue)) {\n\t\t\t\tstage = 2;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tvar pact = new _Pact();\n\tvar reject = _settle.bind(null, pact, 2);\n\t(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);\n\treturn pact;\n\tfunction _resumeAfterBody(value) {\n\t\tresult = value;\n\t\tdo {\n\t\t\tif (update) {\n\t\t\t\tupdateValue = update();\n\t\t\t\tif (updateValue && updateValue.then && !_isSettledPact(updateValue)) {\n\t\t\t\t\tupdateValue.then(_resumeAfterUpdate).then(void 0, reject);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tshouldContinue = test();\n\t\t\tif (!shouldContinue || (_isSettledPact(shouldContinue) && !shouldContinue.v)) {\n\t\t\t\t_settle(pact, 1, result);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (shouldContinue.then) {\n\t\t\t\tshouldContinue.then(_resumeAfterTest).then(void 0, reject);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresult = body();\n\t\t\tif (_isSettledPact(result)) {\n\t\t\t\tresult = result.v;\n\t\t\t}\n\t\t} while (!result || !result.then);\n\t\tresult.then(_resumeAfterBody).then(void 0, reject);\n\t}\n\tfunction _resumeAfterTest(shouldContinue) {\n\t\tif (shouldContinue) {\n\t\t\tresult = body();\n\t\t\tif (result && result.then) {\n\t\t\t\tresult.then(_resumeAfterBody).then(void 0, reject);\n\t\t\t} else {\n\t\t\t\t_resumeAfterBody(result);\n\t\t\t}\n\t\t} else {\n\t\t\t_settle(pact, 1, result);\n\t\t}\n\t}\n\tfunction _resumeAfterUpdate() {\n\t\tif (shouldContinue = test()) {\n\t\t\tif (shouldContinue.then) {\n\t\t\t\tshouldContinue.then(_resumeAfterTest).then(void 0, reject);\n\t\t\t} else {\n\t\t\t\t_resumeAfterTest(shouldContinue);\n\t\t\t}\n\t\t} else {\n\t\t\t_settle(pact, 1, result);\n\t\t}\n\t}\n}\n\n// Asynchronously implement a do ... while loop\nexport function _do(body, test) {\n\tvar awaitBody;\n\tdo {\n\t\tvar result = body();\n\t\tif (result && result.then) {\n\t\t\tif (_isSettledPact(result)) {\n\t\t\t\tresult = result.v;\n\t\t\t} else {\n\t\t\t\tawaitBody = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tvar shouldContinue = test();\n\t\tif (_isSettledPact(shouldContinue)) {\n\t\t\tshouldContinue = shouldContinue.v;\n\t\t}\n\t\tif (!shouldContinue) {\n\t\t\treturn result;\n\t\t}\n\t} while (!shouldContinue.then);\n\tconst pact = new _Pact();\n\tconst reject = _settle.bind(null, pact, 2);\n\t(awaitBody ? result.then(_resumeAfterBody) : shouldContinue.then(_resumeAfterTest)).then(void 0, reject);\n\treturn pact;\n\tfunction _resumeAfterBody(value) {\n\t\tresult = value;\n\t\tfor (;;) {\n\t\t\tshouldContinue = test();\n\t\t\tif (_isSettledPact(shouldContinue)) {\n\t\t\t\tshouldContinue = shouldContinue.v;\n\t\t\t}\n\t\t\tif (!shouldContinue) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (shouldContinue.then) {\n\t\t\t\tshouldContinue.then(_resumeAfterTest).then(void 0, reject);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresult = body();\n\t\t\tif (result && result.then) {\n\t\t\t\tif (_isSettledPact(result)) {\n\t\t\t\t\tresult = result.v;\n\t\t\t\t} else {\n\t\t\t\t\tresult.then(_resumeAfterBody).then(void 0, reject);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t_settle(pact, 1, result);\n\t}\n\tfunction _resumeAfterTest(shouldContinue) {\n\t\tif (shouldContinue) {\n\t\t\tdo {\n\t\t\t\tresult = body();\n\t\t\t\tif (result && result.then) {\n\t\t\t\t\tif (_isSettledPact(result)) {\n\t\t\t\t\t\tresult = result.v;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult.then(_resumeAfterBody).then(void 0, reject);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tshouldContinue = test();\n\t\t\t\tif (_isSettledPact(shouldContinue)) {\n\t\t\t\t\tshouldContinue = shouldContinue.v;\n\t\t\t\t}\n\t\t\t\tif (!shouldContinue) {\n\t\t\t\t\t_settle(pact, 1, result);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} while (!shouldContinue.then);\n\t\t\tshouldContinue.then(_resumeAfterTest).then(void 0, reject);\n\t\t} else {\n\t\t\t_settle(pact, 1, result);\n\t\t}\n\t}\n}\n\n// Asynchronously implement a switch statement\nexport function _switch(discriminant, cases) {\n\tvar dispatchIndex = -1;\n\tvar awaitBody;\n\touter: {\n\t\tfor (var i = 0; i < cases.length; i++) {\n\t\t\tvar test = cases[i][0];\n\t\t\tif (test) {\n\t\t\t\tvar testValue = test();\n\t\t\t\tif (testValue && testValue.then) {\n\t\t\t\t\tbreak outer;\n\t\t\t\t}\n\t\t\t\tif (testValue === discriminant) {\n\t\t\t\t\tdispatchIndex = i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Found the default case, set it as the pending dispatch case\n\t\t\t\tdispatchIndex = i;\n\t\t\t}\n\t\t}\n\t\tif (dispatchIndex !== -1) {\n\t\t\tdo {\n\t\t\t\tvar body = cases[dispatchIndex][1];\n\t\t\t\twhile (!body) {\n\t\t\t\t\tdispatchIndex++;\n\t\t\t\t\tbody = cases[dispatchIndex][1];\n\t\t\t\t}\n\t\t\t\tvar result = body();\n\t\t\t\tif (result && result.then) {\n\t\t\t\t\tawaitBody = true;\n\t\t\t\t\tbreak outer;\n\t\t\t\t}\n\t\t\t\tvar fallthroughCheck = cases[dispatchIndex][2];\n\t\t\t\tdispatchIndex++;\n\t\t\t} while (fallthroughCheck && !fallthroughCheck());\n\t\t\treturn result;\n\t\t}\n\t}\n\tconst pact = new _Pact();\n\tconst reject = _settle.bind(null, pact, 2);\n\t(awaitBody ? result.then(_resumeAfterBody) : testValue.then(_resumeAfterTest)).then(void 0, reject);\n\treturn pact;\n\tfunction _resumeAfterTest(value) {\n\t\tfor (;;) {\n\t\t\tif (value === discriminant) {\n\t\t\t\tdispatchIndex = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (++i === cases.length) {\n\t\t\t\tif (dispatchIndex !== -1) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\t_settle(pact, 1, result);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttest = cases[i][0];\n\t\t\tif (test) {\n\t\t\t\tvalue = test();\n\t\t\t\tif (value && value.then) {\n\t\t\t\t\tvalue.then(_resumeAfterTest).then(void 0, reject);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdispatchIndex = i;\n\t\t\t}\n\t\t}\n\t\tdo {\n\t\t\tvar body = cases[dispatchIndex][1];\n\t\t\twhile (!body) {\n\t\t\t\tdispatchIndex++;\n\t\t\t\tbody = cases[dispatchIndex][1];\n\t\t\t}\n\t\t\tvar result = body();\n\t\t\tif (result && result.then) {\n\t\t\t\tresult.then(_resumeAfterBody).then(void 0, reject);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tvar fallthroughCheck = cases[dispatchIndex][2];\n\t\t\tdispatchIndex++;\n\t\t} while (fallthroughCheck && !fallthroughCheck());\n\t\t_settle(pact, 1, result);\n\t}\n\tfunction _resumeAfterBody(result) {\n\t\tfor (;;) {\n\t\t\tvar fallthroughCheck = cases[dispatchIndex][2];\n\t\t\tif (!fallthroughCheck || fallthroughCheck()) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdispatchIndex++;\n\t\t\tvar body = cases[dispatchIndex][1];\n\t\t\twhile (!body) {\n\t\t\t\tdispatchIndex++;\n\t\t\t\tbody = cases[dispatchIndex][1];\n\t\t\t}\n\t\t\tresult = body();\n\t\t\tif (result && result.then) {\n\t\t\t\tresult.then(_resumeAfterBody).then(void 0, reject);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t_settle(pact, 1, result);\n\t}\n}\n\n// Asynchronously call a function and pass the result to explicitly passed continuations\nexport function _call(body, then, direct) {\n\tif (direct) {\n\t\treturn then ? then(body()) : body();\n\t}\n\ttry {\n\t\tvar result = Promise.resolve(body());\n\t\treturn then ? result.then(then) : result;\n\t} catch (e) {\n\t\treturn Promise.reject(e);\n\t}\n}\n\n// Asynchronously call a function and swallow the result\nexport function _callIgnored(body, direct) {\n\treturn _call(body, _empty, direct);\n}\n\n// Asynchronously call a function and pass the result to explicitly passed continuations\nexport function _invoke(body, then) {\n\tvar result = body();\n\tif (result && result.then) {\n\t\treturn result.then(then);\n\t}\n\treturn then(result);\n}\n\n// Asynchronously call a function and swallow the result\nexport function _invokeIgnored(body) {\n\tvar result = body();\n\tif (result && result.then) {\n\t\treturn result.then(_empty);\n\t}\n}\n\n// Asynchronously call a function and send errors to recovery continuation\nexport function _catch(body, recover) {\n\ttry {\n\t\tvar result = body();\n\t} catch(e) {\n\t\treturn recover(e);\n\t}\n\tif (result && result.then) {\n\t\treturn result.then(void 0, recover);\n\t}\n\treturn result;\n}\n\n// Asynchronously await a promise and pass the result to a finally continuation\nexport function _finallyRethrows(body, finalizer) {\n\ttry {\n\t\tvar result = body();\n\t} catch (e) {\n\t\treturn finalizer(true, e);\n\t}\n\tif (result && result.then) {\n\t\treturn result.then(finalizer.bind(null, false), finalizer.bind(null, true));\n\t}\n\treturn finalizer(false, result);\n}\n\n// Asynchronously await a promise and invoke a finally continuation that always overrides the result\nexport function _finally(body, finalizer) {\n\ttry {\n\t\tvar result = body();\n\t} catch (e) {\n\t\treturn finalizer();\n\t}\n\tif (result && result.then) {\n\t\treturn result.then(finalizer, finalizer);\n\t}\n\treturn finalizer();\n}\n\n// Rethrow or return a value from a finally continuation\nexport function _rethrow(thrown, value) {\n\tif (thrown)\n\t\tthrow value;\n\treturn value;\n}\n\n// Empty function to implement break and other control flow that ignores asynchronous results\nexport function _empty() {\n}\n\n// Sentinel value for early returns in generators \nexport const _earlyReturn = /*#__PURE__*/ {};\n\n// Asynchronously call a function and send errors to recovery continuation, skipping early returns\nexport function _catchInGenerator(body, recover) {\n\treturn _catch(body, function(e) {\n\t\tif (e === _earlyReturn) {\n\t\t\tthrow e;\n\t\t}\n\t\treturn recover(e);\n\t});\n}\n\n// Asynchronous generator class; accepts the entrypoint of the generator, to which it passes itself when the generator should start\nexport const _AsyncGenerator = /*#__PURE__*/(function() {\n\tfunction _AsyncGenerator(entry) {\n\t\tthis._entry = entry;\n\t\tthis._pact = null;\n\t\tthis._resolve = null;\n\t\tthis._return = null;\n\t\tthis._promise = null;\n\t}\n\n\tfunction _wrapReturnedValue(value) {\n\t\treturn { value: value, done: true };\n\t}\n\tfunction _wrapYieldedValue(value) {\n\t\treturn { value: value, done: false };\n\t}\n\n\t_AsyncGenerator.prototype._yield = function(value) {\n\t\t// Yield the value to the pending next call\n\t\tthis._resolve(value && value.then ? value.then(_wrapYieldedValue) : _wrapYieldedValue(value));\n\t\t// Return a pact for an upcoming next/return/throw call\n\t\treturn this._pact = new _Pact();\n\t};\n\t_AsyncGenerator.prototype.next = function(value) {\n\t\t// Advance the generator, starting it if it has yet to be started\n\t\tconst _this = this;\n\t\treturn _this._promise = new Promise(function (resolve) {\n\t\t\tconst _pact = _this._pact;\n\t\t\tif (_pact === null) {\n\t\t\t\tconst _entry = _this._entry;\n\t\t\t\tif (_entry === null) {\n\t\t\t\t\t// Generator is started, but not awaiting a yield expression\n\t\t\t\t\t// Abandon the next call!\n\t\t\t\t\treturn resolve(_this._promise);\n\t\t\t\t}\n\t\t\t\t// Start the generator\n\t\t\t\t_this._entry = null;\n\t\t\t\t_this._resolve = resolve;\n\t\t\t\tfunction returnValue(value) {\n\t\t\t\t\t_this._resolve(value && value.then ? value.then(_wrapReturnedValue) : _wrapReturnedValue(value));\n\t\t\t\t\t_this._pact = null;\n\t\t\t\t\t_this._resolve = null;\n\t\t\t\t}\n\t\t\t\tvar result = _entry(_this);\n\t\t\t\tif (result && result.then) {\n\t\t\t\t\tresult.then(returnValue, function(error) {\n\t\t\t\t\t\tif (error === _earlyReturn) {\n\t\t\t\t\t\t\treturnValue(_this._return);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst pact = new _Pact();\n\t\t\t\t\t\t\t_this._resolve(pact);\n\t\t\t\t\t\t\t_this._pact = null;\n\t\t\t\t\t\t\t_this._resolve = null;\n\t\t\t\t\t\t\t_resolve(pact, 2, error);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\treturnValue(result);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Generator is started and a yield expression is pending, settle it\n\t\t\t\t_this._pact = null;\n\t\t\t\t_this._resolve = resolve;\n\t\t\t\t_settle(_pact, 1, value);\n\t\t\t}\n\t\t});\n\t};\n\t_AsyncGenerator.prototype.return = function(value) {\n\t\t// Early return from the generator if started, otherwise abandons the generator\n\t\tconst _this = this;\n\t\treturn _this._promise = new Promise(function (resolve) {\n\t\t\tconst _pact = _this._pact;\n\t\t\tif (_pact === null) {\n\t\t\t\tif (_this._entry === null) {\n\t\t\t\t\t// Generator is started, but not awaiting a yield expression\n\t\t\t\t\t// Abandon the return call!\n\t\t\t\t\treturn resolve(_this._promise);\n\t\t\t\t}\n\t\t\t\t// Generator is not started, abandon it and return the specified value\n\t\t\t\t_this._entry = null;\n\t\t\t\treturn resolve(value && value.then ? value.then(_wrapReturnedValue) : _wrapReturnedValue(value));\n\t\t\t}\n\t\t\t// Settle the yield expression with a rejected "early return" value\n\t\t\t_this._return = value;\n\t\t\t_this._resolve = resolve;\n\t\t\t_this._pact = null;\n\t\t\t_settle(_pact, 2, _earlyReturn);\n\t\t});\n\t};\n\t_AsyncGenerator.prototype.throw = function(error) {\n\t\t// Inject an exception into the pending yield expression\n\t\tconst _this = this;\n\t\treturn _this._promise = new Promise(function (resolve, reject) {\n\t\t\tconst _pact = _this._pact;\n\t\t\tif (_pact === null) {\n\t\t\t\tif (_this._entry === null) {\n\t\t\t\t\t// Generator is started, but not awaiting a yield expression\n\t\t\t\t\t// Abandon the throw call!\n\t\t\t\t\treturn resolve(_this._promise);\n\t\t\t\t}\n\t\t\t\t// Generator is not started, abandon it and return a rejected Promise containing the error\n\t\t\t\t_this._entry = null;\n\t\t\t\treturn reject(error);\n\t\t\t}\n\t\t\t// Settle the yield expression with the value as a rejection\n\t\t\t_this._resolve = resolve;\n\t\t\t_this._pact = null;\n\t\t\t_settle(_pact, 2, error);\n\t\t});\n\t};\n\n\t_AsyncGenerator.prototype[_asyncIteratorSymbol] = function() {\n\t\treturn this;\n\t};\n\t\n\treturn _AsyncGenerator;\n})();\n';
12812
12909
 
@@ -16371,7 +16468,7 @@ const convertJsModuleToJsClassic = async ({
16371
16468
  asyncAwait: false,
16372
16469
  // already handled + we might not needs it at all
16373
16470
  topLevelAwait: "simple"
16374
- }], babelPluginTransformImportMetaUrl, requireFromJsenv("@babel/plugin-transform-modules-umd")])],
16471
+ }], babelPluginTransformImportMetaUrl, babelPluginTransformImportMetaResolve, requireFromJsenv("@babel/plugin-transform-modules-umd")])],
16375
16472
  urlInfo: jsModuleUrlInfo
16376
16473
  });
16377
16474
  let sourcemap = jsModuleUrlInfo.sourcemap;
@@ -16418,10 +16515,10 @@ const jsenvPluginAsJsClassicConversion = ({
16418
16515
  generateJsClassicFilename
16419
16516
  }) => {
16420
16517
  const isReferencingJsModule = reference => {
16421
- if (reference.type === "js_import_export" || reference.subtype === "system_register_arg" || reference.subtype === "system_import_arg") {
16518
+ if (reference.type === "js_import" || reference.subtype === "system_register_arg" || reference.subtype === "system_import_arg") {
16422
16519
  return true;
16423
16520
  }
16424
- if (reference.type === "js_url_specifier" && reference.expectedType === "js_module") {
16521
+ if (reference.type === "js_url" && reference.expectedType === "js_module") {
16425
16522
  return true;
16426
16523
  }
16427
16524
  return false;
@@ -16483,14 +16580,14 @@ const jsenvPluginAsJsClassicConversion = ({
16483
16580
  await context.fetchUrlContent(jsModuleUrlInfo, {
16484
16581
  reference: jsModuleReference
16485
16582
  });
16486
- if (context.scenarios.dev) {
16583
+ if (context.dev) {
16487
16584
  context.referenceUtils.found({
16488
- type: "js_import_export",
16585
+ type: "js_import",
16489
16586
  subtype: jsModuleReference.subtype,
16490
16587
  specifier: jsModuleReference.url,
16491
16588
  expectedType: "js_module"
16492
16589
  });
16493
- } else if (context.scenarios.build && jsModuleUrlInfo.dependents.size === 0) {
16590
+ } else if (context.build && jsModuleUrlInfo.dependents.size === 0) {
16494
16591
  context.urlGraph.deleteUrlInfo(jsModuleUrlInfo.url);
16495
16592
  }
16496
16593
  const {
@@ -16554,7 +16651,7 @@ const jsenvPluginAsJsClassicHtml = ({
16554
16651
  }
16555
16652
  return null;
16556
16653
  },
16557
- js_url_specifier: reference => {
16654
+ js_url: reference => {
16558
16655
  if (shouldTransformScriptTypeModule && reference.expectedType === "js_module") {
16559
16656
  return turnIntoJsClassicProxy(reference);
16560
16657
  }
@@ -16646,7 +16743,7 @@ const jsenvPluginAsJsClassicHtml = ({
16646
16743
  break;
16647
16744
  }
16648
16745
  } catch (e) {
16649
- if (context.scenarios.dev) {
16746
+ if (context.dev) {
16650
16747
  needsSystemJs = true;
16651
16748
  // ignore cooking error, the browser will trigger it again on fetch
16652
16749
  // + disable cache for this html file because when browser will reload
@@ -16744,7 +16841,7 @@ const jsenvPluginAsJsClassicWorkers = () => {
16744
16841
  name: "jsenv:as_js_classic_workers",
16745
16842
  appliesDuring: "*",
16746
16843
  redirectUrl: {
16747
- js_url_specifier: (reference, context) => {
16844
+ js_url: (reference, context) => {
16748
16845
  if (reference.expectedType !== "js_module") {
16749
16846
  return null;
16750
16847
  }
@@ -17084,7 +17181,7 @@ const rollupPluginJsenv = ({
17084
17181
  const urlInfo = urlGraph.getUrlInfo(fileUrl);
17085
17182
  return {
17086
17183
  code: urlInfo.content,
17087
- map: urlInfo.sourcemap ? sourcemapConverter.toFilePaths(urlInfo.sourcemap) : null
17184
+ map: (sourcemaps === "file" || sourcemaps === "inline") && urlInfo.sourcemap ? sourcemapConverter.toFilePaths(urlInfo.sourcemap) : null
17088
17185
  };
17089
17186
  }
17090
17187
  };
@@ -17252,15 +17349,15 @@ const jsenvPluginAsJsClassicLibrary = ({
17252
17349
  }
17253
17350
  });
17254
17351
  const jsModuleBundledUrlInfo = bundleUrlInfos[jsModuleUrlInfo.url];
17255
- if (context.scenarios.dev) {
17352
+ if (context.dev) {
17256
17353
  jsModuleBundledUrlInfo.sourceUrls.forEach(sourceUrl => {
17257
17354
  context.referenceUtils.inject({
17258
- type: "js_url_specifier",
17355
+ type: "js_url",
17259
17356
  specifier: sourceUrl,
17260
17357
  isImplicit: true
17261
17358
  });
17262
17359
  });
17263
- } else if (context.scenarios.build) {
17360
+ } else if (context.build) {
17264
17361
  jsModuleBundledUrlInfo.sourceUrls.forEach(sourceUrl => {
17265
17362
  const sourceUrlInfo = context.urlGraph.getUrlInfo(sourceUrl);
17266
17363
  if (sourceUrlInfo && sourceUrlInfo.dependents.size === 0) {
@@ -17971,7 +18068,7 @@ const jsenvPluginImportmap = () => {
17971
18068
  name: "jsenv:importmap",
17972
18069
  appliesDuring: "*",
17973
18070
  resolveUrl: {
17974
- js_import_export: reference => {
18071
+ js_import: reference => {
17975
18072
  if (!finalImportmap) {
17976
18073
  return null;
17977
18074
  }
@@ -18113,7 +18210,7 @@ const jsenvPluginImportmap = () => {
18113
18210
  // by "formatReferencedUrl" making the importmap presence useless.
18114
18211
  // In dev/test we keep importmap into the HTML to see it even if useless
18115
18212
  // Duing build we get rid of it
18116
- if (context.scenarios.build) {
18213
+ if (context.build) {
18117
18214
  removeHtmlNode(importmap);
18118
18215
  }
18119
18216
  return {
@@ -19088,7 +19185,7 @@ const createNodeEsmResolver = ({
19088
19185
  parentUrl,
19089
19186
  specifier: reference.specifier
19090
19187
  });
19091
- if (context.scenarios.dev) {
19188
+ if (context.dev) {
19092
19189
  const dependsOnPackageJson = type !== "relative_specifier" && type !== "absolute_specifier" && type !== "node_builtin_specifier";
19093
19190
  if (dependsOnPackageJson) {
19094
19191
  // this reference depends on package.json and node_modules
@@ -19102,7 +19199,7 @@ const createNodeEsmResolver = ({
19102
19199
  });
19103
19200
  }
19104
19201
  }
19105
- if (context.scenarios.dev) {
19202
+ if (context.dev) {
19106
19203
  // without this check a file inside a project without package.json
19107
19204
  // could be considered as a node module if there is a ancestor package.json
19108
19205
  // but we want to version only node modules
@@ -19161,7 +19258,6 @@ const addRelationshipWithPackageJson = ({
19161
19258
  * and the rest uses the web standard url resolution (new URL):
19162
19259
  * - "http_request"
19163
19260
  * - "entry_point"
19164
- * - "js_import_export"
19165
19261
  * - "link_href"
19166
19262
  * - "script_src"
19167
19263
  * - "a_href"
@@ -19174,9 +19270,10 @@ const addRelationshipWithPackageJson = ({
19174
19270
  * - "use_href"
19175
19271
  * - "css_@import"
19176
19272
  * - "css_url"
19177
- * - "sourcemap_comment"
19178
- * - "js_url_specifier"
19273
+ * - "js_import"
19274
+ * - "js_url"
19179
19275
  * - "js_inline_content"
19276
+ * - "sourcemap_comment"
19180
19277
  * - "webmanifest_icon_src"
19181
19278
  * - "package_json"
19182
19279
  */
@@ -19764,7 +19861,7 @@ const jsenvPluginSupervisor = ({
19764
19861
  }
19765
19862
  });
19766
19863
  const [scriptTypeModuleSupervisorFileReference] = context.referenceUtils.inject({
19767
- type: "js_import_export",
19864
+ type: "js_import",
19768
19865
  expectedType: "js_module",
19769
19866
  specifier: scriptTypeModuleSupervisorFileUrl
19770
19867
  });
@@ -19854,7 +19951,7 @@ const jsenvPluginCommonJsGlobals = () => {
19854
19951
  }
19855
19952
  const isJsModule = urlInfo.type === "js_module";
19856
19953
  const replaceMap = {
19857
- "process.env.NODE_ENV": `("${context.scenarios.dev ? "development" : "production"}")`,
19954
+ "process.env.NODE_ENV": `("${context.dev ? "development" : "production"}")`,
19858
19955
  "global": "globalThis",
19859
19956
  "__filename": isJsModule ? `import.meta.url.slice('file:///'.length)` : `document.currentScript.src`,
19860
19957
  "__dirname": isJsModule ? `import.meta.url.slice('file:///'.length).replace(/[\\\/\\\\][^\\\/\\\\]*$/, '')` : `new URL('./', document.currentScript.src).href`
@@ -20024,7 +20121,7 @@ const jsenvPluginImportMetaScenarios = () => {
20024
20121
  value
20025
20122
  });
20026
20123
  };
20027
- if (context.scenarios.build) {
20124
+ if (context.build) {
20028
20125
  // during build ensure replacement for tree-shaking
20029
20126
  dev.forEach(path => {
20030
20127
  replace(path, "undefined");
@@ -20180,14 +20277,14 @@ const jsenvPluginImportAssertions = ({
20180
20277
  // We would have to tell rollup to ignore import with assertion
20181
20278
  // - means rollup can bundle more js file together
20182
20279
  // - means url versioning can work for css inlined in js
20183
- if (context.scenarios.build) {
20280
+ if (context.build) {
20184
20281
  transpilations.json = true;
20185
20282
  transpilations.css = true;
20186
20283
  transpilations.text = true;
20187
20284
  }
20188
20285
  },
20189
20286
  redirectUrl: {
20190
- js_import_export: (reference, context) => {
20287
+ js_import: (reference, context) => {
20191
20288
  if (!reference.assert) {
20192
20289
  return null;
20193
20290
  }
@@ -20226,14 +20323,14 @@ const jsenvPluginAsModules = () => {
20226
20323
  await context.fetchUrlContent(jsonUrlInfo, {
20227
20324
  reference: jsonReference
20228
20325
  });
20229
- if (context.scenarios.dev) {
20326
+ if (context.dev) {
20230
20327
  context.referenceUtils.found({
20231
- type: "js_import_export",
20328
+ type: "js_import",
20232
20329
  subtype: jsonReference.subtype,
20233
20330
  specifier: jsonReference.url,
20234
20331
  expectedType: "js_module"
20235
20332
  });
20236
- } else if (context.scenarios.build && jsonUrlInfo.dependents.size === 0) {
20333
+ } else if (context.build && jsonUrlInfo.dependents.size === 0) {
20237
20334
  context.urlGraph.deleteUrlInfo(jsonUrlInfo.url);
20238
20335
  }
20239
20336
  const jsonText = JSON.stringify(jsonUrlInfo.content.trim());
@@ -20266,14 +20363,14 @@ const jsenvPluginAsModules = () => {
20266
20363
  await context.fetchUrlContent(cssUrlInfo, {
20267
20364
  reference: cssReference
20268
20365
  });
20269
- if (context.scenarios.dev) {
20366
+ if (context.dev) {
20270
20367
  context.referenceUtils.found({
20271
- type: "js_import_export",
20368
+ type: "js_import",
20272
20369
  subtype: cssReference.subtype,
20273
20370
  specifier: cssReference.url,
20274
20371
  expectedType: "js_module"
20275
20372
  });
20276
- } else if (context.scenarios.build && cssUrlInfo.dependents.size === 0) {
20373
+ } else if (context.build && cssUrlInfo.dependents.size === 0) {
20277
20374
  context.urlGraph.deleteUrlInfo(cssUrlInfo.url);
20278
20375
  }
20279
20376
  const cssText = JS_QUOTES.escapeSpecialChars(cssUrlInfo.content, {
@@ -20313,14 +20410,14 @@ const jsenvPluginAsModules = () => {
20313
20410
  await context.fetchUrlContent(textUrlInfo, {
20314
20411
  reference: textReference
20315
20412
  });
20316
- if (context.scenarios.dev) {
20413
+ if (context.dev) {
20317
20414
  context.referenceUtils.found({
20318
- type: "js_import_export",
20415
+ type: "js_import",
20319
20416
  subtype: textReference.subtype,
20320
20417
  specifier: textReference.url,
20321
20418
  expectedType: "js_module"
20322
20419
  });
20323
- } else if (context.scenarios.build && textUrlInfo.dependents.size === 0) {
20420
+ } else if (context.build && textUrlInfo.dependents.size === 0) {
20324
20421
  context.urlGraph.deleteUrlInfo(textUrlInfo.url);
20325
20422
  }
20326
20423
  const textPlain = JS_QUOTES.escapeSpecialChars(urlInfo.content, {
@@ -20345,6 +20442,121 @@ export default inlineContent.text`,
20345
20442
  return [asJsonModule, asCssModule, asTextModule];
20346
20443
  };
20347
20444
 
20445
+ const convertJsClassicToJsModule = async ({
20446
+ urlInfo,
20447
+ jsClassicUrlInfo
20448
+ }) => {
20449
+ const {
20450
+ code,
20451
+ map
20452
+ } = await applyBabelPlugins({
20453
+ babelPlugins: [[babelPluginReplaceTopLevelThis, {
20454
+ isWebWorker: isWebWorkerUrlInfo(urlInfo)
20455
+ }]],
20456
+ urlInfo: jsClassicUrlInfo
20457
+ });
20458
+ const sourcemap = await composeTwoSourcemaps(jsClassicUrlInfo.sourcemap, map);
20459
+ return {
20460
+ content: code,
20461
+ sourcemap
20462
+ };
20463
+ };
20464
+ const babelPluginReplaceTopLevelThis = () => {
20465
+ return {
20466
+ name: "replace-top-level-this",
20467
+ visitor: {
20468
+ Program: (programPath, state) => {
20469
+ const {
20470
+ isWebWorker
20471
+ } = state.opts;
20472
+ programPath.traverse({
20473
+ ThisExpression: path => {
20474
+ const closestFunction = path.getFunctionParent();
20475
+ if (!closestFunction) {
20476
+ path.replaceWithSourceString(isWebWorker ? "self" : "window");
20477
+ }
20478
+ }
20479
+ });
20480
+ }
20481
+ }
20482
+ };
20483
+ };
20484
+
20485
+ /*
20486
+ * Js modules might not be able to import js meant to be loaded by <script>
20487
+ * Among other things this happens for a top level this:
20488
+ * - With <script> this is window
20489
+ * - With an import this is undefined
20490
+ * Example of this: https://github.com/video-dev/hls.js/issues/2911
20491
+ *
20492
+ * This plugin fix this issue by rewriting top level this into window
20493
+ * and can be used like this for instance import("hls?as_js_module")
20494
+ */
20495
+ const jsenvPluginAsJsModule = () => {
20496
+ return {
20497
+ name: "jsenv:as_js_module",
20498
+ appliesDuring: "*",
20499
+ redirectUrl: reference => {
20500
+ if (reference.searchParams.has("as_js_module")) {
20501
+ reference.expectedType = "js_module";
20502
+ const filename = urlToFilename$1(reference.url);
20503
+ const [basename] = splitFileExtension$1(filename);
20504
+ reference.filename = `${basename}.mjs`;
20505
+ }
20506
+ },
20507
+ fetchUrlContent: async (urlInfo, context) => {
20508
+ const [jsClassicReference, jsClassicUrlInfo] = context.getWithoutSearchParam({
20509
+ urlInfo,
20510
+ context,
20511
+ searchParam: "as_js_module",
20512
+ // override the expectedType to "js_classic"
20513
+ // because when there is ?as_js_module it means the underlying resource
20514
+ // is js_classic
20515
+ expectedType: "js_classic"
20516
+ });
20517
+ if (!jsClassicReference) {
20518
+ return null;
20519
+ }
20520
+ await context.fetchUrlContent(jsClassicUrlInfo, {
20521
+ reference: jsClassicReference
20522
+ });
20523
+ if (context.dev) {
20524
+ context.referenceUtils.found({
20525
+ type: "js_import",
20526
+ subtype: jsClassicReference.subtype,
20527
+ specifier: jsClassicReference.url,
20528
+ expectedType: "js_classic"
20529
+ });
20530
+ } else if (context.build && jsClassicUrlInfo.dependents.size === 0) {
20531
+ context.urlGraph.deleteUrlInfo(jsClassicUrlInfo.url);
20532
+ }
20533
+ const {
20534
+ content,
20535
+ sourcemap
20536
+ } = await convertJsClassicToJsModule({
20537
+ urlInfo,
20538
+ jsClassicUrlInfo
20539
+ });
20540
+ return {
20541
+ content,
20542
+ contentType: "text/javascript",
20543
+ type: "js_module",
20544
+ originalUrl: jsClassicUrlInfo.originalUrl,
20545
+ originalContent: jsClassicUrlInfo.originalContent,
20546
+ sourcemap,
20547
+ data: jsClassicUrlInfo.data
20548
+ };
20549
+ }
20550
+ };
20551
+ };
20552
+ const splitFileExtension$1 = filename => {
20553
+ const dotLastIndex = filename.lastIndexOf(".");
20554
+ if (dotLastIndex === -1) {
20555
+ return [filename, ""];
20556
+ }
20557
+ return [filename.slice(0, dotLastIndex), filename.slice(dotLastIndex)];
20558
+ };
20559
+
20348
20560
  // https://github.com/istanbuljs/babel-plugin-istanbul/blob/321740f7b25d803f881466ea819d870f7ed6a254/src/index.js
20349
20561
 
20350
20562
  const babelPluginInstrument = (api, {
@@ -21166,7 +21378,7 @@ const jsenvPluginBabel = ({
21166
21378
  const isSupported = feature => RUNTIME_COMPAT.isSupported(context.clientRuntimeCompat, feature);
21167
21379
  const getImportSpecifier = clientFileUrl => {
21168
21380
  const [reference] = context.referenceUtils.inject({
21169
- type: "js_import_export",
21381
+ type: "js_import",
21170
21382
  expectedType: "js_module",
21171
21383
  specifier: clientFileUrl
21172
21384
  });
@@ -21178,7 +21390,7 @@ const jsenvPluginBabel = ({
21178
21390
  isJsModule,
21179
21391
  getImportSpecifier
21180
21392
  });
21181
- if (context.scenarios.dev) {
21393
+ if (context.dev) {
21182
21394
  const requestHeaders = context.request.headers;
21183
21395
  if (requestHeaders["x-coverage-instanbul"]) {
21184
21396
  const coverageConfig = JSON.parse(requestHeaders["x-coverage-instanbul"]);
@@ -21248,16 +21460,19 @@ const jsenvPluginTopLevelAwait = () => {
21248
21460
  return {
21249
21461
  name: "jsenv:top_level_await",
21250
21462
  appliesDuring: "*",
21463
+ init: context => {
21464
+ if (context.isSupportedOnCurrentClients("top_level_await")) {
21465
+ return false;
21466
+ }
21467
+ // keep it untouched, systemjs will handle it
21468
+ const willTransformJsModules = !context.isSupportedOnCurrentClients("script_type_module") || !context.isSupportedOnCurrentClients("import_dynamic") || !context.isSupportedOnCurrentClients("import_meta");
21469
+ if (willTransformJsModules) {
21470
+ return false;
21471
+ }
21472
+ return true;
21473
+ },
21251
21474
  transformUrlContent: {
21252
- js_module: async (urlInfo, context) => {
21253
- if (context.isSupportedOnCurrentClients("top_level_await")) {
21254
- return null;
21255
- }
21256
- const willTransformJsModules = !context.isSupportedOnCurrentClients("script_type_module") || !context.isSupportedOnCurrentClients("import_dynamic") || !context.isSupportedOnCurrentClients("import_meta");
21257
- // keep it untouched, systemjs will handle it
21258
- if (willTransformJsModules) {
21259
- return null;
21260
- }
21475
+ js_module: async urlInfo => {
21261
21476
  const usesTLA = await usesTopLevelAwait(urlInfo);
21262
21477
  if (!usesTLA) {
21263
21478
  return null;
@@ -21275,7 +21490,7 @@ const jsenvPluginTopLevelAwait = () => {
21275
21490
  // externalHelpers: true,
21276
21491
  // externalHelpersPath: JSON.parse(
21277
21492
  // context.referenceUtils.inject({
21278
- // type: "js_import_export",
21493
+ // type: "js_import",
21279
21494
  // expectedType: "js_module",
21280
21495
  // specifier:
21281
21496
  // "babel-plugin-transform-async-to-promises/helpers.mjs",
@@ -21325,6 +21540,51 @@ const babelPluginMetadataUsesTopLevelAwait = () => {
21325
21540
  };
21326
21541
  };
21327
21542
 
21543
+ const jsenvPluginImportMetaResolve = () => {
21544
+ return {
21545
+ name: "jsenv:import_meta_resolve",
21546
+ appliesDuring: "*",
21547
+ init: context => {
21548
+ if (context.isSupportedOnCurrentClients("import_meta_resolve")) {
21549
+ return false;
21550
+ }
21551
+ const willTransformJsModules = !context.isSupportedOnCurrentClients("script_type_module") || !context.isSupportedOnCurrentClients("import_dynamic") || !context.isSupportedOnCurrentClients("import_meta");
21552
+ // keep it untouched, systemjs will handle it
21553
+ if (willTransformJsModules) {
21554
+ return false;
21555
+ }
21556
+ return true;
21557
+ },
21558
+ transformUrlContent: {
21559
+ js_module: async (urlInfo, context) => {
21560
+ const magicSource = createMagicSource(urlInfo.content);
21561
+ context.referenceUtils._references.forEach(ref => {
21562
+ if (ref.subtype === "import_meta_resolve") {
21563
+ const originalSpecifierLength = Buffer.byteLength(ref.specifier);
21564
+ const specifierLength = Buffer.byteLength(ref.generatedSpecifier.slice(1, -1) // remove `"` around
21565
+ );
21566
+
21567
+ const specifierLengthDiff = specifierLength - originalSpecifierLength;
21568
+ const end = ref.node.end + specifierLengthDiff;
21569
+ magicSource.replace({
21570
+ start: ref.node.start,
21571
+ end,
21572
+ replacement: `new URL(${ref.generatedSpecifier}, import.meta.url).href`
21573
+ });
21574
+ const currentLengthBeforeSpecifier = "import.meta.resolve(".length;
21575
+ const newLengthBeforeSpecifier = "new URL(".length;
21576
+ const lengthDiff = currentLengthBeforeSpecifier - newLengthBeforeSpecifier;
21577
+ ref.specifierColumn -= lengthDiff;
21578
+ ref.specifierStart -= lengthDiff;
21579
+ ref.specifierEnd = ref.specifierStart + Buffer.byteLength(ref.generatedSpecifier);
21580
+ }
21581
+ });
21582
+ return magicSource.toContentAndSourcemap();
21583
+ }
21584
+ }
21585
+ };
21586
+ };
21587
+
21328
21588
  /*
21329
21589
  * Transforms code to make it compatible with browser that would not be able to
21330
21590
  * run it otherwise. For instance:
@@ -21343,13 +21603,14 @@ const jsenvPluginTranspilation = ({
21343
21603
  jsClassicFallback = true,
21344
21604
  systemJsInjection = true,
21345
21605
  topLevelAwait = true,
21606
+ importMetaResolve = true,
21346
21607
  babelHelpersAsImport = true,
21347
21608
  getCustomBabelPlugins
21348
21609
  }) => {
21349
21610
  if (importAssertions === true) {
21350
21611
  importAssertions = {};
21351
21612
  }
21352
- return [...(importAssertions ? [jsenvPluginImportAssertions(importAssertions)] : []),
21613
+ return [...(importMetaResolve ? [jsenvPluginImportMetaResolve()] : []), ...(importAssertions ? [jsenvPluginImportAssertions(importAssertions)] : []),
21353
21614
  // babel also so that rollup can bundle babel helpers for instance
21354
21615
  jsenvPluginBabel({
21355
21616
  topLevelAwait,
@@ -21359,7 +21620,7 @@ const jsenvPluginTranspilation = ({
21359
21620
  jsClassicLibrary,
21360
21621
  jsClassicFallback,
21361
21622
  systemJsInjection
21362
- }),
21623
+ }), jsenvPluginAsJsModule(),
21363
21624
  // topLevelAwait must come after jsenvPluginAsJsClassic because it's related to the module format
21364
21625
  // so we want to wait to know the module format before transforming things related to top level await
21365
21626
  ...(topLevelAwait ? [jsenvPluginTopLevelAwait()] : []), ...(css ? [jsenvPluginCssParcel()] : [])];
@@ -21996,7 +22257,7 @@ const jsenvPluginImportMetaHot = () => {
21996
22257
  transformUrlContent: {
21997
22258
  html: (htmlUrlInfo, context) => {
21998
22259
  // during build we don't really care to parse html hot dependencies
21999
- if (context.scenarios.build) {
22260
+ if (context.build) {
22000
22261
  return;
22001
22262
  }
22002
22263
  const htmlAst = parseHtmlString(htmlUrlInfo.content);
@@ -22047,7 +22308,7 @@ const jsenvPluginImportMetaHot = () => {
22047
22308
  if (importMetaHotPaths.length === 0) {
22048
22309
  return null;
22049
22310
  }
22050
- if (context.scenarios.build) {
22311
+ if (context.build) {
22051
22312
  return removeImportMetaHots(urlInfo, importMetaHotPaths);
22052
22313
  }
22053
22314
  return injectImportMetaHot(urlInfo, context, importMetaHotClientFileUrl);
@@ -22074,7 +22335,7 @@ const removeImportMetaHots = (urlInfo, importMetaHotPaths) => {
22074
22335
  const injectImportMetaHot = (urlInfo, context, importMetaHotClientFileUrl) => {
22075
22336
  const [importMetaHotClientFileReference] = context.referenceUtils.inject({
22076
22337
  parentUrl: urlInfo.url,
22077
- type: "js_import_export",
22338
+ type: "js_import",
22078
22339
  expectedType: "js_module",
22079
22340
  specifier: importMetaHotClientFileUrl
22080
22341
  });
@@ -22496,7 +22757,7 @@ const jsenvPluginRibbon = ({
22496
22757
  specifier: ribbonClientFileUrl.href
22497
22758
  });
22498
22759
  const paramsJson = JSON.stringify({
22499
- text: context.scenarios.dev ? "DEV" : "BUILD"
22760
+ text: context.dev ? "DEV" : "BUILD"
22500
22761
  }, null, " ");
22501
22762
  const scriptNode = createHtmlNode({
22502
22763
  tagName: "script",
@@ -23053,9 +23314,7 @@ build ${entryPointKeys.length} entry points`);
23053
23314
  logLevel,
23054
23315
  rootDirectoryUrl,
23055
23316
  urlGraph: rawGraph,
23056
- scenarios: {
23057
- build: true
23058
- },
23317
+ build: true,
23059
23318
  runtimeCompat,
23060
23319
  plugins: [...plugins, {
23061
23320
  appliesDuring: "build",
@@ -23118,9 +23377,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23118
23377
  logLevel,
23119
23378
  rootDirectoryUrl: buildDirectoryUrl,
23120
23379
  urlGraph: finalGraph,
23121
- scenarios: {
23122
- build: true
23123
- },
23380
+ build: true,
23124
23381
  runtimeCompat,
23125
23382
  plugins: [urlAnalysisPlugin, jsenvPluginAsJsClassic({
23126
23383
  jsClassicLibrary: false,
@@ -23282,6 +23539,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23282
23539
  const generatedUrlObject = new URL(reference.generatedUrl);
23283
23540
  generatedUrlObject.searchParams.delete("as_js_classic");
23284
23541
  generatedUrlObject.searchParams.delete("as_js_classic_library");
23542
+ generatedUrlObject.searchParams.delete("as_js_module");
23285
23543
  generatedUrlObject.searchParams.delete("as_json_module");
23286
23544
  generatedUrlObject.searchParams.delete("as_css_module");
23287
23545
  generatedUrlObject.searchParams.delete("as_text_module");
@@ -23447,7 +23705,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23447
23705
  if (dependencyUrlInfo.type === "js_module") {
23448
23706
  // bundle inline script type module deps
23449
23707
  dependencyUrlInfo.references.forEach(inlineScriptRef => {
23450
- if (inlineScriptRef.type === "js_import_export") {
23708
+ if (inlineScriptRef.type === "js_import") {
23451
23709
  const inlineUrlInfo = rawGraph.getUrlInfo(inlineScriptRef.url);
23452
23710
  addToBundlerIfAny(inlineUrlInfo);
23453
23711
  }
@@ -23476,7 +23734,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23476
23734
  // For instance we will bundle service worker/workers detected like this
23477
23735
  if (rawUrlInfo.type === "js_module") {
23478
23736
  rawUrlInfo.references.forEach(reference => {
23479
- if (reference.type !== "js_url_specifier") {
23737
+ if (reference.type !== "js_url") {
23480
23738
  return;
23481
23739
  }
23482
23740
  const referencedUrlInfo = rawGraph.getUrlInfo(reference.url);
@@ -23489,7 +23747,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23489
23747
  const dependentUrlInfo = rawGraph.getUrlInfo(dependent);
23490
23748
  for (const reference of dependentUrlInfo.references) {
23491
23749
  if (reference.url === referencedUrlInfo.url) {
23492
- willAlreadyBeBundled = reference.type === "js_import_export" && reference.subtype === "import_dynamic" || reference.type === "script_src";
23750
+ willAlreadyBeBundled = reference.type === "js_import" && reference.subtype === "import_dynamic" || reference.type === "script_src";
23493
23751
  }
23494
23752
  }
23495
23753
  }
@@ -23681,7 +23939,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23681
23939
  // __v__() makes versioning dynamic: no need to take into account
23682
23940
  return null;
23683
23941
  }
23684
- if (reference.type === "js_url_specifier" || reference.subtype === "import_dynamic") {
23942
+ if (reference.type === "js_url" || reference.subtype === "import_dynamic") {
23685
23943
  // __v__() makes versioning dynamic: no need to take into account
23686
23944
  return null;
23687
23945
  }
@@ -23712,6 +23970,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23712
23970
  // this information is already hold into ".nomodule"
23713
23971
  buildUrlObject.searchParams.delete("as_js_classic");
23714
23972
  buildUrlObject.searchParams.delete("as_js_classic_library");
23973
+ buildUrlObject.searchParams.delete("as_js_module");
23715
23974
  buildUrlObject.searchParams.delete("as_json_module");
23716
23975
  buildUrlObject.searchParams.delete("as_css_module");
23717
23976
  buildUrlObject.searchParams.delete("as_text_module");
@@ -23733,9 +23992,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23733
23992
  logLevel: logger.level,
23734
23993
  rootDirectoryUrl: buildDirectoryUrl,
23735
23994
  urlGraph: finalGraph,
23736
- scenarios: {
23737
- build: true
23738
- },
23995
+ build: true,
23739
23996
  runtimeCompat,
23740
23997
  plugins: [urlAnalysisPlugin, jsenvPluginInline({
23741
23998
  fetchInlineUrls: false,
@@ -23802,7 +24059,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23802
24059
  usedVersionMappings.add(reference.specifier);
23803
24060
  return () => `${parentUrlInfo.jsQuote}+__v__(${JSON.stringify(reference.specifier)})+${parentUrlInfo.jsQuote}`;
23804
24061
  }
23805
- if (reference.type === "js_url_specifier" || reference.subtype === "import_dynamic") {
24062
+ if (reference.type === "js_url" || reference.subtype === "import_dynamic" || reference.subtype === "import_meta_resolve") {
23806
24063
  usedVersionMappings.add(reference.specifier);
23807
24064
  return () => `__v__(${JSON.stringify(reference.specifier)})`;
23808
24065
  }
@@ -24384,7 +24641,6 @@ const createFileService = ({
24384
24641
  serverStopCallbacks,
24385
24642
  serverEventsDispatcher,
24386
24643
  rootDirectoryUrl,
24387
- scenarios,
24388
24644
  runtimeCompat,
24389
24645
  plugins,
24390
24646
  urlAnalysis,
@@ -24483,7 +24739,7 @@ const createFileService = ({
24483
24739
  signal,
24484
24740
  logLevel,
24485
24741
  rootDirectoryUrl,
24486
- scenarios,
24742
+ dev: true,
24487
24743
  runtimeCompat,
24488
24744
  clientRuntimeCompat: {
24489
24745
  [runtimeName]: runtimeVersion
@@ -24508,7 +24764,7 @@ const createFileService = ({
24508
24764
  sourcemapsSourcesProtocol,
24509
24765
  sourcemapsSourcesContent,
24510
24766
  writeGeneratedFiles,
24511
- outDirectoryUrl: scenarios.dev ? `${rootDirectoryUrl}.jsenv/${runtimeName}@${runtimeVersion}/` : `${rootDirectoryUrl}.jsenv/build/${runtimeName}@${runtimeVersion}/`
24767
+ outDirectoryUrl: `${rootDirectoryUrl}.jsenv/${runtimeName}@${runtimeVersion}/`
24512
24768
  });
24513
24769
  urlGraph.createUrlInfoCallbackRef.current = urlInfo => {
24514
24770
  const {
@@ -24582,7 +24838,7 @@ const createFileService = ({
24582
24838
  allServerEvents[serverEventName]({
24583
24839
  rootDirectoryUrl,
24584
24840
  urlGraph,
24585
- scenarios,
24841
+ dev: true,
24586
24842
  sendServerEvent: data => {
24587
24843
  serverEventsDispatcher.dispatch({
24588
24844
  type: serverEventName,
@@ -24597,7 +24853,7 @@ const createFileService = ({
24597
24853
  }
24598
24854
  const context = {
24599
24855
  rootDirectoryUrl,
24600
- scenarios,
24856
+ dev: true,
24601
24857
  runtimeName,
24602
24858
  runtimeVersion,
24603
24859
  urlGraph,
@@ -24985,9 +25241,6 @@ const startDevServer = async ({
24985
25241
  serverStopCallbacks,
24986
25242
  serverEventsDispatcher,
24987
25243
  rootDirectoryUrl,
24988
- scenarios: {
24989
- dev: true
24990
- },
24991
25244
  runtimeCompat,
24992
25245
  plugins,
24993
25246
  urlAnalysis,