@jsenv/core 35.0.3 → 35.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/html/explorer.html +107 -107
- package/dist/js/new_stylesheet.js +3 -0
- package/dist/js/s.js.map +3 -3
- package/package.json +2 -2
- package/src/build/build.js +589 -587
- package/src/build/build_urls_generator.js +44 -44
- package/src/build/graph_utils.js +14 -14
- package/src/build/jsenv_plugin_line_break_normalization.js +6 -6
- package/src/build/line_break_unix.js +11 -11
- package/src/build/start_build_server.js +37 -37
- package/src/build/version_generator.js +7 -7
- package/src/build/version_mappings_injection.js +23 -23
- package/src/dev/file_service.js +132 -132
- package/src/dev/start_dev_server.js +56 -56
- package/src/dev/user_agent.js +8 -8
- package/src/helpers/basic_fetch.js +24 -24
- package/src/helpers/command/command.js +28 -28
- package/src/helpers/lookup_package_directory.js +19 -16
- package/src/helpers/ping_server.js +17 -17
- package/src/helpers/require_from_jsenv.js +2 -2
- package/src/helpers/watch_source_files.js +9 -9
- package/src/helpers/web_url_converter.js +10 -10
- package/src/helpers/worker_reload.js +27 -27
- package/src/kitchen/compat/features_compatibility.js +1 -1
- package/src/kitchen/compat/runtime_compat.js +26 -24
- package/src/kitchen/errors.js +75 -75
- package/src/kitchen/fetched_content_compliance.js +8 -8
- package/src/kitchen/kitchen.js +251 -250
- package/src/kitchen/url_graph/sort_by_dependencies.js +17 -17
- package/src/kitchen/url_graph/url_graph_loader.js +30 -30
- package/src/kitchen/url_graph/url_graph_report.js +57 -57
- package/src/kitchen/url_graph/url_info_transformations.js +77 -77
- package/src/kitchen/url_graph.js +121 -121
- package/src/kitchen/url_specifier_encoding.js +21 -21
- package/src/kitchen/web_workers.js +5 -5
- package/src/main.js +3 -3
- package/src/plugins/autoreload/client/autoreload.js +96 -96
- package/src/plugins/autoreload/client/reload.js +56 -56
- package/src/plugins/autoreload/client/url_helpers.js +13 -13
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +5 -5
- package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +9 -9
- package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +61 -60
- package/src/plugins/autoreload/jsenv_plugin_hmr.js +15 -15
- package/src/plugins/cache_control/jsenv_plugin_cache_control.js +5 -5
- package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +57 -57
- package/src/plugins/explorer/client/explorer.html +107 -107
- package/src/plugins/explorer/jsenv_plugin_explorer.js +20 -20
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +60 -60
- package/src/plugins/global_scenarios/jsenv_plugin_global_scenarios.js +5 -5
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +3 -3
- package/src/plugins/import_meta_hot/babel_plugin_metadata_import_meta_hot.js +35 -35
- package/src/plugins/import_meta_hot/client/import_meta_hot.js +26 -26
- package/src/plugins/import_meta_hot/html_hot_dependencies.js +43 -43
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +44 -40
- package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +35 -35
- package/src/plugins/import_meta_url/client/import_meta_url_browser.js +21 -21
- package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +3 -3
- package/src/plugins/importmap/jsenv_plugin_importmap.js +54 -54
- package/src/plugins/inline_content_analysis/client/inline_content.js +3 -3
- package/src/plugins/inline_content_analysis/jsenv_plugin_data_urls.js +26 -26
- package/src/plugins/inline_content_analysis/jsenv_plugin_html_inline_content_analysis.js +47 -47
- package/src/plugins/inline_content_analysis/jsenv_plugin_inline_content_analysis.js +9 -9
- package/src/plugins/inline_content_analysis/jsenv_plugin_js_inline_content_analysis.js +101 -101
- package/src/plugins/inlining/jsenv_plugin_inlining.js +9 -9
- package/src/plugins/inlining/jsenv_plugin_inlining_as_data_url.js +11 -11
- package/src/plugins/inlining/jsenv_plugin_inlining_into_html.js +48 -46
- package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +4 -4
- package/src/plugins/plugin_controller.js +124 -124
- package/src/plugins/plugins.js +27 -27
- package/src/plugins/ribbon/client/ribbon.js +6 -6
- package/src/plugins/ribbon/jsenv_plugin_ribbon.js +15 -15
- package/src/plugins/server_events/client/connection_manager.js +52 -52
- package/src/plugins/server_events/client/event_source_connection.js +36 -36
- package/src/plugins/server_events/client/events_manager.js +37 -37
- package/src/plugins/server_events/client/server_events_client.js +7 -7
- package/src/plugins/server_events/client/web_socket_connection.js +39 -39
- package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +9 -9
- package/src/plugins/server_events/server_events_dispatcher.js +43 -43
- package/src/plugins/supervisor/client/supervisor.js +455 -450
- package/src/plugins/supervisor/html_supervisor_injection.js +64 -62
- package/src/plugins/supervisor/js_supervisor_injection.js +67 -67
- package/src/plugins/supervisor/jsenv_plugin_supervisor.js +54 -51
- package/src/plugins/transpilation/as_js_module/convert_js_classic_to_js_module.js +13 -13
- package/src/plugins/transpilation/as_js_module/jsenv_plugin_as_js_module.js +19 -19
- package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +10 -10
- package/src/plugins/transpilation/babel/global_this/client/global_this.js +8 -8
- package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +16 -16
- package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +36 -36
- package/src/plugins/transpilation/babel/helpers/babel_plugins_compatibility.js +3 -3
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +24 -24
- package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +44 -44
- package/src/plugins/transpilation/babel/new_stylesheet/client/new_stylesheet.js +166 -166
- package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +10 -10
- package/src/plugins/transpilation/babel/require_babel_plugin.js +6 -6
- package/src/plugins/transpilation/css/jsenv_plugin_css_transpilation.js +20 -20
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +62 -62
- package/src/plugins/transpilation/js_module_fallback/client/s.js +214 -209
- package/src/plugins/transpilation/js_module_fallback/convert_js_module_to_js_classic.js +45 -45
- package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_resolve.js +6 -6
- package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_url.js +17 -17
- package/src/plugins/transpilation/js_module_fallback/helpers-string.js +1 -1
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_conversion.js +32 -32
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js +17 -17
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +63 -63
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +15 -15
- package/src/plugins/transpilation/jsenv_plugin_import_meta_resolve.js +20 -20
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +23 -23
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +11 -11
- package/src/plugins/url_analysis/css/css_urls.js +12 -12
- package/src/plugins/url_analysis/html/html_urls.js +85 -85
- package/src/plugins/url_analysis/js/js_urls.js +16 -16
- package/src/plugins/url_analysis/jsenv_plugin_reference_expected_types.js +16 -16
- package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +40 -40
- package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +12 -12
- package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +35 -35
- package/src/plugins/url_resolution/node_esm_resolver.js +26 -26
- package/src/plugins/url_version/jsenv_plugin_url_version.js +11 -11
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
* A global will be injected with true/false when needed
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { replacePlaceholders } from "@jsenv/plugin-placeholders"
|
|
8
|
+
import { replacePlaceholders } from "@jsenv/plugin-placeholders";
|
|
9
9
|
|
|
10
10
|
export const jsenvPluginGlobalScenarios = () => {
|
|
11
11
|
const transformIfNeeded = (urlInfo, context) => {
|
|
12
12
|
return replacePlaceholders(urlInfo, {
|
|
13
13
|
__DEV__: context.dev,
|
|
14
14
|
__BUILD__: context.build,
|
|
15
|
-
})
|
|
16
|
-
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
17
|
|
|
18
18
|
return {
|
|
19
19
|
name: "jsenv:global_scenario",
|
|
@@ -23,5 +23,5 @@ export const jsenvPluginGlobalScenarios = () => {
|
|
|
23
23
|
js_module: transformIfNeeded,
|
|
24
24
|
html: transformIfNeeded,
|
|
25
25
|
},
|
|
26
|
-
}
|
|
27
|
-
}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -7,10 +7,10 @@ export const jsenvPluginHttpUrls = () => {
|
|
|
7
7
|
reference.url.startsWith("http:") ||
|
|
8
8
|
reference.url.startsWith("https:")
|
|
9
9
|
) {
|
|
10
|
-
reference.shouldHandle = false
|
|
10
|
+
reference.shouldHandle = false;
|
|
11
11
|
}
|
|
12
12
|
// TODO: according to some pattern matching jsenv could be allowed
|
|
13
13
|
// to fetch and transform http urls
|
|
14
14
|
},
|
|
15
|
-
}
|
|
16
|
-
}
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -10,82 +10,82 @@ export const babelPluginMetadataImportMetaHot = () => {
|
|
|
10
10
|
Object.assign(
|
|
11
11
|
state.file.metadata,
|
|
12
12
|
collectImportMetaProperties(programPath),
|
|
13
|
-
)
|
|
13
|
+
);
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
|
-
}
|
|
17
|
-
}
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
18
|
const collectImportMetaProperties = (programPath) => {
|
|
19
|
-
const importMetaHotPaths = []
|
|
20
|
-
let hotDecline = false
|
|
21
|
-
let hotAcceptSelf = false
|
|
22
|
-
let hotAcceptDependencies = []
|
|
19
|
+
const importMetaHotPaths = [];
|
|
20
|
+
let hotDecline = false;
|
|
21
|
+
let hotAcceptSelf = false;
|
|
22
|
+
let hotAcceptDependencies = [];
|
|
23
23
|
programPath.traverse({
|
|
24
24
|
MemberExpression(path) {
|
|
25
|
-
const { node } = path
|
|
26
|
-
const { object } = node
|
|
25
|
+
const { node } = path;
|
|
26
|
+
const { object } = node;
|
|
27
27
|
if (object.type !== "MetaProperty") {
|
|
28
|
-
return
|
|
28
|
+
return;
|
|
29
29
|
}
|
|
30
|
-
const { property: objectProperty } = object
|
|
30
|
+
const { property: objectProperty } = object;
|
|
31
31
|
if (objectProperty.name !== "meta") {
|
|
32
|
-
return
|
|
32
|
+
return;
|
|
33
33
|
}
|
|
34
|
-
const { property } = node
|
|
35
|
-
const { name } = property
|
|
34
|
+
const { property } = node;
|
|
35
|
+
const { name } = property;
|
|
36
36
|
if (name === "hot") {
|
|
37
|
-
importMetaHotPaths.push(path)
|
|
37
|
+
importMetaHotPaths.push(path);
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
CallExpression(path) {
|
|
41
41
|
if (isImportMetaHotMethodCall(path, "accept")) {
|
|
42
|
-
const callNode = path.node
|
|
43
|
-
const args = callNode.arguments
|
|
42
|
+
const callNode = path.node;
|
|
43
|
+
const args = callNode.arguments;
|
|
44
44
|
if (args.length === 0) {
|
|
45
|
-
hotAcceptSelf = true
|
|
46
|
-
return
|
|
45
|
+
hotAcceptSelf = true;
|
|
46
|
+
return;
|
|
47
47
|
}
|
|
48
|
-
const firstArg = args[0]
|
|
48
|
+
const firstArg = args[0];
|
|
49
49
|
if (firstArg.type === "StringLiteral") {
|
|
50
50
|
hotAcceptDependencies = [
|
|
51
51
|
{
|
|
52
52
|
specifierPath: path.get("arguments")[0],
|
|
53
53
|
},
|
|
54
|
-
]
|
|
55
|
-
return
|
|
54
|
+
];
|
|
55
|
+
return;
|
|
56
56
|
}
|
|
57
57
|
if (firstArg.type === "ArrayExpression") {
|
|
58
|
-
const firstArgPath = path.get("arguments")[0]
|
|
58
|
+
const firstArgPath = path.get("arguments")[0];
|
|
59
59
|
hotAcceptDependencies = firstArg.elements.map((arrayNode, index) => {
|
|
60
60
|
if (arrayNode.type !== "StringLiteral") {
|
|
61
61
|
throw new Error(
|
|
62
62
|
`all array elements must be strings in "import.meta.hot.accept(array)"`,
|
|
63
|
-
)
|
|
63
|
+
);
|
|
64
64
|
}
|
|
65
65
|
return {
|
|
66
66
|
specifierPath: firstArgPath.get(String(index)),
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
return
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
70
|
}
|
|
71
71
|
// accept first arg can be "anything" such as
|
|
72
72
|
// `const cb = () => {}; import.meta.accept(cb)`
|
|
73
|
-
hotAcceptSelf = true
|
|
73
|
+
hotAcceptSelf = true;
|
|
74
74
|
}
|
|
75
75
|
if (isImportMetaHotMethodCall(path, "decline")) {
|
|
76
|
-
hotDecline = true
|
|
76
|
+
hotDecline = true;
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
|
-
})
|
|
79
|
+
});
|
|
80
80
|
return {
|
|
81
81
|
importMetaHotPaths,
|
|
82
82
|
hotDecline,
|
|
83
83
|
hotAcceptSelf,
|
|
84
84
|
hotAcceptDependencies,
|
|
85
|
-
}
|
|
86
|
-
}
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
87
|
const isImportMetaHotMethodCall = (path, methodName) => {
|
|
88
|
-
const { property, object } = path.node.callee
|
|
88
|
+
const { property, object } = path.node.callee;
|
|
89
89
|
return (
|
|
90
90
|
property &&
|
|
91
91
|
property.name === methodName &&
|
|
@@ -93,5 +93,5 @@ const isImportMetaHotMethodCall = (path, methodName) => {
|
|
|
93
93
|
object.property &&
|
|
94
94
|
object.property.name === "hot" &&
|
|
95
95
|
object.object.type === "MetaProperty"
|
|
96
|
-
)
|
|
97
|
-
}
|
|
96
|
+
);
|
|
97
|
+
};
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* https://modern-web.dev/docs/dev-server/plugins/hmr/
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
export const urlHotMetas = {}
|
|
6
|
+
export const urlHotMetas = {};
|
|
7
7
|
|
|
8
8
|
export const createImportMetaHot = (importMetaUrl) => {
|
|
9
|
-
const data = {}
|
|
10
|
-
const url = asUrlWithoutHmrQuery(importMetaUrl)
|
|
9
|
+
const data = {};
|
|
10
|
+
const url = asUrlWithoutHmrQuery(importMetaUrl);
|
|
11
11
|
|
|
12
12
|
return {
|
|
13
13
|
data,
|
|
@@ -16,67 +16,67 @@ export const createImportMetaHot = (importMetaUrl) => {
|
|
|
16
16
|
addUrlMeta(url, {
|
|
17
17
|
dependencies: [url],
|
|
18
18
|
acceptCallback: () => {},
|
|
19
|
-
})
|
|
20
|
-
return
|
|
19
|
+
});
|
|
20
|
+
return;
|
|
21
21
|
}
|
|
22
22
|
if (typeof firstArg === "function") {
|
|
23
23
|
addUrlMeta(url, {
|
|
24
24
|
dependencies: [url],
|
|
25
25
|
acceptCallback: firstArg,
|
|
26
|
-
})
|
|
27
|
-
return
|
|
26
|
+
});
|
|
27
|
+
return;
|
|
28
28
|
}
|
|
29
29
|
if (typeof firstArg === "string") {
|
|
30
30
|
addUrlMeta(url, {
|
|
31
31
|
dependencies: [firstArg],
|
|
32
32
|
acceptCallback: secondArg,
|
|
33
|
-
})
|
|
34
|
-
return
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
35
|
}
|
|
36
36
|
if (Array.isArray(firstArg)) {
|
|
37
37
|
addUrlMeta(url, {
|
|
38
38
|
dependencies: firstArg,
|
|
39
39
|
acceptCallback: secondArg,
|
|
40
|
-
})
|
|
41
|
-
return
|
|
40
|
+
});
|
|
41
|
+
return;
|
|
42
42
|
}
|
|
43
43
|
throw new Error(
|
|
44
44
|
`invalid call to import.meta.hot.accept(), received ${firstArg}`,
|
|
45
|
-
)
|
|
45
|
+
);
|
|
46
46
|
},
|
|
47
47
|
dispose: (callback) => {
|
|
48
48
|
addUrlMeta(url, {
|
|
49
49
|
disposeCallback: () => {
|
|
50
|
-
return callback(data)
|
|
50
|
+
return callback(data);
|
|
51
51
|
},
|
|
52
|
-
})
|
|
52
|
+
});
|
|
53
53
|
},
|
|
54
54
|
decline: () => {
|
|
55
55
|
addUrlMeta(url, {
|
|
56
56
|
declined: true,
|
|
57
|
-
})
|
|
57
|
+
});
|
|
58
58
|
},
|
|
59
59
|
invalidate: () => {
|
|
60
60
|
addUrlMeta(url, {
|
|
61
61
|
invalidated: true,
|
|
62
|
-
})
|
|
62
|
+
});
|
|
63
63
|
},
|
|
64
|
-
}
|
|
65
|
-
}
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
66
|
|
|
67
67
|
const addUrlMeta = (url, meta) => {
|
|
68
68
|
urlHotMetas[url] = {
|
|
69
69
|
...urlHotMetas[url],
|
|
70
70
|
...meta,
|
|
71
|
-
}
|
|
72
|
-
}
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
73
|
|
|
74
74
|
const asUrlWithoutHmrQuery = (url) => {
|
|
75
|
-
const urlObject = new URL(url)
|
|
75
|
+
const urlObject = new URL(url);
|
|
76
76
|
if (urlObject.searchParams.has("hmr")) {
|
|
77
|
-
urlObject.searchParams.delete("hmr")
|
|
78
|
-
urlObject.searchParams.delete("v")
|
|
79
|
-
return urlObject.href
|
|
77
|
+
urlObject.searchParams.delete("hmr");
|
|
78
|
+
urlObject.searchParams.delete("v");
|
|
79
|
+
return urlObject.href;
|
|
80
80
|
}
|
|
81
|
-
return url
|
|
82
|
-
}
|
|
81
|
+
return url;
|
|
82
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getHtmlNodeAttribute, analyzeLinkNode, parseSrcSet } from "@jsenv/ast"
|
|
1
|
+
import { getHtmlNodeAttribute, analyzeLinkNode, parseSrcSet } from "@jsenv/ast";
|
|
2
2
|
|
|
3
3
|
// Some "smart" default applied to decide what should hot reload / fullreload:
|
|
4
4
|
// By default:
|
|
@@ -8,7 +8,7 @@ import { getHtmlNodeAttribute, analyzeLinkNode, parseSrcSet } from "@jsenv/ast"
|
|
|
8
8
|
// - fullreload on <img src="./image.png" hot-decline />
|
|
9
9
|
// - hot reload on <script src="./file.js" hot-accept />
|
|
10
10
|
export const collectHotDataFromHtmlAst = (htmlAst) => {
|
|
11
|
-
const hotReferences = []
|
|
11
|
+
const hotReferences = [];
|
|
12
12
|
|
|
13
13
|
const onSpecifier = ({ specifier, node, attributeName, hotAccepted }) => {
|
|
14
14
|
if (
|
|
@@ -19,115 +19,115 @@ export const collectHotDataFromHtmlAst = (htmlAst) => {
|
|
|
19
19
|
hotReferences.push({
|
|
20
20
|
type: `${node.nodeName}_${attributeName}`,
|
|
21
21
|
specifier,
|
|
22
|
-
})
|
|
22
|
+
});
|
|
23
23
|
}
|
|
24
|
-
}
|
|
24
|
+
};
|
|
25
25
|
|
|
26
26
|
const visitUrlSpecifierAttribute = ({ node, attributeName, hotAccepted }) => {
|
|
27
|
-
const value = getHtmlNodeAttribute(node, attributeName)
|
|
27
|
+
const value = getHtmlNodeAttribute(node, attributeName);
|
|
28
28
|
if (value) {
|
|
29
29
|
onSpecifier({
|
|
30
30
|
specifier: value,
|
|
31
31
|
node,
|
|
32
32
|
attributeName,
|
|
33
33
|
hotAccepted,
|
|
34
|
-
})
|
|
34
|
+
});
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
};
|
|
37
37
|
|
|
38
38
|
const onNode = (node, { hotAccepted }) => {
|
|
39
39
|
// explicitely disabled with [hot-decline] attribute
|
|
40
40
|
if (hotAccepted === false) {
|
|
41
|
-
return
|
|
41
|
+
return;
|
|
42
42
|
}
|
|
43
43
|
if (nodeNamesWithHref.includes(node.nodeName)) {
|
|
44
44
|
visitUrlSpecifierAttribute({
|
|
45
45
|
node,
|
|
46
46
|
attributeName: "href",
|
|
47
47
|
hotAccepted,
|
|
48
|
-
})
|
|
48
|
+
});
|
|
49
49
|
visitUrlSpecifierAttribute({
|
|
50
50
|
node,
|
|
51
51
|
attributeName: "inlined-from-href",
|
|
52
52
|
hotAccepted,
|
|
53
|
-
})
|
|
53
|
+
});
|
|
54
54
|
}
|
|
55
55
|
if (nodeNamesWithSrc.includes(node.nodeName)) {
|
|
56
56
|
visitUrlSpecifierAttribute({
|
|
57
57
|
node,
|
|
58
58
|
attributeName: "src",
|
|
59
59
|
hotAccepted,
|
|
60
|
-
})
|
|
60
|
+
});
|
|
61
61
|
visitUrlSpecifierAttribute({
|
|
62
62
|
node,
|
|
63
63
|
attributeName: "inlined-from-src",
|
|
64
64
|
hotAccepted,
|
|
65
|
-
})
|
|
65
|
+
});
|
|
66
66
|
}
|
|
67
67
|
if (nodeNamesWithSrcset.includes(node.nodeName)) {
|
|
68
|
-
const srcset = getHtmlNodeAttribute(node, "srcset")
|
|
68
|
+
const srcset = getHtmlNodeAttribute(node, "srcset");
|
|
69
69
|
if (srcset) {
|
|
70
|
-
const srcCandidates = parseSrcSet(srcset)
|
|
70
|
+
const srcCandidates = parseSrcSet(srcset);
|
|
71
71
|
srcCandidates.forEach((srcCandidate) => {
|
|
72
72
|
onSpecifier({
|
|
73
73
|
node,
|
|
74
74
|
specifier: srcCandidate.specifier,
|
|
75
75
|
attributeName: "srcset",
|
|
76
76
|
hotAccepted,
|
|
77
|
-
})
|
|
78
|
-
})
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
}
|
|
81
|
+
};
|
|
82
82
|
|
|
83
83
|
const iterate = (node, context) => {
|
|
84
84
|
context = {
|
|
85
85
|
...context,
|
|
86
86
|
...getNodeContext(node),
|
|
87
|
-
}
|
|
88
|
-
onNode(node, context)
|
|
89
|
-
const { childNodes } = node
|
|
87
|
+
};
|
|
88
|
+
onNode(node, context);
|
|
89
|
+
const { childNodes } = node;
|
|
90
90
|
if (childNodes) {
|
|
91
|
-
let i = 0
|
|
91
|
+
let i = 0;
|
|
92
92
|
while (i < childNodes.length) {
|
|
93
|
-
const childNode = childNodes[i++]
|
|
94
|
-
iterate(childNode, context)
|
|
93
|
+
const childNode = childNodes[i++];
|
|
94
|
+
iterate(childNode, context);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
}
|
|
98
|
-
iterate(htmlAst, {})
|
|
97
|
+
};
|
|
98
|
+
iterate(htmlAst, {});
|
|
99
99
|
|
|
100
|
-
return hotReferences
|
|
101
|
-
}
|
|
100
|
+
return hotReferences;
|
|
101
|
+
};
|
|
102
102
|
|
|
103
|
-
const nodeNamesWithHref = ["link", "a", "image", "use"]
|
|
104
|
-
const nodeNamesWithSrc = ["script", "iframe", "img"]
|
|
105
|
-
const nodeNamesWithSrcset = ["img", "source"]
|
|
103
|
+
const nodeNamesWithHref = ["link", "a", "image", "use"];
|
|
104
|
+
const nodeNamesWithSrc = ["script", "iframe", "img"];
|
|
105
|
+
const nodeNamesWithSrcset = ["img", "source"];
|
|
106
106
|
|
|
107
107
|
const getNodeContext = (node) => {
|
|
108
|
-
const context = {}
|
|
109
|
-
const hotAccept = getHtmlNodeAttribute(node, "hot-accept")
|
|
108
|
+
const context = {};
|
|
109
|
+
const hotAccept = getHtmlNodeAttribute(node, "hot-accept");
|
|
110
110
|
if (hotAccept !== undefined) {
|
|
111
|
-
context.hotAccepted = true
|
|
111
|
+
context.hotAccepted = true;
|
|
112
112
|
}
|
|
113
|
-
const hotDecline = getHtmlNodeAttribute(node, "hot-decline")
|
|
113
|
+
const hotDecline = getHtmlNodeAttribute(node, "hot-decline");
|
|
114
114
|
if (hotDecline !== undefined) {
|
|
115
|
-
context.hotAccepted = false
|
|
115
|
+
context.hotAccepted = false;
|
|
116
116
|
}
|
|
117
|
-
return context
|
|
118
|
-
}
|
|
117
|
+
return context;
|
|
118
|
+
};
|
|
119
119
|
|
|
120
120
|
const htmlNodeCanHotReload = (node) => {
|
|
121
121
|
if (node.nodeName === "link") {
|
|
122
|
-
const { isStylesheet, isResourceHint, rel } = analyzeLinkNode(node)
|
|
122
|
+
const { isStylesheet, isResourceHint, rel } = analyzeLinkNode(node);
|
|
123
123
|
if (isStylesheet) {
|
|
124
124
|
// stylesheets can be hot replaced by default
|
|
125
|
-
return true
|
|
125
|
+
return true;
|
|
126
126
|
}
|
|
127
127
|
if (isResourceHint) {
|
|
128
|
-
return false
|
|
128
|
+
return false;
|
|
129
129
|
}
|
|
130
|
-
return rel === "icon"
|
|
130
|
+
return rel === "icon";
|
|
131
131
|
}
|
|
132
132
|
return [
|
|
133
133
|
// "script", // script cannot hot reload
|
|
@@ -144,5 +144,5 @@ const htmlNodeCanHotReload = (node) => {
|
|
|
144
144
|
"source",
|
|
145
145
|
"image",
|
|
146
146
|
"use",
|
|
147
|
-
].includes(node.nodeName)
|
|
148
|
-
}
|
|
147
|
+
].includes(node.nodeName);
|
|
148
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { createMagicSource } from "@jsenv/sourcemap"
|
|
2
|
-
import { parseHtmlString, applyBabelPlugins } from "@jsenv/ast"
|
|
1
|
+
import { createMagicSource } from "@jsenv/sourcemap";
|
|
2
|
+
import { parseHtmlString, applyBabelPlugins } from "@jsenv/ast";
|
|
3
3
|
|
|
4
|
-
import { collectHotDataFromHtmlAst } from "./html_hot_dependencies.js"
|
|
5
|
-
import { babelPluginMetadataImportMetaHot } from "./babel_plugin_metadata_import_meta_hot.js"
|
|
4
|
+
import { collectHotDataFromHtmlAst } from "./html_hot_dependencies.js";
|
|
5
|
+
import { babelPluginMetadataImportMetaHot } from "./babel_plugin_metadata_import_meta_hot.js";
|
|
6
6
|
|
|
7
7
|
export const jsenvPluginImportMetaHot = () => {
|
|
8
8
|
const importMetaHotClientFileUrl = new URL(
|
|
9
9
|
"./client/import_meta_hot.js",
|
|
10
10
|
import.meta.url,
|
|
11
|
-
).href
|
|
11
|
+
).href;
|
|
12
12
|
|
|
13
13
|
return {
|
|
14
14
|
name: "jsenv:import_meta_hot",
|
|
@@ -17,12 +17,12 @@ export const jsenvPluginImportMetaHot = () => {
|
|
|
17
17
|
html: (htmlUrlInfo, context) => {
|
|
18
18
|
// during build we don't really care to parse html hot dependencies
|
|
19
19
|
if (context.build) {
|
|
20
|
-
return
|
|
20
|
+
return;
|
|
21
21
|
}
|
|
22
|
-
const htmlAst = parseHtmlString(htmlUrlInfo.content)
|
|
23
|
-
const hotReferences = collectHotDataFromHtmlAst(htmlAst)
|
|
24
|
-
htmlUrlInfo.data.hotDecline = false
|
|
25
|
-
htmlUrlInfo.data.hotAcceptSelf = false
|
|
22
|
+
const htmlAst = parseHtmlString(htmlUrlInfo.content);
|
|
23
|
+
const hotReferences = collectHotDataFromHtmlAst(htmlAst);
|
|
24
|
+
htmlUrlInfo.data.hotDecline = false;
|
|
25
|
+
htmlUrlInfo.data.hotAcceptSelf = false;
|
|
26
26
|
htmlUrlInfo.data.hotAcceptDependencies = hotReferences.map(
|
|
27
27
|
({ type, specifier }) => {
|
|
28
28
|
const existingReference = context.referenceUtils.find(
|
|
@@ -30,65 +30,69 @@ export const jsenvPluginImportMetaHot = () => {
|
|
|
30
30
|
return (
|
|
31
31
|
existingReference.type === type &&
|
|
32
32
|
existingReference.specifier === specifier
|
|
33
|
-
)
|
|
33
|
+
);
|
|
34
34
|
},
|
|
35
|
-
)
|
|
35
|
+
);
|
|
36
36
|
if (existingReference) {
|
|
37
|
-
return existingReference.url
|
|
37
|
+
return existingReference.url;
|
|
38
38
|
}
|
|
39
39
|
const [reference] = context.referenceUtils.found({
|
|
40
40
|
type,
|
|
41
41
|
specifier,
|
|
42
|
-
})
|
|
43
|
-
return reference.url
|
|
42
|
+
});
|
|
43
|
+
return reference.url;
|
|
44
44
|
},
|
|
45
|
-
)
|
|
45
|
+
);
|
|
46
46
|
},
|
|
47
47
|
css: (cssUrlInfo) => {
|
|
48
|
-
cssUrlInfo.data.hotDecline = false
|
|
49
|
-
cssUrlInfo.data.hotAcceptSelf = false
|
|
50
|
-
cssUrlInfo.data.hotAcceptDependencies = []
|
|
48
|
+
cssUrlInfo.data.hotDecline = false;
|
|
49
|
+
cssUrlInfo.data.hotAcceptSelf = false;
|
|
50
|
+
cssUrlInfo.data.hotAcceptDependencies = [];
|
|
51
51
|
},
|
|
52
52
|
js_module: async (urlInfo, context) => {
|
|
53
53
|
if (!urlInfo.content.includes("import.meta.hot")) {
|
|
54
|
-
return null
|
|
54
|
+
return null;
|
|
55
55
|
}
|
|
56
56
|
const { metadata } = await applyBabelPlugins({
|
|
57
57
|
babelPlugins: [babelPluginMetadataImportMetaHot],
|
|
58
58
|
urlInfo,
|
|
59
|
-
})
|
|
59
|
+
});
|
|
60
60
|
const {
|
|
61
61
|
importMetaHotPaths,
|
|
62
62
|
hotDecline,
|
|
63
63
|
hotAcceptSelf,
|
|
64
64
|
hotAcceptDependencies,
|
|
65
|
-
} = metadata
|
|
66
|
-
urlInfo.data.hotDecline = hotDecline
|
|
67
|
-
urlInfo.data.hotAcceptSelf = hotAcceptSelf
|
|
68
|
-
urlInfo.data.hotAcceptDependencies = hotAcceptDependencies
|
|
65
|
+
} = metadata;
|
|
66
|
+
urlInfo.data.hotDecline = hotDecline;
|
|
67
|
+
urlInfo.data.hotAcceptSelf = hotAcceptSelf;
|
|
68
|
+
urlInfo.data.hotAcceptDependencies = hotAcceptDependencies;
|
|
69
69
|
if (importMetaHotPaths.length === 0) {
|
|
70
|
-
return null
|
|
70
|
+
return null;
|
|
71
71
|
}
|
|
72
72
|
if (context.build) {
|
|
73
|
-
return removeImportMetaHots(urlInfo, importMetaHotPaths)
|
|
73
|
+
return removeImportMetaHots(urlInfo, importMetaHotPaths);
|
|
74
74
|
}
|
|
75
|
-
return injectImportMetaHot(
|
|
75
|
+
return injectImportMetaHot(
|
|
76
|
+
urlInfo,
|
|
77
|
+
context,
|
|
78
|
+
importMetaHotClientFileUrl,
|
|
79
|
+
);
|
|
76
80
|
},
|
|
77
81
|
},
|
|
78
|
-
}
|
|
79
|
-
}
|
|
82
|
+
};
|
|
83
|
+
};
|
|
80
84
|
|
|
81
85
|
const removeImportMetaHots = (urlInfo, importMetaHotPaths) => {
|
|
82
|
-
const magicSource = createMagicSource(urlInfo.content)
|
|
86
|
+
const magicSource = createMagicSource(urlInfo.content);
|
|
83
87
|
importMetaHotPaths.forEach((path) => {
|
|
84
88
|
magicSource.replace({
|
|
85
89
|
start: path.node.start,
|
|
86
90
|
end: path.node.end,
|
|
87
91
|
replacement: "undefined",
|
|
88
|
-
})
|
|
89
|
-
})
|
|
90
|
-
return magicSource.toContentAndSourcemap()
|
|
91
|
-
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
return magicSource.toContentAndSourcemap();
|
|
95
|
+
};
|
|
92
96
|
|
|
93
97
|
// For some reason using magic source here produce
|
|
94
98
|
// better sourcemap than doing the equivalent with babel
|
|
@@ -100,12 +104,12 @@ const injectImportMetaHot = (urlInfo, context, importMetaHotClientFileUrl) => {
|
|
|
100
104
|
type: "js_import",
|
|
101
105
|
expectedType: "js_module",
|
|
102
106
|
specifier: importMetaHotClientFileUrl,
|
|
103
|
-
})
|
|
104
|
-
const magicSource = createMagicSource(urlInfo.content)
|
|
107
|
+
});
|
|
108
|
+
const magicSource = createMagicSource(urlInfo.content);
|
|
105
109
|
magicSource.prepend(
|
|
106
110
|
`import { createImportMetaHot } from ${importMetaHotClientFileReference.generatedSpecifier}
|
|
107
111
|
import.meta.hot = createImportMetaHot(import.meta.url)
|
|
108
112
|
`,
|
|
109
|
-
)
|
|
110
|
-
return magicSource.toContentAndSourcemap()
|
|
111
|
-
}
|
|
113
|
+
);
|
|
114
|
+
return magicSource.toContentAndSourcemap();
|
|
115
|
+
};
|