@utoo/pack 0.0.1-alpha.1

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.
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAGIC_IDENTIFIER_REGEX = void 0;
4
+ exports.decodeMagicIdentifier = decodeMagicIdentifier;
5
+ function decodeHex(hexStr) {
6
+ if (hexStr.trim() === "") {
7
+ throw new Error("can't decode empty hex");
8
+ }
9
+ const num = parseInt(hexStr, 16);
10
+ if (isNaN(num)) {
11
+ throw new Error(`invalid hex: \`${hexStr}\``);
12
+ }
13
+ return String.fromCodePoint(num);
14
+ }
15
+ const DECODE_REGEX = /^__TURBOPACK__([a-zA-Z0-9_$]+)__$/;
16
+ function decodeMagicIdentifier(identifier) {
17
+ const matches = identifier.match(DECODE_REGEX);
18
+ if (!matches) {
19
+ return identifier;
20
+ }
21
+ const inner = matches[1];
22
+ let output = "";
23
+ let mode = 0 /* Mode.Text */;
24
+ let buffer = "";
25
+ for (let i = 0; i < inner.length; i++) {
26
+ const char = inner[i];
27
+ if (mode === 0 /* Mode.Text */) {
28
+ if (char === "_") {
29
+ mode = 1 /* Mode.Underscore */;
30
+ }
31
+ else if (char === "$") {
32
+ mode = 2 /* Mode.Hex */;
33
+ }
34
+ else {
35
+ output += char;
36
+ }
37
+ }
38
+ else if (mode === 1 /* Mode.Underscore */) {
39
+ if (char === "_") {
40
+ output += " ";
41
+ mode = 0 /* Mode.Text */;
42
+ }
43
+ else if (char === "$") {
44
+ output += "_";
45
+ mode = 2 /* Mode.Hex */;
46
+ }
47
+ else {
48
+ output += char;
49
+ mode = 0 /* Mode.Text */;
50
+ }
51
+ }
52
+ else if (mode === 2 /* Mode.Hex */) {
53
+ if (buffer.length === 2) {
54
+ output += decodeHex(buffer);
55
+ buffer = "";
56
+ }
57
+ if (char === "_") {
58
+ if (buffer !== "") {
59
+ throw new Error(`invalid hex: \`${buffer}\``);
60
+ }
61
+ mode = 3 /* Mode.LongHex */;
62
+ }
63
+ else if (char === "$") {
64
+ if (buffer !== "") {
65
+ throw new Error(`invalid hex: \`${buffer}\``);
66
+ }
67
+ mode = 0 /* Mode.Text */;
68
+ }
69
+ else {
70
+ buffer += char;
71
+ }
72
+ }
73
+ else if (mode === 3 /* Mode.LongHex */) {
74
+ if (char === "_") {
75
+ throw new Error(`invalid hex: \`${buffer + char}\``);
76
+ }
77
+ else if (char === "$") {
78
+ output += decodeHex(buffer);
79
+ buffer = "";
80
+ mode = 0 /* Mode.Text */;
81
+ }
82
+ else {
83
+ buffer += char;
84
+ }
85
+ }
86
+ }
87
+ return output;
88
+ }
89
+ exports.MAGIC_IDENTIFIER_REGEX = /__TURBOPACK__[a-zA-Z0-9_$]+__/g;
@@ -0,0 +1,43 @@
1
+ import * as binding from "./binding";
2
+ import type { NapiWrittenEndpoint, StackFrame } from "./binding";
3
+ import { ProjectOptions, RawEntrypoints, Update } from "./types";
4
+ export declare class TurbopackInternalError extends Error {
5
+ name: string;
6
+ constructor(cause: Error);
7
+ }
8
+ export declare function projectFactory(): (options: ProjectOptions, turboEngineOptions: binding.NapiTurboEngineOptions) => Promise<{
9
+ readonly _nativeProject: {
10
+ __napiType: "Project";
11
+ };
12
+ update(options: Partial<ProjectOptions>): Promise<void>;
13
+ writeAllEntrypointsToDisk(): Promise<TurbopackResult<RawEntrypoints>>;
14
+ entrypointsSubscribe(): AsyncGenerator<{
15
+ apps: {
16
+ readonly _nativeEndpoint: {
17
+ __napiType: "Endpoint";
18
+ };
19
+ writeToDisk(): Promise<TurbopackResult<NapiWrittenEndpoint>>;
20
+ clientChanged(): Promise<AsyncIterableIterator<TurbopackResult<{}>>>;
21
+ serverChanged(includeIssues: boolean): Promise<AsyncIterableIterator<TurbopackResult<{}>>>;
22
+ }[];
23
+ libraries: {
24
+ readonly _nativeEndpoint: {
25
+ __napiType: "Endpoint";
26
+ };
27
+ writeToDisk(): Promise<TurbopackResult<NapiWrittenEndpoint>>;
28
+ clientChanged(): Promise<AsyncIterableIterator<TurbopackResult<{}>>>;
29
+ serverChanged(includeIssues: boolean): Promise<AsyncIterableIterator<TurbopackResult<{}>>>;
30
+ }[];
31
+ issues: binding.NapiIssue[];
32
+ diagnostics: binding.NapiDiagnostic[];
33
+ }, void, unknown>;
34
+ hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
35
+ hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<binding.HmrIdentifiers>>;
36
+ traceSource(stackFrame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>;
37
+ getSourceForAsset(filePath: string): Promise<string | null>;
38
+ getSourceMap(filePath: string): Promise<string | null>;
39
+ getSourceMapSync(filePath: string): string | null;
40
+ updateInfoSubscribe(aggregationMs: number): AsyncIterableIterator<TurbopackResult<binding.NapiUpdateMessage>>;
41
+ shutdown(): Promise<void>;
42
+ onExit(): Promise<void>;
43
+ }>;
package/cjs/project.js ADDED
@@ -0,0 +1,290 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.TurbopackInternalError = void 0;
37
+ exports.projectFactory = projectFactory;
38
+ const util_1 = require("util");
39
+ const binding = __importStar(require("./binding"));
40
+ const nanoid_1 = require("nanoid");
41
+ class TurbopackInternalError extends Error {
42
+ constructor(cause) {
43
+ super(cause.message);
44
+ this.name = "TurbopackInternalError";
45
+ this.stack = cause.stack;
46
+ }
47
+ }
48
+ exports.TurbopackInternalError = TurbopackInternalError;
49
+ async function withErrorCause(fn) {
50
+ try {
51
+ return await fn();
52
+ }
53
+ catch (nativeError) {
54
+ throw new TurbopackInternalError(nativeError);
55
+ }
56
+ }
57
+ function ensureLoadersHaveSerializableOptions(turbopackRules) {
58
+ for (const [glob, rule] of Object.entries(turbopackRules)) {
59
+ if (Array.isArray(rule)) {
60
+ checkLoaderItems(rule, glob);
61
+ }
62
+ else {
63
+ checkConfigItem(rule, glob);
64
+ }
65
+ }
66
+ function checkConfigItem(rule, glob) {
67
+ if (!rule)
68
+ return;
69
+ if ("loaders" in rule) {
70
+ checkLoaderItems(rule.loaders, glob);
71
+ }
72
+ else {
73
+ for (const key in rule) {
74
+ const inner = rule[key];
75
+ if (typeof inner === "object" && inner) {
76
+ checkConfigItem(inner, glob);
77
+ }
78
+ }
79
+ }
80
+ }
81
+ function checkLoaderItems(loaderItems, glob) {
82
+ for (const loaderItem of loaderItems) {
83
+ if (typeof loaderItem !== "string" &&
84
+ !(0, util_1.isDeepStrictEqual)(loaderItem, JSON.parse(JSON.stringify(loaderItem)))) {
85
+ throw new Error(`loader ${loaderItem.loader} for match "${glob}" does not have serializable options. Ensure that options passed are plain JavaScript objects and values.`);
86
+ }
87
+ }
88
+ }
89
+ }
90
+ async function serializeConfig(config) {
91
+ var _a, _b;
92
+ let configSerializable = { ...config };
93
+ configSerializable.generateBuildId = () => (0, nanoid_1.nanoid)();
94
+ if ((_a = configSerializable.module) === null || _a === void 0 ? void 0 : _a.rules) {
95
+ ensureLoadersHaveSerializableOptions(configSerializable.module.rules);
96
+ }
97
+ if (configSerializable.optimization) {
98
+ configSerializable.optimization.modularizeImports =
99
+ configSerializable.optimization &&
100
+ ((_b = configSerializable.optimization) === null || _b === void 0 ? void 0 : _b.modularizeImports)
101
+ ? Object.fromEntries(Object.entries(configSerializable.optimization.modularizeImports).map(([mod, config]) => [
102
+ mod,
103
+ {
104
+ ...config,
105
+ transform: typeof config.transform === "string"
106
+ ? config.transform
107
+ : Object.entries(config.transform).map(([key, value]) => [
108
+ key,
109
+ value,
110
+ ]),
111
+ },
112
+ ]))
113
+ : undefined;
114
+ }
115
+ return JSON.stringify(configSerializable, null, 2);
116
+ }
117
+ function rustifyEnv(env) {
118
+ return Object.entries(env)
119
+ .filter(([_, value]) => value != null)
120
+ .map(([name, value]) => ({
121
+ name,
122
+ value,
123
+ }));
124
+ }
125
+ async function rustifyPartialProjectOptions(options) {
126
+ return {
127
+ ...options,
128
+ config: options.config && (await serializeConfig(options.config)),
129
+ processEnv: options.processEnv && rustifyEnv(options.processEnv),
130
+ };
131
+ }
132
+ async function rustifyProjectOptions(options) {
133
+ var _a;
134
+ return {
135
+ ...options,
136
+ config: await serializeConfig(options.config),
137
+ processEnv: rustifyEnv((_a = options.processEnv) !== null && _a !== void 0 ? _a : {}),
138
+ };
139
+ }
140
+ function projectFactory() {
141
+ const cancel = new (class Cancel extends Error {
142
+ })();
143
+ function subscribe(useBuffer, nativeFunction) {
144
+ // A buffer of produced items. This will only contain values if the
145
+ // consumer is slower than the producer.
146
+ let buffer = [];
147
+ // A deferred value waiting for the next produced item. This will only
148
+ // exist if the consumer is faster than the producer.
149
+ let waiting;
150
+ let canceled = false;
151
+ // The native function will call this every time it emits a new result. We
152
+ // either need to notify a waiting consumer, or buffer the new result until
153
+ // the consumer catches up.
154
+ function emitResult(err, value) {
155
+ if (waiting) {
156
+ let { resolve, reject } = waiting;
157
+ waiting = undefined;
158
+ if (err)
159
+ reject(err);
160
+ else
161
+ resolve(value);
162
+ }
163
+ else {
164
+ const item = { err, value };
165
+ if (useBuffer)
166
+ buffer.push(item);
167
+ else
168
+ buffer[0] = item;
169
+ }
170
+ }
171
+ async function* createIterator() {
172
+ const task = await withErrorCause(() => nativeFunction(emitResult));
173
+ try {
174
+ while (!canceled) {
175
+ if (buffer.length > 0) {
176
+ const item = buffer.shift();
177
+ if (item.err)
178
+ throw item.err;
179
+ yield item.value;
180
+ }
181
+ else {
182
+ // eslint-disable-next-line no-loop-func
183
+ yield new Promise((resolve, reject) => {
184
+ waiting = { resolve, reject };
185
+ });
186
+ }
187
+ }
188
+ }
189
+ catch (e) {
190
+ if (e === cancel)
191
+ return;
192
+ if (e instanceof Error) {
193
+ throw new TurbopackInternalError(e);
194
+ }
195
+ throw e;
196
+ }
197
+ finally {
198
+ if (task) {
199
+ binding.rootTaskDispose(task);
200
+ }
201
+ }
202
+ }
203
+ const iterator = createIterator();
204
+ iterator.return = async () => {
205
+ canceled = true;
206
+ if (waiting)
207
+ waiting.reject(cancel);
208
+ return { value: undefined, done: true };
209
+ };
210
+ return iterator;
211
+ }
212
+ class ProjectImpl {
213
+ constructor(nativeProject) {
214
+ this._nativeProject = nativeProject;
215
+ }
216
+ async update(options) {
217
+ await withErrorCause(async () => binding.projectUpdate(this._nativeProject, await rustifyPartialProjectOptions(options)));
218
+ }
219
+ async writeAllEntrypointsToDisk() {
220
+ return await withErrorCause(async () => {
221
+ const napiEndpoints = (await binding.projectWriteAllEntrypointsToDisk(this._nativeProject));
222
+ return napiEntrypointsToRawEntrypoints(napiEndpoints);
223
+ });
224
+ }
225
+ entrypointsSubscribe() {
226
+ const subscription = subscribe(false, async (callback) => binding.projectEntrypointsSubscribe(this._nativeProject, callback));
227
+ return (async function* () {
228
+ for await (const entrypoints of subscription) {
229
+ yield napiEntrypointsToRawEntrypoints(entrypoints);
230
+ }
231
+ })();
232
+ }
233
+ hmrEvents(identifier) {
234
+ return subscribe(true, async (callback) => binding.projectHmrEvents(this._nativeProject, identifier, callback));
235
+ }
236
+ hmrIdentifiersSubscribe() {
237
+ return subscribe(false, async (callback) => binding.projectHmrIdentifiersSubscribe(this._nativeProject, callback));
238
+ }
239
+ traceSource(stackFrame, currentDirectoryFileUrl) {
240
+ return binding.projectTraceSource(this._nativeProject, stackFrame, currentDirectoryFileUrl);
241
+ }
242
+ getSourceForAsset(filePath) {
243
+ return binding.projectGetSourceForAsset(this._nativeProject, filePath);
244
+ }
245
+ getSourceMap(filePath) {
246
+ return binding.projectGetSourceMap(this._nativeProject, filePath);
247
+ }
248
+ getSourceMapSync(filePath) {
249
+ return binding.projectGetSourceMapSync(this._nativeProject, filePath);
250
+ }
251
+ updateInfoSubscribe(aggregationMs) {
252
+ return subscribe(true, async (callback) => binding.projectUpdateInfoSubscribe(this._nativeProject, aggregationMs, callback));
253
+ }
254
+ shutdown() {
255
+ return binding.projectShutdown(this._nativeProject);
256
+ }
257
+ onExit() {
258
+ return binding.projectOnExit(this._nativeProject);
259
+ }
260
+ }
261
+ class EndpointImpl {
262
+ constructor(nativeEndpoint) {
263
+ this._nativeEndpoint = nativeEndpoint;
264
+ }
265
+ async writeToDisk() {
266
+ return await withErrorCause(() => binding.endpointWriteToDisk(this._nativeEndpoint));
267
+ }
268
+ async clientChanged() {
269
+ const clientSubscription = subscribe(false, async (callback) => binding.endpointClientChangedSubscribe(await this._nativeEndpoint, callback));
270
+ await clientSubscription.next();
271
+ return clientSubscription;
272
+ }
273
+ async serverChanged(includeIssues) {
274
+ const serverSubscription = subscribe(false, async (callback) => binding.endpointServerChangedSubscribe(await this._nativeEndpoint, includeIssues, callback));
275
+ await serverSubscription.next();
276
+ return serverSubscription;
277
+ }
278
+ }
279
+ function napiEntrypointsToRawEntrypoints(entrypoints) {
280
+ return {
281
+ apps: (entrypoints.apps || []).map((e) => new EndpointImpl(e)),
282
+ libraries: (entrypoints.libraries || []).map((e) => new EndpointImpl(e)),
283
+ issues: entrypoints.issues,
284
+ diagnostics: entrypoints.diagnostics,
285
+ };
286
+ }
287
+ return async function createProject(options, turboEngineOptions) {
288
+ return new ProjectImpl(await binding.projectNew(await rustifyProjectOptions(options), turboEngineOptions || {}));
289
+ };
290
+ }
package/cjs/types.d.ts ADDED
@@ -0,0 +1,261 @@
1
+ import { HmrIdentifiers, NapiIssue, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "./binding";
2
+ export interface BaseUpdate {
3
+ resource: {
4
+ headers: unknown;
5
+ path: string;
6
+ };
7
+ diagnostics: unknown[];
8
+ issues: NapiIssue[];
9
+ }
10
+ export interface IssuesUpdate extends BaseUpdate {
11
+ type: "issues";
12
+ }
13
+ export interface EcmascriptMergedUpdate {
14
+ type: "EcmascriptMergedUpdate";
15
+ chunks: {
16
+ [moduleName: string]: {
17
+ type: "partial";
18
+ };
19
+ };
20
+ entries: {
21
+ [moduleName: string]: {
22
+ code: string;
23
+ map: string;
24
+ url: string;
25
+ };
26
+ };
27
+ }
28
+ export interface PartialUpdate extends BaseUpdate {
29
+ type: "partial";
30
+ instruction: {
31
+ type: "ChunkListUpdate";
32
+ merged: EcmascriptMergedUpdate[] | undefined;
33
+ };
34
+ }
35
+ export type Update = IssuesUpdate | PartialUpdate;
36
+ export type RustifiedEnv = {
37
+ name: string;
38
+ value: string;
39
+ }[];
40
+ export interface EntryOptions {
41
+ name?: string;
42
+ import: string;
43
+ library?: LibraryOptions;
44
+ }
45
+ export interface LibraryOptions {
46
+ name?: string;
47
+ export?: Array<string>;
48
+ }
49
+ export interface DefineEnv {
50
+ client: RustifiedEnv;
51
+ edge: RustifiedEnv;
52
+ nodejs: RustifiedEnv;
53
+ }
54
+ export interface ExperimentalConfig {
55
+ }
56
+ export type TurbopackRuleConfigItemOrShortcut = TurbopackRuleConfigItem;
57
+ export type TurbopackRuleConfigItem = TurbopackRuleConfigItemOptions | {
58
+ [condition: string]: TurbopackRuleConfigItem;
59
+ } | false;
60
+ /**
61
+ * @deprecated Use `TurbopackRuleConfigItem` instead.
62
+ */
63
+ export type TurbopackLoaderItem = string | {
64
+ loader: string;
65
+ options: Record<string, JSONValue>;
66
+ };
67
+ export type TurbopackRuleConfigItemOptions = {
68
+ loaders: TurbopackLoaderItem[];
69
+ as?: string;
70
+ };
71
+ export interface ModuleOptions {
72
+ rules?: Record<string, TurbopackRuleConfigItemOrShortcut>;
73
+ }
74
+ export interface ResolveOptions {
75
+ alias?: Record<string, string | string[] | Record<string, string | string[]>>;
76
+ extensions?: string[];
77
+ }
78
+ export type ExternalType = "script" | "commonjs" | "esm" | "global";
79
+ export interface ExternalAdvanced {
80
+ root: string;
81
+ type?: ExternalType;
82
+ script?: string;
83
+ }
84
+ export type ExternalConfig = string | ExternalAdvanced;
85
+ export interface ConfigComplete {
86
+ entry: EntryOptions[];
87
+ mode?: "production" | "development";
88
+ module?: ModuleOptions;
89
+ resolve?: ResolveOptions;
90
+ externals?: Record<string, ExternalConfig>;
91
+ output?: {
92
+ path?: string;
93
+ type?: "standalone" | "export";
94
+ filename?: string;
95
+ chunkFilename?: string;
96
+ };
97
+ target?: string;
98
+ sourceMaps?: boolean;
99
+ optimization?: {
100
+ moduleIds?: "named" | "deterministic";
101
+ minify?: boolean;
102
+ treeShaking?: boolean;
103
+ splitChunks?: Record<"js" | "css", {
104
+ minChunkSize?: number;
105
+ maxChunkCountPerGroup?: number;
106
+ maxMergeChunkSize?: number;
107
+ }>;
108
+ modularizeImports?: Record<string, {
109
+ transform: string | Record<string, string>;
110
+ preventFullImport?: boolean;
111
+ skipDefaultConversion?: boolean;
112
+ }>;
113
+ packageImports?: string[];
114
+ transpilePackages?: string[];
115
+ removeConsole?: boolean | {
116
+ exclude?: string[];
117
+ };
118
+ };
119
+ define?: Record<string, string>;
120
+ styles?: {
121
+ sass?: {
122
+ implementation?: string;
123
+ [key: string]: any;
124
+ };
125
+ less?: {
126
+ implementation?: string;
127
+ [key: string]: any;
128
+ };
129
+ styledJsx?: boolean | {
130
+ useLightningcss?: boolean;
131
+ };
132
+ inlineCss?: {
133
+ insert?: string;
134
+ injectType: string;
135
+ };
136
+ styledComponents?: boolean | StyledComponentsConfig;
137
+ emotion?: boolean | EmotionConfig;
138
+ };
139
+ images?: {
140
+ inlineLimit?: number;
141
+ };
142
+ experimental?: ExperimentalConfig;
143
+ persistentCaching?: boolean;
144
+ cacheHandler?: string;
145
+ }
146
+ export interface StyledComponentsConfig {
147
+ /**
148
+ * Enabled by default in development, disabled in production to reduce file size,
149
+ * setting this will override the default for all environments.
150
+ */
151
+ displayName?: boolean;
152
+ topLevelImportPaths?: string[];
153
+ ssr?: boolean;
154
+ fileName?: boolean;
155
+ meaninglessFileNames?: string[];
156
+ minify?: boolean;
157
+ transpileTemplateLiterals?: boolean;
158
+ namespace?: string;
159
+ pure?: boolean;
160
+ cssProp?: boolean;
161
+ }
162
+ export interface EmotionConfig {
163
+ sourceMap?: boolean;
164
+ autoLabel?: "dev-only" | "always" | "never";
165
+ labelFormat?: string;
166
+ importMap?: {
167
+ [importName: string]: {
168
+ [exportName: string]: {
169
+ canonicalImport?: [string, string];
170
+ styledBaseImport?: [string, string];
171
+ };
172
+ };
173
+ };
174
+ }
175
+ export type JSONValue = string | number | boolean | JSONValue[] | {
176
+ [k: string]: JSONValue;
177
+ };
178
+ export interface ProjectOptions {
179
+ /**
180
+ * A root path from which all files must be nested under. Trying to access
181
+ * a file outside this root will fail. Think of this as a chroot.
182
+ */
183
+ rootPath: string;
184
+ /**
185
+ * A path inside the root_path which contains the app/pages directories.
186
+ */
187
+ projectPath: string;
188
+ /**
189
+ * The utoo pack configs.
190
+ */
191
+ config: ConfigComplete;
192
+ /**
193
+ * A map of environment variables to use when compiling code.
194
+ */
195
+ processEnv: Record<string, string>;
196
+ processDefineEnv: DefineEnv;
197
+ /**
198
+ * Whether to watch the filesystem for file changes.
199
+ */
200
+ watch: {
201
+ enable: boolean;
202
+ pollIntervalMs?: number;
203
+ };
204
+ /**
205
+ * The mode in which Next.js is running.
206
+ */
207
+ dev: boolean;
208
+ /**
209
+ * The build id.
210
+ */
211
+ buildId: string;
212
+ }
213
+ export interface Project {
214
+ update(options: Partial<ProjectOptions>): Promise<void>;
215
+ entrypointsSubscribe(): AsyncIterableIterator<TurbopackResult<RawEntrypoints>>;
216
+ hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
217
+ hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<HmrIdentifiers>>;
218
+ getSourceForAsset(filePath: string): Promise<string | null>;
219
+ getSourceMap(filePath: string): Promise<string | null>;
220
+ getSourceMapSync(filePath: string): string | null;
221
+ traceSource(stackFrame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>;
222
+ updateInfoSubscribe(aggregationMs: number): AsyncIterableIterator<TurbopackResult<NapiUpdateMessage>>;
223
+ shutdown(): Promise<void>;
224
+ onExit(): Promise<void>;
225
+ }
226
+ export interface RawEntrypoints {
227
+ apps?: Endpoint[];
228
+ libraries?: Endpoint[];
229
+ }
230
+ export interface Endpoint {
231
+ /** Write files for the endpoint to disk. */
232
+ writeToDisk(): Promise<TurbopackResult<NapiWrittenEndpoint>>;
233
+ /**
234
+ * Listen to client-side changes to the endpoint.
235
+ * After clientChanged() has been awaited it will listen to changes.
236
+ * The async iterator will yield for each change.
237
+ */
238
+ clientChanged(): Promise<AsyncIterableIterator<TurbopackResult>>;
239
+ /**
240
+ * Listen to server-side changes to the endpoint.
241
+ * After serverChanged() has been awaited it will listen to changes.
242
+ * The async iterator will yield for each change.
243
+ */
244
+ serverChanged(includeIssues: boolean): Promise<AsyncIterableIterator<TurbopackResult>>;
245
+ }
246
+ export type StyledString = {
247
+ type: "text";
248
+ value: string;
249
+ } | {
250
+ type: "code";
251
+ value: string;
252
+ } | {
253
+ type: "strong";
254
+ value: string;
255
+ } | {
256
+ type: "stack";
257
+ value: StyledString[];
258
+ } | {
259
+ type: "line";
260
+ value: StyledString[];
261
+ };
package/cjs/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/util.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { NapiIssue } from "./binding";
2
+ import { StyledString } from "./types";
3
+ export declare class ModuleBuildError extends Error {
4
+ name: string;
5
+ }
6
+ export declare function processIssues(result: TurbopackResult, throwIssue: boolean, logErrors: boolean): void;
7
+ export declare function isWellKnownError(issue: NapiIssue): boolean;
8
+ export declare function formatIssue(issue: NapiIssue): string;
9
+ export declare function renderStyledStringToErrorAnsi(string: StyledString): string;
10
+ export declare function isRelevantWarning(issue: NapiIssue): boolean;