@noverax/courier-build 0.4.0 → 0.5.0

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,10 +1,10 @@
1
1
  import { t as RoutesReadError } from "../routes-read-error-DQhKIE2F.js";
2
2
  import { n as isRecord } from "../errno-code-CNx_E80R.js";
3
3
  import { t as workerMessages } from "../worker-messages-BT2vvNQJ.js";
4
- import { a as projectTransformCache, c as UntrustedConfigError, f as configCandidates, i as loadCourierConfigFile, t as findConfigFile } from "../load-config-BeedbpkN.js";
4
+ import { T as configCandidates, a as projectTransformCache, c as UntrustedConfigError, d as configLoadError, h as localPath, i as loadCourierConfigFile, p as maskedError, t as findConfigFile } from "../load-config-barNPfXN.js";
5
5
  import * as nodeModule from "node:module";
6
6
  import { createRequire, syncBuiltinESMExports } from "node:module";
7
- import { basename, dirname, isAbsolute, resolve, sep } from "node:path";
7
+ import { basename, dirname, isAbsolute, sep } from "node:path";
8
8
  import { existsSync, readFileSync } from "node:fs";
9
9
  import { fileURLToPath, pathToFileURL } from "node:url";
10
10
  import { parseEnv } from "node:util";
@@ -98,10 +98,12 @@ async function loadProjectConfig(configFile, request, options) {
98
98
  transformCache
99
99
  });
100
100
  } catch (error) {
101
- throw new RoutesReadError("CONFIG_NOT_LOADED", `${basename(configFile)} did not load, so the routes a page takes were not read: ${error instanceof Error ? error.message : String(error)}`, {
101
+ const failure = configLoadError(error, { entry: configFile });
102
+ const message = `${basename(configFile)} did not load, so the routes a page takes were not read: ${failure.message} ${failure.hint}`;
103
+ throw new RoutesReadError("CONFIG_NOT_LOADED", message, {
102
104
  root: request.root,
103
105
  configFile
104
- }, { stack: error instanceof Error ? error.stack : void 0 });
106
+ }, { stack: failure.cause instanceof Error ? failure.cause.stack : void 0 });
105
107
  }
106
108
  }
107
109
  // src/engine/read-env-files.ts
@@ -132,27 +134,39 @@ function parsedFrom(files) {
132
134
  for (const file of files) for (const [key, value] of Object.entries(parseEnv(readFileSync(file, "utf8")))) if (value !== void 0 && !(key in parsed)) parsed[key] = value;
133
135
  return parsed;
134
136
  }
135
- // src/util/local-path.ts
136
- const NAMESPACE = "\\\\?\\";
137
- const SHARE_NAMESPACE = "\\\\?\\UNC\\";
137
+ // src/engine/reading-failure.ts
138
138
  /**
139
- * A path as this system names it: absolute, written with its own
140
- * separator, `.` and `..` resolved, and on Windows out of the namespace
141
- * `path.toNamespacedPath` writes it in (`\\?\D:\app` is `D:\app`). The code
142
- * a reading runs may name one file in any of these ways; a watcher reports
143
- * it in this one.
139
+ * Why a reading of the routes failed, as a `RoutesReadError` whatever it
140
+ * threw. The engine's own failure is kept as it is, its text the engine's
141
+ * words and what the loader quoted of the project, masked already. Anything
142
+ * else came from the project's code, a getter of its config or a source the
143
+ * core read, and is `CONFIG_NOT_LOADED`, its text and stack with no secret
144
+ * left in them: a bundler prints them, shows them on the page, and a CI
145
+ * log, which may be public, keeps them.
144
146
  *
145
- * @param path - The path, absolute or from the working folder
146
- * @returns The path
147
+ * @param thrown - What the reading threw
148
+ * @param context - The project's root, and the config file once found
149
+ * @param inputs - What the reading had read, for a failure that names none yet
150
+ * @returns The failure
147
151
  * @example
148
152
  * ```ts
149
- * localPath("/app/src/../flags.json"); // "/app/flags.json"
153
+ * readingFailure(new Error(`bad ${process.env.API_KEY}`), { root: "/app" }).message;
154
+ * // → "The routes a page takes were not read: bad [redacted]"
150
155
  * ```
151
156
  */
152
- function localPath(path) {
153
- if (sep === "\\" && path.startsWith(SHARE_NAMESPACE)) return resolve(`\\\\${path.slice(8)}`);
154
- if (sep === "\\" && path.startsWith(NAMESPACE)) return resolve(path.slice(4));
155
- return resolve(path);
157
+ function readingFailure(thrown, context, inputs) {
158
+ if (thrown instanceof RoutesReadError) {
159
+ if (thrown.inputs !== void 0 || inputs === void 0) return thrown;
160
+ return new RoutesReadError(thrown.code, thrown.message, thrown.context, {
161
+ stack: thrown.stack,
162
+ inputs
163
+ });
164
+ }
165
+ const masked = maskedError(thrown);
166
+ return new RoutesReadError("CONFIG_NOT_LOADED", `The routes a page takes were not read: ${masked.message}`, context, {
167
+ stack: thrown instanceof Error ? masked.stack : void 0,
168
+ inputs
169
+ });
156
170
  }
157
171
  // src/engine/track-env-reads.ts
158
172
  /**
@@ -468,7 +482,11 @@ async function readProjectRoutes(request) {
468
482
  routes
469
483
  };
470
484
  } catch (error) {
471
- throw withInputs(error, await reading.inputs(), request);
485
+ const inputs = await reading.inputs();
486
+ throw readingFailure(error, {
487
+ root: request.root,
488
+ configFile: inputs.configFile
489
+ }, inputs);
472
490
  }
473
491
  }
474
492
  async function routesOfSources(loaded, root) {
@@ -495,21 +513,6 @@ async function projectRoutesOf(configFile, root) {
495
513
  configFile
496
514
  });
497
515
  }
498
- function withInputs(error, inputs, request) {
499
- const stack = error instanceof Error ? error.stack : void 0;
500
- if (!(error instanceof RoutesReadError)) return new RoutesReadError("CONFIG_NOT_LOADED", `The routes a page takes were not read: ${error instanceof Error ? error.message : String(error)}`, {
501
- root: request.root,
502
- configFile: inputs.configFile
503
- }, {
504
- stack,
505
- inputs
506
- });
507
- if (error.inputs !== void 0) return error;
508
- return new RoutesReadError(error.code, error.message, error.context, {
509
- stack,
510
- inputs
511
- });
512
- }
513
516
  function byCodeUnits(a, b) {
514
517
  return a < b ? -1 : a > b ? 1 : 0;
515
518
  }
@@ -529,23 +532,17 @@ async function answer(request) {
529
532
  process.send?.(workerMessages.reply(reply), () => process.exit(0));
530
533
  }
531
534
  function failure(error, request) {
532
- if (error instanceof RoutesReadError) return {
533
- ok: false,
534
- code: error.code,
535
- message: error.message,
536
- context: error.context,
537
- stack: error.stack,
538
- inputs: error.inputs
539
- };
535
+ const failed = readingFailure(error, {
536
+ root: request.root,
537
+ configFile: request.configFile
538
+ });
540
539
  return {
541
540
  ok: false,
542
- code: "CONFIG_NOT_LOADED",
543
- message: `The routes a page takes were not read: ${error instanceof Error ? error.message : String(error)}`,
544
- context: {
545
- root: request.root,
546
- configFile: request.configFile
547
- },
548
- stack: error instanceof Error ? error.stack : void 0
541
+ code: failed.code,
542
+ message: failed.message,
543
+ context: failed.context,
544
+ stack: failed.stack,
545
+ inputs: failed.inputs
549
546
  };
550
547
  }
551
548
  export {};
@@ -1,11 +1,11 @@
1
1
  import { t as RoutesReadError } from "../routes-read-error-DQhKIE2F.js";
2
- import { n as routesModuleCode } from "../routes-module-code-DO3aII6v.js";
2
+ import { n as routesModuleCode } from "../routes-module-code-DYtP7uj1.js";
3
3
  import { t as configInPageMessage } from "../config-in-page-message-DLd3f0Jd.js";
4
- import { d as CONFIG_BASENAMES } from "../load-config-BeedbpkN.js";
5
- import { t as sharedEngine } from "../shared-engine-CCu7vP_0.js";
6
- import { t as configFileOf } from "../config-file-of-Zkwyi9zf.js";
4
+ import { w as CONFIG_BASENAMES } from "../load-config-barNPfXN.js";
5
+ import { t as sharedEngine } from "../shared-engine-D0j7uXg8.js";
6
+ import { t as configFileOf } from "../config-file-of-Clf_dWUQ.js";
7
7
  import { n as ROUTES_PATTERN, r as ROUTES_SPECIFIER } from "../routes-module-id-CnUjQjYF.js";
8
- import { t as routesFile } from "../routes-file-DcpgxYb1.js";
8
+ import { t as routesFile } from "../routes-file-DRoqUZ0S.js";
9
9
  import { basename, extname } from "node:path";
10
10
  // src/esbuild/config-in-page.ts
11
11
  const RESOLVING = "@noverax/courier-build:resolving-config";
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { t as RoutesReadError } from "./routes-read-error-DQhKIE2F.js";
2
- import { i as createRoutesEngine, n as routesModuleCode, r as unreadRoutesModuleCode, t as routesCommonJsCode } from "./routes-module-code-DO3aII6v.js";
2
+ import { i as createRoutesEngine, n as routesModuleCode, r as unreadRoutesModuleCode, t as routesCommonJsCode } from "./routes-module-code-DYtP7uj1.js";
3
3
  import { t as configInPageMessage } from "./config-in-page-message-DLd3f0Jd.js";
4
4
  export { RoutesReadError, configInPageMessage, createRoutesEngine, routesCommonJsCode, routesModuleCode, unreadRoutesModuleCode };
@@ -1,6 +1,6 @@
1
- import { n as routesModuleCode, t as routesCommonJsCode } from "../routes-module-code-DO3aII6v.js";
1
+ import { n as routesModuleCode, t as routesCommonJsCode } from "../routes-module-code-DYtP7uj1.js";
2
2
  import { n as isRecord } from "../errno-code-CNx_E80R.js";
3
- import { t as sharedEngine } from "../shared-engine-CCu7vP_0.js";
3
+ import { t as sharedEngine } from "../shared-engine-D0j7uXg8.js";
4
4
  import { parentPort } from "node:worker_threads";
5
5
  // src/jest/routes-thread.ts
6
6
  parentPort?.on("message", (message) => {