@utoo/pack 1.2.11 → 1.2.13-alpha.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.
package/cjs/binding.d.ts CHANGED
@@ -28,6 +28,22 @@ export interface NapiTaskMessage {
28
28
  }
29
29
  export declare function recvTaskMessageInWorker(workerId: number): Promise<NapiTaskMessage>
30
30
  export declare function sendTaskMessage(message: NapiTaskMessage): Promise<void>
31
+ /** Arguments for `NapiTurbopackCallbacks::throw_turbopack_internal_error`. */
32
+ export interface TurbopackInternalErrorOpts {
33
+ message: string
34
+ anonymizedLocation?: string
35
+ }
36
+ export interface NapiTurbopackCallbacksJsObject {
37
+ /**
38
+ * Called when we've encountered a bug in Turbopack and not in the user's code. Constructs and
39
+ * throws a `TurbopackInternalError` type. Logs to anonymized telemetry.
40
+ *
41
+ * As a result of the use of `ErrorStrategy::CalleeHandled`, the first argument is an error if
42
+ * there's a runtime conversion error. This should never happen, but if it does, the function
43
+ * can throw it instead.
44
+ */
45
+ throwTurbopackInternalError: (conversionError: Error | null, opts: TurbopackInternalErrorOpts) => never
46
+ }
31
47
  export interface NapiEndpointConfig {
32
48
 
33
49
  }
@@ -133,7 +149,7 @@ export interface NapiTurboEngineOptions {
133
149
  /** Track dependencies between tasks. If false, any change during build will error. */
134
150
  dependencyTracking?: boolean
135
151
  }
136
- export declare function projectNew(options: NapiProjectOptions, turboEngineOptions: NapiTurboEngineOptions): Promise<{ __napiType: "Project" }>
152
+ export declare function projectNew(options: NapiProjectOptions, turboEngineOptions: NapiTurboEngineOptions, napiCallbacks: NapiTurbopackCallbacksJsObject): Promise<{ __napiType: "Project" }>
137
153
  export declare function projectUpdate(project: { __napiType: "Project" }, options: NapiPartialProjectOptions): Promise<void>
138
154
  /**
139
155
  * Runs exit handlers for the project registered using the [`ExitHandler`] API.
@@ -1,9 +1,16 @@
1
- import type { HmrIdentifiers, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "../binding";
1
+ import type { HmrIdentifiers, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame, TurbopackInternalErrorOpts } from "../binding";
2
2
  import * as binding from "../binding";
3
3
  import { ProjectOptions, RawEntrypoints, Update } from "./types";
4
+ /**
5
+ * An error caused by a bug in Turbopack, and not the user's code (e.g. a Rust panic). These should
6
+ * be written to a log file and details should not be shown to the user.
7
+ *
8
+ * These are constructed in Turbopack by calling `throwTurbopackInternalError`.
9
+ */
4
10
  export declare class TurbopackInternalError extends Error {
5
11
  name: string;
6
- constructor(cause: Error);
12
+ location: string | undefined;
13
+ constructor({ message, anonymizedLocation }: TurbopackInternalErrorOpts);
7
14
  }
8
15
  export declare function projectFactory(): (options: Required<ProjectOptions>, turboEngineOptions: binding.NapiTurboEngineOptions) => Promise<{
9
16
  readonly _nativeProject: {
@@ -40,20 +40,38 @@ const util_1 = require("util");
40
40
  const binding = __importStar(require("../binding"));
41
41
  const common_1 = require("../utils/common");
42
42
  const loaderWorkerPool_1 = require("./loaderWorkerPool");
43
+ /**
44
+ * An error caused by a bug in Turbopack, and not the user's code (e.g. a Rust panic). These should
45
+ * be written to a log file and details should not be shown to the user.
46
+ *
47
+ * These are constructed in Turbopack by calling `throwTurbopackInternalError`.
48
+ */
43
49
  class TurbopackInternalError extends Error {
44
- constructor(cause) {
45
- super(cause.message);
50
+ constructor({ message, anonymizedLocation }) {
51
+ super(message);
46
52
  this.name = "TurbopackInternalError";
47
- this.stack = cause.stack;
53
+ this.location = anonymizedLocation;
48
54
  }
49
55
  }
50
56
  exports.TurbopackInternalError = TurbopackInternalError;
57
+ /**
58
+ * A helper used by the napi Rust entrypoints to construct and throw a `TurbopackInternalError`.
59
+ */
60
+ function throwTurbopackInternalError(conversionError, opts) {
61
+ if (conversionError != null) {
62
+ throw new Error("NAPI type conversion error in throwTurbopackInternalError", { cause: conversionError });
63
+ }
64
+ throw new TurbopackInternalError(opts);
65
+ }
51
66
  async function withErrorCause(fn) {
67
+ var _a;
52
68
  try {
53
69
  return await fn();
54
70
  }
55
71
  catch (nativeError) {
56
- throw new TurbopackInternalError(nativeError);
72
+ throw new TurbopackInternalError({
73
+ message: (_a = nativeError === null || nativeError === void 0 ? void 0 : nativeError.message) !== null && _a !== void 0 ? _a : String(nativeError),
74
+ });
57
75
  }
58
76
  }
59
77
  async function serializeConfig(config) {
@@ -253,7 +271,7 @@ function projectFactory() {
253
271
  if (e === cancel)
254
272
  return;
255
273
  if (e instanceof Error) {
256
- throw new TurbopackInternalError(e);
274
+ throw new TurbopackInternalError({ message: e.message });
257
275
  }
258
276
  throw e;
259
277
  }
@@ -351,6 +369,8 @@ function projectFactory() {
351
369
  };
352
370
  }
353
371
  return async function createProject(options, turboEngineOptions) {
354
- return new ProjectImpl(await binding.projectNew(await rustifyProjectOptions(options), turboEngineOptions || {}));
372
+ return new ProjectImpl(await binding.projectNew(await rustifyProjectOptions(options), turboEngineOptions || {}, {
373
+ throwTurbopackInternalError,
374
+ }));
355
375
  };
356
376
  }
package/esm/binding.d.ts CHANGED
@@ -28,6 +28,22 @@ export interface NapiTaskMessage {
28
28
  }
29
29
  export declare function recvTaskMessageInWorker(workerId: number): Promise<NapiTaskMessage>
30
30
  export declare function sendTaskMessage(message: NapiTaskMessage): Promise<void>
31
+ /** Arguments for `NapiTurbopackCallbacks::throw_turbopack_internal_error`. */
32
+ export interface TurbopackInternalErrorOpts {
33
+ message: string
34
+ anonymizedLocation?: string
35
+ }
36
+ export interface NapiTurbopackCallbacksJsObject {
37
+ /**
38
+ * Called when we've encountered a bug in Turbopack and not in the user's code. Constructs and
39
+ * throws a `TurbopackInternalError` type. Logs to anonymized telemetry.
40
+ *
41
+ * As a result of the use of `ErrorStrategy::CalleeHandled`, the first argument is an error if
42
+ * there's a runtime conversion error. This should never happen, but if it does, the function
43
+ * can throw it instead.
44
+ */
45
+ throwTurbopackInternalError: (conversionError: Error | null, opts: TurbopackInternalErrorOpts) => never
46
+ }
31
47
  export interface NapiEndpointConfig {
32
48
 
33
49
  }
@@ -133,7 +149,7 @@ export interface NapiTurboEngineOptions {
133
149
  /** Track dependencies between tasks. If false, any change during build will error. */
134
150
  dependencyTracking?: boolean
135
151
  }
136
- export declare function projectNew(options: NapiProjectOptions, turboEngineOptions: NapiTurboEngineOptions): Promise<{ __napiType: "Project" }>
152
+ export declare function projectNew(options: NapiProjectOptions, turboEngineOptions: NapiTurboEngineOptions, napiCallbacks: NapiTurbopackCallbacksJsObject): Promise<{ __napiType: "Project" }>
137
153
  export declare function projectUpdate(project: { __napiType: "Project" }, options: NapiPartialProjectOptions): Promise<void>
138
154
  /**
139
155
  * Runs exit handlers for the project registered using the [`ExitHandler`] API.
@@ -1,9 +1,16 @@
1
- import type { HmrIdentifiers, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "../binding";
1
+ import type { HmrIdentifiers, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame, TurbopackInternalErrorOpts } from "../binding";
2
2
  import * as binding from "../binding";
3
3
  import { ProjectOptions, RawEntrypoints, Update } from "./types";
4
+ /**
5
+ * An error caused by a bug in Turbopack, and not the user's code (e.g. a Rust panic). These should
6
+ * be written to a log file and details should not be shown to the user.
7
+ *
8
+ * These are constructed in Turbopack by calling `throwTurbopackInternalError`.
9
+ */
4
10
  export declare class TurbopackInternalError extends Error {
5
11
  name: string;
6
- constructor(cause: Error);
12
+ location: string | undefined;
13
+ constructor({ message, anonymizedLocation }: TurbopackInternalErrorOpts);
7
14
  }
8
15
  export declare function projectFactory(): (options: Required<ProjectOptions>, turboEngineOptions: binding.NapiTurboEngineOptions) => Promise<{
9
16
  readonly _nativeProject: {
@@ -3,19 +3,37 @@ import { isDeepStrictEqual } from "util";
3
3
  import * as binding from "../binding.js";
4
4
  import { getPackPath, rustifyEnv } from "../utils/common.js";
5
5
  import { runLoaderWorkerPool } from "./loaderWorkerPool.js";
6
+ /**
7
+ * An error caused by a bug in Turbopack, and not the user's code (e.g. a Rust panic). These should
8
+ * be written to a log file and details should not be shown to the user.
9
+ *
10
+ * These are constructed in Turbopack by calling `throwTurbopackInternalError`.
11
+ */
6
12
  export class TurbopackInternalError extends Error {
7
- constructor(cause) {
8
- super(cause.message);
13
+ constructor({ message, anonymizedLocation }) {
14
+ super(message);
9
15
  this.name = "TurbopackInternalError";
10
- this.stack = cause.stack;
16
+ this.location = anonymizedLocation;
11
17
  }
12
18
  }
19
+ /**
20
+ * A helper used by the napi Rust entrypoints to construct and throw a `TurbopackInternalError`.
21
+ */
22
+ function throwTurbopackInternalError(conversionError, opts) {
23
+ if (conversionError != null) {
24
+ throw new Error("NAPI type conversion error in throwTurbopackInternalError", { cause: conversionError });
25
+ }
26
+ throw new TurbopackInternalError(opts);
27
+ }
13
28
  async function withErrorCause(fn) {
29
+ var _a;
14
30
  try {
15
31
  return await fn();
16
32
  }
17
33
  catch (nativeError) {
18
- throw new TurbopackInternalError(nativeError);
34
+ throw new TurbopackInternalError({
35
+ message: (_a = nativeError === null || nativeError === void 0 ? void 0 : nativeError.message) !== null && _a !== void 0 ? _a : String(nativeError),
36
+ });
19
37
  }
20
38
  }
21
39
  async function serializeConfig(config) {
@@ -215,7 +233,7 @@ export function projectFactory() {
215
233
  if (e === cancel)
216
234
  return;
217
235
  if (e instanceof Error) {
218
- throw new TurbopackInternalError(e);
236
+ throw new TurbopackInternalError({ message: e.message });
219
237
  }
220
238
  throw e;
221
239
  }
@@ -313,6 +331,8 @@ export function projectFactory() {
313
331
  };
314
332
  }
315
333
  return async function createProject(options, turboEngineOptions) {
316
- return new ProjectImpl(await binding.projectNew(await rustifyProjectOptions(options), turboEngineOptions || {}));
334
+ return new ProjectImpl(await binding.projectNew(await rustifyProjectOptions(options), turboEngineOptions || {}, {
335
+ throwTurbopackInternalError,
336
+ }));
317
337
  };
318
338
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "1.2.11",
3
+ "version": "1.2.13-alpha.0",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "types": "esm/index.d.ts",
@@ -39,7 +39,7 @@
39
39
  "dependencies": {
40
40
  "@babel/code-frame": "7.22.5",
41
41
  "@swc/helpers": "0.5.15",
42
- "@utoo/pack-shared": "1.2.11",
42
+ "@utoo/pack-shared": "1.2.13-alpha.0",
43
43
  "@utoo/style-loader": "^1.0.0",
44
44
  "domparser-rs": "^0.0.7",
45
45
  "find-up": "4.1.0",
@@ -86,12 +86,12 @@
86
86
  },
87
87
  "repository": "git@github.com:utooland/utoo.git",
88
88
  "optionalDependencies": {
89
- "@utoo/pack-darwin-arm64": "1.2.11",
90
- "@utoo/pack-darwin-x64": "1.2.11",
91
- "@utoo/pack-linux-arm64-gnu": "1.2.11",
92
- "@utoo/pack-linux-arm64-musl": "1.2.11",
93
- "@utoo/pack-linux-x64-gnu": "1.2.11",
94
- "@utoo/pack-linux-x64-musl": "1.2.11",
95
- "@utoo/pack-win32-x64-msvc": "1.2.11"
89
+ "@utoo/pack-darwin-arm64": "1.2.13-alpha.0",
90
+ "@utoo/pack-darwin-x64": "1.2.13-alpha.0",
91
+ "@utoo/pack-linux-arm64-gnu": "1.2.13-alpha.0",
92
+ "@utoo/pack-linux-arm64-musl": "1.2.13-alpha.0",
93
+ "@utoo/pack-linux-x64-gnu": "1.2.13-alpha.0",
94
+ "@utoo/pack-linux-x64-musl": "1.2.13-alpha.0",
95
+ "@utoo/pack-win32-x64-msvc": "1.2.13-alpha.0"
96
96
  }
97
97
  }