@jsenv/core 36.1.3 → 36.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 (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
@@ -1,8 +0,0 @@
1
- import { createRequire } from "node:module";
2
- import { pathToFileURL } from "node:url";
3
- import { requireFromJsenv } from "@jsenv/core/src/helpers/require_from_jsenv.js";
4
-
5
- const babelPluginPackagePath = requireFromJsenv.resolve("@jsenv/babel-plugins");
6
- const babelPluginPackageUrl = pathToFileURL(babelPluginPackagePath);
7
-
8
- export const requireBabelPlugin = createRequire(babelPluginPackageUrl);
@@ -1,54 +0,0 @@
1
- import { fileURLToPath } from "node:url";
2
-
3
- export const jsenvPluginCssTranspilation = () => {
4
- return {
5
- name: "jsenv:css_transpilation",
6
- appliesDuring: "*",
7
- transformUrlContent: {
8
- css: async (urlInfo, context) => {
9
- const { code, map } = await transpileCss(urlInfo, context);
10
- return {
11
- content: String(code),
12
- sourcemap: map,
13
- };
14
- },
15
- },
16
- };
17
- };
18
-
19
- const transpileCss = async (urlInfo, context) => {
20
- // https://lightningcss.dev/docs.html
21
- const { transform } = await import("lightningcss");
22
-
23
- const targets = runtimeCompatToTargets(context.runtimeCompat);
24
- const { code, map } = transform({
25
- filename: fileURLToPath(urlInfo.originalUrl),
26
- code: Buffer.from(urlInfo.content),
27
- targets,
28
- minify: false,
29
- drafts: {
30
- nesting: true,
31
- customMedia: true,
32
- },
33
- });
34
- return { code, map };
35
- };
36
-
37
- const runtimeCompatToTargets = (runtimeCompat) => {
38
- const targets = {};
39
- ["chrome", "firefox", "ie", "opera", "safari"].forEach((runtimeName) => {
40
- const version = runtimeCompat[runtimeName];
41
- if (version) {
42
- targets[runtimeName] = versionToBits(version);
43
- }
44
- });
45
- return targets;
46
- };
47
-
48
- const versionToBits = (version) => {
49
- const [major, minor = 0, patch = 0] = version
50
- .split("-")[0]
51
- .split(".")
52
- .map((v) => parseInt(v, 10));
53
- return (major << 16) | (minor << 8) | patch;
54
- };
@@ -1,248 +0,0 @@
1
- /*
2
- * Jsenv wont touch code where "specifier" or "type" is dynamic (see code below)
3
- * ```js
4
- * const file = "./style.css"
5
- * const type = "css"
6
- * import(file, { assert: { type }})
7
- * ```
8
- * Jsenv could throw an error when it knows some browsers in runtimeCompat
9
- * do not support import assertions
10
- * But for now (as it is simpler) we let the browser throw the error
11
- */
12
-
13
- import { urlToFilename, injectQueryParams } from "@jsenv/urls";
14
-
15
- import { JS_QUOTES } from "@jsenv/utils/src/string/js_quotes.js";
16
-
17
- export const jsenvPluginImportAssertions = ({
18
- json = "auto",
19
- css = "auto",
20
- text = "auto",
21
- }) => {
22
- const transpilations = { json, css, text };
23
- const shouldTranspileImportAssertion = (context, type) => {
24
- const transpilation = transpilations[type];
25
- if (transpilation === true) {
26
- return true;
27
- }
28
- if (transpilation === "auto") {
29
- return !context.isSupportedOnCurrentClients(`import_type_${type}`);
30
- }
31
- return false;
32
- };
33
- const markAsJsModuleProxy = (reference) => {
34
- reference.expectedType = "js_module";
35
- reference.filename = `${urlToFilename(reference.url)}.js`;
36
- };
37
- const turnIntoJsModuleProxy = (reference, type) => {
38
- reference.mutation = (magicSource) => {
39
- const { assertNode } = reference;
40
- if (reference.subtype === "import_dynamic") {
41
- const assertPropertyNode = assertNode.properties.find(
42
- (prop) => prop.key.name === "assert",
43
- );
44
- const assertPropertyValue = assertPropertyNode.value;
45
- const typePropertyNode = assertPropertyValue.properties.find(
46
- (prop) => prop.key.name === "type",
47
- );
48
- magicSource.remove({
49
- start: typePropertyNode.start,
50
- end: typePropertyNode.end,
51
- });
52
- } else {
53
- magicSource.remove({
54
- start: assertNode.start,
55
- end: assertNode.end,
56
- });
57
- }
58
- };
59
- const newUrl = injectQueryParams(reference.url, {
60
- [`as_${type}_module`]: "",
61
- });
62
- markAsJsModuleProxy(reference);
63
- return newUrl;
64
- };
65
-
66
- const importAssertions = {
67
- name: "jsenv:import_assertions",
68
- appliesDuring: "*",
69
- init: (context) => {
70
- // transpilation is forced during build so that
71
- // - avoid rollup to see import assertions
72
- // We would have to tell rollup to ignore import with assertion
73
- // - means rollup can bundle more js file together
74
- // - means url versioning can work for css inlined in js
75
- if (context.build) {
76
- transpilations.json = true;
77
- transpilations.css = true;
78
- transpilations.text = true;
79
- }
80
- },
81
- redirectReference: (reference, context) => {
82
- if (!reference.assert) {
83
- return null;
84
- }
85
- const { searchParams } = reference;
86
- if (
87
- searchParams.has("as_json_module") ||
88
- searchParams.has("as_css_module") ||
89
- searchParams.has("as_text_module")
90
- ) {
91
- markAsJsModuleProxy(reference);
92
- return null;
93
- }
94
- const type = reference.assert.type;
95
- if (shouldTranspileImportAssertion(context, type)) {
96
- return turnIntoJsModuleProxy(reference, type);
97
- }
98
- return null;
99
- },
100
- };
101
- return [importAssertions, ...jsenvPluginAsModules()];
102
- };
103
-
104
- const jsenvPluginAsModules = () => {
105
- const inlineContentClientFileUrl = new URL(
106
- "../../reference_analysis/inline_content.js",
107
- import.meta.url,
108
- ).href;
109
-
110
- const asJsonModule = {
111
- name: `jsenv:as_json_module`,
112
- appliesDuring: "*",
113
- fetchUrlContent: async (urlInfo, context) => {
114
- const [jsonReference, jsonUrlInfo] = context.getWithoutSearchParam({
115
- urlInfo,
116
- context,
117
- searchParam: "as_json_module",
118
- expectedType: "json",
119
- });
120
- if (!jsonReference) {
121
- return null;
122
- }
123
- await context.fetchUrlContent(jsonUrlInfo, {
124
- reference: jsonReference,
125
- });
126
- if (context.dev) {
127
- context.referenceUtils.found({
128
- type: "js_import",
129
- subtype: jsonReference.subtype,
130
- specifier: jsonReference.url,
131
- expectedType: "js_module",
132
- });
133
- } else if (context.build && jsonUrlInfo.dependents.size === 0) {
134
- context.urlGraph.deleteUrlInfo(jsonUrlInfo.url);
135
- }
136
- const jsonText = JSON.stringify(jsonUrlInfo.content.trim());
137
- return {
138
- // here we could `export default ${jsonText}`:
139
- // but js engine are optimized to recognize JSON.parse
140
- // and use a faster parsing strategy
141
- content: `export default JSON.parse(${jsonText})`,
142
- contentType: "text/javascript",
143
- type: "js_module",
144
- originalUrl: jsonUrlInfo.originalUrl,
145
- originalContent: jsonUrlInfo.originalContent,
146
- data: jsonUrlInfo.data,
147
- };
148
- },
149
- };
150
-
151
- const asCssModule = {
152
- name: `jsenv:as_css_module`,
153
- appliesDuring: "*",
154
- fetchUrlContent: async (urlInfo, context) => {
155
- const [cssReference, cssUrlInfo] = context.getWithoutSearchParam({
156
- urlInfo,
157
- context,
158
- searchParam: "as_css_module",
159
- expectedType: "css",
160
- });
161
- if (!cssReference) {
162
- return null;
163
- }
164
- await context.fetchUrlContent(cssUrlInfo, {
165
- reference: cssReference,
166
- });
167
- if (context.dev) {
168
- context.referenceUtils.found({
169
- type: "js_import",
170
- subtype: cssReference.subtype,
171
- specifier: cssReference.url,
172
- expectedType: "js_module",
173
- });
174
- } else if (context.build && cssUrlInfo.dependents.size === 0) {
175
- context.urlGraph.deleteUrlInfo(cssUrlInfo.url);
176
- }
177
- const cssText = JS_QUOTES.escapeSpecialChars(cssUrlInfo.content, {
178
- // If template string is choosen and runtime do not support template literals
179
- // it's ok because "jsenv:new_inline_content" plugin executes after this one
180
- // and convert template strings into raw strings
181
- canUseTemplateString: true,
182
- });
183
- return {
184
- content: `import ${JSON.stringify(inlineContentClientFileUrl)}
185
-
186
- const inlineContent = new __InlineContent__(${cssText}, { type: "text/css" })
187
- const stylesheet = new CSSStyleSheet()
188
- stylesheet.replaceSync(inlineContent.text)
189
- export default stylesheet`,
190
- contentType: "text/javascript",
191
- type: "js_module",
192
- originalUrl: cssUrlInfo.originalUrl,
193
- originalContent: cssUrlInfo.originalContent,
194
- data: cssUrlInfo.data,
195
- };
196
- },
197
- };
198
-
199
- const asTextModule = {
200
- name: `jsenv:as_text_module`,
201
- appliesDuring: "*",
202
- fetchUrlContent: async (urlInfo, context) => {
203
- const [textReference, textUrlInfo] = context.getWithoutSearchParam({
204
- urlInfo,
205
- context,
206
- searchParam: "as_text_module",
207
- expectedType: "text",
208
- });
209
- if (!textReference) {
210
- return null;
211
- }
212
- await context.fetchUrlContent(textUrlInfo, {
213
- reference: textReference,
214
- });
215
- if (context.dev) {
216
- context.referenceUtils.found({
217
- type: "js_import",
218
- subtype: textReference.subtype,
219
- specifier: textReference.url,
220
- expectedType: "js_module",
221
- });
222
- } else if (context.build && textUrlInfo.dependents.size === 0) {
223
- context.urlGraph.deleteUrlInfo(textUrlInfo.url);
224
- }
225
- const textPlain = JS_QUOTES.escapeSpecialChars(urlInfo.content, {
226
- // If template string is choosen and runtime do not support template literals
227
- // it's ok because "jsenv:new_inline_content" plugin executes after this one
228
- // and convert template strings into raw strings
229
- canUseTemplateString: true,
230
- });
231
- return {
232
- content: `import { InlineContent } from ${JSON.stringify(
233
- inlineContentClientFileUrl,
234
- )}
235
-
236
- const inlineContent = new InlineContent(${textPlain}, { type: "text/plain" })
237
- export default inlineContent.text`,
238
- contentType: "text/javascript",
239
- type: "js_module",
240
- originalUrl: textUrlInfo.originalUrl,
241
- originalContent: textUrlInfo.originalContent,
242
- data: textUrlInfo.data,
243
- };
244
- },
245
- };
246
-
247
- return [asJsonModule, asCssModule, asTextModule];
248
- };
@@ -1,119 +0,0 @@
1
- /*
2
- * - propagate "?js_module_fallback" query string param on urls
3
- * - perform conversion from js module to js classic when url uses "?js_module_fallback"
4
- */
5
-
6
- import { injectQueryParams } from "@jsenv/urls";
7
- import { convertJsModuleToJsClassic } from "@jsenv/js-module-fallback";
8
-
9
- export const jsenvPluginJsModuleConversion = ({
10
- systemJsInjection,
11
- systemJsClientFileUrl,
12
- generateJsClassicFilename,
13
- }) => {
14
- const isReferencingJsModule = (reference) => {
15
- if (
16
- reference.type === "js_import" ||
17
- reference.subtype === "system_register_arg" ||
18
- reference.subtype === "system_import_arg"
19
- ) {
20
- return true;
21
- }
22
- if (reference.type === "js_url" && reference.expectedType === "js_module") {
23
- return true;
24
- }
25
- return false;
26
- };
27
-
28
- const shouldPropagateJsModuleConversion = (reference, context) => {
29
- if (isReferencingJsModule(reference, context)) {
30
- const parentUrlInfo = context.urlGraph.getUrlInfo(reference.parentUrl);
31
- if (!parentUrlInfo) {
32
- return false;
33
- }
34
- const parentGotAsJsClassic = new URL(parentUrlInfo.url).searchParams.has(
35
- "js_module_fallback",
36
- );
37
- return parentGotAsJsClassic;
38
- }
39
- return false;
40
- };
41
-
42
- const markAsJsClassicProxy = (reference) => {
43
- reference.expectedType = "js_classic";
44
- reference.filename = generateJsClassicFilename(reference.url);
45
- };
46
-
47
- const turnIntoJsClassicProxy = (reference) => {
48
- const urlTransformed = injectQueryParams(reference.url, {
49
- js_module_fallback: "",
50
- });
51
- markAsJsClassicProxy(reference);
52
- return urlTransformed;
53
- };
54
-
55
- return {
56
- name: "jsenv:js_module_conversion",
57
- appliesDuring: "*",
58
- redirectReference: (reference, context) => {
59
- if (reference.searchParams.has("js_module_fallback")) {
60
- markAsJsClassicProxy(reference);
61
- return null;
62
- }
63
- // We want to propagate transformation of js module to js classic to:
64
- // - import specifier (static/dynamic import + re-export)
65
- // - url specifier when inside System.register/_context.import()
66
- // (because it's the transpiled equivalent of static and dynamic imports)
67
- // And not other references otherwise we could try to transform inline resources
68
- // or specifiers inside new URL()...
69
- if (shouldPropagateJsModuleConversion(reference, context)) {
70
- return turnIntoJsClassicProxy(reference, context);
71
- }
72
- return null;
73
- },
74
- fetchUrlContent: async (urlInfo, context) => {
75
- const [jsModuleReference, jsModuleUrlInfo] =
76
- context.getWithoutSearchParam({
77
- urlInfo,
78
- context,
79
- searchParam: "js_module_fallback",
80
- // override the expectedType to "js_module"
81
- // because when there is ?js_module_fallback it means the underlying resource
82
- // is a js_module
83
- expectedType: "js_module",
84
- });
85
- if (!jsModuleReference) {
86
- return null;
87
- }
88
- await context.fetchUrlContent(jsModuleUrlInfo, {
89
- reference: jsModuleReference,
90
- });
91
- if (context.dev) {
92
- context.referenceUtils.found({
93
- type: "js_import",
94
- subtype: jsModuleReference.subtype,
95
- specifier: jsModuleReference.url,
96
- expectedType: "js_module",
97
- });
98
- } else if (context.build && jsModuleUrlInfo.dependents.size === 0) {
99
- context.urlGraph.deleteUrlInfo(jsModuleUrlInfo.url);
100
- }
101
- const { content, sourcemap } = await convertJsModuleToJsClassic({
102
- rootDirectoryUrl: context.rootDirectoryUrl,
103
- systemJsInjection,
104
- systemJsClientFileUrl,
105
- urlInfo,
106
- jsModuleUrlInfo,
107
- });
108
- return {
109
- content,
110
- contentType: "text/javascript",
111
- type: "js_classic",
112
- originalUrl: jsModuleUrlInfo.originalUrl,
113
- originalContent: jsModuleUrlInfo.originalContent,
114
- sourcemap,
115
- data: jsModuleUrlInfo.data,
116
- };
117
- },
118
- };
119
- };
@@ -1,46 +0,0 @@
1
- import { urlToFilename } from "@jsenv/urls";
2
- import { systemJsClientFileUrlDefault } from "@jsenv/js-module-fallback";
3
-
4
- import { jsenvPluginJsModuleConversion } from "./jsenv_plugin_js_module_conversion.js";
5
- import { jsenvPluginJsModuleFallbackInsideHtml } from "./jsenv_plugin_js_module_fallback_inside_html.js";
6
- import { jsenvPluginJsModuleFallbackOnWorkers } from "./jsenv_plugin_js_module_fallback_on_workers.js";
7
-
8
- export const jsenvPluginJsModuleFallback = ({
9
- systemJsInjection = true,
10
- systemJsClientFileUrl = systemJsClientFileUrlDefault,
11
- }) => {
12
- return [
13
- jsenvPluginJsModuleFallbackInsideHtml({
14
- systemJsInjection,
15
- systemJsClientFileUrl,
16
- }),
17
- jsenvPluginJsModuleFallbackOnWorkers(),
18
- jsenvPluginJsModuleConversion({
19
- systemJsInjection,
20
- systemJsClientFileUrl,
21
- generateJsClassicFilename,
22
- }),
23
- ];
24
- };
25
-
26
- const generateJsClassicFilename = (url) => {
27
- const filename = urlToFilename(url);
28
- let [basename, extension] = splitFileExtension(filename);
29
- const { searchParams } = new URL(url);
30
- if (
31
- searchParams.has("as_json_module") ||
32
- searchParams.has("as_css_module") ||
33
- searchParams.has("as_text_module")
34
- ) {
35
- extension = ".js";
36
- }
37
- return `${basename}.nomodule${extension}`;
38
- };
39
-
40
- const splitFileExtension = (filename) => {
41
- const dotLastIndex = filename.lastIndexOf(".");
42
- if (dotLastIndex === -1) {
43
- return [filename, ""];
44
- }
45
- return [filename.slice(0, dotLastIndex), filename.slice(dotLastIndex)];
46
- };