@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "29.7.1",
3
+ "version": "29.8.1",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -67,14 +67,14 @@
67
67
  "@c88/v8-coverage": "0.1.1",
68
68
  "@financial-times/polyfill-useragent-normaliser": "1.10.2",
69
69
  "@jsenv/abort": "4.2.4",
70
- "@jsenv/ast": "1.4.4",
71
- "@jsenv/babel-plugins": "1.0.9",
70
+ "@jsenv/ast": "1.4.5",
71
+ "@jsenv/babel-plugins": "1.0.10",
72
72
  "@jsenv/filesystem": "4.1.6",
73
73
  "@jsenv/importmap": "1.2.1",
74
74
  "@jsenv/integrity": "0.0.1",
75
75
  "@jsenv/log": "3.3.1",
76
76
  "@jsenv/node-esm-resolution": "0.2.0",
77
- "@jsenv/server": "14.1.9",
77
+ "@jsenv/server": "14.1.10",
78
78
  "@jsenv/sourcemap": "1.0.7",
79
79
  "@jsenv/uneval": "1.6.0",
80
80
  "@jsenv/url-meta": "7.0.0",
@@ -90,7 +90,7 @@
90
90
  "istanbul-reports": "3.1.5",
91
91
  "launch-editor": "2.6.0",
92
92
  "pidtree": "0.6.0",
93
- "rollup": "3.2.5",
93
+ "rollup": "3.3.0",
94
94
  "string-width": "5.1.2",
95
95
  "strip-ansi": "7.0.1",
96
96
  "terser": "5.15.1",
@@ -106,7 +106,7 @@
106
106
  "@jsenv/https-local": "3.0.1",
107
107
  "@jsenv/package-workspace": "0.5.0",
108
108
  "@jsenv/performance-impact": "3.0.1",
109
- "eslint": "8.26.0",
109
+ "eslint": "8.27.0",
110
110
  "eslint-plugin-html": "7.1.0",
111
111
  "eslint-plugin-import": "2.26.0",
112
112
  "eslint-plugin-react": "7.31.10",
@@ -229,7 +229,7 @@ build ${entryPointKeys.length} entry points`)
229
229
  logLevel,
230
230
  rootDirectoryUrl,
231
231
  urlGraph: rawGraph,
232
- scenarios: { build: true },
232
+ build: true,
233
233
  runtimeCompat,
234
234
  plugins: [
235
235
  ...plugins,
@@ -302,7 +302,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
302
302
  logLevel,
303
303
  rootDirectoryUrl: buildDirectoryUrl,
304
304
  urlGraph: finalGraph,
305
- scenarios: { build: true },
305
+ build: true,
306
306
  runtimeCompat,
307
307
  plugins: [
308
308
  urlAnalysisPlugin,
@@ -497,6 +497,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
497
497
  const generatedUrlObject = new URL(reference.generatedUrl)
498
498
  generatedUrlObject.searchParams.delete("as_js_classic")
499
499
  generatedUrlObject.searchParams.delete("as_js_classic_library")
500
+ generatedUrlObject.searchParams.delete("as_js_module")
500
501
  generatedUrlObject.searchParams.delete("as_json_module")
501
502
  generatedUrlObject.searchParams.delete("as_css_module")
502
503
  generatedUrlObject.searchParams.delete("as_text_module")
@@ -673,7 +674,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
673
674
  if (dependencyUrlInfo.type === "js_module") {
674
675
  // bundle inline script type module deps
675
676
  dependencyUrlInfo.references.forEach((inlineScriptRef) => {
676
- if (inlineScriptRef.type === "js_import_export") {
677
+ if (inlineScriptRef.type === "js_import") {
677
678
  const inlineUrlInfo = rawGraph.getUrlInfo(
678
679
  inlineScriptRef.url,
679
680
  )
@@ -709,7 +710,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
709
710
  // For instance we will bundle service worker/workers detected like this
710
711
  if (rawUrlInfo.type === "js_module") {
711
712
  rawUrlInfo.references.forEach((reference) => {
712
- if (reference.type !== "js_url_specifier") {
713
+ if (reference.type !== "js_url") {
713
714
  return
714
715
  }
715
716
  const referencedUrlInfo = rawGraph.getUrlInfo(reference.url)
@@ -724,7 +725,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
724
725
  for (const reference of dependentUrlInfo.references) {
725
726
  if (reference.url === referencedUrlInfo.url) {
726
727
  willAlreadyBeBundled =
727
- (reference.type === "js_import_export" &&
728
+ (reference.type === "js_import" &&
728
729
  reference.subtype === "import_dynamic") ||
729
730
  reference.type === "script_src"
730
731
  }
@@ -950,7 +951,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
950
951
  return null
951
952
  }
952
953
  if (
953
- reference.type === "js_url_specifier" ||
954
+ reference.type === "js_url" ||
954
955
  reference.subtype === "import_dynamic"
955
956
  ) {
956
957
  // __v__() makes versioning dynamic: no need to take into account
@@ -984,6 +985,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
984
985
  // this information is already hold into ".nomodule"
985
986
  buildUrlObject.searchParams.delete("as_js_classic")
986
987
  buildUrlObject.searchParams.delete("as_js_classic_library")
988
+ buildUrlObject.searchParams.delete("as_js_module")
987
989
  buildUrlObject.searchParams.delete("as_json_module")
988
990
  buildUrlObject.searchParams.delete("as_css_module")
989
991
  buildUrlObject.searchParams.delete("as_text_module")
@@ -1011,7 +1013,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
1011
1013
  logLevel: logger.level,
1012
1014
  rootDirectoryUrl: buildDirectoryUrl,
1013
1015
  urlGraph: finalGraph,
1014
- scenarios: { build: true },
1016
+ build: true,
1015
1017
  runtimeCompat,
1016
1018
  plugins: [
1017
1019
  urlAnalysisPlugin,
@@ -1099,8 +1101,9 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
1099
1101
  )})+${parentUrlInfo.jsQuote}`
1100
1102
  }
1101
1103
  if (
1102
- reference.type === "js_url_specifier" ||
1103
- reference.subtype === "import_dynamic"
1104
+ reference.type === "js_url" ||
1105
+ reference.subtype === "import_dynamic" ||
1106
+ reference.subtype === "import_meta_resolve"
1104
1107
  ) {
1105
1108
  usedVersionMappings.add(reference.specifier)
1106
1109
  return () => `__v__(${JSON.stringify(reference.specifier)})`
@@ -21,7 +21,6 @@ export const createFileService = ({
21
21
  serverEventsDispatcher,
22
22
 
23
23
  rootDirectoryUrl,
24
- scenarios,
25
24
  runtimeCompat,
26
25
 
27
26
  plugins,
@@ -116,7 +115,7 @@ export const createFileService = ({
116
115
  signal,
117
116
  logLevel,
118
117
  rootDirectoryUrl,
119
- scenarios,
118
+ dev: true,
120
119
  runtimeCompat,
121
120
  clientRuntimeCompat: {
122
121
  [runtimeName]: runtimeVersion,
@@ -146,9 +145,7 @@ export const createFileService = ({
146
145
  sourcemapsSourcesProtocol,
147
146
  sourcemapsSourcesContent,
148
147
  writeGeneratedFiles,
149
- outDirectoryUrl: scenarios.dev
150
- ? `${rootDirectoryUrl}.jsenv/${runtimeName}@${runtimeVersion}/`
151
- : `${rootDirectoryUrl}.jsenv/build/${runtimeName}@${runtimeVersion}/`,
148
+ outDirectoryUrl: `${rootDirectoryUrl}.jsenv/${runtimeName}@${runtimeVersion}/`,
152
149
  })
153
150
  urlGraph.createUrlInfoCallbackRef.current = (urlInfo) => {
154
151
  const { watch } = URL_META.applyAssociations({
@@ -218,7 +215,7 @@ export const createFileService = ({
218
215
  allServerEvents[serverEventName]({
219
216
  rootDirectoryUrl,
220
217
  urlGraph,
221
- scenarios,
218
+ dev: true,
222
219
  sendServerEvent: (data) => {
223
220
  serverEventsDispatcher.dispatch({
224
221
  type: serverEventName,
@@ -236,7 +233,7 @@ export const createFileService = ({
236
233
 
237
234
  const context = {
238
235
  rootDirectoryUrl,
239
- scenarios,
236
+ dev: true,
240
237
  runtimeName,
241
238
  runtimeVersion,
242
239
  urlGraph,
@@ -196,7 +196,6 @@ export const startDevServer = async ({
196
196
  serverEventsDispatcher,
197
197
 
198
198
  rootDirectoryUrl,
199
- scenarios: { dev: true },
200
199
  runtimeCompat,
201
200
 
202
201
  plugins,
@@ -1,4 +1,4 @@
1
- export const featureCompats = {
1
+ export const featuresCompatMap = {
2
2
  script_type_module: {
3
3
  edge: "16",
4
4
  firefox: "60",
@@ -29,6 +29,9 @@ export const featureCompats = {
29
29
  safari: "11.1",
30
30
  samsung: "9.2",
31
31
  },
32
+ import_meta_resolve: {
33
+ chrome: "107",
34
+ },
32
35
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
33
36
  import_dynamic: {
34
37
  android: "8",
@@ -1,9 +1,9 @@
1
1
  import { findHighestVersion } from "@jsenv/utils/src/semantic_versioning/highest_version.js"
2
2
 
3
- import { featureCompats } from "./features_compats.js"
3
+ import { featuresCompatMap } from "./features_compatibility.js"
4
4
 
5
5
  export const RUNTIME_COMPAT = {
6
- featureCompats,
6
+ featuresCompatMap,
7
7
 
8
8
  add: (originalRuntimeCompat, feature) => {
9
9
  const featureCompat = getFeatureCompat(feature)
@@ -41,7 +41,7 @@ export const RUNTIME_COMPAT = {
41
41
 
42
42
  const getFeatureCompat = (feature) => {
43
43
  if (typeof feature === "string") {
44
- const compat = featureCompats[feature]
44
+ const compat = featuresCompatMap[feature]
45
45
  if (!compat) {
46
46
  throw new Error(`"${feature}" feature is unknown`)
47
47
  }
@@ -28,14 +28,15 @@ export const createKitchen = ({
28
28
  logLevel,
29
29
 
30
30
  rootDirectoryUrl,
31
- scenarios,
31
+ dev = false,
32
+ build = false,
32
33
  runtimeCompat,
33
34
  // during dev/test clientRuntimeCompat is a single runtime
34
35
  // during build clientRuntimeCompat is runtimeCompat
35
36
  clientRuntimeCompat = runtimeCompat,
36
37
  urlGraph,
37
38
  plugins,
38
- sourcemaps = scenarios.dev ? "inline" : "none", // "programmatic" and "file" also allowed
39
+ sourcemaps = dev ? "inline" : "none", // "programmatic" and "file" also allowed
39
40
  sourcemapsSourcesProtocol,
40
41
  sourcemapsSourcesContent,
41
42
  sourcemapsSourcesRelative,
@@ -43,16 +44,13 @@ export const createKitchen = ({
43
44
  outDirectoryUrl,
44
45
  }) => {
45
46
  const logger = createLogger({ logLevel })
46
- const pluginController = createPluginController({
47
- plugins,
48
- scenarios,
49
- })
50
47
  const kitchenContext = {
51
48
  signal,
52
49
  logger,
53
50
  rootDirectoryUrl,
54
51
  urlGraph,
55
- scenarios,
52
+ dev,
53
+ build,
56
54
  runtimeCompat,
57
55
  clientRuntimeCompat,
58
56
  isSupportedOnCurrentClients: (feature) => {
@@ -64,7 +62,18 @@ export const createKitchen = ({
64
62
  sourcemaps,
65
63
  outDirectoryUrl,
66
64
  }
67
- pluginController.callHooks("init", kitchenContext)
65
+ const pluginController = createPluginController(kitchenContext)
66
+ const pushPlugins = (plugins) => {
67
+ plugins.forEach((pluginEntry) => {
68
+ if (Array.isArray(pluginEntry)) {
69
+ pushPlugins(pluginEntry)
70
+ } else {
71
+ pluginController.pushPlugin(pluginEntry)
72
+ }
73
+ })
74
+ }
75
+ pushPlugins(plugins)
76
+
68
77
  const createReference = ({
69
78
  data = {},
70
79
  node,
@@ -821,7 +830,7 @@ const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
821
830
  column: reference.specifierColumn,
822
831
  }
823
832
  urlInfo.contentType = reference.contentType
824
- urlInfo.originalContent = context.scenarios.build
833
+ urlInfo.originalContent = context.build
825
834
  ? urlInfo.originalContent === undefined
826
835
  ? reference.content
827
836
  : urlInfo.originalContent
@@ -87,6 +87,7 @@ export const createUrlInfoTransformer = ({
87
87
  // during build it's urlInfo.url to be inside the build
88
88
  // but otherwise it's generatedUrl to be inside .jsenv/ directory
89
89
  const generatedUrlObject = new URL(urlInfo.generatedUrl)
90
+ generatedUrlObject.searchParams.delete("as_js_module")
90
91
  generatedUrlObject.searchParams.delete("as_js_classic")
91
92
  generatedUrlObject.searchParams.delete("as_js_classic_library")
92
93
  const urlForSourcemap = generatedUrlObject.href
@@ -29,8 +29,8 @@ export const urlSpecifierEncoding = {
29
29
  },
30
30
  }
31
31
  const formatters = {
32
- "js_import_export": { encode: JSON.stringify, decode: JSON.parse },
33
- "js_url_specifier": { encode: JSON.stringify, decode: JSON.parse },
32
+ "js_import": { encode: JSON.stringify, decode: JSON.parse },
33
+ "js_url": { encode: JSON.stringify, decode: JSON.parse },
34
34
  "css_@import": { encode: JSON.stringify, decode: JSON.stringify },
35
35
  // https://github.com/webpack-contrib/css-loader/pull/627/files
36
36
  "css_url": {
@@ -297,9 +297,11 @@ const rollupPluginJsenv = ({
297
297
  const urlInfo = urlGraph.getUrlInfo(fileUrl)
298
298
  return {
299
299
  code: urlInfo.content,
300
- map: urlInfo.sourcemap
301
- ? sourcemapConverter.toFilePaths(urlInfo.sourcemap)
302
- : null,
300
+ map:
301
+ (sourcemaps === "file" || sourcemaps === "inline") &&
302
+ urlInfo.sourcemap
303
+ ? sourcemapConverter.toFilePaths(urlInfo.sourcemap)
304
+ : null,
303
305
  }
304
306
  },
305
307
  }
@@ -22,7 +22,7 @@ export const jsenvPluginCommonJsGlobals = () => {
22
22
  const isJsModule = urlInfo.type === "js_module"
23
23
  const replaceMap = {
24
24
  "process.env.NODE_ENV": `("${
25
- context.scenarios.dev ? "development" : "production"
25
+ context.dev ? "development" : "production"
26
26
  }")`,
27
27
  "global": "globalThis",
28
28
  "__filename": isJsModule
@@ -16,7 +16,7 @@ export const jsenvPluginImportMetaHot = () => {
16
16
  transformUrlContent: {
17
17
  html: (htmlUrlInfo, context) => {
18
18
  // during build we don't really care to parse html hot dependencies
19
- if (context.scenarios.build) {
19
+ if (context.build) {
20
20
  return
21
21
  }
22
22
  const htmlAst = parseHtmlString(htmlUrlInfo.content)
@@ -69,7 +69,7 @@ export const jsenvPluginImportMetaHot = () => {
69
69
  if (importMetaHotPaths.length === 0) {
70
70
  return null
71
71
  }
72
- if (context.scenarios.build) {
72
+ if (context.build) {
73
73
  return removeImportMetaHots(urlInfo, importMetaHotPaths)
74
74
  }
75
75
  return injectImportMetaHot(urlInfo, context, importMetaHotClientFileUrl)
@@ -97,7 +97,7 @@ const removeImportMetaHots = (urlInfo, importMetaHotPaths) => {
97
97
  const injectImportMetaHot = (urlInfo, context, importMetaHotClientFileUrl) => {
98
98
  const [importMetaHotClientFileReference] = context.referenceUtils.inject({
99
99
  parentUrl: urlInfo.url,
100
- type: "js_import_export",
100
+ type: "js_import",
101
101
  expectedType: "js_module",
102
102
  specifier: importMetaHotClientFileUrl,
103
103
  })
@@ -33,7 +33,7 @@ export const jsenvPluginImportMetaScenarios = () => {
33
33
  const replace = (path, value) => {
34
34
  replacements.push({ path, value })
35
35
  }
36
- if (context.scenarios.build) {
36
+ if (context.build) {
37
37
  // during build ensure replacement for tree-shaking
38
38
  dev.forEach((path) => {
39
39
  replace(path, "undefined")
@@ -58,7 +58,7 @@ export const jsenvPluginImportmap = () => {
58
58
  name: "jsenv:importmap",
59
59
  appliesDuring: "*",
60
60
  resolveUrl: {
61
- js_import_export: (reference) => {
61
+ js_import: (reference) => {
62
62
  if (!finalImportmap) {
63
63
  return null
64
64
  }
@@ -203,7 +203,7 @@ export const jsenvPluginImportmap = () => {
203
203
  // by "formatReferencedUrl" making the importmap presence useless.
204
204
  // In dev/test we keep importmap into the HTML to see it even if useless
205
205
  // Duing build we get rid of it
206
- if (context.scenarios.build) {
206
+ if (context.build) {
207
207
  removeHtmlNode(importmap)
208
208
  }
209
209
  return {
@@ -17,16 +17,33 @@ const HOOK_NAMES = [
17
17
  "destroy",
18
18
  ]
19
19
 
20
- export const createPluginController = ({ plugins, scenarios }) => {
21
- const flatPlugins = flattenAndFilterPlugins(plugins, { scenarios })
20
+ export const createPluginController = (kitchenContext) => {
21
+ const plugins = []
22
22
  // precompute a list of hooks per hookName for one major reason:
23
23
  // - When debugging, there is less iteration
24
24
  // also it should increase perf as there is less work to do
25
-
26
25
  const hookGroups = {}
27
26
  const addPlugin = (plugin, { position = "start" }) => {
27
+ if (plugin === null || typeof plugin !== "object") {
28
+ throw new TypeError(`plugin must be objects, got ${plugin}`)
29
+ }
30
+ if (!testAppliesDuring(plugin) || !initPlugin(plugin)) {
31
+ if (plugin.destroy) {
32
+ plugin.destroy()
33
+ }
34
+ return
35
+ }
36
+ if (!plugin.name) {
37
+ plugin.name = "anonymous"
38
+ }
39
+ plugins.push(plugin)
28
40
  Object.keys(plugin).forEach((key) => {
29
- if (key === "name" || key === "appliesDuring" || key === "serverEvents") {
41
+ if (
42
+ key === "name" ||
43
+ key === "appliesDuring" ||
44
+ key === "init" ||
45
+ key === "serverEvents"
46
+ ) {
30
47
  return
31
48
  }
32
49
  const isHook = HOOK_NAMES.includes(key)
@@ -50,15 +67,60 @@ export const createPluginController = ({ plugins, scenarios }) => {
50
67
  }
51
68
  })
52
69
  }
70
+ const testAppliesDuring = (plugin) => {
71
+ const { appliesDuring } = plugin
72
+ if (appliesDuring === undefined) {
73
+ // console.debug(`"appliesDuring" is undefined on ${pluginEntry.name}`)
74
+ return true
75
+ }
76
+ if (appliesDuring === "*") {
77
+ return true
78
+ }
79
+ if (typeof appliesDuring === "string") {
80
+ if (appliesDuring !== "dev" && appliesDuring !== "build") {
81
+ throw new TypeError(
82
+ `"appliesDuring" must be "dev" or "build", got ${appliesDuring}`,
83
+ )
84
+ }
85
+ if (kitchenContext[appliesDuring]) {
86
+ return true
87
+ }
88
+ return false
89
+ }
90
+ if (typeof appliesDuring === "object") {
91
+ for (const key of Object.keys(appliesDuring)) {
92
+ if (!appliesDuring[key] && kitchenContext[key]) {
93
+ return false
94
+ }
95
+ if (appliesDuring[key] && kitchenContext[key]) {
96
+ return true
97
+ }
98
+ }
99
+ // throw new Error(`"appliesDuring" is empty`)
100
+ return false
101
+ }
102
+ throw new TypeError(
103
+ `"appliesDuring" must be an object or a string, got ${appliesDuring}`,
104
+ )
105
+ }
106
+ const initPlugin = (plugin) => {
107
+ if (plugin.init) {
108
+ const initReturnValue = plugin.init(kitchenContext)
109
+ if (initReturnValue === false) {
110
+ return false
111
+ }
112
+ if (typeof initReturnValue === "function" && !plugin.destroy) {
113
+ plugin.destroy = initReturnValue
114
+ }
115
+ }
116
+ return true
117
+ }
53
118
  const pushPlugin = (plugin) => {
54
119
  addPlugin(plugin, { position: "start" })
55
120
  }
56
121
  const unshiftPlugin = (plugin) => {
57
122
  addPlugin(plugin, { position: "end" })
58
123
  }
59
- flatPlugins.forEach((plugin) => {
60
- pushPlugin(plugin)
61
- })
62
124
 
63
125
  let lastPluginUsed = null
64
126
  let currentPlugin = null
@@ -172,7 +234,7 @@ export const createPluginController = ({ plugins, scenarios }) => {
172
234
  }
173
235
 
174
236
  return {
175
- plugins: flatPlugins,
237
+ plugins,
176
238
  pushPlugin,
177
239
  unshiftPlugin,
178
240
  getHookFunction,
@@ -190,69 +252,6 @@ export const createPluginController = ({ plugins, scenarios }) => {
190
252
  }
191
253
  }
192
254
 
193
- const flattenAndFilterPlugins = (plugins, { scenarios }) => {
194
- const flatPlugins = []
195
- const visitPluginEntry = (pluginEntry) => {
196
- if (Array.isArray(pluginEntry)) {
197
- pluginEntry.forEach((value) => visitPluginEntry(value))
198
- return
199
- }
200
- if (typeof pluginEntry === "object" && pluginEntry !== null) {
201
- if (!pluginEntry.name) {
202
- pluginEntry.name = "anonymous"
203
- }
204
- const { appliesDuring } = pluginEntry
205
- if (appliesDuring === undefined) {
206
- // console.debug(`"appliesDuring" is undefined on ${pluginEntry.name}`)
207
- flatPlugins.push(pluginEntry)
208
- return
209
- }
210
- if (appliesDuring === "*") {
211
- flatPlugins.push(pluginEntry)
212
- return
213
- }
214
- if (typeof appliesDuring === "string") {
215
- if (!["dev", "build"].includes(appliesDuring)) {
216
- throw new Error(
217
- `"appliesDuring" must be "dev" or "build", got ${appliesDuring}`,
218
- )
219
- }
220
- if (scenarios[appliesDuring]) {
221
- flatPlugins.push(pluginEntry)
222
- return
223
- }
224
- return
225
- }
226
- if (typeof appliesDuring !== "object") {
227
- throw new Error(
228
- `"appliesDuring" must be an object or a string, got ${appliesDuring}`,
229
- )
230
- }
231
- let applies
232
- for (const key of Object.keys(appliesDuring)) {
233
- if (!appliesDuring[key] && scenarios[key]) {
234
- applies = false
235
- break
236
- }
237
- if (appliesDuring[key] && scenarios[key]) {
238
- applies = true
239
- }
240
- }
241
- if (applies) {
242
- flatPlugins.push(pluginEntry)
243
- return
244
- }
245
- if (pluginEntry.destroy) {
246
- pluginEntry.destroy()
247
- }
248
- return
249
- }
250
- throw new Error(`plugin must be objects, got ${pluginEntry}`)
251
- }
252
- plugins.forEach((plugin) => visitPluginEntry(plugin))
253
- return flatPlugins
254
- }
255
-
256
255
  const getHookFunction = (
257
256
  hook,
258
257
  // can be undefined, reference, or urlInfo
@@ -38,7 +38,7 @@ export const jsenvPluginRibbon = ({
38
38
  specifier: ribbonClientFileUrl.href,
39
39
  })
40
40
  const paramsJson = JSON.stringify(
41
- { text: context.scenarios.dev ? "DEV" : "BUILD" },
41
+ { text: context.dev ? "DEV" : "BUILD" },
42
42
  null,
43
43
  " ",
44
44
  )
@@ -302,7 +302,7 @@ export const jsenvPluginSupervisor = ({
302
302
  })
303
303
  const [scriptTypeModuleSupervisorFileReference] =
304
304
  context.referenceUtils.inject({
305
- type: "js_import_export",
305
+ type: "js_import",
306
306
  expectedType: "js_module",
307
307
  specifier: scriptTypeModuleSupervisorFileUrl,
308
308
  })
@@ -25,7 +25,7 @@ export const jsenvPluginToolbar = ({ logs = false } = {}) => {
25
25
  }
26
26
  const htmlAst = parseHtmlString(content)
27
27
  const [toolbarInjectorReference] = referenceUtils.inject({
28
- type: "js_import_export",
28
+ type: "js_import",
29
29
  expectedType: "js_module",
30
30
  specifier: toolbarInjectorClientFileUrl,
31
31
  })
@@ -428,7 +428,7 @@
428
428
  const createMeta = (url) => {
429
429
  return {
430
430
  url,
431
- resolve: (id, parentUrl) => resolveUrl(id, parentUrl),
431
+ resolve: (id) => resolveUrl(id, url),
432
432
  }
433
433
  }
434
434
 
@@ -9,6 +9,7 @@ import { applyBabelPlugins } from "@jsenv/ast"
9
9
  import { requireFromJsenv } from "@jsenv/core/src/require_from_jsenv.js"
10
10
  import { requireBabelPlugin } from "../babel/require_babel_plugin.js"
11
11
  import { babelPluginTransformImportMetaUrl } from "./helpers/babel_plugin_transform_import_meta_url.js"
12
+ import { babelPluginTransformImportMetaResolve } from "./helpers/babel_plugin_transform_import_meta_resolve.js"
12
13
 
13
14
  // import { jsenvPluginAsJsClassicLibrary } from "./jsenv_plugin_as_js_classic_library.js"
14
15
  // because of https://github.com/rpetrich/babel-plugin-transform-async-to-promises/issues/84
@@ -58,6 +59,7 @@ export const convertJsModuleToJsClassic = async ({
58
59
  },
59
60
  ],
60
61
  babelPluginTransformImportMetaUrl,
62
+ babelPluginTransformImportMetaResolve,
61
63
  requireFromJsenv("@babel/plugin-transform-modules-umd"),
62
64
  ]),
63
65
  ],
@@ -0,0 +1,26 @@
1
+ export const babelPluginTransformImportMetaResolve = () => {
2
+ return {
3
+ name: "transform-import-meta-resolve",
4
+ visitor: {
5
+ Program: (programPath) => {
6
+ programPath.traverse({
7
+ MemberExpression: (path) => {
8
+ const node = path.node
9
+ if (
10
+ node.object.type === "MetaProperty" &&
11
+ node.object.property.name === "meta" &&
12
+ node.property.name === "resolve"
13
+ ) {
14
+ const firstArg = node.arguments[0]
15
+ if (firstArg && firstArg.type === "StringLiteral") {
16
+ path.replaceWithSourceString(
17
+ `new URL(${firstArg.value}, document.currentScript.src).href`,
18
+ )
19
+ }
20
+ }
21
+ },
22
+ })
23
+ },
24
+ },
25
+ }
26
+ }