@utoo/pack 1.1.2 → 1.1.3
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 -300
- 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 -408
- 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 -300
- 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 -401
- package/esm/xcodeProfile.d.ts +0 -1
- package/esm/xcodeProfile.js +0 -13
package/esm/dev.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { IncomingMessage, ServerResponse } from "http";
|
|
2
|
-
import send from "send";
|
|
3
|
-
import { Duplex, Writable } from "stream";
|
|
4
|
-
import { BundleOptions } from "./types";
|
|
5
|
-
import { WebpackConfig } from "./webpackCompat";
|
|
6
|
-
export declare function serve(options: BundleOptions | WebpackConfig, projectPath?: string, rootPath?: string, serverOptions?: StartServerOptions): Promise<void>;
|
|
7
|
-
export interface SelfSignedCertificate {
|
|
8
|
-
key: string;
|
|
9
|
-
cert: string;
|
|
10
|
-
rootCA?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface StartServerOptions {
|
|
13
|
-
port: number;
|
|
14
|
-
https?: boolean;
|
|
15
|
-
hostname?: string;
|
|
16
|
-
selfSignedCertificate?: SelfSignedCertificate;
|
|
17
|
-
}
|
|
18
|
-
export type RequestHandler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
19
|
-
export type UpgradeHandler = (req: IncomingMessage, socket: Duplex, head: Buffer) => Promise<void>;
|
|
20
|
-
export type ServerInitResult = {
|
|
21
|
-
requestHandler: RequestHandler;
|
|
22
|
-
upgradeHandler: UpgradeHandler;
|
|
23
|
-
closeUpgraded: () => void;
|
|
24
|
-
};
|
|
25
|
-
export declare function startServer(serverOptions: StartServerOptions, bundleOptions: BundleOptions, projectPath: string, rootPath?: string): Promise<void>;
|
|
26
|
-
export declare function initialize(bundleOptions: BundleOptions, projectPath: string, rootPath?: string): Promise<ServerInitResult>;
|
|
27
|
-
export declare function pipeToNodeResponse(readable: ReadableStream<Uint8Array>, res: ServerResponse, waitUntilForEnd?: Promise<unknown>): Promise<void>;
|
|
28
|
-
export declare function createAbortController(response: Writable): AbortController;
|
|
29
|
-
export declare function isAbortError(e: any): e is Error & {
|
|
30
|
-
name: "AbortError";
|
|
31
|
-
};
|
|
32
|
-
export declare const ResponseAbortedName = "ResponseAborted";
|
|
33
|
-
export declare class ResponseAborted extends Error {
|
|
34
|
-
readonly name = "ResponseAborted";
|
|
35
|
-
}
|
|
36
|
-
export declare class DetachedPromise<T = any> {
|
|
37
|
-
readonly resolve: (value: T | PromiseLike<T>) => void;
|
|
38
|
-
readonly reject: (reason: any) => void;
|
|
39
|
-
readonly promise: Promise<T>;
|
|
40
|
-
constructor();
|
|
41
|
-
}
|
|
42
|
-
export declare function serveStatic(req: IncomingMessage, res: ServerResponse, path: string, opts?: Parameters<typeof send>[2]): Promise<void>;
|
|
43
|
-
export declare function formatHostname(hostname: string): string;
|
package/esm/dev.js
DELETED
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import http from "http";
|
|
3
|
-
import https from "https";
|
|
4
|
-
import { isIPv6 } from "net";
|
|
5
|
-
import path from "path";
|
|
6
|
-
import send from "send";
|
|
7
|
-
import url from "url";
|
|
8
|
-
import { findRootDir } from "./find-root";
|
|
9
|
-
import { createHotReloader } from "./hmr";
|
|
10
|
-
import { createSelfSignedCertificate } from "./mkcert";
|
|
11
|
-
import { blockStdout, getPackPath } from "./util";
|
|
12
|
-
import { compatOptionsFromWebpack } from "./webpackCompat";
|
|
13
|
-
import { xcodeProfilingReady } from "./xcodeProfile";
|
|
14
|
-
export function serve(options, projectPath, rootPath, serverOptions) {
|
|
15
|
-
const bundleOptions = options.webpackMode
|
|
16
|
-
? compatOptionsFromWebpack(options, projectPath, rootPath)
|
|
17
|
-
: options;
|
|
18
|
-
if (!rootPath) {
|
|
19
|
-
// help user to find the rootDir automatically
|
|
20
|
-
rootPath = findRootDir(projectPath || process.cwd());
|
|
21
|
-
}
|
|
22
|
-
return serveInternal(bundleOptions, projectPath, rootPath, serverOptions);
|
|
23
|
-
}
|
|
24
|
-
async function serveInternal(options, projectPath, rootPath, serverOptions) {
|
|
25
|
-
blockStdout();
|
|
26
|
-
if (process.env.XCODE_PROFILE) {
|
|
27
|
-
await xcodeProfilingReady();
|
|
28
|
-
}
|
|
29
|
-
await startServer({
|
|
30
|
-
hostname: (serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.hostname) || "localhost",
|
|
31
|
-
port: (serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.port) || 3000,
|
|
32
|
-
https: serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.https,
|
|
33
|
-
selfSignedCertificate: (serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.https)
|
|
34
|
-
? await createSelfSignedCertificate((serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.hostname) || "localhost")
|
|
35
|
-
: undefined,
|
|
36
|
-
}, {
|
|
37
|
-
...options,
|
|
38
|
-
config: {
|
|
39
|
-
...options.config,
|
|
40
|
-
devServer: { hot: true },
|
|
41
|
-
},
|
|
42
|
-
packPath: getPackPath(),
|
|
43
|
-
}, projectPath || process.cwd(), rootPath);
|
|
44
|
-
}
|
|
45
|
-
export async function startServer(serverOptions, bundleOptions, projectPath, rootPath) {
|
|
46
|
-
let { port, hostname, selfSignedCertificate } = serverOptions;
|
|
47
|
-
process.title = "utoo-pack-dev-server";
|
|
48
|
-
let handlersReady = () => { };
|
|
49
|
-
let handlersError = () => { };
|
|
50
|
-
let handlersPromise = new Promise((resolve, reject) => {
|
|
51
|
-
handlersReady = resolve;
|
|
52
|
-
handlersError = reject;
|
|
53
|
-
});
|
|
54
|
-
let requestHandler = async (req, res) => {
|
|
55
|
-
if (handlersPromise) {
|
|
56
|
-
await handlersPromise;
|
|
57
|
-
return requestHandler(req, res);
|
|
58
|
-
}
|
|
59
|
-
throw new Error("Invariant request handler was not setup");
|
|
60
|
-
};
|
|
61
|
-
let upgradeHandler = async (req, socket, head) => {
|
|
62
|
-
if (handlersPromise) {
|
|
63
|
-
await handlersPromise;
|
|
64
|
-
return upgradeHandler(req, socket, head);
|
|
65
|
-
}
|
|
66
|
-
throw new Error("Invariant upgrade handler was not setup");
|
|
67
|
-
};
|
|
68
|
-
async function requestListener(req, res) {
|
|
69
|
-
try {
|
|
70
|
-
if (handlersPromise) {
|
|
71
|
-
await handlersPromise;
|
|
72
|
-
handlersPromise = undefined;
|
|
73
|
-
}
|
|
74
|
-
await requestHandler(req, res);
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
res.statusCode = 500;
|
|
78
|
-
res.end("Internal Server Error");
|
|
79
|
-
console.error(`Failed to handle request for ${req.url}`);
|
|
80
|
-
console.error(err);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const server = selfSignedCertificate
|
|
84
|
-
? https.createServer({
|
|
85
|
-
key: fs.readFileSync(selfSignedCertificate.key),
|
|
86
|
-
cert: fs.readFileSync(selfSignedCertificate.cert),
|
|
87
|
-
}, requestListener)
|
|
88
|
-
: http.createServer(requestListener);
|
|
89
|
-
server.on("upgrade", async (req, socket, head) => {
|
|
90
|
-
try {
|
|
91
|
-
await upgradeHandler(req, socket, head);
|
|
92
|
-
}
|
|
93
|
-
catch (err) {
|
|
94
|
-
socket.destroy();
|
|
95
|
-
console.error(`Failed to handle request for ${req.url}`);
|
|
96
|
-
console.error(err);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
let portRetryCount = 0;
|
|
100
|
-
const originalPort = port;
|
|
101
|
-
server.on("error", (err) => {
|
|
102
|
-
if (port && err.code === "EADDRINUSE" && portRetryCount < 10) {
|
|
103
|
-
port += 1;
|
|
104
|
-
portRetryCount += 1;
|
|
105
|
-
server.listen(port, hostname);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
console.error(`Failed to start server`);
|
|
109
|
-
console.error(err);
|
|
110
|
-
process.exit(1);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
await new Promise((resolve) => {
|
|
114
|
-
server.on("listening", async () => {
|
|
115
|
-
const addr = server.address();
|
|
116
|
-
const actualHostname = formatHostname(typeof addr === "object"
|
|
117
|
-
? (addr === null || addr === void 0 ? void 0 : addr.address) || hostname || "localhost"
|
|
118
|
-
: addr);
|
|
119
|
-
const formattedHostname = !hostname || actualHostname === "0.0.0.0"
|
|
120
|
-
? "localhost"
|
|
121
|
-
: actualHostname === "[::]"
|
|
122
|
-
? "[::1]"
|
|
123
|
-
: formatHostname(hostname);
|
|
124
|
-
port = typeof addr === "object" ? (addr === null || addr === void 0 ? void 0 : addr.port) || port : port;
|
|
125
|
-
if (portRetryCount) {
|
|
126
|
-
console.warn(`Port ${originalPort} is in use, using available port ${port} instead.`);
|
|
127
|
-
}
|
|
128
|
-
if (process.env.TURBOPACK_DEBUG_JS) {
|
|
129
|
-
console.log(`Listening on ${serverOptions.https ? "https" : "http"}://${formattedHostname}:${port} ...`);
|
|
130
|
-
}
|
|
131
|
-
try {
|
|
132
|
-
let cleanupStarted = false;
|
|
133
|
-
let closeUpgraded = null;
|
|
134
|
-
const cleanup = () => {
|
|
135
|
-
if (cleanupStarted) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
cleanupStarted = true;
|
|
139
|
-
(async () => {
|
|
140
|
-
console.debug("start-server process cleanup");
|
|
141
|
-
await new Promise((res) => {
|
|
142
|
-
server.close((err) => {
|
|
143
|
-
if (err)
|
|
144
|
-
console.error(err);
|
|
145
|
-
res();
|
|
146
|
-
});
|
|
147
|
-
server.closeAllConnections();
|
|
148
|
-
closeUpgraded === null || closeUpgraded === void 0 ? void 0 : closeUpgraded();
|
|
149
|
-
});
|
|
150
|
-
console.debug("start-server process cleanup finished");
|
|
151
|
-
process.exit(0);
|
|
152
|
-
})();
|
|
153
|
-
};
|
|
154
|
-
const exception = (err) => {
|
|
155
|
-
console.error(err);
|
|
156
|
-
};
|
|
157
|
-
process.on("SIGINT", cleanup);
|
|
158
|
-
process.on("SIGTERM", cleanup);
|
|
159
|
-
process.on("rejectionHandled", () => { });
|
|
160
|
-
process.on("uncaughtException", exception);
|
|
161
|
-
process.on("unhandledRejection", exception);
|
|
162
|
-
const initResult = await initialize(bundleOptions, projectPath, rootPath);
|
|
163
|
-
requestHandler = initResult.requestHandler;
|
|
164
|
-
upgradeHandler = initResult.upgradeHandler;
|
|
165
|
-
closeUpgraded = initResult.closeUpgraded;
|
|
166
|
-
handlersReady();
|
|
167
|
-
}
|
|
168
|
-
catch (err) {
|
|
169
|
-
handlersError();
|
|
170
|
-
console.error(err);
|
|
171
|
-
process.exit(1);
|
|
172
|
-
}
|
|
173
|
-
resolve();
|
|
174
|
-
});
|
|
175
|
-
server.listen(port, hostname);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
export async function initialize(bundleOptions, projectPath, rootPath) {
|
|
179
|
-
process.env.NODE_ENV = "development";
|
|
180
|
-
const hotReloader = await createHotReloader(bundleOptions, projectPath, rootPath);
|
|
181
|
-
await hotReloader.start();
|
|
182
|
-
const requestHandlerImpl = async (req, res) => {
|
|
183
|
-
req.on("error", console.error);
|
|
184
|
-
res.on("error", console.error);
|
|
185
|
-
const handleRequest = async () => {
|
|
186
|
-
var _a;
|
|
187
|
-
if (!(req.method === "GET" || req.method === "HEAD")) {
|
|
188
|
-
res.setHeader("Allow", ["GET", "HEAD"]);
|
|
189
|
-
res.statusCode = 405;
|
|
190
|
-
res.end();
|
|
191
|
-
}
|
|
192
|
-
const distRoot = path.resolve(projectPath, ((_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.path) || "./dist");
|
|
193
|
-
try {
|
|
194
|
-
const reqUrl = req.url || "";
|
|
195
|
-
const path = url.parse(reqUrl).pathname || "";
|
|
196
|
-
return await serveStatic(req, res, path, { root: distRoot });
|
|
197
|
-
}
|
|
198
|
-
catch (err) {
|
|
199
|
-
res.setHeader("Cache-Control", "private, no-cache, no-store, max-age=0, must-revalidate");
|
|
200
|
-
res.statusCode = 404;
|
|
201
|
-
res.end();
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
try {
|
|
205
|
-
await handleRequest();
|
|
206
|
-
}
|
|
207
|
-
catch (err) {
|
|
208
|
-
res.statusCode = 500;
|
|
209
|
-
res.end("Internal Server Error");
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
let requestHandler = requestHandlerImpl;
|
|
213
|
-
const logError = async (type, err) => {
|
|
214
|
-
if (type === "unhandledRejection") {
|
|
215
|
-
console.error("unhandledRejection: ", err);
|
|
216
|
-
}
|
|
217
|
-
else if (type === "uncaughtException") {
|
|
218
|
-
console.error("uncaughtException: ", err);
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
process.on("uncaughtException", logError.bind(null, "uncaughtException"));
|
|
222
|
-
process.on("unhandledRejection", logError.bind(null, "unhandledRejection"));
|
|
223
|
-
const upgradeHandler = async (req, socket, head) => {
|
|
224
|
-
var _a;
|
|
225
|
-
try {
|
|
226
|
-
const isHMRRequest = (_a = req.url) === null || _a === void 0 ? void 0 : _a.includes("turbopack-hmr");
|
|
227
|
-
if (isHMRRequest) {
|
|
228
|
-
hotReloader.onHMR(req, socket, head);
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
socket.end();
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
catch (err) {
|
|
235
|
-
console.error("Error handling upgrade request", err);
|
|
236
|
-
socket.end();
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
return {
|
|
240
|
-
requestHandler,
|
|
241
|
-
upgradeHandler,
|
|
242
|
-
closeUpgraded() {
|
|
243
|
-
hotReloader.close();
|
|
244
|
-
},
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
export async function pipeToNodeResponse(readable, res, waitUntilForEnd) {
|
|
248
|
-
try {
|
|
249
|
-
const { errored, destroyed } = res;
|
|
250
|
-
if (errored || destroyed)
|
|
251
|
-
return;
|
|
252
|
-
const controller = createAbortController(res);
|
|
253
|
-
const writer = createWriterFromResponse(res, waitUntilForEnd);
|
|
254
|
-
await readable.pipeTo(writer, { signal: controller.signal });
|
|
255
|
-
}
|
|
256
|
-
catch (err) {
|
|
257
|
-
if (isAbortError(err))
|
|
258
|
-
return;
|
|
259
|
-
throw new Error("failed to pipe response", { cause: err });
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
export function createAbortController(response) {
|
|
263
|
-
const controller = new AbortController();
|
|
264
|
-
response.once("close", () => {
|
|
265
|
-
if (response.writableFinished)
|
|
266
|
-
return;
|
|
267
|
-
controller.abort(new ResponseAborted());
|
|
268
|
-
});
|
|
269
|
-
return controller;
|
|
270
|
-
}
|
|
271
|
-
export function isAbortError(e) {
|
|
272
|
-
return (e === null || e === void 0 ? void 0 : e.name) === "AbortError" || (e === null || e === void 0 ? void 0 : e.name) === ResponseAbortedName;
|
|
273
|
-
}
|
|
274
|
-
export const ResponseAbortedName = "ResponseAborted";
|
|
275
|
-
export class ResponseAborted extends Error {
|
|
276
|
-
constructor() {
|
|
277
|
-
super(...arguments);
|
|
278
|
-
this.name = ResponseAbortedName;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
function createWriterFromResponse(res, waitUntilForEnd) {
|
|
282
|
-
let started = false;
|
|
283
|
-
let drained = new DetachedPromise();
|
|
284
|
-
function onDrain() {
|
|
285
|
-
drained.resolve();
|
|
286
|
-
}
|
|
287
|
-
res.on("drain", onDrain);
|
|
288
|
-
res.once("close", () => {
|
|
289
|
-
res.off("drain", onDrain);
|
|
290
|
-
drained.resolve();
|
|
291
|
-
});
|
|
292
|
-
const finished = new DetachedPromise();
|
|
293
|
-
res.once("finish", () => {
|
|
294
|
-
finished.resolve();
|
|
295
|
-
});
|
|
296
|
-
return new WritableStream({
|
|
297
|
-
write: async (chunk) => {
|
|
298
|
-
if (!started) {
|
|
299
|
-
started = true;
|
|
300
|
-
res.flushHeaders();
|
|
301
|
-
}
|
|
302
|
-
try {
|
|
303
|
-
const ok = res.write(chunk);
|
|
304
|
-
if ("flush" in res && typeof res.flush === "function") {
|
|
305
|
-
res.flush();
|
|
306
|
-
}
|
|
307
|
-
if (!ok) {
|
|
308
|
-
await drained.promise;
|
|
309
|
-
drained = new DetachedPromise();
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
catch (err) {
|
|
313
|
-
res.end();
|
|
314
|
-
throw new Error("failed to write chunk to response", { cause: err });
|
|
315
|
-
}
|
|
316
|
-
},
|
|
317
|
-
abort: (err) => {
|
|
318
|
-
if (res.writableFinished)
|
|
319
|
-
return;
|
|
320
|
-
res.destroy(err);
|
|
321
|
-
},
|
|
322
|
-
close: async () => {
|
|
323
|
-
if (waitUntilForEnd) {
|
|
324
|
-
await waitUntilForEnd;
|
|
325
|
-
}
|
|
326
|
-
if (res.writableFinished)
|
|
327
|
-
return;
|
|
328
|
-
res.end();
|
|
329
|
-
return finished.promise;
|
|
330
|
-
},
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
export class DetachedPromise {
|
|
334
|
-
constructor() {
|
|
335
|
-
let resolve;
|
|
336
|
-
let reject;
|
|
337
|
-
this.promise = new Promise((res, rej) => {
|
|
338
|
-
resolve = res;
|
|
339
|
-
reject = rej;
|
|
340
|
-
});
|
|
341
|
-
this.resolve = resolve;
|
|
342
|
-
this.reject = reject;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
export function serveStatic(req, res, path, opts) {
|
|
346
|
-
return new Promise((resolve, reject) => {
|
|
347
|
-
send(req, path, opts)
|
|
348
|
-
.on("directory", () => {
|
|
349
|
-
const err = new Error("No directory access");
|
|
350
|
-
err.code = "ENOENT";
|
|
351
|
-
reject(err);
|
|
352
|
-
})
|
|
353
|
-
.on("error", reject)
|
|
354
|
-
.pipe(res)
|
|
355
|
-
.on("finish", resolve);
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
export function formatHostname(hostname) {
|
|
359
|
-
return isIPv6(hostname) ? `[${hostname}]` : hostname;
|
|
360
|
-
}
|
package/esm/find-root.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare function findRootLockFile(cwd: string): string | undefined;
|
|
2
|
-
export declare function findPackageJson(cwd: string): string | undefined;
|
|
3
|
-
export declare function findWorkspacesRoot(cwd: string): string;
|
|
4
|
-
export declare function findRootDir(cwd: string): string;
|
package/esm/find-root.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import findUp from "find-up";
|
|
2
|
-
import { readFileSync } from "fs";
|
|
3
|
-
import { dirname } from "path";
|
|
4
|
-
export function findRootLockFile(cwd) {
|
|
5
|
-
return findUp.sync([
|
|
6
|
-
"pnpm-lock.yaml",
|
|
7
|
-
"package-lock.json",
|
|
8
|
-
"yarn.lock",
|
|
9
|
-
"bun.lock",
|
|
10
|
-
"bun.lockb",
|
|
11
|
-
], {
|
|
12
|
-
cwd,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
// compatible with tnpm
|
|
16
|
-
export function findPackageJson(cwd) {
|
|
17
|
-
return findUp.sync(["package.json"], {
|
|
18
|
-
cwd,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
function isWorkspaceRoot(pkgPath) {
|
|
22
|
-
const pkgJson = readFileSync(pkgPath, "utf-8");
|
|
23
|
-
const pkgJsonContent = JSON.parse(pkgJson);
|
|
24
|
-
return Boolean(pkgJsonContent.workspaces);
|
|
25
|
-
}
|
|
26
|
-
// refer from: https://github.com/umijs/mako/blob/next/crates/pm/src/helper/workspace.rs#L153
|
|
27
|
-
// TODO: 这块逻辑后续跟 utoo-pkg 使用一套方法
|
|
28
|
-
export function findWorkspacesRoot(cwd) {
|
|
29
|
-
const pkgJson = findPackageJson(cwd);
|
|
30
|
-
if (!pkgJson)
|
|
31
|
-
return cwd;
|
|
32
|
-
const pkgJsonFiles = [pkgJson];
|
|
33
|
-
while (true) {
|
|
34
|
-
const lastPkgJson = pkgJsonFiles[pkgJsonFiles.length - 1];
|
|
35
|
-
const currentDir = dirname(lastPkgJson);
|
|
36
|
-
const parentDir = dirname(currentDir);
|
|
37
|
-
if (parentDir === currentDir)
|
|
38
|
-
break;
|
|
39
|
-
if (isWorkspaceRoot(lastPkgJson))
|
|
40
|
-
break;
|
|
41
|
-
const newPkgJson = findPackageJson(parentDir);
|
|
42
|
-
if (!newPkgJson)
|
|
43
|
-
break;
|
|
44
|
-
pkgJsonFiles.push(newPkgJson);
|
|
45
|
-
}
|
|
46
|
-
return dirname(pkgJsonFiles[pkgJsonFiles.length - 1]);
|
|
47
|
-
}
|
|
48
|
-
export function findRootDir(cwd) {
|
|
49
|
-
const lockFile = findRootLockFile(cwd);
|
|
50
|
-
if (!lockFile)
|
|
51
|
-
return findWorkspacesRoot(cwd);
|
|
52
|
-
const lockFiles = [lockFile];
|
|
53
|
-
while (true) {
|
|
54
|
-
const lastLockFile = lockFiles[lockFiles.length - 1];
|
|
55
|
-
const currentDir = dirname(lastLockFile);
|
|
56
|
-
const parentDir = dirname(currentDir);
|
|
57
|
-
// dirname('/')==='/' so if we happen to reach the FS root (as might happen in a container we need to quit to avoid looping forever
|
|
58
|
-
if (parentDir === currentDir)
|
|
59
|
-
break;
|
|
60
|
-
const newLockFile = findRootLockFile(parentDir);
|
|
61
|
-
if (!newLockFile)
|
|
62
|
-
break;
|
|
63
|
-
lockFiles.push(newLockFile);
|
|
64
|
-
}
|
|
65
|
-
return dirname(lockFiles[lockFiles.length - 1]);
|
|
66
|
-
}
|
package/esm/hmr.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { IncomingMessage } from "http";
|
|
2
|
-
import { Duplex } from "stream";
|
|
3
|
-
import type webpack from "webpack";
|
|
4
|
-
import { BundleOptions, Project, Update as TurbopackUpdate } from "./types";
|
|
5
|
-
export declare const enum HMR_ACTIONS_SENT_TO_BROWSER {
|
|
6
|
-
RELOAD = "reload",
|
|
7
|
-
CLIENT_CHANGES = "clientChanges",
|
|
8
|
-
SERVER_ONLY_CHANGES = "serverOnlyChanges",
|
|
9
|
-
SYNC = "sync",
|
|
10
|
-
BUILT = "built",
|
|
11
|
-
BUILDING = "building",
|
|
12
|
-
TURBOPACK_MESSAGE = "turbopack-message",
|
|
13
|
-
TURBOPACK_CONNECTED = "turbopack-connected"
|
|
14
|
-
}
|
|
15
|
-
export interface TurbopackMessageAction {
|
|
16
|
-
action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE;
|
|
17
|
-
data: TurbopackUpdate | TurbopackUpdate[];
|
|
18
|
-
}
|
|
19
|
-
export interface TurbopackConnectedAction {
|
|
20
|
-
action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED;
|
|
21
|
-
data: {
|
|
22
|
-
sessionId: number;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
interface BuildingAction {
|
|
26
|
-
action: HMR_ACTIONS_SENT_TO_BROWSER.BUILDING;
|
|
27
|
-
}
|
|
28
|
-
export interface CompilationError {
|
|
29
|
-
moduleName?: string;
|
|
30
|
-
message: string;
|
|
31
|
-
details?: string;
|
|
32
|
-
moduleTrace?: Array<{
|
|
33
|
-
moduleName?: string;
|
|
34
|
-
}>;
|
|
35
|
-
stack?: string;
|
|
36
|
-
}
|
|
37
|
-
export interface SyncAction {
|
|
38
|
-
action: HMR_ACTIONS_SENT_TO_BROWSER.SYNC;
|
|
39
|
-
hash: string;
|
|
40
|
-
errors: ReadonlyArray<CompilationError>;
|
|
41
|
-
warnings: ReadonlyArray<CompilationError>;
|
|
42
|
-
updatedModules?: ReadonlyArray<string>;
|
|
43
|
-
}
|
|
44
|
-
export interface BuiltAction {
|
|
45
|
-
action: HMR_ACTIONS_SENT_TO_BROWSER.BUILT;
|
|
46
|
-
hash: string;
|
|
47
|
-
errors: ReadonlyArray<CompilationError>;
|
|
48
|
-
warnings: ReadonlyArray<CompilationError>;
|
|
49
|
-
updatedModules?: ReadonlyArray<string>;
|
|
50
|
-
}
|
|
51
|
-
export interface ReloadAction {
|
|
52
|
-
action: HMR_ACTIONS_SENT_TO_BROWSER.RELOAD;
|
|
53
|
-
data: string;
|
|
54
|
-
}
|
|
55
|
-
export type HMR_ACTION_TYPES = TurbopackMessageAction | TurbopackConnectedAction | BuildingAction | SyncAction | BuiltAction | ReloadAction;
|
|
56
|
-
export interface HotReloaderInterface {
|
|
57
|
-
turbopackProject?: Project;
|
|
58
|
-
serverStats: webpack.Stats | null;
|
|
59
|
-
setHmrServerError(error: Error | null): void;
|
|
60
|
-
clearHmrServerError(): void;
|
|
61
|
-
start(): Promise<void>;
|
|
62
|
-
send(action: HMR_ACTION_TYPES): void;
|
|
63
|
-
onHMR(req: IncomingMessage, socket: Duplex, head: Buffer, onUpgrade?: (client: {
|
|
64
|
-
send(data: string): void;
|
|
65
|
-
}) => void): void;
|
|
66
|
-
buildFallbackError(): Promise<void>;
|
|
67
|
-
close(): void;
|
|
68
|
-
}
|
|
69
|
-
export type ChangeSubscriptions = Map<string, Promise<AsyncIterableIterator<TurbopackResult>>>;
|
|
70
|
-
export type ReadyIds = Set<string>;
|
|
71
|
-
export type StartBuilding = (id: string, forceRebuild: boolean) => () => void;
|
|
72
|
-
export type ClientState = {
|
|
73
|
-
hmrPayloads: Map<string, HMR_ACTION_TYPES>;
|
|
74
|
-
turbopackUpdates: TurbopackUpdate[];
|
|
75
|
-
subscriptions: Map<string, AsyncIterator<any>>;
|
|
76
|
-
};
|
|
77
|
-
export type SendHmr = (id: string, payload: HMR_ACTION_TYPES) => void;
|
|
78
|
-
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>;
|
|
80
|
-
export {};
|