@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.
- package/bin/cli.js +9 -0
- package/cjs/binding.d.ts +222 -0
- package/cjs/binding.js +341 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +75 -0
- package/cjs/magicIdentifier.d.ts +2 -0
- package/cjs/magicIdentifier.js +89 -0
- package/cjs/project.d.ts +43 -0
- package/cjs/project.js +290 -0
- package/cjs/types.d.ts +261 -0
- package/cjs/types.js +2 -0
- package/cjs/util.d.ts +10 -0
- package/cjs/util.js +139 -0
- package/cjs/xcodeProfile.d.ts +1 -0
- package/cjs/xcodeProfile.js +16 -0
- package/esm/binding.d.ts +222 -0
- package/esm/binding.js +341 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +69 -0
- package/esm/magicIdentifier.d.ts +2 -0
- package/esm/magicIdentifier.js +85 -0
- package/esm/project.d.ts +43 -0
- package/esm/project.js +252 -0
- package/esm/types.d.ts +261 -0
- package/esm/types.js +1 -0
- package/esm/util.d.ts +10 -0
- package/esm/util.js +130 -0
- package/esm/xcodeProfile.d.ts +1 -0
- package/esm/xcodeProfile.js +13 -0
- package/global.d.ts +10 -0
- package/package.json +75 -0
package/esm/project.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "util";
|
|
2
|
+
import * as binding from "./binding";
|
|
3
|
+
import { nanoid } from "nanoid";
|
|
4
|
+
export class TurbopackInternalError extends Error {
|
|
5
|
+
constructor(cause) {
|
|
6
|
+
super(cause.message);
|
|
7
|
+
this.name = "TurbopackInternalError";
|
|
8
|
+
this.stack = cause.stack;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
async function withErrorCause(fn) {
|
|
12
|
+
try {
|
|
13
|
+
return await fn();
|
|
14
|
+
}
|
|
15
|
+
catch (nativeError) {
|
|
16
|
+
throw new TurbopackInternalError(nativeError);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function ensureLoadersHaveSerializableOptions(turbopackRules) {
|
|
20
|
+
for (const [glob, rule] of Object.entries(turbopackRules)) {
|
|
21
|
+
if (Array.isArray(rule)) {
|
|
22
|
+
checkLoaderItems(rule, glob);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
checkConfigItem(rule, glob);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function checkConfigItem(rule, glob) {
|
|
29
|
+
if (!rule)
|
|
30
|
+
return;
|
|
31
|
+
if ("loaders" in rule) {
|
|
32
|
+
checkLoaderItems(rule.loaders, glob);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
for (const key in rule) {
|
|
36
|
+
const inner = rule[key];
|
|
37
|
+
if (typeof inner === "object" && inner) {
|
|
38
|
+
checkConfigItem(inner, glob);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function checkLoaderItems(loaderItems, glob) {
|
|
44
|
+
for (const loaderItem of loaderItems) {
|
|
45
|
+
if (typeof loaderItem !== "string" &&
|
|
46
|
+
!isDeepStrictEqual(loaderItem, JSON.parse(JSON.stringify(loaderItem)))) {
|
|
47
|
+
throw new Error(`loader ${loaderItem.loader} for match "${glob}" does not have serializable options. Ensure that options passed are plain JavaScript objects and values.`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function serializeConfig(config) {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
let configSerializable = { ...config };
|
|
55
|
+
configSerializable.generateBuildId = () => nanoid();
|
|
56
|
+
if ((_a = configSerializable.module) === null || _a === void 0 ? void 0 : _a.rules) {
|
|
57
|
+
ensureLoadersHaveSerializableOptions(configSerializable.module.rules);
|
|
58
|
+
}
|
|
59
|
+
if (configSerializable.optimization) {
|
|
60
|
+
configSerializable.optimization.modularizeImports =
|
|
61
|
+
configSerializable.optimization &&
|
|
62
|
+
((_b = configSerializable.optimization) === null || _b === void 0 ? void 0 : _b.modularizeImports)
|
|
63
|
+
? Object.fromEntries(Object.entries(configSerializable.optimization.modularizeImports).map(([mod, config]) => [
|
|
64
|
+
mod,
|
|
65
|
+
{
|
|
66
|
+
...config,
|
|
67
|
+
transform: typeof config.transform === "string"
|
|
68
|
+
? config.transform
|
|
69
|
+
: Object.entries(config.transform).map(([key, value]) => [
|
|
70
|
+
key,
|
|
71
|
+
value,
|
|
72
|
+
]),
|
|
73
|
+
},
|
|
74
|
+
]))
|
|
75
|
+
: undefined;
|
|
76
|
+
}
|
|
77
|
+
return JSON.stringify(configSerializable, null, 2);
|
|
78
|
+
}
|
|
79
|
+
function rustifyEnv(env) {
|
|
80
|
+
return Object.entries(env)
|
|
81
|
+
.filter(([_, value]) => value != null)
|
|
82
|
+
.map(([name, value]) => ({
|
|
83
|
+
name,
|
|
84
|
+
value,
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
async function rustifyPartialProjectOptions(options) {
|
|
88
|
+
return {
|
|
89
|
+
...options,
|
|
90
|
+
config: options.config && (await serializeConfig(options.config)),
|
|
91
|
+
processEnv: options.processEnv && rustifyEnv(options.processEnv),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
async function rustifyProjectOptions(options) {
|
|
95
|
+
var _a;
|
|
96
|
+
return {
|
|
97
|
+
...options,
|
|
98
|
+
config: await serializeConfig(options.config),
|
|
99
|
+
processEnv: rustifyEnv((_a = options.processEnv) !== null && _a !== void 0 ? _a : {}),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export function projectFactory() {
|
|
103
|
+
const cancel = new (class Cancel extends Error {
|
|
104
|
+
})();
|
|
105
|
+
function subscribe(useBuffer, nativeFunction) {
|
|
106
|
+
// A buffer of produced items. This will only contain values if the
|
|
107
|
+
// consumer is slower than the producer.
|
|
108
|
+
let buffer = [];
|
|
109
|
+
// A deferred value waiting for the next produced item. This will only
|
|
110
|
+
// exist if the consumer is faster than the producer.
|
|
111
|
+
let waiting;
|
|
112
|
+
let canceled = false;
|
|
113
|
+
// The native function will call this every time it emits a new result. We
|
|
114
|
+
// either need to notify a waiting consumer, or buffer the new result until
|
|
115
|
+
// the consumer catches up.
|
|
116
|
+
function emitResult(err, value) {
|
|
117
|
+
if (waiting) {
|
|
118
|
+
let { resolve, reject } = waiting;
|
|
119
|
+
waiting = undefined;
|
|
120
|
+
if (err)
|
|
121
|
+
reject(err);
|
|
122
|
+
else
|
|
123
|
+
resolve(value);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const item = { err, value };
|
|
127
|
+
if (useBuffer)
|
|
128
|
+
buffer.push(item);
|
|
129
|
+
else
|
|
130
|
+
buffer[0] = item;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async function* createIterator() {
|
|
134
|
+
const task = await withErrorCause(() => nativeFunction(emitResult));
|
|
135
|
+
try {
|
|
136
|
+
while (!canceled) {
|
|
137
|
+
if (buffer.length > 0) {
|
|
138
|
+
const item = buffer.shift();
|
|
139
|
+
if (item.err)
|
|
140
|
+
throw item.err;
|
|
141
|
+
yield item.value;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// eslint-disable-next-line no-loop-func
|
|
145
|
+
yield new Promise((resolve, reject) => {
|
|
146
|
+
waiting = { resolve, reject };
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
if (e === cancel)
|
|
153
|
+
return;
|
|
154
|
+
if (e instanceof Error) {
|
|
155
|
+
throw new TurbopackInternalError(e);
|
|
156
|
+
}
|
|
157
|
+
throw e;
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
if (task) {
|
|
161
|
+
binding.rootTaskDispose(task);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const iterator = createIterator();
|
|
166
|
+
iterator.return = async () => {
|
|
167
|
+
canceled = true;
|
|
168
|
+
if (waiting)
|
|
169
|
+
waiting.reject(cancel);
|
|
170
|
+
return { value: undefined, done: true };
|
|
171
|
+
};
|
|
172
|
+
return iterator;
|
|
173
|
+
}
|
|
174
|
+
class ProjectImpl {
|
|
175
|
+
constructor(nativeProject) {
|
|
176
|
+
this._nativeProject = nativeProject;
|
|
177
|
+
}
|
|
178
|
+
async update(options) {
|
|
179
|
+
await withErrorCause(async () => binding.projectUpdate(this._nativeProject, await rustifyPartialProjectOptions(options)));
|
|
180
|
+
}
|
|
181
|
+
async writeAllEntrypointsToDisk() {
|
|
182
|
+
return await withErrorCause(async () => {
|
|
183
|
+
const napiEndpoints = (await binding.projectWriteAllEntrypointsToDisk(this._nativeProject));
|
|
184
|
+
return napiEntrypointsToRawEntrypoints(napiEndpoints);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
entrypointsSubscribe() {
|
|
188
|
+
const subscription = subscribe(false, async (callback) => binding.projectEntrypointsSubscribe(this._nativeProject, callback));
|
|
189
|
+
return (async function* () {
|
|
190
|
+
for await (const entrypoints of subscription) {
|
|
191
|
+
yield napiEntrypointsToRawEntrypoints(entrypoints);
|
|
192
|
+
}
|
|
193
|
+
})();
|
|
194
|
+
}
|
|
195
|
+
hmrEvents(identifier) {
|
|
196
|
+
return subscribe(true, async (callback) => binding.projectHmrEvents(this._nativeProject, identifier, callback));
|
|
197
|
+
}
|
|
198
|
+
hmrIdentifiersSubscribe() {
|
|
199
|
+
return subscribe(false, async (callback) => binding.projectHmrIdentifiersSubscribe(this._nativeProject, callback));
|
|
200
|
+
}
|
|
201
|
+
traceSource(stackFrame, currentDirectoryFileUrl) {
|
|
202
|
+
return binding.projectTraceSource(this._nativeProject, stackFrame, currentDirectoryFileUrl);
|
|
203
|
+
}
|
|
204
|
+
getSourceForAsset(filePath) {
|
|
205
|
+
return binding.projectGetSourceForAsset(this._nativeProject, filePath);
|
|
206
|
+
}
|
|
207
|
+
getSourceMap(filePath) {
|
|
208
|
+
return binding.projectGetSourceMap(this._nativeProject, filePath);
|
|
209
|
+
}
|
|
210
|
+
getSourceMapSync(filePath) {
|
|
211
|
+
return binding.projectGetSourceMapSync(this._nativeProject, filePath);
|
|
212
|
+
}
|
|
213
|
+
updateInfoSubscribe(aggregationMs) {
|
|
214
|
+
return subscribe(true, async (callback) => binding.projectUpdateInfoSubscribe(this._nativeProject, aggregationMs, callback));
|
|
215
|
+
}
|
|
216
|
+
shutdown() {
|
|
217
|
+
return binding.projectShutdown(this._nativeProject);
|
|
218
|
+
}
|
|
219
|
+
onExit() {
|
|
220
|
+
return binding.projectOnExit(this._nativeProject);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
class EndpointImpl {
|
|
224
|
+
constructor(nativeEndpoint) {
|
|
225
|
+
this._nativeEndpoint = nativeEndpoint;
|
|
226
|
+
}
|
|
227
|
+
async writeToDisk() {
|
|
228
|
+
return await withErrorCause(() => binding.endpointWriteToDisk(this._nativeEndpoint));
|
|
229
|
+
}
|
|
230
|
+
async clientChanged() {
|
|
231
|
+
const clientSubscription = subscribe(false, async (callback) => binding.endpointClientChangedSubscribe(await this._nativeEndpoint, callback));
|
|
232
|
+
await clientSubscription.next();
|
|
233
|
+
return clientSubscription;
|
|
234
|
+
}
|
|
235
|
+
async serverChanged(includeIssues) {
|
|
236
|
+
const serverSubscription = subscribe(false, async (callback) => binding.endpointServerChangedSubscribe(await this._nativeEndpoint, includeIssues, callback));
|
|
237
|
+
await serverSubscription.next();
|
|
238
|
+
return serverSubscription;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function napiEntrypointsToRawEntrypoints(entrypoints) {
|
|
242
|
+
return {
|
|
243
|
+
apps: (entrypoints.apps || []).map((e) => new EndpointImpl(e)),
|
|
244
|
+
libraries: (entrypoints.libraries || []).map((e) => new EndpointImpl(e)),
|
|
245
|
+
issues: entrypoints.issues,
|
|
246
|
+
diagnostics: entrypoints.diagnostics,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
return async function createProject(options, turboEngineOptions) {
|
|
250
|
+
return new ProjectImpl(await binding.projectNew(await rustifyProjectOptions(options), turboEngineOptions || {}));
|
|
251
|
+
};
|
|
252
|
+
}
|
package/esm/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/esm/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/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;
|
package/esm/util.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { bold, green, magenta, red } from "picocolors";
|
|
2
|
+
import { codeFrameColumns } from "@babel/code-frame";
|
|
3
|
+
import { decodeMagicIdentifier, MAGIC_IDENTIFIER_REGEX, } from "./magicIdentifier";
|
|
4
|
+
export class ModuleBuildError extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.name = "ModuleBuildError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function processIssues(result, throwIssue, logErrors) {
|
|
11
|
+
const relevantIssues = new Set();
|
|
12
|
+
for (const issue of result.issues) {
|
|
13
|
+
if (issue.severity !== "error" &&
|
|
14
|
+
issue.severity !== "fatal" &&
|
|
15
|
+
issue.severity !== "warning")
|
|
16
|
+
continue;
|
|
17
|
+
if (issue.severity !== "warning") {
|
|
18
|
+
if (throwIssue) {
|
|
19
|
+
const formatted = formatIssue(issue);
|
|
20
|
+
relevantIssues.add(formatted);
|
|
21
|
+
}
|
|
22
|
+
// if we throw the issue it will most likely get handed and logged elsewhere
|
|
23
|
+
else if (logErrors && isWellKnownError(issue)) {
|
|
24
|
+
const formatted = formatIssue(issue);
|
|
25
|
+
console.error(formatted);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (relevantIssues.size && throwIssue) {
|
|
30
|
+
throw new ModuleBuildError([...relevantIssues].join("\n\n"));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function isWellKnownError(issue) {
|
|
34
|
+
const { title } = issue;
|
|
35
|
+
const formattedTitle = renderStyledStringToErrorAnsi(title);
|
|
36
|
+
// TODO: add more well known errors
|
|
37
|
+
if (formattedTitle.includes("Module not found") ||
|
|
38
|
+
formattedTitle.includes("Unknown module type")) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
export function formatIssue(issue) {
|
|
44
|
+
const { filePath, title, description, source } = issue;
|
|
45
|
+
let { documentationLink } = issue;
|
|
46
|
+
let formattedTitle = renderStyledStringToErrorAnsi(title).replace(/\n/g, "\n ");
|
|
47
|
+
let formattedFilePath = filePath
|
|
48
|
+
.replace("[project]/", "./")
|
|
49
|
+
.replaceAll("/./", "/")
|
|
50
|
+
.replace("\\\\?\\", "");
|
|
51
|
+
let message = "";
|
|
52
|
+
if (source && source.range) {
|
|
53
|
+
const { start } = source.range;
|
|
54
|
+
message = `${formattedFilePath}:${start.line + 1}:${start.column + 1}\n${formattedTitle}`;
|
|
55
|
+
}
|
|
56
|
+
else if (formattedFilePath) {
|
|
57
|
+
message = `${formattedFilePath}\n${formattedTitle}`;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
message = formattedTitle;
|
|
61
|
+
}
|
|
62
|
+
message += "\n";
|
|
63
|
+
if ((source === null || source === void 0 ? void 0 : source.range) && source.source.content) {
|
|
64
|
+
const { start, end } = source.range;
|
|
65
|
+
message +=
|
|
66
|
+
codeFrameColumns(source.source.content, {
|
|
67
|
+
start: {
|
|
68
|
+
line: start.line + 1,
|
|
69
|
+
column: start.column + 1,
|
|
70
|
+
},
|
|
71
|
+
end: {
|
|
72
|
+
line: end.line + 1,
|
|
73
|
+
column: end.column + 1,
|
|
74
|
+
},
|
|
75
|
+
}, { forceColor: true }).trim() + "\n\n";
|
|
76
|
+
}
|
|
77
|
+
if (description) {
|
|
78
|
+
message += renderStyledStringToErrorAnsi(description) + "\n\n";
|
|
79
|
+
}
|
|
80
|
+
// TODO: make it possible to enable this for debugging, but not in tests.
|
|
81
|
+
// if (detail) {
|
|
82
|
+
// message += renderStyledStringToErrorAnsi(detail) + '\n\n'
|
|
83
|
+
// }
|
|
84
|
+
// TODO: Include a trace from the issue.
|
|
85
|
+
if (documentationLink) {
|
|
86
|
+
message += documentationLink + "\n\n";
|
|
87
|
+
}
|
|
88
|
+
return message;
|
|
89
|
+
}
|
|
90
|
+
export function renderStyledStringToErrorAnsi(string) {
|
|
91
|
+
function decodeMagicIdentifiers(str) {
|
|
92
|
+
return str.replaceAll(MAGIC_IDENTIFIER_REGEX, (ident) => {
|
|
93
|
+
try {
|
|
94
|
+
return magenta(`{${decodeMagicIdentifier(ident)}}`);
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
return magenta(`{${ident} (decoding failed: ${e})}`);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
switch (string.type) {
|
|
102
|
+
case "text":
|
|
103
|
+
return decodeMagicIdentifiers(string.value);
|
|
104
|
+
case "strong":
|
|
105
|
+
return bold(red(decodeMagicIdentifiers(string.value)));
|
|
106
|
+
case "code":
|
|
107
|
+
return green(decodeMagicIdentifiers(string.value));
|
|
108
|
+
case "line":
|
|
109
|
+
return string.value.map(renderStyledStringToErrorAnsi).join("");
|
|
110
|
+
case "stack":
|
|
111
|
+
return string.value.map(renderStyledStringToErrorAnsi).join("\n");
|
|
112
|
+
default:
|
|
113
|
+
throw new Error("Unknown StyledString type", string);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export function isRelevantWarning(issue) {
|
|
117
|
+
return issue.severity === "warning" && !isNodeModulesIssue(issue);
|
|
118
|
+
}
|
|
119
|
+
function isNodeModulesIssue(issue) {
|
|
120
|
+
if (issue.severity === "warning" && issue.stage === "config") {
|
|
121
|
+
// Override for the externalize issue
|
|
122
|
+
// `Package foo (serverExternalPackages or default list) can't be external`
|
|
123
|
+
if (renderStyledStringToErrorAnsi(issue.title).includes("can't be external")) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return (issue.severity === "warning" &&
|
|
128
|
+
(issue.filePath.match(/^(?:.*[\\/])?node_modules(?:[\\/].*)?$/) !== null ||
|
|
129
|
+
issue.filePath.includes("@utoo/pack")));
|
|
130
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function xcodeProfilingReady(): Promise<void>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export async function xcodeProfilingReady() {
|
|
2
|
+
await new Promise((resolve) => {
|
|
3
|
+
const readline = require("readline");
|
|
4
|
+
const rl = readline.createInterface({
|
|
5
|
+
input: process.stdin,
|
|
6
|
+
output: process.stdout,
|
|
7
|
+
});
|
|
8
|
+
rl.question(`Xcode profile enabled. Current process ${process.title} (${process.pid}) . Press Enter to continue...\n`, () => {
|
|
9
|
+
rl.close();
|
|
10
|
+
resolve();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
}
|
package/global.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NapiDiagnostic, NapiIssue } from "./src/binding";
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
export type TurbopackResult<T = {}> = T & {
|
|
5
|
+
issues: NapiIssue[];
|
|
6
|
+
diagnostics: NapiDiagnostic[];
|
|
7
|
+
};
|
|
8
|
+
export type RefCell = { readonly __tag: unique symbol };
|
|
9
|
+
export type ExternalEndpoint = { readonly __tag: unique symbol };
|
|
10
|
+
}
|