@jsenv/core 40.0.2 → 40.0.3
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/{js → client/autoreload}/autoreload.js +45 -2
- package/dist/{html → client/directory_listing}/directory_listing.html +2 -2
- package/dist/{js → client/directory_listing/js}/directory_listing.js +3 -3
- package/dist/js/build.js +319 -15321
- package/dist/js/start_build_server.js +8 -4
- package/dist/js/start_dev_server.js +29 -35
- package/dist/jsenv_core.js +13 -1
- package/dist/jsenv_core_packages.js +10061 -0
- package/dist/main.js +117 -0
- package/dist/plugins.js +7944 -0
- package/package.json +9 -9
- package/src/build/build.js +61 -60
- package/src/build/build_params.js +20 -0
- package/src/build/build_specifier_manager.js +10 -0
- package/src/build/build_urls_generator.js +5 -1
- package/src/build/jsenv_plugin_subbuilds.js +71 -0
- package/src/dev/start_dev_server.js +21 -7
- package/src/kitchen/fetched_content_compliance.js +7 -3
- package/src/kitchen/kitchen.js +3 -0
- package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +1 -4
- package/src/plugins/html_syntax_error_fallback/jsenv_plugin_html_syntax_error_fallback.js +4 -3
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +2 -3
- package/src/plugins/protocol_file/jsenv_plugin_directory_listing.js +1 -2
- package/src/plugins/ribbon/jsenv_plugin_ribbon.js +2 -2
- package/dist/js/main.js +0 -994
- package/dist/js/process_teardown_events.js +0 -1848
- /package/dist/babel_helpers/{OverloadYield → overloadYield}/OverloadYield.js +0 -0
- /package/dist/{css → client/directory_listing/css}/directory_listing.css +0 -0
- /package/dist/{other → client/directory_listing/other}/dir.png +0 -0
- /package/dist/{other → client/directory_listing/other}/file.png +0 -0
- /package/dist/{other → client/directory_listing/other}/home.svg +0 -0
- /package/dist/{html → client/html_syntax_error}/html_syntax_error.html +0 -0
- /package/dist/{js → client/import_meta_hot}/import_meta_hot.js +0 -0
- /package/dist/{js → client/inline_content}/inline_content.js +0 -0
- /package/dist/{js → client/new_stylesheet}/new_stylesheet.js +0 -0
- /package/dist/{js → client/regenerator_runtime}/regenerator_runtime.js +0 -0
- /package/dist/{js → client/ribbon}/ribbon.js +0 -0
- /package/dist/{js → client/server_events_client}/server_events_client.js +0 -0
package/dist/main.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { createMagicSource } from "@jsenv/sourcemap";
|
|
2
|
+
import { URL_META, asUrlWithoutSearch } from "./jsenv_core_packages.js";
|
|
3
|
+
|
|
4
|
+
const jsenvPluginInjections = (rawAssociations) => {
|
|
5
|
+
let resolvedAssociations;
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
name: "jsenv:injections",
|
|
9
|
+
appliesDuring: "*",
|
|
10
|
+
init: (context) => {
|
|
11
|
+
resolvedAssociations = URL_META.resolveAssociations(
|
|
12
|
+
{ injectionsGetter: rawAssociations },
|
|
13
|
+
context.rootDirectoryUrl,
|
|
14
|
+
);
|
|
15
|
+
},
|
|
16
|
+
transformUrlContent: async (urlInfo) => {
|
|
17
|
+
const { injectionsGetter } = URL_META.applyAssociations({
|
|
18
|
+
url: asUrlWithoutSearch(urlInfo.url),
|
|
19
|
+
associations: resolvedAssociations,
|
|
20
|
+
});
|
|
21
|
+
if (!injectionsGetter) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
if (typeof injectionsGetter !== "function") {
|
|
25
|
+
throw new TypeError("injectionsGetter must be a function");
|
|
26
|
+
}
|
|
27
|
+
const injections = await injectionsGetter(urlInfo);
|
|
28
|
+
if (!injections) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const keys = Object.keys(injections);
|
|
32
|
+
if (keys.length === 0) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return replacePlaceholders(urlInfo.content, injections, urlInfo);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const injectionSymbol = Symbol.for("jsenv_injection");
|
|
41
|
+
const INJECTIONS = {
|
|
42
|
+
optional: (value) => {
|
|
43
|
+
return { [injectionSymbol]: "optional", value };
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// we export this because it is imported by jsenv_plugin_placeholder.js and unit test
|
|
48
|
+
const replacePlaceholders = (content, replacements, urlInfo) => {
|
|
49
|
+
const magicSource = createMagicSource(content);
|
|
50
|
+
for (const key of Object.keys(replacements)) {
|
|
51
|
+
let index = content.indexOf(key);
|
|
52
|
+
const replacement = replacements[key];
|
|
53
|
+
let isOptional;
|
|
54
|
+
let value;
|
|
55
|
+
if (replacement && replacement[injectionSymbol]) {
|
|
56
|
+
const valueBehindSymbol = replacement[injectionSymbol];
|
|
57
|
+
isOptional = valueBehindSymbol === "optional";
|
|
58
|
+
value = replacement.value;
|
|
59
|
+
} else {
|
|
60
|
+
value = replacement;
|
|
61
|
+
}
|
|
62
|
+
if (index === -1) {
|
|
63
|
+
if (!isOptional) {
|
|
64
|
+
urlInfo.context.logger.warn(
|
|
65
|
+
`placeholder "${key}" not found in ${urlInfo.url}.
|
|
66
|
+
--- suggestion a ---
|
|
67
|
+
Add "${key}" in that file.
|
|
68
|
+
--- suggestion b ---
|
|
69
|
+
Fix eventual typo in "${key}"?
|
|
70
|
+
--- suggestion c ---
|
|
71
|
+
Mark injection as optional using INJECTIONS.optional():
|
|
72
|
+
import { INJECTIONS } from "@jsenv/core";
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
"${key}": INJECTIONS.optional(${JSON.stringify(value)}),
|
|
76
|
+
};`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
while (index !== -1) {
|
|
83
|
+
const start = index;
|
|
84
|
+
const end = index + key.length;
|
|
85
|
+
magicSource.replace({
|
|
86
|
+
start,
|
|
87
|
+
end,
|
|
88
|
+
replacement:
|
|
89
|
+
urlInfo.type === "js_classic" ||
|
|
90
|
+
urlInfo.type === "js_module" ||
|
|
91
|
+
urlInfo.type === "html"
|
|
92
|
+
? JSON.stringify(value, null, " ")
|
|
93
|
+
: value,
|
|
94
|
+
});
|
|
95
|
+
index = content.indexOf(key, end);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return magicSource.toContentAndSourcemap();
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// dev
|
|
102
|
+
const startDevServer = async (...args) => {
|
|
103
|
+
const namespace = await import("./js/start_dev_server.js");
|
|
104
|
+
return namespace.startDevServer(...args);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// build
|
|
108
|
+
const build = async (...args) => {
|
|
109
|
+
const namespace = await import("./js/build.js");
|
|
110
|
+
return namespace.build(...args);
|
|
111
|
+
};
|
|
112
|
+
const startBuildServer = async (...args) => {
|
|
113
|
+
const namespace = await import("./js/start_build_server.js");
|
|
114
|
+
return namespace.startBuildServer(...args);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export { INJECTIONS, build, jsenvPluginInjections, replacePlaceholders, startBuildServer, startDevServer };
|