@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/cjs/core/hmr.js
CHANGED
|
@@ -30,11 +30,6 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
30
30
|
const createProject = (0, project_1.projectFactory)();
|
|
31
31
|
const project = await createProject({
|
|
32
32
|
processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
|
|
33
|
-
defineEnv: (0, common_1.createDefineEnv)({
|
|
34
|
-
config: bundleOptions.config,
|
|
35
|
-
dev: true,
|
|
36
|
-
optionDefineEnv: bundleOptions.defineEnv,
|
|
37
|
-
}),
|
|
38
33
|
watch: {
|
|
39
34
|
enable: true,
|
|
40
35
|
},
|
|
@@ -256,6 +251,77 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
256
251
|
})();
|
|
257
252
|
});
|
|
258
253
|
},
|
|
254
|
+
registerClient(ws) {
|
|
255
|
+
const subscriptions = new Map();
|
|
256
|
+
clients.add(ws);
|
|
257
|
+
clientStates.set(ws, {
|
|
258
|
+
hmrPayloads: new Map(),
|
|
259
|
+
turbopackUpdates: [],
|
|
260
|
+
subscriptions,
|
|
261
|
+
});
|
|
262
|
+
const turbopackConnected = {
|
|
263
|
+
action: pack_shared_1.HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED,
|
|
264
|
+
data: { sessionId },
|
|
265
|
+
};
|
|
266
|
+
sendToClient(ws, turbopackConnected);
|
|
267
|
+
const errors = [];
|
|
268
|
+
const sync = {
|
|
269
|
+
action: pack_shared_1.HMR_ACTIONS_SENT_TO_BROWSER.SYNC,
|
|
270
|
+
errors,
|
|
271
|
+
warnings: [],
|
|
272
|
+
hash: "",
|
|
273
|
+
};
|
|
274
|
+
sendToClient(ws, sync);
|
|
275
|
+
},
|
|
276
|
+
unregisterClient(ws) {
|
|
277
|
+
var _a;
|
|
278
|
+
const state = clientStates.get(ws);
|
|
279
|
+
if (state) {
|
|
280
|
+
for (const subscription of state.subscriptions.values()) {
|
|
281
|
+
(_a = subscription.return) === null || _a === void 0 ? void 0 : _a.call(subscription);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
clientStates.delete(ws);
|
|
285
|
+
clients.delete(ws);
|
|
286
|
+
},
|
|
287
|
+
handleClientMessage(ws, data) {
|
|
288
|
+
const parsedData = JSON.parse(data);
|
|
289
|
+
switch (parsedData.event) {
|
|
290
|
+
case "client-error":
|
|
291
|
+
case "client-warning":
|
|
292
|
+
case "client-success":
|
|
293
|
+
case "client-full-reload": {
|
|
294
|
+
const { hadRuntimeError, dependencyChain } = parsedData;
|
|
295
|
+
if (hadRuntimeError) {
|
|
296
|
+
console.warn(exports.FAST_REFRESH_RUNTIME_RELOAD);
|
|
297
|
+
}
|
|
298
|
+
if (Array.isArray(dependencyChain) &&
|
|
299
|
+
typeof dependencyChain[0] === "string") {
|
|
300
|
+
const cleanedModulePath = dependencyChain[0]
|
|
301
|
+
.replace(/^\[project\]/, ".")
|
|
302
|
+
.replace(/ \[.*\] \(.*\)$/, "");
|
|
303
|
+
console.warn(`Fast Refresh had to perform a full reload when ${cleanedModulePath} changed.`);
|
|
304
|
+
}
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
default:
|
|
308
|
+
if (!parsedData.type) {
|
|
309
|
+
throw new Error(`unrecognized HMR message "${data}"`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
switch (parsedData.type) {
|
|
313
|
+
case "turbopack-subscribe":
|
|
314
|
+
subscribeToHmrEvents(ws, parsedData.path);
|
|
315
|
+
break;
|
|
316
|
+
case "turbopack-unsubscribe":
|
|
317
|
+
unsubscribeFromHmrEvents(ws, parsedData.path);
|
|
318
|
+
break;
|
|
319
|
+
default:
|
|
320
|
+
if (!parsedData.event) {
|
|
321
|
+
throw new Error(`unrecognized Turbopack HMR message "${data}"`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
},
|
|
259
325
|
send(action) {
|
|
260
326
|
const payload = JSON.stringify(action);
|
|
261
327
|
for (const client of clients) {
|
|
@@ -274,8 +340,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
274
340
|
},
|
|
275
341
|
close() {
|
|
276
342
|
for (const wsClient of clients) {
|
|
277
|
-
|
|
278
|
-
wsClient.terminate();
|
|
343
|
+
wsClient.close();
|
|
279
344
|
}
|
|
280
345
|
clients.clear();
|
|
281
346
|
},
|
package/cjs/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/cjs/utils/common.js
CHANGED
|
@@ -3,12 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.rustifyEnv = exports.processIssues = exports.ModuleBuildError = exports.isWellKnownError = exports.debounce =
|
|
6
|
+
exports.rustifyEnv = exports.processIssues = exports.ModuleBuildError = exports.isWellKnownError = exports.debounce = void 0;
|
|
7
7
|
exports.blockStdout = blockStdout;
|
|
8
8
|
exports.getPackPath = getPackPath;
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
var pack_shared_1 = require("@utoo/pack-shared");
|
|
11
|
-
Object.defineProperty(exports, "createDefineEnv", { enumerable: true, get: function () { return pack_shared_1.createDefineEnv; } });
|
|
12
11
|
Object.defineProperty(exports, "debounce", { enumerable: true, get: function () { return pack_shared_1.debounce; } });
|
|
13
12
|
Object.defineProperty(exports, "isWellKnownError", { enumerable: true, get: function () { return pack_shared_1.isWellKnownError; } });
|
|
14
13
|
Object.defineProperty(exports, "ModuleBuildError", { enumerable: true, get: function () { return pack_shared_1.ModuleBuildError; } });
|
package/esm/binding.d.ts
CHANGED
|
@@ -9,22 +9,6 @@ export declare class ExternalObject<T> {
|
|
|
9
9
|
[K: symbol]: T
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
/** Arguments for `NapiTurbopackCallbacks::throw_turbopack_internal_error`. */
|
|
13
|
-
export interface TurbopackInternalErrorOpts {
|
|
14
|
-
message: string
|
|
15
|
-
anonymizedLocation?: string
|
|
16
|
-
}
|
|
17
|
-
export interface NapiTurbopackCallbacksJsObject {
|
|
18
|
-
/**
|
|
19
|
-
* Called when we've encountered a bug in Turbopack and not in the user's code. Constructs and
|
|
20
|
-
* throws a `TurbopackInternalError` type. Logs to anonymized telemetry.
|
|
21
|
-
*
|
|
22
|
-
* As a result of the use of `ErrorStrategy::CalleeHandled`, the first argument is an error if
|
|
23
|
-
* there's a runtime conversion error. This should never happen, but if it does, the function
|
|
24
|
-
* can throw it instead.
|
|
25
|
-
*/
|
|
26
|
-
throwTurbopackInternalError: (conversionError: Error | null, opts: TurbopackInternalErrorOpts) => never
|
|
27
|
-
}
|
|
28
12
|
export declare function registerWorkerScheduler(creator: (arg: NapiWorkerCreation) => any, terminator: (arg: NapiWorkerTermination) => any): void
|
|
29
13
|
export declare function workerCreated(workerId: number): void
|
|
30
14
|
export interface NapiWorkerCreation {
|
|
@@ -93,11 +77,6 @@ export interface NapiProjectOptions {
|
|
|
93
77
|
config: string
|
|
94
78
|
/** A map of environment variables to use when compiling code. */
|
|
95
79
|
processEnv: Array<NapiEnvVar>
|
|
96
|
-
/**
|
|
97
|
-
* A map of environment variables which should get injected at compile
|
|
98
|
-
* time.
|
|
99
|
-
*/
|
|
100
|
-
defineEnv: NapiDefineEnv
|
|
101
80
|
/** The mode in which Next.js is running. */
|
|
102
81
|
dev: boolean
|
|
103
82
|
/** The build id. */
|
|
@@ -119,11 +98,6 @@ export interface NapiPartialProjectOptions {
|
|
|
119
98
|
config?: string
|
|
120
99
|
/** A map of environment variables to use when compiling code. */
|
|
121
100
|
processEnv?: Array<NapiEnvVar>
|
|
122
|
-
/**
|
|
123
|
-
* A map of environment variables which should get injected at compile
|
|
124
|
-
* time.
|
|
125
|
-
*/
|
|
126
|
-
defineEnv?: NapiDefineEnv
|
|
127
101
|
/** The mode in which Next.js is running. */
|
|
128
102
|
dev?: boolean
|
|
129
103
|
/** The build id. */
|
|
@@ -136,11 +110,6 @@ export interface NapiPartialProjectOptions {
|
|
|
136
110
|
noMangling?: boolean
|
|
137
111
|
packPath?: string
|
|
138
112
|
}
|
|
139
|
-
export interface NapiDefineEnv {
|
|
140
|
-
client: Array<NapiEnvVar>
|
|
141
|
-
edge: Array<NapiEnvVar>
|
|
142
|
-
nodejs: Array<NapiEnvVar>
|
|
143
|
-
}
|
|
144
113
|
export interface NapiTurboEngineOptions {
|
|
145
114
|
/** Use the new backend with persistent caching enabled. */
|
|
146
115
|
persistentCaching?: boolean
|
|
@@ -214,6 +183,11 @@ export declare function projectTraceSource(project: { __napiType: "Project" }, f
|
|
|
214
183
|
export declare function projectGetSourceForAsset(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
|
|
215
184
|
export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: RcStr): Promise<string | null>
|
|
216
185
|
export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: RcStr): string | null
|
|
186
|
+
/** Arguments for `NapiTurbopackCallbacks::throw_turbopack_internal_error`. */
|
|
187
|
+
export interface TurbopackInternalErrorOpts {
|
|
188
|
+
message: string
|
|
189
|
+
anonymizedLocation?: string
|
|
190
|
+
}
|
|
217
191
|
/**
|
|
218
192
|
* A version of [`NapiTurbopackCallbacks`] that can accepted as an argument to a napi function.
|
|
219
193
|
*
|
package/esm/commands/build.js
CHANGED
|
@@ -6,7 +6,7 @@ import path from "path";
|
|
|
6
6
|
import { resolveBundleOptions } from "../config/webpackCompat.js";
|
|
7
7
|
import { projectFactory } from "../core/project.js";
|
|
8
8
|
import { HtmlPlugin } from "../plugins/HtmlPlugin.js";
|
|
9
|
-
import { blockStdout,
|
|
9
|
+
import { blockStdout, getPackPath } from "../utils/common.js";
|
|
10
10
|
import { findRootDir } from "../utils/findRoot.js";
|
|
11
11
|
import { getInitialAssetsFromStats } from "../utils/getInitialAssets.js";
|
|
12
12
|
import { processHtmlEntry } from "../utils/htmlEntry.js";
|
|
@@ -22,7 +22,7 @@ export function build(options, projectPath, rootPath) {
|
|
|
22
22
|
return buildInternal(bundleOptions, projectPath, rootPath);
|
|
23
23
|
}
|
|
24
24
|
async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
25
|
-
var _a, _b, _c, _d, _e, _f
|
|
25
|
+
var _a, _b, _c, _d, _e, _f;
|
|
26
26
|
blockStdout();
|
|
27
27
|
if (process.env.XCODE_PROFILE) {
|
|
28
28
|
await xcodeProfilingReady();
|
|
@@ -33,15 +33,10 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
33
33
|
const createProject = projectFactory();
|
|
34
34
|
const project = await createProject({
|
|
35
35
|
processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
|
|
36
|
-
defineEnv: createDefineEnv({
|
|
37
|
-
config: bundleOptions.config,
|
|
38
|
-
dev: (_b = bundleOptions.dev) !== null && _b !== void 0 ? _b : false,
|
|
39
|
-
optionDefineEnv: bundleOptions.defineEnv,
|
|
40
|
-
}),
|
|
41
36
|
watch: {
|
|
42
37
|
enable: false,
|
|
43
38
|
},
|
|
44
|
-
dev: (
|
|
39
|
+
dev: (_b = bundleOptions.dev) !== null && _b !== void 0 ? _b : false,
|
|
45
40
|
buildId: bundleOptions.buildId || nanoid(),
|
|
46
41
|
config: {
|
|
47
42
|
...bundleOptions.config,
|
|
@@ -53,7 +48,7 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
53
48
|
rootPath: rootPath || projectPath || process.cwd(),
|
|
54
49
|
packPath: getPackPath(),
|
|
55
50
|
}, {
|
|
56
|
-
persistentCaching: (
|
|
51
|
+
persistentCaching: (_c = bundleOptions.config.persistentCaching) !== null && _c !== void 0 ? _c : false,
|
|
57
52
|
});
|
|
58
53
|
const entrypoints = await project.writeAllEntrypointsToDisk();
|
|
59
54
|
handleIssues(entrypoints.issues);
|
|
@@ -69,20 +64,20 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
69
64
|
];
|
|
70
65
|
if (htmlConfigs.length > 0) {
|
|
71
66
|
const assets = { js: [], css: [] };
|
|
72
|
-
const outputDir = ((
|
|
67
|
+
const outputDir = ((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || path.join(process.cwd(), "dist");
|
|
73
68
|
if (assets.js.length === 0 && assets.css.length === 0) {
|
|
74
69
|
const discovered = getInitialAssetsFromStats(outputDir);
|
|
75
70
|
assets.js.push(...discovered.js);
|
|
76
71
|
assets.css.push(...discovered.css);
|
|
77
72
|
}
|
|
78
|
-
const publicPath = (
|
|
73
|
+
const publicPath = (_e = bundleOptions.config.output) === null || _e === void 0 ? void 0 : _e.publicPath;
|
|
79
74
|
for (const config of htmlConfigs) {
|
|
80
75
|
const plugin = new HtmlPlugin(config);
|
|
81
76
|
await plugin.generate(outputDir, assets, publicPath);
|
|
82
77
|
}
|
|
83
78
|
}
|
|
84
79
|
if (process.env.ANALYZE) {
|
|
85
|
-
await analyzeBundle(((
|
|
80
|
+
await analyzeBundle(((_f = bundleOptions.config.output) === null || _f === void 0 ? void 0 : _f.path) || "dist");
|
|
86
81
|
}
|
|
87
82
|
await project.shutdown();
|
|
88
83
|
// TODO: Maybe run tasks in worker is a better way, see
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from "http";
|
|
2
|
+
import send from "send";
|
|
3
|
+
import { Duplex, Writable } from "stream";
|
|
4
|
+
import { BundleOptions } from "../config/types";
|
|
5
|
+
import { WebpackConfig } from "../config/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
|
+
logServerInfo?: boolean;
|
|
17
|
+
selfSignedCertificate?: SelfSignedCertificate;
|
|
18
|
+
}
|
|
19
|
+
export type RequestHandler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
20
|
+
export type UpgradeHandler = (req: IncomingMessage, socket: Duplex, head: Buffer) => Promise<void>;
|
|
21
|
+
export type ServerInitResult = {
|
|
22
|
+
requestHandler: RequestHandler;
|
|
23
|
+
upgradeHandler: UpgradeHandler;
|
|
24
|
+
closeUpgraded: () => void;
|
|
25
|
+
};
|
|
26
|
+
export declare function startServer(serverOptions: StartServerOptions, bundleOptions: BundleOptions, projectPath: string, rootPath?: string): Promise<void>;
|
|
27
|
+
export declare function initialize(bundleOptions: BundleOptions, projectPath: string, rootPath?: string): Promise<ServerInitResult>;
|
|
28
|
+
export declare function pipeToNodeResponse(readable: ReadableStream<Uint8Array>, res: ServerResponse, waitUntilForEnd?: Promise<unknown>): Promise<void>;
|
|
29
|
+
export declare function createAbortController(response: Writable): AbortController;
|
|
30
|
+
export declare function isAbortError(e: any): e is Error & {
|
|
31
|
+
name: "AbortError";
|
|
32
|
+
};
|
|
33
|
+
export declare const ResponseAbortedName = "ResponseAborted";
|
|
34
|
+
export declare class ResponseAborted extends Error {
|
|
35
|
+
readonly name = "ResponseAborted";
|
|
36
|
+
}
|
|
37
|
+
export declare class DetachedPromise<T = any> {
|
|
38
|
+
readonly resolve: (value: T | PromiseLike<T>) => void;
|
|
39
|
+
readonly reject: (reason: any) => void;
|
|
40
|
+
readonly promise: Promise<T>;
|
|
41
|
+
constructor();
|
|
42
|
+
}
|
|
43
|
+
export declare function serveStatic(req: IncomingMessage, res: ServerResponse, path: string, opts?: Parameters<typeof send>[2]): Promise<void>;
|
|
44
|
+
export declare function formatHostname(hostname: string): string;
|