@jsenv/core 27.0.0-alpha.64 → 27.0.0-alpha.65

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 (146) hide show
  1. package/dist/html/explorer.html +557 -0
  2. package/dist/js/controllable_file.mjs +227 -0
  3. package/dist/{event_source_client.js → js/event_source_client.js} +19 -244
  4. package/dist/js/global_this.js +32 -0
  5. package/dist/js/html_supervisor_installer.js +522 -0
  6. package/dist/js/html_supervisor_setup.js +79 -0
  7. package/dist/{import_meta_hot.js → js/import_meta_hot.js} +1 -3
  8. package/dist/js/inline_content.js +8 -0
  9. package/dist/js/new_stylesheet.js +409 -0
  10. package/dist/js/regenerator_runtime.js +721 -0
  11. package/dist/js/s.js +429 -0
  12. package/dist/main.js +13362 -0
  13. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/AsyncGenerator/AsyncGenerator.js +95 -0
  14. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/AwaitValue/AwaitValue.js +3 -0
  15. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/applyDecoratorDescriptor/applyDecoratorDescriptor.js +29 -0
  16. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +9 -0
  17. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/arrayWithHoles/arrayWithHoles.js +4 -0
  18. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +5 -0
  19. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/assertThisInitialized/assertThisInitialized.js +8 -0
  20. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +52 -0
  21. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/asyncIterator/asyncIterator.js +78 -0
  22. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/asyncToGenerator/asyncToGenerator.js +39 -0
  23. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +4 -0
  24. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +24 -0
  25. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +7 -0
  26. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +14 -0
  27. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classCallCheck/classCallCheck.js +5 -0
  28. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -0
  29. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -0
  30. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +8 -0
  31. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classNameTDZError/classNameTDZError.js +4 -0
  32. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +6 -0
  33. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +6 -0
  34. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +7 -0
  35. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -0
  36. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +7 -0
  37. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +7 -0
  38. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +3 -0
  39. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +8 -0
  40. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +9 -0
  41. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +5 -0
  42. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -0
  43. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/construct/construct.js +15 -0
  44. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createClass/createClass.js +18 -0
  45. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +63 -0
  46. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +22 -0
  47. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createRawReactElement/createRawReactElement.js +50 -0
  48. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createSuper/createSuper.js +22 -0
  49. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/decorate/decorate.js +622 -0
  50. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/defaults/defaults.js +14 -0
  51. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +26 -0
  52. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/defineProperty/defineProperty.js +19 -0
  53. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/extends/extends.js +16 -0
  54. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/get/get.js +21 -0
  55. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/getPrototypeOf/getPrototypeOf.js +2 -0
  56. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/inherits/inherits.js +21 -0
  57. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/inheritsLoose/inheritsLoose.js +6 -0
  58. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +10 -0
  59. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +3 -0
  60. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/instanceof/instanceof.js +7 -0
  61. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/interopRequireDefault/interopRequireDefault.js +5 -0
  62. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +49 -0
  63. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/isNativeFunction/isNativeFunction.js +4 -0
  64. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -0
  65. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/iterableToArray/iterableToArray.js +3 -0
  66. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +38 -0
  67. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +13 -0
  68. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/jsx/jsx.js +49 -0
  69. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/maybeArrayLike/maybeArrayLike.js +10 -0
  70. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/newArrowCheck/newArrowCheck.js +5 -0
  71. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/nonIterableRest/nonIterableRest.js +3 -0
  72. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/nonIterableSpread/nonIterableSpread.js +3 -0
  73. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -0
  74. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectSpread/objectSpread.js +22 -0
  75. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectSpread2/objectSpread2.js +41 -0
  76. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +20 -0
  77. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +15 -0
  78. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +10 -0
  79. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/readOnlyError/readOnlyError.js +4 -0
  80. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/readme.md +8 -0
  81. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/set/set.js +51 -0
  82. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/setPrototypeOf/setPrototypeOf.js +5 -0
  83. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -0
  84. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/slicedToArray/slicedToArray.js +5 -0
  85. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +7 -0
  86. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/superPropBase/superPropBase.js +10 -0
  87. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +11 -0
  88. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +8 -0
  89. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/tdz/tdz.js +4 -0
  90. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/temporalRef/temporalRef.js +5 -0
  91. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/temporalUndefined/temporalUndefined.js +3 -0
  92. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/toArray/toArray.js +5 -0
  93. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/toConsumableArray/toConsumableArray.js +5 -0
  94. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/toPrimitive/toPrimitive.js +14 -0
  95. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/toPropertyKey/toPropertyKey.js +5 -0
  96. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/typeof/typeof.js +7 -0
  97. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +10 -0
  98. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +7 -0
  99. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +35 -0
  100. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/wrapRegExp/wrapRegExp.js +67 -0
  101. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/writeOnlyError/writeOnlyError.js +4 -0
  102. package/dist/other/jsenv.png +0 -0
  103. package/package.json +15 -11
  104. package/src/build/build.js +152 -67
  105. package/src/build/build_urls_generator.js +18 -2
  106. package/src/build/inject_service_worker_urls.js +1 -1
  107. package/src/build/resync_ressource_hints.js +56 -9
  108. package/src/dev/plugins/explorer/client/explorer.html +1 -1
  109. package/src/dev/start_dev_server.js +17 -3
  110. package/src/execute/execute.js +3 -0
  111. package/src/omega/errors.js +10 -7
  112. package/src/omega/kitchen.js +209 -216
  113. package/src/omega/url_graph/url_graph_report.js +2 -2
  114. package/src/omega/url_graph.js +1 -1
  115. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +5 -10
  116. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +1 -3
  117. package/src/plugins/bundling/js_module/bundle_js_module.js +66 -24
  118. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +171 -53
  119. package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +9 -13
  120. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +6 -6
  121. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +5 -10
  122. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +12 -2
  123. package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +12 -0
  124. package/src/plugins/plugin_controller.js +17 -3
  125. package/src/plugins/plugins.js +16 -19
  126. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +7 -13
  127. package/src/plugins/transpilation/as_js_classic/{jsenv_plugin_script_type_module_as_classic.js → jsenv_plugin_as_js_classic_html.js} +0 -0
  128. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +1 -2
  129. package/src/plugins/url_analysis/html/html_urls.js +3 -0
  130. package/src/plugins/url_analysis/js/js_urls.js +2 -1
  131. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +87 -1
  132. package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +3 -0
  133. package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +0 -3
  134. package/src/test/execute_plan.js +2 -0
  135. package/dist/event_source_client.js.map +0 -188
  136. package/dist/html_supervisor_installer.js +0 -1236
  137. package/dist/html_supervisor_installer.js.map +0 -337
  138. package/dist/html_supervisor_setup.js +0 -95
  139. package/dist/html_supervisor_setup.js.map +0 -57
  140. package/dist/import_meta_hot.js.map +0 -42
  141. package/dist/s.js +0 -626
  142. package/dist/s.js.map +0 -207
  143. package/src/jsenv_root_directory_url.js +0 -1
  144. package/src/omega/compat/default_runtime_compat.js +0 -11
  145. package/src/plugins/filesystem_magic/jsenv_plugin_filesystem_magic.js +0 -61
  146. package/src/plugins/transpilation/babel/new_stylesheet/client/.eslintrc.cjs +0 -24
@@ -1,18 +1,26 @@
1
+ import { pathToFileURL } from "node:url"
1
2
  import {
2
3
  isFileSystemPath,
3
4
  normalizeStructuredMetaMap,
4
- urlIsInsideOf,
5
5
  urlToMeta,
6
6
  } from "@jsenv/filesystem"
7
7
  import { createDetailedMessage } from "@jsenv/logger"
8
8
 
9
+ import { babelHelperNameFromUrl } from "@jsenv/babel-plugins"
9
10
  import { applyRollupPlugins } from "@jsenv/utils/js_ast/apply_rollup_plugins.js"
10
11
  import { sourcemapConverter } from "@jsenv/utils/sourcemap/sourcemap_converter.js"
11
12
  import { fileUrlConverter } from "@jsenv/core/src/omega/file_url_converter.js"
12
- import { babelHelperNameFromUrl } from "@jsenv/babel-plugins"
13
13
 
14
- const jsenvBabelPluginDirectoryUrl = new URL(
15
- "../../transpilation/babel/",
14
+ const globalThisClientFileUrl = new URL(
15
+ "../../transpilation/babel/global_this/client/global_this.js",
16
+ import.meta.url,
17
+ ).href
18
+ const newStylesheetClientFileUrl = new URL(
19
+ "../../transpilation/babel/new_stylesheet/client/new_stylesheet.js",
20
+ import.meta.url,
21
+ ).href
22
+ const regeneratorRuntimeClientFileUrl = new URL(
23
+ "../../transpilation/babel/regenerator_runtime/client/regenerator_runtime.js",
16
24
  import.meta.url,
17
25
  ).href
18
26
 
@@ -30,6 +38,7 @@ export const bundleJsModule = async ({
30
38
  runtimeCompat,
31
39
  sourcemaps,
32
40
  } = context
41
+ const { babelHelpersChunk = true, include } = options
33
42
  const { jsModuleBundleUrlInfos } = await buildWithRollup({
34
43
  signal,
35
44
  logger,
@@ -40,7 +49,9 @@ export const bundleJsModule = async ({
40
49
 
41
50
  runtimeCompat,
42
51
  sourcemaps,
43
- options,
52
+
53
+ include,
54
+ babelHelpersChunk,
44
55
  })
45
56
  return jsModuleBundleUrlInfos
46
57
  }
@@ -55,7 +66,9 @@ export const buildWithRollup = async ({
55
66
 
56
67
  runtimeCompat,
57
68
  sourcemaps,
58
- options,
69
+
70
+ include,
71
+ babelHelpersChunk,
59
72
  }) => {
60
73
  const resultRef = { current: null }
61
74
  try {
@@ -71,7 +84,8 @@ export const buildWithRollup = async ({
71
84
 
72
85
  runtimeCompat,
73
86
  sourcemaps,
74
- options,
87
+ include,
88
+ babelHelpersChunk,
75
89
  resultRef,
76
90
  }),
77
91
  ],
@@ -81,6 +95,16 @@ export const buildWithRollup = async ({
81
95
  if (warning.code === "CIRCULAR_DEPENDENCY") {
82
96
  return
83
97
  }
98
+ if (
99
+ warning.code === "THIS_IS_UNDEFINED" &&
100
+ pathToFileURL(warning.id).href === globalThisClientFileUrl
101
+ ) {
102
+ return
103
+ }
104
+ if (warning.code === "EVAL") {
105
+ // ideally we should disable only for jsenv files
106
+ return
107
+ }
84
108
  logger.warn(String(warning))
85
109
  },
86
110
  },
@@ -104,7 +128,9 @@ const rollupPluginJsenv = ({
104
128
  urlGraph,
105
129
  jsModuleUrlInfos,
106
130
  sourcemaps,
107
- options,
131
+
132
+ include,
133
+ babelHelpersChunk,
108
134
 
109
135
  resultRef,
110
136
  }) => {
@@ -118,10 +144,10 @@ const rollupPluginJsenv = ({
118
144
  })
119
145
  }
120
146
  let importCanBeBundled = () => true
121
- if (options.include) {
147
+ if (include) {
122
148
  const bundleIncludeConfig = normalizeStructuredMetaMap(
123
149
  {
124
- bundle: options.include,
150
+ bundle: include,
125
151
  },
126
152
  rootDirectoryUrl,
127
153
  )
@@ -152,7 +178,7 @@ const rollupPluginJsenv = ({
152
178
  implicitlyLoadedAfterOneOf: previousNonEntryPointModuleId
153
179
  ? [previousNonEntryPointModuleId]
154
180
  : null,
155
- preserveSignature: "allow-extension",
181
+ // preserveSignature: "allow-extension",
156
182
  })
157
183
  previousNonEntryPointModuleId = id
158
184
  })
@@ -224,19 +250,27 @@ const rollupPluginJsenv = ({
224
250
  return insideJs ? `js/${name}` : `${name}`
225
251
  },
226
252
  manualChunks: (id) => {
227
- const fileUrl = fileUrlConverter.asFileUrl(id)
228
- if (
229
- fileUrl.endsWith(
230
- "babel-plugin-transform-async-to-promises/helpers.mjs",
231
- )
232
- ) {
233
- return "babel_helpers"
234
- }
235
- if (babelHelperNameFromUrl(fileUrl)) {
236
- return "babel_helpers"
237
- }
238
- if (urlIsInsideOf(fileUrl, jsenvBabelPluginDirectoryUrl)) {
239
- return "babel_helpers"
253
+ if (babelHelpersChunk) {
254
+ const fileUrl = fileUrlConverter.asFileUrl(id)
255
+ if (
256
+ fileUrl.endsWith(
257
+ "babel-plugin-transform-async-to-promises/helpers.mjs",
258
+ )
259
+ ) {
260
+ return "babel_helpers"
261
+ }
262
+ if (babelHelperNameFromUrl(fileUrl)) {
263
+ return "babel_helpers"
264
+ }
265
+ if (fileUrl === globalThisClientFileUrl) {
266
+ return "babel_helpers"
267
+ }
268
+ if (fileUrl === newStylesheetClientFileUrl) {
269
+ return "babel_helpers"
270
+ }
271
+ if (fileUrl === regeneratorRuntimeClientFileUrl) {
272
+ return "babel_helpers"
273
+ }
240
274
  }
241
275
  return null
242
276
  },
@@ -261,6 +295,14 @@ const rollupPluginJsenv = ({
261
295
  if (!importCanBeBundled(url)) {
262
296
  return { id: url, external: true }
263
297
  }
298
+ const urlInfo = urlGraph.getUrlInfo(url)
299
+ if (!urlInfo) {
300
+ // happen when excluded by urlAnalysis.include
301
+ return { id: url, external: true }
302
+ }
303
+ if (!urlInfo.shouldHandle) {
304
+ return { id: url, external: true }
305
+ }
264
306
  const filePath = fileUrlConverter.asFilePath(url)
265
307
  return filePath
266
308
  },
@@ -1,66 +1,184 @@
1
- import { readFileSync } from "node:fs"
2
- import { urlIsInsideOf, urlToRelativeUrl } from "@jsenv/filesystem"
1
+ import { readFileSync, readdirSync, realpathSync, statSync } from "node:fs"
2
+ import { pathToFileURL } from "node:url"
3
+ import {
4
+ urlIsInsideOf,
5
+ urlToRelativeUrl,
6
+ urlToExtension,
7
+ } from "@jsenv/filesystem"
3
8
 
9
+ import { applyFileSystemMagicResolution } from "@jsenv/node-esm-resolution"
10
+ import { ensurePathnameTrailingSlash } from "@jsenv/utils/urls/url_utils.js"
4
11
  import { CONTENT_TYPE } from "@jsenv/utils/content_type/content_type.js"
5
12
 
6
- export const jsenvPluginFileUrls = () => {
7
- return [jsenvPluginResolveAbsoluteFileUrls(), jsenvPluginFetchFileUrls()]
8
- }
13
+ export const jsenvPluginFileUrls = ({
14
+ magicExtensions = ["inherit", ".js"],
15
+ magicDirectoryIndex = true,
16
+ preservesSymlink = true,
17
+ directoryReferenceAllowed = false,
18
+ }) => {
19
+ const getExtensionsToTry = (magicExtensions, importer) => {
20
+ const extensionsSet = new Set()
21
+ magicExtensions.forEach((magicExtension) => {
22
+ if (magicExtension === "inherit") {
23
+ const importerExtension = urlToExtension(importer)
24
+ extensionsSet.add(importerExtension)
25
+ } else {
26
+ extensionsSet.add(magicExtension)
27
+ }
28
+ })
29
+ return Array.from(extensionsSet.values())
30
+ }
31
+
32
+ return [
33
+ {
34
+ name: "jsenv:file_url_resolution",
35
+ appliesDuring: "*",
36
+ redirectUrl: (reference) => {
37
+ // http, https, data, about, ...
38
+ if (!reference.url.startsWith("file:")) {
39
+ return null
40
+ }
41
+ if (reference.isInline) {
42
+ return null
43
+ }
44
+ const urlObject = new URL(reference.url)
45
+ let stat
46
+ try {
47
+ stat = statSync(urlObject)
48
+ } catch (e) {
49
+ if (e.code === "ENOENT") {
50
+ stat = null
51
+ } else {
52
+ throw e
53
+ }
54
+ }
55
+ const { search, hash } = urlObject
56
+ const resolveSymlink = (fileUrl) => {
57
+ const realPath = realpathSync(new URL(fileUrl))
58
+ const realFileUrl = `${pathToFileURL(realPath)}${search}${hash}`
59
+ return realFileUrl
60
+ }
9
61
 
10
- const jsenvPluginResolveAbsoluteFileUrls = () => {
11
- return {
12
- name: "jsenv:resolve_absolute_file_urls",
13
- appliesDuring: {
14
- // during dev and test it's a browser running the code
15
- // so absolute file urls needs to be relativized
16
- dev: true,
17
- test: true,
18
- // during build it's fine to use file:// urls
19
- build: false,
62
+ let { pathname } = urlObject
63
+ const pathnameUsesTrailingSlash = pathname.endsWith("/")
64
+ urlObject.search = ""
65
+ urlObject.hash = ""
66
+ // force trailing slash on directories and remove eventual trailing slash on files
67
+ if (stat && stat.isDirectory()) {
68
+ reference.expectedType = "directory"
69
+ if (!pathnameUsesTrailingSlash) {
70
+ urlObject.pathname = `${pathname}/`
71
+ }
72
+ if (directoryReferenceAllowed) {
73
+ return preservesSymlink
74
+ ? urlObject.href
75
+ : resolveSymlink(urlObject.href)
76
+ }
77
+ // give a chane to magic resolution if enabled
78
+ } else if (pathnameUsesTrailingSlash) {
79
+ // a warning would be great because it's strange to reference a file with a trailing slash
80
+ urlObject.pathname = pathname.slice(0, -1)
81
+ }
82
+ const url = urlObject.href
83
+ const filesystemResolution = applyFileSystemMagicResolution(url, {
84
+ fileStat: stat,
85
+ magicDirectoryIndex,
86
+ magicExtensions: getExtensionsToTry(
87
+ magicExtensions,
88
+ reference.parentUrl,
89
+ ),
90
+ })
91
+ if (!filesystemResolution.found) {
92
+ return null
93
+ }
94
+ const fileUrlRaw = filesystemResolution.url
95
+ const fileUrl = `${fileUrlRaw}${search}${hash}`
96
+ return preservesSymlink ? fileUrl : resolveSymlink(fileUrl)
97
+ },
20
98
  },
21
- resolveUrl: (reference) => {
22
- if (!reference.specifier.startsWith("/@fs/")) {
23
- return null
24
- }
25
- const fsRootRelativeUrl = reference.specifier.slice("/@fs/".length)
26
- return `file:///${fsRootRelativeUrl}`
99
+ {
100
+ name: "jsenv:filesystem_resolution",
101
+ appliesDuring: "*",
102
+ resolveUrl: {
103
+ filesystem: (reference, context) => {
104
+ const { parentUrl } = reference
105
+ const parentUrlInfo = context.urlGraph.getUrlInfo(parentUrl)
106
+ const baseUrl =
107
+ parentUrlInfo && parentUrlInfo.type === "directory"
108
+ ? ensurePathnameTrailingSlash(parentUrl)
109
+ : parentUrl
110
+ return new URL(reference.specifier, baseUrl).href
111
+ },
112
+ },
27
113
  },
28
- formatUrl: (reference, context) => {
29
- if (!reference.generatedUrl.startsWith("file:")) {
114
+ {
115
+ name: "jsenv:@fs_resolution",
116
+ appliesDuring: {
117
+ // during dev and test it's a browser running the code
118
+ // so absolute file urls needs to be relativized
119
+ dev: true,
120
+ test: true,
121
+ // during build it's fine to use file:// urls
122
+ build: false,
123
+ },
124
+ resolveUrl: (reference) => {
125
+ if (reference.specifier.startsWith("/@fs/")) {
126
+ const fsRootRelativeUrl = reference.specifier.slice("/@fs/".length)
127
+ return `file:///${fsRootRelativeUrl}`
128
+ }
30
129
  return null
31
- }
32
- if (urlIsInsideOf(reference.generatedUrl, context.rootDirectoryUrl)) {
33
- return `/${urlToRelativeUrl(
34
- reference.generatedUrl,
35
- context.rootDirectoryUrl,
36
- )}`
37
- }
38
- return `/@fs/${reference.generatedUrl.slice("file:///".length)}`
130
+ },
131
+ formatUrl: (reference, context) => {
132
+ if (!reference.generatedUrl.startsWith("file:")) {
133
+ return null
134
+ }
135
+ if (urlIsInsideOf(reference.generatedUrl, context.rootDirectoryUrl)) {
136
+ return `/${urlToRelativeUrl(
137
+ reference.generatedUrl,
138
+ context.rootDirectoryUrl,
139
+ )}`
140
+ }
141
+ return `/@fs/${reference.generatedUrl.slice("file:///".length)}`
142
+ },
39
143
  },
40
- }
41
- }
42
-
43
- const jsenvPluginFetchFileUrls = () => {
44
- return {
45
- name: "jsenv:fetch_file_urls",
46
- appliesDuring: "*",
47
- fetchUrlContent: (urlInfo) => {
48
- if (!urlInfo.url.startsWith("file:")) {
49
- return null
50
- }
51
- const urlObject = new URL(urlInfo.url)
52
- const fileBuffer = readFileSync(urlObject)
53
- const contentType = CONTENT_TYPE.fromUrlExtension(urlInfo.url)
54
- if (CONTENT_TYPE.isTextual(contentType)) {
144
+ {
145
+ name: "jsenv:file_url_fetching",
146
+ appliesDuring: "*",
147
+ fetchUrlContent: (urlInfo, context) => {
148
+ if (!urlInfo.url.startsWith("file:")) {
149
+ return null
150
+ }
151
+ const urlObject = new URL(urlInfo.url)
152
+ if (context.reference.expectedType === "directory") {
153
+ if (directoryReferenceAllowed) {
154
+ const directoryEntries = readdirSync(urlObject)
155
+ return {
156
+ type: "directory",
157
+ contentType: "application/json",
158
+ content: JSON.stringify(directoryEntries, null, " "),
159
+ filename: urlToRelativeUrl(
160
+ ensurePathnameTrailingSlash(urlInfo.url),
161
+ context.rootDirectoryUrl,
162
+ ),
163
+ }
164
+ }
165
+ const error = new Error("found a directory on filesystem")
166
+ error.code = "EISDIR"
167
+ throw error
168
+ }
169
+ const fileBuffer = readFileSync(urlObject)
170
+ const contentType = CONTENT_TYPE.fromUrlExtension(urlInfo.url)
171
+ if (CONTENT_TYPE.isTextual(contentType)) {
172
+ return {
173
+ contentType,
174
+ content: String(fileBuffer),
175
+ }
176
+ }
55
177
  return {
56
178
  contentType,
57
- content: String(fileBuffer),
179
+ content: fileBuffer,
58
180
  }
59
- }
60
- return {
61
- contentType,
62
- content: fileBuffer,
63
- }
181
+ },
64
182
  },
65
- }
183
+ ]
66
184
  }
@@ -4,8 +4,6 @@
4
4
  * - scripts are wrapped to be supervised
5
5
  */
6
6
 
7
- import { urlIsInsideOf } from "@jsenv/filesystem"
8
-
9
7
  import {
10
8
  parseHtmlString,
11
9
  stringifyHtmlAst,
@@ -21,22 +19,20 @@ import {
21
19
  setHtmlNodeGeneratedText,
22
20
  } from "@jsenv/utils/html_ast/html_ast.js"
23
21
  import { generateInlineContentUrl } from "@jsenv/utils/urls/inline_content_url_generator.js"
24
- import { jsenvRootDirectoryUrl } from "@jsenv/core/src/jsenv_root_directory_url.js"
25
22
 
26
23
  export const jsenvPluginHtmlSupervisor = ({
27
- rootDirectoryUrl,
28
24
  logs = false,
29
25
  measurePerf = false,
30
26
  }) => {
31
- const preferSourceFiles =
32
- rootDirectoryUrl === jsenvRootDirectoryUrl ||
33
- urlIsInsideOf(rootDirectoryUrl, jsenvRootDirectoryUrl)
34
- const htmlSupervisorSetupFileUrl = preferSourceFiles
35
- ? new URL("./client/html_supervisor_setup.js", import.meta.url).href
36
- : new URL("./dist/html_supervisor_setup.js", jsenvRootDirectoryUrl).href
37
- const htmlSupervisorInstallerFileUrl = preferSourceFiles
38
- ? new URL("./client/html_supervisor_installer.js", import.meta.url).href
39
- : new URL("./dist/html_supervisor_installer.js", jsenvRootDirectoryUrl).href
27
+ const htmlSupervisorSetupFileUrl = new URL(
28
+ "./client/html_supervisor_setup.js?js_classic",
29
+ import.meta.url,
30
+ ).href
31
+
32
+ const htmlSupervisorInstallerFileUrl = new URL(
33
+ "./client/html_supervisor_installer.js",
34
+ import.meta.url,
35
+ ).href
40
36
 
41
37
  return {
42
38
  name: "jsenv:html_supervisor",
@@ -2,11 +2,11 @@ export const jsenvPluginHttpUrls = () => {
2
2
  return {
3
3
  name: "jsenv:http_urls",
4
4
  appliesDuring: "*",
5
- fetchUrlContent: (urlInfo) => {
6
- if (urlInfo.url.startsWith("http") || urlInfo.url.startsWith("https")) {
7
- return { external: true }
8
- }
9
- return null
10
- },
5
+ // fetchUrlContent: (urlInfo) => {
6
+ // if (urlInfo.url.startsWith("http") || urlInfo.url.startsWith("https")) {
7
+ // return { shouldHandle: false }
8
+ // }
9
+ // return null
10
+ // },
11
11
  }
12
12
  }
@@ -1,19 +1,14 @@
1
- import { urlIsInsideOf } from "@jsenv/filesystem"
2
-
3
1
  import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
4
2
  import { parseHtmlString } from "@jsenv/utils/html_ast/html_ast.js"
5
3
  import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
6
- import { jsenvRootDirectoryUrl } from "@jsenv/core/src/jsenv_root_directory_url.js"
7
4
  import { collectHotDataFromHtmlAst } from "./html_hot_dependencies.js"
8
5
  import { babelPluginMetadataImportMetaHot } from "./babel_plugin_metadata_import_meta_hot.js"
9
6
 
10
- export const jsenvPluginImportMetaHot = ({ rootDirectoryUrl }) => {
11
- const preferSourceFiles =
12
- rootDirectoryUrl === jsenvRootDirectoryUrl ||
13
- urlIsInsideOf(rootDirectoryUrl, jsenvRootDirectoryUrl)
14
- const importMetaHotClientFileUrl = preferSourceFiles
15
- ? new URL("./client/import_meta_hot.js", import.meta.url).href
16
- : new URL("./dist/import_meta_hot.js", jsenvRootDirectoryUrl).href
7
+ export const jsenvPluginImportMetaHot = () => {
8
+ const importMetaHotClientFileUrl = new URL(
9
+ "./client/import_meta_hot.js",
10
+ import.meta.url,
11
+ ).href
17
12
 
18
13
  return {
19
14
  name: "jsenv:import_meta_hot",
@@ -13,12 +13,13 @@ import {
13
13
  applyNodeEsmResolution,
14
14
  defaultLookupPackageScope,
15
15
  defaultReadPackageJson,
16
+ readCustomConditionsFromProcessArgs,
16
17
  } from "@jsenv/node-esm-resolution"
17
18
 
18
19
  export const jsenvPluginNodeEsmResolution = ({
19
20
  rootDirectoryUrl,
20
- // https://nodejs.org/api/esm.html#resolver-algorithm-specification
21
- packageConditions = ["browser", "import"],
21
+ runtimeCompat,
22
+ packageConditions,
22
23
  filesInvalidatingCache = ["package.json", "package-lock.json"],
23
24
  }) => {
24
25
  const packageScopesCache = new Map()
@@ -64,6 +65,7 @@ export const jsenvPluginNodeEsmResolution = ({
64
65
 
65
66
  return [
66
67
  jsenvPluginNodeEsmResolver({
68
+ runtimeCompat,
67
69
  packageConditions,
68
70
  lookupPackageScope,
69
71
  readPackageJson,
@@ -76,10 +78,18 @@ export const jsenvPluginNodeEsmResolution = ({
76
78
  }
77
79
 
78
80
  const jsenvPluginNodeEsmResolver = ({
81
+ runtimeCompat,
79
82
  packageConditions,
80
83
  lookupPackageScope,
81
84
  readPackageJson,
82
85
  }) => {
86
+ const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node")
87
+ // https://nodejs.org/api/esm.html#resolver-algorithm-specification
88
+ packageConditions = packageConditions || [
89
+ ...readCustomConditionsFromProcessArgs(),
90
+ nodeRuntimeEnabled ? "node" : "browser",
91
+ "import",
92
+ ]
83
93
  return {
84
94
  name: "jsenv:node_esm_resolve",
85
95
  appliesDuring: "*",
@@ -0,0 +1,12 @@
1
+ export const jsenvPluginNodeRuntime = ({ runtimeCompat }) => {
2
+ const nodeFound = Object.keys(runtimeCompat).includes("node")
3
+ if (!nodeFound) {
4
+ return []
5
+ }
6
+
7
+ // what do we need to do?
8
+ return {
9
+ name: "jsenv:node_runtime",
10
+ appliesDuring: "*",
11
+ }
12
+ }
@@ -159,6 +159,9 @@ const flattenAndFilterPlugins = (pluginsRaw, { scenario }) => {
159
159
  return
160
160
  }
161
161
  if (typeof pluginEntry === "object" && pluginEntry !== null) {
162
+ if (!pluginEntry.name) {
163
+ pluginEntry.name = "anonymous"
164
+ }
162
165
  const { appliesDuring } = pluginEntry
163
166
  if (appliesDuring === undefined) {
164
167
  console.warn(`"appliesDuring" is undefined on ${pluginEntry.name}`)
@@ -168,9 +171,20 @@ const flattenAndFilterPlugins = (pluginsRaw, { scenario }) => {
168
171
  plugins.push(pluginEntry)
169
172
  return
170
173
  }
174
+ if (typeof appliesDuring === "string") {
175
+ if (!["dev", "build", "test"].includes(appliesDuring)) {
176
+ throw new Error(
177
+ `"appliesDuring" must be "dev", "test" or "build", got ${appliesDuring}`,
178
+ )
179
+ }
180
+ if (appliesDuring === scenario) {
181
+ plugins.push(pluginEntry)
182
+ }
183
+ return
184
+ }
171
185
  if (typeof appliesDuring !== "object") {
172
186
  throw new Error(
173
- `"appliesDuring" must be an object or "*", got ${appliesDuring}`,
187
+ `"appliesDuring" must be an object or a string, got ${appliesDuring}`,
174
188
  )
175
189
  }
176
190
  if (appliesDuring[scenario]) {
@@ -252,8 +266,8 @@ const returnValueAssertions = [
252
266
  return { content: valueReturned }
253
267
  }
254
268
  if (typeof valueReturned === "object") {
255
- const { external, content } = valueReturned
256
- if (external) {
269
+ const { shouldHandle, content } = valueReturned
270
+ if (shouldHandle === false) {
257
271
  return undefined
258
272
  }
259
273
  if (typeof content !== "string" && !Buffer.isBuffer(content)) {