@veryfront/ext-bundler-esbuild 0.1.1235 → 0.1.1237

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.
@@ -97,5 +97,10 @@ interface ImportMetaPonyfill extends ImportMetaPonyfillCommonjs, ImportMetaPonyf
97
97
  export declare let import_meta_ponyfill_commonjs: ImportMetaPonyfillCommonjs;
98
98
  export declare let import_meta_ponyfill_esmodule: ImportMetaPonyfillEsmodule;
99
99
  export declare let import_meta_ponyfill: ImportMetaPonyfill;
100
+ declare global {
101
+ interface Error {
102
+ cause?: unknown;
103
+ }
104
+ }
100
105
  export {};
101
106
  //# sourceMappingURL=_dnt.polyfills.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAGlE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;;;;;;;WAcG;QACH,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;;;;;;;;WAYG;QACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,MAAM,CAAC;QACtE;;;;;;;;WAQG;QACH,IAAI,EAAE,OAAO,CAAC;QAEd;;;;;;;;;;;;WAYG;QACH,QAAQ,EAAE,MAAM,CAAC;QAEjB;;;;;;;;;;;;WAYG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB;CACF;AAED,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,KAAK,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,UAAU,0BAA0B;IAClC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AAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CACtC;AACD,UAAU,kBACR,SAAQ,0BAA0B,EAAE,0BAA0B;CAC/D;AAiBD,eAAO,IAAI,6BAA6B,EA2BnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,6BAA6B,EA4DnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,oBAAoB,EAoB1B,kBAAkB,CAAC;AACxB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC"}
@@ -6,6 +6,10 @@ import type { ChildProcess } from "node:child_process";
6
6
  * Native Node represents an active child with `null` exit fields. Some
7
7
  * compatible runtimes leave those fields undefined until the child exits.
8
8
  */
9
+ /** The ownership latch is module-wide; tests must clear it between cases. */
10
+ export declare function __resetOwnershipErrorForTests(): void;
11
+ /** Exercise the latch without starting a real esbuild service. */
12
+ export declare function __recordOwnershipErrorForTests(cause?: unknown): Error;
9
13
  export declare function isLiveEsbuildServiceProcess(child: Pick<ChildProcess, "killed" | "exitCode" | "signalCode">): boolean;
10
14
  /**
11
15
  * esbuild-backed {@link Bundler} implementation.
@@ -1 +1 @@
1
- {"version":3,"file":"esbuild-bundler.d.ts","sourceRoot":"","sources":["../src/esbuild-bundler.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EAEb,OAAO,EACP,YAAY,EAGZ,gBAAgB,EAChB,eAAe,EAChB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AA+LvD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,UAAU,GAAG,YAAY,CAAC,GAC9D,OAAO,CAIT;AAwHD;;;;;GAKG;AACH,qBAAa,cAAe,YAAW,OAAO;IACtC,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IAsCrD,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;IAa9D,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IAqCtD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAiF5B"}
1
+ {"version":3,"file":"esbuild-bundler.d.ts","sourceRoot":"","sources":["../src/esbuild-bundler.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EAEb,OAAO,EACP,YAAY,EAGZ,gBAAgB,EAChB,eAAe,EAChB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAgPvD;;;;;GAKG;AACH,6EAA6E;AAC7E,wBAAgB,6BAA6B,IAAI,IAAI,CAEpD;AAED,kEAAkE;AAClE,wBAAgB,8BAA8B,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,KAAK,CAErE;AAED,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,UAAU,GAAG,YAAY,CAAC,GAC9D,OAAO,CAIT;AA6HD;;;;;GAKG;AACH,qBAAa,cAAe,YAAW,OAAO;IACtC,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IAsCrD,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;IAa9D,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IAqCtD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAiF5B"}
@@ -27,10 +27,53 @@ let activeOperationCount = 0;
27
27
  let activeOperationsIdle = Promise.resolve();
28
28
  let resolveActiveOperationsIdle = null;
29
29
  const operationScopes = new AsyncLocalStorage();
30
+ const OWNERSHIP_ERROR_MESSAGE = "[ext-bundler-esbuild] Cannot own an esbuild service started outside the module-wide adapter; restart the process and use only the Bundler contract";
31
+ const MAX_CAUSE_DETAIL_LENGTH = 200;
32
+ /** Absolute POSIX and Windows paths, reduced to a basename below. */
33
+ const ABSOLUTE_PATH_PATTERN = /(?:[A-Za-z]:)?(?:\/|\\\\)[^\s"']*/g;
34
+ /**
35
+ * Reduce a cause to a single redacted line.
36
+ *
37
+ * The message is logged, so it must not carry a machine's filesystem layout:
38
+ * a compiled runtime resolves esbuild under a temp directory, and spawn errors
39
+ * quote that path verbatim. Keeping only the basename preserves what the reader
40
+ * needs -- which binary or module failed -- without the surrounding layout. The
41
+ * first line only, so a stack never reaches the message, and bounded so a large
42
+ * esbuild diagnostic cannot dominate the log line.
43
+ */
44
+ function describeCause(cause) {
45
+ if (cause === undefined)
46
+ return "";
47
+ const raw = cause instanceof Error ? cause.message : String(cause);
48
+ const firstLine = raw.split("\n", 1)[0] ?? "";
49
+ const withoutPaths = firstLine.replace(ABSOLUTE_PATH_PATTERN, (match) => {
50
+ const parts = match.split(/[\/\\]/).filter(Boolean);
51
+ return parts.length > 0 ? parts[parts.length - 1] : match;
52
+ });
53
+ const detail = withoutPaths.trim().slice(0, MAX_CAUSE_DETAIL_LENGTH);
54
+ return detail ? ` (underlying failure: ${detail})` : "";
55
+ }
56
+ /**
57
+ * Latch the ownership failure, keeping whatever really went wrong.
58
+ *
59
+ * The latch is permanent, so the first call decides the error every later
60
+ * operation sees. That call is often made before the operation settles, when no
61
+ * cause is known yet; adopting the cause afterwards is what keeps the real
62
+ * failure visible instead of reporting a lifecycle problem that may not be the
63
+ * actual one. The cause is folded into the message because callers log
64
+ * `error.message` and would otherwise never print the chain.
65
+ */
30
66
  function recordOwnershipError(cause) {
31
- const message = "[ext-bundler-esbuild] Cannot own an esbuild service started outside the module-wide adapter; restart the process and use only the Bundler contract";
32
- esbuildOwnershipError ??= new Error(message, cause === undefined ? undefined : { cause });
33
- return esbuildOwnershipError;
67
+ const existing = esbuildOwnershipError;
68
+ if (!existing) {
69
+ esbuildOwnershipError = new Error(`${OWNERSHIP_ERROR_MESSAGE}${describeCause(cause)}`, cause === undefined ? undefined : { cause });
70
+ return esbuildOwnershipError;
71
+ }
72
+ if (cause !== undefined && existing.cause === undefined) {
73
+ existing.cause = cause;
74
+ existing.message = `${OWNERSHIP_ERROR_MESSAGE}${describeCause(cause)}`;
75
+ }
76
+ return existing;
34
77
  }
35
78
  async function getEsbuild() {
36
79
  await ensureEsbuildBinary();
@@ -163,6 +206,14 @@ function isEsbuildServiceSpawn(spawnArgs) {
163
206
  * Native Node represents an active child with `null` exit fields. Some
164
207
  * compatible runtimes leave those fields undefined until the child exits.
165
208
  */
209
+ /** The ownership latch is module-wide; tests must clear it between cases. */
210
+ export function __resetOwnershipErrorForTests() {
211
+ esbuildOwnershipError = null;
212
+ }
213
+ /** Exercise the latch without starting a real esbuild service. */
214
+ export function __recordOwnershipErrorForTests(cause) {
215
+ return recordOwnershipError(cause);
216
+ }
166
217
  export function isLiveEsbuildServiceProcess(child) {
167
218
  return !child.killed &&
168
219
  (child.exitCode === null || child.exitCode === undefined) &&
@@ -211,9 +262,14 @@ function invokeEsbuild(operation) {
211
262
  }
212
263
  const ownedService = capturedService ?? esbuildService;
213
264
  if (!ownedService || !isLiveService(ownedService)) {
214
- const ownershipError = recordOwnershipError();
265
+ // Latch synchronously so a concurrent operation cannot pass the admission
266
+ // check in runBundlerOperation and drive esbuild while ownership is already
267
+ // known to be invalid. The rejection handler still supplies the cause: the
268
+ // latch is created without one here, and recordOwnershipError adopts the
269
+ // first cause offered afterwards.
270
+ recordOwnershipError();
215
271
  return result.then(() => {
216
- throw ownershipError;
272
+ throw recordOwnershipError();
217
273
  }, (cause) => {
218
274
  throw recordOwnershipError(cause);
219
275
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veryfront/ext-bundler-esbuild",
3
- "version": "0.1.1235",
3
+ "version": "0.1.1237",
4
4
  "description": "Veryfront first-party extension package for ext-bundler-esbuild",
5
5
  "keywords": [
6
6
  "veryfront",
@@ -50,7 +50,7 @@
50
50
  "esbuild": "0.28.1"
51
51
  },
52
52
  "peerDependencies": {
53
- "veryfront": "^0.1.1235"
53
+ "veryfront": "^0.1.1237"
54
54
  },
55
55
  "type": "module",
56
56
  "types": "./esm/index.d.ts",