@jsenv/core 25.0.0 → 25.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/browser_runtime/browser_runtime_91c5a3b8.js.map +2 -2
  2. package/dist/build_manifest.js +4 -4
  3. package/dist/compile_proxy/asset-manifest.json +2 -2
  4. package/dist/compile_proxy/{compile_proxy_e3b0c442_809f35f7.js.map → compile_proxy.html__inline__20_809f35f7.js.map} +0 -0
  5. package/dist/compile_proxy/{compile_proxy_7ad5faa6.html → compile_proxy_8dfaee51.html} +3 -4
  6. package/dist/redirector/asset-manifest.json +2 -2
  7. package/dist/redirector/{redirector_e3b0c442_e391410e.js.map → redirector.html__inline__15_e391410e.js.map} +0 -0
  8. package/dist/redirector/{redirector_eb92e8a7.html → redirector_3e9a97b9.html} +3 -4
  9. package/dist/toolbar/asset-manifest.json +1 -1
  10. package/dist/toolbar/{toolbar_f7b8a263.html → toolbar_361afb84.html} +2 -3
  11. package/dist/toolbar_injector/asset-manifest.json +2 -2
  12. package/dist/toolbar_injector/{toolbar_injector_49e4756e.js → toolbar_injector_fac1e995.js} +2 -2
  13. package/dist/toolbar_injector/{toolbar_injector_49e4756e.js.map → toolbar_injector_fac1e995.js.map} +2 -2
  14. package/package.json +8 -8
  15. package/readme.md +61 -52
  16. package/src/buildProject.js +21 -13
  17. package/src/commonJsToJavaScriptModule.js +8 -7
  18. package/src/execute.js +2 -0
  19. package/src/executeTestPlan.js +14 -0
  20. package/src/internal/building/buildUsingRollup.js +4 -2
  21. package/src/internal/building/build_stats.js +3 -0
  22. package/src/internal/building/build_url_generator.js +153 -0
  23. package/src/internal/building/css/parseCssRessource.js +32 -26
  24. package/src/internal/building/html/parseHtmlRessource.js +109 -91
  25. package/src/internal/building/js/parseJsRessource.js +5 -13
  26. package/src/internal/building/parseRessource.js +3 -0
  27. package/src/internal/building/ressource_builder.js +72 -64
  28. package/src/internal/building/ressource_builder_util.js +17 -5
  29. package/src/internal/building/rollup_plugin_jsenv.js +262 -189
  30. package/src/internal/building/url_fetcher.js +16 -7
  31. package/src/internal/building/url_loader.js +1 -5
  32. package/src/internal/building/url_versioning.js +0 -173
  33. package/src/internal/compiling/babel_plugin_import_metadata.js +7 -11
  34. package/src/internal/compiling/babel_plugin_proxy_external_imports.js +31 -0
  35. package/src/internal/compiling/compile-directory/compile-asset.js +8 -4
  36. package/src/internal/compiling/compile-directory/getOrGenerateCompiledFile.js +43 -8
  37. package/src/internal/compiling/compile-directory/updateMeta.js +2 -8
  38. package/src/internal/compiling/compile-directory/validateCache.js +1 -2
  39. package/src/internal/compiling/compileFile.js +22 -10
  40. package/src/internal/compiling/compileHtml.js +15 -28
  41. package/src/internal/compiling/createCompiledFileService.js +22 -24
  42. package/src/internal/compiling/html_source_file_service.js +18 -19
  43. package/src/internal/compiling/js-compilation-service/jsenvTransform.js +14 -4
  44. package/src/internal/compiling/js-compilation-service/transformJs.js +9 -5
  45. package/src/internal/compiling/jsenvCompilerForHtml.js +534 -263
  46. package/src/internal/compiling/jsenvCompilerForJavaScript.js +15 -11
  47. package/src/internal/compiling/startCompileServer.js +83 -20
  48. package/src/internal/compiling/transformResultToCompilationResult.js +47 -25
  49. package/src/internal/executing/executePlan.js +2 -0
  50. package/src/internal/fetchUrl.js +3 -2
  51. package/src/internal/integrity/integrity_algorithms.js +26 -0
  52. package/src/internal/integrity/integrity_parsing.js +50 -0
  53. package/src/internal/integrity/integrity_update.js +23 -0
  54. package/src/internal/integrity/integrity_validation.js +49 -0
  55. package/src/internal/jsenvCoreDirectoryUrl.js +2 -0
  56. package/src/internal/jsenv_remote_directory.js +156 -0
  57. package/src/internal/origin_directory_converter.js +62 -0
  58. package/src/internal/response_validation.js +11 -24
  59. package/src/internal/sourceMappingURLUtils.js +10 -0
  60. package/src/internal/url_conversion.js +1 -0
@@ -38,7 +38,9 @@ export const createCompiledFileService = ({
38
38
  logger,
39
39
 
40
40
  projectDirectoryUrl,
41
+ jsenvDirectoryRelativeUrl,
41
42
  outDirectoryRelativeUrl,
43
+ jsenvRemoteDirectory,
42
44
 
43
45
  runtimeSupport,
44
46
  babelPluginMap,
@@ -89,12 +91,9 @@ export const createCompiledFileService = ({
89
91
 
90
92
  const importmapInfos = {}
91
93
 
92
- return (request, { pushResponse, redirectRequest }) => {
94
+ return async (request, { pushResponse, redirectRequest }) => {
93
95
  const { origin, ressource } = request
94
- // we use "ressourceToPathname" to remove eventual query param from the url
95
- // Without this a pattern like "**/*.js" would not match "file.js?t=1"
96
- // This would result in file not being compiled when they should
97
- const requestUrl = `${origin}${ressourceToPathname(ressource)}`
96
+ const requestUrl = `${origin}${ressource}`
98
97
 
99
98
  const requestCompileInfo = serverUrlToCompileInfo(requestUrl, {
100
99
  outDirectoryRelativeUrl,
@@ -140,8 +139,6 @@ export const createCompiledFileService = ({
140
139
  }
141
140
 
142
141
  const originalFileRelativeUrl = afterCompileId
143
- projectFileRequestedCallback(originalFileRelativeUrl, request)
144
-
145
142
  const originalFileUrl = `${projectDirectoryUrl}${originalFileRelativeUrl}`
146
143
  const compileDirectoryRelativeUrl = `${outDirectoryRelativeUrl}${compileId}/`
147
144
  const compileDirectoryUrl = resolveDirectoryUrl(
@@ -152,23 +149,22 @@ export const createCompiledFileService = ({
152
149
  originalFileRelativeUrl,
153
150
  compileDirectoryUrl,
154
151
  )
155
-
156
152
  const compiler = getCompiler({ originalFileUrl, compileMeta })
157
153
  // no compiler -> serve original file
158
- // we don't redirect otherwise it complexify ressource tracking
159
- // and url resolution
154
+ // we redirect "internally" (we dont send 304 to the browser)
155
+ // to keep ressource tracking and url resolution simple
160
156
  if (!compiler) {
161
157
  return redirectRequest({
162
158
  pathname: `/${originalFileRelativeUrl}`,
163
159
  })
164
160
  }
165
-
166
161
  // compile this if needed
167
162
  const compileResponsePromise = compileFile({
168
163
  compileServerOperation,
169
164
  logger,
170
165
 
171
166
  projectDirectoryUrl,
167
+ jsenvRemoteDirectory,
172
168
  originalFileUrl,
173
169
  compiledFileUrl,
174
170
 
@@ -181,14 +177,16 @@ export const createCompiledFileService = ({
181
177
  return compiler({
182
178
  logger,
183
179
 
184
- code,
185
- url: originalFileUrl,
186
- compiledUrl: compiledFileUrl,
187
180
  projectDirectoryUrl,
181
+ jsenvRemoteDirectory,
188
182
  compileServerOrigin: request.origin,
183
+ jsenvDirectoryRelativeUrl,
189
184
  outDirectoryRelativeUrl,
190
- compileId,
185
+ url: originalFileUrl,
186
+ compiledUrl: compiledFileUrl,
191
187
  request,
188
+
189
+ compileId,
192
190
  babelPluginMap: shakeBabelPluginMap({
193
191
  babelPluginMap,
194
192
  missingFeatureNames: groupMap[compileId].missingFeatureNames,
@@ -204,6 +202,7 @@ export const createCompiledFileService = ({
204
202
  topLevelAwait,
205
203
  prependSystemJs,
206
204
 
205
+ code,
207
206
  sourcemapMethod,
208
207
  sourcemapExcludeSources,
209
208
  jsenvEventSourceClientInjection,
@@ -238,6 +237,14 @@ const canAvoidSystemJs = ({
238
237
  }
239
238
 
240
239
  const getCompiler = ({ originalFileUrl, compileMeta }) => {
240
+ // we remove eventual query param from the url
241
+ // Without this a pattern like "**/*.js" would not match "file.js?t=1"
242
+ // This would result in file not being compiled when they should
243
+ // Ideally we would do a first pass with the query param and a second without
244
+ const urlObject = new URL(originalFileUrl)
245
+ urlObject.search = ""
246
+ originalFileUrl = urlObject.href
247
+
241
248
  const { jsenvCompiler, customCompiler } = urlToMeta({
242
249
  url: originalFileUrl,
243
250
  structuredMetaMap: compileMeta,
@@ -307,12 +314,3 @@ const contentTypeExtensions = {
307
314
  "application/importmap+json": ".importmap",
308
315
  // "text/css": ".css",
309
316
  }
310
-
311
- const ressourceToPathname = (ressource) => {
312
- const searchSeparatorIndex = ressource.indexOf("?")
313
- const pathname =
314
- searchSeparatorIndex === -1
315
- ? ressource
316
- : ressource.slice(0, searchSeparatorIndex)
317
- return pathname
318
- }
@@ -41,7 +41,7 @@ import {
41
41
  removeHtmlNodeAttribute,
42
42
  getHtmlNodeTextNode,
43
43
  setHtmlNodeText,
44
- getUniqueNameForInlineHtmlNode,
44
+ getIdForInlineHtmlNode,
45
45
  } from "./compileHtml.js"
46
46
  import { jsenvCoreDirectoryUrl } from "../jsenvCoreDirectoryUrl.js"
47
47
 
@@ -121,8 +121,8 @@ export const createTransformHtmlSourceFileService = ({
121
121
  jsenvScriptInjection,
122
122
  jsenvEventSourceClientInjection,
123
123
  jsenvToolbarInjection,
124
- onInlineModuleScript: ({ scriptContent, scriptIdentifier }) => {
125
- const inlineScriptUrl = resolveUrl(scriptIdentifier, fileUrl)
124
+ onInlineModuleScript: ({ scriptContent, scriptSpecifier }) => {
125
+ const inlineScriptUrl = resolveUrl(scriptSpecifier, fileUrl)
126
126
  htmlInlineScriptMap.set(inlineScriptUrl, {
127
127
  htmlFileUrl: fileUrl,
128
128
  scriptContent,
@@ -232,35 +232,35 @@ const transformHTMLSourceFile = async ({
232
232
  const { scripts } = parseHtmlAstRessources(htmlAst)
233
233
  scripts.forEach((script) => {
234
234
  const typeAttribute = getHtmlNodeAttributeByName(script, "type")
235
+ const type = typeAttribute ? typeAttribute.value : ""
235
236
  const srcAttribute = getHtmlNodeAttributeByName(script, "src")
236
-
237
- // remote
238
- if (typeAttribute && typeAttribute.value === "module" && srcAttribute) {
237
+ const src = srcAttribute ? srcAttribute.value : ""
238
+ if (type === "module" && src) {
239
239
  removeHtmlNodeAttribute(script, srcAttribute)
240
+ // Ideally jsenv should take into account eventual
241
+ // "integrity" and "crossorigin" attribute during "executeFileUsingDynamicImport"
240
242
  setHtmlNodeText(
241
243
  script,
242
244
  `window.__jsenv__.executeFileUsingDynamicImport(${JSON.stringify(
243
- srcAttribute.value,
245
+ src,
244
246
  )})`,
245
247
  )
246
248
  return
247
249
  }
248
- // inline
249
250
  const textNode = getHtmlNodeTextNode(script)
250
- if (typeAttribute && typeAttribute.value === "module" && textNode) {
251
- const scriptIdentifier = getUniqueNameForInlineHtmlNode(
252
- script,
253
- scripts,
254
- `${urlToFilename(fileUrl)}__inline__[id].js`,
255
- )
251
+ if (type === "module" && textNode) {
252
+ const scriptId = getIdForInlineHtmlNode(script, scripts)
253
+ const scriptSpecifier = `${urlToFilename(
254
+ fileUrl,
255
+ )}__inline__${scriptId}.js`
256
256
  onInlineModuleScript({
257
257
  scriptContent: textNode.value,
258
- scriptIdentifier,
258
+ scriptSpecifier,
259
259
  })
260
260
  setHtmlNodeText(
261
261
  script,
262
262
  `window.__jsenv__.executeFileUsingDynamicImport(${JSON.stringify(
263
- `./${scriptIdentifier}`,
263
+ `./${scriptSpecifier}`,
264
264
  )})`,
265
265
  )
266
266
  return
@@ -275,7 +275,8 @@ const transformHTMLSourceFile = async ({
275
275
  projectDirectoryUrl,
276
276
  })
277
277
 
278
- return stringifyHtmlAst(htmlAst)
278
+ const htmlTransformed = stringifyHtmlAst(htmlAst)
279
+ return htmlTransformed
279
280
  }
280
281
 
281
282
  const visitImportmapScripts = async ({
@@ -315,14 +316,12 @@ const visitImportmapScripts = async ({
315
316
  )
316
317
  return
317
318
  }
318
-
319
319
  const importMapContent = await importMapResponse.json()
320
320
  const importMapInlined = moveImportMap(
321
321
  importMapContent,
322
322
  importMapUrl,
323
323
  htmlFileUrl,
324
324
  )
325
-
326
325
  replaceHtmlNode(
327
326
  importmapScript,
328
327
  `<script type="importmap">${JSON.stringify(
@@ -6,6 +6,7 @@ import {
6
6
  getMinimalBabelPluginMap,
7
7
  babelPluginsFromBabelPluginMap,
8
8
  } from "@jsenv/core/src/internal/compiling/babel_plugins.js"
9
+ import { babelPluginProxyExternalImports } from "@jsenv/core/src/internal/compiling/babel_plugin_proxy_external_imports.js"
9
10
  import { babelPluginImportMetadata } from "@jsenv/core/src/internal/compiling/babel_plugin_import_metadata.js"
10
11
 
11
12
  import { ansiToHTML } from "./ansiToHTML.js"
@@ -15,9 +16,7 @@ import { babelPluginSystemJsPrepend } from "./babel_plugin_systemjs_prepend.js"
15
16
  import { filePathToBabelHelperName } from "./babelHelper.js"
16
17
 
17
18
  export const jsenvTransform = async ({
18
- code,
19
- map, // optional
20
- ast, // optional
19
+ jsenvRemoteDirectory,
21
20
  url,
22
21
  relativeUrl, // optional
23
22
 
@@ -25,12 +24,15 @@ export const jsenvTransform = async ({
25
24
  moduleOutFormat,
26
25
  importMetaFormat = moduleOutFormat,
27
26
  topLevelAwait,
28
-
29
27
  babelHelpersInjectionAsImport,
30
28
  prependSystemJs,
31
29
  transformGenerator,
32
30
  regeneratorRuntimeImportPath,
31
+
33
32
  sourcemapEnabled,
33
+ ast, // optional
34
+ map, // optional
35
+ code,
34
36
  }) => {
35
37
  const transformModulesSystemJs = require("@babel/plugin-transform-modules-systemjs")
36
38
  const proposalDynamicImport = require("@babel/plugin-proposal-dynamic-import")
@@ -146,6 +148,14 @@ export const jsenvTransform = async ({
146
148
  ],
147
149
  }
148
150
  : {}),
151
+ ...(jsenvRemoteDirectory
152
+ ? {
153
+ "proxy-external-imports": [
154
+ babelPluginProxyExternalImports,
155
+ { jsenvRemoteDirectory },
156
+ ],
157
+ }
158
+ : {}),
149
159
  "import-metadata": [babelPluginImportMetadata],
150
160
  }
151
161
  if (moduleOutFormat === "systemjs") {
@@ -3,10 +3,9 @@ import { urlToRelativeUrl } from "@jsenv/filesystem"
3
3
  import { jsenvTransform } from "./jsenvTransform.js"
4
4
 
5
5
  export const transformJs = async ({
6
- code,
7
- map,
8
- url,
9
6
  projectDirectoryUrl,
7
+ jsenvRemoteDirectory,
8
+ url,
10
9
 
11
10
  babelPluginMap,
12
11
  moduleOutFormat = "esmodule",
@@ -16,6 +15,9 @@ export const transformJs = async ({
16
15
  topLevelAwait,
17
16
  transformGenerator = true,
18
17
  sourcemapEnabled = true,
18
+
19
+ map,
20
+ code,
19
21
  }) => {
20
22
  if (typeof projectDirectoryUrl !== "string") {
21
23
  throw new TypeError(
@@ -40,12 +42,14 @@ export const transformJs = async ({
40
42
  }
41
43
 
42
44
  const transformResult = await jsenvTransform({
43
- code,
44
- map,
45
45
  url,
46
46
  relativeUrl: url.startsWith(projectDirectoryUrl)
47
47
  ? urlToRelativeUrl(url, projectDirectoryUrl)
48
48
  : undefined,
49
+ projectDirectoryUrl,
50
+ jsenvRemoteDirectory,
51
+ code,
52
+ map,
49
53
 
50
54
  babelPluginMap,
51
55
  moduleOutFormat,