@jsenv/core 24.6.3 → 25.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/browser_runtime/asset-manifest.json +2 -1
  2. package/dist/browser_runtime/{browser_runtime-c7288751.js → browser_runtime_91c5a3b8.js} +213 -109
  3. package/dist/browser_runtime/browser_runtime_91c5a3b8.js.map +1089 -0
  4. package/dist/build_manifest.js +6 -6
  5. package/dist/compile_proxy/asset-manifest.json +2 -1
  6. package/dist/compile_proxy/{compile_proxy-28148b58.html → compile_proxy_7ad5faa6.html} +133 -40
  7. package/dist/compile_proxy/{compile_proxy.html__inline__20-4887fb1d.js.map → compile_proxy_e3b0c442_809f35f7.js.map} +7 -7
  8. package/dist/event_source_client/asset-manifest.json +2 -1
  9. package/dist/event_source_client/{event_source_client-9f14c8b9.js → event_source_client_620fbc2c.js} +6 -12
  10. package/dist/event_source_client/{event_source_client-9f14c8b9.js.map → event_source_client_620fbc2c.js.map} +2 -2
  11. package/dist/redirector/asset-manifest.json +2 -1
  12. package/dist/redirector/{redirector.html__inline__15-19e529b9.js.map → redirector_e3b0c442_e391410e.js.map} +7 -7
  13. package/dist/redirector/{redirector-3c05dbb2.html → redirector_eb92e8a7.html} +133 -40
  14. package/dist/toolbar/asset-manifest.json +11 -10
  15. package/dist/toolbar/assets/{compilation.css-209d68b4.map → compilation.css_e37c747b.map} +1 -1
  16. package/dist/toolbar/assets/{eventsource.css-38cd0a36.map → eventsource.css_c0c71e7b.map} +1 -1
  17. package/dist/toolbar/assets/{execution.css-0ebe522f.map → execution.css_f3377c10.map} +1 -1
  18. package/dist/toolbar/assets/{focus.css-3f9c156d.map → focus.css_896f3e45.map} +1 -1
  19. package/dist/toolbar/assets/{light-theme.css-78b19a80.map → light-theme.css_72a60fa3.map} +1 -1
  20. package/dist/toolbar/assets/{overflow-menu.css-d9688a1c.map → overflow-menu.css_2859d519.map} +1 -1
  21. package/dist/toolbar/assets/{settings.css-2b81b245.map → settings.css_61548139.map} +1 -1
  22. package/dist/toolbar/assets/{toolbar.main.css-846920e9.map → toolbar.main.css_269d7ce2.map} +9 -9
  23. package/dist/toolbar/assets/{tooltip.css-03395ee6.map → tooltip.css_a94a8bdd.map} +1 -1
  24. package/dist/toolbar/{toolbar.main-eb8acf83.js.map → toolbar.main2_6c1b3d82.js.map} +9 -9
  25. package/dist/toolbar/{toolbar-bab473ea.html → toolbar_04ba410c.html} +155 -62
  26. package/dist/toolbar_injector/asset-manifest.json +3 -2
  27. package/dist/toolbar_injector/assets/{jsenv-logo-188b9ca6.svg → jsenv-logo_188b9ca6.svg} +0 -0
  28. package/dist/toolbar_injector/{toolbar_injector-5e32f96a.js → toolbar_injector_4a48bc53.js} +25 -26
  29. package/dist/toolbar_injector/{toolbar_injector-5e32f96a.js.map → toolbar_injector_4a48bc53.js.map} +4 -5
  30. package/package.json +6 -5
  31. package/readme.md +34 -111
  32. package/src/buildProject.js +45 -32
  33. package/src/dev_server.js +13 -3
  34. package/src/execute.js +7 -1
  35. package/src/executeTestPlan.js +6 -0
  36. package/src/internal/browser_feature_detection/browser_feature_detection.js +18 -25
  37. package/src/internal/browser_runtime/browser_runtime.js +2 -2
  38. package/src/internal/browser_runtime/createBrowserRuntime.js +1 -1
  39. package/src/internal/browser_runtime/displayErrorInDocument.js +2 -0
  40. package/src/internal/browser_runtime/displayErrorNotification.js +1 -1
  41. package/src/internal/building/buildUsingRollup.js +12 -17
  42. package/src/internal/building/build_logs.js +2 -2
  43. package/src/internal/building/build_stats.js +11 -1
  44. package/src/internal/building/html/parseHtmlRessource.js +2 -26
  45. package/src/internal/building/js/parseJsRessource.js +3 -2
  46. package/src/internal/building/json_module.js +11 -0
  47. package/src/internal/building/parseRessource.js +1 -1
  48. package/src/internal/building/ressource_builder.js +210 -216
  49. package/src/internal/building/rollup_plugin_jsenv.js +536 -371
  50. package/src/internal/building/url_loader.js +8 -142
  51. package/src/internal/building/url_versioning.js +220 -0
  52. package/src/internal/compiling/compileHtml.js +8 -1
  53. package/src/internal/compiling/createCompiledFileService.js +32 -44
  54. package/src/internal/compiling/html_source_file_service.js +66 -51
  55. package/src/internal/compiling/js-compilation-service/babel_plugin_systemjs_prepend.js +23 -0
  56. package/src/internal/compiling/js-compilation-service/jsenvTransform.js +21 -63
  57. package/src/internal/compiling/js-compilation-service/transformJs.js +4 -4
  58. package/src/internal/compiling/jsenvCompilerForHtml.js +47 -48
  59. package/src/internal/compiling/jsenvCompilerForImportmap.js +15 -76
  60. package/src/internal/compiling/jsenvCompilerForJavaScript.js +11 -2
  61. package/src/internal/compiling/startCompileServer.js +31 -7
  62. package/src/internal/dev_server/toolbar/compilation/toolbar.compilation.js +9 -9
  63. package/src/internal/executing/executePlan.js +6 -0
  64. package/src/internal/generateGroupMap/{jsenvBabelPluginCompatMap.js → babel_plugins_compatibility.js} +0 -0
  65. package/src/internal/generateGroupMap/{featuresCompatMap.js → features_compatibility.js} +9 -1
  66. package/src/internal/generateGroupMap/generateGroupMap.js +6 -35
  67. package/src/internal/generateGroupMap/one_runtime_compat.js +9 -12
  68. package/src/internal/generateGroupMap/runtime_compat.js +10 -15
  69. package/src/internal/generateGroupMap/runtime_compat_composition.js +2 -2
  70. package/src/internal/generateGroupMap/shake_babel_plugin_map.js +21 -0
  71. package/src/internal/import-resolution/importmap_default.js +52 -0
  72. package/src/internal/node_feature_detection/node_feature_detection.js +25 -19
  73. package/src/internal/runtime/s.js +101 -6
  74. package/src/internal/unevalException.js +1 -1
  75. package/src/jsenvServiceWorkerFinalizer.js +10 -9
  76. package/dist/browser_runtime/browser_runtime-c7288751.js.map +0 -1069
  77. package/src/internal/building/asset_url_versioning.js +0 -50
  78. package/src/internal/building/rollup_build_sourcemap.js +0 -54
  79. package/src/internal/building/url-versioning.js +0 -96
  80. package/src/internal/compiling/js-compilation-service/findAsyncPluginNameInBabelPluginMap.js +0 -9
  81. package/src/internal/generateGroupMap/jsenvPluginCompatMap.js +0 -1
  82. package/src/internal/import-resolution/importmap-default.js +0 -34
  83. package/src/internal/renderNamePattern.js +0 -6
@@ -1,50 +0,0 @@
1
- import { computeBuildRelativeUrl } from "./url-versioning.js"
2
-
3
- export const computeBuildRelativeUrlForRessource = (
4
- ressource,
5
- { lineBreakNormalization },
6
- ) => {
7
- return computeBuildRelativeUrl(ressource.url, ressource.bufferAfterBuild, {
8
- pattern: fileNamePatternFromRessource(ressource),
9
- contentType: ressource.contentType,
10
- lineBreakNormalization,
11
- })
12
- }
13
-
14
- const assetFileNamePattern = "assets/[name]-[hash][extname]"
15
- const assetFileNamePatternWithoutHash = "assets/[name][extname]"
16
-
17
- const fileNamePatternFromRessource = (ressource) => {
18
- if (ressource.fileNamePattern) {
19
- return ressource.fileNamePattern
20
- }
21
-
22
- if (ressource.urlVersioningDisabled) {
23
- if (canMoveToAssetsDirectory(ressource)) {
24
- return assetFileNamePatternWithoutHash
25
- }
26
- return `[name][extname]`
27
- }
28
-
29
- if (canMoveToAssetsDirectory(ressource)) {
30
- return assetFileNamePattern
31
- }
32
- return `[name]-[hash][extname]`
33
- }
34
-
35
- const canMoveToAssetsDirectory = (ressource) => {
36
- if (ressource.isEntryPoint) {
37
- return false
38
- }
39
- // in theory js module can be moved to assets directory
40
- // but that needs to be tested
41
- if (ressource.isJsModule) {
42
- return false
43
- }
44
- // service worker MUST be at the root (same level than the HTML file)
45
- // otherwise it might be registered for the scope "/assets/" instead of "/"
46
- if (ressource.isServiceWorker) {
47
- return false
48
- }
49
- return true
50
- }
@@ -1,54 +0,0 @@
1
- import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem"
2
-
3
- import { setJavaScriptSourceMappingUrl } from "@jsenv/core/src/internal/sourceMappingURLUtils.js"
4
-
5
- export const injectSourcemapInRollupBuild = (
6
- rollupBuild,
7
- { buildDirectoryUrl },
8
- ) => {
9
- const rollupBuildWithSourcemap = {}
10
-
11
- Object.keys(rollupBuild).forEach((buildRelativeUrl) => {
12
- const rollupFileInfo = rollupBuild[buildRelativeUrl]
13
- const { type, code, map } = rollupFileInfo
14
-
15
- if (type === "asset" || !map) {
16
- rollupBuildWithSourcemap[buildRelativeUrl] = rollupFileInfo
17
- return
18
- }
19
-
20
- const sourcemapBuildRelativeUrl = `${buildRelativeUrl}.map`
21
- const sourcemapRollupFileInfo = rollupBuild[sourcemapBuildRelativeUrl]
22
- if (sourcemapRollupFileInfo) {
23
- rollupBuildWithSourcemap[buildRelativeUrl] = rollupFileInfo
24
- return
25
- }
26
-
27
- const fileBuildUrl = resolveUrl(buildRelativeUrl, buildDirectoryUrl)
28
- const sourcemapBuildUrl = resolveUrl(
29
- sourcemapBuildRelativeUrl,
30
- buildDirectoryUrl,
31
- )
32
- const fileSourcemapString = JSON.stringify(map, null, " ")
33
- const sourcemapBuildUrlRelativeToFileBuildUrl = urlToRelativeUrl(
34
- sourcemapBuildUrl,
35
- fileBuildUrl,
36
- )
37
- const codeWithSourcemapComment = setJavaScriptSourceMappingUrl(
38
- code,
39
- sourcemapBuildUrlRelativeToFileBuildUrl,
40
- )
41
-
42
- rollupBuildWithSourcemap[sourcemapBuildRelativeUrl] = {
43
- type: "asset",
44
- fileName: sourcemapBuildRelativeUrl,
45
- source: fileSourcemapString,
46
- }
47
- rollupBuildWithSourcemap[buildRelativeUrl] = {
48
- ...rollupFileInfo,
49
- code: codeWithSourcemapComment,
50
- }
51
- })
52
-
53
- return rollupBuildWithSourcemap
54
- }
@@ -1,96 +0,0 @@
1
- import { createHash } from "crypto"
2
- import {
3
- urlToParentUrl,
4
- urlToBasename,
5
- urlToExtension,
6
- } from "@jsenv/filesystem"
7
- import { renderNamePattern } from "../renderNamePattern.js"
8
-
9
- export const computeBuildRelativeUrl = (
10
- fileUrl,
11
- fileContent,
12
- {
13
- pattern = "[name]-[hash][extname]",
14
- contentType = "application/octet-stream",
15
- lineBreakNormalization = false,
16
- } = {},
17
- ) => {
18
- const buildRelativeUrl = renderNamePattern(
19
- typeof pattern === "function" ? pattern() : pattern,
20
- {
21
- dirname: () => urlToParentUrl(fileUrl),
22
- name: () => urlToBasename(fileUrl),
23
- hash: () =>
24
- generateContentHash(fileContent, {
25
- contentType,
26
- lineBreakNormalization,
27
- }),
28
- extname: () => urlToExtension(fileUrl),
29
- },
30
- )
31
- return buildRelativeUrl
32
- }
33
-
34
- // https://github.com/rollup/rollup/blob/19e50af3099c2f627451a45a84e2fa90d20246d5/src/utils/FileEmitter.ts#L47
35
- export const generateContentHash = (
36
- stringOrBuffer,
37
- {
38
- contentType = "application/octet-stream",
39
- lineBreakNormalization = false,
40
- } = {},
41
- ) => {
42
- const hash = createHash("sha256")
43
- hash.update(
44
- lineBreakNormalization && contentTypeIsTextual(contentType)
45
- ? normalizeLineBreaks(stringOrBuffer)
46
- : stringOrBuffer,
47
- )
48
- return hash.digest("hex").slice(0, 8)
49
- }
50
-
51
- const contentTypeIsTextual = (contentType) => {
52
- if (contentType.startsWith("text/")) {
53
- return true
54
- }
55
- // catch things like application/manifest+json, application/importmap+json
56
- if (/^application\/\w+\+json$/.test(contentType)) {
57
- return true
58
- }
59
- if (CONTENT_TYPE_AS_TEXT.includes(contentType)) {
60
- return true
61
- }
62
- return false
63
- }
64
-
65
- const CONTENT_TYPE_AS_TEXT = [
66
- "application/javascript",
67
- "application/json",
68
- "image/svg+xml",
69
- ]
70
-
71
- const normalizeLineBreaks = (stringOrBuffer) => {
72
- if (typeof stringOrBuffer === "string") {
73
- const stringWithLinuxBreaks = stringOrBuffer.replace(/\r\n/g, "\n")
74
- return stringWithLinuxBreaks
75
- }
76
- return normalizeLineBreaksForBuffer(stringOrBuffer)
77
- }
78
-
79
- // https://github.com/nodejs/help/issues/1738#issuecomment-458460503
80
- const normalizeLineBreaksForBuffer = (buffer) => {
81
- const int32Array = new Int32Array(buffer, 0, buffer.length)
82
- const int32ArrayWithLineBreaksNormalized = int32Array.filter(
83
- (element, index, typedArray) => {
84
- if (element === 0x0d) {
85
- if (typedArray[index + 1] === 0x0a) {
86
- // Windows -> Unix
87
- return false
88
- }
89
- // Mac OS -> Unix
90
- typedArray[index] = 0x0a
91
- }
92
- return true
93
- },
94
- )
95
- return Buffer.from(int32ArrayWithLineBreaksNormalized)
96
- }
@@ -1,9 +0,0 @@
1
- export const findAsyncPluginNameInBabelPluginMap = (babelPluginMap) => {
2
- if ("transform-async-to-promises" in babelPluginMap) {
3
- return "transform-async-to-promises"
4
- }
5
- if ("transform-async-to-generator" in babelPluginMap) {
6
- return "transform-async-to-generator"
7
- }
8
- return ""
9
- }
@@ -1 +0,0 @@
1
- export const jsenvPluginCompatMap = {}
@@ -1,34 +0,0 @@
1
- import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem"
2
-
3
- import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js"
4
-
5
- // in case there is no importmap, force the presence
6
- // so that '@jsenv/core/' are still remapped
7
- export const getDefaultImportMap = ({
8
- importMapFileUrl,
9
- projectDirectoryUrl,
10
- compileDirectoryRelativeUrl,
11
- }) => {
12
- const compileDirectoryUrl = resolveUrl(
13
- compileDirectoryRelativeUrl,
14
- projectDirectoryUrl,
15
- )
16
- const jsenvCoreDirectoryRelativeUrl = urlToRelativeUrl(
17
- jsenvCoreDirectoryUrl,
18
- projectDirectoryUrl,
19
- )
20
- const jsenvCoreDirectoryCompileUrl = resolveUrl(
21
- jsenvCoreDirectoryRelativeUrl,
22
- compileDirectoryUrl,
23
- )
24
- const jsenvCoreDirectoryUrlRelativeToImportMap = urlToRelativeUrl(
25
- jsenvCoreDirectoryCompileUrl,
26
- importMapFileUrl,
27
- )
28
-
29
- return {
30
- imports: {
31
- "@jsenv/core/": jsenvCoreDirectoryUrlRelativeToImportMap,
32
- },
33
- }
34
- }
@@ -1,6 +0,0 @@
1
- export const renderNamePattern = (pattern, replacements) => {
2
- return pattern.replace(/\[(\w+)\]/g, (_match, type) => {
3
- const replacement = replacements[type]()
4
- return replacement
5
- })
6
- }