@jsenv/core 35.0.3 → 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/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 +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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { performance } from "node:perf_hooks"
|
|
1
|
+
import { performance } from "node:perf_hooks";
|
|
2
2
|
|
|
3
3
|
const HOOK_NAMES = [
|
|
4
4
|
"init",
|
|
@@ -15,28 +15,28 @@ const HOOK_NAMES = [
|
|
|
15
15
|
"cooked",
|
|
16
16
|
"augmentResponse", // is called only during dev/tests
|
|
17
17
|
"destroy",
|
|
18
|
-
]
|
|
18
|
+
];
|
|
19
19
|
|
|
20
20
|
export const createPluginController = (kitchenContext) => {
|
|
21
|
-
const plugins = []
|
|
21
|
+
const plugins = [];
|
|
22
22
|
// precompute a list of hooks per hookName for one major reason:
|
|
23
23
|
// - When debugging, there is less iteration
|
|
24
24
|
// also it should increase perf as there is less work to do
|
|
25
|
-
const hookGroups = {}
|
|
25
|
+
const hookGroups = {};
|
|
26
26
|
const addPlugin = (plugin, { position = "start" }) => {
|
|
27
27
|
if (plugin === null || typeof plugin !== "object") {
|
|
28
|
-
throw new TypeError(`plugin must be objects, got ${plugin}`)
|
|
28
|
+
throw new TypeError(`plugin must be objects, got ${plugin}`);
|
|
29
29
|
}
|
|
30
30
|
if (!testAppliesDuring(plugin) || !initPlugin(plugin)) {
|
|
31
31
|
if (plugin.destroy) {
|
|
32
|
-
plugin.destroy()
|
|
32
|
+
plugin.destroy();
|
|
33
33
|
}
|
|
34
|
-
return
|
|
34
|
+
return;
|
|
35
35
|
}
|
|
36
36
|
if (!plugin.name) {
|
|
37
|
-
plugin.name = "anonymous"
|
|
37
|
+
plugin.name = "anonymous";
|
|
38
38
|
}
|
|
39
|
-
plugins.push(plugin)
|
|
39
|
+
plugins.push(plugin);
|
|
40
40
|
Object.keys(plugin).forEach((key) => {
|
|
41
41
|
if (
|
|
42
42
|
key === "name" ||
|
|
@@ -44,194 +44,194 @@ export const createPluginController = (kitchenContext) => {
|
|
|
44
44
|
key === "init" ||
|
|
45
45
|
key === "serverEvents"
|
|
46
46
|
) {
|
|
47
|
-
return
|
|
47
|
+
return;
|
|
48
48
|
}
|
|
49
|
-
const isHook = HOOK_NAMES.includes(key)
|
|
49
|
+
const isHook = HOOK_NAMES.includes(key);
|
|
50
50
|
if (!isHook) {
|
|
51
|
-
console.warn(`Unexpected "${key}" property on "${plugin.name}" plugin`)
|
|
51
|
+
console.warn(`Unexpected "${key}" property on "${plugin.name}" plugin`);
|
|
52
52
|
}
|
|
53
|
-
const hookName = key
|
|
54
|
-
const hookValue = plugin[hookName]
|
|
53
|
+
const hookName = key;
|
|
54
|
+
const hookValue = plugin[hookName];
|
|
55
55
|
if (hookValue) {
|
|
56
|
-
const group = hookGroups[hookName] || (hookGroups[hookName] = [])
|
|
56
|
+
const group = hookGroups[hookName] || (hookGroups[hookName] = []);
|
|
57
57
|
const hook = {
|
|
58
58
|
plugin,
|
|
59
59
|
name: hookName,
|
|
60
60
|
value: hookValue,
|
|
61
|
-
}
|
|
61
|
+
};
|
|
62
62
|
if (position === "start") {
|
|
63
|
-
group.push(hook)
|
|
63
|
+
group.push(hook);
|
|
64
64
|
} else {
|
|
65
|
-
group.unshift(hook)
|
|
65
|
+
group.unshift(hook);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
})
|
|
69
|
-
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
70
|
const testAppliesDuring = (plugin) => {
|
|
71
|
-
const { appliesDuring } = plugin
|
|
71
|
+
const { appliesDuring } = plugin;
|
|
72
72
|
if (appliesDuring === undefined) {
|
|
73
73
|
// console.debug(`"appliesDuring" is undefined on ${pluginEntry.name}`)
|
|
74
|
-
return true
|
|
74
|
+
return true;
|
|
75
75
|
}
|
|
76
76
|
if (appliesDuring === "*") {
|
|
77
|
-
return true
|
|
77
|
+
return true;
|
|
78
78
|
}
|
|
79
79
|
if (typeof appliesDuring === "string") {
|
|
80
80
|
if (appliesDuring !== "dev" && appliesDuring !== "build") {
|
|
81
81
|
throw new TypeError(
|
|
82
82
|
`"appliesDuring" must be "dev" or "build", got ${appliesDuring}`,
|
|
83
|
-
)
|
|
83
|
+
);
|
|
84
84
|
}
|
|
85
85
|
if (kitchenContext[appliesDuring]) {
|
|
86
|
-
return true
|
|
86
|
+
return true;
|
|
87
87
|
}
|
|
88
|
-
return false
|
|
88
|
+
return false;
|
|
89
89
|
}
|
|
90
90
|
if (typeof appliesDuring === "object") {
|
|
91
91
|
for (const key of Object.keys(appliesDuring)) {
|
|
92
92
|
if (!appliesDuring[key] && kitchenContext[key]) {
|
|
93
|
-
return false
|
|
93
|
+
return false;
|
|
94
94
|
}
|
|
95
95
|
if (appliesDuring[key] && kitchenContext[key]) {
|
|
96
|
-
return true
|
|
96
|
+
return true;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
// throw new Error(`"appliesDuring" is empty`)
|
|
100
|
-
return false
|
|
100
|
+
return false;
|
|
101
101
|
}
|
|
102
102
|
throw new TypeError(
|
|
103
103
|
`"appliesDuring" must be an object or a string, got ${appliesDuring}`,
|
|
104
|
-
)
|
|
105
|
-
}
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
106
|
const initPlugin = (plugin) => {
|
|
107
107
|
if (plugin.init) {
|
|
108
|
-
const initReturnValue = plugin.init(kitchenContext)
|
|
108
|
+
const initReturnValue = plugin.init(kitchenContext);
|
|
109
109
|
if (initReturnValue === false) {
|
|
110
|
-
return false
|
|
110
|
+
return false;
|
|
111
111
|
}
|
|
112
112
|
if (typeof initReturnValue === "function" && !plugin.destroy) {
|
|
113
|
-
plugin.destroy = initReturnValue
|
|
113
|
+
plugin.destroy = initReturnValue;
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
return true
|
|
117
|
-
}
|
|
116
|
+
return true;
|
|
117
|
+
};
|
|
118
118
|
const pushPlugin = (plugin) => {
|
|
119
|
-
addPlugin(plugin, { position: "start" })
|
|
120
|
-
}
|
|
119
|
+
addPlugin(plugin, { position: "start" });
|
|
120
|
+
};
|
|
121
121
|
const unshiftPlugin = (plugin) => {
|
|
122
|
-
addPlugin(plugin, { position: "end" })
|
|
123
|
-
}
|
|
122
|
+
addPlugin(plugin, { position: "end" });
|
|
123
|
+
};
|
|
124
124
|
|
|
125
|
-
let lastPluginUsed = null
|
|
126
|
-
let currentPlugin = null
|
|
127
|
-
let currentHookName = null
|
|
125
|
+
let lastPluginUsed = null;
|
|
126
|
+
let currentPlugin = null;
|
|
127
|
+
let currentHookName = null;
|
|
128
128
|
const callHook = (hook, info, context) => {
|
|
129
|
-
const hookFn = getHookFunction(hook, info)
|
|
129
|
+
const hookFn = getHookFunction(hook, info);
|
|
130
130
|
if (!hookFn) {
|
|
131
|
-
return null
|
|
131
|
+
return null;
|
|
132
132
|
}
|
|
133
|
-
let startTimestamp
|
|
133
|
+
let startTimestamp;
|
|
134
134
|
if (info.timing) {
|
|
135
|
-
startTimestamp = performance.now()
|
|
135
|
+
startTimestamp = performance.now();
|
|
136
136
|
}
|
|
137
|
-
lastPluginUsed = hook.plugin
|
|
138
|
-
currentPlugin = hook.plugin
|
|
139
|
-
currentHookName = hook.name
|
|
140
|
-
let valueReturned = hookFn(info, context)
|
|
141
|
-
currentPlugin = null
|
|
142
|
-
currentHookName = null
|
|
137
|
+
lastPluginUsed = hook.plugin;
|
|
138
|
+
currentPlugin = hook.plugin;
|
|
139
|
+
currentHookName = hook.name;
|
|
140
|
+
let valueReturned = hookFn(info, context);
|
|
141
|
+
currentPlugin = null;
|
|
142
|
+
currentHookName = null;
|
|
143
143
|
if (info.timing) {
|
|
144
144
|
info.timing[`${hook.name}-${hook.plugin.name.replace("jsenv:", "")}`] =
|
|
145
|
-
performance.now() - startTimestamp
|
|
145
|
+
performance.now() - startTimestamp;
|
|
146
146
|
}
|
|
147
|
-
valueReturned = assertAndNormalizeReturnValue(hook.name, valueReturned)
|
|
148
|
-
return valueReturned
|
|
149
|
-
}
|
|
147
|
+
valueReturned = assertAndNormalizeReturnValue(hook.name, valueReturned);
|
|
148
|
+
return valueReturned;
|
|
149
|
+
};
|
|
150
150
|
const callAsyncHook = async (hook, info, context) => {
|
|
151
|
-
const hookFn = getHookFunction(hook, info)
|
|
151
|
+
const hookFn = getHookFunction(hook, info);
|
|
152
152
|
if (!hookFn) {
|
|
153
|
-
return null
|
|
153
|
+
return null;
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
let startTimestamp
|
|
156
|
+
let startTimestamp;
|
|
157
157
|
if (info.timing) {
|
|
158
|
-
startTimestamp = performance.now()
|
|
158
|
+
startTimestamp = performance.now();
|
|
159
159
|
}
|
|
160
|
-
lastPluginUsed = hook.plugin
|
|
161
|
-
currentPlugin = hook.plugin
|
|
162
|
-
currentHookName = hook.name
|
|
163
|
-
let valueReturned = await hookFn(info, context)
|
|
164
|
-
currentPlugin = null
|
|
165
|
-
currentHookName = null
|
|
160
|
+
lastPluginUsed = hook.plugin;
|
|
161
|
+
currentPlugin = hook.plugin;
|
|
162
|
+
currentHookName = hook.name;
|
|
163
|
+
let valueReturned = await hookFn(info, context);
|
|
164
|
+
currentPlugin = null;
|
|
165
|
+
currentHookName = null;
|
|
166
166
|
if (info.timing) {
|
|
167
167
|
info.timing[`${hook.name}-${hook.plugin.name.replace("jsenv:", "")}`] =
|
|
168
|
-
performance.now() - startTimestamp
|
|
168
|
+
performance.now() - startTimestamp;
|
|
169
169
|
}
|
|
170
|
-
valueReturned = assertAndNormalizeReturnValue(hook.name, valueReturned)
|
|
171
|
-
return valueReturned
|
|
172
|
-
}
|
|
170
|
+
valueReturned = assertAndNormalizeReturnValue(hook.name, valueReturned);
|
|
171
|
+
return valueReturned;
|
|
172
|
+
};
|
|
173
173
|
|
|
174
174
|
const callHooks = (hookName, info, context, callback) => {
|
|
175
|
-
const hooks = hookGroups[hookName]
|
|
175
|
+
const hooks = hookGroups[hookName];
|
|
176
176
|
if (hooks) {
|
|
177
177
|
for (const hook of hooks) {
|
|
178
|
-
const returnValue = callHook(hook, info, context)
|
|
178
|
+
const returnValue = callHook(hook, info, context);
|
|
179
179
|
if (returnValue && callback) {
|
|
180
|
-
callback(returnValue, hook.plugin)
|
|
180
|
+
callback(returnValue, hook.plugin);
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
|
-
}
|
|
184
|
+
};
|
|
185
185
|
const callAsyncHooks = async (hookName, info, context, callback) => {
|
|
186
|
-
const hooks = hookGroups[hookName]
|
|
186
|
+
const hooks = hookGroups[hookName];
|
|
187
187
|
if (hooks) {
|
|
188
188
|
await hooks.reduce(async (previous, hook) => {
|
|
189
|
-
await previous
|
|
190
|
-
const returnValue = await callAsyncHook(hook, info, context)
|
|
189
|
+
await previous;
|
|
190
|
+
const returnValue = await callAsyncHook(hook, info, context);
|
|
191
191
|
if (returnValue && callback) {
|
|
192
|
-
await callback(returnValue, hook.plugin)
|
|
192
|
+
await callback(returnValue, hook.plugin);
|
|
193
193
|
}
|
|
194
|
-
}, Promise.resolve())
|
|
194
|
+
}, Promise.resolve());
|
|
195
195
|
}
|
|
196
|
-
}
|
|
196
|
+
};
|
|
197
197
|
|
|
198
198
|
const callHooksUntil = (hookName, info, context) => {
|
|
199
|
-
const hooks = hookGroups[hookName]
|
|
199
|
+
const hooks = hookGroups[hookName];
|
|
200
200
|
if (hooks) {
|
|
201
201
|
for (const hook of hooks) {
|
|
202
|
-
const returnValue = callHook(hook, info, context)
|
|
202
|
+
const returnValue = callHook(hook, info, context);
|
|
203
203
|
if (returnValue) {
|
|
204
|
-
return returnValue
|
|
204
|
+
return returnValue;
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
-
return null
|
|
209
|
-
}
|
|
208
|
+
return null;
|
|
209
|
+
};
|
|
210
210
|
const callAsyncHooksUntil = (hookName, info, context) => {
|
|
211
|
-
const hooks = hookGroups[hookName]
|
|
211
|
+
const hooks = hookGroups[hookName];
|
|
212
212
|
if (!hooks) {
|
|
213
|
-
return null
|
|
213
|
+
return null;
|
|
214
214
|
}
|
|
215
215
|
if (hooks.length === 0) {
|
|
216
|
-
return null
|
|
216
|
+
return null;
|
|
217
217
|
}
|
|
218
218
|
return new Promise((resolve, reject) => {
|
|
219
219
|
const visit = (index) => {
|
|
220
220
|
if (index >= hooks.length) {
|
|
221
|
-
return resolve()
|
|
221
|
+
return resolve();
|
|
222
222
|
}
|
|
223
|
-
const hook = hooks[index]
|
|
224
|
-
const returnValue = callAsyncHook(hook, info, context)
|
|
223
|
+
const hook = hooks[index];
|
|
224
|
+
const returnValue = callAsyncHook(hook, info, context);
|
|
225
225
|
return Promise.resolve(returnValue).then((output) => {
|
|
226
226
|
if (output) {
|
|
227
|
-
return resolve(output)
|
|
227
|
+
return resolve(output);
|
|
228
228
|
}
|
|
229
|
-
return visit(index + 1)
|
|
230
|
-
}, reject)
|
|
231
|
-
}
|
|
232
|
-
visit(0)
|
|
233
|
-
})
|
|
234
|
-
}
|
|
229
|
+
return visit(index + 1);
|
|
230
|
+
}, reject);
|
|
231
|
+
};
|
|
232
|
+
visit(0);
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
235
|
|
|
236
236
|
return {
|
|
237
237
|
plugins,
|
|
@@ -249,43 +249,43 @@ export const createPluginController = (kitchenContext) => {
|
|
|
249
249
|
getLastPluginUsed: () => lastPluginUsed,
|
|
250
250
|
getCurrentPlugin: () => currentPlugin,
|
|
251
251
|
getCurrentHookName: () => currentHookName,
|
|
252
|
-
}
|
|
253
|
-
}
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
254
|
|
|
255
255
|
const getHookFunction = (
|
|
256
256
|
hook,
|
|
257
257
|
// can be undefined, reference, or urlInfo
|
|
258
258
|
info = {},
|
|
259
259
|
) => {
|
|
260
|
-
const hookValue = hook.value
|
|
260
|
+
const hookValue = hook.value;
|
|
261
261
|
if (typeof hookValue === "object") {
|
|
262
|
-
const hookForType = hookValue[info.type] || hookValue["*"]
|
|
262
|
+
const hookForType = hookValue[info.type] || hookValue["*"];
|
|
263
263
|
if (!hookForType) {
|
|
264
|
-
return null
|
|
264
|
+
return null;
|
|
265
265
|
}
|
|
266
|
-
return hookForType
|
|
266
|
+
return hookForType;
|
|
267
267
|
}
|
|
268
|
-
return hookValue
|
|
269
|
-
}
|
|
268
|
+
return hookValue;
|
|
269
|
+
};
|
|
270
270
|
|
|
271
271
|
const assertAndNormalizeReturnValue = (hookName, returnValue) => {
|
|
272
272
|
// all hooks are allowed to return null/undefined as a signal of "I don't do anything"
|
|
273
273
|
if (returnValue === null || returnValue === undefined) {
|
|
274
|
-
return returnValue
|
|
274
|
+
return returnValue;
|
|
275
275
|
}
|
|
276
276
|
for (const returnValueAssertion of returnValueAssertions) {
|
|
277
277
|
if (!returnValueAssertion.appliesTo.includes(hookName)) {
|
|
278
|
-
continue
|
|
278
|
+
continue;
|
|
279
279
|
}
|
|
280
|
-
const assertionResult = returnValueAssertion.assertion(returnValue)
|
|
280
|
+
const assertionResult = returnValueAssertion.assertion(returnValue);
|
|
281
281
|
if (assertionResult !== undefined) {
|
|
282
282
|
// normalization
|
|
283
|
-
returnValue = assertionResult
|
|
284
|
-
break
|
|
283
|
+
returnValue = assertionResult;
|
|
284
|
+
break;
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
|
-
return returnValue
|
|
288
|
-
}
|
|
287
|
+
return returnValue;
|
|
288
|
+
};
|
|
289
289
|
|
|
290
290
|
const returnValueAssertions = [
|
|
291
291
|
{
|
|
@@ -293,14 +293,14 @@ const returnValueAssertions = [
|
|
|
293
293
|
appliesTo: ["resolveUrl", "redirectUrl"],
|
|
294
294
|
assertion: (valueReturned) => {
|
|
295
295
|
if (valueReturned instanceof URL) {
|
|
296
|
-
return valueReturned.href
|
|
296
|
+
return valueReturned.href;
|
|
297
297
|
}
|
|
298
298
|
if (typeof valueReturned === "string") {
|
|
299
|
-
return undefined
|
|
299
|
+
return undefined;
|
|
300
300
|
}
|
|
301
301
|
throw new Error(
|
|
302
302
|
`Unexpected value returned by plugin: it must be a string; got ${valueReturned}`,
|
|
303
|
-
)
|
|
303
|
+
);
|
|
304
304
|
},
|
|
305
305
|
},
|
|
306
306
|
{
|
|
@@ -313,23 +313,23 @@ const returnValueAssertions = [
|
|
|
313
313
|
],
|
|
314
314
|
assertion: (valueReturned) => {
|
|
315
315
|
if (typeof valueReturned === "string" || Buffer.isBuffer(valueReturned)) {
|
|
316
|
-
return { content: valueReturned }
|
|
316
|
+
return { content: valueReturned };
|
|
317
317
|
}
|
|
318
318
|
if (typeof valueReturned === "object") {
|
|
319
|
-
const { shouldHandle, content, body } = valueReturned
|
|
319
|
+
const { shouldHandle, content, body } = valueReturned;
|
|
320
320
|
if (shouldHandle === false) {
|
|
321
|
-
return undefined
|
|
321
|
+
return undefined;
|
|
322
322
|
}
|
|
323
323
|
if (typeof content !== "string" && !Buffer.isBuffer(content) && !body) {
|
|
324
324
|
throw new Error(
|
|
325
325
|
`Unexpected "content" returned by plugin: it must be a string or a buffer; got ${content}`,
|
|
326
|
-
)
|
|
326
|
+
);
|
|
327
327
|
}
|
|
328
|
-
return undefined
|
|
328
|
+
return undefined;
|
|
329
329
|
}
|
|
330
330
|
throw new Error(
|
|
331
331
|
`Unexpected value returned by plugin: it must be a string, a buffer or an object; got ${valueReturned}`,
|
|
332
|
-
)
|
|
332
|
+
);
|
|
333
333
|
},
|
|
334
334
|
},
|
|
335
|
-
]
|
|
335
|
+
];
|
package/src/plugins/plugins.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { jsenvPluginUrlAnalysis } from "./url_analysis/jsenv_plugin_url_analysis.js"
|
|
2
|
-
import { jsenvPluginImportmap } from "./importmap/jsenv_plugin_importmap.js"
|
|
3
|
-
import { jsenvPluginUrlResolution } from "./url_resolution/jsenv_plugin_url_resolution.js"
|
|
4
|
-
import { jsenvPluginUrlVersion } from "./url_version/jsenv_plugin_url_version.js"
|
|
5
|
-
import { jsenvPluginFileUrls } from "./file_urls/jsenv_plugin_file_urls.js"
|
|
6
|
-
import { jsenvPluginHttpUrls } from "./http_urls/jsenv_plugin_http_urls.js"
|
|
7
|
-
import { jsenvPluginInlineContentAnalysis } from "./inline_content_analysis/jsenv_plugin_inline_content_analysis.js"
|
|
8
|
-
import { jsenvPluginInlining } from "./inlining/jsenv_plugin_inlining.js"
|
|
9
|
-
import { jsenvPluginSupervisor } from "./supervisor/jsenv_plugin_supervisor.js"
|
|
10
|
-
import { jsenvPluginCommonJsGlobals } from "./commonjs_globals/jsenv_plugin_commonjs_globals.js"
|
|
11
|
-
import { jsenvPluginImportMetaScenarios } from "./import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js"
|
|
12
|
-
import { jsenvPluginGlobalScenarios } from "./global_scenarios/jsenv_plugin_global_scenarios.js"
|
|
13
|
-
import { jsenvPluginTranspilation } from "./transpilation/jsenv_plugin_transpilation.js"
|
|
14
|
-
import { jsenvPluginNodeRuntime } from "./node_runtime/jsenv_plugin_node_runtime.js"
|
|
1
|
+
import { jsenvPluginUrlAnalysis } from "./url_analysis/jsenv_plugin_url_analysis.js";
|
|
2
|
+
import { jsenvPluginImportmap } from "./importmap/jsenv_plugin_importmap.js";
|
|
3
|
+
import { jsenvPluginUrlResolution } from "./url_resolution/jsenv_plugin_url_resolution.js";
|
|
4
|
+
import { jsenvPluginUrlVersion } from "./url_version/jsenv_plugin_url_version.js";
|
|
5
|
+
import { jsenvPluginFileUrls } from "./file_urls/jsenv_plugin_file_urls.js";
|
|
6
|
+
import { jsenvPluginHttpUrls } from "./http_urls/jsenv_plugin_http_urls.js";
|
|
7
|
+
import { jsenvPluginInlineContentAnalysis } from "./inline_content_analysis/jsenv_plugin_inline_content_analysis.js";
|
|
8
|
+
import { jsenvPluginInlining } from "./inlining/jsenv_plugin_inlining.js";
|
|
9
|
+
import { jsenvPluginSupervisor } from "./supervisor/jsenv_plugin_supervisor.js";
|
|
10
|
+
import { jsenvPluginCommonJsGlobals } from "./commonjs_globals/jsenv_plugin_commonjs_globals.js";
|
|
11
|
+
import { jsenvPluginImportMetaScenarios } from "./import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js";
|
|
12
|
+
import { jsenvPluginGlobalScenarios } from "./global_scenarios/jsenv_plugin_global_scenarios.js";
|
|
13
|
+
import { jsenvPluginTranspilation } from "./transpilation/jsenv_plugin_transpilation.js";
|
|
14
|
+
import { jsenvPluginNodeRuntime } from "./node_runtime/jsenv_plugin_node_runtime.js";
|
|
15
15
|
// autoreload
|
|
16
|
-
import { jsenvPluginImportMetaHot } from "./import_meta_hot/jsenv_plugin_import_meta_hot.js"
|
|
17
|
-
import { jsenvPluginAutoreload } from "./autoreload/jsenv_plugin_autoreload.js"
|
|
18
|
-
import { jsenvPluginCacheControl } from "./cache_control/jsenv_plugin_cache_control.js"
|
|
16
|
+
import { jsenvPluginImportMetaHot } from "./import_meta_hot/jsenv_plugin_import_meta_hot.js";
|
|
17
|
+
import { jsenvPluginAutoreload } from "./autoreload/jsenv_plugin_autoreload.js";
|
|
18
|
+
import { jsenvPluginCacheControl } from "./cache_control/jsenv_plugin_cache_control.js";
|
|
19
19
|
// dev only
|
|
20
|
-
import { jsenvPluginExplorer } from "./explorer/jsenv_plugin_explorer.js"
|
|
20
|
+
import { jsenvPluginExplorer } from "./explorer/jsenv_plugin_explorer.js";
|
|
21
21
|
// other
|
|
22
|
-
import { jsenvPluginRibbon } from "./ribbon/jsenv_plugin_ribbon.js"
|
|
22
|
+
import { jsenvPluginRibbon } from "./ribbon/jsenv_plugin_ribbon.js";
|
|
23
23
|
|
|
24
24
|
export const getCorePlugins = ({
|
|
25
25
|
rootDirectoryUrl,
|
|
@@ -43,23 +43,23 @@ export const getCorePlugins = ({
|
|
|
43
43
|
ribbon = true,
|
|
44
44
|
} = {}) => {
|
|
45
45
|
if (explorer === true) {
|
|
46
|
-
explorer = {}
|
|
46
|
+
explorer = {};
|
|
47
47
|
}
|
|
48
48
|
if (cacheControl === true) {
|
|
49
|
-
cacheControl = {}
|
|
49
|
+
cacheControl = {};
|
|
50
50
|
}
|
|
51
51
|
if (supervisor === true) {
|
|
52
|
-
supervisor = {}
|
|
52
|
+
supervisor = {};
|
|
53
53
|
}
|
|
54
54
|
if (fileSystemMagicRedirection === true) {
|
|
55
|
-
fileSystemMagicRedirection = {}
|
|
55
|
+
fileSystemMagicRedirection = {};
|
|
56
56
|
}
|
|
57
57
|
if (clientAutoreload === true) {
|
|
58
|
-
clientAutoreload = {}
|
|
58
|
+
clientAutoreload = {};
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
if (ribbon === true) {
|
|
62
|
-
ribbon = {}
|
|
62
|
+
ribbon = {};
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
return [
|
|
@@ -101,5 +101,5 @@ export const getCorePlugins = ({
|
|
|
101
101
|
...(cacheControl ? [jsenvPluginCacheControl(cacheControl)] : []),
|
|
102
102
|
...(explorer ? [jsenvPluginExplorer(explorer)] : []),
|
|
103
103
|
...(ribbon ? [jsenvPluginRibbon({ rootDirectoryUrl, ...ribbon })] : []),
|
|
104
|
-
]
|
|
105
|
-
}
|
|
104
|
+
];
|
|
105
|
+
};
|
|
@@ -36,16 +36,16 @@ export const injectRibbon = ({ text }) => {
|
|
|
36
36
|
text-align: center;
|
|
37
37
|
user-select: none;
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
`;
|
|
40
40
|
|
|
41
41
|
const html = /* html */ `<div id="jsenv_ribbon_container">
|
|
42
42
|
<style>${css}</style>
|
|
43
43
|
<div id="jsenv_ribbon">
|
|
44
44
|
<div id="jsenv_ribbon_text">${text}</div>
|
|
45
45
|
</div>
|
|
46
|
-
</div
|
|
46
|
+
</div>`;
|
|
47
47
|
|
|
48
|
-
const node = document.createElement("div")
|
|
49
|
-
node.innerHTML = html
|
|
50
|
-
document.body.appendChild(node.firstChild)
|
|
51
|
-
}
|
|
48
|
+
const node = document.createElement("div");
|
|
49
|
+
node.innerHTML = html;
|
|
50
|
+
document.body.appendChild(node.firstChild);
|
|
51
|
+
};
|
|
@@ -3,15 +3,15 @@ import {
|
|
|
3
3
|
stringifyHtmlAst,
|
|
4
4
|
createHtmlNode,
|
|
5
5
|
injectHtmlNode,
|
|
6
|
-
} from "@jsenv/ast"
|
|
7
|
-
import { URL_META } from "@jsenv/url-meta"
|
|
8
|
-
import { asUrlWithoutSearch } from "@jsenv/urls"
|
|
6
|
+
} from "@jsenv/ast";
|
|
7
|
+
import { URL_META } from "@jsenv/url-meta";
|
|
8
|
+
import { asUrlWithoutSearch } from "@jsenv/urls";
|
|
9
9
|
|
|
10
10
|
export const jsenvPluginRibbon = ({
|
|
11
11
|
rootDirectoryUrl,
|
|
12
12
|
htmlInclude = "/**/*.html",
|
|
13
13
|
}) => {
|
|
14
|
-
const ribbonClientFileUrl = new URL("./client/ribbon.js", import.meta.url)
|
|
14
|
+
const ribbonClientFileUrl = new URL("./client/ribbon.js", import.meta.url);
|
|
15
15
|
const associations = URL_META.resolveAssociations(
|
|
16
16
|
{
|
|
17
17
|
ribbon: {
|
|
@@ -19,34 +19,34 @@ export const jsenvPluginRibbon = ({
|
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
21
|
rootDirectoryUrl,
|
|
22
|
-
)
|
|
22
|
+
);
|
|
23
23
|
return {
|
|
24
24
|
name: "jsenv:ribbon",
|
|
25
25
|
appliesDuring: "dev",
|
|
26
26
|
transformUrlContent: {
|
|
27
27
|
html: (urlInfo, context) => {
|
|
28
28
|
if (urlInfo.data.isJsenvToolbar || urlInfo.data.noribbon) {
|
|
29
|
-
return null
|
|
29
|
+
return null;
|
|
30
30
|
}
|
|
31
31
|
const { ribbon } = URL_META.applyAssociations({
|
|
32
32
|
url: asUrlWithoutSearch(urlInfo.url),
|
|
33
33
|
associations,
|
|
34
|
-
})
|
|
34
|
+
});
|
|
35
35
|
if (!ribbon) {
|
|
36
|
-
return null
|
|
36
|
+
return null;
|
|
37
37
|
}
|
|
38
|
-
const htmlAst = parseHtmlString(urlInfo.content)
|
|
38
|
+
const htmlAst = parseHtmlString(urlInfo.content);
|
|
39
39
|
const [ribbonClientFileReference] = context.referenceUtils.inject({
|
|
40
40
|
type: "script",
|
|
41
41
|
subtype: "js_module",
|
|
42
42
|
expectedType: "js_module",
|
|
43
43
|
specifier: ribbonClientFileUrl.href,
|
|
44
|
-
})
|
|
44
|
+
});
|
|
45
45
|
const paramsJson = JSON.stringify(
|
|
46
46
|
{ text: context.dev ? "DEV" : "BUILD" },
|
|
47
47
|
null,
|
|
48
48
|
" ",
|
|
49
|
-
)
|
|
49
|
+
);
|
|
50
50
|
injectHtmlNode(
|
|
51
51
|
htmlAst,
|
|
52
52
|
createHtmlNode({
|
|
@@ -57,9 +57,9 @@ export const jsenvPluginRibbon = ({
|
|
|
57
57
|
injectRibbon(${paramsJson});`,
|
|
58
58
|
}),
|
|
59
59
|
"jsenv:ribbon",
|
|
60
|
-
)
|
|
61
|
-
return stringifyHtmlAst(htmlAst)
|
|
60
|
+
);
|
|
61
|
+
return stringifyHtmlAst(htmlAst);
|
|
62
62
|
},
|
|
63
63
|
},
|
|
64
|
-
}
|
|
65
|
-
}
|
|
64
|
+
};
|
|
65
|
+
};
|