@utoo/pack 1.4.12-alpha.4 → 1.4.12-alpha.6
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 +2 -0
- package/cjs/commands/build.js +9 -13
- package/cjs/commands/dev.js +13 -2
- package/cjs/core/hmr.d.ts +1 -1
- package/cjs/core/hmr.js +23 -7
- package/cjs/core/project.d.ts +2 -0
- package/cjs/core/project.js +2 -0
- package/cjs/core/types.d.ts +2 -0
- package/cjs/utils/getInitialAssets.d.ts +2 -0
- package/cjs/utils/getInitialAssets.js +29 -5
- package/esm/binding.d.ts +2 -0
- package/esm/commands/build.js +10 -14
- package/esm/commands/dev.js +13 -2
- package/esm/core/hmr.d.ts +1 -1
- package/esm/core/hmr.js +24 -8
- package/esm/core/project.d.ts +2 -0
- package/esm/core/project.js +2 -0
- package/esm/core/types.d.ts +2 -0
- package/esm/utils/getInitialAssets.d.ts +2 -0
- package/esm/utils/getInitialAssets.js +28 -5
- package/package.json +9 -9
package/cjs/binding.d.ts
CHANGED
|
@@ -146,6 +146,8 @@ export declare function projectShutdown(project: { __napiType: "Project" }): Pro
|
|
|
146
146
|
export interface NapiEntrypoints {
|
|
147
147
|
apps?: Array<ExternalObject<ExternalEndpoint>>
|
|
148
148
|
libraries?: Array<ExternalObject<ExternalEndpoint>>
|
|
149
|
+
appPaths?: Array<NapiWrittenEndpoint>
|
|
150
|
+
libraryPaths?: Array<NapiWrittenEndpoint>
|
|
149
151
|
}
|
|
150
152
|
export declare function projectWriteAllEntrypointsToDisk(project: { __napiType: "Project" }): Promise<TurbopackResult>
|
|
151
153
|
export declare function projectEntrypointsSubscribe(project: { __napiType: "Project" }, func: (...args: any[]) => any): { __napiType: "RootTask" }
|
package/cjs/commands/build.js
CHANGED
|
@@ -31,7 +31,7 @@ function build(options, projectPath, rootPath) {
|
|
|
31
31
|
return buildInternal(bundleOptions, projectPath, rootPath);
|
|
32
32
|
}
|
|
33
33
|
async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
34
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
34
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
35
35
|
(0, common_1.blockStdout)();
|
|
36
36
|
if (process.env.XCODE_PROFILE) {
|
|
37
37
|
await (0, xcodeProfile_1.xcodeProfilingReady)();
|
|
@@ -39,6 +39,7 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
39
39
|
const resolvedProjectPath = projectPath || process.cwd();
|
|
40
40
|
const resolvedRootPath = rootPath || projectPath || process.cwd();
|
|
41
41
|
const persistentCaching = (_a = bundleOptions.config.persistentCaching) !== null && _a !== void 0 ? _a : false;
|
|
42
|
+
const shouldCreateWebpackStats = Boolean(process.env.ANALYZE) || Boolean(bundleOptions.config.stats);
|
|
42
43
|
(0, htmlEntry_1.processHtmlEntry)(bundleOptions.config, resolvedProjectPath);
|
|
43
44
|
(0, validateEntry_1.validateEntryPaths)(bundleOptions.config, resolvedProjectPath);
|
|
44
45
|
await (0, cleanOutput_1.cleanOutput)(bundleOptions.config, resolvedProjectPath);
|
|
@@ -56,9 +57,7 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
56
57
|
tracing: (_d = bundleOptions.tracing) !== null && _d !== void 0 ? _d : true,
|
|
57
58
|
config: {
|
|
58
59
|
...bundleOptions.config,
|
|
59
|
-
stats:
|
|
60
|
-
bundleOptions.config.stats ||
|
|
61
|
-
bundleOptions.config.entry.some((e) => !!e.html),
|
|
60
|
+
stats: shouldCreateWebpackStats,
|
|
62
61
|
pluginRuntimeStrategy: (_f = (_e = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.config) === null || _e === void 0 ? void 0 : _e.pluginRuntimeStrategy) !== null && _f !== void 0 ? _f : ((0, runtimePluginStratety_1.useWorkerThreads)() ? "workerThreads" : "childProcesses"),
|
|
63
62
|
},
|
|
64
63
|
projectPath: (0, normalizePath_1.normalizePath)(resolvedProjectPath),
|
|
@@ -69,7 +68,6 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
69
68
|
// Build mode is a short-lived, one-shot compilation, so avoid paying
|
|
70
69
|
// dependency graph bookkeeping cost unless the persistent cache needs it.
|
|
71
70
|
dependencyTracking: persistentCaching,
|
|
72
|
-
isShortSession: true,
|
|
73
71
|
});
|
|
74
72
|
const entrypoints = await project.writeAllEntrypointsToDisk();
|
|
75
73
|
(0, pack_shared_1.handleIssues)(entrypoints.issues);
|
|
@@ -84,21 +82,19 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
84
82
|
.map((e) => e.html),
|
|
85
83
|
];
|
|
86
84
|
if (htmlConfigs.length > 0) {
|
|
87
|
-
const assets =
|
|
85
|
+
const assets = (0, getInitialAssets_1.getInitialAssetsFromEndpointPaths)([
|
|
86
|
+
...((_g = entrypoints.appPaths) !== null && _g !== void 0 ? _g : []),
|
|
87
|
+
...((_h = entrypoints.libraryPaths) !== null && _h !== void 0 ? _h : []),
|
|
88
|
+
]);
|
|
88
89
|
const outputDir = (0, cleanOutput_1.getOutputPath)(bundleOptions.config, resolvedProjectPath);
|
|
89
|
-
|
|
90
|
-
const discovered = (0, getInitialAssets_1.getInitialAssetsFromStats)(outputDir);
|
|
91
|
-
assets.js.push(...discovered.js);
|
|
92
|
-
assets.css.push(...discovered.css);
|
|
93
|
-
}
|
|
94
|
-
const publicPath = (_g = bundleOptions.config.output) === null || _g === void 0 ? void 0 : _g.publicPath;
|
|
90
|
+
const publicPath = (_j = bundleOptions.config.output) === null || _j === void 0 ? void 0 : _j.publicPath;
|
|
95
91
|
for (const config of htmlConfigs) {
|
|
96
92
|
const plugin = new HtmlPlugin_1.HtmlPlugin(config);
|
|
97
93
|
await plugin.generate(outputDir, assets, publicPath);
|
|
98
94
|
}
|
|
99
95
|
}
|
|
100
96
|
if (process.env.ANALYZE) {
|
|
101
|
-
await analyzeBundle(((
|
|
97
|
+
await analyzeBundle(((_k = bundleOptions.config.output) === null || _k === void 0 ? void 0 : _k.path) || "dist");
|
|
102
98
|
}
|
|
103
99
|
}
|
|
104
100
|
finally {
|
package/cjs/commands/dev.js
CHANGED
|
@@ -234,8 +234,19 @@ async function runDev(options, projectPath, rootPath, serverOptions) {
|
|
|
234
234
|
: serveOptsBase.hostname;
|
|
235
235
|
(0, printServerInfo_1.printServerInfo)(scheme, displayHost, serveOptsBase.port);
|
|
236
236
|
}
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
let cleanupStarted = false;
|
|
238
|
+
const cleanup = async () => {
|
|
239
|
+
if (cleanupStarted) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
cleanupStarted = true;
|
|
243
|
+
try {
|
|
244
|
+
await hotReloader.close();
|
|
245
|
+
}
|
|
246
|
+
catch (err) {
|
|
247
|
+
console.error(err);
|
|
248
|
+
process.exit(1);
|
|
249
|
+
}
|
|
239
250
|
// We always create HTTP/1.1 server (http or https), so closeAllConnections exists; Hono's
|
|
240
251
|
// ServerType union includes HTTP/2, so TS does not narrow. Use runtime check to satisfy types.
|
|
241
252
|
if ("closeAllConnections" in server &&
|
package/cjs/core/hmr.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface HotReloaderInterface {
|
|
|
38
38
|
/** Handle a message from a client (JSON string). */
|
|
39
39
|
handleClientMessage(ws: WSLike, data: string): void;
|
|
40
40
|
buildFallbackError(): Promise<void>;
|
|
41
|
-
close(): void
|
|
41
|
+
close(): Promise<void>;
|
|
42
42
|
}
|
|
43
43
|
export type ChangeSubscriptions = Map<string, Promise<AsyncIterableIterator<TurbopackResult>>>;
|
|
44
44
|
export type ReadyIds = Set<string>;
|
package/cjs/core/hmr.js
CHANGED
|
@@ -74,9 +74,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
74
74
|
.filter((e) => !!e.html)
|
|
75
75
|
.map((e) => e.html),
|
|
76
76
|
];
|
|
77
|
-
const shouldCreateWebpackStats = Boolean(process.env.ANALYZE) ||
|
|
78
|
-
bundleOptions.config.stats ||
|
|
79
|
-
htmlConfigs.length > 0;
|
|
77
|
+
const shouldCreateWebpackStats = Boolean(process.env.ANALYZE) || Boolean(bundleOptions.config.stats);
|
|
80
78
|
let project;
|
|
81
79
|
try {
|
|
82
80
|
project = await createProject({
|
|
@@ -164,6 +162,18 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
164
162
|
hmrEventHappened = true;
|
|
165
163
|
sendEnqueuedMessagesDebounce();
|
|
166
164
|
}
|
|
165
|
+
const writtenEndpointPaths = new Map();
|
|
166
|
+
function updateWrittenEndpointPaths(endpoints, paths) {
|
|
167
|
+
if (!endpoints || !paths) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
endpoints.forEach((endpoint, index) => {
|
|
171
|
+
const written = paths[index];
|
|
172
|
+
if (written) {
|
|
173
|
+
writtenEndpointPaths.set(endpoint, written);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
167
177
|
async function regenerateHtml() {
|
|
168
178
|
var _a;
|
|
169
179
|
if (htmlConfigs.length === 0) {
|
|
@@ -171,7 +181,9 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
171
181
|
}
|
|
172
182
|
const outputDir = (0, cleanOutput_1.getOutputPath)(bundleOptions.config, resolvedProjectPath);
|
|
173
183
|
const publicPath = (_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.publicPath;
|
|
174
|
-
const assets = (0, getInitialAssets_1.
|
|
184
|
+
const assets = (0, getInitialAssets_1.getInitialAssetsFromEndpointPaths)([
|
|
185
|
+
...writtenEndpointPaths.values(),
|
|
186
|
+
]);
|
|
175
187
|
for (const config of htmlConfigs) {
|
|
176
188
|
const plugin = new HtmlPlugin_1.HtmlPlugin(config);
|
|
177
189
|
await plugin.generate(outputDir, assets, publicPath);
|
|
@@ -180,11 +192,14 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
180
192
|
async function writeAllEntrypointsToDisk() {
|
|
181
193
|
const result = await project.writeAllEntrypointsToDisk();
|
|
182
194
|
(0, common_1.processIssues)(result, true, true);
|
|
195
|
+
updateWrittenEndpointPaths(result.apps, result.appPaths);
|
|
196
|
+
updateWrittenEndpointPaths(result.libraries, result.libraryPaths);
|
|
183
197
|
await regenerateHtml();
|
|
184
198
|
}
|
|
185
199
|
async function writeEntrypointToDisk(entrypoint) {
|
|
186
200
|
const result = await entrypoint.writeToDisk();
|
|
187
201
|
(0, common_1.processIssues)(result, true, true);
|
|
202
|
+
writtenEndpointPaths.set(entrypoint, result);
|
|
188
203
|
await regenerateHtml();
|
|
189
204
|
}
|
|
190
205
|
async function writeOutputToDisk(entrypoint) {
|
|
@@ -533,11 +548,11 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
533
548
|
async buildFallbackError() {
|
|
534
549
|
// Not implemented yet.
|
|
535
550
|
},
|
|
536
|
-
close() {
|
|
551
|
+
async close() {
|
|
537
552
|
closed = true;
|
|
538
|
-
|
|
553
|
+
const disposePromise = disposeBackgroundWatchSubscriptions();
|
|
539
554
|
closePromise !== null && closePromise !== void 0 ? closePromise : (closePromise = project
|
|
540
|
-
.
|
|
555
|
+
.shutdown()
|
|
541
556
|
.catch((err) => {
|
|
542
557
|
console.error(err);
|
|
543
558
|
})
|
|
@@ -548,6 +563,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
548
563
|
wsClient.close();
|
|
549
564
|
}
|
|
550
565
|
clients.clear();
|
|
566
|
+
await Promise.all([disposePromise, closePromise]);
|
|
551
567
|
},
|
|
552
568
|
};
|
|
553
569
|
handleEntrypointsSubscription().catch((err) => {
|
package/cjs/core/project.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export declare function projectFactory(): (options: Required<ProjectOptions>, tu
|
|
|
37
37
|
clientChanged(): Promise<AsyncIterableIterator<TurbopackResult<{}>>>;
|
|
38
38
|
serverChanged(includeIssues: boolean): Promise<AsyncIterableIterator<TurbopackResult<{}>>>;
|
|
39
39
|
}[];
|
|
40
|
+
appPaths: NapiWrittenEndpoint[] | undefined;
|
|
41
|
+
libraryPaths: NapiWrittenEndpoint[] | undefined;
|
|
40
42
|
issues: binding.NapiIssue[];
|
|
41
43
|
}, void, unknown>;
|
|
42
44
|
hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
|
package/cjs/core/project.js
CHANGED
|
@@ -490,6 +490,8 @@ function projectFactory() {
|
|
|
490
490
|
return {
|
|
491
491
|
apps: (entrypoints.apps || []).map((e) => new EndpointImpl(e)),
|
|
492
492
|
libraries: (entrypoints.libraries || []).map((e) => new EndpointImpl(e)),
|
|
493
|
+
appPaths: entrypoints.appPaths,
|
|
494
|
+
libraryPaths: entrypoints.libraryPaths,
|
|
493
495
|
issues: entrypoints.issues,
|
|
494
496
|
};
|
|
495
497
|
}
|
package/cjs/core/types.d.ts
CHANGED
|
@@ -73,6 +73,8 @@ export interface Project {
|
|
|
73
73
|
export interface RawEntrypoints {
|
|
74
74
|
apps?: Endpoint[];
|
|
75
75
|
libraries?: Endpoint[];
|
|
76
|
+
appPaths?: NapiWrittenEndpoint[];
|
|
77
|
+
libraryPaths?: NapiWrittenEndpoint[];
|
|
76
78
|
}
|
|
77
79
|
export interface Endpoint {
|
|
78
80
|
/** Write files for the endpoint to disk. */
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { NapiWrittenEndpoint } from "../binding";
|
|
1
2
|
export interface Assets {
|
|
2
3
|
js: string[];
|
|
3
4
|
css: string[];
|
|
4
5
|
}
|
|
5
6
|
export declare function getInitialAssetsFromStats(outputDir: string): Assets;
|
|
7
|
+
export declare function getInitialAssetsFromEndpointPaths(endpoints: NapiWrittenEndpoint[]): Assets;
|
|
@@ -4,8 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getInitialAssetsFromStats = getInitialAssetsFromStats;
|
|
7
|
+
exports.getInitialAssetsFromEndpointPaths = getInitialAssetsFromEndpointPaths;
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
10
|
+
function addUniqueAsset(assets, file) {
|
|
11
|
+
if (!assets.includes(file)) {
|
|
12
|
+
assets.push(file);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function isJavascriptAsset(file) {
|
|
16
|
+
return (file.endsWith(".js") &&
|
|
17
|
+
!file.endsWith(".LICENSE.txt") &&
|
|
18
|
+
!file.endsWith(".map"));
|
|
19
|
+
}
|
|
9
20
|
function getInitialAssetsFromStats(outputDir) {
|
|
10
21
|
const assets = { js: [], css: [] };
|
|
11
22
|
const statsPath = path_1.default.join(outputDir, "stats.json");
|
|
@@ -16,12 +27,11 @@ function getInitialAssetsFromStats(outputDir) {
|
|
|
16
27
|
Object.values(stats.entrypoints).forEach((entrypoint) => {
|
|
17
28
|
var _a;
|
|
18
29
|
(_a = entrypoint.assets) === null || _a === void 0 ? void 0 : _a.forEach((asset) => {
|
|
19
|
-
if (asset.name.endsWith(".js")
|
|
20
|
-
assets.js
|
|
30
|
+
if (asset.name.endsWith(".js")) {
|
|
31
|
+
addUniqueAsset(assets.js, asset.name);
|
|
21
32
|
}
|
|
22
|
-
if (asset.name.endsWith(".css")
|
|
23
|
-
|
|
24
|
-
assets.css.push(asset.name);
|
|
33
|
+
if (asset.name.endsWith(".css")) {
|
|
34
|
+
addUniqueAsset(assets.css, asset.name);
|
|
25
35
|
}
|
|
26
36
|
});
|
|
27
37
|
});
|
|
@@ -33,3 +43,17 @@ function getInitialAssetsFromStats(outputDir) {
|
|
|
33
43
|
}
|
|
34
44
|
return assets;
|
|
35
45
|
}
|
|
46
|
+
function getInitialAssetsFromEndpointPaths(endpoints) {
|
|
47
|
+
const assets = { js: [], css: [] };
|
|
48
|
+
endpoints.forEach((endpoint) => {
|
|
49
|
+
endpoint.clientPaths.forEach((file) => {
|
|
50
|
+
if (isJavascriptAsset(file)) {
|
|
51
|
+
addUniqueAsset(assets.js, file);
|
|
52
|
+
}
|
|
53
|
+
if (file.endsWith(".css")) {
|
|
54
|
+
addUniqueAsset(assets.css, file);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
return assets;
|
|
59
|
+
}
|
package/esm/binding.d.ts
CHANGED
|
@@ -146,6 +146,8 @@ export declare function projectShutdown(project: { __napiType: "Project" }): Pro
|
|
|
146
146
|
export interface NapiEntrypoints {
|
|
147
147
|
apps?: Array<ExternalObject<ExternalEndpoint>>
|
|
148
148
|
libraries?: Array<ExternalObject<ExternalEndpoint>>
|
|
149
|
+
appPaths?: Array<NapiWrittenEndpoint>
|
|
150
|
+
libraryPaths?: Array<NapiWrittenEndpoint>
|
|
149
151
|
}
|
|
150
152
|
export declare function projectWriteAllEntrypointsToDisk(project: { __napiType: "Project" }): Promise<TurbopackResult>
|
|
151
153
|
export declare function projectEntrypointsSubscribe(project: { __napiType: "Project" }, func: (...args: any[]) => any): { __napiType: "RootTask" }
|
package/esm/commands/build.js
CHANGED
|
@@ -9,7 +9,7 @@ import { HtmlPlugin } from "../plugins/HtmlPlugin.js";
|
|
|
9
9
|
import { cleanOutput, getOutputPath } from "../utils/cleanOutput.js";
|
|
10
10
|
import { blockStdout, getPackPath } from "../utils/common.js";
|
|
11
11
|
import { findRootDir } from "../utils/findRoot.js";
|
|
12
|
-
import {
|
|
12
|
+
import { getInitialAssetsFromEndpointPaths } from "../utils/getInitialAssets.js";
|
|
13
13
|
import { processHtmlEntry } from "../utils/htmlEntry.js";
|
|
14
14
|
import { acquirePersistentCacheLock } from "../utils/lockfile.js";
|
|
15
15
|
import { normalizePath } from "../utils/normalizePath.js";
|
|
@@ -25,7 +25,7 @@ export function build(options, projectPath, rootPath) {
|
|
|
25
25
|
return buildInternal(bundleOptions, projectPath, rootPath);
|
|
26
26
|
}
|
|
27
27
|
async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
28
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
28
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
29
29
|
blockStdout();
|
|
30
30
|
if (process.env.XCODE_PROFILE) {
|
|
31
31
|
await xcodeProfilingReady();
|
|
@@ -33,6 +33,7 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
33
33
|
const resolvedProjectPath = projectPath || process.cwd();
|
|
34
34
|
const resolvedRootPath = rootPath || projectPath || process.cwd();
|
|
35
35
|
const persistentCaching = (_a = bundleOptions.config.persistentCaching) !== null && _a !== void 0 ? _a : false;
|
|
36
|
+
const shouldCreateWebpackStats = Boolean(process.env.ANALYZE) || Boolean(bundleOptions.config.stats);
|
|
36
37
|
processHtmlEntry(bundleOptions.config, resolvedProjectPath);
|
|
37
38
|
validateEntryPaths(bundleOptions.config, resolvedProjectPath);
|
|
38
39
|
await cleanOutput(bundleOptions.config, resolvedProjectPath);
|
|
@@ -50,9 +51,7 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
50
51
|
tracing: (_d = bundleOptions.tracing) !== null && _d !== void 0 ? _d : true,
|
|
51
52
|
config: {
|
|
52
53
|
...bundleOptions.config,
|
|
53
|
-
stats:
|
|
54
|
-
bundleOptions.config.stats ||
|
|
55
|
-
bundleOptions.config.entry.some((e) => !!e.html),
|
|
54
|
+
stats: shouldCreateWebpackStats,
|
|
56
55
|
pluginRuntimeStrategy: (_f = (_e = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.config) === null || _e === void 0 ? void 0 : _e.pluginRuntimeStrategy) !== null && _f !== void 0 ? _f : (useWorkerThreads() ? "workerThreads" : "childProcesses"),
|
|
57
56
|
},
|
|
58
57
|
projectPath: normalizePath(resolvedProjectPath),
|
|
@@ -63,7 +62,6 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
63
62
|
// Build mode is a short-lived, one-shot compilation, so avoid paying
|
|
64
63
|
// dependency graph bookkeeping cost unless the persistent cache needs it.
|
|
65
64
|
dependencyTracking: persistentCaching,
|
|
66
|
-
isShortSession: true,
|
|
67
65
|
});
|
|
68
66
|
const entrypoints = await project.writeAllEntrypointsToDisk();
|
|
69
67
|
handleIssues(entrypoints.issues);
|
|
@@ -78,21 +76,19 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
78
76
|
.map((e) => e.html),
|
|
79
77
|
];
|
|
80
78
|
if (htmlConfigs.length > 0) {
|
|
81
|
-
const assets =
|
|
79
|
+
const assets = getInitialAssetsFromEndpointPaths([
|
|
80
|
+
...((_g = entrypoints.appPaths) !== null && _g !== void 0 ? _g : []),
|
|
81
|
+
...((_h = entrypoints.libraryPaths) !== null && _h !== void 0 ? _h : []),
|
|
82
|
+
]);
|
|
82
83
|
const outputDir = getOutputPath(bundleOptions.config, resolvedProjectPath);
|
|
83
|
-
|
|
84
|
-
const discovered = getInitialAssetsFromStats(outputDir);
|
|
85
|
-
assets.js.push(...discovered.js);
|
|
86
|
-
assets.css.push(...discovered.css);
|
|
87
|
-
}
|
|
88
|
-
const publicPath = (_g = bundleOptions.config.output) === null || _g === void 0 ? void 0 : _g.publicPath;
|
|
84
|
+
const publicPath = (_j = bundleOptions.config.output) === null || _j === void 0 ? void 0 : _j.publicPath;
|
|
89
85
|
for (const config of htmlConfigs) {
|
|
90
86
|
const plugin = new HtmlPlugin(config);
|
|
91
87
|
await plugin.generate(outputDir, assets, publicPath);
|
|
92
88
|
}
|
|
93
89
|
}
|
|
94
90
|
if (process.env.ANALYZE) {
|
|
95
|
-
await analyzeBundle(((
|
|
91
|
+
await analyzeBundle(((_k = bundleOptions.config.output) === null || _k === void 0 ? void 0 : _k.path) || "dist");
|
|
96
92
|
}
|
|
97
93
|
}
|
|
98
94
|
finally {
|
package/esm/commands/dev.js
CHANGED
|
@@ -228,8 +228,19 @@ async function runDev(options, projectPath, rootPath, serverOptions) {
|
|
|
228
228
|
: serveOptsBase.hostname;
|
|
229
229
|
printServerInfo(scheme, displayHost, serveOptsBase.port);
|
|
230
230
|
}
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
let cleanupStarted = false;
|
|
232
|
+
const cleanup = async () => {
|
|
233
|
+
if (cleanupStarted) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
cleanupStarted = true;
|
|
237
|
+
try {
|
|
238
|
+
await hotReloader.close();
|
|
239
|
+
}
|
|
240
|
+
catch (err) {
|
|
241
|
+
console.error(err);
|
|
242
|
+
process.exit(1);
|
|
243
|
+
}
|
|
233
244
|
// We always create HTTP/1.1 server (http or https), so closeAllConnections exists; Hono's
|
|
234
245
|
// ServerType union includes HTTP/2, so TS does not narrow. Use runtime check to satisfy types.
|
|
235
246
|
if ("closeAllConnections" in server &&
|
package/esm/core/hmr.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface HotReloaderInterface {
|
|
|
38
38
|
/** Handle a message from a client (JSON string). */
|
|
39
39
|
handleClientMessage(ws: WSLike, data: string): void;
|
|
40
40
|
buildFallbackError(): Promise<void>;
|
|
41
|
-
close(): void
|
|
41
|
+
close(): Promise<void>;
|
|
42
42
|
}
|
|
43
43
|
export type ChangeSubscriptions = Map<string, Promise<AsyncIterableIterator<TurbopackResult>>>;
|
|
44
44
|
export type ReadyIds = Set<string>;
|
package/esm/core/hmr.js
CHANGED
|
@@ -4,7 +4,7 @@ import { WebSocketServer } from "ws";
|
|
|
4
4
|
import { HtmlPlugin } from "../plugins/HtmlPlugin.js";
|
|
5
5
|
import { cleanOutput, getOutputPath } from "../utils/cleanOutput.js";
|
|
6
6
|
import { debounce, getPackPath, processIssues } from "../utils/common.js";
|
|
7
|
-
import {
|
|
7
|
+
import { getInitialAssetsFromEndpointPaths } from "../utils/getInitialAssets.js";
|
|
8
8
|
import { processHtmlEntry } from "../utils/htmlEntry.js";
|
|
9
9
|
import { acquirePersistentCacheLock } from "../utils/lockfile.js";
|
|
10
10
|
import { normalizePath } from "../utils/normalizePath.js";
|
|
@@ -69,9 +69,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
69
69
|
.filter((e) => !!e.html)
|
|
70
70
|
.map((e) => e.html),
|
|
71
71
|
];
|
|
72
|
-
const shouldCreateWebpackStats = Boolean(process.env.ANALYZE) ||
|
|
73
|
-
bundleOptions.config.stats ||
|
|
74
|
-
htmlConfigs.length > 0;
|
|
72
|
+
const shouldCreateWebpackStats = Boolean(process.env.ANALYZE) || Boolean(bundleOptions.config.stats);
|
|
75
73
|
let project;
|
|
76
74
|
try {
|
|
77
75
|
project = await createProject({
|
|
@@ -159,6 +157,18 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
159
157
|
hmrEventHappened = true;
|
|
160
158
|
sendEnqueuedMessagesDebounce();
|
|
161
159
|
}
|
|
160
|
+
const writtenEndpointPaths = new Map();
|
|
161
|
+
function updateWrittenEndpointPaths(endpoints, paths) {
|
|
162
|
+
if (!endpoints || !paths) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
endpoints.forEach((endpoint, index) => {
|
|
166
|
+
const written = paths[index];
|
|
167
|
+
if (written) {
|
|
168
|
+
writtenEndpointPaths.set(endpoint, written);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
162
172
|
async function regenerateHtml() {
|
|
163
173
|
var _a;
|
|
164
174
|
if (htmlConfigs.length === 0) {
|
|
@@ -166,7 +176,9 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
166
176
|
}
|
|
167
177
|
const outputDir = getOutputPath(bundleOptions.config, resolvedProjectPath);
|
|
168
178
|
const publicPath = (_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.publicPath;
|
|
169
|
-
const assets =
|
|
179
|
+
const assets = getInitialAssetsFromEndpointPaths([
|
|
180
|
+
...writtenEndpointPaths.values(),
|
|
181
|
+
]);
|
|
170
182
|
for (const config of htmlConfigs) {
|
|
171
183
|
const plugin = new HtmlPlugin(config);
|
|
172
184
|
await plugin.generate(outputDir, assets, publicPath);
|
|
@@ -175,11 +187,14 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
175
187
|
async function writeAllEntrypointsToDisk() {
|
|
176
188
|
const result = await project.writeAllEntrypointsToDisk();
|
|
177
189
|
processIssues(result, true, true);
|
|
190
|
+
updateWrittenEndpointPaths(result.apps, result.appPaths);
|
|
191
|
+
updateWrittenEndpointPaths(result.libraries, result.libraryPaths);
|
|
178
192
|
await regenerateHtml();
|
|
179
193
|
}
|
|
180
194
|
async function writeEntrypointToDisk(entrypoint) {
|
|
181
195
|
const result = await entrypoint.writeToDisk();
|
|
182
196
|
processIssues(result, true, true);
|
|
197
|
+
writtenEndpointPaths.set(entrypoint, result);
|
|
183
198
|
await regenerateHtml();
|
|
184
199
|
}
|
|
185
200
|
async function writeOutputToDisk(entrypoint) {
|
|
@@ -528,11 +543,11 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
528
543
|
async buildFallbackError() {
|
|
529
544
|
// Not implemented yet.
|
|
530
545
|
},
|
|
531
|
-
close() {
|
|
546
|
+
async close() {
|
|
532
547
|
closed = true;
|
|
533
|
-
|
|
548
|
+
const disposePromise = disposeBackgroundWatchSubscriptions();
|
|
534
549
|
closePromise !== null && closePromise !== void 0 ? closePromise : (closePromise = project
|
|
535
|
-
.
|
|
550
|
+
.shutdown()
|
|
536
551
|
.catch((err) => {
|
|
537
552
|
console.error(err);
|
|
538
553
|
})
|
|
@@ -543,6 +558,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
543
558
|
wsClient.close();
|
|
544
559
|
}
|
|
545
560
|
clients.clear();
|
|
561
|
+
await Promise.all([disposePromise, closePromise]);
|
|
546
562
|
},
|
|
547
563
|
};
|
|
548
564
|
handleEntrypointsSubscription().catch((err) => {
|
package/esm/core/project.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export declare function projectFactory(): (options: Required<ProjectOptions>, tu
|
|
|
37
37
|
clientChanged(): Promise<AsyncIterableIterator<TurbopackResult<{}>>>;
|
|
38
38
|
serverChanged(includeIssues: boolean): Promise<AsyncIterableIterator<TurbopackResult<{}>>>;
|
|
39
39
|
}[];
|
|
40
|
+
appPaths: NapiWrittenEndpoint[] | undefined;
|
|
41
|
+
libraryPaths: NapiWrittenEndpoint[] | undefined;
|
|
40
42
|
issues: binding.NapiIssue[];
|
|
41
43
|
}, void, unknown>;
|
|
42
44
|
hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
|
package/esm/core/project.js
CHANGED
|
@@ -451,6 +451,8 @@ export function projectFactory() {
|
|
|
451
451
|
return {
|
|
452
452
|
apps: (entrypoints.apps || []).map((e) => new EndpointImpl(e)),
|
|
453
453
|
libraries: (entrypoints.libraries || []).map((e) => new EndpointImpl(e)),
|
|
454
|
+
appPaths: entrypoints.appPaths,
|
|
455
|
+
libraryPaths: entrypoints.libraryPaths,
|
|
454
456
|
issues: entrypoints.issues,
|
|
455
457
|
};
|
|
456
458
|
}
|
package/esm/core/types.d.ts
CHANGED
|
@@ -73,6 +73,8 @@ export interface Project {
|
|
|
73
73
|
export interface RawEntrypoints {
|
|
74
74
|
apps?: Endpoint[];
|
|
75
75
|
libraries?: Endpoint[];
|
|
76
|
+
appPaths?: NapiWrittenEndpoint[];
|
|
77
|
+
libraryPaths?: NapiWrittenEndpoint[];
|
|
76
78
|
}
|
|
77
79
|
export interface Endpoint {
|
|
78
80
|
/** Write files for the endpoint to disk. */
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { NapiWrittenEndpoint } from "../binding";
|
|
1
2
|
export interface Assets {
|
|
2
3
|
js: string[];
|
|
3
4
|
css: string[];
|
|
4
5
|
}
|
|
5
6
|
export declare function getInitialAssetsFromStats(outputDir: string): Assets;
|
|
7
|
+
export declare function getInitialAssetsFromEndpointPaths(endpoints: NapiWrittenEndpoint[]): Assets;
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
+
function addUniqueAsset(assets, file) {
|
|
4
|
+
if (!assets.includes(file)) {
|
|
5
|
+
assets.push(file);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function isJavascriptAsset(file) {
|
|
9
|
+
return (file.endsWith(".js") &&
|
|
10
|
+
!file.endsWith(".LICENSE.txt") &&
|
|
11
|
+
!file.endsWith(".map"));
|
|
12
|
+
}
|
|
3
13
|
export function getInitialAssetsFromStats(outputDir) {
|
|
4
14
|
const assets = { js: [], css: [] };
|
|
5
15
|
const statsPath = path.join(outputDir, "stats.json");
|
|
@@ -10,12 +20,11 @@ export function getInitialAssetsFromStats(outputDir) {
|
|
|
10
20
|
Object.values(stats.entrypoints).forEach((entrypoint) => {
|
|
11
21
|
var _a;
|
|
12
22
|
(_a = entrypoint.assets) === null || _a === void 0 ? void 0 : _a.forEach((asset) => {
|
|
13
|
-
if (asset.name.endsWith(".js")
|
|
14
|
-
assets.js
|
|
23
|
+
if (asset.name.endsWith(".js")) {
|
|
24
|
+
addUniqueAsset(assets.js, asset.name);
|
|
15
25
|
}
|
|
16
|
-
if (asset.name.endsWith(".css")
|
|
17
|
-
|
|
18
|
-
assets.css.push(asset.name);
|
|
26
|
+
if (asset.name.endsWith(".css")) {
|
|
27
|
+
addUniqueAsset(assets.css, asset.name);
|
|
19
28
|
}
|
|
20
29
|
});
|
|
21
30
|
});
|
|
@@ -27,3 +36,17 @@ export function getInitialAssetsFromStats(outputDir) {
|
|
|
27
36
|
}
|
|
28
37
|
return assets;
|
|
29
38
|
}
|
|
39
|
+
export function getInitialAssetsFromEndpointPaths(endpoints) {
|
|
40
|
+
const assets = { js: [], css: [] };
|
|
41
|
+
endpoints.forEach((endpoint) => {
|
|
42
|
+
endpoint.clientPaths.forEach((file) => {
|
|
43
|
+
if (isJavascriptAsset(file)) {
|
|
44
|
+
addUniqueAsset(assets.js, file);
|
|
45
|
+
}
|
|
46
|
+
if (file.endsWith(".css")) {
|
|
47
|
+
addUniqueAsset(assets.css, file);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
return assets;
|
|
52
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/pack",
|
|
3
|
-
"version": "1.4.12-alpha.
|
|
3
|
+
"version": "1.4.12-alpha.6",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"types": "esm/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@hono/node-server": "^1.19.11",
|
|
42
42
|
"@hono/node-ws": "^1.3.0",
|
|
43
43
|
"@swc/helpers": "0.5.15",
|
|
44
|
-
"@utoo/pack-shared": "1.4.12-alpha.
|
|
44
|
+
"@utoo/pack-shared": "1.4.12-alpha.6",
|
|
45
45
|
"domparser-rs": "^0.0.7",
|
|
46
46
|
"find-up": "4.1.0",
|
|
47
47
|
"get-port": "5.1.1",
|
|
@@ -96,12 +96,12 @@
|
|
|
96
96
|
"directory": "packages/pack"
|
|
97
97
|
},
|
|
98
98
|
"optionalDependencies": {
|
|
99
|
-
"@utoo/pack-darwin-arm64": "1.4.12-alpha.
|
|
100
|
-
"@utoo/pack-darwin-x64": "1.4.12-alpha.
|
|
101
|
-
"@utoo/pack-linux-arm64-gnu": "1.4.12-alpha.
|
|
102
|
-
"@utoo/pack-linux-arm64-musl": "1.4.12-alpha.
|
|
103
|
-
"@utoo/pack-linux-x64-gnu": "1.4.12-alpha.
|
|
104
|
-
"@utoo/pack-linux-x64-musl": "1.4.12-alpha.
|
|
105
|
-
"@utoo/pack-win32-x64-msvc": "1.4.12-alpha.
|
|
99
|
+
"@utoo/pack-darwin-arm64": "1.4.12-alpha.6",
|
|
100
|
+
"@utoo/pack-darwin-x64": "1.4.12-alpha.6",
|
|
101
|
+
"@utoo/pack-linux-arm64-gnu": "1.4.12-alpha.6",
|
|
102
|
+
"@utoo/pack-linux-arm64-musl": "1.4.12-alpha.6",
|
|
103
|
+
"@utoo/pack-linux-x64-gnu": "1.4.12-alpha.6",
|
|
104
|
+
"@utoo/pack-linux-x64-musl": "1.4.12-alpha.6",
|
|
105
|
+
"@utoo/pack-win32-x64-msvc": "1.4.12-alpha.6"
|
|
106
106
|
}
|
|
107
107
|
}
|