@utoo/pack 1.2.13 → 1.3.0-alpha.0
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/cjs/binding.d.ts +5 -31
- package/cjs/commands/build.js +6 -11
- package/cjs/commands/dev-legacy.d.ts +44 -0
- package/cjs/commands/dev-legacy.js +458 -0
- package/cjs/commands/dev.d.ts +6 -31
- package/cjs/commands/dev.js +142 -365
- package/cjs/core/hmr.d.ts +14 -0
- package/cjs/core/hmr.js +72 -7
- package/cjs/utils/common.d.ts +1 -1
- package/cjs/utils/common.js +1 -2
- package/esm/binding.d.ts +5 -31
- package/esm/commands/build.js +7 -12
- package/esm/commands/dev-legacy.d.ts +44 -0
- package/esm/commands/dev-legacy.js +442 -0
- package/esm/commands/dev.d.ts +6 -31
- package/esm/commands/dev.js +143 -356
- package/esm/core/hmr.d.ts +14 -0
- package/esm/core/hmr.js +73 -8
- package/esm/utils/common.d.ts +1 -1
- package/esm/utils/common.js +1 -1
- package/package.json +13 -9
package/esm/core/hmr.js
CHANGED
|
@@ -3,7 +3,7 @@ import { nanoid } from "nanoid";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { WebSocketServer } from "ws";
|
|
5
5
|
import { HtmlPlugin } from "../plugins/HtmlPlugin.js";
|
|
6
|
-
import {
|
|
6
|
+
import { debounce, getPackPath, processIssues } from "../utils/common.js";
|
|
7
7
|
import { getInitialAssetsFromStats } from "../utils/getInitialAssets.js";
|
|
8
8
|
import { processHtmlEntry } from "../utils/htmlEntry.js";
|
|
9
9
|
import { normalizePath } from "../utils/normalize-path.js";
|
|
@@ -22,11 +22,6 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
22
22
|
const createProject = projectFactory();
|
|
23
23
|
const project = await createProject({
|
|
24
24
|
processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
|
|
25
|
-
defineEnv: createDefineEnv({
|
|
26
|
-
config: bundleOptions.config,
|
|
27
|
-
dev: true,
|
|
28
|
-
optionDefineEnv: bundleOptions.defineEnv,
|
|
29
|
-
}),
|
|
30
25
|
watch: {
|
|
31
26
|
enable: true,
|
|
32
27
|
},
|
|
@@ -248,6 +243,77 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
248
243
|
})();
|
|
249
244
|
});
|
|
250
245
|
},
|
|
246
|
+
registerClient(ws) {
|
|
247
|
+
const subscriptions = new Map();
|
|
248
|
+
clients.add(ws);
|
|
249
|
+
clientStates.set(ws, {
|
|
250
|
+
hmrPayloads: new Map(),
|
|
251
|
+
turbopackUpdates: [],
|
|
252
|
+
subscriptions,
|
|
253
|
+
});
|
|
254
|
+
const turbopackConnected = {
|
|
255
|
+
action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED,
|
|
256
|
+
data: { sessionId },
|
|
257
|
+
};
|
|
258
|
+
sendToClient(ws, turbopackConnected);
|
|
259
|
+
const errors = [];
|
|
260
|
+
const sync = {
|
|
261
|
+
action: HMR_ACTIONS_SENT_TO_BROWSER.SYNC,
|
|
262
|
+
errors,
|
|
263
|
+
warnings: [],
|
|
264
|
+
hash: "",
|
|
265
|
+
};
|
|
266
|
+
sendToClient(ws, sync);
|
|
267
|
+
},
|
|
268
|
+
unregisterClient(ws) {
|
|
269
|
+
var _a;
|
|
270
|
+
const state = clientStates.get(ws);
|
|
271
|
+
if (state) {
|
|
272
|
+
for (const subscription of state.subscriptions.values()) {
|
|
273
|
+
(_a = subscription.return) === null || _a === void 0 ? void 0 : _a.call(subscription);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
clientStates.delete(ws);
|
|
277
|
+
clients.delete(ws);
|
|
278
|
+
},
|
|
279
|
+
handleClientMessage(ws, data) {
|
|
280
|
+
const parsedData = JSON.parse(data);
|
|
281
|
+
switch (parsedData.event) {
|
|
282
|
+
case "client-error":
|
|
283
|
+
case "client-warning":
|
|
284
|
+
case "client-success":
|
|
285
|
+
case "client-full-reload": {
|
|
286
|
+
const { hadRuntimeError, dependencyChain } = parsedData;
|
|
287
|
+
if (hadRuntimeError) {
|
|
288
|
+
console.warn(FAST_REFRESH_RUNTIME_RELOAD);
|
|
289
|
+
}
|
|
290
|
+
if (Array.isArray(dependencyChain) &&
|
|
291
|
+
typeof dependencyChain[0] === "string") {
|
|
292
|
+
const cleanedModulePath = dependencyChain[0]
|
|
293
|
+
.replace(/^\[project\]/, ".")
|
|
294
|
+
.replace(/ \[.*\] \(.*\)$/, "");
|
|
295
|
+
console.warn(`Fast Refresh had to perform a full reload when ${cleanedModulePath} changed.`);
|
|
296
|
+
}
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
default:
|
|
300
|
+
if (!parsedData.type) {
|
|
301
|
+
throw new Error(`unrecognized HMR message "${data}"`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
switch (parsedData.type) {
|
|
305
|
+
case "turbopack-subscribe":
|
|
306
|
+
subscribeToHmrEvents(ws, parsedData.path);
|
|
307
|
+
break;
|
|
308
|
+
case "turbopack-unsubscribe":
|
|
309
|
+
unsubscribeFromHmrEvents(ws, parsedData.path);
|
|
310
|
+
break;
|
|
311
|
+
default:
|
|
312
|
+
if (!parsedData.event) {
|
|
313
|
+
throw new Error(`unrecognized Turbopack HMR message "${data}"`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
},
|
|
251
317
|
send(action) {
|
|
252
318
|
const payload = JSON.stringify(action);
|
|
253
319
|
for (const client of clients) {
|
|
@@ -266,8 +332,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
266
332
|
},
|
|
267
333
|
close() {
|
|
268
334
|
for (const wsClient of clients) {
|
|
269
|
-
|
|
270
|
-
wsClient.terminate();
|
|
335
|
+
wsClient.close();
|
|
271
336
|
}
|
|
272
337
|
clients.clear();
|
|
273
338
|
},
|
package/esm/utils/common.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { debounce, isWellKnownError, ModuleBuildError, processIssues, rustifyEnv, } from "@utoo/pack-shared";
|
|
2
2
|
export declare function blockStdout(): void;
|
|
3
3
|
/**
|
|
4
4
|
* Pack 根目录(pack 包所在目录)。
|
package/esm/utils/common.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
4
|
-
export {
|
|
4
|
+
export { debounce, isWellKnownError, ModuleBuildError, processIssues, rustifyEnv, } from "@utoo/pack-shared";
|
|
5
5
|
// ref:
|
|
6
6
|
// https://github.com/vercel/next.js/pull/51883
|
|
7
7
|
export function blockStdout() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/pack",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-alpha.0",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"types": "esm/index.d.ts",
|
|
@@ -38,11 +38,15 @@
|
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@babel/code-frame": "7.22.5",
|
|
41
|
+
"@hono/node-server": "^1.19.11",
|
|
42
|
+
"@hono/node-ws": "^1.3.0",
|
|
41
43
|
"@swc/helpers": "0.5.15",
|
|
42
|
-
"@utoo/pack-shared": "1.
|
|
44
|
+
"@utoo/pack-shared": "1.3.0-alpha.0",
|
|
43
45
|
"@utoo/style-loader": "^1.0.0",
|
|
44
46
|
"domparser-rs": "^0.0.7",
|
|
45
47
|
"find-up": "4.1.0",
|
|
48
|
+
"get-port": "^7.1.0",
|
|
49
|
+
"hono": "^4.12.5",
|
|
46
50
|
"nanoid": "^3.3.11",
|
|
47
51
|
"picocolors": "^1.1.1",
|
|
48
52
|
"send": "0.17.1",
|
|
@@ -86,12 +90,12 @@
|
|
|
86
90
|
},
|
|
87
91
|
"repository": "git@github.com:utooland/utoo.git",
|
|
88
92
|
"optionalDependencies": {
|
|
89
|
-
"@utoo/pack-darwin-arm64": "1.
|
|
90
|
-
"@utoo/pack-darwin-x64": "1.
|
|
91
|
-
"@utoo/pack-linux-arm64-gnu": "1.
|
|
92
|
-
"@utoo/pack-linux-arm64-musl": "1.
|
|
93
|
-
"@utoo/pack-linux-x64-gnu": "1.
|
|
94
|
-
"@utoo/pack-linux-x64-musl": "1.
|
|
95
|
-
"@utoo/pack-win32-x64-msvc": "1.
|
|
93
|
+
"@utoo/pack-darwin-arm64": "1.3.0-alpha.0",
|
|
94
|
+
"@utoo/pack-darwin-x64": "1.3.0-alpha.0",
|
|
95
|
+
"@utoo/pack-linux-arm64-gnu": "1.3.0-alpha.0",
|
|
96
|
+
"@utoo/pack-linux-arm64-musl": "1.3.0-alpha.0",
|
|
97
|
+
"@utoo/pack-linux-x64-gnu": "1.3.0-alpha.0",
|
|
98
|
+
"@utoo/pack-linux-x64-musl": "1.3.0-alpha.0",
|
|
99
|
+
"@utoo/pack-win32-x64-msvc": "1.3.0-alpha.0"
|
|
96
100
|
}
|
|
97
101
|
}
|