@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "36.0.1",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -62,14 +62,14 @@
|
|
|
62
62
|
"@babel/plugin-transform-modules-umd": "7.18.6",
|
|
63
63
|
"@financial-times/polyfill-useragent-normaliser": "1.10.2",
|
|
64
64
|
"@jsenv/abort": "4.2.4",
|
|
65
|
-
"@jsenv/ast": "
|
|
65
|
+
"@jsenv/ast": "4.0.0",
|
|
66
66
|
"@jsenv/babel-plugins": "1.1.6",
|
|
67
67
|
"@jsenv/filesystem": "4.2.3",
|
|
68
68
|
"@jsenv/importmap": "1.2.1",
|
|
69
69
|
"@jsenv/integrity": "0.0.1",
|
|
70
|
-
"@jsenv/log": "3.3.
|
|
70
|
+
"@jsenv/log": "3.3.5",
|
|
71
71
|
"@jsenv/node-esm-resolution": "1.0.1",
|
|
72
|
-
"@jsenv/server": "15.0.
|
|
72
|
+
"@jsenv/server": "15.0.3",
|
|
73
73
|
"@jsenv/sourcemap": "1.0.10",
|
|
74
74
|
"@jsenv/url-meta": "8.1.0",
|
|
75
75
|
"@jsenv/urls": "2.0.0",
|
|
@@ -83,16 +83,16 @@
|
|
|
83
83
|
"@babel/plugin-syntax-import-assertions": "7.20.0",
|
|
84
84
|
"@jsenv/assert": "./packages/assert/",
|
|
85
85
|
"@jsenv/eslint-config": "./packages/eslint-config/",
|
|
86
|
-
"@jsenv/file-size-impact": "14.1.
|
|
86
|
+
"@jsenv/file-size-impact": "14.1.1",
|
|
87
87
|
"@jsenv/https-local": "3.0.6",
|
|
88
|
-
"@jsenv/package-workspace": "0.5.
|
|
89
|
-
"@jsenv/performance-impact": "4.1.
|
|
88
|
+
"@jsenv/package-workspace": "0.5.2",
|
|
89
|
+
"@jsenv/performance-impact": "4.1.1",
|
|
90
90
|
"@jsenv/plugin-globals": "./packages/jsenv-plugin-globals/",
|
|
91
91
|
"@jsenv/plugin-minification": "./packages/jsenv-plugin-minification/",
|
|
92
92
|
"@jsenv/plugin-placeholders": "./packages/jsenv-plugin-placeholders/",
|
|
93
93
|
"@jsenv/plugin-as-js-classic": "./packages/jsenv-plugin-as-js-classic/",
|
|
94
94
|
"@jsenv/test": "./packages/test/",
|
|
95
|
-
"eslint": "8.
|
|
95
|
+
"eslint": "8.40.0",
|
|
96
96
|
"eslint-plugin-html": "7.1.0",
|
|
97
97
|
"eslint-plugin-import": "2.27.5",
|
|
98
98
|
"eslint-plugin-react": "7.32.2",
|
package/src/build/build.js
CHANGED
|
@@ -64,9 +64,8 @@ import {
|
|
|
64
64
|
isWebWorkerEntryPointReference,
|
|
65
65
|
isWebWorkerUrlInfo,
|
|
66
66
|
} from "../kitchen/web_workers.js";
|
|
67
|
-
import {
|
|
67
|
+
import { jsenvPluginReferenceAnalysis } from "../plugins/reference_analysis/jsenv_plugin_reference_analysis.js";
|
|
68
68
|
import { jsenvPluginInlining } from "../plugins/inlining/jsenv_plugin_inlining.js";
|
|
69
|
-
import { jsenvPluginInlineContentAnalysis } from "../plugins/inline_content_analysis/jsenv_plugin_inline_content_analysis.js";
|
|
70
69
|
import { jsenvPluginJsModuleFallback } from "../plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js";
|
|
71
70
|
import { getCorePlugins } from "../plugins/plugins.js";
|
|
72
71
|
import { jsenvPluginLineBreakNormalization } from "./jsenv_plugin_line_break_normalization.js";
|
|
@@ -98,11 +97,11 @@ export const defaultRuntimeCompat = {
|
|
|
98
97
|
* @param {Object} buildParameters
|
|
99
98
|
* @param {string|url} buildParameters.sourceDirectoryUrl
|
|
100
99
|
* Directory containing source files
|
|
100
|
+
* @param {string|url} buildParameters.buildDirectoryUrl
|
|
101
|
+
* Directory where optimized files will be written
|
|
101
102
|
* @param {object} buildParameters.entryPoints
|
|
102
103
|
* Object where keys are paths to source files and values are their future name in the build directory.
|
|
103
104
|
* Keys are relative to sourceDirectoryUrl
|
|
104
|
-
* @param {string|url} buildParameters.buildDirectoryUrl
|
|
105
|
-
* Directory where optimized files will be written
|
|
106
105
|
* @param {object} buildParameters.runtimeCompat
|
|
107
106
|
* Code generated will be compatible with these runtimes
|
|
108
107
|
* @param {string} [buildParameters.assetsDirectory=""]
|
|
@@ -128,17 +127,16 @@ export const build = async ({
|
|
|
128
127
|
handleSIGINT = true,
|
|
129
128
|
logLevel = "info",
|
|
130
129
|
sourceDirectoryUrl,
|
|
131
|
-
entryPoints = {},
|
|
132
130
|
buildDirectoryUrl,
|
|
131
|
+
entryPoints = {},
|
|
133
132
|
assetsDirectory = "",
|
|
134
133
|
|
|
135
134
|
runtimeCompat = defaultRuntimeCompat,
|
|
136
135
|
base = runtimeCompat.node ? "./" : "/",
|
|
137
136
|
plugins = [],
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
urlResolution,
|
|
137
|
+
referenceAnalysis = {},
|
|
138
|
+
nodeEsmResolution,
|
|
139
|
+
webResolution,
|
|
142
140
|
fileSystemMagicRedirection,
|
|
143
141
|
directoryReferenceAllowed,
|
|
144
142
|
scenarioPlaceholders,
|
|
@@ -153,6 +151,8 @@ export const build = async ({
|
|
|
153
151
|
watch = false,
|
|
154
152
|
|
|
155
153
|
directoryToClean,
|
|
154
|
+
sourcemaps = "none",
|
|
155
|
+
sourcemapsSourcesContent,
|
|
156
156
|
writeOnFileSystem = true,
|
|
157
157
|
outDirectoryUrl,
|
|
158
158
|
assetManifest = versioningMethod === "filename",
|
|
@@ -319,6 +319,12 @@ build ${entryPointKeys.length} entry points`);
|
|
|
319
319
|
...plugins,
|
|
320
320
|
{
|
|
321
321
|
appliesDuring: "build",
|
|
322
|
+
formatReference: (reference) => {
|
|
323
|
+
if (!reference.shouldHandle) {
|
|
324
|
+
return `ignore:${reference.specifier}`;
|
|
325
|
+
}
|
|
326
|
+
return null;
|
|
327
|
+
},
|
|
322
328
|
fetchUrlContent: (urlInfo, context) => {
|
|
323
329
|
if (context.reference.original) {
|
|
324
330
|
rawRedirections.set(
|
|
@@ -327,20 +333,15 @@ build ${entryPointKeys.length} entry points`);
|
|
|
327
333
|
);
|
|
328
334
|
}
|
|
329
335
|
},
|
|
330
|
-
formatUrl: (reference) => {
|
|
331
|
-
if (!reference.shouldHandle) {
|
|
332
|
-
return `ignore:${reference.specifier}`;
|
|
333
|
-
}
|
|
334
|
-
return null;
|
|
335
|
-
},
|
|
336
336
|
},
|
|
337
337
|
...getCorePlugins({
|
|
338
338
|
rootDirectoryUrl: sourceDirectoryUrl,
|
|
339
339
|
urlGraph: rawGraph,
|
|
340
340
|
runtimeCompat,
|
|
341
341
|
|
|
342
|
-
|
|
343
|
-
|
|
342
|
+
referenceAnalysis,
|
|
343
|
+
nodeEsmResolution,
|
|
344
|
+
webResolution,
|
|
344
345
|
fileSystemMagicRedirection,
|
|
345
346
|
directoryReferenceAllowed,
|
|
346
347
|
transpilation: {
|
|
@@ -379,10 +380,6 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
379
380
|
const bundleUrlInfos = {};
|
|
380
381
|
const bundlers = {};
|
|
381
382
|
const finalGraph = createUrlGraph();
|
|
382
|
-
const urlAnalysisPlugin = jsenvPluginUrlAnalysis({
|
|
383
|
-
rootDirectoryUrl: sourceDirectoryUrl,
|
|
384
|
-
...urlAnalysis,
|
|
385
|
-
});
|
|
386
383
|
const finalGraphKitchen = createKitchen({
|
|
387
384
|
logLevel,
|
|
388
385
|
rootDirectoryUrl: buildDirectoryUrl,
|
|
@@ -391,21 +388,21 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
391
388
|
runtimeCompat,
|
|
392
389
|
...contextSharedDuringBuild,
|
|
393
390
|
plugins: [
|
|
394
|
-
|
|
391
|
+
jsenvPluginReferenceAnalysis({
|
|
392
|
+
...referenceAnalysis,
|
|
393
|
+
fetchInlineUrls: false,
|
|
394
|
+
}),
|
|
395
395
|
...(lineBreakNormalization
|
|
396
396
|
? [jsenvPluginLineBreakNormalization()]
|
|
397
397
|
: []),
|
|
398
398
|
jsenvPluginJsModuleFallback({
|
|
399
399
|
systemJsInjection: true,
|
|
400
400
|
}),
|
|
401
|
-
jsenvPluginInlineContentAnalysis({
|
|
402
|
-
fetchInlineUrls: false,
|
|
403
|
-
}),
|
|
404
401
|
jsenvPluginInlining(),
|
|
405
402
|
{
|
|
406
403
|
name: "jsenv:build",
|
|
407
404
|
appliesDuring: "build",
|
|
408
|
-
|
|
405
|
+
resolveReference: (reference) => {
|
|
409
406
|
const getUrl = () => {
|
|
410
407
|
if (reference.type === "filesystem") {
|
|
411
408
|
const parentRawUrl = buildDirectoryRedirections.get(
|
|
@@ -429,8 +426,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
429
426
|
url = bundleInternalRedirections.get(url) || url;
|
|
430
427
|
return url;
|
|
431
428
|
},
|
|
432
|
-
// redirecting
|
|
433
|
-
|
|
429
|
+
// redirecting references into the build directory
|
|
430
|
+
redirectReference: (reference) => {
|
|
434
431
|
if (!reference.url.startsWith("file:")) {
|
|
435
432
|
return null;
|
|
436
433
|
}
|
|
@@ -493,7 +490,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
493
490
|
const isEntryPoint =
|
|
494
491
|
reference.isEntryPoint ||
|
|
495
492
|
isWebWorkerEntryPointReference(reference);
|
|
496
|
-
// the url info do not exists yet (it will be created after this "
|
|
493
|
+
// the url info do not exists yet (it will be created after this "redirectReference" hook)
|
|
497
494
|
// And the content will be generated when url is cooked by url graph loader.
|
|
498
495
|
// Here we just want to reserve an url for that file
|
|
499
496
|
const urlInfo = {
|
|
@@ -579,7 +576,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
579
576
|
});
|
|
580
577
|
return buildUrl;
|
|
581
578
|
},
|
|
582
|
-
|
|
579
|
+
formatReference: (reference) => {
|
|
583
580
|
if (!reference.generatedUrl.startsWith("file:")) {
|
|
584
581
|
if (!versioning && reference.generatedUrl.startsWith("ignore:")) {
|
|
585
582
|
return reference.generatedUrl.slice("ignore:".length);
|
|
@@ -675,7 +672,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
675
672
|
{
|
|
676
673
|
name: "jsenv:optimize",
|
|
677
674
|
appliesDuring: "build",
|
|
678
|
-
|
|
675
|
+
transformUrlContent: async (urlInfo, context) => {
|
|
679
676
|
await rawGraphKitchen.pluginController.callAsyncHooks(
|
|
680
677
|
"optimizeUrlContent",
|
|
681
678
|
urlInfo,
|
|
@@ -984,6 +981,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
984
981
|
if (!versioning) {
|
|
985
982
|
break inject_version_in_urls;
|
|
986
983
|
}
|
|
984
|
+
logger.debug("versioning start");
|
|
987
985
|
const versioningTask = createTaskLog("inject version in urls", {
|
|
988
986
|
disabled: logger.levels.debug || !logger.levels.info,
|
|
989
987
|
});
|
|
@@ -1092,7 +1090,9 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1092
1090
|
parseHtmlString(urlInfo.content, {
|
|
1093
1091
|
storeOriginalPositions: false,
|
|
1094
1092
|
}),
|
|
1095
|
-
{
|
|
1093
|
+
{
|
|
1094
|
+
cleanupJsenvAttributes: true,
|
|
1095
|
+
},
|
|
1096
1096
|
)
|
|
1097
1097
|
: urlInfo.content;
|
|
1098
1098
|
const contentVersionGenerator = createVersionGenerator();
|
|
@@ -1183,24 +1183,32 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1183
1183
|
runtimeCompat,
|
|
1184
1184
|
...contextSharedDuringBuild,
|
|
1185
1185
|
plugins: [
|
|
1186
|
-
|
|
1187
|
-
|
|
1186
|
+
jsenvPluginReferenceAnalysis({
|
|
1187
|
+
...referenceAnalysis,
|
|
1188
1188
|
fetchInlineUrls: false,
|
|
1189
|
-
|
|
1189
|
+
inlineConvertedScript: true, // to be able to version their urls
|
|
1190
1190
|
allowEscapeForVersioning: true,
|
|
1191
1191
|
}),
|
|
1192
1192
|
{
|
|
1193
1193
|
name: "jsenv:versioning",
|
|
1194
1194
|
appliesDuring: "build",
|
|
1195
|
-
|
|
1195
|
+
resolveReference: (reference) => {
|
|
1196
1196
|
const buildUrl = buildUrls.get(reference.specifier);
|
|
1197
1197
|
if (buildUrl) {
|
|
1198
1198
|
return buildUrl;
|
|
1199
1199
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1200
|
+
let urlObject;
|
|
1201
|
+
if (reference.specifier[0] === "/") {
|
|
1202
|
+
urlObject = new URL(
|
|
1203
|
+
reference.specifier.slice(1),
|
|
1204
|
+
buildDirectoryUrl,
|
|
1205
|
+
);
|
|
1206
|
+
} else {
|
|
1207
|
+
urlObject = new URL(
|
|
1208
|
+
reference.specifier,
|
|
1209
|
+
reference.baseUrl || reference.parentUrl,
|
|
1210
|
+
);
|
|
1211
|
+
}
|
|
1204
1212
|
const url = urlObject.href;
|
|
1205
1213
|
// during versioning we revisit the deps
|
|
1206
1214
|
// but the code used to enforce trailing slash on directories
|
|
@@ -1218,7 +1226,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1218
1226
|
}
|
|
1219
1227
|
return url;
|
|
1220
1228
|
},
|
|
1221
|
-
|
|
1229
|
+
formatReference: (reference) => {
|
|
1222
1230
|
if (!reference.shouldHandle) {
|
|
1223
1231
|
if (reference.generatedUrl.startsWith("ignore:")) {
|
|
1224
1232
|
return reference.generatedUrl.slice("ignore:".length);
|
package/src/dev/file_service.js
CHANGED
|
@@ -10,7 +10,6 @@ import { createUrlGraph } from "../kitchen/url_graph.js";
|
|
|
10
10
|
import { createKitchen } from "../kitchen/kitchen.js";
|
|
11
11
|
import { RUNTIME_COMPAT } from "../kitchen/compat/runtime_compat.js";
|
|
12
12
|
import { getCorePlugins } from "../plugins/plugins.js";
|
|
13
|
-
import { explorerHtmlFileUrl } from "../plugins/explorer/jsenv_plugin_explorer.js";
|
|
14
13
|
import { jsenvPluginServerEventsClientInjection } from "../plugins/server_events/jsenv_plugin_server_events_client_injection.js";
|
|
15
14
|
import { parseUserAgentHeader } from "./user_agent.js";
|
|
16
15
|
|
|
@@ -27,14 +26,14 @@ export const createFileService = ({
|
|
|
27
26
|
runtimeCompat,
|
|
28
27
|
|
|
29
28
|
plugins,
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
referenceAnalysis,
|
|
30
|
+
nodeEsmResolution,
|
|
31
|
+
webResolution,
|
|
32
32
|
fileSystemMagicRedirection,
|
|
33
33
|
supervisor,
|
|
34
34
|
transpilation,
|
|
35
35
|
clientAutoreload,
|
|
36
36
|
cooldownBetweenFileEvents,
|
|
37
|
-
explorer,
|
|
38
37
|
cacheControl,
|
|
39
38
|
ribbon,
|
|
40
39
|
sourcemaps,
|
|
@@ -93,19 +92,11 @@ export const createFileService = ({
|
|
|
93
92
|
});
|
|
94
93
|
const clientRuntimeCompat = { [runtimeName]: runtimeVersion };
|
|
95
94
|
|
|
96
|
-
let defaultFileUrl;
|
|
97
|
-
if (explorer) {
|
|
98
|
-
defaultFileUrl = String(explorerHtmlFileUrl);
|
|
99
|
-
} else if (sourceMainFilePath) {
|
|
100
|
-
defaultFileUrl = String(new URL(sourceMainFilePath, sourceDirectoryUrl));
|
|
101
|
-
} else {
|
|
102
|
-
defaultFileUrl = String(new URL("./index.html", sourceDirectoryUrl));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
95
|
const kitchen = createKitchen({
|
|
106
96
|
signal,
|
|
107
97
|
logLevel,
|
|
108
98
|
rootDirectoryUrl: sourceDirectoryUrl,
|
|
99
|
+
mainFilePath: sourceMainFilePath,
|
|
109
100
|
urlGraph,
|
|
110
101
|
dev: true,
|
|
111
102
|
runtimeCompat,
|
|
@@ -121,11 +112,11 @@ export const createFileService = ({
|
|
|
121
112
|
...plugins,
|
|
122
113
|
...getCorePlugins({
|
|
123
114
|
rootDirectoryUrl: sourceDirectoryUrl,
|
|
124
|
-
defaultFileUrl,
|
|
125
115
|
runtimeCompat,
|
|
126
116
|
|
|
127
|
-
|
|
128
|
-
|
|
117
|
+
referenceAnalysis,
|
|
118
|
+
nodeEsmResolution,
|
|
119
|
+
webResolution,
|
|
129
120
|
fileSystemMagicRedirection,
|
|
130
121
|
supervisor,
|
|
131
122
|
transpilation,
|
|
@@ -133,7 +124,6 @@ export const createFileService = ({
|
|
|
133
124
|
clientAutoreload,
|
|
134
125
|
clientFileChangeCallbackList,
|
|
135
126
|
clientFilesPruneCallbackList,
|
|
136
|
-
explorer,
|
|
137
127
|
cacheControl,
|
|
138
128
|
ribbon,
|
|
139
129
|
}),
|
|
@@ -24,7 +24,7 @@ import { createFileService } from "./file_service.js";
|
|
|
24
24
|
*/
|
|
25
25
|
export const startDevServer = async ({
|
|
26
26
|
sourceDirectoryUrl,
|
|
27
|
-
sourceMainFilePath,
|
|
27
|
+
sourceMainFilePath = "./index.html",
|
|
28
28
|
port = 3456,
|
|
29
29
|
hostname,
|
|
30
30
|
acceptAnyIp,
|
|
@@ -50,12 +50,12 @@ export const startDevServer = async ({
|
|
|
50
50
|
// code would be supported during dev but not after build
|
|
51
51
|
runtimeCompat = defaultRuntimeCompat,
|
|
52
52
|
plugins = [],
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
referenceAnalysis = {},
|
|
54
|
+
nodeEsmResolution,
|
|
55
|
+
webResolution,
|
|
55
56
|
supervisor = true,
|
|
56
57
|
fileSystemMagicRedirection,
|
|
57
58
|
transpilation,
|
|
58
|
-
explorer = true, // see jsenv_plugin_explorer.js
|
|
59
59
|
cacheControl = true,
|
|
60
60
|
ribbon = true,
|
|
61
61
|
// toolbar = false,
|
|
@@ -78,6 +78,11 @@ export const startDevServer = async ({
|
|
|
78
78
|
sourceDirectoryUrl,
|
|
79
79
|
"sourceDirectoryUrl",
|
|
80
80
|
);
|
|
81
|
+
if (typeof sourceMainFilePath !== "string") {
|
|
82
|
+
throw new TypeError(
|
|
83
|
+
`sourceMainFilePath must be a string, got ${sourceMainFilePath}`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
81
86
|
if (outDirectoryUrl === undefined) {
|
|
82
87
|
if (!process.env.CI) {
|
|
83
88
|
const packageDirectoryUrl = lookupPackageDirectory(sourceDirectoryUrl);
|
|
@@ -185,14 +190,14 @@ export const startDevServer = async ({
|
|
|
185
190
|
runtimeCompat,
|
|
186
191
|
|
|
187
192
|
plugins,
|
|
188
|
-
|
|
189
|
-
|
|
193
|
+
referenceAnalysis,
|
|
194
|
+
nodeEsmResolution,
|
|
195
|
+
webResolution,
|
|
190
196
|
fileSystemMagicRedirection,
|
|
191
197
|
supervisor,
|
|
192
198
|
transpilation,
|
|
193
199
|
clientAutoreload,
|
|
194
200
|
cooldownBetweenFileEvents,
|
|
195
|
-
explorer,
|
|
196
201
|
cacheControl,
|
|
197
202
|
ribbon,
|
|
198
203
|
sourcemaps,
|
package/src/kitchen/kitchen.js
CHANGED
|
@@ -28,6 +28,7 @@ export const createKitchen = ({
|
|
|
28
28
|
logLevel,
|
|
29
29
|
|
|
30
30
|
rootDirectoryUrl,
|
|
31
|
+
mainFilePath,
|
|
31
32
|
urlGraph,
|
|
32
33
|
dev = false,
|
|
33
34
|
build = false,
|
|
@@ -49,6 +50,7 @@ export const createKitchen = ({
|
|
|
49
50
|
signal,
|
|
50
51
|
logger,
|
|
51
52
|
rootDirectoryUrl,
|
|
53
|
+
mainFilePath,
|
|
52
54
|
urlGraph,
|
|
53
55
|
dev,
|
|
54
56
|
build,
|
|
@@ -66,17 +68,34 @@ export const createKitchen = ({
|
|
|
66
68
|
outDirectoryUrl,
|
|
67
69
|
};
|
|
68
70
|
const pluginController = createPluginController(kitchenContext);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
pushPlugins(pluginEntry);
|
|
73
|
-
} else {
|
|
74
|
-
pluginController.pushPlugin(pluginEntry);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
pushPlugins(plugins);
|
|
71
|
+
plugins.forEach((pluginEntry) => {
|
|
72
|
+
pluginController.pushPlugin(pluginEntry);
|
|
73
|
+
});
|
|
79
74
|
|
|
75
|
+
/*
|
|
76
|
+
* - "http_request"
|
|
77
|
+
* - "entry_point"
|
|
78
|
+
* - "link_href"
|
|
79
|
+
* - "style"
|
|
80
|
+
* - "script"
|
|
81
|
+
* - "a_href"
|
|
82
|
+
* - "iframe_src
|
|
83
|
+
* - "img_src"
|
|
84
|
+
* - "img_srcset"
|
|
85
|
+
* - "source_src"
|
|
86
|
+
* - "source_srcset"
|
|
87
|
+
* - "image_href"
|
|
88
|
+
* - "use_href"
|
|
89
|
+
* - "css_@import"
|
|
90
|
+
* - "css_url"
|
|
91
|
+
* - "js_import"
|
|
92
|
+
* - "js_import_script"
|
|
93
|
+
* - "js_url"
|
|
94
|
+
* - "js_inline_content"
|
|
95
|
+
* - "sourcemap_comment"
|
|
96
|
+
* - "webmanifest_icon_src"
|
|
97
|
+
* - "package_json"
|
|
98
|
+
* */
|
|
80
99
|
const createReference = ({
|
|
81
100
|
data = {},
|
|
82
101
|
node,
|
|
@@ -183,18 +202,18 @@ export const createKitchen = ({
|
|
|
183
202
|
resolveReference(reference, context),
|
|
184
203
|
};
|
|
185
204
|
try {
|
|
186
|
-
let
|
|
187
|
-
"
|
|
205
|
+
let url = pluginController.callHooksUntil(
|
|
206
|
+
"resolveReference",
|
|
188
207
|
reference,
|
|
189
208
|
referenceContext,
|
|
190
209
|
);
|
|
191
|
-
if (!
|
|
210
|
+
if (!url) {
|
|
192
211
|
throw new Error(`NO_RESOLVE`);
|
|
193
212
|
}
|
|
194
|
-
if (
|
|
213
|
+
if (url.includes("?debug")) {
|
|
195
214
|
reference.debug = true;
|
|
196
215
|
}
|
|
197
|
-
|
|
216
|
+
url = normalizeUrl(url);
|
|
198
217
|
let referencedUrlObject;
|
|
199
218
|
let searchParams;
|
|
200
219
|
const onReferenceUrlChange = (referenceUrl) => {
|
|
@@ -203,7 +222,7 @@ export const createKitchen = ({
|
|
|
203
222
|
reference.url = referenceUrl;
|
|
204
223
|
reference.searchParams = searchParams;
|
|
205
224
|
};
|
|
206
|
-
onReferenceUrlChange(
|
|
225
|
+
onReferenceUrlChange(url);
|
|
207
226
|
|
|
208
227
|
if (reference.debug) {
|
|
209
228
|
logger.debug(`url resolved by "${
|
|
@@ -214,7 +233,7 @@ ${ANSI.color(reference.url, ANSI.YELLOW)}
|
|
|
214
233
|
`);
|
|
215
234
|
}
|
|
216
235
|
pluginController.callHooks(
|
|
217
|
-
"
|
|
236
|
+
"redirectReference",
|
|
218
237
|
reference,
|
|
219
238
|
referenceContext,
|
|
220
239
|
(returnValue, plugin) => {
|
|
@@ -247,7 +266,7 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
247
266
|
// But do not represent an other resource, it is considered as
|
|
248
267
|
// the same resource under the hood
|
|
249
268
|
pluginController.callHooks(
|
|
250
|
-
"
|
|
269
|
+
"transformReferenceSearchParams",
|
|
251
270
|
reference,
|
|
252
271
|
referenceContext,
|
|
253
272
|
(returnValue) => {
|
|
@@ -258,7 +277,7 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
258
277
|
},
|
|
259
278
|
);
|
|
260
279
|
const returnValue = pluginController.callHooksUntil(
|
|
261
|
-
"
|
|
280
|
+
"formatReference",
|
|
262
281
|
reference,
|
|
263
282
|
referenceContext,
|
|
264
283
|
);
|
package/src/kitchen/url_graph.js
CHANGED
|
@@ -259,7 +259,7 @@ const createUrlInfo = (url) => {
|
|
|
259
259
|
dependencies: new Set(),
|
|
260
260
|
dependents: new Set(),
|
|
261
261
|
implicitUrls: new Set(),
|
|
262
|
-
type: undefined, // "html", "css", "js_classic", "js_module", "importmap", "json", "webmanifest", ...
|
|
262
|
+
type: undefined, // "html", "css", "js_classic", "js_module", "importmap", "sourcemap", "json", "webmanifest", ...
|
|
263
263
|
subtype: undefined, // "worker", "service_worker", "shared_worker" for js, otherwise undefined
|
|
264
264
|
typeHint: undefined,
|
|
265
265
|
subtypeHint: undefined,
|
|
@@ -2,7 +2,7 @@ export const jsenvPluginHmr = () => {
|
|
|
2
2
|
return {
|
|
3
3
|
name: "jsenv:hmr",
|
|
4
4
|
appliesDuring: "dev",
|
|
5
|
-
|
|
5
|
+
redirectReference: (reference) => {
|
|
6
6
|
if (!reference.searchParams.has("hmr")) {
|
|
7
7
|
reference.data.hmr = false;
|
|
8
8
|
return null;
|
|
@@ -17,7 +17,7 @@ export const jsenvPluginHmr = () => {
|
|
|
17
17
|
urlObject.searchParams.delete("v");
|
|
18
18
|
return urlObject.href;
|
|
19
19
|
},
|
|
20
|
-
|
|
20
|
+
transformReferenceSearchParams: (reference, context) => {
|
|
21
21
|
if (reference.type === "package_json") {
|
|
22
22
|
// maybe the if above shoulb be .isImplicit but it's just a detail anyway
|
|
23
23
|
return null;
|
|
@@ -22,7 +22,7 @@ export const jsenvPluginFileUrls = ({
|
|
|
22
22
|
{
|
|
23
23
|
name: "jsenv:file_url_resolution",
|
|
24
24
|
appliesDuring: "*",
|
|
25
|
-
|
|
25
|
+
redirectReference: (reference) => {
|
|
26
26
|
// http, https, data, about, ...
|
|
27
27
|
if (!reference.url.startsWith("file:")) {
|
|
28
28
|
return null;
|
|
@@ -111,7 +111,7 @@ export const jsenvPluginFileUrls = ({
|
|
|
111
111
|
{
|
|
112
112
|
name: "jsenv:filesystem_resolution",
|
|
113
113
|
appliesDuring: "*",
|
|
114
|
-
|
|
114
|
+
resolveReference: {
|
|
115
115
|
filesystem: (reference, context) => {
|
|
116
116
|
const { parentUrl } = reference;
|
|
117
117
|
const parentUrlInfo = context.urlGraph.getUrlInfo(parentUrl);
|
|
@@ -129,14 +129,14 @@ export const jsenvPluginFileUrls = ({
|
|
|
129
129
|
// so absolute file urls needs to be relativized
|
|
130
130
|
// during build it's fine to use file:// urls
|
|
131
131
|
appliesDuring: "dev",
|
|
132
|
-
|
|
132
|
+
resolveReference: (reference) => {
|
|
133
133
|
if (reference.specifier.startsWith("/@fs/")) {
|
|
134
134
|
const fsRootRelativeUrl = reference.specifier.slice("/@fs/".length);
|
|
135
135
|
return `file:///${fsRootRelativeUrl}`;
|
|
136
136
|
}
|
|
137
137
|
return null;
|
|
138
138
|
},
|
|
139
|
-
|
|
139
|
+
formatReference: (reference, context) => {
|
|
140
140
|
if (!reference.generatedUrl.startsWith("file:")) {
|
|
141
141
|
return null;
|
|
142
142
|
}
|
|
@@ -6,7 +6,7 @@ export const jsenvPluginInlining = () => {
|
|
|
6
6
|
{
|
|
7
7
|
name: "jsenv:inlining",
|
|
8
8
|
appliesDuring: "*",
|
|
9
|
-
|
|
9
|
+
redirectReference: (reference) => {
|
|
10
10
|
const { searchParams } = reference;
|
|
11
11
|
if (searchParams.has("inline")) {
|
|
12
12
|
const urlObject = new URL(reference.url);
|
|
@@ -4,7 +4,7 @@ export const jsenvPluginInliningAsDataUrl = () => {
|
|
|
4
4
|
return {
|
|
5
5
|
name: "jsenv:inlining_as_data_url",
|
|
6
6
|
appliesDuring: "*",
|
|
7
|
-
|
|
7
|
+
formatReference: {
|
|
8
8
|
// if the referenced url is a worker we could use
|
|
9
9
|
// https://www.oreilly.com/library/view/web-workers/9781449322120/ch04.html
|
|
10
10
|
// but maybe we should rather use ?object_url
|
|
@@ -34,10 +34,21 @@ export const jsenvPluginInliningAsDataUrl = () => {
|
|
|
34
34
|
return (async () => {
|
|
35
35
|
const urlInfo = context.urlGraph.getUrlInfo(reference.url);
|
|
36
36
|
await context.cook(urlInfo, { reference });
|
|
37
|
+
const contentAsBase64 = Buffer.from(urlInfo.content).toString(
|
|
38
|
+
"base64",
|
|
39
|
+
);
|
|
37
40
|
const specifier = DATA_URL.stringify({
|
|
38
41
|
mediaType: urlInfo.contentType,
|
|
39
42
|
base64Flag: true,
|
|
40
|
-
data:
|
|
43
|
+
data: contentAsBase64,
|
|
44
|
+
});
|
|
45
|
+
context.referenceUtils.becomesInline(reference, {
|
|
46
|
+
line: reference.line,
|
|
47
|
+
column: reference.column,
|
|
48
|
+
isOriginal: reference.isOriginal,
|
|
49
|
+
specifier,
|
|
50
|
+
content: contentAsBase64,
|
|
51
|
+
contentType: urlInfo.contentType,
|
|
41
52
|
});
|
|
42
53
|
return specifier;
|
|
43
54
|
})();
|