@jsenv/core 35.0.2 → 35.0.4
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/dist/jsenv_core.js +15 -17
- package/package.json +1 -1
- 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 +136 -135
- 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 +23 -25
- 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 +30 -30
- 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 +36 -36
- package/src/plugins/url_resolution/node_esm_resolver.js +26 -26
- package/src/plugins/url_version/jsenv_plugin_url_version.js +11 -11
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getBabelHelperFileUrl } from "@jsenv/babel-plugins"
|
|
2
|
-
import { requireBabelPlugin } from "../require_babel_plugin.js"
|
|
3
|
-
import { babelPluginCompatMap } from "./babel_plugins_compatibility.js"
|
|
1
|
+
import { getBabelHelperFileUrl } from "@jsenv/babel-plugins";
|
|
2
|
+
import { requireBabelPlugin } from "../require_babel_plugin.js";
|
|
3
|
+
import { babelPluginCompatMap } from "./babel_plugins_compatibility.js";
|
|
4
4
|
|
|
5
5
|
export const getBaseBabelPluginStructure = ({
|
|
6
6
|
url,
|
|
@@ -9,32 +9,32 @@ export const getBaseBabelPluginStructure = ({
|
|
|
9
9
|
// getImportSpecifier,
|
|
10
10
|
}) => {
|
|
11
11
|
const isBabelPluginNeeded = (babelPluginName) => {
|
|
12
|
-
return !isSupported(babelPluginCompatMap[babelPluginName])
|
|
13
|
-
}
|
|
12
|
+
return !isSupported(babelPluginCompatMap[babelPluginName]);
|
|
13
|
+
};
|
|
14
14
|
|
|
15
|
-
const babelPluginStructure = {}
|
|
15
|
+
const babelPluginStructure = {};
|
|
16
16
|
if (isBabelPluginNeeded("proposal-numeric-separator")) {
|
|
17
17
|
babelPluginStructure["proposal-numeric-separator"] = requireBabelPlugin(
|
|
18
18
|
"@babel/plugin-proposal-numeric-separator",
|
|
19
|
-
)
|
|
19
|
+
);
|
|
20
20
|
}
|
|
21
21
|
if (isBabelPluginNeeded("proposal-json-strings")) {
|
|
22
22
|
babelPluginStructure["proposal-json-strings"] = requireBabelPlugin(
|
|
23
23
|
"@babel/plugin-proposal-json-strings",
|
|
24
|
-
)
|
|
24
|
+
);
|
|
25
25
|
}
|
|
26
26
|
if (isBabelPluginNeeded("proposal-object-rest-spread")) {
|
|
27
27
|
babelPluginStructure["proposal-object-rest-spread"] = requireBabelPlugin(
|
|
28
28
|
"@babel/plugin-proposal-object-rest-spread",
|
|
29
|
-
)
|
|
29
|
+
);
|
|
30
30
|
}
|
|
31
31
|
if (isBabelPluginNeeded("proposal-optional-catch-binding")) {
|
|
32
32
|
babelPluginStructure["proposal-optional-catch-binding"] =
|
|
33
|
-
requireBabelPlugin("@babel/plugin-proposal-optional-catch-binding")
|
|
33
|
+
requireBabelPlugin("@babel/plugin-proposal-optional-catch-binding");
|
|
34
34
|
}
|
|
35
35
|
if (isBabelPluginNeeded("proposal-unicode-property-regex")) {
|
|
36
36
|
babelPluginStructure["proposal-unicode-property-regex"] =
|
|
37
|
-
requireBabelPlugin("@babel/plugin-proposal-unicode-property-regex")
|
|
37
|
+
requireBabelPlugin("@babel/plugin-proposal-unicode-property-regex");
|
|
38
38
|
}
|
|
39
39
|
if (isBabelPluginNeeded("transform-async-to-promises")) {
|
|
40
40
|
babelPluginStructure["transform-async-to-promises"] = [
|
|
@@ -48,80 +48,80 @@ export const getBaseBabelPluginStructure = ({
|
|
|
48
48
|
// "babel-plugin-transform-async-to-promises/helpers.mjs",
|
|
49
49
|
// ) : null
|
|
50
50
|
},
|
|
51
|
-
]
|
|
51
|
+
];
|
|
52
52
|
}
|
|
53
53
|
if (isBabelPluginNeeded("transform-arrow-functions")) {
|
|
54
54
|
babelPluginStructure["transform-arrow-functions"] = requireBabelPlugin(
|
|
55
55
|
"@babel/plugin-transform-arrow-functions",
|
|
56
|
-
)
|
|
56
|
+
);
|
|
57
57
|
}
|
|
58
58
|
if (isBabelPluginNeeded("transform-block-scoped-functions")) {
|
|
59
59
|
babelPluginStructure["transform-block-scoped-functions"] =
|
|
60
|
-
requireBabelPlugin("@babel/plugin-transform-block-scoped-functions")
|
|
60
|
+
requireBabelPlugin("@babel/plugin-transform-block-scoped-functions");
|
|
61
61
|
}
|
|
62
62
|
if (isBabelPluginNeeded("transform-block-scoping")) {
|
|
63
63
|
babelPluginStructure["transform-block-scoping"] = requireBabelPlugin(
|
|
64
64
|
"@babel/plugin-transform-block-scoping",
|
|
65
|
-
)
|
|
65
|
+
);
|
|
66
66
|
}
|
|
67
67
|
if (isBabelPluginNeeded("transform-classes")) {
|
|
68
68
|
babelPluginStructure["transform-classes"] = requireBabelPlugin(
|
|
69
69
|
"@babel/plugin-transform-classes",
|
|
70
|
-
)
|
|
70
|
+
);
|
|
71
71
|
}
|
|
72
72
|
if (isBabelPluginNeeded("transform-computed-properties")) {
|
|
73
73
|
babelPluginStructure["transform-computed-properties"] = requireBabelPlugin(
|
|
74
74
|
"@babel/plugin-transform-computed-properties",
|
|
75
|
-
)
|
|
75
|
+
);
|
|
76
76
|
}
|
|
77
77
|
if (isBabelPluginNeeded("transform-destructuring")) {
|
|
78
78
|
babelPluginStructure["transform-destructuring"] = requireBabelPlugin(
|
|
79
79
|
"@babel/plugin-transform-destructuring",
|
|
80
|
-
)
|
|
80
|
+
);
|
|
81
81
|
}
|
|
82
82
|
if (isBabelPluginNeeded("transform-dotall-regex")) {
|
|
83
83
|
babelPluginStructure["transform-dotall-regex"] = requireBabelPlugin(
|
|
84
84
|
"@babel/plugin-transform-dotall-regex",
|
|
85
|
-
)
|
|
85
|
+
);
|
|
86
86
|
}
|
|
87
87
|
if (isBabelPluginNeeded("transform-duplicate-keys")) {
|
|
88
88
|
babelPluginStructure["transform-duplicate-keys"] = requireBabelPlugin(
|
|
89
89
|
"@babel/plugin-transform-duplicate-keys",
|
|
90
|
-
)
|
|
90
|
+
);
|
|
91
91
|
}
|
|
92
92
|
if (isBabelPluginNeeded("transform-exponentiation-operator")) {
|
|
93
93
|
babelPluginStructure["transform-exponentiation-operator"] =
|
|
94
|
-
requireBabelPlugin("@babel/plugin-transform-exponentiation-operator")
|
|
94
|
+
requireBabelPlugin("@babel/plugin-transform-exponentiation-operator");
|
|
95
95
|
}
|
|
96
96
|
if (isBabelPluginNeeded("transform-for-of")) {
|
|
97
97
|
babelPluginStructure["transform-for-of"] = requireBabelPlugin(
|
|
98
98
|
"@babel/plugin-transform-for-of",
|
|
99
|
-
)
|
|
99
|
+
);
|
|
100
100
|
}
|
|
101
101
|
if (isBabelPluginNeeded("transform-function-name")) {
|
|
102
102
|
babelPluginStructure["transform-function-name"] = requireBabelPlugin(
|
|
103
103
|
"@babel/plugin-transform-function-name",
|
|
104
|
-
)
|
|
104
|
+
);
|
|
105
105
|
}
|
|
106
106
|
if (isBabelPluginNeeded("transform-literals")) {
|
|
107
107
|
babelPluginStructure["transform-literals"] = requireBabelPlugin(
|
|
108
108
|
"@babel/plugin-transform-literals",
|
|
109
|
-
)
|
|
109
|
+
);
|
|
110
110
|
}
|
|
111
111
|
if (isBabelPluginNeeded("transform-new-target")) {
|
|
112
112
|
babelPluginStructure["transform-new-target"] = requireBabelPlugin(
|
|
113
113
|
"@babel/plugin-transform-new-target",
|
|
114
|
-
)
|
|
114
|
+
);
|
|
115
115
|
}
|
|
116
116
|
if (isBabelPluginNeeded("transform-object-super")) {
|
|
117
117
|
babelPluginStructure["transform-object-super"] = requireBabelPlugin(
|
|
118
118
|
"@babel/plugin-transform-object-super",
|
|
119
|
-
)
|
|
119
|
+
);
|
|
120
120
|
}
|
|
121
121
|
if (isBabelPluginNeeded("transform-parameters")) {
|
|
122
122
|
babelPluginStructure["transform-parameters"] = requireBabelPlugin(
|
|
123
123
|
"@babel/plugin-transform-parameters",
|
|
124
|
-
)
|
|
124
|
+
);
|
|
125
125
|
}
|
|
126
126
|
if (isBabelPluginNeeded("transform-regenerator")) {
|
|
127
127
|
babelPluginStructure["transform-regenerator"] = [
|
|
@@ -131,27 +131,27 @@ export const getBaseBabelPluginStructure = ({
|
|
|
131
131
|
generators: true,
|
|
132
132
|
async: false,
|
|
133
133
|
},
|
|
134
|
-
]
|
|
134
|
+
];
|
|
135
135
|
}
|
|
136
136
|
if (isBabelPluginNeeded("transform-shorthand-properties")) {
|
|
137
137
|
babelPluginStructure["transform-shorthand-properties"] = [
|
|
138
138
|
requireBabelPlugin("@babel/plugin-transform-shorthand-properties"),
|
|
139
|
-
]
|
|
139
|
+
];
|
|
140
140
|
}
|
|
141
141
|
if (isBabelPluginNeeded("transform-spread")) {
|
|
142
142
|
babelPluginStructure["transform-spread"] = [
|
|
143
143
|
requireBabelPlugin("@babel/plugin-transform-spread"),
|
|
144
|
-
]
|
|
144
|
+
];
|
|
145
145
|
}
|
|
146
146
|
if (isBabelPluginNeeded("transform-sticky-regex")) {
|
|
147
147
|
babelPluginStructure["transform-sticky-regex"] = [
|
|
148
148
|
requireBabelPlugin("@babel/plugin-transform-sticky-regex"),
|
|
149
|
-
]
|
|
149
|
+
];
|
|
150
150
|
}
|
|
151
151
|
if (isBabelPluginNeeded("transform-template-literals")) {
|
|
152
152
|
babelPluginStructure["transform-template-literals"] = [
|
|
153
153
|
requireBabelPlugin("@babel/plugin-transform-template-literals"),
|
|
154
|
-
]
|
|
154
|
+
];
|
|
155
155
|
}
|
|
156
156
|
if (
|
|
157
157
|
isBabelPluginNeeded("transform-typeof-symbol") &&
|
|
@@ -162,12 +162,12 @@ export const getBaseBabelPluginStructure = ({
|
|
|
162
162
|
) {
|
|
163
163
|
babelPluginStructure["transform-typeof-symbol"] = [
|
|
164
164
|
requireBabelPlugin("@babel/plugin-transform-typeof-symbol"),
|
|
165
|
-
]
|
|
165
|
+
];
|
|
166
166
|
}
|
|
167
167
|
if (isBabelPluginNeeded("transform-unicode-regex")) {
|
|
168
168
|
babelPluginStructure["transform-unicode-regex"] = [
|
|
169
169
|
requireBabelPlugin("@babel/plugin-transform-unicode-regex"),
|
|
170
|
-
]
|
|
170
|
+
];
|
|
171
171
|
}
|
|
172
|
-
return babelPluginStructure
|
|
173
|
-
}
|
|
172
|
+
return babelPluginStructure;
|
|
173
|
+
};
|
|
@@ -421,12 +421,12 @@ export const babelPluginCompatMap = {
|
|
|
421
421
|
samsung: "1",
|
|
422
422
|
electron: "0.20",
|
|
423
423
|
},
|
|
424
|
-
}
|
|
424
|
+
};
|
|
425
425
|
|
|
426
426
|
// copy of transform-async-to-generator
|
|
427
427
|
// so that async is not transpiled when supported
|
|
428
428
|
babelPluginCompatMap["transform-async-to-promises"] =
|
|
429
|
-
babelPluginCompatMap["transform-async-to-generator"]
|
|
429
|
+
babelPluginCompatMap["transform-async-to-generator"];
|
|
430
430
|
|
|
431
431
|
babelPluginCompatMap["regenerator-transform"] =
|
|
432
|
-
babelPluginCompatMap["transform-regenerator"]
|
|
432
|
+
babelPluginCompatMap["transform-regenerator"];
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { applyBabelPlugins } from "@jsenv/ast"
|
|
1
|
+
import { applyBabelPlugins } from "@jsenv/ast";
|
|
2
2
|
|
|
3
|
-
import { RUNTIME_COMPAT } from "@jsenv/core/src/kitchen/compat/runtime_compat.js"
|
|
4
|
-
import { getBaseBabelPluginStructure } from "./helpers/babel_plugin_structure.js"
|
|
5
|
-
import { babelPluginBabelHelpersAsJsenvImports } from "./helpers/babel_plugin_babel_helpers_as_jsenv_imports.js"
|
|
6
|
-
import { babelPluginNewStylesheetAsJsenvImport } from "./new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js"
|
|
7
|
-
import { babelPluginGlobalThisAsJsenvImport } from "./global_this/babel_plugin_global_this_as_jsenv_import.js"
|
|
8
|
-
import { babelPluginRegeneratorRuntimeAsJsenvImport } from "./regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js"
|
|
3
|
+
import { RUNTIME_COMPAT } from "@jsenv/core/src/kitchen/compat/runtime_compat.js";
|
|
4
|
+
import { getBaseBabelPluginStructure } from "./helpers/babel_plugin_structure.js";
|
|
5
|
+
import { babelPluginBabelHelpersAsJsenvImports } from "./helpers/babel_plugin_babel_helpers_as_jsenv_imports.js";
|
|
6
|
+
import { babelPluginNewStylesheetAsJsenvImport } from "./new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js";
|
|
7
|
+
import { babelPluginGlobalThisAsJsenvImport } from "./global_this/babel_plugin_global_this_as_jsenv_import.js";
|
|
8
|
+
import { babelPluginRegeneratorRuntimeAsJsenvImport } from "./regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js";
|
|
9
9
|
|
|
10
10
|
export const jsenvPluginBabel = ({
|
|
11
11
|
getCustomBabelPlugins,
|
|
12
12
|
babelHelpersAsImport = true,
|
|
13
13
|
} = {}) => {
|
|
14
14
|
const transformWithBabel = async (urlInfo, context) => {
|
|
15
|
-
const isJsModule = urlInfo.type === "js_module"
|
|
15
|
+
const isJsModule = urlInfo.type === "js_module";
|
|
16
16
|
|
|
17
17
|
const isSupported = (feature) =>
|
|
18
|
-
RUNTIME_COMPAT.isSupported(context.clientRuntimeCompat, feature)
|
|
18
|
+
RUNTIME_COMPAT.isSupported(context.clientRuntimeCompat, feature);
|
|
19
19
|
const getImportSpecifier = (clientFileUrl) => {
|
|
20
20
|
const [reference] = context.referenceUtils.inject({
|
|
21
21
|
type: "js_import",
|
|
22
22
|
expectedType: "js_module",
|
|
23
23
|
specifier: clientFileUrl,
|
|
24
|
-
})
|
|
25
|
-
return JSON.parse(reference.generatedSpecifier)
|
|
26
|
-
}
|
|
24
|
+
});
|
|
25
|
+
return JSON.parse(reference.generatedSpecifier);
|
|
26
|
+
};
|
|
27
27
|
|
|
28
28
|
const babelPluginStructure = getBaseBabelPluginStructure({
|
|
29
29
|
url: urlInfo.url,
|
|
30
30
|
isSupported,
|
|
31
31
|
isJsModule,
|
|
32
32
|
getImportSpecifier,
|
|
33
|
-
})
|
|
33
|
+
});
|
|
34
34
|
if (getCustomBabelPlugins) {
|
|
35
|
-
Object.assign(babelPluginStructure, getCustomBabelPlugins(context))
|
|
35
|
+
Object.assign(babelPluginStructure, getCustomBabelPlugins(context));
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
if (isJsModule && babelHelpersAsImport) {
|
|
@@ -42,7 +42,7 @@ export const jsenvPluginBabel = ({
|
|
|
42
42
|
{
|
|
43
43
|
getImportSpecifier,
|
|
44
44
|
},
|
|
45
|
-
]
|
|
45
|
+
];
|
|
46
46
|
}
|
|
47
47
|
if (!isSupported("async_generator_function")) {
|
|
48
48
|
babelPluginStructure["regenerator-runtime-as-jsenv-import"] = [
|
|
@@ -50,7 +50,7 @@ export const jsenvPluginBabel = ({
|
|
|
50
50
|
{
|
|
51
51
|
getImportSpecifier,
|
|
52
52
|
},
|
|
53
|
-
]
|
|
53
|
+
];
|
|
54
54
|
}
|
|
55
55
|
if (!isSupported("new_stylesheet")) {
|
|
56
56
|
babelPluginStructure["new-stylesheet-as-jsenv-import"] = [
|
|
@@ -58,7 +58,7 @@ export const jsenvPluginBabel = ({
|
|
|
58
58
|
{
|
|
59
59
|
getImportSpecifier,
|
|
60
60
|
},
|
|
61
|
-
]
|
|
61
|
+
];
|
|
62
62
|
}
|
|
63
63
|
if (Object.keys(babelPluginStructure).length > 0) {
|
|
64
64
|
babelPluginStructure["babel-helper-as-jsenv-import"] = [
|
|
@@ -66,7 +66,7 @@ export const jsenvPluginBabel = ({
|
|
|
66
66
|
{
|
|
67
67
|
getImportSpecifier,
|
|
68
68
|
},
|
|
69
|
-
]
|
|
69
|
+
];
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
// otherwise, concerning global_this, and new_stylesheet we must inject the code
|
|
@@ -74,7 +74,7 @@ export const jsenvPluginBabel = ({
|
|
|
74
74
|
|
|
75
75
|
const babelPlugins = Object.keys(babelPluginStructure).map(
|
|
76
76
|
(babelPluginName) => babelPluginStructure[babelPluginName],
|
|
77
|
-
)
|
|
77
|
+
);
|
|
78
78
|
const { code, map } = await applyBabelPlugins({
|
|
79
79
|
babelPlugins,
|
|
80
80
|
urlInfo,
|
|
@@ -83,12 +83,12 @@ export const jsenvPluginBabel = ({
|
|
|
83
83
|
retainLines: context.dev,
|
|
84
84
|
},
|
|
85
85
|
},
|
|
86
|
-
})
|
|
86
|
+
});
|
|
87
87
|
return {
|
|
88
88
|
content: code,
|
|
89
89
|
sourcemap: map,
|
|
90
|
-
}
|
|
91
|
-
}
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
92
|
return {
|
|
93
93
|
name: "jsenv:babel",
|
|
94
94
|
appliesDuring: "*",
|
|
@@ -96,5 +96,5 @@ export const jsenvPluginBabel = ({
|
|
|
96
96
|
js_classic: transformWithBabel,
|
|
97
97
|
js_module: transformWithBabel,
|
|
98
98
|
},
|
|
99
|
-
}
|
|
100
|
-
}
|
|
99
|
+
};
|
|
100
|
+
};
|
|
@@ -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 newStylesheetClientFileUrl = new URL(
|
|
5
5
|
"./client/new_stylesheet.js",
|
|
6
6
|
import.meta.url,
|
|
7
|
-
).href
|
|
7
|
+
).href;
|
|
8
8
|
|
|
9
9
|
export const babelPluginNewStylesheetAsJsenvImport = (
|
|
10
10
|
babel,
|
|
@@ -15,58 +15,58 @@ export const babelPluginNewStylesheetAsJsenvImport = (
|
|
|
15
15
|
visitor: {
|
|
16
16
|
Program: (programPath, babelState) => {
|
|
17
17
|
if (babelState.filename) {
|
|
18
|
-
const fileUrl = pathToFileURL(babelState.filename).href
|
|
18
|
+
const fileUrl = pathToFileURL(babelState.filename).href;
|
|
19
19
|
if (fileUrl === newStylesheetClientFileUrl) {
|
|
20
|
-
return
|
|
20
|
+
return;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
let usesNewStylesheet = false
|
|
23
|
+
let usesNewStylesheet = false;
|
|
24
24
|
programPath.traverse({
|
|
25
25
|
NewExpression: (path) => {
|
|
26
|
-
usesNewStylesheet = isNewCssStyleSheetCall(path.node)
|
|
26
|
+
usesNewStylesheet = isNewCssStyleSheetCall(path.node);
|
|
27
27
|
if (usesNewStylesheet) {
|
|
28
|
-
path.stop()
|
|
28
|
+
path.stop();
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
MemberExpression: (path) => {
|
|
32
|
-
usesNewStylesheet = isDocumentAdoptedStyleSheets(path.node)
|
|
32
|
+
usesNewStylesheet = isDocumentAdoptedStyleSheets(path.node);
|
|
33
33
|
if (usesNewStylesheet) {
|
|
34
|
-
path.stop()
|
|
34
|
+
path.stop();
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
CallExpression: (path) => {
|
|
38
38
|
if (path.node.callee.type !== "Import") {
|
|
39
39
|
// Some other function call, not import();
|
|
40
|
-
return
|
|
40
|
+
return;
|
|
41
41
|
}
|
|
42
42
|
if (path.node.arguments[0].type !== "StringLiteral") {
|
|
43
43
|
// Non-string argument, probably a variable or expression, e.g.
|
|
44
44
|
// import(moduleId)
|
|
45
45
|
// import('./' + moduleName)
|
|
46
|
-
return
|
|
46
|
+
return;
|
|
47
47
|
}
|
|
48
|
-
const sourcePath = path.get("arguments")[0]
|
|
48
|
+
const sourcePath = path.get("arguments")[0];
|
|
49
49
|
usesNewStylesheet =
|
|
50
50
|
hasCssModuleQueryParam(sourcePath) ||
|
|
51
|
-
hasImportTypeCssAssertion(path)
|
|
51
|
+
hasImportTypeCssAssertion(path);
|
|
52
52
|
if (usesNewStylesheet) {
|
|
53
|
-
path.stop()
|
|
53
|
+
path.stop();
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
ImportDeclaration: (path) => {
|
|
57
|
-
const sourcePath = path.get("source")
|
|
57
|
+
const sourcePath = path.get("source");
|
|
58
58
|
usesNewStylesheet =
|
|
59
59
|
hasCssModuleQueryParam(sourcePath) ||
|
|
60
|
-
hasImportTypeCssAssertion(path)
|
|
60
|
+
hasImportTypeCssAssertion(path);
|
|
61
61
|
if (usesNewStylesheet) {
|
|
62
|
-
path.stop()
|
|
62
|
+
path.stop();
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
ExportAllDeclaration: (path) => {
|
|
66
|
-
const sourcePath = path.get("source")
|
|
67
|
-
usesNewStylesheet = hasCssModuleQueryParam(sourcePath)
|
|
66
|
+
const sourcePath = path.get("source");
|
|
67
|
+
usesNewStylesheet = hasCssModuleQueryParam(sourcePath);
|
|
68
68
|
if (usesNewStylesheet) {
|
|
69
|
-
path.stop()
|
|
69
|
+
path.stop();
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
ExportNamedDeclaration: (path) => {
|
|
@@ -76,34 +76,34 @@ export const babelPluginNewStylesheetAsJsenvImport = (
|
|
|
76
76
|
// export { varName }
|
|
77
77
|
// export const constName = ...
|
|
78
78
|
// export function funcName() {}
|
|
79
|
-
return
|
|
79
|
+
return;
|
|
80
80
|
}
|
|
81
|
-
const sourcePath = path.get("source")
|
|
82
|
-
usesNewStylesheet = hasCssModuleQueryParam(sourcePath)
|
|
81
|
+
const sourcePath = path.get("source");
|
|
82
|
+
usesNewStylesheet = hasCssModuleQueryParam(sourcePath);
|
|
83
83
|
if (usesNewStylesheet) {
|
|
84
|
-
path.stop()
|
|
84
|
+
path.stop();
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
|
-
})
|
|
87
|
+
});
|
|
88
88
|
if (usesNewStylesheet) {
|
|
89
89
|
injectJsImport({
|
|
90
90
|
programPath,
|
|
91
91
|
from: getImportSpecifier(newStylesheetClientFileUrl),
|
|
92
92
|
sideEffect: true,
|
|
93
|
-
})
|
|
93
|
+
});
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
},
|
|
97
|
-
}
|
|
98
|
-
}
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
99
|
|
|
100
100
|
const isNewCssStyleSheetCall = (node) => {
|
|
101
101
|
return (
|
|
102
102
|
node.type === "NewExpression" &&
|
|
103
103
|
node.callee.type === "Identifier" &&
|
|
104
104
|
node.callee.name === "CSSStyleSheet"
|
|
105
|
-
)
|
|
106
|
-
}
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
107
|
|
|
108
108
|
const isDocumentAdoptedStyleSheets = (node) => {
|
|
109
109
|
return (
|
|
@@ -112,31 +112,31 @@ const isDocumentAdoptedStyleSheets = (node) => {
|
|
|
112
112
|
node.object.name === "document" &&
|
|
113
113
|
node.property.type === "Identifier" &&
|
|
114
114
|
node.property.name === "adoptedStyleSheets"
|
|
115
|
-
)
|
|
116
|
-
}
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
117
|
|
|
118
118
|
const hasCssModuleQueryParam = (path) => {
|
|
119
|
-
const { node } = path
|
|
119
|
+
const { node } = path;
|
|
120
120
|
return (
|
|
121
121
|
node.type === "StringLiteral" &&
|
|
122
122
|
new URL(node.value, "https://jsenv.dev").searchParams.has(`css_module`)
|
|
123
|
-
)
|
|
124
|
-
}
|
|
123
|
+
);
|
|
124
|
+
};
|
|
125
125
|
|
|
126
126
|
const hasImportTypeCssAssertion = (path) => {
|
|
127
127
|
const importAssertionsDescriptor = getImportAssertionsDescriptor(
|
|
128
128
|
path.node.assertions,
|
|
129
|
-
)
|
|
130
|
-
return Boolean(importAssertionsDescriptor.type === "css")
|
|
131
|
-
}
|
|
129
|
+
);
|
|
130
|
+
return Boolean(importAssertionsDescriptor.type === "css");
|
|
131
|
+
};
|
|
132
132
|
|
|
133
133
|
const getImportAssertionsDescriptor = (importAssertions) => {
|
|
134
|
-
const importAssertionsDescriptor = {}
|
|
134
|
+
const importAssertionsDescriptor = {};
|
|
135
135
|
if (importAssertions) {
|
|
136
136
|
importAssertions.forEach((importAssertion) => {
|
|
137
137
|
importAssertionsDescriptor[importAssertion.key.name] =
|
|
138
|
-
importAssertion.value.value
|
|
139
|
-
})
|
|
138
|
+
importAssertion.value.value;
|
|
139
|
+
});
|
|
140
140
|
}
|
|
141
|
-
return importAssertionsDescriptor
|
|
142
|
-
}
|
|
141
|
+
return importAssertionsDescriptor;
|
|
142
|
+
};
|