@jsenv/core 27.0.0-alpha.63 → 27.0.0-alpha.66

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 (170) hide show
  1. package/dist/babel_helpers/AsyncGenerator/AsyncGenerator.js +95 -0
  2. package/dist/babel_helpers/AwaitValue/AwaitValue.js +3 -0
  3. package/dist/babel_helpers/applyDecoratorDescriptor/applyDecoratorDescriptor.js +29 -0
  4. package/dist/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +9 -0
  5. package/dist/babel_helpers/arrayWithHoles/arrayWithHoles.js +4 -0
  6. package/dist/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +5 -0
  7. package/dist/babel_helpers/assertThisInitialized/assertThisInitialized.js +8 -0
  8. package/dist/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +52 -0
  9. package/dist/babel_helpers/asyncIterator/asyncIterator.js +78 -0
  10. package/dist/babel_helpers/asyncToGenerator/asyncToGenerator.js +39 -0
  11. package/dist/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +4 -0
  12. package/dist/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +24 -0
  13. package/dist/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +7 -0
  14. package/dist/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +14 -0
  15. package/dist/babel_helpers/classCallCheck/classCallCheck.js +5 -0
  16. package/dist/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -0
  17. package/dist/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -0
  18. package/dist/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +8 -0
  19. package/dist/babel_helpers/classNameTDZError/classNameTDZError.js +4 -0
  20. package/dist/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +6 -0
  21. package/dist/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +6 -0
  22. package/dist/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +7 -0
  23. package/dist/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -0
  24. package/dist/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +7 -0
  25. package/dist/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +7 -0
  26. package/dist/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +3 -0
  27. package/dist/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +8 -0
  28. package/dist/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +9 -0
  29. package/dist/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +5 -0
  30. package/dist/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -0
  31. package/dist/babel_helpers/construct/construct.js +15 -0
  32. package/dist/babel_helpers/createClass/createClass.js +18 -0
  33. package/dist/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +63 -0
  34. package/dist/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +22 -0
  35. package/dist/babel_helpers/createRawReactElement/createRawReactElement.js +50 -0
  36. package/dist/babel_helpers/createSuper/createSuper.js +22 -0
  37. package/dist/babel_helpers/decorate/decorate.js +622 -0
  38. package/dist/babel_helpers/defaults/defaults.js +14 -0
  39. package/dist/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +26 -0
  40. package/dist/babel_helpers/defineProperty/defineProperty.js +19 -0
  41. package/dist/babel_helpers/extends/extends.js +16 -0
  42. package/dist/babel_helpers/get/get.js +21 -0
  43. package/dist/babel_helpers/getPrototypeOf/getPrototypeOf.js +2 -0
  44. package/dist/babel_helpers/inherits/inherits.js +21 -0
  45. package/dist/babel_helpers/inheritsLoose/inheritsLoose.js +6 -0
  46. package/dist/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +10 -0
  47. package/dist/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +3 -0
  48. package/dist/babel_helpers/instanceof/instanceof.js +7 -0
  49. package/dist/babel_helpers/interopRequireDefault/interopRequireDefault.js +5 -0
  50. package/dist/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +49 -0
  51. package/dist/babel_helpers/isNativeFunction/isNativeFunction.js +4 -0
  52. package/dist/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -0
  53. package/dist/babel_helpers/iterableToArray/iterableToArray.js +3 -0
  54. package/dist/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +38 -0
  55. package/dist/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +13 -0
  56. package/dist/babel_helpers/jsx/jsx.js +49 -0
  57. package/dist/babel_helpers/maybeArrayLike/maybeArrayLike.js +10 -0
  58. package/dist/babel_helpers/newArrowCheck/newArrowCheck.js +5 -0
  59. package/dist/babel_helpers/nonIterableRest/nonIterableRest.js +3 -0
  60. package/dist/babel_helpers/nonIterableSpread/nonIterableSpread.js +3 -0
  61. package/dist/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -0
  62. package/dist/babel_helpers/objectSpread/objectSpread.js +22 -0
  63. package/dist/babel_helpers/objectSpread2/objectSpread2.js +41 -0
  64. package/dist/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +20 -0
  65. package/dist/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +15 -0
  66. package/dist/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +10 -0
  67. package/dist/babel_helpers/readOnlyError/readOnlyError.js +4 -0
  68. package/dist/babel_helpers/readme.md +8 -0
  69. package/dist/babel_helpers/set/set.js +51 -0
  70. package/dist/babel_helpers/setPrototypeOf/setPrototypeOf.js +5 -0
  71. package/dist/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -0
  72. package/dist/babel_helpers/slicedToArray/slicedToArray.js +5 -0
  73. package/dist/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +7 -0
  74. package/dist/babel_helpers/superPropBase/superPropBase.js +10 -0
  75. package/dist/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +11 -0
  76. package/dist/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +8 -0
  77. package/dist/babel_helpers/tdz/tdz.js +4 -0
  78. package/dist/babel_helpers/temporalRef/temporalRef.js +5 -0
  79. package/dist/babel_helpers/temporalUndefined/temporalUndefined.js +3 -0
  80. package/dist/babel_helpers/toArray/toArray.js +5 -0
  81. package/dist/babel_helpers/toConsumableArray/toConsumableArray.js +5 -0
  82. package/dist/babel_helpers/toPrimitive/toPrimitive.js +14 -0
  83. package/dist/babel_helpers/toPropertyKey/toPropertyKey.js +5 -0
  84. package/dist/babel_helpers/typeof/typeof.js +7 -0
  85. package/dist/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +10 -0
  86. package/dist/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +7 -0
  87. package/dist/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +35 -0
  88. package/dist/babel_helpers/wrapRegExp/wrapRegExp.js +67 -0
  89. package/dist/babel_helpers/writeOnlyError/writeOnlyError.js +4 -0
  90. package/dist/html/explorer.html +557 -0
  91. package/dist/js/controllable_file.mjs +227 -0
  92. package/dist/{event_source_client.js → js/event_source_client.js} +19 -244
  93. package/dist/js/global_this.js +32 -0
  94. package/dist/js/html_supervisor_installer.js +522 -0
  95. package/dist/js/html_supervisor_setup.js +79 -0
  96. package/dist/{import_meta_hot.js → js/import_meta_hot.js} +1 -3
  97. package/dist/js/inline_content.js +8 -0
  98. package/dist/js/new_stylesheet.js +409 -0
  99. package/dist/js/regenerator_runtime.js +721 -0
  100. package/dist/js/s.js +429 -0
  101. package/dist/main.js +13383 -0
  102. package/dist/other/jsenv.png +0 -0
  103. package/main.js +1 -0
  104. package/package.json +18 -14
  105. package/src/build/build.js +175 -69
  106. package/src/build/build_urls_generator.js +18 -2
  107. package/src/build/inject_global_version_mappings.js +18 -5
  108. package/src/build/inject_service_worker_urls.js +1 -1
  109. package/src/build/resync_ressource_hints.js +56 -9
  110. package/src/build/start_build_server.js +38 -29
  111. package/src/dev/plugins/explorer/client/explorer.html +1 -1
  112. package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +1 -1
  113. package/src/dev/start_dev_server.js +18 -4
  114. package/src/execute/execute.js +3 -0
  115. package/src/execute/runtimes/browsers/from_playwright.js +10 -0
  116. package/src/execute/runtimes/node/node_process.js +8 -0
  117. package/src/omega/errors.js +10 -7
  118. package/src/omega/kitchen.js +251 -340
  119. package/src/omega/server/file_service.js +34 -17
  120. package/src/omega/url_graph/url_graph_load.js +10 -17
  121. package/src/omega/url_graph/url_graph_report.js +2 -2
  122. package/src/omega/url_graph/url_info_transformations.js +1 -4
  123. package/src/omega/url_graph.js +7 -3
  124. package/src/omega/url_specifier_encoding.js +59 -0
  125. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +5 -10
  126. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +1 -3
  127. package/src/plugins/bundling/js_module/bundle_js_module.js +66 -24
  128. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +178 -53
  129. package/src/plugins/html_supervisor/client/html_supervisor_installer.js +1 -1
  130. package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +9 -13
  131. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +6 -6
  132. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +5 -10
  133. package/src/plugins/importmap/jsenv_plugin_importmap.js +2 -4
  134. package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +51 -42
  135. package/src/plugins/inline/jsenv_plugin_data_urls.js +1 -4
  136. package/src/plugins/inline/jsenv_plugin_html_inline_content.js +3 -5
  137. package/src/plugins/inline/jsenv_plugin_inline_query_param.js +1 -4
  138. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +1 -4
  139. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +16 -2
  140. package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +12 -0
  141. package/src/plugins/plugin_controller.js +17 -3
  142. package/src/plugins/plugins.js +15 -15
  143. package/src/plugins/transpilation/as_js_classic/client/s.js +362 -807
  144. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +20 -10
  145. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +302 -0
  146. package/src/plugins/transpilation/as_js_classic/{jsenv_plugin_workers_type_module_as_classic.js → jsenv_plugin_as_js_classic_workers.js} +2 -2
  147. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +5 -2
  148. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +1 -2
  149. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +2 -0
  150. package/src/plugins/url_analysis/html/html_urls.js +3 -0
  151. package/src/plugins/url_analysis/js/js_urls.js +2 -1
  152. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +94 -1
  153. package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +3 -0
  154. package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +0 -3
  155. package/src/test/execute_plan.js +34 -13
  156. package/src/test/execute_test_plan.js +2 -0
  157. package/src/test/logs_file_execution.js +47 -38
  158. package/dist/event_source_client.js.map +0 -188
  159. package/dist/html_supervisor_installer.js +0 -1236
  160. package/dist/html_supervisor_installer.js.map +0 -337
  161. package/dist/html_supervisor_setup.js +0 -95
  162. package/dist/html_supervisor_setup.js.map +0 -57
  163. package/dist/import_meta_hot.js.map +0 -42
  164. package/src/jsenv_root_directory_url.js +0 -1
  165. package/src/omega/compat/default_runtime_compat.js +0 -11
  166. package/src/plugins/filesystem_magic/jsenv_plugin_filesystem_magic.js +0 -61
  167. package/src/plugins/transpilation/as_js_classic/client/s.js.md +0 -1
  168. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +0 -270
  169. package/src/plugins/transpilation/babel/new_stylesheet/client/.eslintrc.cjs +0 -24
  170. package/src/plugins/transpilation/fetch_original_url_info.js +0 -30
Binary file
package/main.js CHANGED
@@ -24,3 +24,4 @@ export { startBuildServer } from "./src/build/start_build_server.js"
24
24
 
25
25
  // advanced
26
26
  export { execute } from "./src/execute/execute.js"
27
+ export { injectGlobals } from "./src/plugins/inject_globals/jsenv_plugin_inject_globals.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "27.0.0-alpha.63",
3
+ "version": "27.0.0-alpha.66",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -23,7 +23,10 @@
23
23
  "imports": {},
24
24
  "exports": {
25
25
  ".": {
26
- "import": "./main.js"
26
+ "import": {
27
+ "development": "./main.js",
28
+ "default": "./dist/main.js"
29
+ }
27
30
  },
28
31
  "./*": "./*"
29
32
  },
@@ -34,13 +37,14 @@
34
37
  "/main.js"
35
38
  ],
36
39
  "workspaces": [
37
- "./packages/*"
40
+ "./packages/*",
41
+ "./packages/create-jsenv/*"
38
42
  ],
39
43
  "scripts": {
40
44
  "eslint": "npx eslint . --ext=.js,.mjs,.cjs,.html",
41
- "dev": "node ./scripts/dev/dev.mjs",
42
- "build": "node ./scripts/build/build.mjs",
43
- "test": "node ./scripts/test/test.mjs",
45
+ "dev": "node --conditions=development ./scripts/dev/dev.mjs",
46
+ "build": "node --conditions=development ./scripts/build/build.mjs",
47
+ "test": "node --conditions=development ./scripts/test/test.mjs",
44
48
  "test-packages": "npm run test --workspaces --if-present",
45
49
  "start_file_server": "node ./scripts/dev/start_file_server.mjs",
46
50
  "workspace-versions": "node ./scripts/publish/workspace_versions.mjs",
@@ -68,12 +72,12 @@
68
72
  "@jsenv/filesystem": "3.2.2",
69
73
  "@jsenv/importmap": "1.2.0",
70
74
  "@jsenv/integrity": "0.0.1",
71
- "@jsenv/log": "1.6.1",
72
- "@jsenv/logger": "4.0.1",
73
- "@jsenv/node-esm-resolution": "0.0.7",
74
- "@jsenv/server": "12.6.2",
75
+ "@jsenv/log": "1.6.2",
76
+ "@jsenv/logger": "4.1.1",
77
+ "@jsenv/node-esm-resolution": "0.0.10",
78
+ "@jsenv/server": "12.6.3",
75
79
  "@jsenv/uneval": "1.6.0",
76
- "@jsenv/utils": "1.7.7",
80
+ "@jsenv/utils": "1.8.2",
77
81
  "construct-style-sheets-polyfill": "3.1.0",
78
82
  "cssnano": "5.1.7",
79
83
  "cssnano-preset-default": "5.2.7",
@@ -97,11 +101,11 @@
97
101
  "@babel/plugin-syntax-import-assertions": "7.16.7",
98
102
  "@jsenv/assert": "2.5.4",
99
103
  "@jsenv/eslint-config": "16.0.9",
100
- "@jsenv/file-size-impact": "12.1.11",
104
+ "@jsenv/file-size-impact": "12.1.12",
101
105
  "@jsenv/https-local": "1.0.11",
102
106
  "@jsenv/importmap-node-module": "5.1.3",
103
- "@jsenv/package-workspace": "0.1.2",
104
- "@jsenv/performance-impact": "2.2.10",
107
+ "@jsenv/package-workspace": "0.2.0",
108
+ "@jsenv/performance-impact": "2.2.11",
105
109
  "@jsenv/pwa": "5.0.0",
106
110
  "eslint": "8.13.0",
107
111
  "eslint-plugin-html": "6.2.0",
@@ -25,6 +25,8 @@ import {
25
25
  setUrlFilename,
26
26
  asUrlUntilPathname,
27
27
  normalizeUrl,
28
+ asUrlWithoutSearch,
29
+ ensurePathnameTrailingSlash,
28
30
  } from "@jsenv/utils/urls/url_utils.js"
29
31
  import { createVersionGenerator } from "@jsenv/utils/versioning/version_generator.js"
30
32
  import { generateSourcemapUrl } from "@jsenv/utils/sourcemap/sourcemap_utils.js"
@@ -34,10 +36,10 @@ import {
34
36
  } from "@jsenv/utils/html_ast/html_ast.js"
35
37
  import { sortByDependencies } from "@jsenv/utils/graph/sort_by_dependencies.js"
36
38
 
39
+ import { createUrlGraph } from "../omega/url_graph.js"
37
40
  import { jsenvPluginUrlAnalysis } from "../plugins/url_analysis/jsenv_plugin_url_analysis.js"
38
41
  import { jsenvPluginInline } from "../plugins/inline/jsenv_plugin_inline.js"
39
42
  import { jsenvPluginAsJsClassic } from "../plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js"
40
- import { createUrlGraph } from "../omega/url_graph.js"
41
43
  import { getCorePlugins } from "../plugins/plugins.js"
42
44
  import { createKitchen } from "../omega/kitchen.js"
43
45
  import { loadUrlGraph } from "../omega/url_graph/url_graph_load.js"
@@ -86,13 +88,27 @@ export const build = async ({
86
88
  rootDirectoryUrl,
87
89
  buildDirectoryUrl,
88
90
  entryPoints = {},
91
+ baseUrl = "/",
89
92
 
93
+ // default runtimeCompat corresponds to dynamic import
94
+ // (meaning we can keep <script type="module">)
95
+ runtimeCompat = {
96
+ // android: "8",
97
+ chrome: "63",
98
+ edge: "79",
99
+ firefox: "67",
100
+ ios: "11.3",
101
+ opera: "50",
102
+ safari: "11.3",
103
+ samsung: "8.2",
104
+ },
90
105
  plugins = [],
91
106
  sourcemaps = false,
107
+ urlAnalysis = {},
92
108
  nodeEsmResolution,
93
109
  fileSystemMagicResolution,
110
+ directoryReferenceAllowed,
94
111
  injectedGlobals,
95
- runtimeCompat,
96
112
  transpilation = {},
97
113
  bundling = true,
98
114
  minification = true,
@@ -112,7 +128,6 @@ export const build = async ({
112
128
  buildDirectoryClean = true,
113
129
  writeOnFileSystem = true,
114
130
  writeGeneratedFiles = false,
115
- baseUrl = "/",
116
131
  assetManifest = true,
117
132
  assetManifestFileRelativeUrl = "asset-manifest.json",
118
133
  }) => {
@@ -151,12 +166,16 @@ build "${entryPointKeys[0]}"`)
151
166
  logger.info(`
152
167
  build ${entryPointKeys.length} entry points`)
153
168
  }
169
+ const useExplicitJsClassicConversion = entryPointKeys.some((key) =>
170
+ entryPoints[key].includes("?as_js_classic"),
171
+ )
154
172
 
155
173
  const rawGraph = createUrlGraph()
156
174
  const prebuildTask = createTaskLog("prebuild", {
157
175
  disabled: infoLogsAreDisabled,
158
176
  })
159
177
  let urlCount = 0
178
+ const prebuildRedirections = new Map()
160
179
  const rawGraphKitchen = createKitchen({
161
180
  signal,
162
181
  logger,
@@ -176,16 +195,37 @@ build ${entryPointKeys.length} entry points`)
176
195
  prebuildTask.setRightText(urlCount)
177
196
  },
178
197
  },
198
+ {
199
+ appliesDuring: "build",
200
+ fetchUrlContent: (urlInfo, context) => {
201
+ if (context.reference.original) {
202
+ prebuildRedirections.set(
203
+ context.reference.original.url,
204
+ context.reference.url,
205
+ )
206
+ }
207
+ },
208
+ formatUrl: (reference) => {
209
+ if (!reference.shouldHandle) {
210
+ return `ignore:${reference.specifier}`
211
+ }
212
+ return null
213
+ },
214
+ },
179
215
  ...getCorePlugins({
180
216
  rootDirectoryUrl,
181
217
  urlGraph: rawGraph,
182
218
  scenario: "build",
219
+ runtimeCompat,
183
220
 
221
+ urlAnalysis,
184
222
  nodeEsmResolution,
185
223
  fileSystemMagicResolution,
224
+ directoryReferenceAllowed,
186
225
  injectedGlobals,
187
226
  transpilation: {
188
227
  ...transpilation,
228
+ babelHelpersAsImport: !useExplicitJsClassicConversion,
189
229
  jsModuleAsJsClassic: false,
190
230
  },
191
231
  minification,
@@ -199,6 +239,7 @@ build ${entryPointKeys.length} entry points`)
199
239
  operation: buildOperation,
200
240
  urlGraph: rawGraph,
201
241
  kitchen: rawGraphKitchen,
242
+ writeGeneratedFiles,
202
243
  outDirectoryUrl: new URL(`.jsenv/build/`, rootDirectoryUrl),
203
244
  startLoading: (cookEntryFile) => {
204
245
  Object.keys(entryPoints).forEach((key) => {
@@ -209,6 +250,7 @@ build ${entryPointKeys.length} entry points`)
209
250
  })
210
251
  entryUrls.push(entryUrlInfo.url)
211
252
  entryUrlInfo.filename = entryPoints[key]
253
+ // entryUrlInfo.data.entryPointKey = key
212
254
  })
213
255
  },
214
256
  })
@@ -222,8 +264,8 @@ build ${entryPointKeys.length} entry points`)
222
264
  buildDirectoryUrl,
223
265
  })
224
266
  const rawUrls = {}
267
+ const bundleRedirections = {}
225
268
  const buildUrls = {}
226
- const rawUrlRedirections = {}
227
269
  const bundleUrlInfos = {}
228
270
  const bundlers = {}
229
271
  rawGraphKitchen.pluginController.plugins.forEach((plugin) => {
@@ -313,7 +355,7 @@ build ${entryPointKeys.length} entry points`)
313
355
  })
314
356
  }
315
357
  })
316
- const bundleUrlRedirections = {}
358
+ const bundleInternalRedirections = {}
317
359
  await Object.keys(bundlers).reduce(async (previous, type) => {
318
360
  await previous
319
361
  const bundler = bundlers[type]
@@ -334,7 +376,7 @@ build ${entryPointKeys.length} entry points`)
334
376
  },
335
377
  urlInfosToBundle,
336
378
  {
337
- ...rawGraphKitchen.baseContext,
379
+ ...rawGraphKitchen.kitchenContext,
338
380
  buildDirectoryUrl,
339
381
  },
340
382
  )
@@ -355,15 +397,20 @@ build ${entryPointKeys.length} entry points`)
355
397
  const buildUrl = buildUrlsGenerator.generate(url, {
356
398
  urlInfo: bundleUrlInfo,
357
399
  })
358
- rawUrlRedirections[url] = buildUrl
400
+ bundleRedirections[url] = buildUrl
359
401
  rawUrls[buildUrl] = url
360
402
  bundleUrlInfos[buildUrl] = bundleUrlInfo
403
+ if (buildUrl.includes("?")) {
404
+ bundleUrlInfos[asUrlWithoutSearch(buildUrl)] = bundleUrlInfo
405
+ }
361
406
  if (bundlerGeneratedUrlInfo.data.bundleRelativeUrl) {
362
407
  const urlForBundler = new URL(
363
408
  bundlerGeneratedUrlInfo.data.bundleRelativeUrl,
364
409
  buildDirectoryUrl,
365
410
  ).href
366
- bundleUrlRedirections[urlForBundler] = buildUrl
411
+ if (urlForBundler !== buildUrl) {
412
+ bundleInternalRedirections[urlForBundler] = buildUrl
413
+ }
367
414
  }
368
415
  })
369
416
  } catch (e) {
@@ -373,7 +420,11 @@ build ${entryPointKeys.length} entry points`)
373
420
  bundleTask.done()
374
421
  }, Promise.resolve())
375
422
 
376
- const buildUrlRedirections = {}
423
+ const urlAnalysisPlugin = jsenvPluginUrlAnalysis({
424
+ rootDirectoryUrl,
425
+ ...urlAnalysis,
426
+ })
427
+ const postBuildRedirections = {}
377
428
  const finalGraph = createUrlGraph()
378
429
  const optimizeUrlContentHooks =
379
430
  rawGraphKitchen.pluginController.addHook("optimizeUrlContent")
@@ -387,31 +438,58 @@ build ${entryPointKeys.length} entry points`)
387
438
  runtimeCompat,
388
439
  writeGeneratedFiles,
389
440
  plugins: [
390
- jsenvPluginUrlAnalysis(),
391
- jsenvPluginAsJsClassic({
392
- systemJsInjection: true,
393
- }),
394
- jsenvPluginInline({
395
- fetchInlineUrls: false,
396
- }),
441
+ urlAnalysisPlugin,
442
+ jsenvPluginAsJsClassic({ systemJsInjection: true }),
443
+ jsenvPluginInline({ fetchInlineUrls: false }),
397
444
  {
398
445
  name: "jsenv:postbuild",
399
- appliesDuring: { build: true },
446
+ appliesDuring: "build",
400
447
  resolveUrl: (reference) => {
401
- if (reference.specifier[0] === "#") {
402
- reference.external = true
448
+ const performInternalRedirections = (url) => {
449
+ const prebuildRedirection = prebuildRedirections.get(url)
450
+ if (prebuildRedirection) {
451
+ logger.debug(
452
+ `\nprebuild redirection\n${url} ->\n${prebuildRedirection}\n`,
453
+ )
454
+ url = prebuildRedirection
455
+ }
456
+ const bundleRedirection = bundleRedirections[url]
457
+ if (bundleRedirection) {
458
+ logger.debug(
459
+ `\nbundler redirection\n${url} ->\n${bundleRedirection}\n`,
460
+ )
461
+ url = bundleRedirection
462
+ }
463
+ const bundleInternalRedirection = bundleInternalRedirections[url]
464
+ if (bundleInternalRedirection) {
465
+ logger.debug(
466
+ `\nbundler internal redirection\n${url} ->\n${bundleInternalRedirection}\n`,
467
+ )
468
+ url = bundleInternalRedirection
469
+ }
470
+ return url
403
471
  }
404
- let url =
405
- reference.specifier[0] === "/"
406
- ? new URL(reference.specifier.slice(1), buildDirectoryUrl).href
407
- : new URL(reference.specifier, reference.parentUrl).href
408
- const urlRedirectedByBundle = bundleUrlRedirections[url]
409
- if (urlRedirectedByBundle) {
410
- return urlRedirectedByBundle
472
+
473
+ if (reference.type === "filesystem") {
474
+ const parentRawUrl = rawUrls[reference.parentUrl]
475
+ const baseUrl = ensurePathnameTrailingSlash(parentRawUrl)
476
+ return performInternalRedirections(
477
+ new URL(reference.specifier, baseUrl).href,
478
+ )
479
+ }
480
+ if (reference.specifier[0] === "/") {
481
+ return performInternalRedirections(
482
+ new URL(reference.specifier.slice(1), buildDirectoryUrl).href,
483
+ )
411
484
  }
412
- const urlRedirected = rawUrlRedirections[url]
413
- return urlRedirected || url
485
+ return performInternalRedirections(
486
+ new URL(
487
+ reference.specifier,
488
+ reference.baseUrl || reference.parentUrl,
489
+ ).href,
490
+ )
414
491
  },
492
+ // redirecting urls into the build directory
415
493
  redirectUrl: (reference) => {
416
494
  if (!reference.url.startsWith("file:")) {
417
495
  return null
@@ -421,11 +499,6 @@ build ${entryPointKeys.length} entry points`)
421
499
  if (rawUrl) {
422
500
  return reference.url
423
501
  }
424
- // from rollup or postcss
425
- const bundleUrlInfo = bundleUrlInfos[reference.url]
426
- if (bundleUrlInfo) {
427
- return reference.url
428
- }
429
502
  // from "js_module_as_js_classic":
430
503
  // - injecting "?as_js_classic" for the first time
431
504
  // - injecting "?as_js_classic" because the parentUrl has it
@@ -441,9 +514,8 @@ build ${entryPointKeys.length} entry points`)
441
514
  }
442
515
  let rawUrl
443
516
  if (urlIsInsideOf(reference.url, buildDirectoryUrl)) {
444
- // rawUrl = rawUrls[reference.url] || reference.url
445
517
  const originalBuildUrl =
446
- buildUrlRedirections[referenceOriginalUrl]
518
+ postBuildRedirections[referenceOriginalUrl]
447
519
  rawUrl = originalBuildUrl
448
520
  ? rawUrls[originalBuildUrl]
449
521
  : reference.url
@@ -465,7 +537,7 @@ build ${entryPointKeys.length} entry points`)
465
537
  filename: reference.filename,
466
538
  },
467
539
  })
468
- buildUrlRedirections[originalBuildUrl] = buildUrl
540
+ postBuildRedirections[originalBuildUrl] = buildUrl
469
541
  rawUrls[buildUrl] = rawUrl
470
542
  return buildUrl
471
543
  }
@@ -509,11 +581,16 @@ build ${entryPointKeys.length} entry points`)
509
581
  return buildUrl
510
582
  }
511
583
  const rawUrlInfo = rawGraph.getUrlInfo(reference.url)
584
+ const parentUrlInfo = finalGraph.getUrlInfo(reference.parentUrl)
512
585
  // files from root directory but not given to rollup nor postcss
513
586
  if (rawUrlInfo) {
514
587
  const buildUrl = buildUrlsGenerator.generate(reference.url, {
515
588
  urlInfo: rawUrlInfo,
589
+ parentUrlInfo,
516
590
  })
591
+ if (buildUrl.includes("?")) {
592
+ rawUrls[asUrlWithoutSearch(buildUrl)] = rawUrlInfo.url
593
+ }
517
594
  rawUrls[buildUrl] = rawUrlInfo.url
518
595
  return buildUrl
519
596
  }
@@ -534,6 +611,9 @@ build ${entryPointKeys.length} entry points`)
534
611
  },
535
612
  formatUrl: (reference) => {
536
613
  if (!reference.generatedUrl.startsWith("file:")) {
614
+ if (!versioning && reference.generatedUrl.startsWith("ignore:")) {
615
+ return reference.generatedUrl.slice("ignore:".length)
616
+ }
537
617
  return null
538
618
  }
539
619
  if (!urlIsInsideOf(reference.generatedUrl, buildDirectoryUrl)) {
@@ -541,6 +621,10 @@ build ${entryPointKeys.length} entry points`)
541
621
  `urls should be inside build directory at this stage, found "${reference.url}"`,
542
622
  )
543
623
  }
624
+ if (reference.isRessourceHint) {
625
+ // return the raw url, we will resync at the end
626
+ return rawUrls[reference.url]
627
+ }
544
628
  // remove eventual search params and hash
545
629
  const urlUntilPathname = asUrlUntilPathname(reference.generatedUrl)
546
630
  let specifier
@@ -566,23 +650,18 @@ build ${entryPointKeys.length} entry points`)
566
650
  return specifier
567
651
  },
568
652
  fetchUrlContent: async (finalUrlInfo, context) => {
569
- if (!finalUrlInfo.url.startsWith("file:")) {
570
- return { external: true }
571
- }
572
653
  const fromBundleOrRawGraph = (url) => {
573
654
  const bundleUrlInfo = bundleUrlInfos[url]
574
655
  if (bundleUrlInfo) {
656
+ logger.debug(`fetching from bundle ${url}`)
575
657
  return bundleUrlInfo
576
658
  }
577
659
  const rawUrl = rawUrls[url] || url
578
660
  const rawUrlInfo = rawGraph.getUrlInfo(rawUrl)
579
661
  if (!rawUrlInfo) {
580
- const originalBuildUrl = buildUrlRedirections[url]
581
- if (originalBuildUrl) {
582
- return fromBundleOrRawGraph(originalBuildUrl)
583
- }
584
662
  throw new Error(`Cannot find url`)
585
663
  }
664
+ logger.debug(`fetching from raw graph ${url}`)
586
665
  if (rawUrlInfo.isInline) {
587
666
  // Inline content, such as <script> inside html, is transformed during the previous phase.
588
667
  // If we read the inline content it would be considered as the original content.
@@ -609,10 +688,7 @@ build ${entryPointKeys.length} entry points`)
609
688
  specifier: context.reference.specifier,
610
689
  injected: true,
611
690
  })
612
- await rawGraphKitchen.cook({
613
- reference: ref,
614
- urlInfo: rawUrlInfo,
615
- })
691
+ await rawGraphKitchen.cook(rawUrlInfo, { reference: ref })
616
692
  return rawUrlInfo
617
693
  }
618
694
  // reference updated during "postbuild":
@@ -625,7 +701,7 @@ build ${entryPointKeys.length} entry points`)
625
701
  },
626
702
  {
627
703
  name: "jsenv:optimize",
628
- appliesDuring: { build: true },
704
+ appliesDuring: "build",
629
705
  finalizeUrlContent: async (urlInfo, context) => {
630
706
  if (optimizeUrlContentHooks.length) {
631
707
  await rawGraphKitchen.pluginController.callAsyncHooks(
@@ -652,6 +728,7 @@ build ${entryPointKeys.length} entry points`)
652
728
  urlGraph: finalGraph,
653
729
  kitchen: finalGraphKitchen,
654
730
  outDirectoryUrl: new URL(".jsenv/postbuild/", rootDirectoryUrl),
731
+ writeGeneratedFiles,
655
732
  skipRessourceHint: true,
656
733
  startLoading: (cookEntryFile) => {
657
734
  entryUrls.forEach((entryUrl) => {
@@ -688,6 +765,7 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
688
765
  runtimeCompat,
689
766
  writeGeneratedFiles,
690
767
  rawGraph,
768
+ urlAnalysisPlugin,
691
769
  finalGraph,
692
770
  finalGraphKitchen,
693
771
  lineBreakNormalization,
@@ -695,10 +773,10 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
695
773
  })
696
774
  }
697
775
  GRAPH.forEach(finalGraph, (urlInfo) => {
698
- if (!urlInfo.url.startsWith("file:")) {
776
+ if (!urlInfo.shouldHandle) {
699
777
  return
700
778
  }
701
- if (urlInfo.external) {
779
+ if (!urlInfo.url.startsWith("file:")) {
702
780
  return
703
781
  }
704
782
  if (urlInfo.type === "html") {
@@ -720,10 +798,11 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
720
798
  urlInfo.data.buildUrlSpecifier = buildUrlSpecifier
721
799
  })
722
800
  await resyncRessourceHints({
801
+ logger,
723
802
  finalGraphKitchen,
724
803
  finalGraph,
725
804
  rawUrls,
726
- buildUrls,
805
+ postBuildRedirections,
727
806
  })
728
807
  buildOperation.throwIfAborted()
729
808
  const cleanupActions = []
@@ -753,10 +832,13 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
753
832
  const buildFileContents = {}
754
833
  const buildInlineContents = {}
755
834
  GRAPH.forEach(finalGraph, (urlInfo) => {
756
- if (urlInfo.external) {
835
+ if (!urlInfo.shouldHandle) {
757
836
  return
758
837
  }
759
- if (urlInfo.url.startsWith("data:")) {
838
+ if (!urlInfo.url.startsWith("file:")) {
839
+ return
840
+ }
841
+ if (urlInfo.type === "directory") {
760
842
  return
761
843
  }
762
844
  const buildRelativeUrl = urlToRelativeUrl(
@@ -890,6 +972,7 @@ const applyUrlVersioning = async ({
890
972
  runtimeCompat,
891
973
  writeGeneratedFiles,
892
974
  rawGraph,
975
+ urlAnalysisPlugin,
893
976
  finalGraph,
894
977
  finalGraphKitchen,
895
978
  lineBreakNormalization,
@@ -911,7 +994,7 @@ const applyUrlVersioning = async ({
911
994
  // ignore:
912
995
  // - inline files:
913
996
  // they are already taken into account in the file where they appear
914
- // - external files
997
+ // - ignored files:
915
998
  // we don't know their content
916
999
  // - unused files without reference
917
1000
  // File updated such as style.css -> style.css.js or file.js->file.es5.js
@@ -921,7 +1004,7 @@ const applyUrlVersioning = async ({
921
1004
  if (urlInfo.isInline) {
922
1005
  return
923
1006
  }
924
- if (urlInfo.external) {
1007
+ if (!urlInfo.shouldHandle) {
925
1008
  return
926
1009
  }
927
1010
  if (!urlInfo.data.isEntryPoint && urlInfo.dependents.size === 0) {
@@ -944,8 +1027,8 @@ const applyUrlVersioning = async ({
944
1027
  lineBreakNormalization,
945
1028
  })
946
1029
  urlInfo.dependencies.forEach((dependencyUrl) => {
947
- // this dependency is inline (data:) or remote (http://, https://)
948
- if (!dependencyUrl.startsWith("file:")) {
1030
+ // this dependency is inline
1031
+ if (dependencyUrl.startsWith("data:")) {
949
1032
  return
950
1033
  }
951
1034
  const dependencyUrlInfo = finalGraph.getUrlInfo(dependencyUrl)
@@ -953,7 +1036,7 @@ const applyUrlVersioning = async ({
953
1036
  // this content is part of the file, no need to take into account twice
954
1037
  dependencyUrlInfo.isInline ||
955
1038
  // this dependency content is not known
956
- dependencyUrlInfo.external
1039
+ !dependencyUrlInfo.shouldHandle
957
1040
  ) {
958
1041
  return
959
1042
  }
@@ -995,7 +1078,7 @@ const applyUrlVersioning = async ({
995
1078
  runtimeCompat,
996
1079
  writeGeneratedFiles,
997
1080
  plugins: [
998
- jsenvPluginUrlAnalysis(),
1081
+ urlAnalysisPlugin,
999
1082
  jsenvPluginInline({
1000
1083
  fetchInlineUrls: false,
1001
1084
  analyzeConvertedScripts: true, // to be able to version their urls
@@ -1005,18 +1088,44 @@ const applyUrlVersioning = async ({
1005
1088
  name: "jsenv:versioning",
1006
1089
  appliesDuring: { build: true },
1007
1090
  resolveUrl: (reference) => {
1008
- if (reference.specifier[0] === "#") {
1009
- reference.external = true
1010
- }
1011
1091
  const buildUrl = buildUrls[reference.specifier]
1012
1092
  if (buildUrl) {
1013
1093
  return buildUrl
1014
1094
  }
1015
- const url = new URL(reference.specifier, reference.parentUrl).href
1095
+ const urlObject = new URL(
1096
+ reference.specifier,
1097
+ reference.baseUrl || reference.parentUrl,
1098
+ )
1099
+ const url = urlObject.href
1100
+ // during versioning we revisit the deps
1101
+ // but the code used to enforce trailing slash on directories
1102
+ // is not applied because "jsenv:file_url_resolution" is not used
1103
+ // so here we search if the url with a trailing slash exists
1104
+ if (
1105
+ reference.type === "filesystem" &&
1106
+ !urlObject.pathname.endsWith("/")
1107
+ ) {
1108
+ const urlWithTrailingSlash = `${url}/`
1109
+ const specifier = Object.keys(buildUrls).find(
1110
+ (key) => buildUrls[key] === urlWithTrailingSlash,
1111
+ )
1112
+ if (specifier) {
1113
+ return urlWithTrailingSlash
1114
+ }
1115
+ }
1016
1116
  return url
1017
1117
  },
1018
1118
  formatUrl: (reference) => {
1019
- if (reference.isInline) {
1119
+ if (!reference.shouldHandle) {
1120
+ if (reference.generatedUrl.startsWith("ignore:")) {
1121
+ return reference.generatedUrl.slice("ignore:".length)
1122
+ }
1123
+ return null
1124
+ }
1125
+ if (reference.isInline || reference.url.startsWith("data:")) {
1126
+ return null
1127
+ }
1128
+ if (reference.isRessourceHint) {
1020
1129
  return null
1021
1130
  }
1022
1131
  // specifier comes from "normalize" hook done a bit earlier in this file
@@ -1025,8 +1134,7 @@ const applyUrlVersioning = async ({
1025
1134
  if (!canUseVersionedUrl(referencedUrlInfo)) {
1026
1135
  return reference.specifier
1027
1136
  }
1028
- // data:* urls and so on
1029
- if (!referencedUrlInfo.url.startsWith("file:")) {
1137
+ if (!referencedUrlInfo.shouldHandle) {
1030
1138
  return null
1031
1139
  }
1032
1140
  const versionedUrl = referencedUrlInfo.data.versionedUrl
@@ -1063,9 +1171,6 @@ const applyUrlVersioning = async ({
1063
1171
  return versionedSpecifier
1064
1172
  },
1065
1173
  fetchUrlContent: (versionedUrlInfo) => {
1066
- if (!versionedUrlInfo.url.startsWith("file:")) {
1067
- return { external: true }
1068
- }
1069
1174
  if (versionedUrlInfo.isInline) {
1070
1175
  const rawUrlInfo = rawGraph.getUrlInfo(
1071
1176
  rawUrls[versionedUrlInfo.url],
@@ -1090,6 +1195,7 @@ const applyUrlVersioning = async ({
1090
1195
  urlGraph: finalGraph,
1091
1196
  kitchen: versioningKitchen,
1092
1197
  skipRessourceHint: true,
1198
+ writeGeneratedFiles,
1093
1199
  startLoading: (cookEntryFile) => {
1094
1200
  postBuildEntryUrls.forEach((postBuildEntryUrl) => {
1095
1201
  cookEntryFile({
@@ -1,4 +1,4 @@
1
- import { urlToFilename } from "@jsenv/filesystem"
1
+ import { urlToFilename, urlToRelativeUrl } from "@jsenv/filesystem"
2
2
 
3
3
  import { memoizeByFirstArgument } from "@jsenv/utils/memoize/memoize_by_first_argument.js"
4
4
 
@@ -17,6 +17,7 @@ export const createBuilUrlsGenerator = ({ buildDirectoryUrl }) => {
17
17
 
18
18
  const generate = memoizeByFirstArgument((url, { urlInfo, parentUrlInfo }) => {
19
19
  const directoryPath = determineDirectoryPath({
20
+ buildDirectoryUrl,
20
21
  urlInfo,
21
22
  parentUrlInfo,
22
23
  })
@@ -69,9 +70,24 @@ const splitFileExtension = (filename) => {
69
70
  return [filename.slice(0, dotLastIndex), filename.slice(dotLastIndex)]
70
71
  }
71
72
 
72
- const determineDirectoryPath = ({ urlInfo, parentUrlInfo }) => {
73
+ const determineDirectoryPath = ({
74
+ buildDirectoryUrl,
75
+ urlInfo,
76
+ parentUrlInfo,
77
+ }) => {
78
+ if (urlInfo.type === "directory") {
79
+ return ""
80
+ }
81
+ if (parentUrlInfo && parentUrlInfo.type === "directory") {
82
+ const parentDirectoryPath = urlToRelativeUrl(
83
+ parentUrlInfo.url,
84
+ buildDirectoryUrl,
85
+ )
86
+ return parentDirectoryPath
87
+ }
73
88
  if (urlInfo.isInline) {
74
89
  const parentDirectoryPath = determineDirectoryPath({
90
+ buildDirectoryUrl,
75
91
  urlInfo: parentUrlInfo,
76
92
  })
77
93
  return parentDirectoryPath