@jsenv/core 25.1.1 → 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 (58) 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 +7 -7
  15. package/readme.md +43 -49
  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 +4 -1
  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 +92 -68
  25. package/src/internal/building/js/parseJsRessource.js +4 -7
  26. package/src/internal/building/parseRessource.js +3 -0
  27. package/src/internal/building/ressource_builder.js +64 -62
  28. package/src/internal/building/ressource_builder_util.js +17 -5
  29. package/src/internal/building/rollup_plugin_jsenv.js +259 -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/createCompiledFileService.js +22 -24
  41. package/src/internal/compiling/html_source_file_service.js +9 -9
  42. package/src/internal/compiling/js-compilation-service/jsenvTransform.js +14 -4
  43. package/src/internal/compiling/js-compilation-service/transformJs.js +9 -5
  44. package/src/internal/compiling/jsenvCompilerForHtml.js +221 -182
  45. package/src/internal/compiling/jsenvCompilerForJavaScript.js +15 -11
  46. package/src/internal/compiling/startCompileServer.js +79 -19
  47. package/src/internal/compiling/transformResultToCompilationResult.js +47 -25
  48. package/src/internal/executing/executePlan.js +2 -0
  49. package/src/internal/fetchUrl.js +3 -2
  50. package/src/internal/integrity/integrity_algorithms.js +26 -0
  51. package/src/internal/integrity/integrity_parsing.js +50 -0
  52. package/src/internal/integrity/integrity_update.js +23 -0
  53. package/src/internal/integrity/integrity_validation.js +49 -0
  54. package/src/internal/jsenv_remote_directory.js +156 -0
  55. package/src/internal/origin_directory_converter.js +62 -0
  56. package/src/internal/response_validation.js +11 -24
  57. package/src/internal/sourceMappingURLUtils.js +10 -0
  58. package/src/internal/url_conversion.js +1 -0
@@ -232,22 +232,23 @@ 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
+ if (type === "module" && textNode) {
251
252
  const scriptId = getIdForInlineHtmlNode(script, scripts)
252
253
  const scriptSpecifier = `${urlToFilename(
253
254
  fileUrl,
@@ -274,7 +275,8 @@ const transformHTMLSourceFile = async ({
274
275
  projectDirectoryUrl,
275
276
  })
276
277
 
277
- return stringifyHtmlAst(htmlAst)
278
+ const htmlTransformed = stringifyHtmlAst(htmlAst)
279
+ return htmlTransformed
278
280
  }
279
281
 
280
282
  const visitImportmapScripts = async ({
@@ -314,14 +316,12 @@ const visitImportmapScripts = async ({
314
316
  )
315
317
  return
316
318
  }
317
-
318
319
  const importMapContent = await importMapResponse.json()
319
320
  const importMapInlined = moveImportMap(
320
321
  importMapContent,
321
322
  importMapUrl,
322
323
  htmlFileUrl,
323
324
  )
324
-
325
325
  replaceHtmlNode(
326
326
  importmapScript,
327
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,