@utoo/pack 0.0.1-alpha.18 → 0.0.1-alpha.2

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
@@ -63,7 +63,7 @@ export interface NapiProjectOptions {
63
63
  * A map of environment variables which should get injected at compile
64
64
  * time.
65
65
  */
66
- defineEnv: NapiDefineEnv
66
+ processDefineEnv: NapiDefineEnv
67
67
  /** The mode in which Next.js is running. */
68
68
  dev: boolean
69
69
  /** The build id. */
@@ -88,7 +88,7 @@ export interface NapiPartialProjectOptions {
88
88
  * A map of environment variables which should get injected at compile
89
89
  * time.
90
90
  */
91
- defineEnv?: NapiDefineEnv
91
+ processDefineEnv?: NapiDefineEnv
92
92
  /** The mode in which Next.js is running. */
93
93
  dev?: boolean
94
94
  /** The build id. */
@@ -136,7 +136,7 @@ export interface NapiEntrypoints {
136
136
  }
137
137
  export declare function projectWriteAllEntrypointsToDisk(project: { __napiType: "Project" }): Promise<TurbopackResult>
138
138
  export declare function projectEntrypointsSubscribe(project: { __napiType: "Project" }, func: (...args: any[]) => any): { __napiType: "RootTask" }
139
- export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier: RcStr, func: (...args: any[]) => any): { __napiType: "RootTask" }
139
+ export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier: string, func: (...args: any[]) => any): { __napiType: "RootTask" }
140
140
  export interface HmrIdentifiers {
141
141
  identifiers: Array<string>
142
142
  }
@@ -166,18 +166,16 @@ export declare function projectUpdateInfoSubscribe(project: { __napiType: "Proje
166
166
  export interface StackFrame {
167
167
  isServer: boolean
168
168
  isInternal?: boolean
169
- originalFile?: RcStr
170
- file: RcStr
171
- /** 1-indexed, unlike source map tokens */
169
+ originalFile?: string
170
+ file: string
172
171
  line?: number
173
- /** 1-indexed, unlike source map tokens */
174
172
  column?: number
175
- methodName?: RcStr
173
+ methodName?: string
176
174
  }
177
175
  export declare function projectTraceSource(project: { __napiType: "Project" }, frame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>
178
176
  export declare function projectGetSourceForAsset(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
179
- export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: RcStr): Promise<string | null>
180
- export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: RcStr): string | null
177
+ export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
178
+ export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: string): string | null
181
179
  export declare function rootTaskDispose(rootTask: { __napiType: "RootTask" }): void
182
180
  export interface NapiIssue {
183
181
  severity: string
@@ -188,7 +186,7 @@ export interface NapiIssue {
188
186
  detail?: any
189
187
  source?: NapiIssueSource
190
188
  documentationLink: string
191
- importTraces: any
189
+ subIssues: Array<NapiIssue>
192
190
  }
193
191
  export interface NapiIssueSource {
194
192
  source: NapiSource
package/cjs/build.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- import { BundleOptions } from "./types";
2
- import { WebpackConfig } from "./webpackCompat";
3
- export declare function build(bundleOptions: BundleOptions, projectPath?: string, rootPath?: string): Promise<void>;
4
- export declare function build(webpackConfig: WebpackConfig, projectPath?: string, rootPath?: string): Promise<void>;
1
+ import { BuildOptions } from "./types";
2
+ export declare function build(projectOptions: BuildOptions, projectPath?: string, rootPath?: string): Promise<void>;
package/cjs/build.js CHANGED
@@ -4,34 +4,27 @@ exports.build = build;
4
4
  const nanoid_1 = require("nanoid");
5
5
  const project_1 = require("./project");
6
6
  const util_1 = require("./util");
7
- const webpackCompat_1 = require("./webpackCompat");
8
7
  const xcodeProfile_1 = require("./xcodeProfile");
9
- function build(options, projectPath, rootPath) {
10
- const bundleOptions = options.compatMode
11
- ? (0, webpackCompat_1.compatOptionsFromWebpack)(options)
12
- : options;
13
- return buildInternal(bundleOptions, projectPath, rootPath);
14
- }
15
- async function buildInternal(bundleOptions, projectPath, rootPath) {
16
- var _a, _b, _c;
8
+ async function build(projectOptions, projectPath, rootPath) {
9
+ var _a, _b, _c, _d;
17
10
  (0, util_1.blockStdout)();
18
11
  if (process.env.XCODE_PROFILE) {
19
12
  await (0, xcodeProfile_1.xcodeProfilingReady)();
20
13
  }
21
14
  const createProject = (0, project_1.projectFactory)();
22
15
  const project = await createProject({
23
- processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
24
- defineEnv: (0, util_1.createDefineEnv)({
25
- config: bundleOptions.config,
26
- dev: (_b = bundleOptions.dev) !== null && _b !== void 0 ? _b : false,
27
- optionDefineEnv: bundleOptions.defineEnv,
16
+ processEnv: (_a = projectOptions.processEnv) !== null && _a !== void 0 ? _a : {},
17
+ processDefineEnv: (0, util_1.createDefineEnv)({
18
+ config: projectOptions.config,
19
+ dev: (_b = projectOptions.dev) !== null && _b !== void 0 ? _b : false,
20
+ optionDefineEnv: projectOptions.processDefineEnv,
28
21
  }),
29
- watch: {
22
+ watch: (_c = projectOptions.watch) !== null && _c !== void 0 ? _c : {
30
23
  enable: false,
31
24
  },
32
- dev: (_c = bundleOptions.dev) !== null && _c !== void 0 ? _c : false,
33
- buildId: bundleOptions.buildId || (0, nanoid_1.nanoid)(),
34
- config: bundleOptions.config,
25
+ dev: (_d = projectOptions.dev) !== null && _d !== void 0 ? _d : false,
26
+ buildId: (0, nanoid_1.nanoid)(),
27
+ config: projectOptions.config,
35
28
  projectPath: projectPath || process.cwd(),
36
29
  rootPath: rootPath || projectPath || process.cwd(),
37
30
  }, {
@@ -1,7 +1,8 @@
1
+ import { ModernSourceMapPayload } from "./sourceMap";
2
+ import { Project, ProjectOptions, Update as TurbopackUpdate } from "./types";
3
+ import type webpack from "webpack";
1
4
  import { IncomingMessage } from "http";
2
5
  import { Duplex } from "stream";
3
- import type webpack from "webpack";
4
- import { BundleOptions, Project, Update as TurbopackUpdate } from "./types";
5
6
  export declare const enum HMR_ACTIONS_SENT_TO_BROWSER {
6
7
  RELOAD = "reload",
7
8
  CLIENT_CHANGES = "clientChanges",
@@ -16,6 +17,10 @@ export interface TurbopackMessageAction {
16
17
  action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE;
17
18
  data: TurbopackUpdate | TurbopackUpdate[];
18
19
  }
20
+ export interface TurbopackMessageAction {
21
+ action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE;
22
+ data: TurbopackUpdate | TurbopackUpdate[];
23
+ }
19
24
  export interface TurbopackConnectedAction {
20
25
  action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED;
21
26
  data: {
@@ -60,12 +65,14 @@ export interface HotReloaderInterface {
60
65
  clearHmrServerError(): void;
61
66
  start(): Promise<void>;
62
67
  send(action: HMR_ACTION_TYPES): void;
63
- onHMR(req: IncomingMessage, socket: Duplex, head: Buffer, onUpgrade?: (client: {
68
+ onHMR(req: IncomingMessage, _socket: Duplex, head: Buffer, onUpgrade: (client: {
64
69
  send(data: string): void;
65
70
  }) => void): void;
66
71
  buildFallbackError(): Promise<void>;
67
72
  close(): void;
68
73
  }
74
+ type FindSourceMapPayload = (sourceURL: string) => ModernSourceMapPayload | undefined;
75
+ export declare function setBundlerFindSourceMapImplementation(findSourceMapImplementation: FindSourceMapPayload): void;
69
76
  export type ChangeSubscriptions = Map<string, Promise<AsyncIterableIterator<TurbopackResult>>>;
70
77
  export type ReadyIds = Set<string>;
71
78
  export type StartBuilding = (id: string, forceRebuild: boolean) => () => void;
@@ -76,5 +83,5 @@ export type ClientState = {
76
83
  };
77
84
  export type SendHmr = (id: string, payload: HMR_ACTION_TYPES) => void;
78
85
  export declare const FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
79
- export declare function createHotReloader(bundleOptions: BundleOptions, projectPath?: string, rootPath?: string): Promise<HotReloaderInterface>;
86
+ export declare function createHotReloader(projectOptions: ProjectOptions, projectPath?: string, rootPath?: string): Promise<HotReloaderInterface>;
80
87
  export {};
@@ -4,34 +4,76 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FAST_REFRESH_RUNTIME_RELOAD = void 0;
7
+ exports.setBundlerFindSourceMapImplementation = setBundlerFindSourceMapImplementation;
7
8
  exports.createHotReloader = createHotReloader;
8
- const nanoid_1 = require("nanoid");
9
9
  const ws_1 = __importDefault(require("ws"));
10
+ const path_1 = require("path");
11
+ const url_1 = require("url");
10
12
  const project_1 = require("./project");
11
13
  const util_1 = require("./util");
14
+ const nanoid_1 = require("nanoid");
12
15
  const wsServer = new ws_1.default.Server({ noServer: true });
13
16
  const sessionId = Math.floor(Number.MAX_SAFE_INTEGER * Math.random());
17
+ /**
18
+ * Replaces turbopack:///[project] with the specified project in the `source` field.
19
+ */
20
+ function rewriteTurbopackSources(projectRoot, sourceMap) {
21
+ if ("sections" in sourceMap) {
22
+ for (const section of sourceMap.sections) {
23
+ rewriteTurbopackSources(projectRoot, section.map);
24
+ }
25
+ }
26
+ else {
27
+ for (let i = 0; i < sourceMap.sources.length; i++) {
28
+ sourceMap.sources[i] = (0, url_1.pathToFileURL)((0, path_1.join)(projectRoot, sourceMap.sources[i].replace(/turbopack:\/\/\/\[project\]/, ""))).toString();
29
+ }
30
+ }
31
+ }
32
+ function getSourceMapFromTurbopack(project, projectRoot, sourceURL) {
33
+ let sourceMapJson = null;
34
+ try {
35
+ sourceMapJson = project.getSourceMapSync(sourceURL);
36
+ }
37
+ catch (err) { }
38
+ if (sourceMapJson === null) {
39
+ return undefined;
40
+ }
41
+ else {
42
+ const payload = JSON.parse(sourceMapJson);
43
+ // The sourcemap from Turbopack is not yet written to disk so its `sources`
44
+ // are not absolute paths yet. We need to rewrite them to be absolute paths.
45
+ rewriteTurbopackSources(projectRoot, payload);
46
+ return payload;
47
+ }
48
+ }
49
+ // Find a source map using the bundler's API.
50
+ // This is only a fallback for when Node.js fails to due to bugs e.g. https://github.com/nodejs/node/issues/52102
51
+ // TODO: Remove once all supported Node.js versions are fixed.
52
+ // TODO(veil): Set from Webpack as well
53
+ let bundlerFindSourceMapPayload = () => undefined;
54
+ function setBundlerFindSourceMapImplementation(findSourceMapImplementation) {
55
+ bundlerFindSourceMapPayload = findSourceMapImplementation;
56
+ }
14
57
  exports.FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
15
- async function createHotReloader(bundleOptions, projectPath, rootPath) {
16
- var _a;
58
+ async function createHotReloader(projectOptions, projectPath, rootPath) {
59
+ var _a, _b;
17
60
  const createProject = (0, project_1.projectFactory)();
18
61
  const project = await createProject({
19
- processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
20
- defineEnv: (0, util_1.createDefineEnv)({
21
- config: bundleOptions.config,
62
+ processEnv: (_a = projectOptions.processEnv) !== null && _a !== void 0 ? _a : {},
63
+ processDefineEnv: (0, util_1.createDefineEnv)({
64
+ config: projectOptions.config,
22
65
  dev: true,
23
- optionDefineEnv: bundleOptions.defineEnv,
66
+ optionDefineEnv: projectOptions.processDefineEnv,
24
67
  }),
25
- watch: {
26
- enable: true,
68
+ watch: (_b = projectOptions.watch) !== null && _b !== void 0 ? _b : {
69
+ enable: false,
27
70
  },
28
71
  dev: true,
29
- buildId: bundleOptions.buildId || (0, nanoid_1.nanoid)(),
72
+ buildId: (0, nanoid_1.nanoid)(),
30
73
  config: {
31
- ...bundleOptions.config,
32
- mode: "development",
74
+ ...projectOptions.config,
33
75
  optimization: {
34
- ...bundleOptions.config.optimization,
76
+ ...projectOptions.config.optimization,
35
77
  minify: false,
36
78
  moduleIds: "named",
37
79
  },
@@ -41,6 +83,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
41
83
  }, {
42
84
  persistentCaching: true,
43
85
  });
86
+ setBundlerFindSourceMapImplementation(getSourceMapFromTurbopack.bind(null, project, projectOptions.projectPath));
44
87
  const entrypointsSubscription = project.entrypointsSubscribe();
45
88
  let currentEntriesHandlingResolve;
46
89
  let currentEntriesHandling = new Promise((resolve) => (currentEntriesHandlingResolve = resolve));
@@ -73,6 +116,9 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
73
116
  const sendEnqueuedMessagesDebounce = (0, util_1.debounce)(sendEnqueuedMessages, 2);
74
117
  function sendTurbopackMessage(payload) {
75
118
  var _a;
119
+ // TODO(PACK-2049): For some reason we end up emitting hundreds of issues messages on bigger apps,
120
+ // a lot of which are duplicates.
121
+ // They are currently not handled on the client at all, so might as well not send them for now.
76
122
  payload.diagnostics = [];
77
123
  payload.issues = [];
78
124
  for (const client of clients) {
@@ -136,9 +182,10 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
136
182
  const hotReloader = {
137
183
  turbopackProject: project,
138
184
  serverStats: null,
185
+ // TODO: Figure out if socket type can match the HotReloaderInterface
139
186
  onHMR(req, socket, head, onUpgrade) {
140
187
  wsServer.handleUpgrade(req, socket, head, (client) => {
141
- onUpgrade === null || onUpgrade === void 0 ? void 0 : onUpgrade(client);
188
+ onUpgrade(client);
142
189
  const subscriptions = new Map();
143
190
  clients.add(client);
144
191
  clientStates.set(client, {
package/cjs/index.d.ts CHANGED
@@ -1,14 +1,15 @@
1
- import { build } from "./build";
2
- import { serve } from "./dev";
3
- import * as webpackCompat from "./webpackCompat";
4
- export { build };
5
- export { serve };
6
- declare const utoopack: {
7
- build: typeof build;
8
- serve: typeof serve;
9
- };
10
- export default utoopack;
11
- export type WebpackConfig = webpackCompat.WebpackConfig;
12
- declare namespace utoopack {
13
- type WebpackConfig = webpackCompat.WebpackConfig;
1
+ import { NapiDiagnostic, NapiIssue } from "./binding";
2
+ export { build } from "./build";
3
+ export { watch } from "./watch";
4
+ declare global {
5
+ export type TurbopackResult<T = {}> = T & {
6
+ issues: NapiIssue[];
7
+ diagnostics: NapiDiagnostic[];
8
+ };
9
+ export type RefCell = {
10
+ readonly __tag: unique symbol;
11
+ };
12
+ export type ExternalEndpoint = {
13
+ readonly __tag: unique symbol;
14
+ };
14
15
  }
package/cjs/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serve = exports.build = void 0;
4
- const build_1 = require("./build");
3
+ exports.watch = exports.build = void 0;
4
+ var build_1 = require("./build");
5
5
  Object.defineProperty(exports, "build", { enumerable: true, get: function () { return build_1.build; } });
6
- const dev_1 = require("./dev");
7
- Object.defineProperty(exports, "serve", { enumerable: true, get: function () { return dev_1.serve; } });
8
- const utoopack = { build: build_1.build, serve: dev_1.serve };
9
- exports.default = utoopack;
6
+ var watch_1 = require("./watch");
7
+ Object.defineProperty(exports, "watch", { enumerable: true, get: function () { return watch_1.watch; } });
package/cjs/project.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { HmrIdentifiers, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "./binding";
2
1
  import * as binding from "./binding";
2
+ import type { NapiWrittenEndpoint, StackFrame } from "./binding";
3
3
  import { ProjectOptions, RawEntrypoints, Update } from "./types";
4
4
  export declare class TurbopackInternalError extends Error {
5
5
  name: string;
6
6
  constructor(cause: Error);
7
7
  }
8
- export declare function projectFactory(): (options: Required<ProjectOptions>, turboEngineOptions: binding.NapiTurboEngineOptions) => Promise<{
8
+ export declare function projectFactory(): (options: ProjectOptions, turboEngineOptions: binding.NapiTurboEngineOptions) => Promise<{
9
9
  readonly _nativeProject: {
10
10
  __napiType: "Project";
11
11
  };
@@ -32,12 +32,12 @@ export declare function projectFactory(): (options: Required<ProjectOptions>, tu
32
32
  diagnostics: binding.NapiDiagnostic[];
33
33
  }, void, unknown>;
34
34
  hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
35
- hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<HmrIdentifiers>>;
35
+ hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<binding.HmrIdentifiers>>;
36
36
  traceSource(stackFrame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>;
37
37
  getSourceForAsset(filePath: string): Promise<string | null>;
38
38
  getSourceMap(filePath: string): Promise<string | null>;
39
39
  getSourceMapSync(filePath: string): string | null;
40
- updateInfoSubscribe(aggregationMs: number): AsyncIterableIterator<TurbopackResult<NapiUpdateMessage>>;
40
+ updateInfoSubscribe(aggregationMs: number): AsyncIterableIterator<TurbopackResult<binding.NapiUpdateMessage>>;
41
41
  shutdown(): Promise<void>;
42
42
  onExit(): Promise<void>;
43
43
  }>;
package/cjs/project.js CHANGED
@@ -37,6 +37,7 @@ exports.TurbopackInternalError = void 0;
37
37
  exports.projectFactory = projectFactory;
38
38
  const util_1 = require("util");
39
39
  const binding = __importStar(require("./binding"));
40
+ const nanoid_1 = require("nanoid");
40
41
  const util_2 = require("./util");
41
42
  class TurbopackInternalError extends Error {
42
43
  constructor(cause) {
@@ -90,6 +91,7 @@ function ensureLoadersHaveSerializableOptions(turbopackRules) {
90
91
  async function serializeConfig(config) {
91
92
  var _a, _b;
92
93
  let configSerializable = { ...config };
94
+ configSerializable.generateBuildId = () => (0, nanoid_1.nanoid)();
93
95
  if ((_a = configSerializable.module) === null || _a === void 0 ? void 0 : _a.rules) {
94
96
  ensureLoadersHaveSerializableOptions(configSerializable.module.rules);
95
97
  }
@@ -0,0 +1,21 @@
1
+ import { type SourceMapPayload } from "module";
2
+ /**
3
+ * https://tc39.es/source-map/#index-map
4
+ */
5
+ interface IndexSourceMapSection {
6
+ offset: {
7
+ line: number;
8
+ column: number;
9
+ };
10
+ map: ModernRawSourceMap;
11
+ }
12
+ interface IndexSourceMap {
13
+ version: number;
14
+ file: string;
15
+ sections: IndexSourceMapSection[];
16
+ }
17
+ interface ModernRawSourceMap extends SourceMapPayload {
18
+ ignoreList?: number[];
19
+ }
20
+ export type ModernSourceMapPayload = ModernRawSourceMap | IndexSourceMap;
21
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/types.d.ts CHANGED
@@ -1,17 +1,4 @@
1
- import { HmrIdentifiers, NapiDiagnostic, NapiIssue, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "./binding";
2
- declare global {
3
- export type TurbopackResult<T = {}> = T & {
4
- issues: NapiIssue[];
5
- diagnostics: NapiDiagnostic[];
6
- };
7
- export type RefCell = {
8
- readonly __tag: unique symbol;
9
- };
10
- export type ExternalEndpoint = {
11
- readonly __tag: unique symbol;
12
- };
13
- export type RcStr = string;
14
- }
1
+ import { HmrIdentifiers, NapiIssue, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "./binding";
15
2
  export interface BaseUpdate {
16
3
  resource: {
17
4
  headers: unknown;
@@ -66,6 +53,7 @@ export interface DefineEnv {
66
53
  }
67
54
  export interface ExperimentalConfig {
68
55
  }
56
+ export type TurbopackRuleConfigItemOrShortcut = TurbopackRuleConfigItem;
69
57
  export type TurbopackRuleConfigItem = TurbopackRuleConfigItemOptions | {
70
58
  [condition: string]: TurbopackRuleConfigItem;
71
59
  } | false;
@@ -81,7 +69,7 @@ export type TurbopackRuleConfigItemOptions = {
81
69
  as?: string;
82
70
  };
83
71
  export interface ModuleOptions {
84
- rules?: Record<string, TurbopackRuleConfigItem>;
72
+ rules?: Record<string, TurbopackRuleConfigItemOrShortcut>;
85
73
  }
86
74
  export interface ResolveOptions {
87
75
  alias?: Record<string, string | string[] | Record<string, string | string[]>>;
@@ -152,7 +140,6 @@ export interface ConfigComplete {
152
140
  images?: {
153
141
  inlineLimit?: number;
154
142
  };
155
- stats?: boolean;
156
143
  experimental?: ExperimentalConfig;
157
144
  persistentCaching?: boolean;
158
145
  cacheHandler?: string;
@@ -206,25 +193,25 @@ export interface ProjectOptions {
206
193
  /**
207
194
  * A map of environment variables to use when compiling code.
208
195
  */
209
- processEnv?: Record<string, string>;
210
- defineEnv?: DefineEnv;
196
+ processEnv: Record<string, string>;
197
+ processDefineEnv: DefineEnv;
211
198
  /**
212
199
  * Whether to watch the filesystem for file changes.
213
200
  */
214
- watch?: {
201
+ watch: {
215
202
  enable: boolean;
216
203
  pollIntervalMs?: number;
217
204
  };
218
205
  /**
219
206
  * The mode of utoo-pack.
220
207
  */
221
- dev?: boolean;
208
+ dev: boolean;
222
209
  /**
223
210
  * The build id.
224
211
  */
225
- buildId?: string;
212
+ buildId: string;
226
213
  }
227
- export type BundleOptions = Omit<ProjectOptions, "rootPath" | "projectPath">;
214
+ export type BuildOptions = Omit<ProjectOptions, "rootPath" | "projectPath">;
228
215
  export interface Project {
229
216
  update(options: Partial<ProjectOptions>): Promise<void>;
230
217
  entrypointsSubscribe(): AsyncIterableIterator<TurbopackResult<RawEntrypoints>>;
package/cjs/util.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NapiIssue } from "./binding";
2
- import { ConfigComplete, DefineEnv, RustifiedEnv, StyledString } from "./types";
2
+ import { DefineEnv, StyledString, RustifiedEnv, ConfigComplete } from "./types";
3
3
  export declare class ModuleBuildError extends Error {
4
4
  name: string;
5
5
  }
package/cjs/util.js CHANGED
@@ -10,8 +10,8 @@ exports.rustifyEnv = rustifyEnv;
10
10
  exports.createDefineEnv = createDefineEnv;
11
11
  exports.debounce = debounce;
12
12
  exports.blockStdout = blockStdout;
13
- const code_frame_1 = require("@babel/code-frame");
14
13
  const picocolors_1 = require("picocolors");
14
+ const code_frame_1 = require("@babel/code-frame");
15
15
  const magicIdentifier_1 = require("./magicIdentifier");
16
16
  class ModuleBuildError extends Error {
17
17
  constructor() {
package/cjs/watch.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { ProjectOptions } from "./types";
2
+ export declare function watch(options: ProjectOptions, projectPath: string, rootPath?: string): Promise<void>;
package/cjs/watch.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.watch = watch;
4
+ const hotReloader_1 = require("./hotReloader");
5
+ const util_1 = require("./util");
6
+ const xcodeProfile_1 = require("./xcodeProfile");
7
+ async function watch(options, projectPath, rootPath) {
8
+ (0, util_1.blockStdout)();
9
+ if (process.env.XCODE_PROFILE) {
10
+ await (0, xcodeProfile_1.xcodeProfilingReady)();
11
+ }
12
+ const hotReloader = await (0, hotReloader_1.createHotReloader)(options, projectPath, rootPath);
13
+ await hotReloader.start();
14
+ }
package/esm/binding.d.ts CHANGED
@@ -63,7 +63,7 @@ export interface NapiProjectOptions {
63
63
  * A map of environment variables which should get injected at compile
64
64
  * time.
65
65
  */
66
- defineEnv: NapiDefineEnv
66
+ processDefineEnv: NapiDefineEnv
67
67
  /** The mode in which Next.js is running. */
68
68
  dev: boolean
69
69
  /** The build id. */
@@ -88,7 +88,7 @@ export interface NapiPartialProjectOptions {
88
88
  * A map of environment variables which should get injected at compile
89
89
  * time.
90
90
  */
91
- defineEnv?: NapiDefineEnv
91
+ processDefineEnv?: NapiDefineEnv
92
92
  /** The mode in which Next.js is running. */
93
93
  dev?: boolean
94
94
  /** The build id. */
@@ -136,7 +136,7 @@ export interface NapiEntrypoints {
136
136
  }
137
137
  export declare function projectWriteAllEntrypointsToDisk(project: { __napiType: "Project" }): Promise<TurbopackResult>
138
138
  export declare function projectEntrypointsSubscribe(project: { __napiType: "Project" }, func: (...args: any[]) => any): { __napiType: "RootTask" }
139
- export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier: RcStr, func: (...args: any[]) => any): { __napiType: "RootTask" }
139
+ export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier: string, func: (...args: any[]) => any): { __napiType: "RootTask" }
140
140
  export interface HmrIdentifiers {
141
141
  identifiers: Array<string>
142
142
  }
@@ -166,18 +166,16 @@ export declare function projectUpdateInfoSubscribe(project: { __napiType: "Proje
166
166
  export interface StackFrame {
167
167
  isServer: boolean
168
168
  isInternal?: boolean
169
- originalFile?: RcStr
170
- file: RcStr
171
- /** 1-indexed, unlike source map tokens */
169
+ originalFile?: string
170
+ file: string
172
171
  line?: number
173
- /** 1-indexed, unlike source map tokens */
174
172
  column?: number
175
- methodName?: RcStr
173
+ methodName?: string
176
174
  }
177
175
  export declare function projectTraceSource(project: { __napiType: "Project" }, frame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>
178
176
  export declare function projectGetSourceForAsset(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
179
- export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: RcStr): Promise<string | null>
180
- export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: RcStr): string | null
177
+ export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
178
+ export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: string): string | null
181
179
  export declare function rootTaskDispose(rootTask: { __napiType: "RootTask" }): void
182
180
  export interface NapiIssue {
183
181
  severity: string
@@ -188,7 +186,7 @@ export interface NapiIssue {
188
186
  detail?: any
189
187
  source?: NapiIssueSource
190
188
  documentationLink: string
191
- importTraces: any
189
+ subIssues: Array<NapiIssue>
192
190
  }
193
191
  export interface NapiIssueSource {
194
192
  source: NapiSource
package/esm/build.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- import { BundleOptions } from "./types";
2
- import { WebpackConfig } from "./webpackCompat";
3
- export declare function build(bundleOptions: BundleOptions, projectPath?: string, rootPath?: string): Promise<void>;
4
- export declare function build(webpackConfig: WebpackConfig, projectPath?: string, rootPath?: string): Promise<void>;
1
+ import { BuildOptions } from "./types";
2
+ export declare function build(projectOptions: BuildOptions, projectPath?: string, rootPath?: string): Promise<void>;
package/esm/build.js CHANGED
@@ -1,34 +1,27 @@
1
1
  import { nanoid } from "nanoid";
2
2
  import { projectFactory } from "./project";
3
3
  import { blockStdout, createDefineEnv, formatIssue, isRelevantWarning, } from "./util";
4
- import { compatOptionsFromWebpack } from "./webpackCompat";
5
4
  import { xcodeProfilingReady } from "./xcodeProfile";
6
- export function build(options, projectPath, rootPath) {
7
- const bundleOptions = options.compatMode
8
- ? compatOptionsFromWebpack(options)
9
- : options;
10
- return buildInternal(bundleOptions, projectPath, rootPath);
11
- }
12
- async function buildInternal(bundleOptions, projectPath, rootPath) {
13
- var _a, _b, _c;
5
+ export async function build(projectOptions, projectPath, rootPath) {
6
+ var _a, _b, _c, _d;
14
7
  blockStdout();
15
8
  if (process.env.XCODE_PROFILE) {
16
9
  await xcodeProfilingReady();
17
10
  }
18
11
  const createProject = projectFactory();
19
12
  const project = await createProject({
20
- processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
21
- defineEnv: createDefineEnv({
22
- config: bundleOptions.config,
23
- dev: (_b = bundleOptions.dev) !== null && _b !== void 0 ? _b : false,
24
- optionDefineEnv: bundleOptions.defineEnv,
13
+ processEnv: (_a = projectOptions.processEnv) !== null && _a !== void 0 ? _a : {},
14
+ processDefineEnv: createDefineEnv({
15
+ config: projectOptions.config,
16
+ dev: (_b = projectOptions.dev) !== null && _b !== void 0 ? _b : false,
17
+ optionDefineEnv: projectOptions.processDefineEnv,
25
18
  }),
26
- watch: {
19
+ watch: (_c = projectOptions.watch) !== null && _c !== void 0 ? _c : {
27
20
  enable: false,
28
21
  },
29
- dev: (_c = bundleOptions.dev) !== null && _c !== void 0 ? _c : false,
30
- buildId: bundleOptions.buildId || nanoid(),
31
- config: bundleOptions.config,
22
+ dev: (_d = projectOptions.dev) !== null && _d !== void 0 ? _d : false,
23
+ buildId: nanoid(),
24
+ config: projectOptions.config,
32
25
  projectPath: projectPath || process.cwd(),
33
26
  rootPath: rootPath || projectPath || process.cwd(),
34
27
  }, {