@jsenv/core 36.1.3 → 36.2.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 (38) hide show
  1. package/dist/js/{global_this.js → global_this_js_classic.js} +3 -3
  2. package/dist/js/global_this_js_module.js +20 -0
  3. package/dist/js/inline_content.js +10 -0
  4. package/dist/jsenv_core.js +7479 -7675
  5. package/package.json +20 -20
  6. package/src/build/build.js +4 -4
  7. package/src/dev/file_service.js +1 -1
  8. package/src/kitchen/client/inline_content.js +17 -0
  9. package/src/kitchen/kitchen.js +7 -1
  10. package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +4 -1
  11. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +4 -1
  12. package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +4 -1
  13. package/src/plugins/plugins.js +1 -1
  14. package/src/kitchen/compat/features_compatibility.js +0 -220
  15. package/src/kitchen/compat/runtime_compat.js +0 -56
  16. package/src/plugins/reference_analysis/inline_content.js +0 -7
  17. package/src/plugins/transpilation/as_js_module/convert_js_classic_to_js_module.js +0 -45
  18. package/src/plugins/transpilation/as_js_module/jsenv_plugin_as_js_module.js +0 -78
  19. package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +0 -34
  20. package/src/plugins/transpilation/babel/global_this/client/global_this.js +0 -25
  21. package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +0 -52
  22. package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +0 -173
  23. package/src/plugins/transpilation/babel/helpers/babel_plugins_compatibility.js +0 -432
  24. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +0 -100
  25. package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +0 -142
  26. package/src/plugins/transpilation/babel/new_stylesheet/client/new_stylesheet.js +0 -381
  27. package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +0 -33
  28. package/src/plugins/transpilation/babel/regenerator_runtime/client/regenerator_runtime.js +0 -748
  29. package/src/plugins/transpilation/babel/require_babel_plugin.js +0 -8
  30. package/src/plugins/transpilation/css/jsenv_plugin_css_transpilation.js +0 -54
  31. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +0 -248
  32. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_conversion.js +0 -119
  33. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js +0 -46
  34. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +0 -240
  35. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +0 -62
  36. package/src/plugins/transpilation/jsenv_plugin_import_meta_resolve.js +0 -48
  37. package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +0 -87
  38. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +0 -56
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "36.1.3",
3
+ "version": "36.2.1",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -35,10 +35,10 @@
35
35
  "/src/"
36
36
  ],
37
37
  "workspaces": [
38
+ "./packages/independent/*",
38
39
  "./packages/internal/*",
39
- "./packages/plugins/*",
40
- "./packages/rest/*",
41
- "./packages/rest/create-jsenv/*"
40
+ "./packages/related/*",
41
+ "./packages/related/create-jsenv/*"
42
42
  ],
43
43
  "scripts": {
44
44
  "eslint": "npx eslint . --ext=.js,.mjs,.cjs,.html",
@@ -60,44 +60,44 @@
60
60
  "dependencies": {
61
61
  "@financial-times/polyfill-useragent-normaliser": "1.10.2",
62
62
  "@jsenv/abort": "4.2.4",
63
- "@jsenv/ast": "4.0.2",
64
- "@jsenv/babel-plugins": "1.1.6",
63
+ "@jsenv/ast": "4.0.3",
65
64
  "@jsenv/filesystem": "4.2.3",
66
65
  "@jsenv/importmap": "1.2.1",
67
66
  "@jsenv/integrity": "0.0.1",
68
67
  "@jsenv/log": "3.3.5",
69
68
  "@jsenv/node-esm-resolution": "1.0.1",
70
- "@jsenv/plugin-supervisor": "1.0.1",
71
- "@jsenv/js-module-fallback": "1.0.1",
69
+ "@jsenv/js-module-fallback": "1.0.4",
70
+ "@jsenv/runtime-compat": "1.0.0",
72
71
  "@jsenv/server": "15.0.3",
73
72
  "@jsenv/sourcemap": "1.0.10",
73
+ "@jsenv/plugin-transpilation": "1.0.0",
74
+ "@jsenv/plugin-supervisor": "1.1.0",
74
75
  "@jsenv/url-meta": "8.1.0",
75
76
  "@jsenv/urls": "2.0.0",
76
- "@jsenv/utils": "2.0.1",
77
- "construct-style-sheets-polyfill": "3.1.0",
78
- "lightningcss": "1.20.0"
77
+ "@jsenv/utils": "2.0.1"
79
78
  },
80
79
  "devDependencies": {
81
80
  "@babel/eslint-parser": "7.21.8",
82
81
  "@babel/plugin-syntax-import-assertions": "7.20.0",
83
- "@jsenv/assert": "./packages/rest/assert/",
84
- "@jsenv/eslint-config": "./packages/rest/eslint-config/",
85
- "@jsenv/file-size-impact": "14.1.1",
82
+ "babel-plugin-transform-async-to-promises": "0.8.18",
83
+ "@jsenv/assert": "./packages/independent/assert/",
86
84
  "@jsenv/core": "./",
85
+ "@jsenv/eslint-config": "./packages/independent/eslint-config/",
86
+ "@jsenv/file-size-impact": "14.1.1",
87
87
  "@jsenv/https-local": "3.0.6",
88
88
  "@jsenv/package-workspace": "0.5.2",
89
89
  "@jsenv/performance-impact": "4.1.1",
90
- "@jsenv/plugin-globals": "./packages/plugins/jsenv-plugin-globals/",
91
- "@jsenv/plugin-minification": "./packages/plugins/jsenv-plugin-minification/",
92
- "@jsenv/plugin-placeholders": "./packages/plugins/jsenv-plugin-placeholders/",
93
- "@jsenv/plugin-as-js-classic": "./packages/plugins/jsenv-plugin-as-js-classic/",
94
- "@jsenv/test": "./packages/rest/test/",
90
+ "@jsenv/plugin-globals": "./packages/related/plugin-globals/",
91
+ "@jsenv/plugin-minification": "./packages/related/plugin-minification/",
92
+ "@jsenv/plugin-placeholders": "./packages/related/plugin-placeholders/",
93
+ "@jsenv/plugin-as-js-classic": "./packages/related/plugin-as-js-classic/",
94
+ "@jsenv/test": "./packages/related/test/",
95
95
  "eslint": "8.41.0",
96
96
  "eslint-plugin-html": "7.1.0",
97
97
  "eslint-plugin-import": "2.27.5",
98
98
  "eslint-plugin-react": "7.32.2",
99
99
  "open": "9.1.0",
100
- "playwright": "1.34.2",
100
+ "playwright": "1.34.3",
101
101
  "prettier": "2.8.8"
102
102
  }
103
103
  }
@@ -52,22 +52,22 @@ import {
52
52
  insertHtmlNodeAfter,
53
53
  findHtmlNode,
54
54
  } from "@jsenv/ast";
55
+ import { RUNTIME_COMPAT } from "@jsenv/runtime-compat";
56
+ import { jsenvPluginJsModuleFallback } from "@jsenv/plugin-transpilation";
55
57
 
56
58
  import { lookupPackageDirectory } from "../helpers/lookup_package_directory.js";
57
59
  import { watchSourceFiles } from "../helpers/watch_source_files.js";
58
60
  import { createUrlGraph } from "../kitchen/url_graph.js";
59
61
  import { createKitchen } from "../kitchen/kitchen.js";
60
- import { RUNTIME_COMPAT } from "../kitchen/compat/runtime_compat.js";
61
62
  import { createUrlGraphLoader } from "../kitchen/url_graph/url_graph_loader.js";
62
63
  import { createUrlGraphSummary } from "../kitchen/url_graph/url_graph_report.js";
63
64
  import {
64
65
  isWebWorkerEntryPointReference,
65
66
  isWebWorkerUrlInfo,
66
67
  } from "../kitchen/web_workers.js";
68
+ import { getCorePlugins } from "../plugins/plugins.js";
67
69
  import { jsenvPluginReferenceAnalysis } from "../plugins/reference_analysis/jsenv_plugin_reference_analysis.js";
68
70
  import { jsenvPluginInlining } from "../plugins/inlining/jsenv_plugin_inlining.js";
69
- import { jsenvPluginJsModuleFallback } from "../plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js";
70
- import { getCorePlugins } from "../plugins/plugins.js";
71
71
  import { jsenvPluginLineBreakNormalization } from "./jsenv_plugin_line_break_normalization.js";
72
72
 
73
73
  import { GRAPH } from "./graph_utils.js";
@@ -343,8 +343,8 @@ build ${entryPointKeys.length} entry points`);
343
343
  magicDirectoryIndex,
344
344
  directoryReferenceAllowed,
345
345
  transpilation: {
346
- ...transpilation,
347
346
  babelHelpersAsImport: !explicitJsModuleFallback,
347
+ ...transpilation,
348
348
  jsModuleFallbackOnJsClassic: false,
349
349
  },
350
350
 
@@ -3,12 +3,12 @@ import { serveDirectory, composeTwoResponses } from "@jsenv/server";
3
3
  import { bufferToEtag } from "@jsenv/filesystem";
4
4
  import { asUrlWithoutSearch } from "@jsenv/urls";
5
5
  import { URL_META } from "@jsenv/url-meta";
6
+ import { RUNTIME_COMPAT } from "@jsenv/runtime-compat";
6
7
 
7
8
  import { WEB_URL_CONVERTER } from "../helpers/web_url_converter.js";
8
9
  import { watchSourceFiles } from "../helpers/watch_source_files.js";
9
10
  import { createUrlGraph } from "../kitchen/url_graph.js";
10
11
  import { createKitchen } from "../kitchen/kitchen.js";
11
- import { RUNTIME_COMPAT } from "../kitchen/compat/runtime_compat.js";
12
12
  import { getCorePlugins } from "../plugins/plugins.js";
13
13
  import { jsenvPluginServerEventsClientInjection } from "../plugins/server_events/jsenv_plugin_server_events_client_injection.js";
14
14
  import { parseUserAgentHeader } from "./user_agent.js";
@@ -0,0 +1,17 @@
1
+ /* eslint-env browser,node */
2
+
3
+ /*
4
+ * This file does not use export const InlineContent = function() {} on purpose:
5
+ * - An export would be renamed by rollup,
6
+ * making it harder to statically detect new InlineContent() calls
7
+ * - An export would be renamed by terser
8
+ * here again it becomes hard to detect new InlineContent() calls
9
+ * Instead it sets "__InlineContent__" on the global object and terser is configured by jsenv
10
+ * to preserve the __InlineContent__ global variable name
11
+ */
12
+
13
+ const globalObject = typeof self === "object" ? self : process;
14
+ globalObject.__InlineContent__ = function (content, { type = "text/plain" }) {
15
+ this.text = content;
16
+ this.type = type;
17
+ };
@@ -10,11 +10,11 @@ import { URL_META } from "@jsenv/url-meta";
10
10
  import { writeFileSync, ensureWindowsDriveLetter } from "@jsenv/filesystem";
11
11
  import { createLogger, createDetailedMessage, ANSI } from "@jsenv/log";
12
12
  import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js";
13
+ import { RUNTIME_COMPAT } from "@jsenv/runtime-compat";
13
14
 
14
15
  import { createPluginController } from "../plugins/plugin_controller.js";
15
16
  import { urlSpecifierEncoding } from "./url_specifier_encoding.js";
16
17
  import { createUrlInfoTransformer } from "./url_graph/url_info_transformations.js";
17
- import { RUNTIME_COMPAT } from "./compat/runtime_compat.js";
18
18
  import {
19
19
  createResolveUrlError,
20
20
  createFetchUrlContentError,
@@ -24,6 +24,11 @@ import {
24
24
  import { assertFetchedContentCompliance } from "./fetched_content_compliance.js";
25
25
  import { isWebWorkerEntryPointReference } from "./web_workers.js";
26
26
 
27
+ const inlineContentClientFileUrl = new URL(
28
+ "./client/inline_content.js",
29
+ import.meta.url,
30
+ ).href;
31
+
27
32
  export const createKitchen = ({
28
33
  signal,
29
34
  logLevel,
@@ -531,6 +536,7 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
531
536
  // references
532
537
  const references = [];
533
538
  context.referenceUtils = {
539
+ inlineContentClientFileUrl,
534
540
  _references: references,
535
541
  find: (predicate) => references.find(predicate),
536
542
  readGeneratedSpecifier,
@@ -42,7 +42,10 @@ export const jsenvPluginCommonJsGlobals = () => {
42
42
  },
43
43
  ],
44
44
  ],
45
- urlInfo,
45
+ input: urlInfo.content,
46
+ inputIsJsModule: urlInfo.type === "js_module",
47
+ inputUrl: urlInfo.originalUrl,
48
+ outputUrl: urlInfo.generatedUrl,
46
49
  });
47
50
  const { expressionPaths } = metadata;
48
51
  const keys = Object.keys(expressionPaths);
@@ -55,7 +55,10 @@ export const jsenvPluginImportMetaHot = () => {
55
55
  }
56
56
  const { metadata } = await applyBabelPlugins({
57
57
  babelPlugins: [babelPluginMetadataImportMetaHot],
58
- urlInfo,
58
+ input: urlInfo.content,
59
+ inputIsJsModule: true,
60
+ inputUrl: urlInfo.originalUrl,
61
+ outputUrl: urlInfo.generatedUrl,
59
62
  });
60
63
  const {
61
64
  importMetaHotPaths,
@@ -26,7 +26,10 @@ export const jsenvPluginImportMetaScenarios = () => {
26
26
  }
27
27
  const { metadata } = await applyBabelPlugins({
28
28
  babelPlugins: [babelPluginMetadataImportMetaScenarios],
29
- urlInfo,
29
+ input: urlInfo.content,
30
+ inputIsJsModule: true,
31
+ inputUrl: urlInfo.originalUrl,
32
+ outputUrl: urlInfo.generatedUrl,
30
33
  });
31
34
  const { dev = [], build = [] } = metadata.importMetaScenarios;
32
35
  const replacements = [];
@@ -1,4 +1,5 @@
1
1
  import { jsenvPluginSupervisor } from "@jsenv/plugin-supervisor";
2
+ import { jsenvPluginTranspilation } from "@jsenv/plugin-transpilation";
2
3
 
3
4
  import { jsenvPluginReferenceAnalysis } from "./reference_analysis/jsenv_plugin_reference_analysis.js";
4
5
  import { jsenvPluginImportmap } from "./importmap/jsenv_plugin_importmap.js";
@@ -11,7 +12,6 @@ import { jsenvPluginInlining } from "./inlining/jsenv_plugin_inlining.js";
11
12
  import { jsenvPluginCommonJsGlobals } from "./commonjs_globals/jsenv_plugin_commonjs_globals.js";
12
13
  import { jsenvPluginImportMetaScenarios } from "./import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js";
13
14
  import { jsenvPluginGlobalScenarios } from "./global_scenarios/jsenv_plugin_global_scenarios.js";
14
- import { jsenvPluginTranspilation } from "./transpilation/jsenv_plugin_transpilation.js";
15
15
  import { jsenvPluginNodeRuntime } from "./node_runtime/jsenv_plugin_node_runtime.js";
16
16
  // autoreload
17
17
  import { jsenvPluginImportMetaHot } from "./import_meta_hot/jsenv_plugin_import_meta_hot.js";
@@ -1,220 +0,0 @@
1
- export const featuresCompatMap = {
2
- script_type_module: {
3
- edge: "16",
4
- firefox: "60",
5
- chrome: "61",
6
- safari: "10.1",
7
- opera: "48",
8
- ios: "10.3",
9
- android: "61",
10
- samsung: "8.2",
11
- },
12
- document_current_script: {
13
- edge: "12",
14
- firefox: "4",
15
- chrome: "29",
16
- safari: "8",
17
- opera: "16",
18
- android: "4.4",
19
- samsung: "4",
20
- },
21
- // https://caniuse.com/?search=import.meta
22
- import_meta: {
23
- android: "9",
24
- chrome: "64",
25
- edge: "79",
26
- firefox: "62",
27
- ios: "12",
28
- opera: "51",
29
- safari: "11.1",
30
- samsung: "9.2",
31
- },
32
- import_meta_resolve: {
33
- chrome: "107",
34
- edge: "105",
35
- firefox: "106",
36
- },
37
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
38
- import_dynamic: {
39
- android: "8",
40
- chrome: "63",
41
- edge: "79",
42
- firefox: "67",
43
- ios: "11.3",
44
- opera: "50",
45
- safari: "11.3",
46
- samsung: "8.0",
47
- node: "13.2",
48
- },
49
- top_level_await: {
50
- edge: "89",
51
- chrome: "89",
52
- firefox: "89",
53
- opera: "75",
54
- safari: "15",
55
- samsung: "15",
56
- ios: "15",
57
- node: "14.8",
58
- },
59
- // https://caniuse.com/import-maps
60
- importmap: {
61
- edge: "89",
62
- chrome: "89",
63
- opera: "76",
64
- samsung: "15",
65
- firefox: "108",
66
- safari: "16.4",
67
- },
68
- import_type_json: {
69
- chrome: "91",
70
- edge: "91",
71
- },
72
- import_type_css: {
73
- chrome: "93",
74
- edge: "93",
75
- },
76
- import_type_text: {},
77
- // https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet#browser_compatibility
78
- new_stylesheet: {
79
- chrome: "73",
80
- edge: "79",
81
- opera: "53",
82
- android: "73",
83
- },
84
- // https://caniuse.com/?search=worker
85
- worker: {
86
- ie: "10",
87
- edge: "12",
88
- firefox: "3.5",
89
- chrome: "4",
90
- opera: "11.5",
91
- safari: "4",
92
- ios: "5",
93
- android: "4.4",
94
- },
95
- // https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker#browser_compatibility
96
- worker_type_module: {
97
- chrome: "80",
98
- edge: "80",
99
- opera: "67",
100
- android: "80",
101
- },
102
- worker_importmap: {},
103
- service_worker: {
104
- edge: "17",
105
- firefox: "44",
106
- chrome: "40",
107
- safari: "11.1",
108
- opera: "27",
109
- ios: "11.3",
110
- android: "12.12",
111
- },
112
- service_worker_type_module: {
113
- chrome: "80",
114
- edge: "80",
115
- opera: "67",
116
- android: "80",
117
- },
118
- shared_worker: {
119
- chrome: "4",
120
- edge: "79",
121
- firefox: "29",
122
- opera: "10.6",
123
- },
124
- shared_worker_type_module: {
125
- chrome: "80",
126
- edge: "80",
127
- opera: "67",
128
- },
129
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis#browser_compatibility
130
- global_this: {
131
- edge: "79",
132
- firefox: "65",
133
- chrome: "71",
134
- safari: "12.1",
135
- opera: "58",
136
- ios: "12.2",
137
- android: "94",
138
- node: "12",
139
- },
140
- async_generator_function: {
141
- chrome: "63",
142
- opera: "50",
143
- edge: "79",
144
- firefox: "57",
145
- safari: "12",
146
- node: "10",
147
- ios: "12",
148
- samsung: "8",
149
- electron: "3",
150
- },
151
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#browser_compatibility
152
- template_literals: {
153
- chrome: "41",
154
- edge: "12",
155
- firefox: "34",
156
- opera: "28",
157
- safari: "9",
158
- ios: "9",
159
- android: "4",
160
- node: "4",
161
- },
162
- arrow_function: {
163
- chrome: "47",
164
- opera: "34",
165
- edge: "13",
166
- firefox: "45",
167
- safari: "10",
168
- node: "6",
169
- ios: "10",
170
- samsung: "5",
171
- electron: "0.36",
172
- },
173
- const_bindings: {
174
- chrome: "41",
175
- opera: "28",
176
- edge: "12",
177
- firefox: "46",
178
- safari: "10",
179
- node: "4",
180
- ie: "11",
181
- ios: "10",
182
- samsung: "3.4",
183
- electron: "0.22",
184
- },
185
- object_properties_shorthand: {
186
- chrome: "43",
187
- opera: "30",
188
- edge: "12",
189
- firefox: "33",
190
- safari: "9",
191
- node: "4",
192
- ios: "9",
193
- samsung: "4",
194
- electron: "0.28",
195
- },
196
- reserved_words: {
197
- chrome: "13",
198
- opera: "10.50",
199
- edge: "12",
200
- firefox: "2",
201
- safari: "3.1",
202
- node: "0.10",
203
- ie: "9",
204
- android: "4.4",
205
- ios: "6",
206
- phantom: "2",
207
- samsung: "1",
208
- electron: "0.20",
209
- },
210
- symbols: {
211
- chrome: "38",
212
- opera: "25",
213
- edge: "12",
214
- firefox: "36",
215
- safari: "9",
216
- ios: "9",
217
- samsung: "4",
218
- node: "0.12",
219
- },
220
- };
@@ -1,56 +0,0 @@
1
- import { findHighestVersion } from "@jsenv/utils/src/semantic_versioning/highest_version.js";
2
-
3
- import { featuresCompatMap } from "./features_compatibility.js";
4
-
5
- export const RUNTIME_COMPAT = {
6
- featuresCompatMap,
7
-
8
- add: (originalRuntimeCompat, feature) => {
9
- const featureCompat = getFeatureCompat(feature);
10
- const runtimeCompat = {
11
- ...originalRuntimeCompat,
12
- };
13
- Object.keys(originalRuntimeCompat).forEach((runtimeName) => {
14
- const secondVersion = featureCompat[runtimeName]; // the version supported by the feature
15
- if (secondVersion) {
16
- const firstVersion = originalRuntimeCompat[runtimeName];
17
- runtimeCompat[runtimeName] = findHighestVersion(
18
- firstVersion,
19
- secondVersion,
20
- );
21
- }
22
- });
23
- return runtimeCompat;
24
- },
25
-
26
- isSupported: (runtimeCompat, feature) => {
27
- const featureCompat = getFeatureCompat(feature);
28
- const runtimeNames = Object.keys(runtimeCompat);
29
- const runtimeWithoutCompat = runtimeNames.find((runtimeName) => {
30
- const runtimeVersion = runtimeCompat[runtimeName];
31
- const runtimeVersionCompatible = featureCompat[runtimeName] || "Infinity";
32
- const highestVersion = findHighestVersion(
33
- runtimeVersion,
34
- runtimeVersionCompatible,
35
- );
36
- return highestVersion !== runtimeVersion;
37
- });
38
- return !runtimeWithoutCompat;
39
- },
40
- };
41
-
42
- const getFeatureCompat = (feature) => {
43
- if (typeof feature === "string") {
44
- const compat = featuresCompatMap[feature];
45
- if (!compat) {
46
- throw new Error(`"${feature}" feature is unknown`);
47
- }
48
- return compat;
49
- }
50
- if (typeof feature !== "object") {
51
- throw new TypeError(
52
- `feature must be a string or an object, got ${feature}`,
53
- );
54
- }
55
- return feature;
56
- };
@@ -1,7 +0,0 @@
1
- /* eslint-env browser,node */
2
-
3
- const globalObject = typeof self === "object" ? self : process;
4
- globalObject.__InlineContent__ = function (content, { type = "text/plain" }) {
5
- this.text = content;
6
- this.type = type;
7
- };
@@ -1,45 +0,0 @@
1
- import { applyBabelPlugins } from "@jsenv/ast";
2
- import { composeTwoSourcemaps } from "@jsenv/sourcemap";
3
-
4
- import { isWebWorkerUrlInfo } from "@jsenv/core/src/kitchen/web_workers.js";
5
-
6
- export const convertJsClassicToJsModule = async ({
7
- urlInfo,
8
- jsClassicUrlInfo,
9
- }) => {
10
- const { code, map } = await applyBabelPlugins({
11
- babelPlugins: [
12
- [
13
- babelPluginReplaceTopLevelThis,
14
- {
15
- isWebWorker: isWebWorkerUrlInfo(urlInfo),
16
- },
17
- ],
18
- ],
19
- urlInfo: jsClassicUrlInfo,
20
- });
21
- const sourcemap = await composeTwoSourcemaps(jsClassicUrlInfo.sourcemap, map);
22
- return {
23
- content: code,
24
- sourcemap,
25
- };
26
- };
27
-
28
- const babelPluginReplaceTopLevelThis = () => {
29
- return {
30
- name: "replace-top-level-this",
31
- visitor: {
32
- Program: (programPath, state) => {
33
- const { isWebWorker } = state.opts;
34
- programPath.traverse({
35
- ThisExpression: (path) => {
36
- const closestFunction = path.getFunctionParent();
37
- if (!closestFunction) {
38
- path.replaceWithSourceString(isWebWorker ? "self" : "window");
39
- }
40
- },
41
- });
42
- },
43
- },
44
- };
45
- };
@@ -1,78 +0,0 @@
1
- /*
2
- * Js modules might not be able to import js meant to be loaded by <script>
3
- * Among other things this happens for a top level this:
4
- * - With <script> this is window
5
- * - With an import this is undefined
6
- * Example of this: https://github.com/video-dev/hls.js/issues/2911
7
- *
8
- * This plugin fix this issue by rewriting top level this into window
9
- * and can be used like this for instance import("hls?as_js_module")
10
- */
11
-
12
- import { urlToFilename } from "@jsenv/urls";
13
-
14
- import { convertJsClassicToJsModule } from "./convert_js_classic_to_js_module.js";
15
-
16
- export const jsenvPluginAsJsModule = () => {
17
- return {
18
- name: "jsenv:as_js_module",
19
- appliesDuring: "*",
20
- redirectReference: (reference) => {
21
- if (reference.searchParams.has("as_js_module")) {
22
- reference.expectedType = "js_module";
23
- const filename = urlToFilename(reference.url);
24
- const [basename] = splitFileExtension(filename);
25
- reference.filename = `${basename}.mjs`;
26
- }
27
- },
28
- fetchUrlContent: async (urlInfo, context) => {
29
- const [jsClassicReference, jsClassicUrlInfo] =
30
- context.getWithoutSearchParam({
31
- urlInfo,
32
- context,
33
- searchParam: "as_js_module",
34
- // override the expectedType to "js_classic"
35
- // because when there is ?as_js_module it means the underlying resource
36
- // is js_classic
37
- expectedType: "js_classic",
38
- });
39
- if (!jsClassicReference) {
40
- return null;
41
- }
42
- await context.fetchUrlContent(jsClassicUrlInfo, {
43
- reference: jsClassicReference,
44
- });
45
- if (context.dev) {
46
- context.referenceUtils.found({
47
- type: "js_import",
48
- subtype: jsClassicReference.subtype,
49
- specifier: jsClassicReference.url,
50
- expectedType: "js_classic",
51
- });
52
- } else if (context.build && jsClassicUrlInfo.dependents.size === 0) {
53
- context.urlGraph.deleteUrlInfo(jsClassicUrlInfo.url);
54
- }
55
- const { content, sourcemap } = await convertJsClassicToJsModule({
56
- urlInfo,
57
- jsClassicUrlInfo,
58
- });
59
- return {
60
- content,
61
- contentType: "text/javascript",
62
- type: "js_module",
63
- originalUrl: jsClassicUrlInfo.originalUrl,
64
- originalContent: jsClassicUrlInfo.originalContent,
65
- sourcemap,
66
- data: jsClassicUrlInfo.data,
67
- };
68
- },
69
- };
70
- };
71
-
72
- const splitFileExtension = (filename) => {
73
- const dotLastIndex = filename.lastIndexOf(".");
74
- if (dotLastIndex === -1) {
75
- return [filename, ""];
76
- }
77
- return [filename.slice(0, dotLastIndex), filename.slice(dotLastIndex)];
78
- };