@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,28 +1,28 @@
|
|
|
1
1
|
export const sortByDependencies = (nodes) => {
|
|
2
|
-
const visited = []
|
|
3
|
-
const sorted = []
|
|
4
|
-
const circular = []
|
|
2
|
+
const visited = [];
|
|
3
|
+
const sorted = [];
|
|
4
|
+
const circular = [];
|
|
5
5
|
const visit = (url) => {
|
|
6
|
-
const isSorted = sorted.includes(url)
|
|
6
|
+
const isSorted = sorted.includes(url);
|
|
7
7
|
if (isSorted) {
|
|
8
|
-
return
|
|
8
|
+
return;
|
|
9
9
|
}
|
|
10
|
-
const isVisited = visited.includes(url)
|
|
10
|
+
const isVisited = visited.includes(url);
|
|
11
11
|
if (isVisited) {
|
|
12
12
|
if (!circular.includes(url)) {
|
|
13
|
-
circular.push(url)
|
|
13
|
+
circular.push(url);
|
|
14
14
|
}
|
|
15
15
|
} else {
|
|
16
|
-
visited.push(url)
|
|
16
|
+
visited.push(url);
|
|
17
17
|
nodes[url].dependencies.forEach((dependencyUrl) => {
|
|
18
|
-
visit(dependencyUrl, url)
|
|
19
|
-
})
|
|
20
|
-
sorted.push(url)
|
|
18
|
+
visit(dependencyUrl, url);
|
|
19
|
+
});
|
|
20
|
+
sorted.push(url);
|
|
21
21
|
}
|
|
22
|
-
}
|
|
22
|
+
};
|
|
23
23
|
Object.keys(nodes).forEach((url) => {
|
|
24
|
-
visit(url)
|
|
25
|
-
})
|
|
26
|
-
sorted.circular = circular
|
|
27
|
-
return sorted
|
|
28
|
-
}
|
|
24
|
+
visit(url);
|
|
25
|
+
});
|
|
26
|
+
sorted.circular = circular;
|
|
27
|
+
return sorted;
|
|
28
|
+
};
|
|
@@ -1,77 +1,77 @@
|
|
|
1
1
|
export const createUrlGraphLoader = (context) => {
|
|
2
|
-
const promises = []
|
|
3
|
-
const promiseMap = new Map()
|
|
2
|
+
const promises = [];
|
|
3
|
+
const promiseMap = new Map();
|
|
4
4
|
const load = (
|
|
5
5
|
urlInfo,
|
|
6
6
|
dishContext,
|
|
7
7
|
{ ignoreRessourceHint = true, ignoreDynamicImport = false } = {},
|
|
8
8
|
) => {
|
|
9
|
-
const promiseFromData = promiseMap.get(urlInfo)
|
|
10
|
-
if (promiseFromData) return promiseFromData
|
|
9
|
+
const promiseFromData = promiseMap.get(urlInfo);
|
|
10
|
+
if (promiseFromData) return promiseFromData;
|
|
11
11
|
const promise = (async () => {
|
|
12
12
|
await context.cook(urlInfo, {
|
|
13
13
|
cookDuringCook: load,
|
|
14
14
|
...dishContext,
|
|
15
|
-
})
|
|
15
|
+
});
|
|
16
16
|
loadReferencedUrlInfos(urlInfo, {
|
|
17
17
|
ignoreRessourceHint,
|
|
18
18
|
ignoreDynamicImport,
|
|
19
|
-
})
|
|
20
|
-
})()
|
|
21
|
-
promises.push(promise)
|
|
22
|
-
promiseMap.set(urlInfo, promise)
|
|
23
|
-
return promise
|
|
24
|
-
}
|
|
19
|
+
});
|
|
20
|
+
})();
|
|
21
|
+
promises.push(promise);
|
|
22
|
+
promiseMap.set(urlInfo, promise);
|
|
23
|
+
return promise;
|
|
24
|
+
};
|
|
25
25
|
|
|
26
26
|
const loadReferencedUrlInfos = (
|
|
27
27
|
urlInfo,
|
|
28
28
|
{ ignoreRessourceHint, ignoreDynamicImport },
|
|
29
29
|
) => {
|
|
30
|
-
const { references } = urlInfo
|
|
30
|
+
const { references } = urlInfo;
|
|
31
31
|
references.forEach((reference) => {
|
|
32
32
|
// we don't cook resource hints
|
|
33
33
|
// because they might refer to resource that will be modified during build
|
|
34
34
|
// It also means something else have to reference that url in order to cook it
|
|
35
35
|
// so that the preload is deleted by "resync_resource_hints.js" otherwise
|
|
36
36
|
if (ignoreRessourceHint && reference.isResourceHint) {
|
|
37
|
-
return
|
|
37
|
+
return;
|
|
38
38
|
}
|
|
39
39
|
if (ignoreDynamicImport && reference.subtype === "import_dynamic") {
|
|
40
|
-
return
|
|
40
|
+
return;
|
|
41
41
|
}
|
|
42
42
|
// we use reference.generatedUrl to mimic what a browser would do:
|
|
43
43
|
// do a fetch to the specifier as found in the file
|
|
44
44
|
const referencedUrlInfo = context.urlGraph.reuseOrCreateUrlInfo(
|
|
45
45
|
reference.generatedUrl,
|
|
46
|
-
)
|
|
46
|
+
);
|
|
47
47
|
load(referencedUrlInfo, {
|
|
48
48
|
reference,
|
|
49
49
|
ignoreRessourceHint,
|
|
50
50
|
ignoreDynamicImport,
|
|
51
|
-
})
|
|
52
|
-
})
|
|
53
|
-
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
54
|
|
|
55
55
|
const getAllLoadDonePromise = async (operation) => {
|
|
56
56
|
const waitAll = async () => {
|
|
57
57
|
if (operation) {
|
|
58
|
-
operation.throwIfAborted()
|
|
58
|
+
operation.throwIfAborted();
|
|
59
59
|
}
|
|
60
60
|
if (promises.length === 0) {
|
|
61
|
-
return
|
|
61
|
+
return;
|
|
62
62
|
}
|
|
63
|
-
const promisesToWait = promises.slice()
|
|
64
|
-
promises.length = 0
|
|
65
|
-
await Promise.all(promisesToWait)
|
|
66
|
-
await waitAll()
|
|
67
|
-
}
|
|
68
|
-
await waitAll()
|
|
69
|
-
promiseMap.clear()
|
|
70
|
-
}
|
|
63
|
+
const promisesToWait = promises.slice();
|
|
64
|
+
promises.length = 0;
|
|
65
|
+
await Promise.all(promisesToWait);
|
|
66
|
+
await waitAll();
|
|
67
|
+
};
|
|
68
|
+
await waitAll();
|
|
69
|
+
promiseMap.clear();
|
|
70
|
+
};
|
|
71
71
|
|
|
72
72
|
return {
|
|
73
73
|
load,
|
|
74
74
|
loadReferencedUrlInfos,
|
|
75
75
|
getAllLoadDonePromise,
|
|
76
|
-
}
|
|
77
|
-
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ANSI, byteAsFileSize, distributePercentages } from "@jsenv/log"
|
|
1
|
+
import { ANSI, byteAsFileSize, distributePercentages } from "@jsenv/log";
|
|
2
2
|
|
|
3
3
|
export const createUrlGraphSummary = (
|
|
4
4
|
urlGraph,
|
|
5
5
|
{ title = "graph summary" } = {},
|
|
6
6
|
) => {
|
|
7
|
-
const graphReport = createUrlGraphReport(urlGraph)
|
|
7
|
+
const graphReport = createUrlGraphReport(urlGraph);
|
|
8
8
|
return `--- ${title} ---
|
|
9
9
|
${createRepartitionMessage(graphReport)}
|
|
10
|
-
|
|
11
|
-
}
|
|
10
|
+
--------------------`;
|
|
11
|
+
};
|
|
12
12
|
|
|
13
13
|
const createUrlGraphReport = (urlGraph) => {
|
|
14
14
|
const countGroups = {
|
|
@@ -19,7 +19,7 @@ const createUrlGraphReport = (urlGraph) => {
|
|
|
19
19
|
json: 0,
|
|
20
20
|
other: 0,
|
|
21
21
|
total: 0,
|
|
22
|
-
}
|
|
22
|
+
};
|
|
23
23
|
const sizeGroups = {
|
|
24
24
|
sourcemaps: 0,
|
|
25
25
|
html: 0,
|
|
@@ -28,70 +28,70 @@ const createUrlGraphReport = (urlGraph) => {
|
|
|
28
28
|
json: 0,
|
|
29
29
|
other: 0,
|
|
30
30
|
total: 0,
|
|
31
|
-
}
|
|
31
|
+
};
|
|
32
32
|
urlGraph.urlInfoMap.forEach((urlInfo) => {
|
|
33
33
|
if (urlInfo.url.startsWith("data:")) {
|
|
34
|
-
return
|
|
34
|
+
return;
|
|
35
35
|
}
|
|
36
36
|
// ignore:
|
|
37
37
|
// - inline files: they are already taken into account in the file where they appear
|
|
38
38
|
// - ignored files: we don't know their content
|
|
39
39
|
if (urlInfo.isInline || !urlInfo.shouldHandle) {
|
|
40
|
-
return
|
|
40
|
+
return;
|
|
41
41
|
}
|
|
42
42
|
// file loaded via import assertion are already inside the graph
|
|
43
43
|
// their js module equivalent are ignored to avoid counting it twice
|
|
44
44
|
// in the build graph the file targeted by import assertion will likely be gone
|
|
45
45
|
// and only the js module remain (likely bundled)
|
|
46
|
-
const urlObject = new URL(urlInfo.url)
|
|
46
|
+
const urlObject = new URL(urlInfo.url);
|
|
47
47
|
if (
|
|
48
48
|
urlObject.searchParams.has("as_json_module") ||
|
|
49
49
|
urlObject.searchParams.has("as_css_module") ||
|
|
50
50
|
urlObject.searchParams.has("as_text_module")
|
|
51
51
|
) {
|
|
52
|
-
return
|
|
52
|
+
return;
|
|
53
53
|
}
|
|
54
|
-
const urlContentSize = Buffer.byteLength(urlInfo.content)
|
|
55
|
-
const category = determineCategory(urlInfo)
|
|
54
|
+
const urlContentSize = Buffer.byteLength(urlInfo.content);
|
|
55
|
+
const category = determineCategory(urlInfo);
|
|
56
56
|
if (category === "sourcemap") {
|
|
57
|
-
countGroups.sourcemaps
|
|
58
|
-
sizeGroups.sourcemaps += urlContentSize
|
|
59
|
-
return
|
|
57
|
+
countGroups.sourcemaps++;
|
|
58
|
+
sizeGroups.sourcemaps += urlContentSize;
|
|
59
|
+
return;
|
|
60
60
|
}
|
|
61
|
-
countGroups.total
|
|
62
|
-
sizeGroups.total += urlContentSize
|
|
61
|
+
countGroups.total++;
|
|
62
|
+
sizeGroups.total += urlContentSize;
|
|
63
63
|
if (category === "html") {
|
|
64
|
-
countGroups.html
|
|
65
|
-
sizeGroups.html += urlContentSize
|
|
66
|
-
return
|
|
64
|
+
countGroups.html++;
|
|
65
|
+
sizeGroups.html += urlContentSize;
|
|
66
|
+
return;
|
|
67
67
|
}
|
|
68
68
|
if (category === "css") {
|
|
69
|
-
countGroups.css
|
|
70
|
-
sizeGroups.css += urlContentSize
|
|
71
|
-
return
|
|
69
|
+
countGroups.css++;
|
|
70
|
+
sizeGroups.css += urlContentSize;
|
|
71
|
+
return;
|
|
72
72
|
}
|
|
73
73
|
if (category === "js") {
|
|
74
|
-
countGroups.js
|
|
75
|
-
sizeGroups.js += urlContentSize
|
|
76
|
-
return
|
|
74
|
+
countGroups.js++;
|
|
75
|
+
sizeGroups.js += urlContentSize;
|
|
76
|
+
return;
|
|
77
77
|
}
|
|
78
78
|
if (category === "json") {
|
|
79
|
-
countGroups.json
|
|
80
|
-
sizeGroups.json += urlContentSize
|
|
81
|
-
return
|
|
79
|
+
countGroups.json++;
|
|
80
|
+
sizeGroups.json += urlContentSize;
|
|
81
|
+
return;
|
|
82
82
|
}
|
|
83
|
-
countGroups.other
|
|
84
|
-
sizeGroups.other += urlContentSize
|
|
85
|
-
return
|
|
86
|
-
})
|
|
83
|
+
countGroups.other++;
|
|
84
|
+
sizeGroups.other += urlContentSize;
|
|
85
|
+
return;
|
|
86
|
+
});
|
|
87
87
|
|
|
88
|
-
const sizesToDistribute = {}
|
|
88
|
+
const sizesToDistribute = {};
|
|
89
89
|
Object.keys(sizeGroups).forEach((groupName) => {
|
|
90
90
|
if (groupName !== "sourcemaps" && groupName !== "total") {
|
|
91
|
-
sizesToDistribute[groupName] = sizeGroups[groupName]
|
|
91
|
+
sizesToDistribute[groupName] = sizeGroups[groupName];
|
|
92
92
|
}
|
|
93
|
-
})
|
|
94
|
-
const percentageGroups = distributePercentages(sizesToDistribute)
|
|
93
|
+
});
|
|
94
|
+
const percentageGroups = distributePercentages(sizesToDistribute);
|
|
95
95
|
|
|
96
96
|
return {
|
|
97
97
|
// sourcemaps are special, there size are ignored
|
|
@@ -132,27 +132,27 @@ const createUrlGraphReport = (urlGraph) => {
|
|
|
132
132
|
size: sizeGroups.total,
|
|
133
133
|
percentage: 100,
|
|
134
134
|
},
|
|
135
|
-
}
|
|
136
|
-
}
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
137
|
|
|
138
138
|
const determineCategory = (urlInfo) => {
|
|
139
139
|
if (urlInfo.type === "sourcemap") {
|
|
140
|
-
return "sourcemap"
|
|
140
|
+
return "sourcemap";
|
|
141
141
|
}
|
|
142
142
|
if (urlInfo.type === "html") {
|
|
143
|
-
return "html"
|
|
143
|
+
return "html";
|
|
144
144
|
}
|
|
145
145
|
if (urlInfo.type === "css") {
|
|
146
|
-
return "css"
|
|
146
|
+
return "css";
|
|
147
147
|
}
|
|
148
148
|
if (urlInfo.type === "js_module" || urlInfo.type === "js_classic") {
|
|
149
|
-
return "js"
|
|
149
|
+
return "js";
|
|
150
150
|
}
|
|
151
151
|
if (urlInfo.type === "json") {
|
|
152
|
-
return "json"
|
|
152
|
+
return "json";
|
|
153
153
|
}
|
|
154
|
-
return "other"
|
|
155
|
-
}
|
|
154
|
+
return "other";
|
|
155
|
+
};
|
|
156
156
|
|
|
157
157
|
const createRepartitionMessage = ({ html, css, js, json, other, total }) => {
|
|
158
158
|
const addPart = (name, { count, size, percentage }) => {
|
|
@@ -160,10 +160,10 @@ const createRepartitionMessage = ({ html, css, js, json, other, total }) => {
|
|
|
160
160
|
`${ANSI.color(`${name}:`, ANSI.GREY)} ${count} (${byteAsFileSize(
|
|
161
161
|
size,
|
|
162
162
|
)} / ${percentage} %)`,
|
|
163
|
-
)
|
|
164
|
-
}
|
|
163
|
+
);
|
|
164
|
+
};
|
|
165
165
|
|
|
166
|
-
const parts = []
|
|
166
|
+
const parts = [];
|
|
167
167
|
// if (sourcemaps.count) {
|
|
168
168
|
// parts.push(
|
|
169
169
|
// `${ANSI.color(`sourcemaps:`, ANSI.GREY)} ${
|
|
@@ -172,21 +172,21 @@ const createRepartitionMessage = ({ html, css, js, json, other, total }) => {
|
|
|
172
172
|
// )
|
|
173
173
|
// }
|
|
174
174
|
if (html.count) {
|
|
175
|
-
addPart("html ", html)
|
|
175
|
+
addPart("html ", html);
|
|
176
176
|
}
|
|
177
177
|
if (css.count) {
|
|
178
|
-
addPart("css ", css)
|
|
178
|
+
addPart("css ", css);
|
|
179
179
|
}
|
|
180
180
|
if (js.count) {
|
|
181
|
-
addPart("js ", js)
|
|
181
|
+
addPart("js ", js);
|
|
182
182
|
}
|
|
183
183
|
if (json.count) {
|
|
184
|
-
addPart("json ", json)
|
|
184
|
+
addPart("json ", json);
|
|
185
185
|
}
|
|
186
186
|
if (other.count) {
|
|
187
|
-
addPart("other", other)
|
|
187
|
+
addPart("other", other);
|
|
188
188
|
}
|
|
189
|
-
addPart("total", total)
|
|
189
|
+
addPart("total", total);
|
|
190
190
|
return `- ${parts.join(`
|
|
191
|
-
- `)}
|
|
192
|
-
}
|
|
191
|
+
- `)}`;
|
|
192
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { pathToFileURL } from "node:url"
|
|
2
|
-
import { bufferToEtag } from "@jsenv/filesystem"
|
|
3
|
-
import { urlToRelativeUrl, isFileSystemPath } from "@jsenv/urls"
|
|
1
|
+
import { pathToFileURL } from "node:url";
|
|
2
|
+
import { bufferToEtag } from "@jsenv/filesystem";
|
|
3
|
+
import { urlToRelativeUrl, isFileSystemPath } from "@jsenv/urls";
|
|
4
4
|
import {
|
|
5
5
|
composeTwoSourcemaps,
|
|
6
6
|
SOURCEMAP,
|
|
7
7
|
generateSourcemapFileUrl,
|
|
8
8
|
generateSourcemapDataUrl,
|
|
9
|
-
} from "@jsenv/sourcemap"
|
|
9
|
+
} from "@jsenv/sourcemap";
|
|
10
10
|
|
|
11
11
|
export const createUrlInfoTransformer = ({
|
|
12
12
|
logger,
|
|
@@ -19,26 +19,26 @@ export const createUrlInfoTransformer = ({
|
|
|
19
19
|
foundSourcemap,
|
|
20
20
|
}) => {
|
|
21
21
|
if (sourcemapsSourcesProtocol === undefined) {
|
|
22
|
-
sourcemapsSourcesProtocol = "file:///"
|
|
22
|
+
sourcemapsSourcesProtocol = "file:///";
|
|
23
23
|
}
|
|
24
24
|
if (sourcemapsSourcesContent === undefined) {
|
|
25
|
-
sourcemapsSourcesContent = true
|
|
25
|
+
sourcemapsSourcesContent = true;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const sourcemapsEnabled =
|
|
29
29
|
sourcemaps === "inline" ||
|
|
30
30
|
sourcemaps === "file" ||
|
|
31
|
-
sourcemaps === "programmatic"
|
|
31
|
+
sourcemaps === "programmatic";
|
|
32
32
|
|
|
33
33
|
const normalizeSourcemap = (urlInfo, sourcemap) => {
|
|
34
|
-
let { sources } = sourcemap
|
|
34
|
+
let { sources } = sourcemap;
|
|
35
35
|
if (sources) {
|
|
36
36
|
sources = sources.map((source) => {
|
|
37
37
|
if (source && isFileSystemPath(source)) {
|
|
38
|
-
return String(pathToFileURL(source))
|
|
38
|
+
return String(pathToFileURL(source));
|
|
39
39
|
}
|
|
40
|
-
return source
|
|
41
|
-
})
|
|
40
|
+
return source;
|
|
41
|
+
});
|
|
42
42
|
}
|
|
43
43
|
const wantSourcesContent =
|
|
44
44
|
// for inline content (<script> insdide html)
|
|
@@ -47,36 +47,36 @@ export const createUrlInfoTransformer = ({
|
|
|
47
47
|
sourcemapsSourcesContent ||
|
|
48
48
|
urlInfo.isInline ||
|
|
49
49
|
(sources &&
|
|
50
|
-
sources.some((source) => !source || !source.startsWith("file:")))
|
|
50
|
+
sources.some((source) => !source || !source.startsWith("file:")));
|
|
51
51
|
if (sources && sources.length > 1) {
|
|
52
52
|
sourcemap.sources = sources.map(
|
|
53
53
|
(source) => new URL(source, urlInfo.originalUrl).href,
|
|
54
|
-
)
|
|
54
|
+
);
|
|
55
55
|
if (!wantSourcesContent) {
|
|
56
|
-
sourcemap.sourcesContent = undefined
|
|
56
|
+
sourcemap.sourcesContent = undefined;
|
|
57
57
|
}
|
|
58
|
-
return sourcemap
|
|
58
|
+
return sourcemap;
|
|
59
59
|
}
|
|
60
|
-
sourcemap.sources = [urlInfo.originalUrl]
|
|
61
|
-
sourcemap.sourcesContent = [urlInfo.originalContent]
|
|
60
|
+
sourcemap.sources = [urlInfo.originalUrl];
|
|
61
|
+
sourcemap.sourcesContent = [urlInfo.originalContent];
|
|
62
62
|
if (!wantSourcesContent) {
|
|
63
|
-
sourcemap.sourcesContent = undefined
|
|
63
|
+
sourcemap.sourcesContent = undefined;
|
|
64
64
|
}
|
|
65
|
-
return sourcemap
|
|
66
|
-
}
|
|
65
|
+
return sourcemap;
|
|
66
|
+
};
|
|
67
67
|
|
|
68
68
|
const initTransformations = async (urlInfo, context) => {
|
|
69
69
|
urlInfo.originalContentEtag =
|
|
70
70
|
urlInfo.originalContentEtag ||
|
|
71
|
-
bufferToEtag(Buffer.from(urlInfo.originalContent))
|
|
71
|
+
bufferToEtag(Buffer.from(urlInfo.originalContent));
|
|
72
72
|
if (!sourcemapsEnabled) {
|
|
73
|
-
return
|
|
73
|
+
return;
|
|
74
74
|
}
|
|
75
75
|
if (!SOURCEMAP.enabledOnContentType(urlInfo.contentType)) {
|
|
76
|
-
return
|
|
76
|
+
return;
|
|
77
77
|
}
|
|
78
78
|
if (urlInfo.generatedUrl.startsWith("data:")) {
|
|
79
|
-
return
|
|
79
|
+
return;
|
|
80
80
|
}
|
|
81
81
|
// sourcemap is a special kind of reference:
|
|
82
82
|
// It's a reference to a content generated dynamically the content itself.
|
|
@@ -86,12 +86,12 @@ export const createUrlInfoTransformer = ({
|
|
|
86
86
|
// when jsenv is done cooking the file
|
|
87
87
|
// during build it's urlInfo.url to be inside the build
|
|
88
88
|
// but otherwise it's generatedUrl to be inside .jsenv/ directory
|
|
89
|
-
const generatedUrlObject = new URL(urlInfo.generatedUrl)
|
|
90
|
-
generatedUrlObject.searchParams.delete("js_module_fallback")
|
|
91
|
-
generatedUrlObject.searchParams.delete("as_js_module")
|
|
92
|
-
generatedUrlObject.searchParams.delete("as_js_classic")
|
|
93
|
-
const urlForSourcemap = generatedUrlObject.href
|
|
94
|
-
urlInfo.sourcemapGeneratedUrl = generateSourcemapFileUrl(urlForSourcemap)
|
|
89
|
+
const generatedUrlObject = new URL(urlInfo.generatedUrl);
|
|
90
|
+
generatedUrlObject.searchParams.delete("js_module_fallback");
|
|
91
|
+
generatedUrlObject.searchParams.delete("as_js_module");
|
|
92
|
+
generatedUrlObject.searchParams.delete("as_js_classic");
|
|
93
|
+
const urlForSourcemap = generatedUrlObject.href;
|
|
94
|
+
urlInfo.sourcemapGeneratedUrl = generateSourcemapFileUrl(urlForSourcemap);
|
|
95
95
|
|
|
96
96
|
// already loaded during "load" hook (happens during build)
|
|
97
97
|
if (urlInfo.sourcemap) {
|
|
@@ -100,71 +100,71 @@ export const createUrlInfoTransformer = ({
|
|
|
100
100
|
urlInfo,
|
|
101
101
|
specifier: urlInfo.sourcemapGeneratedUrl,
|
|
102
102
|
},
|
|
103
|
-
)
|
|
104
|
-
sourcemapUrlInfo.isInline = sourcemaps === "inline"
|
|
105
|
-
urlInfo.sourcemapReference = sourcemapReference
|
|
106
|
-
urlInfo.sourcemap = normalizeSourcemap(urlInfo, urlInfo.sourcemap)
|
|
107
|
-
return
|
|
103
|
+
);
|
|
104
|
+
sourcemapUrlInfo.isInline = sourcemaps === "inline";
|
|
105
|
+
urlInfo.sourcemapReference = sourcemapReference;
|
|
106
|
+
urlInfo.sourcemap = normalizeSourcemap(urlInfo, urlInfo.sourcemap);
|
|
107
|
+
return;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
// check for existing sourcemap for this content
|
|
111
111
|
const sourcemapFound = SOURCEMAP.readComment({
|
|
112
112
|
contentType: urlInfo.contentType,
|
|
113
113
|
content: urlInfo.content,
|
|
114
|
-
})
|
|
114
|
+
});
|
|
115
115
|
if (sourcemapFound) {
|
|
116
|
-
const { type, line, column, specifier } = sourcemapFound
|
|
116
|
+
const { type, line, column, specifier } = sourcemapFound;
|
|
117
117
|
const [sourcemapReference, sourcemapUrlInfo] = foundSourcemap({
|
|
118
118
|
urlInfo,
|
|
119
119
|
type,
|
|
120
120
|
specifier,
|
|
121
121
|
specifierLine: line,
|
|
122
122
|
specifierColumn: column,
|
|
123
|
-
})
|
|
123
|
+
});
|
|
124
124
|
try {
|
|
125
|
-
await context.cook(sourcemapUrlInfo, { reference: sourcemapReference })
|
|
126
|
-
const sourcemapRaw = JSON.parse(sourcemapUrlInfo.content)
|
|
127
|
-
const sourcemap = normalizeSourcemap(urlInfo, sourcemapRaw)
|
|
128
|
-
urlInfo.sourcemap = sourcemap
|
|
125
|
+
await context.cook(sourcemapUrlInfo, { reference: sourcemapReference });
|
|
126
|
+
const sourcemapRaw = JSON.parse(sourcemapUrlInfo.content);
|
|
127
|
+
const sourcemap = normalizeSourcemap(urlInfo, sourcemapRaw);
|
|
128
|
+
urlInfo.sourcemap = sourcemap;
|
|
129
129
|
} catch (e) {
|
|
130
|
-
logger.error(`Error while handling existing sourcemap: ${e.message}`)
|
|
131
|
-
return
|
|
130
|
+
logger.error(`Error while handling existing sourcemap: ${e.message}`);
|
|
131
|
+
return;
|
|
132
132
|
}
|
|
133
133
|
} else {
|
|
134
134
|
const [, sourcemapUrlInfo] = injectSourcemapPlaceholder({
|
|
135
135
|
urlInfo,
|
|
136
136
|
specifier: urlInfo.sourcemapGeneratedUrl,
|
|
137
|
-
})
|
|
138
|
-
sourcemapUrlInfo.isInline = sourcemaps === "inline"
|
|
137
|
+
});
|
|
138
|
+
sourcemapUrlInfo.isInline = sourcemaps === "inline";
|
|
139
139
|
}
|
|
140
|
-
}
|
|
140
|
+
};
|
|
141
141
|
|
|
142
142
|
const applyIntermediateTransformations = (urlInfo, transformations) => {
|
|
143
143
|
if (!transformations) {
|
|
144
|
-
return
|
|
144
|
+
return;
|
|
145
145
|
}
|
|
146
146
|
const { type, contentType, content, sourcemap, sourcemapIsWrong } =
|
|
147
|
-
transformations
|
|
147
|
+
transformations;
|
|
148
148
|
if (type) {
|
|
149
|
-
urlInfo.type = type
|
|
149
|
+
urlInfo.type = type;
|
|
150
150
|
}
|
|
151
151
|
if (contentType) {
|
|
152
|
-
urlInfo.contentType = contentType
|
|
152
|
+
urlInfo.contentType = contentType;
|
|
153
153
|
}
|
|
154
154
|
if (content) {
|
|
155
|
-
urlInfo.content = content
|
|
155
|
+
urlInfo.content = content;
|
|
156
156
|
}
|
|
157
157
|
if (sourcemapsEnabled && sourcemap) {
|
|
158
|
-
const sourcemapNormalized = normalizeSourcemap(urlInfo, sourcemap)
|
|
158
|
+
const sourcemapNormalized = normalizeSourcemap(urlInfo, sourcemap);
|
|
159
159
|
const finalSourcemap = composeTwoSourcemaps(
|
|
160
160
|
urlInfo.sourcemap,
|
|
161
161
|
sourcemapNormalized,
|
|
162
|
-
)
|
|
162
|
+
);
|
|
163
163
|
const finalSourcemapNormalized = normalizeSourcemap(
|
|
164
164
|
urlInfo,
|
|
165
165
|
finalSourcemap,
|
|
166
|
-
)
|
|
167
|
-
urlInfo.sourcemap = finalSourcemapNormalized
|
|
166
|
+
);
|
|
167
|
+
urlInfo.sourcemap = finalSourcemapNormalized;
|
|
168
168
|
// A plugin is allowed to modify url content
|
|
169
169
|
// without returning a sourcemap
|
|
170
170
|
// This is the case for preact and react plugins.
|
|
@@ -174,13 +174,13 @@ export const createUrlInfoTransformer = ({
|
|
|
174
174
|
// is a nightmare no-one could solve in years so
|
|
175
175
|
// jsenv won't emit a warning and use the following strategy:
|
|
176
176
|
// "no sourcemap is better than wrong sourcemap"
|
|
177
|
-
urlInfo.sourcemapIsWrong = urlInfo.sourcemapIsWrong || sourcemapIsWrong
|
|
177
|
+
urlInfo.sourcemapIsWrong = urlInfo.sourcemapIsWrong || sourcemapIsWrong;
|
|
178
178
|
}
|
|
179
|
-
}
|
|
179
|
+
};
|
|
180
180
|
|
|
181
181
|
const applyFinalTransformations = (urlInfo, transformations) => {
|
|
182
182
|
if (transformations) {
|
|
183
|
-
applyIntermediateTransformations(urlInfo, transformations)
|
|
183
|
+
applyIntermediateTransformations(urlInfo, transformations);
|
|
184
184
|
}
|
|
185
185
|
if (urlInfo.sourcemapReference) {
|
|
186
186
|
if (
|
|
@@ -193,31 +193,31 @@ export const createUrlInfoTransformer = ({
|
|
|
193
193
|
// - to inject versioning into the entry point content
|
|
194
194
|
// in this scenarion we don't want to call injectSourcemap
|
|
195
195
|
// just update the content and the
|
|
196
|
-
const sourcemapReference = urlInfo.sourcemapReference
|
|
197
|
-
const sourcemapUrlInfo = urlGraph.getUrlInfo(sourcemapReference.url)
|
|
198
|
-
sourcemapUrlInfo.contentType = "application/json"
|
|
199
|
-
const sourcemap = urlInfo.sourcemap
|
|
196
|
+
const sourcemapReference = urlInfo.sourcemapReference;
|
|
197
|
+
const sourcemapUrlInfo = urlGraph.getUrlInfo(sourcemapReference.url);
|
|
198
|
+
sourcemapUrlInfo.contentType = "application/json";
|
|
199
|
+
const sourcemap = urlInfo.sourcemap;
|
|
200
200
|
if (sourcemapsSourcesRelative) {
|
|
201
201
|
sourcemap.sources = sourcemap.sources.map((source) => {
|
|
202
|
-
const sourceRelative = urlToRelativeUrl(source, urlInfo.url)
|
|
203
|
-
return sourceRelative || "."
|
|
204
|
-
})
|
|
202
|
+
const sourceRelative = urlToRelativeUrl(source, urlInfo.url);
|
|
203
|
+
return sourceRelative || ".";
|
|
204
|
+
});
|
|
205
205
|
}
|
|
206
206
|
if (sourcemapsSourcesProtocol !== "file:///") {
|
|
207
207
|
sourcemap.sources = sourcemap.sources.map((source) => {
|
|
208
208
|
if (source.startsWith("file:///")) {
|
|
209
209
|
return `${sourcemapsSourcesProtocol}${source.slice(
|
|
210
210
|
"file:///".length,
|
|
211
|
-
)}
|
|
211
|
+
)}`;
|
|
212
212
|
}
|
|
213
|
-
return source
|
|
214
|
-
})
|
|
213
|
+
return source;
|
|
214
|
+
});
|
|
215
215
|
}
|
|
216
|
-
sourcemapUrlInfo.content = JSON.stringify(sourcemap, null, " ")
|
|
216
|
+
sourcemapUrlInfo.content = JSON.stringify(sourcemap, null, " ");
|
|
217
217
|
if (!urlInfo.sourcemapIsWrong) {
|
|
218
218
|
if (sourcemaps === "inline") {
|
|
219
219
|
sourcemapReference.generatedSpecifier =
|
|
220
|
-
generateSourcemapDataUrl(sourcemap)
|
|
220
|
+
generateSourcemapDataUrl(sourcemap);
|
|
221
221
|
}
|
|
222
222
|
if (sourcemaps === "file" || sourcemaps === "inline") {
|
|
223
223
|
urlInfo.content = SOURCEMAP.writeComment({
|
|
@@ -227,24 +227,24 @@ export const createUrlInfoTransformer = ({
|
|
|
227
227
|
sourcemaps === "file" && sourcemapsSourcesRelative
|
|
228
228
|
? urlToRelativeUrl(sourcemapReference.url, urlInfo.url)
|
|
229
229
|
: sourcemapReference.generatedSpecifier,
|
|
230
|
-
})
|
|
230
|
+
});
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
} else {
|
|
234
234
|
// in the end we don't use the sourcemap placeholder
|
|
235
|
-
urlGraph.deleteUrlInfo(urlInfo.sourcemapReference.url)
|
|
235
|
+
urlGraph.deleteUrlInfo(urlInfo.sourcemapReference.url);
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
urlInfo.contentEtag =
|
|
240
240
|
urlInfo.content === urlInfo.originalContent
|
|
241
241
|
? urlInfo.originalContentEtag
|
|
242
|
-
: bufferToEtag(Buffer.from(urlInfo.content))
|
|
243
|
-
}
|
|
242
|
+
: bufferToEtag(Buffer.from(urlInfo.content));
|
|
243
|
+
};
|
|
244
244
|
|
|
245
245
|
return {
|
|
246
246
|
initTransformations,
|
|
247
247
|
applyIntermediateTransformations,
|
|
248
248
|
applyFinalTransformations,
|
|
249
|
-
}
|
|
250
|
-
}
|
|
249
|
+
};
|
|
250
|
+
};
|