@utoo/pack 1.2.12 → 1.2.13

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
@@ -9,6 +9,22 @@ export declare class ExternalObject<T> {
9
9
  [K: symbol]: T
10
10
  }
11
11
  }
12
+ /** Arguments for `NapiTurbopackCallbacks::throw_turbopack_internal_error`. */
13
+ export interface TurbopackInternalErrorOpts {
14
+ message: string
15
+ anonymizedLocation?: string
16
+ }
17
+ export interface NapiTurbopackCallbacksJsObject {
18
+ /**
19
+ * Called when we've encountered a bug in Turbopack and not in the user's code. Constructs and
20
+ * throws a `TurbopackInternalError` type. Logs to anonymized telemetry.
21
+ *
22
+ * As a result of the use of `ErrorStrategy::CalleeHandled`, the first argument is an error if
23
+ * there's a runtime conversion error. This should never happen, but if it does, the function
24
+ * can throw it instead.
25
+ */
26
+ throwTurbopackInternalError: (conversionError: Error | null, opts: TurbopackInternalErrorOpts) => never
27
+ }
12
28
  export declare function registerWorkerScheduler(creator: (arg: NapiWorkerCreation) => any, terminator: (arg: NapiWorkerTermination) => any): void
13
29
  export declare function workerCreated(workerId: number): void
14
30
  export interface NapiWorkerCreation {
@@ -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.
@@ -198,6 +214,23 @@ export declare function projectTraceSource(project: { __napiType: "Project" }, f
198
214
  export declare function projectGetSourceForAsset(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
199
215
  export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: RcStr): Promise<string | null>
200
216
  export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: RcStr): string | null
217
+ /**
218
+ * A version of [`NapiTurbopackCallbacks`] that can accepted as an argument to a napi function.
219
+ *
220
+ * This can be converted into a [`NapiTurbopackCallbacks`] with
221
+ * [`NapiTurbopackCallbacks::from_js`].
222
+ */
223
+ export interface NapiTurbopackCallbacksJsObject {
224
+ /**
225
+ * Called when we've encountered a bug in Turbopack and not in the user's code. Constructs and
226
+ * throws a `TurbopackInternalError` type. Logs to anonymized telemetry.
227
+ *
228
+ * As a result of the use of `ErrorStrategy::CalleeHandled`, the first argument is an error if
229
+ * there's a runtime conversion error. This should never happen, but if it does, the function
230
+ * can throw it instead.
231
+ */
232
+ throwTurbopackInternalError: (conversionError: Error | null, opts: TurbopackInternalErrorOpts) => never
233
+ }
201
234
  export declare function rootTaskDispose(rootTask: { __napiType: "RootTask" }): void
202
235
  export interface NapiIssue {
203
236
  severity: string
@@ -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
  }
@@ -0,0 +1,16 @@
1
+ import type { UserConfig } from "./config/types";
2
+ /**
3
+ * Type-safe config helper for utoopack.config.mjs / utoopack.config.js.
4
+ * Provides type inference and editor support, similar to Vite/Rollup defineConfig.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * // utoopack.config.mjs
9
+ * import { defineConfig } from '@utoo/pack';
10
+ * export default defineConfig({
11
+ * entry: [{ import: './src/index.ts', html: { template: './index.html' } }],
12
+ * output: { path: './dist', clean: true },
13
+ * });
14
+ * ```
15
+ */
16
+ export declare function defineConfig(config: UserConfig): UserConfig;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineConfig = defineConfig;
4
+ /**
5
+ * Type-safe config helper for utoopack.config.mjs / utoopack.config.js.
6
+ * Provides type inference and editor support, similar to Vite/Rollup defineConfig.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * // utoopack.config.mjs
11
+ * import { defineConfig } from '@utoo/pack';
12
+ * export default defineConfig({
13
+ * entry: [{ import: './src/index.ts', html: { template: './index.html' } }],
14
+ * output: { path: './dist', clean: true },
15
+ * });
16
+ * ```
17
+ */
18
+ function defineConfig(config) {
19
+ return config;
20
+ }
package/cjs/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { serve } from "./commands/dev";
3
3
  import * as webpackCompat from "./config/webpackCompat";
4
4
  export { build };
5
5
  export { serve };
6
+ export { defineConfig } from "./defineConfig";
6
7
  declare const utoopack: {
7
8
  build: typeof build;
8
9
  serve: typeof serve;
package/cjs/index.js CHANGED
@@ -14,11 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.serve = exports.build = void 0;
17
+ exports.defineConfig = exports.serve = exports.build = void 0;
18
18
  const build_1 = require("./commands/build");
19
19
  Object.defineProperty(exports, "build", { enumerable: true, get: function () { return build_1.build; } });
20
20
  const dev_1 = require("./commands/dev");
21
21
  Object.defineProperty(exports, "serve", { enumerable: true, get: function () { return dev_1.serve; } });
22
+ var defineConfig_1 = require("./defineConfig");
23
+ Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return defineConfig_1.defineConfig; } });
22
24
  const utoopack = { build: build_1.build, serve: dev_1.serve };
23
25
  exports.default = utoopack;
24
26
  __exportStar(require("./config/types"), exports);
package/esm/binding.d.ts CHANGED
@@ -9,6 +9,22 @@ export declare class ExternalObject<T> {
9
9
  [K: symbol]: T
10
10
  }
11
11
  }
12
+ /** Arguments for `NapiTurbopackCallbacks::throw_turbopack_internal_error`. */
13
+ export interface TurbopackInternalErrorOpts {
14
+ message: string
15
+ anonymizedLocation?: string
16
+ }
17
+ export interface NapiTurbopackCallbacksJsObject {
18
+ /**
19
+ * Called when we've encountered a bug in Turbopack and not in the user's code. Constructs and
20
+ * throws a `TurbopackInternalError` type. Logs to anonymized telemetry.
21
+ *
22
+ * As a result of the use of `ErrorStrategy::CalleeHandled`, the first argument is an error if
23
+ * there's a runtime conversion error. This should never happen, but if it does, the function
24
+ * can throw it instead.
25
+ */
26
+ throwTurbopackInternalError: (conversionError: Error | null, opts: TurbopackInternalErrorOpts) => never
27
+ }
12
28
  export declare function registerWorkerScheduler(creator: (arg: NapiWorkerCreation) => any, terminator: (arg: NapiWorkerTermination) => any): void
13
29
  export declare function workerCreated(workerId: number): void
14
30
  export interface NapiWorkerCreation {
@@ -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.
@@ -198,6 +214,23 @@ export declare function projectTraceSource(project: { __napiType: "Project" }, f
198
214
  export declare function projectGetSourceForAsset(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
199
215
  export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: RcStr): Promise<string | null>
200
216
  export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: RcStr): string | null
217
+ /**
218
+ * A version of [`NapiTurbopackCallbacks`] that can accepted as an argument to a napi function.
219
+ *
220
+ * This can be converted into a [`NapiTurbopackCallbacks`] with
221
+ * [`NapiTurbopackCallbacks::from_js`].
222
+ */
223
+ export interface NapiTurbopackCallbacksJsObject {
224
+ /**
225
+ * Called when we've encountered a bug in Turbopack and not in the user's code. Constructs and
226
+ * throws a `TurbopackInternalError` type. Logs to anonymized telemetry.
227
+ *
228
+ * As a result of the use of `ErrorStrategy::CalleeHandled`, the first argument is an error if
229
+ * there's a runtime conversion error. This should never happen, but if it does, the function
230
+ * can throw it instead.
231
+ */
232
+ throwTurbopackInternalError: (conversionError: Error | null, opts: TurbopackInternalErrorOpts) => never
233
+ }
201
234
  export declare function rootTaskDispose(rootTask: { __napiType: "RootTask" }): void
202
235
  export interface NapiIssue {
203
236
  severity: string
@@ -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
  }
@@ -0,0 +1,16 @@
1
+ import type { UserConfig } from "./config/types";
2
+ /**
3
+ * Type-safe config helper for utoopack.config.mjs / utoopack.config.js.
4
+ * Provides type inference and editor support, similar to Vite/Rollup defineConfig.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * // utoopack.config.mjs
9
+ * import { defineConfig } from '@utoo/pack';
10
+ * export default defineConfig({
11
+ * entry: [{ import: './src/index.ts', html: { template: './index.html' } }],
12
+ * output: { path: './dist', clean: true },
13
+ * });
14
+ * ```
15
+ */
16
+ export declare function defineConfig(config: UserConfig): UserConfig;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Type-safe config helper for utoopack.config.mjs / utoopack.config.js.
3
+ * Provides type inference and editor support, similar to Vite/Rollup defineConfig.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * // utoopack.config.mjs
8
+ * import { defineConfig } from '@utoo/pack';
9
+ * export default defineConfig({
10
+ * entry: [{ import: './src/index.ts', html: { template: './index.html' } }],
11
+ * output: { path: './dist', clean: true },
12
+ * });
13
+ * ```
14
+ */
15
+ export function defineConfig(config) {
16
+ return config;
17
+ }
package/esm/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { serve } from "./commands/dev";
3
3
  import * as webpackCompat from "./config/webpackCompat";
4
4
  export { build };
5
5
  export { serve };
6
+ export { defineConfig } from "./defineConfig";
6
7
  declare const utoopack: {
7
8
  build: typeof build;
8
9
  serve: typeof serve;
package/esm/index.js CHANGED
@@ -2,6 +2,7 @@ import { build } from "./commands/build.js";
2
2
  import { serve } from "./commands/dev.js";
3
3
  export { build };
4
4
  export { serve };
5
+ export { defineConfig } from "./defineConfig.js";
5
6
  const utoopack = { build, serve };
6
7
  export default utoopack;
7
8
  export * from "./config/types.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
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.12",
42
+ "@utoo/pack-shared": "1.2.13",
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.12",
90
- "@utoo/pack-darwin-x64": "1.2.12",
91
- "@utoo/pack-linux-arm64-gnu": "1.2.12",
92
- "@utoo/pack-linux-arm64-musl": "1.2.12",
93
- "@utoo/pack-linux-x64-gnu": "1.2.12",
94
- "@utoo/pack-linux-x64-musl": "1.2.12",
95
- "@utoo/pack-win32-x64-msvc": "1.2.12"
89
+ "@utoo/pack-darwin-arm64": "1.2.13",
90
+ "@utoo/pack-darwin-x64": "1.2.13",
91
+ "@utoo/pack-linux-arm64-gnu": "1.2.13",
92
+ "@utoo/pack-linux-arm64-musl": "1.2.13",
93
+ "@utoo/pack-linux-x64-gnu": "1.2.13",
94
+ "@utoo/pack-linux-x64-musl": "1.2.13",
95
+ "@utoo/pack-win32-x64-msvc": "1.2.13"
96
96
  }
97
97
  }