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