@jsenv/core 35.0.5 → 36.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/js/inline_content.js +5 -4
- package/dist/jsenv_core.js +1127 -1497
- package/package.json +8 -8
- package/src/build/build.js +49 -41
- package/src/dev/file_service.js +7 -17
- package/src/dev/start_dev_server.js +12 -7
- package/src/kitchen/kitchen.js +38 -19
- package/src/kitchen/url_graph.js +1 -1
- package/src/plugins/autoreload/jsenv_plugin_hmr.js +2 -2
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +4 -4
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +1 -1
- package/src/plugins/importmap/jsenv_plugin_importmap.js +1 -1
- package/src/plugins/inlining/jsenv_plugin_inlining.js +1 -1
- package/src/plugins/inlining/jsenv_plugin_inlining_as_data_url.js +13 -2
- package/src/plugins/plugin_controller.js +19 -10
- package/src/plugins/plugins.js +21 -25
- package/src/plugins/{url_analysis/css/css_urls.js → reference_analysis/css/jsenv_plugin_css_reference_analysis.js} +11 -1
- package/src/plugins/{inline_content_analysis/jsenv_plugin_data_urls.js → reference_analysis/data_urls/jsenv_plugin_data_urls_analysis.js} +19 -19
- package/src/plugins/reference_analysis/directory/jsenv_plugin_directory_reference_analysis.js +51 -0
- package/src/plugins/reference_analysis/html/jsenv_plugin_html_reference_analysis.js +429 -0
- package/src/plugins/reference_analysis/inline_content.js +7 -0
- package/src/plugins/reference_analysis/js/jsenv_plugin_js_reference_analysis.js +161 -0
- package/src/plugins/reference_analysis/jsenv_plugin_reference_analysis.js +120 -0
- package/src/plugins/{url_analysis → reference_analysis}/jsenv_plugin_reference_expected_types.js +19 -12
- package/src/plugins/{url_analysis/webmanifest/webmanifest_urls.js → reference_analysis/webmanifest/jsenv_plugin_webmanifest_reference_analysis.js} +13 -1
- package/src/plugins/resolution_node_esm/jsenv_plugin_node_esm_resolution.js +74 -0
- package/src/plugins/{url_resolution → resolution_node_esm}/node_esm_resolver.js +8 -0
- package/src/plugins/resolution_web/jsenv_plugin_web_resolution.js +45 -0
- package/src/plugins/transpilation/as_js_module/jsenv_plugin_as_js_module.js +1 -1
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +1 -1
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +4 -6
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_conversion.js +1 -1
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +4 -6
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +1 -1
- package/src/plugins/url_type_from_reference.js +13 -0
- package/src/plugins/{url_version/jsenv_plugin_url_version.js → version_search_param/jsenv_plugin_version_search_param.js} +4 -4
- package/dist/html/explorer.html +0 -559
- package/dist/other/jsenv.png +0 -0
- package/src/plugins/explorer/client/explorer.html +0 -608
- package/src/plugins/explorer/client/jsenv.png +0 -0
- package/src/plugins/explorer/jsenv_plugin_explorer.js +0 -86
- package/src/plugins/inline_content_analysis/client/inline_content.js +0 -6
- package/src/plugins/inline_content_analysis/jsenv_plugin_html_inline_content_analysis.js +0 -206
- package/src/plugins/inline_content_analysis/jsenv_plugin_inline_content_analysis.js +0 -34
- package/src/plugins/inline_content_analysis/jsenv_plugin_js_inline_content_analysis.js +0 -314
- package/src/plugins/url_analysis/html/html_urls.js +0 -313
- package/src/plugins/url_analysis/js/js_urls.js +0 -65
- package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +0 -116
- package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +0 -140
|
@@ -3,12 +3,12 @@ import { performance } from "node:perf_hooks";
|
|
|
3
3
|
const HOOK_NAMES = [
|
|
4
4
|
"init",
|
|
5
5
|
"serve", // is called only during dev/tests
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"resolveReference",
|
|
7
|
+
"redirectReference",
|
|
8
|
+
"transformReferenceSearchParams",
|
|
9
|
+
"formatReference",
|
|
8
10
|
"fetchUrlContent",
|
|
9
11
|
"transformUrlContent",
|
|
10
|
-
"transformUrlSearchParams",
|
|
11
|
-
"formatUrl",
|
|
12
12
|
"finalizeUrlContent",
|
|
13
13
|
"bundle", // is called only during build
|
|
14
14
|
"optimizeUrlContent", // is called only during build
|
|
@@ -23,7 +23,16 @@ export const createPluginController = (kitchenContext) => {
|
|
|
23
23
|
// - When debugging, there is less iteration
|
|
24
24
|
// also it should increase perf as there is less work to do
|
|
25
25
|
const hookGroups = {};
|
|
26
|
-
const addPlugin = (plugin, { position = "
|
|
26
|
+
const addPlugin = (plugin, { position = "end" }) => {
|
|
27
|
+
if (Array.isArray(plugin)) {
|
|
28
|
+
if (position === "start") {
|
|
29
|
+
plugin = plugin.slice().reverse();
|
|
30
|
+
}
|
|
31
|
+
plugin.forEach((plugin) => {
|
|
32
|
+
addPlugin(plugin, { position });
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
27
36
|
if (plugin === null || typeof plugin !== "object") {
|
|
28
37
|
throw new TypeError(`plugin must be objects, got ${plugin}`);
|
|
29
38
|
}
|
|
@@ -60,9 +69,9 @@ export const createPluginController = (kitchenContext) => {
|
|
|
60
69
|
value: hookValue,
|
|
61
70
|
};
|
|
62
71
|
if (position === "start") {
|
|
63
|
-
group.push(hook);
|
|
64
|
-
} else {
|
|
65
72
|
group.unshift(hook);
|
|
73
|
+
} else {
|
|
74
|
+
group.push(hook);
|
|
66
75
|
}
|
|
67
76
|
}
|
|
68
77
|
});
|
|
@@ -116,10 +125,10 @@ export const createPluginController = (kitchenContext) => {
|
|
|
116
125
|
return true;
|
|
117
126
|
};
|
|
118
127
|
const pushPlugin = (plugin) => {
|
|
119
|
-
addPlugin(plugin, { position: "
|
|
128
|
+
addPlugin(plugin, { position: "end" });
|
|
120
129
|
};
|
|
121
130
|
const unshiftPlugin = (plugin) => {
|
|
122
|
-
addPlugin(plugin, { position: "
|
|
131
|
+
addPlugin(plugin, { position: "start" });
|
|
123
132
|
};
|
|
124
133
|
|
|
125
134
|
let lastPluginUsed = null;
|
|
@@ -290,7 +299,7 @@ const assertAndNormalizeReturnValue = (hookName, returnValue) => {
|
|
|
290
299
|
const returnValueAssertions = [
|
|
291
300
|
{
|
|
292
301
|
name: "url_assertion",
|
|
293
|
-
appliesTo: ["
|
|
302
|
+
appliesTo: ["resolveReference", "redirectReference"],
|
|
294
303
|
assertion: (valueReturned) => {
|
|
295
304
|
if (valueReturned instanceof URL) {
|
|
296
305
|
return valueReturned.href;
|
package/src/plugins/plugins.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsenvPluginReferenceAnalysis } from "./reference_analysis/jsenv_plugin_reference_analysis.js";
|
|
2
2
|
import { jsenvPluginImportmap } from "./importmap/jsenv_plugin_importmap.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { jsenvPluginNodeEsmResolution } from "./resolution_node_esm/jsenv_plugin_node_esm_resolution.js";
|
|
4
|
+
import { jsenvPluginWebResolution } from "./resolution_web/jsenv_plugin_web_resolution.js";
|
|
5
|
+
import { jsenvPluginVersionSearchParam } from "./version_search_param/jsenv_plugin_version_search_param.js";
|
|
5
6
|
import { jsenvPluginFileUrls } from "./file_urls/jsenv_plugin_file_urls.js";
|
|
6
7
|
import { jsenvPluginHttpUrls } from "./http_urls/jsenv_plugin_http_urls.js";
|
|
7
|
-
import { jsenvPluginInlineContentAnalysis } from "./inline_content_analysis/jsenv_plugin_inline_content_analysis.js";
|
|
8
8
|
import { jsenvPluginInlining } from "./inlining/jsenv_plugin_inlining.js";
|
|
9
9
|
import { jsenvPluginSupervisor } from "./supervisor/jsenv_plugin_supervisor.js";
|
|
10
10
|
import { jsenvPluginCommonJsGlobals } from "./commonjs_globals/jsenv_plugin_commonjs_globals.js";
|
|
@@ -16,18 +16,16 @@ import { jsenvPluginNodeRuntime } from "./node_runtime/jsenv_plugin_node_runtime
|
|
|
16
16
|
import { jsenvPluginImportMetaHot } from "./import_meta_hot/jsenv_plugin_import_meta_hot.js";
|
|
17
17
|
import { jsenvPluginAutoreload } from "./autoreload/jsenv_plugin_autoreload.js";
|
|
18
18
|
import { jsenvPluginCacheControl } from "./cache_control/jsenv_plugin_cache_control.js";
|
|
19
|
-
// dev only
|
|
20
|
-
import { jsenvPluginExplorer } from "./explorer/jsenv_plugin_explorer.js";
|
|
21
19
|
// other
|
|
22
20
|
import { jsenvPluginRibbon } from "./ribbon/jsenv_plugin_ribbon.js";
|
|
23
21
|
|
|
24
22
|
export const getCorePlugins = ({
|
|
25
23
|
rootDirectoryUrl,
|
|
26
|
-
defaultFileUrl,
|
|
27
24
|
runtimeCompat,
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
referenceAnalysis = {},
|
|
27
|
+
nodeEsmResolution = {},
|
|
28
|
+
webResolution = {},
|
|
31
29
|
fileSystemMagicRedirection,
|
|
32
30
|
directoryReferenceAllowed,
|
|
33
31
|
supervisor,
|
|
@@ -37,14 +35,10 @@ export const getCorePlugins = ({
|
|
|
37
35
|
clientAutoreload = false,
|
|
38
36
|
clientFileChangeCallbackList,
|
|
39
37
|
clientFilesPruneCallbackList,
|
|
40
|
-
explorer,
|
|
41
38
|
cacheControl,
|
|
42
39
|
scenarioPlaceholders = true,
|
|
43
40
|
ribbon = true,
|
|
44
41
|
} = {}) => {
|
|
45
|
-
if (explorer === true) {
|
|
46
|
-
explorer = {};
|
|
47
|
-
}
|
|
48
42
|
if (cacheControl === true) {
|
|
49
43
|
cacheControl = {};
|
|
50
44
|
}
|
|
@@ -57,31 +51,34 @@ export const getCorePlugins = ({
|
|
|
57
51
|
if (clientAutoreload === true) {
|
|
58
52
|
clientAutoreload = {};
|
|
59
53
|
}
|
|
60
|
-
|
|
61
54
|
if (ribbon === true) {
|
|
62
55
|
ribbon = {};
|
|
63
56
|
}
|
|
64
57
|
|
|
65
58
|
return [
|
|
66
|
-
|
|
59
|
+
jsenvPluginReferenceAnalysis(referenceAnalysis),
|
|
67
60
|
jsenvPluginTranspilation(transpilation),
|
|
68
61
|
jsenvPluginImportmap(),
|
|
69
|
-
// before node esm to handle bare specifiers
|
|
70
|
-
// + before node esm to handle importmap before inline content
|
|
71
|
-
jsenvPluginInlineContentAnalysis(), // before "file urls" to resolve and load inline urls
|
|
72
62
|
...(inlining ? [jsenvPluginInlining()] : []),
|
|
73
63
|
...(supervisor ? [jsenvPluginSupervisor(supervisor)] : []), // after inline as it needs inline script to be cooked
|
|
64
|
+
|
|
65
|
+
/* When resolving references the following applies by default:
|
|
66
|
+
- http urls are resolved by jsenvPluginHttpUrls
|
|
67
|
+
- reference.type === "filesystem" -> resolved by jsenv_plugin_file_urls.js
|
|
68
|
+
- reference inside a js module -> resolved by node esm
|
|
69
|
+
- All the rest uses web standard url resolution
|
|
70
|
+
*/
|
|
74
71
|
jsenvPluginFileUrls({
|
|
75
72
|
directoryReferenceAllowed,
|
|
76
73
|
...fileSystemMagicRedirection,
|
|
77
74
|
}),
|
|
78
75
|
jsenvPluginHttpUrls(),
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
76
|
+
...(nodeEsmResolution
|
|
77
|
+
? [jsenvPluginNodeEsmResolution(nodeEsmResolution)]
|
|
78
|
+
: []),
|
|
79
|
+
jsenvPluginWebResolution(webResolution),
|
|
80
|
+
|
|
81
|
+
jsenvPluginVersionSearchParam(),
|
|
85
82
|
jsenvPluginCommonJsGlobals(),
|
|
86
83
|
jsenvPluginImportMetaScenarios(),
|
|
87
84
|
...(scenarioPlaceholders ? [jsenvPluginGlobalScenarios()] : []),
|
|
@@ -99,7 +96,6 @@ export const getCorePlugins = ({
|
|
|
99
96
|
]
|
|
100
97
|
: []),
|
|
101
98
|
...(cacheControl ? [jsenvPluginCacheControl(cacheControl)] : []),
|
|
102
|
-
...(explorer ? [jsenvPluginExplorer(explorer)] : []),
|
|
103
99
|
...(ribbon ? [jsenvPluginRibbon({ rootDirectoryUrl, ...ribbon })] : []),
|
|
104
100
|
];
|
|
105
101
|
};
|
|
@@ -5,7 +5,17 @@
|
|
|
5
5
|
import { parseCssUrls } from "@jsenv/ast";
|
|
6
6
|
import { createMagicSource } from "@jsenv/sourcemap";
|
|
7
7
|
|
|
8
|
-
export const
|
|
8
|
+
export const jsenvPluginCssReferenceAnalysis = () => {
|
|
9
|
+
return {
|
|
10
|
+
name: "jsenv:css_reference_analysis",
|
|
11
|
+
appliesDuring: "*",
|
|
12
|
+
transformUrlContent: {
|
|
13
|
+
css: parseAndTransformCssUrls,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const parseAndTransformCssUrls = async (urlInfo, context) => {
|
|
9
19
|
const cssUrls = await parseCssUrls({
|
|
10
20
|
css: urlInfo.content,
|
|
11
21
|
url: urlInfo.originalUrl,
|
|
@@ -1,32 +1,17 @@
|
|
|
1
1
|
import { DATA_URL } from "@jsenv/urls";
|
|
2
2
|
import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js";
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const jsenvPluginDataUrlsAnalysis = () => {
|
|
5
5
|
return {
|
|
6
|
-
name: "jsenv:
|
|
6
|
+
name: "jsenv:data_urls_analysis",
|
|
7
7
|
appliesDuring: "*",
|
|
8
|
-
|
|
8
|
+
resolveReference: (reference) => {
|
|
9
9
|
if (!reference.specifier.startsWith("data:")) {
|
|
10
10
|
return null;
|
|
11
11
|
}
|
|
12
12
|
return reference.specifier;
|
|
13
13
|
},
|
|
14
|
-
|
|
15
|
-
if (!urlInfo.url.startsWith("data:")) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
const {
|
|
19
|
-
contentType,
|
|
20
|
-
base64Flag,
|
|
21
|
-
data: urlData,
|
|
22
|
-
} = DATA_URL.parse(urlInfo.url);
|
|
23
|
-
urlInfo.data.base64Flag = base64Flag;
|
|
24
|
-
return {
|
|
25
|
-
content: contentFromUrlData({ contentType, base64Flag, urlData }),
|
|
26
|
-
contentType,
|
|
27
|
-
};
|
|
28
|
-
},
|
|
29
|
-
formatUrl: (reference, context) => {
|
|
14
|
+
formatReference: (reference, context) => {
|
|
30
15
|
if (!reference.generatedUrl.startsWith("data:")) {
|
|
31
16
|
return null;
|
|
32
17
|
}
|
|
@@ -49,6 +34,21 @@ export const jsenvPluginDataUrls = () => {
|
|
|
49
34
|
return specifier;
|
|
50
35
|
})();
|
|
51
36
|
},
|
|
37
|
+
fetchUrlContent: (urlInfo) => {
|
|
38
|
+
if (!urlInfo.url.startsWith("data:")) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const {
|
|
42
|
+
contentType,
|
|
43
|
+
base64Flag,
|
|
44
|
+
data: urlData,
|
|
45
|
+
} = DATA_URL.parse(urlInfo.url);
|
|
46
|
+
urlInfo.data.base64Flag = base64Flag;
|
|
47
|
+
return {
|
|
48
|
+
content: contentFromUrlData({ contentType, base64Flag, urlData }),
|
|
49
|
+
contentType,
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
52
|
};
|
|
53
53
|
};
|
|
54
54
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { urlToRelativeUrl } from "@jsenv/urls";
|
|
2
|
+
|
|
3
|
+
export const jsenvPluginDirectoryReferenceAnalysis = () => {
|
|
4
|
+
return {
|
|
5
|
+
name: "jsenv:directory_reference_analysis",
|
|
6
|
+
transformUrlContent: {
|
|
7
|
+
directory: (urlInfo, context) => {
|
|
8
|
+
const originalDirectoryReference = findOriginalDirectoryReference(
|
|
9
|
+
urlInfo,
|
|
10
|
+
context,
|
|
11
|
+
);
|
|
12
|
+
const directoryRelativeUrl = urlToRelativeUrl(
|
|
13
|
+
urlInfo.url,
|
|
14
|
+
context.rootDirectoryUrl,
|
|
15
|
+
);
|
|
16
|
+
JSON.parse(urlInfo.content).forEach((directoryEntryName) => {
|
|
17
|
+
context.referenceUtils.found({
|
|
18
|
+
type: "filesystem",
|
|
19
|
+
subtype: "directory_entry",
|
|
20
|
+
specifier: directoryEntryName,
|
|
21
|
+
trace: {
|
|
22
|
+
message: `"${directoryRelativeUrl}${directoryEntryName}" entry in directory referenced by ${originalDirectoryReference.trace.message}`,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const findOriginalDirectoryReference = (urlInfo, context) => {
|
|
32
|
+
const findNonFileSystemAncestor = (urlInfo) => {
|
|
33
|
+
for (const dependentUrl of urlInfo.dependents) {
|
|
34
|
+
const dependentUrlInfo = context.urlGraph.getUrlInfo(dependentUrl);
|
|
35
|
+
if (dependentUrlInfo.type !== "directory") {
|
|
36
|
+
return [dependentUrlInfo, urlInfo];
|
|
37
|
+
}
|
|
38
|
+
const found = findNonFileSystemAncestor(dependentUrlInfo);
|
|
39
|
+
if (found) {
|
|
40
|
+
return found;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return [];
|
|
44
|
+
};
|
|
45
|
+
const [ancestor, child] = findNonFileSystemAncestor(urlInfo);
|
|
46
|
+
if (!ancestor) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const ref = ancestor.references.find((ref) => ref.url === child.url);
|
|
50
|
+
return ref;
|
|
51
|
+
};
|