@jsenv/core 35.0.3 → 35.0.5
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.
- package/dist/html/explorer.html +107 -107
- package/dist/js/new_stylesheet.js +3 -0
- package/dist/js/s.js.map +3 -3
- package/package.json +2 -2
- package/src/build/build.js +589 -587
- package/src/build/build_urls_generator.js +44 -44
- package/src/build/graph_utils.js +14 -14
- package/src/build/jsenv_plugin_line_break_normalization.js +6 -6
- package/src/build/line_break_unix.js +11 -11
- package/src/build/start_build_server.js +37 -37
- package/src/build/version_generator.js +7 -7
- package/src/build/version_mappings_injection.js +23 -23
- package/src/dev/file_service.js +132 -132
- package/src/dev/start_dev_server.js +56 -56
- package/src/dev/user_agent.js +8 -8
- package/src/helpers/basic_fetch.js +24 -24
- package/src/helpers/command/command.js +28 -28
- package/src/helpers/lookup_package_directory.js +19 -16
- package/src/helpers/ping_server.js +17 -17
- package/src/helpers/require_from_jsenv.js +2 -2
- package/src/helpers/watch_source_files.js +9 -9
- package/src/helpers/web_url_converter.js +10 -10
- package/src/helpers/worker_reload.js +27 -27
- package/src/kitchen/compat/features_compatibility.js +1 -1
- package/src/kitchen/compat/runtime_compat.js +26 -24
- package/src/kitchen/errors.js +75 -75
- package/src/kitchen/fetched_content_compliance.js +8 -8
- package/src/kitchen/kitchen.js +251 -250
- package/src/kitchen/url_graph/sort_by_dependencies.js +17 -17
- package/src/kitchen/url_graph/url_graph_loader.js +30 -30
- package/src/kitchen/url_graph/url_graph_report.js +57 -57
- package/src/kitchen/url_graph/url_info_transformations.js +77 -77
- package/src/kitchen/url_graph.js +121 -121
- package/src/kitchen/url_specifier_encoding.js +21 -21
- package/src/kitchen/web_workers.js +5 -5
- package/src/main.js +3 -3
- package/src/plugins/autoreload/client/autoreload.js +96 -96
- package/src/plugins/autoreload/client/reload.js +56 -56
- package/src/plugins/autoreload/client/url_helpers.js +13 -13
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +5 -5
- package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +9 -9
- package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +61 -60
- package/src/plugins/autoreload/jsenv_plugin_hmr.js +15 -15
- package/src/plugins/cache_control/jsenv_plugin_cache_control.js +5 -5
- package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +57 -57
- package/src/plugins/explorer/client/explorer.html +107 -107
- package/src/plugins/explorer/jsenv_plugin_explorer.js +20 -20
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +60 -60
- package/src/plugins/global_scenarios/jsenv_plugin_global_scenarios.js +5 -5
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +3 -3
- package/src/plugins/import_meta_hot/babel_plugin_metadata_import_meta_hot.js +35 -35
- package/src/plugins/import_meta_hot/client/import_meta_hot.js +26 -26
- package/src/plugins/import_meta_hot/html_hot_dependencies.js +43 -43
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +44 -40
- package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +35 -35
- package/src/plugins/import_meta_url/client/import_meta_url_browser.js +21 -21
- package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +3 -3
- package/src/plugins/importmap/jsenv_plugin_importmap.js +54 -54
- package/src/plugins/inline_content_analysis/client/inline_content.js +3 -3
- package/src/plugins/inline_content_analysis/jsenv_plugin_data_urls.js +26 -26
- package/src/plugins/inline_content_analysis/jsenv_plugin_html_inline_content_analysis.js +47 -47
- package/src/plugins/inline_content_analysis/jsenv_plugin_inline_content_analysis.js +9 -9
- package/src/plugins/inline_content_analysis/jsenv_plugin_js_inline_content_analysis.js +101 -101
- package/src/plugins/inlining/jsenv_plugin_inlining.js +9 -9
- package/src/plugins/inlining/jsenv_plugin_inlining_as_data_url.js +11 -11
- package/src/plugins/inlining/jsenv_plugin_inlining_into_html.js +48 -46
- package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +4 -4
- package/src/plugins/plugin_controller.js +124 -124
- package/src/plugins/plugins.js +27 -27
- package/src/plugins/ribbon/client/ribbon.js +6 -6
- package/src/plugins/ribbon/jsenv_plugin_ribbon.js +15 -15
- package/src/plugins/server_events/client/connection_manager.js +52 -52
- package/src/plugins/server_events/client/event_source_connection.js +36 -36
- package/src/plugins/server_events/client/events_manager.js +37 -37
- package/src/plugins/server_events/client/server_events_client.js +7 -7
- package/src/plugins/server_events/client/web_socket_connection.js +39 -39
- package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +9 -9
- package/src/plugins/server_events/server_events_dispatcher.js +43 -43
- package/src/plugins/supervisor/client/supervisor.js +455 -450
- package/src/plugins/supervisor/html_supervisor_injection.js +64 -62
- package/src/plugins/supervisor/js_supervisor_injection.js +67 -67
- package/src/plugins/supervisor/jsenv_plugin_supervisor.js +54 -51
- package/src/plugins/transpilation/as_js_module/convert_js_classic_to_js_module.js +13 -13
- package/src/plugins/transpilation/as_js_module/jsenv_plugin_as_js_module.js +19 -19
- package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +10 -10
- package/src/plugins/transpilation/babel/global_this/client/global_this.js +8 -8
- package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +16 -16
- package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +36 -36
- package/src/plugins/transpilation/babel/helpers/babel_plugins_compatibility.js +3 -3
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +24 -24
- package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +44 -44
- package/src/plugins/transpilation/babel/new_stylesheet/client/new_stylesheet.js +166 -166
- package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +10 -10
- package/src/plugins/transpilation/babel/require_babel_plugin.js +6 -6
- package/src/plugins/transpilation/css/jsenv_plugin_css_transpilation.js +20 -20
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +62 -62
- package/src/plugins/transpilation/js_module_fallback/client/s.js +214 -209
- package/src/plugins/transpilation/js_module_fallback/convert_js_module_to_js_classic.js +45 -45
- package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_resolve.js +6 -6
- package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_url.js +17 -17
- package/src/plugins/transpilation/js_module_fallback/helpers-string.js +1 -1
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_conversion.js +32 -32
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js +17 -17
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +63 -63
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +15 -15
- package/src/plugins/transpilation/jsenv_plugin_import_meta_resolve.js +20 -20
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +23 -23
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +11 -11
- package/src/plugins/url_analysis/css/css_urls.js +12 -12
- package/src/plugins/url_analysis/html/html_urls.js +85 -85
- package/src/plugins/url_analysis/js/js_urls.js +16 -16
- package/src/plugins/url_analysis/jsenv_plugin_reference_expected_types.js +16 -16
- package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +40 -40
- package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +12 -12
- package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +35 -35
- package/src/plugins/url_resolution/node_esm_resolver.js +26 -26
- package/src/plugins/url_version/jsenv_plugin_url_version.js +11 -11
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* This plugin provides a way for jsenv to know when js execution is done
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { fileURLToPath } from "node:url"
|
|
6
|
-
import { getOriginalPosition } from "@jsenv/sourcemap"
|
|
7
|
-
import { stringifyUrlSite } from "@jsenv/urls"
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { getOriginalPosition } from "@jsenv/sourcemap";
|
|
7
|
+
import { stringifyUrlSite } from "@jsenv/urls";
|
|
8
8
|
|
|
9
|
-
import { injectSupervisorIntoHTML } from "./html_supervisor_injection.js"
|
|
10
|
-
import { requireFromJsenv } from "@jsenv/core/src/helpers/require_from_jsenv.js"
|
|
9
|
+
import { injectSupervisorIntoHTML } from "./html_supervisor_injection.js";
|
|
10
|
+
import { requireFromJsenv } from "@jsenv/core/src/helpers/require_from_jsenv.js";
|
|
11
11
|
|
|
12
12
|
export const supervisorFileUrl = new URL(
|
|
13
13
|
"./client/supervisor.js",
|
|
14
14
|
import.meta.url,
|
|
15
|
-
).href
|
|
15
|
+
).href;
|
|
16
16
|
|
|
17
17
|
export const jsenvPluginSupervisor = ({
|
|
18
18
|
logs = false,
|
|
@@ -26,42 +26,44 @@ export const jsenvPluginSupervisor = ({
|
|
|
26
26
|
appliesDuring: "dev",
|
|
27
27
|
serve: async (request, context) => {
|
|
28
28
|
if (request.pathname.startsWith("/__get_code_frame__/")) {
|
|
29
|
-
const { pathname, searchParams } = new URL(request.url)
|
|
30
|
-
let urlWithLineAndColumn = pathname.slice(
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const { pathname, searchParams } = new URL(request.url);
|
|
30
|
+
let urlWithLineAndColumn = pathname.slice(
|
|
31
|
+
"/__get_code_frame__/".length,
|
|
32
|
+
);
|
|
33
|
+
urlWithLineAndColumn = decodeURIComponent(urlWithLineAndColumn);
|
|
34
|
+
const match = urlWithLineAndColumn.match(/:([0-9]+):([0-9]+)$/);
|
|
33
35
|
if (!match) {
|
|
34
36
|
return {
|
|
35
37
|
status: 400,
|
|
36
38
|
body: "Missing line and column in url",
|
|
37
|
-
}
|
|
39
|
+
};
|
|
38
40
|
}
|
|
39
|
-
const file = urlWithLineAndColumn.slice(0, match.index)
|
|
40
|
-
let line = parseInt(match[1])
|
|
41
|
-
let column = parseInt(match[2])
|
|
42
|
-
const urlInfo = context.urlGraph.getUrlInfo(file)
|
|
41
|
+
const file = urlWithLineAndColumn.slice(0, match.index);
|
|
42
|
+
let line = parseInt(match[1]);
|
|
43
|
+
let column = parseInt(match[2]);
|
|
44
|
+
const urlInfo = context.urlGraph.getUrlInfo(file);
|
|
43
45
|
if (!urlInfo) {
|
|
44
46
|
return {
|
|
45
47
|
status: 204,
|
|
46
48
|
headers: {
|
|
47
49
|
"cache-control": "no-store",
|
|
48
50
|
},
|
|
49
|
-
}
|
|
51
|
+
};
|
|
50
52
|
}
|
|
51
|
-
const remap = searchParams.has("remap")
|
|
53
|
+
const remap = searchParams.has("remap");
|
|
52
54
|
if (remap) {
|
|
53
|
-
const sourcemap = urlInfo.sourcemap
|
|
55
|
+
const sourcemap = urlInfo.sourcemap;
|
|
54
56
|
if (sourcemap) {
|
|
55
57
|
const original = getOriginalPosition({
|
|
56
58
|
sourcemap,
|
|
57
59
|
url: file,
|
|
58
60
|
line,
|
|
59
61
|
column,
|
|
60
|
-
})
|
|
62
|
+
});
|
|
61
63
|
if (original.line !== null) {
|
|
62
|
-
line = original.line
|
|
64
|
+
line = original.line;
|
|
63
65
|
if (original.column !== null) {
|
|
64
|
-
column = original.column
|
|
66
|
+
column = original.column;
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
}
|
|
@@ -71,7 +73,7 @@ export const jsenvPluginSupervisor = ({
|
|
|
71
73
|
line,
|
|
72
74
|
column,
|
|
73
75
|
content: urlInfo.originalContent,
|
|
74
|
-
})
|
|
76
|
+
});
|
|
75
77
|
return {
|
|
76
78
|
status: 200,
|
|
77
79
|
headers: {
|
|
@@ -80,37 +82,38 @@ export const jsenvPluginSupervisor = ({
|
|
|
80
82
|
"content-length": Buffer.byteLength(codeFrame),
|
|
81
83
|
},
|
|
82
84
|
body: codeFrame,
|
|
83
|
-
}
|
|
85
|
+
};
|
|
84
86
|
}
|
|
85
87
|
if (request.pathname.startsWith("/__get_error_cause__/")) {
|
|
86
|
-
let file = request.pathname.slice("/__get_error_cause__/".length)
|
|
87
|
-
file = decodeURIComponent(file)
|
|
88
|
+
let file = request.pathname.slice("/__get_error_cause__/".length);
|
|
89
|
+
file = decodeURIComponent(file);
|
|
88
90
|
if (!file) {
|
|
89
91
|
return {
|
|
90
92
|
status: 400,
|
|
91
93
|
body: "Missing file in url",
|
|
92
|
-
}
|
|
94
|
+
};
|
|
93
95
|
}
|
|
94
96
|
const getErrorCauseInfo = () => {
|
|
95
|
-
const urlInfo = context.urlGraph.getUrlInfo(file)
|
|
97
|
+
const urlInfo = context.urlGraph.getUrlInfo(file);
|
|
96
98
|
if (!urlInfo) {
|
|
97
|
-
return null
|
|
99
|
+
return null;
|
|
98
100
|
}
|
|
99
|
-
const { error } = urlInfo
|
|
101
|
+
const { error } = urlInfo;
|
|
100
102
|
if (error) {
|
|
101
|
-
return error
|
|
103
|
+
return error;
|
|
102
104
|
}
|
|
103
105
|
// search in direct dependencies (404 or 500)
|
|
104
|
-
const { dependencies } = urlInfo
|
|
106
|
+
const { dependencies } = urlInfo;
|
|
105
107
|
for (const dependencyUrl of dependencies) {
|
|
106
|
-
const dependencyUrlInfo =
|
|
108
|
+
const dependencyUrlInfo =
|
|
109
|
+
context.urlGraph.getUrlInfo(dependencyUrl);
|
|
107
110
|
if (dependencyUrlInfo.error) {
|
|
108
|
-
return dependencyUrlInfo.error
|
|
111
|
+
return dependencyUrlInfo.error;
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
|
-
return null
|
|
112
|
-
}
|
|
113
|
-
const causeInfo = getErrorCauseInfo()
|
|
114
|
+
return null;
|
|
115
|
+
};
|
|
116
|
+
const causeInfo = getErrorCauseInfo();
|
|
114
117
|
const body = JSON.stringify(
|
|
115
118
|
causeInfo
|
|
116
119
|
? {
|
|
@@ -125,7 +128,7 @@ export const jsenvPluginSupervisor = ({
|
|
|
125
128
|
: null,
|
|
126
129
|
null,
|
|
127
130
|
" ",
|
|
128
|
-
)
|
|
131
|
+
);
|
|
129
132
|
return {
|
|
130
133
|
status: 200,
|
|
131
134
|
headers: {
|
|
@@ -134,29 +137,29 @@ export const jsenvPluginSupervisor = ({
|
|
|
134
137
|
"content-length": Buffer.byteLength(body),
|
|
135
138
|
},
|
|
136
139
|
body,
|
|
137
|
-
}
|
|
140
|
+
};
|
|
138
141
|
}
|
|
139
142
|
if (request.pathname.startsWith("/__open_in_editor__/")) {
|
|
140
|
-
let file = request.pathname.slice("/__open_in_editor__/".length)
|
|
141
|
-
file = decodeURIComponent(file)
|
|
143
|
+
let file = request.pathname.slice("/__open_in_editor__/".length);
|
|
144
|
+
file = decodeURIComponent(file);
|
|
142
145
|
if (!file) {
|
|
143
146
|
return {
|
|
144
147
|
status: 400,
|
|
145
148
|
body: "Missing file in url",
|
|
146
|
-
}
|
|
149
|
+
};
|
|
147
150
|
}
|
|
148
|
-
const launch = requireFromJsenv("launch-editor")
|
|
151
|
+
const launch = requireFromJsenv("launch-editor");
|
|
149
152
|
launch(fileURLToPath(file), () => {
|
|
150
153
|
// ignore error for now
|
|
151
|
-
})
|
|
154
|
+
});
|
|
152
155
|
return {
|
|
153
156
|
status: 200,
|
|
154
157
|
headers: {
|
|
155
158
|
"cache-control": "no-store",
|
|
156
159
|
},
|
|
157
|
-
}
|
|
160
|
+
};
|
|
158
161
|
}
|
|
159
|
-
return null
|
|
162
|
+
return null;
|
|
160
163
|
},
|
|
161
164
|
transformUrlContent: {
|
|
162
165
|
html: ({ url, content }, context) => {
|
|
@@ -164,7 +167,7 @@ export const jsenvPluginSupervisor = ({
|
|
|
164
167
|
type: "script",
|
|
165
168
|
expectedType: "js_classic",
|
|
166
169
|
specifier: supervisorFileUrl,
|
|
167
|
-
})
|
|
170
|
+
});
|
|
168
171
|
|
|
169
172
|
return injectSupervisorIntoHTML(
|
|
170
173
|
{
|
|
@@ -204,12 +207,12 @@ export const jsenvPluginSupervisor = ({
|
|
|
204
207
|
specifier: inlineScriptUrl,
|
|
205
208
|
contentType: "text/javascript",
|
|
206
209
|
content: textContent,
|
|
207
|
-
})
|
|
208
|
-
return inlineScriptReference.generatedSpecifier
|
|
210
|
+
});
|
|
211
|
+
return inlineScriptReference.generatedSpecifier;
|
|
209
212
|
},
|
|
210
213
|
},
|
|
211
|
-
)
|
|
214
|
+
);
|
|
212
215
|
},
|
|
213
216
|
},
|
|
214
|
-
}
|
|
215
|
-
}
|
|
217
|
+
};
|
|
218
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { applyBabelPlugins } from "@jsenv/ast"
|
|
2
|
-
import { composeTwoSourcemaps } from "@jsenv/sourcemap"
|
|
1
|
+
import { applyBabelPlugins } from "@jsenv/ast";
|
|
2
|
+
import { composeTwoSourcemaps } from "@jsenv/sourcemap";
|
|
3
3
|
|
|
4
|
-
import { isWebWorkerUrlInfo } from "@jsenv/core/src/kitchen/web_workers.js"
|
|
4
|
+
import { isWebWorkerUrlInfo } from "@jsenv/core/src/kitchen/web_workers.js";
|
|
5
5
|
|
|
6
6
|
export const convertJsClassicToJsModule = async ({
|
|
7
7
|
urlInfo,
|
|
@@ -17,29 +17,29 @@ export const convertJsClassicToJsModule = async ({
|
|
|
17
17
|
],
|
|
18
18
|
],
|
|
19
19
|
urlInfo: jsClassicUrlInfo,
|
|
20
|
-
})
|
|
21
|
-
const sourcemap = await composeTwoSourcemaps(jsClassicUrlInfo.sourcemap, map)
|
|
20
|
+
});
|
|
21
|
+
const sourcemap = await composeTwoSourcemaps(jsClassicUrlInfo.sourcemap, map);
|
|
22
22
|
return {
|
|
23
23
|
content: code,
|
|
24
24
|
sourcemap,
|
|
25
|
-
}
|
|
26
|
-
}
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
27
|
|
|
28
28
|
const babelPluginReplaceTopLevelThis = () => {
|
|
29
29
|
return {
|
|
30
30
|
name: "replace-top-level-this",
|
|
31
31
|
visitor: {
|
|
32
32
|
Program: (programPath, state) => {
|
|
33
|
-
const { isWebWorker } = state.opts
|
|
33
|
+
const { isWebWorker } = state.opts;
|
|
34
34
|
programPath.traverse({
|
|
35
35
|
ThisExpression: (path) => {
|
|
36
|
-
const closestFunction = path.getFunctionParent()
|
|
36
|
+
const closestFunction = path.getFunctionParent();
|
|
37
37
|
if (!closestFunction) {
|
|
38
|
-
path.replaceWithSourceString(isWebWorker ? "self" : "window")
|
|
38
|
+
path.replaceWithSourceString(isWebWorker ? "self" : "window");
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
|
-
})
|
|
41
|
+
});
|
|
42
42
|
},
|
|
43
43
|
},
|
|
44
|
-
}
|
|
45
|
-
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
* and can be used like this for instance import("hls?as_js_module")
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { urlToFilename } from "@jsenv/urls"
|
|
12
|
+
import { urlToFilename } from "@jsenv/urls";
|
|
13
13
|
|
|
14
|
-
import { convertJsClassicToJsModule } from "./convert_js_classic_to_js_module.js"
|
|
14
|
+
import { convertJsClassicToJsModule } from "./convert_js_classic_to_js_module.js";
|
|
15
15
|
|
|
16
16
|
export const jsenvPluginAsJsModule = () => {
|
|
17
17
|
return {
|
|
@@ -19,10 +19,10 @@ export const jsenvPluginAsJsModule = () => {
|
|
|
19
19
|
appliesDuring: "*",
|
|
20
20
|
redirectUrl: (reference) => {
|
|
21
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
|
|
22
|
+
reference.expectedType = "js_module";
|
|
23
|
+
const filename = urlToFilename(reference.url);
|
|
24
|
+
const [basename] = splitFileExtension(filename);
|
|
25
|
+
reference.filename = `${basename}.mjs`;
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
fetchUrlContent: async (urlInfo, context) => {
|
|
@@ -35,27 +35,27 @@ export const jsenvPluginAsJsModule = () => {
|
|
|
35
35
|
// because when there is ?as_js_module it means the underlying resource
|
|
36
36
|
// is js_classic
|
|
37
37
|
expectedType: "js_classic",
|
|
38
|
-
})
|
|
38
|
+
});
|
|
39
39
|
if (!jsClassicReference) {
|
|
40
|
-
return null
|
|
40
|
+
return null;
|
|
41
41
|
}
|
|
42
42
|
await context.fetchUrlContent(jsClassicUrlInfo, {
|
|
43
43
|
reference: jsClassicReference,
|
|
44
|
-
})
|
|
44
|
+
});
|
|
45
45
|
if (context.dev) {
|
|
46
46
|
context.referenceUtils.found({
|
|
47
47
|
type: "js_import",
|
|
48
48
|
subtype: jsClassicReference.subtype,
|
|
49
49
|
specifier: jsClassicReference.url,
|
|
50
50
|
expectedType: "js_classic",
|
|
51
|
-
})
|
|
51
|
+
});
|
|
52
52
|
} else if (context.build && jsClassicUrlInfo.dependents.size === 0) {
|
|
53
|
-
context.urlGraph.deleteUrlInfo(jsClassicUrlInfo.url)
|
|
53
|
+
context.urlGraph.deleteUrlInfo(jsClassicUrlInfo.url);
|
|
54
54
|
}
|
|
55
55
|
const { content, sourcemap } = await convertJsClassicToJsModule({
|
|
56
56
|
urlInfo,
|
|
57
57
|
jsClassicUrlInfo,
|
|
58
|
-
})
|
|
58
|
+
});
|
|
59
59
|
return {
|
|
60
60
|
content,
|
|
61
61
|
contentType: "text/javascript",
|
|
@@ -64,15 +64,15 @@ export const jsenvPluginAsJsModule = () => {
|
|
|
64
64
|
originalContent: jsClassicUrlInfo.originalContent,
|
|
65
65
|
sourcemap,
|
|
66
66
|
data: jsClassicUrlInfo.data,
|
|
67
|
-
}
|
|
67
|
+
};
|
|
68
68
|
},
|
|
69
|
-
}
|
|
70
|
-
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
71
|
|
|
72
72
|
const splitFileExtension = (filename) => {
|
|
73
|
-
const dotLastIndex = filename.lastIndexOf(".")
|
|
73
|
+
const dotLastIndex = filename.lastIndexOf(".");
|
|
74
74
|
if (dotLastIndex === -1) {
|
|
75
|
-
return [filename, ""]
|
|
75
|
+
return [filename, ""];
|
|
76
76
|
}
|
|
77
|
-
return [filename.slice(0, dotLastIndex), filename.slice(dotLastIndex)]
|
|
78
|
-
}
|
|
77
|
+
return [filename.slice(0, dotLastIndex), filename.slice(dotLastIndex)];
|
|
78
|
+
};
|
package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { pathToFileURL } from "node:url"
|
|
2
|
-
import { injectJsImport } from "@jsenv/ast"
|
|
1
|
+
import { pathToFileURL } from "node:url";
|
|
2
|
+
import { injectJsImport } from "@jsenv/ast";
|
|
3
3
|
|
|
4
4
|
export const globalThisClientFileUrl = new URL(
|
|
5
5
|
"./client/global_this.js",
|
|
6
6
|
import.meta.url,
|
|
7
|
-
).href
|
|
7
|
+
).href;
|
|
8
8
|
|
|
9
9
|
export const babelPluginGlobalThisAsJsenvImport = (
|
|
10
10
|
babel,
|
|
@@ -14,21 +14,21 @@ export const babelPluginGlobalThisAsJsenvImport = (
|
|
|
14
14
|
name: "global-this-as-jsenv-import",
|
|
15
15
|
visitor: {
|
|
16
16
|
Identifier(path, opts) {
|
|
17
|
-
const { filename } = opts
|
|
18
|
-
const fileUrl = pathToFileURL(filename).href
|
|
17
|
+
const { filename } = opts;
|
|
18
|
+
const fileUrl = pathToFileURL(filename).href;
|
|
19
19
|
if (fileUrl === globalThisClientFileUrl) {
|
|
20
|
-
return
|
|
20
|
+
return;
|
|
21
21
|
}
|
|
22
|
-
const { node } = path
|
|
22
|
+
const { node } = path;
|
|
23
23
|
// we should do this once, tree shaking will remote it but still
|
|
24
24
|
if (node.name === "globalThis") {
|
|
25
25
|
injectJsImport({
|
|
26
26
|
programPath: path.scope.getProgramParent().path,
|
|
27
27
|
from: getImportSpecifier(globalThisClientFileUrl),
|
|
28
28
|
sideEffect: true,
|
|
29
|
-
})
|
|
29
|
+
});
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
},
|
|
33
|
-
}
|
|
34
|
-
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -2,24 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
/* eslint-disable no-redeclare */
|
|
4
4
|
/* global globalThis */
|
|
5
|
-
let globalObject
|
|
5
|
+
let globalObject;
|
|
6
6
|
if (typeof globalThis === "object") {
|
|
7
|
-
globalObject = globalThis
|
|
7
|
+
globalObject = globalThis;
|
|
8
8
|
} else {
|
|
9
9
|
if (this) {
|
|
10
|
-
globalObject = this
|
|
10
|
+
globalObject = this;
|
|
11
11
|
} else {
|
|
12
12
|
// eslint-disable-next-line no-extend-native
|
|
13
13
|
Object.defineProperty(Object.prototype, "__global__", {
|
|
14
14
|
get() {
|
|
15
|
-
return this
|
|
15
|
+
return this;
|
|
16
16
|
},
|
|
17
17
|
configurable: true,
|
|
18
|
-
})
|
|
18
|
+
});
|
|
19
19
|
// eslint-disable-next-line no-undef
|
|
20
|
-
globalObject = __global__
|
|
21
|
-
delete Object.prototype.__global__
|
|
20
|
+
globalObject = __global__;
|
|
21
|
+
delete Object.prototype.__global__;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
globalObject.globalThis = globalObject
|
|
24
|
+
globalObject.globalThis = globalObject;
|
|
25
25
|
}
|
package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { pathToFileURL } from "node:url"
|
|
2
|
-
import { injectJsImport } from "@jsenv/ast"
|
|
1
|
+
import { pathToFileURL } from "node:url";
|
|
2
|
+
import { injectJsImport } from "@jsenv/ast";
|
|
3
3
|
import {
|
|
4
4
|
getBabelHelperFileUrl,
|
|
5
5
|
babelHelperNameFromUrl,
|
|
6
|
-
} from "@jsenv/babel-plugins"
|
|
6
|
+
} from "@jsenv/babel-plugins";
|
|
7
7
|
|
|
8
8
|
// named import approach found here:
|
|
9
9
|
// https://github.com/rollup/rollup-plugin-babel/blob/18e4232a450f320f44c651aa8c495f21c74d59ac/src/helperPlugin.js#L1
|
|
@@ -20,22 +20,22 @@ export const babelPluginBabelHelpersAsJsenvImports = (
|
|
|
20
20
|
return {
|
|
21
21
|
name: "babel-helper-as-jsenv-import",
|
|
22
22
|
pre: (file) => {
|
|
23
|
-
const cachedHelpers = {}
|
|
23
|
+
const cachedHelpers = {};
|
|
24
24
|
file.set("helperGenerator", (name) => {
|
|
25
25
|
// the list of possible helpers name
|
|
26
26
|
// https://github.com/babel/babel/blob/99f4f6c3b03c7f3f67cf1b9f1a21b80cfd5b0224/packages/babel-helpers/src/helpers.js#L13
|
|
27
27
|
if (!file.availableHelper(name)) {
|
|
28
|
-
return undefined
|
|
28
|
+
return undefined;
|
|
29
29
|
}
|
|
30
30
|
if (cachedHelpers[name]) {
|
|
31
|
-
return cachedHelpers[name]
|
|
31
|
+
return cachedHelpers[name];
|
|
32
32
|
}
|
|
33
|
-
const filePath = file.opts.filename
|
|
34
|
-
const fileUrl = pathToFileURL(filePath).href
|
|
33
|
+
const filePath = file.opts.filename;
|
|
34
|
+
const fileUrl = pathToFileURL(filePath).href;
|
|
35
35
|
if (babelHelperNameFromUrl(fileUrl) === name) {
|
|
36
|
-
return undefined
|
|
36
|
+
return undefined;
|
|
37
37
|
}
|
|
38
|
-
const babelHelperImportSpecifier = getBabelHelperFileUrl(name)
|
|
38
|
+
const babelHelperImportSpecifier = getBabelHelperFileUrl(name);
|
|
39
39
|
const helper = injectJsImport({
|
|
40
40
|
programPath: file.path,
|
|
41
41
|
from: getImportSpecifier(babelHelperImportSpecifier),
|
|
@@ -43,10 +43,10 @@ export const babelPluginBabelHelpersAsJsenvImports = (
|
|
|
43
43
|
// disable interop, useless as we work only with js modules
|
|
44
44
|
importedType: "es6",
|
|
45
45
|
// importedInterop: "uncompiled",
|
|
46
|
-
})
|
|
47
|
-
cachedHelpers[name] = helper
|
|
48
|
-
return helper
|
|
49
|
-
})
|
|
46
|
+
});
|
|
47
|
+
cachedHelpers[name] = helper;
|
|
48
|
+
return helper;
|
|
49
|
+
});
|
|
50
50
|
},
|
|
51
|
-
}
|
|
52
|
-
}
|
|
51
|
+
};
|
|
52
|
+
};
|