@jsenv/core 41.0.1 → 41.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.
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createSupportsColor, isUnicodeSupported, emojiRegex, eastAsianWidth, clearTerminal, eraseLines } from "./jsenv_core_node_modules.js";
|
|
2
2
|
import { stripVTControlCharacters } from "node:util";
|
|
3
|
-
import { pathToFileURL } from "node:url";
|
|
4
3
|
|
|
5
4
|
const createCallbackListNotifiedOnce = () => {
|
|
6
5
|
let callbacks = [];
|
|
@@ -1394,116 +1393,4 @@ const createTaskLog = (
|
|
|
1394
1393
|
};
|
|
1395
1394
|
};
|
|
1396
1395
|
|
|
1397
|
-
|
|
1398
|
-
if (typeof url === "string") {
|
|
1399
|
-
const urlObject = new URL(url);
|
|
1400
|
-
const { pathname } = urlObject;
|
|
1401
|
-
const pathnameTransformed = transformer(pathname);
|
|
1402
|
-
if (pathnameTransformed === pathname) {
|
|
1403
|
-
return url;
|
|
1404
|
-
}
|
|
1405
|
-
let { origin } = urlObject;
|
|
1406
|
-
// origin is "null" for "file://" urls with Node.js
|
|
1407
|
-
if (origin === "null" && urlObject.href.startsWith("file:")) {
|
|
1408
|
-
origin = "file://";
|
|
1409
|
-
}
|
|
1410
|
-
const { search, hash } = urlObject;
|
|
1411
|
-
const urlWithPathnameTransformed = `${origin}${pathnameTransformed}${search}${hash}`;
|
|
1412
|
-
return urlWithPathnameTransformed;
|
|
1413
|
-
}
|
|
1414
|
-
const pathnameTransformed = transformer(url.pathname);
|
|
1415
|
-
url.pathname = pathnameTransformed;
|
|
1416
|
-
return url;
|
|
1417
|
-
};
|
|
1418
|
-
const ensurePathnameTrailingSlash = (url) => {
|
|
1419
|
-
return transformUrlPathname(url, (pathname) => {
|
|
1420
|
-
return pathname.endsWith("/") ? pathname : `${pathname}/`;
|
|
1421
|
-
});
|
|
1422
|
-
};
|
|
1423
|
-
|
|
1424
|
-
const isFileSystemPath = (value) => {
|
|
1425
|
-
if (typeof value !== "string") {
|
|
1426
|
-
throw new TypeError(
|
|
1427
|
-
`isFileSystemPath first arg must be a string, got ${value}`,
|
|
1428
|
-
);
|
|
1429
|
-
}
|
|
1430
|
-
if (value[0] === "/") {
|
|
1431
|
-
return true;
|
|
1432
|
-
}
|
|
1433
|
-
return startsWithWindowsDriveLetter(value);
|
|
1434
|
-
};
|
|
1435
|
-
|
|
1436
|
-
const startsWithWindowsDriveLetter = (string) => {
|
|
1437
|
-
const firstChar = string[0];
|
|
1438
|
-
if (!/[a-zA-Z]/.test(firstChar)) return false;
|
|
1439
|
-
|
|
1440
|
-
const secondChar = string[1];
|
|
1441
|
-
if (secondChar !== ":") return false;
|
|
1442
|
-
|
|
1443
|
-
return true;
|
|
1444
|
-
};
|
|
1445
|
-
|
|
1446
|
-
const fileSystemPathToUrl = (value) => {
|
|
1447
|
-
if (!isFileSystemPath(value)) {
|
|
1448
|
-
throw new Error(`value must be a filesystem path, got ${value}`);
|
|
1449
|
-
}
|
|
1450
|
-
return String(pathToFileURL(value));
|
|
1451
|
-
};
|
|
1452
|
-
|
|
1453
|
-
const validateDirectoryUrl = (value) => {
|
|
1454
|
-
let urlString;
|
|
1455
|
-
|
|
1456
|
-
if (value instanceof URL) {
|
|
1457
|
-
urlString = value.href;
|
|
1458
|
-
} else if (typeof value === "string") {
|
|
1459
|
-
if (isFileSystemPath(value)) {
|
|
1460
|
-
urlString = fileSystemPathToUrl(value);
|
|
1461
|
-
} else {
|
|
1462
|
-
try {
|
|
1463
|
-
urlString = String(new URL(value));
|
|
1464
|
-
} catch {
|
|
1465
|
-
return {
|
|
1466
|
-
valid: false,
|
|
1467
|
-
value,
|
|
1468
|
-
message: `must be a valid url`,
|
|
1469
|
-
};
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
} else if (
|
|
1473
|
-
value &&
|
|
1474
|
-
typeof value === "object" &&
|
|
1475
|
-
typeof value.href === "string"
|
|
1476
|
-
) {
|
|
1477
|
-
value = value.href;
|
|
1478
|
-
} else {
|
|
1479
|
-
return {
|
|
1480
|
-
valid: false,
|
|
1481
|
-
value,
|
|
1482
|
-
message: `must be a string or an url`,
|
|
1483
|
-
};
|
|
1484
|
-
}
|
|
1485
|
-
if (!urlString.startsWith("file://")) {
|
|
1486
|
-
return {
|
|
1487
|
-
valid: false,
|
|
1488
|
-
value,
|
|
1489
|
-
message: 'must start with "file://"',
|
|
1490
|
-
};
|
|
1491
|
-
}
|
|
1492
|
-
return {
|
|
1493
|
-
valid: true,
|
|
1494
|
-
value: ensurePathnameTrailingSlash(urlString),
|
|
1495
|
-
};
|
|
1496
|
-
};
|
|
1497
|
-
|
|
1498
|
-
const assertAndNormalizeDirectoryUrl = (
|
|
1499
|
-
directoryUrl,
|
|
1500
|
-
name = "directoryUrl",
|
|
1501
|
-
) => {
|
|
1502
|
-
const { valid, message, value } = validateDirectoryUrl(directoryUrl);
|
|
1503
|
-
if (!valid) {
|
|
1504
|
-
throw new TypeError(`${name} ${message}, got ${value}`);
|
|
1505
|
-
}
|
|
1506
|
-
return value;
|
|
1507
|
-
};
|
|
1508
|
-
|
|
1509
|
-
export { Abort, assertAndNormalizeDirectoryUrl, createLogger, createTaskLog, raceProcessTeardownEvents };
|
|
1396
|
+
export { Abort, createLogger, createTaskLog, raceProcessTeardownEvents };
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { startServer, serverPluginCORS, jsenvAccessControlAllowedHeaders,
|
|
2
|
-
import {
|
|
3
|
-
import { assertAndNormalizeDirectoryUrl, createLogger, Abort, raceProcessTeardownEvents, createTaskLog } from "./jsenv_core_packages.js";
|
|
1
|
+
import { startServer, createFileSystemFetch, serverPluginCORS, jsenvAccessControlAllowedHeaders, serverPluginErrorHandler } from "@jsenv/server";
|
|
2
|
+
import { createLogger, Abort, raceProcessTeardownEvents, createTaskLog } from "./jsenv_core_packages.js";
|
|
4
3
|
import "./jsenv_core_node_modules.js";
|
|
5
4
|
import "node:process";
|
|
6
5
|
import "node:os";
|
|
7
6
|
import "node:tty";
|
|
8
7
|
import "node:util";
|
|
9
|
-
import "node:url";
|
|
10
8
|
|
|
11
9
|
/*
|
|
12
10
|
* startBuildServer is mean to interact with the build files;
|
|
@@ -32,9 +30,9 @@ import "node:url";
|
|
|
32
30
|
*/
|
|
33
31
|
const startBuildServer = async ({
|
|
34
32
|
buildDirectoryUrl,
|
|
35
|
-
|
|
33
|
+
buildDirectoryMainFileRelativeUrl = "index.html",
|
|
36
34
|
port = 9779,
|
|
37
|
-
routes,
|
|
35
|
+
routes = [],
|
|
38
36
|
serverPlugins = [],
|
|
39
37
|
acceptAnyIp,
|
|
40
38
|
hostname,
|
|
@@ -46,46 +44,7 @@ const startBuildServer = async ({
|
|
|
46
44
|
signal = new AbortController().signal,
|
|
47
45
|
handleSIGINT = true,
|
|
48
46
|
keepProcessAlive = true,
|
|
49
|
-
|
|
50
|
-
...rest
|
|
51
47
|
}) => {
|
|
52
|
-
// params validation
|
|
53
|
-
{
|
|
54
|
-
const unexpectedParamNames = Object.keys(rest);
|
|
55
|
-
if (unexpectedParamNames.length > 0) {
|
|
56
|
-
throw new TypeError(
|
|
57
|
-
`${unexpectedParamNames.join(",")}: there is no such param`,
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
buildDirectoryUrl = assertAndNormalizeDirectoryUrl(
|
|
61
|
-
buildDirectoryUrl,
|
|
62
|
-
"buildDirectoryUrl",
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
if (buildMainFilePath) {
|
|
66
|
-
if (typeof buildMainFilePath !== "string") {
|
|
67
|
-
throw new TypeError(
|
|
68
|
-
`buildMainFilePath must be a string, got ${buildMainFilePath}`,
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
if (buildMainFilePath[0] === "/") {
|
|
72
|
-
buildMainFilePath = buildMainFilePath.slice(1);
|
|
73
|
-
} else {
|
|
74
|
-
const buildMainFileUrl = new URL(buildMainFilePath, buildDirectoryUrl)
|
|
75
|
-
.href;
|
|
76
|
-
if (!buildMainFileUrl.startsWith(buildDirectoryUrl)) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
`buildMainFilePath must be relative, got ${buildMainFilePath}`,
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
buildMainFilePath = buildMainFileUrl.slice(buildDirectoryUrl.length);
|
|
82
|
-
}
|
|
83
|
-
if (!existsSync(new URL(buildMainFilePath, buildDirectoryUrl))) {
|
|
84
|
-
buildMainFilePath = null;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
48
|
const logger = createLogger({ logLevel });
|
|
90
49
|
const operation = Abort.startOperation();
|
|
91
50
|
operation.addAbortSignal(signal);
|
|
@@ -118,7 +77,6 @@ const startBuildServer = async ({
|
|
|
118
77
|
port,
|
|
119
78
|
serverTiming: true,
|
|
120
79
|
requestWaitingMs: 60_000,
|
|
121
|
-
routes,
|
|
122
80
|
plugins: [
|
|
123
81
|
serverPluginCORS({
|
|
124
82
|
accessControlAllowRequestOrigin: true,
|
|
@@ -129,14 +87,20 @@ const startBuildServer = async ({
|
|
|
129
87
|
timingAllowOrigin: true,
|
|
130
88
|
}),
|
|
131
89
|
...serverPlugins,
|
|
132
|
-
serverPluginStaticFiles({
|
|
133
|
-
directoryUrl: buildDirectoryUrl,
|
|
134
|
-
mainFilePath: buildMainFilePath,
|
|
135
|
-
}),
|
|
136
90
|
serverPluginErrorHandler({
|
|
137
91
|
sendErrorDetails: false,
|
|
138
92
|
}),
|
|
139
93
|
],
|
|
94
|
+
routes: [
|
|
95
|
+
...routes,
|
|
96
|
+
{
|
|
97
|
+
endpoint: "GET /",
|
|
98
|
+
description: "Serve build files",
|
|
99
|
+
fetch: createFileSystemFetch(buildDirectoryUrl, {
|
|
100
|
+
mainFileRelativeUrl: buildDirectoryMainFileRelativeUrl,
|
|
101
|
+
}),
|
|
102
|
+
},
|
|
103
|
+
],
|
|
140
104
|
});
|
|
141
105
|
startBuildServerTask.done();
|
|
142
106
|
if (hostname) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WebSocketResponse, pickContentType, ServerEvents, serverPluginCORS, jsenvAccessControlAllowedHeaders, composeTwoResponses,
|
|
1
|
+
import { WebSocketResponse, pickContentType, ServerEvents, serverPluginCORS, jsenvAccessControlAllowedHeaders, composeTwoResponses, fetchDirectory, serverPluginErrorHandler, startServer } from "@jsenv/server";
|
|
2
2
|
import { convertFileSystemErrorToResponseProperties } from "@jsenv/server/src/plugins/filesystem/filesystem_error_to_response.js";
|
|
3
3
|
import { lookupPackageDirectory, registerDirectoryLifecycle, urlToRelativeUrl, moveUrl, urlIsOrIsInsideOf, ensureWindowsDriveLetter, createDetailedMessage, stringifyUrlSite, generateContentFrame, validateResponseIntegrity, setUrlFilename, getCallerPosition, urlToBasename, urlToExtension, asSpecifierWithoutSearch, asUrlWithoutSearch, injectQueryParamsIntoSpecifier, bufferToEtag, isFileSystemPath, urlToPathname, setUrlBasename, urlToFileSystemPath, writeFileSync, createLogger, URL_META, applyNodeEsmResolution, normalizeUrl, ANSI, RUNTIME_COMPAT, CONTENT_TYPE, readPackageAtOrNull, errorToHTML, DATA_URL, normalizeImportMap, composeTwoImportMaps, resolveImport, JS_QUOTES, readCustomConditionsFromProcessArgs, readEntryStatSync, ensurePathnameTrailingSlash, compareFileUrls, urlToFilename, applyFileSystemMagicResolution, getExtensionsToTry, setUrlExtension, isSpecifierForNodeBuiltin, injectQueryParams, memoizeByFirstArgument, assertAndNormalizeDirectoryUrl, createTaskLog, formatError } from "./jsenv_core_packages.js";
|
|
4
4
|
import { readFileSync, existsSync, readdirSync, lstatSync, realpathSync } from "node:fs";
|
|
@@ -10041,7 +10041,7 @@ const startDevServer = async ({
|
|
|
10041
10041
|
};
|
|
10042
10042
|
}
|
|
10043
10043
|
if (code === "DIRECTORY_REFERENCE_NOT_ALLOWED") {
|
|
10044
|
-
return
|
|
10044
|
+
return fetchDirectory(reference.url, {
|
|
10045
10045
|
headers: {
|
|
10046
10046
|
accept: "text/html",
|
|
10047
10047
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "41.0.
|
|
3
|
+
"version": "41.0.3",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"@jsenv/plugin-minification": "1.7.3",
|
|
82
82
|
"@jsenv/plugin-supervisor": "1.7.15",
|
|
83
83
|
"@jsenv/plugin-transpilation": "1.5.70",
|
|
84
|
-
"@jsenv/server": "17.0.
|
|
84
|
+
"@jsenv/server": "17.0.2",
|
|
85
85
|
"@jsenv/sourcemap": "1.3.17",
|
|
86
86
|
"react-table": "7.8.0"
|
|
87
87
|
},
|
|
@@ -14,16 +14,14 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { Abort, raceProcessTeardownEvents } from "@jsenv/abort";
|
|
17
|
-
import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem";
|
|
18
17
|
import { createLogger, createTaskLog } from "@jsenv/humanize";
|
|
19
18
|
import {
|
|
19
|
+
createFileSystemFetch,
|
|
20
20
|
jsenvAccessControlAllowedHeaders,
|
|
21
21
|
serverPluginCORS,
|
|
22
22
|
serverPluginErrorHandler,
|
|
23
|
-
serverPluginStaticFiles,
|
|
24
23
|
startServer,
|
|
25
24
|
} from "@jsenv/server";
|
|
26
|
-
import { existsSync } from "node:fs";
|
|
27
25
|
|
|
28
26
|
/**
|
|
29
27
|
* Start a server for build files.
|
|
@@ -33,9 +31,9 @@ import { existsSync } from "node:fs";
|
|
|
33
31
|
*/
|
|
34
32
|
export const startBuildServer = async ({
|
|
35
33
|
buildDirectoryUrl,
|
|
36
|
-
|
|
34
|
+
buildDirectoryMainFileRelativeUrl = "index.html",
|
|
37
35
|
port = 9779,
|
|
38
|
-
routes,
|
|
36
|
+
routes = [],
|
|
39
37
|
serverPlugins = [],
|
|
40
38
|
acceptAnyIp,
|
|
41
39
|
hostname,
|
|
@@ -47,46 +45,7 @@ export const startBuildServer = async ({
|
|
|
47
45
|
signal = new AbortController().signal,
|
|
48
46
|
handleSIGINT = true,
|
|
49
47
|
keepProcessAlive = true,
|
|
50
|
-
|
|
51
|
-
...rest
|
|
52
48
|
}) => {
|
|
53
|
-
// params validation
|
|
54
|
-
{
|
|
55
|
-
const unexpectedParamNames = Object.keys(rest);
|
|
56
|
-
if (unexpectedParamNames.length > 0) {
|
|
57
|
-
throw new TypeError(
|
|
58
|
-
`${unexpectedParamNames.join(",")}: there is no such param`,
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
buildDirectoryUrl = assertAndNormalizeDirectoryUrl(
|
|
62
|
-
buildDirectoryUrl,
|
|
63
|
-
"buildDirectoryUrl",
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
if (buildMainFilePath) {
|
|
67
|
-
if (typeof buildMainFilePath !== "string") {
|
|
68
|
-
throw new TypeError(
|
|
69
|
-
`buildMainFilePath must be a string, got ${buildMainFilePath}`,
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
if (buildMainFilePath[0] === "/") {
|
|
73
|
-
buildMainFilePath = buildMainFilePath.slice(1);
|
|
74
|
-
} else {
|
|
75
|
-
const buildMainFileUrl = new URL(buildMainFilePath, buildDirectoryUrl)
|
|
76
|
-
.href;
|
|
77
|
-
if (!buildMainFileUrl.startsWith(buildDirectoryUrl)) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
`buildMainFilePath must be relative, got ${buildMainFilePath}`,
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
buildMainFilePath = buildMainFileUrl.slice(buildDirectoryUrl.length);
|
|
83
|
-
}
|
|
84
|
-
if (!existsSync(new URL(buildMainFilePath, buildDirectoryUrl))) {
|
|
85
|
-
buildMainFilePath = null;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
49
|
const logger = createLogger({ logLevel });
|
|
91
50
|
const operation = Abort.startOperation();
|
|
92
51
|
operation.addAbortSignal(signal);
|
|
@@ -120,7 +79,6 @@ export const startBuildServer = async ({
|
|
|
120
79
|
port,
|
|
121
80
|
serverTiming: true,
|
|
122
81
|
requestWaitingMs: 60_000,
|
|
123
|
-
routes,
|
|
124
82
|
plugins: [
|
|
125
83
|
serverPluginCORS({
|
|
126
84
|
accessControlAllowRequestOrigin: true,
|
|
@@ -131,14 +89,20 @@ export const startBuildServer = async ({
|
|
|
131
89
|
timingAllowOrigin: true,
|
|
132
90
|
}),
|
|
133
91
|
...serverPlugins,
|
|
134
|
-
serverPluginStaticFiles({
|
|
135
|
-
directoryUrl: buildDirectoryUrl,
|
|
136
|
-
mainFilePath: buildMainFilePath,
|
|
137
|
-
}),
|
|
138
92
|
serverPluginErrorHandler({
|
|
139
93
|
sendErrorDetails: false,
|
|
140
94
|
}),
|
|
141
95
|
],
|
|
96
|
+
routes: [
|
|
97
|
+
...routes,
|
|
98
|
+
{
|
|
99
|
+
endpoint: "GET /",
|
|
100
|
+
description: "Serve build files",
|
|
101
|
+
fetch: createFileSystemFetch(buildDirectoryUrl, {
|
|
102
|
+
mainFileRelativeUrl: buildDirectoryMainFileRelativeUrl,
|
|
103
|
+
}),
|
|
104
|
+
},
|
|
105
|
+
],
|
|
142
106
|
});
|
|
143
107
|
startBuildServerTask.done();
|
|
144
108
|
if (hostname) {
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
import { createLogger, createTaskLog, formatError } from "@jsenv/humanize";
|
|
7
7
|
import {
|
|
8
8
|
composeTwoResponses,
|
|
9
|
+
fetchDirectory,
|
|
9
10
|
jsenvAccessControlAllowedHeaders,
|
|
10
|
-
serveDirectory,
|
|
11
11
|
serverPluginCORS,
|
|
12
12
|
serverPluginErrorHandler,
|
|
13
13
|
startServer,
|
|
@@ -595,7 +595,7 @@ export const startDevServer = async ({
|
|
|
595
595
|
};
|
|
596
596
|
}
|
|
597
597
|
if (code === "DIRECTORY_REFERENCE_NOT_ALLOWED") {
|
|
598
|
-
return
|
|
598
|
+
return fetchDirectory(reference.url, {
|
|
599
599
|
headers: {
|
|
600
600
|
accept: "text/html",
|
|
601
601
|
},
|