@jsenv/core 41.0.2 → 41.0.4

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.
@@ -10,7 +10,7 @@ import { generateSourcemapFileUrl, createMagicSource, composeTwoSourcemaps, gene
10
10
  import { createPluginsController } from "@jsenv/server/src/plugins_controller.js";
11
11
  import { jsenvPluginSupervisor } from "@jsenv/plugin-supervisor";
12
12
  import { WebSocketResponse, pickContentType } from "@jsenv/server";
13
- import { randomUUID, createHash } from "node:crypto";
13
+ import { createHash } from "node:crypto";
14
14
  import "./jsenv_core_node_modules.js";
15
15
  import "node:os";
16
16
  import "node:tty";
@@ -8823,47 +8823,6 @@ const jsenvPluginCleanHTML = () => {
8823
8823
  };
8824
8824
  };
8825
8825
 
8826
- /**
8827
- * https://docs.google.com/document/d/1rfKPnxsNuXhnF7AiQZhu9kIwdiMS5hnAI05HBwFuBSM/edit?tab=t.0#heading=h.7nki9mck5t64
8828
- * https://chromium.googlesource.com/devtools/devtools-frontend/+/main/docs/ecosystem/automatic_workspace_folders.md
8829
- * https://github.com/ChromeDevTools/vite-plugin-devtools-json
8830
- */
8831
-
8832
-
8833
- const jsenvPluginChromeDevtoolsJson = () => {
8834
- const getOrCreateUUID = (kitchen) => {
8835
- const { outDirectoryUrl } = kitchen.context;
8836
- const uuidFileUrl = new URL("./uuid.json", outDirectoryUrl);
8837
- if (existsSync(uuidFileUrl)) {
8838
- const { uuid } = JSON.parse(readFileSync(uuidFileUrl, "utf8"));
8839
- return uuid;
8840
- }
8841
- const uuid = randomUUID();
8842
- writeFileSync(uuidFileUrl, JSON.stringify({ uuid }), { });
8843
- return uuid;
8844
- };
8845
-
8846
- return {
8847
- name: "jsenv_plugin_chrome_devtools_json",
8848
- appliesDuring: "dev",
8849
- serverRoutes: [
8850
- {
8851
- endpoint: "GET /.well-known/appspecific/com.chrome.devtools.json",
8852
- declarationSource: import.meta.url,
8853
- fetch: (request, { kitchen }) => {
8854
- const { rootDirectoryUrl } = kitchen.context;
8855
- return Response.json({
8856
- workspace: {
8857
- root: urlToFileSystemPath(rootDirectoryUrl),
8858
- uuid: getOrCreateUUID(kitchen),
8859
- },
8860
- });
8861
- },
8862
- },
8863
- ],
8864
- };
8865
- };
8866
-
8867
8826
  const jsenvPluginAutoreloadOnServerRestart = () => {
8868
8827
  const autoreloadOnRestartClientFileUrl = import.meta
8869
8828
  .resolve("@jsenv/server/src/plugins/autoreload_on_server_restart/client/autoreload_on_server_restart.js");
@@ -9308,7 +9267,6 @@ const getCorePlugins = ({
9308
9267
  ...(ribbon ? [jsenvPluginRibbon({ rootDirectoryUrl, ...ribbon })] : []),
9309
9268
  ...(dropToOpen ? [jsenvPluginDropToOpen()] : []),
9310
9269
  jsenvPluginCleanHTML(),
9311
- jsenvPluginChromeDevtoolsJson(),
9312
9270
  ...(packageSideEffects
9313
9271
  ? [jsenvPluginPackageSideEffects({ packageDirectory })]
9314
9272
  : []),
@@ -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
- const transformUrlPathname = (url, transformer) => {
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, serverPluginStaticFiles, serverPluginErrorHandler } from "@jsenv/server";
2
- import { existsSync } from "node:fs";
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;
@@ -34,7 +32,7 @@ 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,55 +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 (buildDirectoryMainFileRelativeUrl) {
66
- if (typeof buildDirectoryMainFileRelativeUrl !== "string") {
67
- throw new TypeError(
68
- `buildDirectoryMainFileRelativeUrl must be a string, got ${buildDirectoryMainFileRelativeUrl}`,
69
- );
70
- }
71
- if (buildDirectoryMainFileRelativeUrl[0] === "/") {
72
- buildDirectoryMainFileRelativeUrl =
73
- buildDirectoryMainFileRelativeUrl.slice(1);
74
- } else {
75
- const buildMainFileUrl = new URL(
76
- buildDirectoryMainFileRelativeUrl,
77
- buildDirectoryUrl,
78
- ).href;
79
- if (!buildMainFileUrl.startsWith(buildDirectoryUrl)) {
80
- throw new Error(
81
- `buildDirectoryMainFileRelativeUrl must be relative, got ${buildDirectoryMainFileRelativeUrl}`,
82
- );
83
- }
84
- buildDirectoryMainFileRelativeUrl = buildMainFileUrl.slice(
85
- buildDirectoryUrl.length,
86
- );
87
- }
88
- if (
89
- !existsSync(
90
- new URL(buildDirectoryMainFileRelativeUrl, buildDirectoryUrl),
91
- )
92
- ) {
93
- buildDirectoryMainFileRelativeUrl = null;
94
- }
95
- }
96
- }
97
-
98
48
  const logger = createLogger({ logLevel });
99
49
  const operation = Abort.startOperation();
100
50
  operation.addAbortSignal(signal);
@@ -127,7 +77,6 @@ const startBuildServer = async ({
127
77
  port,
128
78
  serverTiming: true,
129
79
  requestWaitingMs: 60_000,
130
- routes,
131
80
  plugins: [
132
81
  serverPluginCORS({
133
82
  accessControlAllowRequestOrigin: true,
@@ -138,15 +87,20 @@ const startBuildServer = async ({
138
87
  timingAllowOrigin: true,
139
88
  }),
140
89
  ...serverPlugins,
141
- serverPluginStaticFiles({
142
- serverRelativeUrl: "/",
143
- directoryUrl: buildDirectoryUrl,
144
- directoryMainFileRelativeUrl: buildDirectoryMainFileRelativeUrl,
145
- }),
146
90
  serverPluginErrorHandler({
147
91
  sendErrorDetails: false,
148
92
  }),
149
93
  ],
94
+ routes: [
95
+ ...routes,
96
+ {
97
+ endpoint: "GET /",
98
+ description: "Serve build files",
99
+ fetch: createFileSystemFetch(buildDirectoryUrl, {
100
+ mainFileRelativeUrl: buildDirectoryMainFileRelativeUrl,
101
+ }),
102
+ },
103
+ ],
150
104
  });
151
105
  startBuildServerTask.done();
152
106
  if (hostname) {