@jsenv/core 40.6.2 → 40.7.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/dist/build/browserslist_index/browserslist_index.js +62 -48
- package/dist/build/build.js +412 -185
- package/dist/build/jsenv_core_packages.js +103 -105
- package/dist/client/directory_listing/js/directory_listing.js +41 -26
- package/dist/client/ribbon/ribbon.js +40 -37
- package/dist/jsenv_core.js +4 -0
- package/dist/start_build_server/jsenv_core_packages.js +29 -29
- package/dist/start_dev_server/jsenv_core_packages.js +103 -105
- package/dist/start_dev_server/start_dev_server.js +412 -182
- package/package.json +21 -12
- package/src/build/build.js +9 -9
- package/src/build/build_specifier_manager.js +3 -3
- package/src/build/build_urls_generator.js +2 -2
- package/src/dev/start_dev_server.js +11 -8
- package/src/helpers/web_url_converter.js +2 -2
- package/src/kitchen/errors.js +1 -1
- package/src/kitchen/kitchen.js +2 -0
- package/src/kitchen/out_directory_url.js +2 -2
- package/src/kitchen/url_graph/url_graph.js +1 -0
- package/src/kitchen/url_graph/url_info_injections.js +172 -0
- package/src/kitchen/url_graph/url_info_transformations.js +28 -7
- package/src/main.js +1 -1
- package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +2 -2
- package/src/plugins/chrome_devtools_json/jsenv_plugin_chrome_devtools_json.js +1 -0
- package/src/plugins/global_scenarios/jsenv_plugin_global_scenarios.js +4 -9
- package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +2 -0
- package/src/plugins/injections/jsenv_plugin_injections.js +51 -85
- package/src/plugins/plugin_controller.js +28 -7
- package/src/plugins/plugins.js +3 -1
- package/src/plugins/protocol_file/client/directory_listing.jsx +42 -23
- package/src/plugins/protocol_file/file_and_server_urls_converter.js +2 -5
- package/src/plugins/protocol_file/jsenv_plugin_directory_listing.js +65 -49
- package/src/plugins/protocol_file/jsenv_plugin_fs_redirection.js +36 -3
- package/src/plugins/protocol_file/jsenv_plugin_protocol_file.js +3 -0
- package/src/plugins/ribbon/client/ribbon.js +40 -37
- package/src/plugins/injections/internal/inject_globals.js +0 -52
|
@@ -3,11 +3,17 @@ import {
|
|
|
3
3
|
applyFileSystemMagicResolution,
|
|
4
4
|
getExtensionsToTry,
|
|
5
5
|
} from "@jsenv/node-esm-resolution";
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
urlIsOrIsInsideOf,
|
|
8
|
+
urlToExtension,
|
|
9
|
+
urlToFilename,
|
|
10
|
+
urlToPathname,
|
|
11
|
+
} from "@jsenv/urls";
|
|
12
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
8
13
|
import { pathToFileURL } from "node:url";
|
|
9
14
|
|
|
10
15
|
export const jsenvPluginFsRedirection = ({
|
|
16
|
+
spa,
|
|
11
17
|
directoryContentMagicName,
|
|
12
18
|
magicExtensions = ["inherit", ".js"],
|
|
13
19
|
magicDirectoryIndex = true,
|
|
@@ -97,11 +103,19 @@ export const jsenvPluginFsRedirection = ({
|
|
|
97
103
|
// 3. The url pathname does not ends with "/"
|
|
98
104
|
// In that case we assume client explicitely asks to load a directory
|
|
99
105
|
if (
|
|
106
|
+
spa &&
|
|
100
107
|
!urlToExtension(urlObject) &&
|
|
101
108
|
!urlToPathname(urlObject).endsWith("/")
|
|
102
109
|
) {
|
|
103
|
-
const {
|
|
110
|
+
const { requestedUrl, rootDirectoryUrl, mainFilePath } =
|
|
104
111
|
reference.ownerUrlInfo.context;
|
|
112
|
+
const closestHtmlRootFile = getClosestHtmlRootFile(
|
|
113
|
+
requestedUrl,
|
|
114
|
+
rootDirectoryUrl,
|
|
115
|
+
);
|
|
116
|
+
if (closestHtmlRootFile) {
|
|
117
|
+
return closestHtmlRootFile;
|
|
118
|
+
}
|
|
105
119
|
return new URL(mainFilePath, rootDirectoryUrl);
|
|
106
120
|
}
|
|
107
121
|
return null;
|
|
@@ -150,3 +164,22 @@ const resolveSymlink = (fileUrl) => {
|
|
|
150
164
|
}
|
|
151
165
|
return realUrlObject.href;
|
|
152
166
|
};
|
|
167
|
+
|
|
168
|
+
const getClosestHtmlRootFile = (requestedUrl, serverRootDirectoryUrl) => {
|
|
169
|
+
let directoryUrl = new URL("./", requestedUrl);
|
|
170
|
+
while (true) {
|
|
171
|
+
const indexHtmlFileUrl = new URL(`index.html`, directoryUrl);
|
|
172
|
+
if (existsSync(indexHtmlFileUrl)) {
|
|
173
|
+
return indexHtmlFileUrl.href;
|
|
174
|
+
}
|
|
175
|
+
const filename = urlToFilename(directoryUrl);
|
|
176
|
+
const htmlFileUrlCandidate = new URL(`${filename}.html`, directoryUrl);
|
|
177
|
+
if (existsSync(htmlFileUrlCandidate)) {
|
|
178
|
+
return htmlFileUrlCandidate.href;
|
|
179
|
+
}
|
|
180
|
+
if (!urlIsOrIsInsideOf(directoryUrl, serverRootDirectoryUrl)) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
directoryUrl = new URL("../", directoryUrl);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
@@ -9,6 +9,7 @@ import { jsenvPluginFsRedirection } from "./jsenv_plugin_fs_redirection.js";
|
|
|
9
9
|
const directoryContentMagicName = "...";
|
|
10
10
|
|
|
11
11
|
export const jsenvPluginProtocolFile = ({
|
|
12
|
+
spa = true,
|
|
12
13
|
magicExtensions,
|
|
13
14
|
magicDirectoryIndex,
|
|
14
15
|
preserveSymlinks,
|
|
@@ -20,6 +21,7 @@ export const jsenvPluginProtocolFile = ({
|
|
|
20
21
|
}) => {
|
|
21
22
|
return [
|
|
22
23
|
jsenvPluginFsRedirection({
|
|
24
|
+
spa,
|
|
23
25
|
directoryContentMagicName,
|
|
24
26
|
magicExtensions,
|
|
25
27
|
magicDirectoryIndex,
|
|
@@ -75,6 +77,7 @@ export const jsenvPluginProtocolFile = ({
|
|
|
75
77
|
...(directoryListing
|
|
76
78
|
? [
|
|
77
79
|
jsenvPluginDirectoryListing({
|
|
80
|
+
spa,
|
|
78
81
|
...directoryListing,
|
|
79
82
|
directoryContentMagicName,
|
|
80
83
|
rootDirectoryUrl,
|
|
@@ -1,43 +1,46 @@
|
|
|
1
1
|
export const injectRibbon = ({ text }) => {
|
|
2
2
|
const css = /* css */ `
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
3
|
+
#jsenv_ribbon_container {
|
|
4
|
+
position: fixed;
|
|
5
|
+
z-index: 1001;
|
|
6
|
+
top: 0;
|
|
7
|
+
right: 0;
|
|
8
|
+
width: 100px;
|
|
9
|
+
height: 100px;
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
opacity: 0.5;
|
|
12
|
+
pointer-events: none;
|
|
13
|
+
}
|
|
14
|
+
#jsenv_ribbon {
|
|
15
|
+
position: absolute;
|
|
16
|
+
top: -10px;
|
|
17
|
+
right: -10px;
|
|
18
|
+
width: 100%;
|
|
19
|
+
height: 100%;
|
|
20
|
+
}
|
|
21
|
+
#jsenv_ribbon_text {
|
|
22
|
+
position: absolute;
|
|
23
|
+
left: 0px;
|
|
24
|
+
top: 20px;
|
|
25
|
+
transform: rotate(45deg);
|
|
26
|
+
display: block;
|
|
27
|
+
width: 125px;
|
|
28
|
+
line-height: 36px;
|
|
29
|
+
background-color: orange;
|
|
30
|
+
color: rgb(55, 7, 7);
|
|
31
|
+
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
|
|
32
|
+
font-weight: 700;
|
|
33
|
+
font-size: 16px;
|
|
34
|
+
font-family: "Lato", sans-serif;
|
|
35
|
+
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
|
|
36
|
+
text-align: center;
|
|
37
|
+
user-select: none;
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
39
40
|
const html = /* html */ `<div id="jsenv_ribbon_container">
|
|
40
|
-
<style
|
|
41
|
+
<style>
|
|
42
|
+
${css}
|
|
43
|
+
</style>
|
|
41
44
|
<div id="jsenv_ribbon">
|
|
42
45
|
<div id="jsenv_ribbon_text">${text}</div>
|
|
43
46
|
</div>
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { injectJsenvScript, parseHtml, stringifyHtmlAst } from "@jsenv/ast";
|
|
2
|
-
import { createMagicSource } from "@jsenv/sourcemap";
|
|
3
|
-
|
|
4
|
-
export const injectGlobals = (content, globals, urlInfo) => {
|
|
5
|
-
if (urlInfo.type === "html") {
|
|
6
|
-
return globalInjectorOnHtml(content, globals, urlInfo);
|
|
7
|
-
}
|
|
8
|
-
if (urlInfo.type === "js_classic" || urlInfo.type === "js_module") {
|
|
9
|
-
return globalsInjectorOnJs(content, globals, urlInfo);
|
|
10
|
-
}
|
|
11
|
-
throw new Error(`cannot inject globals into "${urlInfo.type}"`);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const globalInjectorOnHtml = (content, globals, urlInfo) => {
|
|
15
|
-
// ideally we would inject an importmap but browser support is too low
|
|
16
|
-
// (even worse for worker/service worker)
|
|
17
|
-
// so for now we inject code into entry points
|
|
18
|
-
const htmlAst = parseHtml({
|
|
19
|
-
html: content,
|
|
20
|
-
url: urlInfo.url,
|
|
21
|
-
storeOriginalPositions: false,
|
|
22
|
-
});
|
|
23
|
-
const clientCode = generateClientCodeForGlobals(globals, {
|
|
24
|
-
isWebWorker: false,
|
|
25
|
-
});
|
|
26
|
-
injectJsenvScript(htmlAst, {
|
|
27
|
-
content: clientCode,
|
|
28
|
-
pluginName: "jsenv:inject_globals",
|
|
29
|
-
});
|
|
30
|
-
return stringifyHtmlAst(htmlAst);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const globalsInjectorOnJs = (content, globals, urlInfo) => {
|
|
34
|
-
const clientCode = generateClientCodeForGlobals(globals, {
|
|
35
|
-
isWebWorker:
|
|
36
|
-
urlInfo.subtype === "worker" ||
|
|
37
|
-
urlInfo.subtype === "service_worker" ||
|
|
38
|
-
urlInfo.subtype === "shared_worker",
|
|
39
|
-
});
|
|
40
|
-
const magicSource = createMagicSource(content);
|
|
41
|
-
magicSource.prepend(clientCode);
|
|
42
|
-
return magicSource.toContentAndSourcemap();
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const generateClientCodeForGlobals = (globals, { isWebWorker = false }) => {
|
|
46
|
-
const globalName = isWebWorker ? "self" : "window";
|
|
47
|
-
return `Object.assign(${globalName}, ${JSON.stringify(
|
|
48
|
-
globals,
|
|
49
|
-
null,
|
|
50
|
-
" ",
|
|
51
|
-
)});`;
|
|
52
|
-
};
|