@utoo/pack 1.1.2-alpha.5 → 1.1.2-lingguang
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/README.md +2 -2
- package/cjs/index.d.ts +7 -6
- package/cjs/index.js +6 -5
- package/config_schema.json +1 -1
- package/esm/index.d.ts +7 -6
- package/esm/index.js +6 -5
- package/package.json +19 -18
- package/cjs/build.d.ts +0 -3
- package/cjs/build.js +0 -82
- package/cjs/dev.d.ts +0 -43
- package/cjs/dev.js +0 -376
- package/cjs/find-root.d.ts +0 -4
- package/cjs/find-root.js +0 -75
- package/cjs/hmr.d.ts +0 -80
- package/cjs/hmr.js +0 -286
- package/cjs/loaderWorkerPool.d.ts +0 -1
- package/cjs/loaderWorkerPool.js +0 -35
- package/cjs/mkcert.d.ts +0 -7
- package/cjs/mkcert.js +0 -183
- package/cjs/project.d.ts +0 -43
- package/cjs/project.js +0 -285
- package/cjs/types.d.ts +0 -284
- package/cjs/types.js +0 -2
- package/cjs/util.d.ts +0 -19
- package/cjs/util.js +0 -155
- package/cjs/webpackCompat.d.ts +0 -7
- package/cjs/webpackCompat.js +0 -382
- package/cjs/xcodeProfile.d.ts +0 -1
- package/cjs/xcodeProfile.js +0 -16
- package/esm/build.d.ts +0 -3
- package/esm/build.js +0 -79
- package/esm/dev.d.ts +0 -43
- package/esm/dev.js +0 -360
- package/esm/find-root.d.ts +0 -4
- package/esm/find-root.js +0 -66
- package/esm/hmr.d.ts +0 -80
- package/esm/hmr.js +0 -279
- package/esm/loaderWorkerPool.d.ts +0 -1
- package/esm/loaderWorkerPool.js +0 -32
- package/esm/mkcert.d.ts +0 -7
- package/esm/mkcert.js +0 -176
- package/esm/project.d.ts +0 -43
- package/esm/project.js +0 -247
- package/esm/types.d.ts +0 -284
- package/esm/types.js +0 -1
- package/esm/util.d.ts +0 -19
- package/esm/util.js +0 -141
- package/esm/webpackCompat.d.ts +0 -7
- package/esm/webpackCompat.js +0 -375
- package/esm/xcodeProfile.d.ts +0 -1
- package/esm/xcodeProfile.js +0 -13
package/esm/project.js
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import { isDeepStrictEqual } from "util";
|
|
2
|
-
import * as binding from "./binding";
|
|
3
|
-
import { runLoaderWorkerPool } from "./loaderWorkerPool";
|
|
4
|
-
import { rustifyEnv } from "./util";
|
|
5
|
-
export class TurbopackInternalError extends Error {
|
|
6
|
-
constructor(cause) {
|
|
7
|
-
super(cause.message);
|
|
8
|
-
this.name = "TurbopackInternalError";
|
|
9
|
-
this.stack = cause.stack;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
async function withErrorCause(fn) {
|
|
13
|
-
try {
|
|
14
|
-
return await fn();
|
|
15
|
-
}
|
|
16
|
-
catch (nativeError) {
|
|
17
|
-
throw new TurbopackInternalError(nativeError);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function ensureLoadersHaveSerializableOptions(turbopackRules) {
|
|
21
|
-
for (const [glob, rule] of Object.entries(turbopackRules)) {
|
|
22
|
-
if (Array.isArray(rule)) {
|
|
23
|
-
checkLoaderItems(rule, glob);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
checkConfigItem(rule, glob);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function checkConfigItem(rule, glob) {
|
|
30
|
-
if (!rule)
|
|
31
|
-
return;
|
|
32
|
-
if ("loaders" in rule) {
|
|
33
|
-
checkLoaderItems(rule.loaders, glob);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
for (const key in rule) {
|
|
37
|
-
const inner = rule[key];
|
|
38
|
-
if (typeof inner === "object" && inner) {
|
|
39
|
-
checkConfigItem(inner, glob);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function checkLoaderItems(loaderItems, glob) {
|
|
45
|
-
for (const loaderItem of loaderItems) {
|
|
46
|
-
if (typeof loaderItem !== "string" &&
|
|
47
|
-
!isDeepStrictEqual(loaderItem, JSON.parse(JSON.stringify(loaderItem)))) {
|
|
48
|
-
throw new Error(`loader ${loaderItem.loader} for match "${glob}" does not have serializable options. Ensure that options passed are plain JavaScript objects and values.`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
async function serializeConfig(config) {
|
|
54
|
-
var _a, _b;
|
|
55
|
-
let configSerializable = { ...config };
|
|
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
|
-
async function rustifyPartialProjectOptions(options) {
|
|
80
|
-
return {
|
|
81
|
-
...options,
|
|
82
|
-
config: options.config && (await serializeConfig(options.config)),
|
|
83
|
-
processEnv: options.processEnv && rustifyEnv(options.processEnv),
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
async function rustifyProjectOptions(options) {
|
|
87
|
-
var _a;
|
|
88
|
-
return {
|
|
89
|
-
...options,
|
|
90
|
-
config: await serializeConfig(options.config),
|
|
91
|
-
processEnv: rustifyEnv((_a = options.processEnv) !== null && _a !== void 0 ? _a : {}),
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
export function projectFactory() {
|
|
95
|
-
const cancel = new (class Cancel extends Error {
|
|
96
|
-
})();
|
|
97
|
-
function subscribe(useBuffer, nativeFunction) {
|
|
98
|
-
// A buffer of produced items. This will only contain values if the
|
|
99
|
-
// consumer is slower than the producer.
|
|
100
|
-
let buffer = [];
|
|
101
|
-
// A deferred value waiting for the next produced item. This will only
|
|
102
|
-
// exist if the consumer is faster than the producer.
|
|
103
|
-
let waiting;
|
|
104
|
-
let canceled = false;
|
|
105
|
-
// The native function will call this every time it emits a new result. We
|
|
106
|
-
// either need to notify a waiting consumer, or buffer the new result until
|
|
107
|
-
// the consumer catches up.
|
|
108
|
-
function emitResult(err, value) {
|
|
109
|
-
if (waiting) {
|
|
110
|
-
let { resolve, reject } = waiting;
|
|
111
|
-
waiting = undefined;
|
|
112
|
-
if (err)
|
|
113
|
-
reject(err);
|
|
114
|
-
else
|
|
115
|
-
resolve(value);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
const item = { err, value };
|
|
119
|
-
if (useBuffer)
|
|
120
|
-
buffer.push(item);
|
|
121
|
-
else
|
|
122
|
-
buffer[0] = item;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
async function* createIterator() {
|
|
126
|
-
const task = await withErrorCause(() => nativeFunction(emitResult));
|
|
127
|
-
try {
|
|
128
|
-
while (!canceled) {
|
|
129
|
-
if (buffer.length > 0) {
|
|
130
|
-
const item = buffer.shift();
|
|
131
|
-
if (item.err)
|
|
132
|
-
throw item.err;
|
|
133
|
-
yield item.value;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
// eslint-disable-next-line no-loop-func
|
|
137
|
-
yield new Promise((resolve, reject) => {
|
|
138
|
-
waiting = { resolve, reject };
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
catch (e) {
|
|
144
|
-
if (e === cancel)
|
|
145
|
-
return;
|
|
146
|
-
if (e instanceof Error) {
|
|
147
|
-
throw new TurbopackInternalError(e);
|
|
148
|
-
}
|
|
149
|
-
throw e;
|
|
150
|
-
}
|
|
151
|
-
finally {
|
|
152
|
-
if (task) {
|
|
153
|
-
binding.rootTaskDispose(task);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
const iterator = createIterator();
|
|
158
|
-
iterator.return = async () => {
|
|
159
|
-
canceled = true;
|
|
160
|
-
if (waiting)
|
|
161
|
-
waiting.reject(cancel);
|
|
162
|
-
return { value: undefined, done: true };
|
|
163
|
-
};
|
|
164
|
-
return iterator;
|
|
165
|
-
}
|
|
166
|
-
class ProjectImpl {
|
|
167
|
-
constructor(nativeProject) {
|
|
168
|
-
this._nativeProject = nativeProject;
|
|
169
|
-
if (typeof binding.registerWorkerScheduler === "function") {
|
|
170
|
-
runLoaderWorkerPool(binding, require.resolve("@utoo/pack/cjs/binding.js"));
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
async update(options) {
|
|
174
|
-
await withErrorCause(async () => binding.projectUpdate(this._nativeProject, await rustifyPartialProjectOptions(options)));
|
|
175
|
-
}
|
|
176
|
-
async writeAllEntrypointsToDisk() {
|
|
177
|
-
return await withErrorCause(async () => {
|
|
178
|
-
const napiEndpoints = (await binding.projectWriteAllEntrypointsToDisk(this._nativeProject));
|
|
179
|
-
return napiEntrypointsToRawEntrypoints(napiEndpoints);
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
entrypointsSubscribe() {
|
|
183
|
-
const subscription = subscribe(false, async (callback) => binding.projectEntrypointsSubscribe(this._nativeProject, callback));
|
|
184
|
-
return (async function* () {
|
|
185
|
-
for await (const entrypoints of subscription) {
|
|
186
|
-
yield napiEntrypointsToRawEntrypoints(entrypoints);
|
|
187
|
-
}
|
|
188
|
-
})();
|
|
189
|
-
}
|
|
190
|
-
hmrEvents(identifier) {
|
|
191
|
-
return subscribe(true, async (callback) => binding.projectHmrEvents(this._nativeProject, identifier, callback));
|
|
192
|
-
}
|
|
193
|
-
hmrIdentifiersSubscribe() {
|
|
194
|
-
return subscribe(false, async (callback) => binding.projectHmrIdentifiersSubscribe(this._nativeProject, callback));
|
|
195
|
-
}
|
|
196
|
-
traceSource(stackFrame, currentDirectoryFileUrl) {
|
|
197
|
-
return binding.projectTraceSource(this._nativeProject, stackFrame, currentDirectoryFileUrl);
|
|
198
|
-
}
|
|
199
|
-
getSourceForAsset(filePath) {
|
|
200
|
-
return binding.projectGetSourceForAsset(this._nativeProject, filePath);
|
|
201
|
-
}
|
|
202
|
-
getSourceMap(filePath) {
|
|
203
|
-
return binding.projectGetSourceMap(this._nativeProject, filePath);
|
|
204
|
-
}
|
|
205
|
-
getSourceMapSync(filePath) {
|
|
206
|
-
return binding.projectGetSourceMapSync(this._nativeProject, filePath);
|
|
207
|
-
}
|
|
208
|
-
updateInfoSubscribe(aggregationMs) {
|
|
209
|
-
return subscribe(true, async (callback) => binding.projectUpdateInfoSubscribe(this._nativeProject, aggregationMs, callback));
|
|
210
|
-
}
|
|
211
|
-
shutdown() {
|
|
212
|
-
return binding.projectShutdown(this._nativeProject);
|
|
213
|
-
}
|
|
214
|
-
onExit() {
|
|
215
|
-
return binding.projectOnExit(this._nativeProject);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
class EndpointImpl {
|
|
219
|
-
constructor(nativeEndpoint) {
|
|
220
|
-
this._nativeEndpoint = nativeEndpoint;
|
|
221
|
-
}
|
|
222
|
-
async writeToDisk() {
|
|
223
|
-
return await withErrorCause(() => binding.endpointWriteToDisk(this._nativeEndpoint));
|
|
224
|
-
}
|
|
225
|
-
async clientChanged() {
|
|
226
|
-
const clientSubscription = subscribe(false, async (callback) => binding.endpointClientChangedSubscribe(await this._nativeEndpoint, callback));
|
|
227
|
-
await clientSubscription.next();
|
|
228
|
-
return clientSubscription;
|
|
229
|
-
}
|
|
230
|
-
async serverChanged(includeIssues) {
|
|
231
|
-
const serverSubscription = subscribe(false, async (callback) => binding.endpointServerChangedSubscribe(await this._nativeEndpoint, includeIssues, callback));
|
|
232
|
-
await serverSubscription.next();
|
|
233
|
-
return serverSubscription;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
function napiEntrypointsToRawEntrypoints(entrypoints) {
|
|
237
|
-
return {
|
|
238
|
-
apps: (entrypoints.apps || []).map((e) => new EndpointImpl(e)),
|
|
239
|
-
libraries: (entrypoints.libraries || []).map((e) => new EndpointImpl(e)),
|
|
240
|
-
issues: entrypoints.issues,
|
|
241
|
-
diagnostics: entrypoints.diagnostics,
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
return async function createProject(options, turboEngineOptions) {
|
|
245
|
-
return new ProjectImpl(await binding.projectNew(await rustifyProjectOptions(options), turboEngineOptions || {}));
|
|
246
|
-
};
|
|
247
|
-
}
|
package/esm/types.d.ts
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
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
|
-
}
|
|
15
|
-
export interface BaseUpdate {
|
|
16
|
-
resource: {
|
|
17
|
-
headers: unknown;
|
|
18
|
-
path: string;
|
|
19
|
-
};
|
|
20
|
-
diagnostics: unknown[];
|
|
21
|
-
issues: NapiIssue[];
|
|
22
|
-
}
|
|
23
|
-
export interface IssuesUpdate extends BaseUpdate {
|
|
24
|
-
type: "issues";
|
|
25
|
-
}
|
|
26
|
-
export interface EcmascriptMergedUpdate {
|
|
27
|
-
type: "EcmascriptMergedUpdate";
|
|
28
|
-
chunks: {
|
|
29
|
-
[moduleName: string]: {
|
|
30
|
-
type: "partial";
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
entries: {
|
|
34
|
-
[moduleName: string]: {
|
|
35
|
-
code: string;
|
|
36
|
-
map: string;
|
|
37
|
-
url: string;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export interface PartialUpdate extends BaseUpdate {
|
|
42
|
-
type: "partial";
|
|
43
|
-
instruction: {
|
|
44
|
-
type: "ChunkListUpdate";
|
|
45
|
-
merged: EcmascriptMergedUpdate[] | undefined;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
export type Update = IssuesUpdate | PartialUpdate;
|
|
49
|
-
export type RustifiedEnv = {
|
|
50
|
-
name: string;
|
|
51
|
-
value: string;
|
|
52
|
-
}[];
|
|
53
|
-
export interface EntryOptions {
|
|
54
|
-
name?: string;
|
|
55
|
-
import: string;
|
|
56
|
-
library?: LibraryOptions;
|
|
57
|
-
}
|
|
58
|
-
export interface LibraryOptions {
|
|
59
|
-
name?: string;
|
|
60
|
-
export?: Array<string>;
|
|
61
|
-
}
|
|
62
|
-
export interface DefineEnv {
|
|
63
|
-
client: RustifiedEnv;
|
|
64
|
-
edge: RustifiedEnv;
|
|
65
|
-
nodejs: RustifiedEnv;
|
|
66
|
-
}
|
|
67
|
-
export interface ExperimentalConfig {
|
|
68
|
-
}
|
|
69
|
-
export type TurbopackRuleConfigItem = TurbopackRuleConfigItemOptions | {
|
|
70
|
-
[condition: string]: TurbopackRuleConfigItem;
|
|
71
|
-
} | false;
|
|
72
|
-
/**
|
|
73
|
-
* @deprecated Use `TurbopackRuleConfigItem` instead.
|
|
74
|
-
*/
|
|
75
|
-
export type TurbopackLoaderItem = string | {
|
|
76
|
-
loader: string;
|
|
77
|
-
options: Record<string, JSONValue>;
|
|
78
|
-
};
|
|
79
|
-
export type TurbopackRuleConfigItemOrShortcut = TurbopackLoaderItem[] | TurbopackRuleConfigItem;
|
|
80
|
-
export type TurbopackRuleConfigItemOptions = {
|
|
81
|
-
loaders: TurbopackLoaderItem[];
|
|
82
|
-
as?: string;
|
|
83
|
-
};
|
|
84
|
-
export type TurbopackRuleCondition = {
|
|
85
|
-
path: string | RegExp;
|
|
86
|
-
};
|
|
87
|
-
export interface ModuleOptions {
|
|
88
|
-
rules?: Record<string, TurbopackRuleConfigItem>;
|
|
89
|
-
}
|
|
90
|
-
export interface ResolveOptions {
|
|
91
|
-
alias?: Record<string, string | string[] | Record<string, string | string[]>>;
|
|
92
|
-
extensions?: string[];
|
|
93
|
-
}
|
|
94
|
-
export type ExternalType = "script" | "commonjs" | "esm" | "global";
|
|
95
|
-
export interface ExternalAdvanced {
|
|
96
|
-
root: string;
|
|
97
|
-
type?: ExternalType;
|
|
98
|
-
script?: string;
|
|
99
|
-
}
|
|
100
|
-
export type ExternalConfig = string | ExternalAdvanced;
|
|
101
|
-
export interface ConfigComplete {
|
|
102
|
-
entry: EntryOptions[];
|
|
103
|
-
mode?: "production" | "development";
|
|
104
|
-
module?: ModuleOptions;
|
|
105
|
-
resolve?: ResolveOptions;
|
|
106
|
-
externals?: Record<string, ExternalConfig>;
|
|
107
|
-
output?: {
|
|
108
|
-
path?: string;
|
|
109
|
-
type?: "standalone" | "export";
|
|
110
|
-
filename?: string;
|
|
111
|
-
chunkFilename?: string;
|
|
112
|
-
clean?: boolean;
|
|
113
|
-
copy?: Array<{
|
|
114
|
-
from: string;
|
|
115
|
-
to?: string;
|
|
116
|
-
} | string>;
|
|
117
|
-
publicPath?: string;
|
|
118
|
-
};
|
|
119
|
-
target?: string;
|
|
120
|
-
sourceMaps?: boolean;
|
|
121
|
-
define?: Record<string, string>;
|
|
122
|
-
optimization?: {
|
|
123
|
-
moduleIds?: "named" | "deterministic";
|
|
124
|
-
minify?: boolean;
|
|
125
|
-
treeShaking?: boolean;
|
|
126
|
-
splitChunks?: Record<"js" | "css", {
|
|
127
|
-
minChunkSize?: number;
|
|
128
|
-
maxChunkCountPerGroup?: number;
|
|
129
|
-
maxMergeChunkSize?: number;
|
|
130
|
-
}>;
|
|
131
|
-
modularizeImports?: Record<string, {
|
|
132
|
-
transform: string | Record<string, string>;
|
|
133
|
-
preventFullImport?: boolean;
|
|
134
|
-
skipDefaultConversion?: boolean;
|
|
135
|
-
handleDefaultImport?: boolean;
|
|
136
|
-
handleNamespaceImport?: boolean;
|
|
137
|
-
style?: string;
|
|
138
|
-
}>;
|
|
139
|
-
packageImports?: string[];
|
|
140
|
-
transpilePackages?: string[];
|
|
141
|
-
removeConsole?: boolean | {
|
|
142
|
-
exclude?: string[];
|
|
143
|
-
};
|
|
144
|
-
concatenateModules?: boolean;
|
|
145
|
-
removeUnusedExports?: boolean;
|
|
146
|
-
nestedAsyncChunking?: boolean;
|
|
147
|
-
wasmAsAsset?: boolean;
|
|
148
|
-
};
|
|
149
|
-
styles?: {
|
|
150
|
-
less?: {
|
|
151
|
-
implementation?: string;
|
|
152
|
-
[key: string]: any;
|
|
153
|
-
};
|
|
154
|
-
sass?: {
|
|
155
|
-
implementation?: string;
|
|
156
|
-
[key: string]: any;
|
|
157
|
-
};
|
|
158
|
-
inlineCss?: {
|
|
159
|
-
insert?: string;
|
|
160
|
-
injectType?: string;
|
|
161
|
-
};
|
|
162
|
-
styledJsx?: boolean | {
|
|
163
|
-
useLightningcss?: boolean;
|
|
164
|
-
};
|
|
165
|
-
styledComponents?: boolean | StyledComponentsConfig;
|
|
166
|
-
emotion?: boolean | EmotionConfig;
|
|
167
|
-
};
|
|
168
|
-
images?: {
|
|
169
|
-
inlineLimit?: number;
|
|
170
|
-
};
|
|
171
|
-
stats?: boolean;
|
|
172
|
-
persistentCaching?: boolean;
|
|
173
|
-
nodePolyfill?: boolean;
|
|
174
|
-
devServer?: {
|
|
175
|
-
hot: boolean;
|
|
176
|
-
};
|
|
177
|
-
cacheHandler?: string;
|
|
178
|
-
experimental?: ExperimentalConfig;
|
|
179
|
-
}
|
|
180
|
-
export interface StyledComponentsConfig {
|
|
181
|
-
/**
|
|
182
|
-
* Enabled by default in development, disabled in production to reduce file size,
|
|
183
|
-
* setting this will override the default for all environments.
|
|
184
|
-
*/
|
|
185
|
-
displayName?: boolean;
|
|
186
|
-
topLevelImportPaths?: string[];
|
|
187
|
-
ssr?: boolean;
|
|
188
|
-
fileName?: boolean;
|
|
189
|
-
meaninglessFileNames?: string[];
|
|
190
|
-
minify?: boolean;
|
|
191
|
-
transpileTemplateLiterals?: boolean;
|
|
192
|
-
namespace?: string;
|
|
193
|
-
pure?: boolean;
|
|
194
|
-
cssProp?: boolean;
|
|
195
|
-
}
|
|
196
|
-
export interface EmotionConfig {
|
|
197
|
-
sourceMap?: boolean;
|
|
198
|
-
autoLabel?: "dev-only" | "always" | "never";
|
|
199
|
-
labelFormat?: string;
|
|
200
|
-
importMap?: {
|
|
201
|
-
[importName: string]: {
|
|
202
|
-
[exportName: string]: {
|
|
203
|
-
canonicalImport?: [string, string];
|
|
204
|
-
styledBaseImport?: [string, string];
|
|
205
|
-
};
|
|
206
|
-
};
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
export type JSONValue = string | number | boolean | JSONValue[] | {
|
|
210
|
-
[k: string]: JSONValue;
|
|
211
|
-
};
|
|
212
|
-
export interface ProjectOptions {
|
|
213
|
-
/**
|
|
214
|
-
* A root path from which all files must be nested under. Trying to access
|
|
215
|
-
* a file outside this root will fail. Think of this as a chroot.
|
|
216
|
-
*/
|
|
217
|
-
rootPath: string;
|
|
218
|
-
/**
|
|
219
|
-
* A path inside the root_path which contains the app/pages directories.
|
|
220
|
-
*/
|
|
221
|
-
projectPath: string;
|
|
222
|
-
/**
|
|
223
|
-
* The utoo pack configs.
|
|
224
|
-
*/
|
|
225
|
-
config: ConfigComplete;
|
|
226
|
-
/**
|
|
227
|
-
* A map of environment variables to use when compiling code.
|
|
228
|
-
*/
|
|
229
|
-
processEnv?: Record<string, string>;
|
|
230
|
-
defineEnv?: DefineEnv;
|
|
231
|
-
/**
|
|
232
|
-
* Whether to watch the filesystem for file changes.
|
|
233
|
-
*/
|
|
234
|
-
watch?: {
|
|
235
|
-
enable: boolean;
|
|
236
|
-
pollIntervalMs?: number;
|
|
237
|
-
};
|
|
238
|
-
/**
|
|
239
|
-
* The mode of utoo-pack.
|
|
240
|
-
*/
|
|
241
|
-
dev?: boolean;
|
|
242
|
-
/**
|
|
243
|
-
* The build id.
|
|
244
|
-
*/
|
|
245
|
-
buildId?: string;
|
|
246
|
-
/**
|
|
247
|
-
* Absolute path for `@utoo/pack`.
|
|
248
|
-
*/
|
|
249
|
-
packPath?: string;
|
|
250
|
-
}
|
|
251
|
-
export type BundleOptions = Omit<ProjectOptions, "rootPath" | "projectPath">;
|
|
252
|
-
export interface Project {
|
|
253
|
-
update(options: Partial<ProjectOptions>): Promise<void>;
|
|
254
|
-
entrypointsSubscribe(): AsyncIterableIterator<TurbopackResult<RawEntrypoints>>;
|
|
255
|
-
hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
|
|
256
|
-
hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<HmrIdentifiers>>;
|
|
257
|
-
getSourceForAsset(filePath: string): Promise<string | null>;
|
|
258
|
-
getSourceMap(filePath: string): Promise<string | null>;
|
|
259
|
-
getSourceMapSync(filePath: string): string | null;
|
|
260
|
-
traceSource(stackFrame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>;
|
|
261
|
-
updateInfoSubscribe(aggregationMs: number): AsyncIterableIterator<TurbopackResult<NapiUpdateMessage>>;
|
|
262
|
-
shutdown(): Promise<void>;
|
|
263
|
-
onExit(): Promise<void>;
|
|
264
|
-
}
|
|
265
|
-
export interface RawEntrypoints {
|
|
266
|
-
apps?: Endpoint[];
|
|
267
|
-
libraries?: Endpoint[];
|
|
268
|
-
}
|
|
269
|
-
export interface Endpoint {
|
|
270
|
-
/** Write files for the endpoint to disk. */
|
|
271
|
-
writeToDisk(): Promise<TurbopackResult<NapiWrittenEndpoint>>;
|
|
272
|
-
/**
|
|
273
|
-
* Listen to client-side changes to the endpoint.
|
|
274
|
-
* After clientChanged() has been awaited it will listen to changes.
|
|
275
|
-
* The async iterator will yield for each change.
|
|
276
|
-
*/
|
|
277
|
-
clientChanged(): Promise<AsyncIterableIterator<TurbopackResult>>;
|
|
278
|
-
/**
|
|
279
|
-
* Listen to server-side changes to the endpoint.
|
|
280
|
-
* After serverChanged() has been awaited it will listen to changes.
|
|
281
|
-
* The async iterator will yield for each change.
|
|
282
|
-
*/
|
|
283
|
-
serverChanged(includeIssues: boolean): Promise<AsyncIterableIterator<TurbopackResult>>;
|
|
284
|
-
}
|
package/esm/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/util.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { NapiIssue } from "./binding";
|
|
2
|
-
import { ConfigComplete, DefineEnv, RustifiedEnv } 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 rustifyEnv(env: Record<string, string>): RustifiedEnv;
|
|
9
|
-
interface DefineEnvOptions {
|
|
10
|
-
config: ConfigComplete;
|
|
11
|
-
dev: boolean;
|
|
12
|
-
optionDefineEnv?: DefineEnv;
|
|
13
|
-
}
|
|
14
|
-
export declare function createDefineEnv(options: DefineEnvOptions): DefineEnv;
|
|
15
|
-
type AnyFunc<T> = (this: T, ...args: any) => any;
|
|
16
|
-
export declare function debounce<T, F extends AnyFunc<T>>(fn: F, ms: number, maxWait?: number): (this: T, ...passedArgs: Parameters<F>) => void;
|
|
17
|
-
export declare function blockStdout(): void;
|
|
18
|
-
export declare function getPackPath(): string;
|
|
19
|
-
export {};
|
package/esm/util.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { formatIssue, renderStyledStringToErrorAnsi } from "@utoo/pack-shared";
|
|
2
|
-
import path from "path";
|
|
3
|
-
export class ModuleBuildError extends Error {
|
|
4
|
-
constructor() {
|
|
5
|
-
super(...arguments);
|
|
6
|
-
this.name = "ModuleBuildError";
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export function processIssues(result, throwIssue, logErrors) {
|
|
10
|
-
const relevantIssues = new Set();
|
|
11
|
-
for (const issue of result.issues) {
|
|
12
|
-
if (issue.severity !== "error" &&
|
|
13
|
-
issue.severity !== "fatal" &&
|
|
14
|
-
issue.severity !== "warning")
|
|
15
|
-
continue;
|
|
16
|
-
if (issue.severity !== "warning") {
|
|
17
|
-
if (throwIssue) {
|
|
18
|
-
const formatted = formatIssue(issue);
|
|
19
|
-
relevantIssues.add(formatted);
|
|
20
|
-
}
|
|
21
|
-
// if we throw the issue it will most likely get handed and logged elsewhere
|
|
22
|
-
else if (logErrors && isWellKnownError(issue)) {
|
|
23
|
-
const formatted = formatIssue(issue);
|
|
24
|
-
console.error(formatted);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (relevantIssues.size && throwIssue) {
|
|
29
|
-
throw new ModuleBuildError([...relevantIssues].join("\n\n"));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export function isWellKnownError(issue) {
|
|
33
|
-
const { title } = issue;
|
|
34
|
-
const formattedTitle = renderStyledStringToErrorAnsi(title);
|
|
35
|
-
// TODO: add more well known errors
|
|
36
|
-
if (formattedTitle.includes("Module not found") ||
|
|
37
|
-
formattedTitle.includes("Unknown module type")) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
export function rustifyEnv(env) {
|
|
43
|
-
return Object.entries(env)
|
|
44
|
-
.filter(([_, value]) => value != null)
|
|
45
|
-
.map(([name, value]) => ({
|
|
46
|
-
name,
|
|
47
|
-
value,
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
export function createDefineEnv(options) {
|
|
51
|
-
var _a;
|
|
52
|
-
let defineEnv = (_a = options.optionDefineEnv) !== null && _a !== void 0 ? _a : {
|
|
53
|
-
client: [],
|
|
54
|
-
edge: [],
|
|
55
|
-
nodejs: [],
|
|
56
|
-
};
|
|
57
|
-
function getDefineEnv() {
|
|
58
|
-
var _a;
|
|
59
|
-
const envs = {
|
|
60
|
-
"process.env.NODE_ENV": options.dev ? "development" : "production",
|
|
61
|
-
};
|
|
62
|
-
const userDefines = (_a = options.config.define) !== null && _a !== void 0 ? _a : {};
|
|
63
|
-
for (const key in userDefines) {
|
|
64
|
-
envs[key] = userDefines[key];
|
|
65
|
-
}
|
|
66
|
-
// serialize
|
|
67
|
-
const defineEnvStringified = {};
|
|
68
|
-
for (const key in defineEnv) {
|
|
69
|
-
const value = envs[key];
|
|
70
|
-
defineEnvStringified[key] = JSON.stringify(value);
|
|
71
|
-
}
|
|
72
|
-
return defineEnvStringified;
|
|
73
|
-
}
|
|
74
|
-
// TODO: future define envs need to extends for more compiler like server or edge.
|
|
75
|
-
for (const variant of Object.keys(defineEnv)) {
|
|
76
|
-
defineEnv[variant] = rustifyEnv(getDefineEnv());
|
|
77
|
-
}
|
|
78
|
-
return defineEnv;
|
|
79
|
-
}
|
|
80
|
-
export function debounce(fn, ms, maxWait = Infinity) {
|
|
81
|
-
let timeoutId;
|
|
82
|
-
// The time the debouncing function was first called during this debounce queue.
|
|
83
|
-
let startTime = 0;
|
|
84
|
-
// The time the debouncing function was last called.
|
|
85
|
-
let lastCall = 0;
|
|
86
|
-
// The arguments and this context of the last call to the debouncing function.
|
|
87
|
-
let args, context;
|
|
88
|
-
// A helper used to that either invokes the debounced function, or
|
|
89
|
-
// reschedules the timer if a more recent call was made.
|
|
90
|
-
function run() {
|
|
91
|
-
const now = Date.now();
|
|
92
|
-
const diff = lastCall + ms - now;
|
|
93
|
-
// If the diff is non-positive, then we've waited at least `ms`
|
|
94
|
-
// milliseconds since the last call. Or if we've waited for longer than the
|
|
95
|
-
// max wait time, we must call the debounced function.
|
|
96
|
-
if (diff <= 0 || startTime + maxWait >= now) {
|
|
97
|
-
// It's important to clear the timeout id before invoking the debounced
|
|
98
|
-
// function, in case the function calls the debouncing function again.
|
|
99
|
-
timeoutId = undefined;
|
|
100
|
-
fn.apply(context, args);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
// Else, a new call was made after the original timer was scheduled. We
|
|
104
|
-
// didn't clear the timeout (doing so is very slow), so now we need to
|
|
105
|
-
// reschedule the timer for the time difference.
|
|
106
|
-
timeoutId = setTimeout(run, diff);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return function (...passedArgs) {
|
|
110
|
-
// The arguments and this context of the most recent call are saved so the
|
|
111
|
-
// debounced function can be invoked with them later.
|
|
112
|
-
args = passedArgs;
|
|
113
|
-
context = this;
|
|
114
|
-
// Instead of constantly clearing and scheduling a timer, we record the
|
|
115
|
-
// time of the last call. If a second call comes in before the timer fires,
|
|
116
|
-
// then we'll reschedule in the run function. Doing this is considerably
|
|
117
|
-
// faster.
|
|
118
|
-
lastCall = Date.now();
|
|
119
|
-
// Only schedule a new timer if we're not currently waiting.
|
|
120
|
-
if (timeoutId === undefined) {
|
|
121
|
-
startTime = lastCall;
|
|
122
|
-
timeoutId = setTimeout(run, ms);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
// ref:
|
|
127
|
-
// https://github.com/vercel/next.js/pull/51883
|
|
128
|
-
export function blockStdout() {
|
|
129
|
-
// rust needs stdout to be blocking, otherwise it will throw an error (on macOS at least) when writing a lot of data (logs) to it
|
|
130
|
-
// see https://github.com/napi-rs/napi-rs/issues/1630
|
|
131
|
-
// and https://github.com/nodejs/node/blob/main/doc/api/process.md#a-note-on-process-io
|
|
132
|
-
if (process.stdout._handle != null) {
|
|
133
|
-
process.stdout._handle.setBlocking(true);
|
|
134
|
-
}
|
|
135
|
-
if (process.stderr._handle != null) {
|
|
136
|
-
process.stderr._handle.setBlocking(true);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
export function getPackPath() {
|
|
140
|
-
return path.resolve(__dirname, "..");
|
|
141
|
-
}
|
package/esm/webpackCompat.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type webpack from "webpack";
|
|
2
|
-
import { BundleOptions } from "./types";
|
|
3
|
-
export declare function readWebpackConfig(projectPath?: string, rootPath?: string): any;
|
|
4
|
-
export type WebpackConfig = Partial<Pick<webpack.Configuration, "name" | "entry" | "mode" | "module" | "resolve" | "externals" | "output" | "target" | "devtool" | "optimization" | "plugins" | "stats">> & {
|
|
5
|
-
webpackMode: true;
|
|
6
|
-
};
|
|
7
|
-
export declare function compatOptionsFromWebpack(webpackConfig: WebpackConfig, projectPath?: string, rootPath?: string): BundleOptions;
|