@utoo/pack 1.4.12-alpha.2 → 1.4.12-alpha.4
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 +0 -7
- package/cjs/commands/build.js +13 -9
- package/cjs/core/hmr.js +4 -20
- package/cjs/core/project.d.ts +0 -3
- package/cjs/core/project.js +0 -3
- package/cjs/core/types.d.ts +1 -5
- package/cjs/utils/getInitialAssets.d.ts +0 -2
- package/cjs/utils/getInitialAssets.js +5 -29
- package/esm/binding.d.ts +0 -7
- package/esm/commands/build.js +14 -10
- package/esm/core/hmr.js +5 -21
- package/esm/core/project.d.ts +0 -3
- package/esm/core/project.js +0 -3
- package/esm/core/types.d.ts +1 -5
- package/esm/utils/getInitialAssets.d.ts +0 -2
- package/esm/utils/getInitialAssets.js +5 -28
- package/package.json +9 -9
package/cjs/binding.d.ts
CHANGED
|
@@ -146,8 +146,6 @@ 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>
|
|
151
149
|
}
|
|
152
150
|
export declare function projectWriteAllEntrypointsToDisk(project: { __napiType: "Project" }): Promise<TurbopackResult>
|
|
153
151
|
export declare function projectEntrypointsSubscribe(project: { __napiType: "Project" }, func: (...args: any[]) => any): { __napiType: "RootTask" }
|
|
@@ -243,11 +241,6 @@ export interface NapiSourcePos {
|
|
|
243
241
|
line: number
|
|
244
242
|
column: number
|
|
245
243
|
}
|
|
246
|
-
export interface NapiDiagnostic {
|
|
247
|
-
category: string
|
|
248
|
-
name: string
|
|
249
|
-
payload: Record<string, string>
|
|
250
|
-
}
|
|
251
244
|
/**
|
|
252
245
|
* Initialize tracing subscriber to emit traces. This configures subscribers
|
|
253
246
|
* for Trace Event Format <https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview>.
|
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;
|
|
35
35
|
(0, common_1.blockStdout)();
|
|
36
36
|
if (process.env.XCODE_PROFILE) {
|
|
37
37
|
await (0, xcodeProfile_1.xcodeProfilingReady)();
|
|
@@ -39,7 +39,6 @@ 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);
|
|
43
42
|
(0, htmlEntry_1.processHtmlEntry)(bundleOptions.config, resolvedProjectPath);
|
|
44
43
|
(0, validateEntry_1.validateEntryPaths)(bundleOptions.config, resolvedProjectPath);
|
|
45
44
|
await (0, cleanOutput_1.cleanOutput)(bundleOptions.config, resolvedProjectPath);
|
|
@@ -57,7 +56,9 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
57
56
|
tracing: (_d = bundleOptions.tracing) !== null && _d !== void 0 ? _d : true,
|
|
58
57
|
config: {
|
|
59
58
|
...bundleOptions.config,
|
|
60
|
-
stats:
|
|
59
|
+
stats: Boolean(process.env.ANALYZE) ||
|
|
60
|
+
bundleOptions.config.stats ||
|
|
61
|
+
bundleOptions.config.entry.some((e) => !!e.html),
|
|
61
62
|
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"),
|
|
62
63
|
},
|
|
63
64
|
projectPath: (0, normalizePath_1.normalizePath)(resolvedProjectPath),
|
|
@@ -68,6 +69,7 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
68
69
|
// Build mode is a short-lived, one-shot compilation, so avoid paying
|
|
69
70
|
// dependency graph bookkeeping cost unless the persistent cache needs it.
|
|
70
71
|
dependencyTracking: persistentCaching,
|
|
72
|
+
isShortSession: true,
|
|
71
73
|
});
|
|
72
74
|
const entrypoints = await project.writeAllEntrypointsToDisk();
|
|
73
75
|
(0, pack_shared_1.handleIssues)(entrypoints.issues);
|
|
@@ -82,19 +84,21 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
82
84
|
.map((e) => e.html),
|
|
83
85
|
];
|
|
84
86
|
if (htmlConfigs.length > 0) {
|
|
85
|
-
const assets =
|
|
86
|
-
...((_g = entrypoints.appPaths) !== null && _g !== void 0 ? _g : []),
|
|
87
|
-
...((_h = entrypoints.libraryPaths) !== null && _h !== void 0 ? _h : []),
|
|
88
|
-
]);
|
|
87
|
+
const assets = { js: [], css: [] };
|
|
89
88
|
const outputDir = (0, cleanOutput_1.getOutputPath)(bundleOptions.config, resolvedProjectPath);
|
|
90
|
-
|
|
89
|
+
if (assets.js.length === 0 && assets.css.length === 0) {
|
|
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;
|
|
91
95
|
for (const config of htmlConfigs) {
|
|
92
96
|
const plugin = new HtmlPlugin_1.HtmlPlugin(config);
|
|
93
97
|
await plugin.generate(outputDir, assets, publicPath);
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
100
|
if (process.env.ANALYZE) {
|
|
97
|
-
await analyzeBundle(((
|
|
101
|
+
await analyzeBundle(((_h = bundleOptions.config.output) === null || _h === void 0 ? void 0 : _h.path) || "dist");
|
|
98
102
|
}
|
|
99
103
|
}
|
|
100
104
|
finally {
|
package/cjs/core/hmr.js
CHANGED
|
@@ -74,7 +74,9 @@ 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) ||
|
|
77
|
+
const shouldCreateWebpackStats = Boolean(process.env.ANALYZE) ||
|
|
78
|
+
bundleOptions.config.stats ||
|
|
79
|
+
htmlConfigs.length > 0;
|
|
78
80
|
let project;
|
|
79
81
|
try {
|
|
80
82
|
project = await createProject({
|
|
@@ -155,7 +157,6 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
155
157
|
const sendEnqueuedMessagesDebounce = (0, common_1.debounce)(sendEnqueuedMessages, 2);
|
|
156
158
|
function sendTurbopackMessage(payload) {
|
|
157
159
|
var _a;
|
|
158
|
-
payload.diagnostics = [];
|
|
159
160
|
payload.issues = [];
|
|
160
161
|
for (const client of clients) {
|
|
161
162
|
(_a = clientStates.get(client)) === null || _a === void 0 ? void 0 : _a.turbopackUpdates.push(payload);
|
|
@@ -163,18 +164,6 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
163
164
|
hmrEventHappened = true;
|
|
164
165
|
sendEnqueuedMessagesDebounce();
|
|
165
166
|
}
|
|
166
|
-
const writtenEndpointPaths = new Map();
|
|
167
|
-
function updateWrittenEndpointPaths(endpoints, paths) {
|
|
168
|
-
if (!endpoints || !paths) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
endpoints.forEach((endpoint, index) => {
|
|
172
|
-
const written = paths[index];
|
|
173
|
-
if (written) {
|
|
174
|
-
writtenEndpointPaths.set(endpoint, written);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
167
|
async function regenerateHtml() {
|
|
179
168
|
var _a;
|
|
180
169
|
if (htmlConfigs.length === 0) {
|
|
@@ -182,9 +171,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
182
171
|
}
|
|
183
172
|
const outputDir = (0, cleanOutput_1.getOutputPath)(bundleOptions.config, resolvedProjectPath);
|
|
184
173
|
const publicPath = (_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.publicPath;
|
|
185
|
-
const assets = (0, getInitialAssets_1.
|
|
186
|
-
...writtenEndpointPaths.values(),
|
|
187
|
-
]);
|
|
174
|
+
const assets = (0, getInitialAssets_1.getInitialAssetsFromStats)(outputDir);
|
|
188
175
|
for (const config of htmlConfigs) {
|
|
189
176
|
const plugin = new HtmlPlugin_1.HtmlPlugin(config);
|
|
190
177
|
await plugin.generate(outputDir, assets, publicPath);
|
|
@@ -193,14 +180,11 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
193
180
|
async function writeAllEntrypointsToDisk() {
|
|
194
181
|
const result = await project.writeAllEntrypointsToDisk();
|
|
195
182
|
(0, common_1.processIssues)(result, true, true);
|
|
196
|
-
updateWrittenEndpointPaths(result.apps, result.appPaths);
|
|
197
|
-
updateWrittenEndpointPaths(result.libraries, result.libraryPaths);
|
|
198
183
|
await regenerateHtml();
|
|
199
184
|
}
|
|
200
185
|
async function writeEntrypointToDisk(entrypoint) {
|
|
201
186
|
const result = await entrypoint.writeToDisk();
|
|
202
187
|
(0, common_1.processIssues)(result, true, true);
|
|
203
|
-
writtenEndpointPaths.set(entrypoint, result);
|
|
204
188
|
await regenerateHtml();
|
|
205
189
|
}
|
|
206
190
|
async function writeOutputToDisk(entrypoint) {
|
package/cjs/core/project.d.ts
CHANGED
|
@@ -37,10 +37,7 @@ 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;
|
|
42
40
|
issues: binding.NapiIssue[];
|
|
43
|
-
diagnostics: binding.NapiDiagnostic[];
|
|
44
41
|
}, void, unknown>;
|
|
45
42
|
hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
|
|
46
43
|
hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<HmrIdentifiers>>;
|
package/cjs/core/project.js
CHANGED
|
@@ -490,10 +490,7 @@ 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,
|
|
495
493
|
issues: entrypoints.issues,
|
|
496
|
-
diagnostics: entrypoints.diagnostics,
|
|
497
494
|
};
|
|
498
495
|
}
|
|
499
496
|
return async function createProject(options, turboEngineOptions) {
|
package/cjs/core/types.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { HmrIdentifiers,
|
|
1
|
+
import { HmrIdentifiers, NapiIssue, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "../binding";
|
|
2
2
|
import { BundleOptions } from "../config/types";
|
|
3
3
|
declare global {
|
|
4
4
|
export type TurbopackResult<T = {}> = T & {
|
|
5
5
|
issues: NapiIssue[];
|
|
6
|
-
diagnostics: NapiDiagnostic[];
|
|
7
6
|
};
|
|
8
7
|
export type RefCell = {
|
|
9
8
|
readonly __tag: unique symbol;
|
|
@@ -18,7 +17,6 @@ export interface BaseUpdate {
|
|
|
18
17
|
headers: unknown;
|
|
19
18
|
path: string;
|
|
20
19
|
};
|
|
21
|
-
diagnostics: unknown[];
|
|
22
20
|
issues: NapiIssue[];
|
|
23
21
|
}
|
|
24
22
|
export interface IssuesUpdate extends BaseUpdate {
|
|
@@ -75,8 +73,6 @@ export interface Project {
|
|
|
75
73
|
export interface RawEntrypoints {
|
|
76
74
|
apps?: Endpoint[];
|
|
77
75
|
libraries?: Endpoint[];
|
|
78
|
-
appPaths?: NapiWrittenEndpoint[];
|
|
79
|
-
libraryPaths?: NapiWrittenEndpoint[];
|
|
80
76
|
}
|
|
81
77
|
export interface Endpoint {
|
|
82
78
|
/** Write files for the endpoint to disk. */
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type { NapiWrittenEndpoint } from "../binding";
|
|
2
1
|
export interface Assets {
|
|
3
2
|
js: string[];
|
|
4
3
|
css: string[];
|
|
5
4
|
}
|
|
6
5
|
export declare function getInitialAssetsFromStats(outputDir: string): Assets;
|
|
7
|
-
export declare function getInitialAssetsFromEndpointPaths(endpoints: NapiWrittenEndpoint[]): Assets;
|
|
@@ -4,19 +4,8 @@ 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;
|
|
8
7
|
const fs_1 = __importDefault(require("fs"));
|
|
9
8
|
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
|
-
}
|
|
20
9
|
function getInitialAssetsFromStats(outputDir) {
|
|
21
10
|
const assets = { js: [], css: [] };
|
|
22
11
|
const statsPath = path_1.default.join(outputDir, "stats.json");
|
|
@@ -27,11 +16,12 @@ function getInitialAssetsFromStats(outputDir) {
|
|
|
27
16
|
Object.values(stats.entrypoints).forEach((entrypoint) => {
|
|
28
17
|
var _a;
|
|
29
18
|
(_a = entrypoint.assets) === null || _a === void 0 ? void 0 : _a.forEach((asset) => {
|
|
30
|
-
if (asset.name.endsWith(".js")) {
|
|
31
|
-
|
|
19
|
+
if (asset.name.endsWith(".js") && !assets.js.includes(asset.name)) {
|
|
20
|
+
assets.js.push(asset.name);
|
|
32
21
|
}
|
|
33
|
-
if (asset.name.endsWith(".css")
|
|
34
|
-
|
|
22
|
+
if (asset.name.endsWith(".css") &&
|
|
23
|
+
!assets.css.includes(asset.name)) {
|
|
24
|
+
assets.css.push(asset.name);
|
|
35
25
|
}
|
|
36
26
|
});
|
|
37
27
|
});
|
|
@@ -43,17 +33,3 @@ function getInitialAssetsFromStats(outputDir) {
|
|
|
43
33
|
}
|
|
44
34
|
return assets;
|
|
45
35
|
}
|
|
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,8 +146,6 @@ 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>
|
|
151
149
|
}
|
|
152
150
|
export declare function projectWriteAllEntrypointsToDisk(project: { __napiType: "Project" }): Promise<TurbopackResult>
|
|
153
151
|
export declare function projectEntrypointsSubscribe(project: { __napiType: "Project" }, func: (...args: any[]) => any): { __napiType: "RootTask" }
|
|
@@ -243,11 +241,6 @@ export interface NapiSourcePos {
|
|
|
243
241
|
line: number
|
|
244
242
|
column: number
|
|
245
243
|
}
|
|
246
|
-
export interface NapiDiagnostic {
|
|
247
|
-
category: string
|
|
248
|
-
name: string
|
|
249
|
-
payload: Record<string, string>
|
|
250
|
-
}
|
|
251
244
|
/**
|
|
252
245
|
* Initialize tracing subscriber to emit traces. This configures subscribers
|
|
253
246
|
* for Trace Event Format <https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview>.
|
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 { getInitialAssetsFromStats } 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;
|
|
29
29
|
blockStdout();
|
|
30
30
|
if (process.env.XCODE_PROFILE) {
|
|
31
31
|
await xcodeProfilingReady();
|
|
@@ -33,7 +33,6 @@ 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);
|
|
37
36
|
processHtmlEntry(bundleOptions.config, resolvedProjectPath);
|
|
38
37
|
validateEntryPaths(bundleOptions.config, resolvedProjectPath);
|
|
39
38
|
await cleanOutput(bundleOptions.config, resolvedProjectPath);
|
|
@@ -51,7 +50,9 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
51
50
|
tracing: (_d = bundleOptions.tracing) !== null && _d !== void 0 ? _d : true,
|
|
52
51
|
config: {
|
|
53
52
|
...bundleOptions.config,
|
|
54
|
-
stats:
|
|
53
|
+
stats: Boolean(process.env.ANALYZE) ||
|
|
54
|
+
bundleOptions.config.stats ||
|
|
55
|
+
bundleOptions.config.entry.some((e) => !!e.html),
|
|
55
56
|
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"),
|
|
56
57
|
},
|
|
57
58
|
projectPath: normalizePath(resolvedProjectPath),
|
|
@@ -62,6 +63,7 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
62
63
|
// Build mode is a short-lived, one-shot compilation, so avoid paying
|
|
63
64
|
// dependency graph bookkeeping cost unless the persistent cache needs it.
|
|
64
65
|
dependencyTracking: persistentCaching,
|
|
66
|
+
isShortSession: true,
|
|
65
67
|
});
|
|
66
68
|
const entrypoints = await project.writeAllEntrypointsToDisk();
|
|
67
69
|
handleIssues(entrypoints.issues);
|
|
@@ -76,19 +78,21 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
76
78
|
.map((e) => e.html),
|
|
77
79
|
];
|
|
78
80
|
if (htmlConfigs.length > 0) {
|
|
79
|
-
const assets =
|
|
80
|
-
...((_g = entrypoints.appPaths) !== null && _g !== void 0 ? _g : []),
|
|
81
|
-
...((_h = entrypoints.libraryPaths) !== null && _h !== void 0 ? _h : []),
|
|
82
|
-
]);
|
|
81
|
+
const assets = { js: [], css: [] };
|
|
83
82
|
const outputDir = getOutputPath(bundleOptions.config, resolvedProjectPath);
|
|
84
|
-
|
|
83
|
+
if (assets.js.length === 0 && assets.css.length === 0) {
|
|
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;
|
|
85
89
|
for (const config of htmlConfigs) {
|
|
86
90
|
const plugin = new HtmlPlugin(config);
|
|
87
91
|
await plugin.generate(outputDir, assets, publicPath);
|
|
88
92
|
}
|
|
89
93
|
}
|
|
90
94
|
if (process.env.ANALYZE) {
|
|
91
|
-
await analyzeBundle(((
|
|
95
|
+
await analyzeBundle(((_h = bundleOptions.config.output) === null || _h === void 0 ? void 0 : _h.path) || "dist");
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
98
|
finally {
|
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 { getInitialAssetsFromStats } 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,7 +69,9 @@ 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) ||
|
|
72
|
+
const shouldCreateWebpackStats = Boolean(process.env.ANALYZE) ||
|
|
73
|
+
bundleOptions.config.stats ||
|
|
74
|
+
htmlConfigs.length > 0;
|
|
73
75
|
let project;
|
|
74
76
|
try {
|
|
75
77
|
project = await createProject({
|
|
@@ -150,7 +152,6 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
150
152
|
const sendEnqueuedMessagesDebounce = debounce(sendEnqueuedMessages, 2);
|
|
151
153
|
function sendTurbopackMessage(payload) {
|
|
152
154
|
var _a;
|
|
153
|
-
payload.diagnostics = [];
|
|
154
155
|
payload.issues = [];
|
|
155
156
|
for (const client of clients) {
|
|
156
157
|
(_a = clientStates.get(client)) === null || _a === void 0 ? void 0 : _a.turbopackUpdates.push(payload);
|
|
@@ -158,18 +159,6 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
158
159
|
hmrEventHappened = true;
|
|
159
160
|
sendEnqueuedMessagesDebounce();
|
|
160
161
|
}
|
|
161
|
-
const writtenEndpointPaths = new Map();
|
|
162
|
-
function updateWrittenEndpointPaths(endpoints, paths) {
|
|
163
|
-
if (!endpoints || !paths) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
endpoints.forEach((endpoint, index) => {
|
|
167
|
-
const written = paths[index];
|
|
168
|
-
if (written) {
|
|
169
|
-
writtenEndpointPaths.set(endpoint, written);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
162
|
async function regenerateHtml() {
|
|
174
163
|
var _a;
|
|
175
164
|
if (htmlConfigs.length === 0) {
|
|
@@ -177,9 +166,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
177
166
|
}
|
|
178
167
|
const outputDir = getOutputPath(bundleOptions.config, resolvedProjectPath);
|
|
179
168
|
const publicPath = (_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.publicPath;
|
|
180
|
-
const assets =
|
|
181
|
-
...writtenEndpointPaths.values(),
|
|
182
|
-
]);
|
|
169
|
+
const assets = getInitialAssetsFromStats(outputDir);
|
|
183
170
|
for (const config of htmlConfigs) {
|
|
184
171
|
const plugin = new HtmlPlugin(config);
|
|
185
172
|
await plugin.generate(outputDir, assets, publicPath);
|
|
@@ -188,14 +175,11 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
188
175
|
async function writeAllEntrypointsToDisk() {
|
|
189
176
|
const result = await project.writeAllEntrypointsToDisk();
|
|
190
177
|
processIssues(result, true, true);
|
|
191
|
-
updateWrittenEndpointPaths(result.apps, result.appPaths);
|
|
192
|
-
updateWrittenEndpointPaths(result.libraries, result.libraryPaths);
|
|
193
178
|
await regenerateHtml();
|
|
194
179
|
}
|
|
195
180
|
async function writeEntrypointToDisk(entrypoint) {
|
|
196
181
|
const result = await entrypoint.writeToDisk();
|
|
197
182
|
processIssues(result, true, true);
|
|
198
|
-
writtenEndpointPaths.set(entrypoint, result);
|
|
199
183
|
await regenerateHtml();
|
|
200
184
|
}
|
|
201
185
|
async function writeOutputToDisk(entrypoint) {
|
package/esm/core/project.d.ts
CHANGED
|
@@ -37,10 +37,7 @@ 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;
|
|
42
40
|
issues: binding.NapiIssue[];
|
|
43
|
-
diagnostics: binding.NapiDiagnostic[];
|
|
44
41
|
}, void, unknown>;
|
|
45
42
|
hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
|
|
46
43
|
hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<HmrIdentifiers>>;
|
package/esm/core/project.js
CHANGED
|
@@ -451,10 +451,7 @@ 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,
|
|
456
454
|
issues: entrypoints.issues,
|
|
457
|
-
diagnostics: entrypoints.diagnostics,
|
|
458
455
|
};
|
|
459
456
|
}
|
|
460
457
|
return async function createProject(options, turboEngineOptions) {
|
package/esm/core/types.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { HmrIdentifiers,
|
|
1
|
+
import { HmrIdentifiers, NapiIssue, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "../binding";
|
|
2
2
|
import { BundleOptions } from "../config/types";
|
|
3
3
|
declare global {
|
|
4
4
|
export type TurbopackResult<T = {}> = T & {
|
|
5
5
|
issues: NapiIssue[];
|
|
6
|
-
diagnostics: NapiDiagnostic[];
|
|
7
6
|
};
|
|
8
7
|
export type RefCell = {
|
|
9
8
|
readonly __tag: unique symbol;
|
|
@@ -18,7 +17,6 @@ export interface BaseUpdate {
|
|
|
18
17
|
headers: unknown;
|
|
19
18
|
path: string;
|
|
20
19
|
};
|
|
21
|
-
diagnostics: unknown[];
|
|
22
20
|
issues: NapiIssue[];
|
|
23
21
|
}
|
|
24
22
|
export interface IssuesUpdate extends BaseUpdate {
|
|
@@ -75,8 +73,6 @@ export interface Project {
|
|
|
75
73
|
export interface RawEntrypoints {
|
|
76
74
|
apps?: Endpoint[];
|
|
77
75
|
libraries?: Endpoint[];
|
|
78
|
-
appPaths?: NapiWrittenEndpoint[];
|
|
79
|
-
libraryPaths?: NapiWrittenEndpoint[];
|
|
80
76
|
}
|
|
81
77
|
export interface Endpoint {
|
|
82
78
|
/** Write files for the endpoint to disk. */
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type { NapiWrittenEndpoint } from "../binding";
|
|
2
1
|
export interface Assets {
|
|
3
2
|
js: string[];
|
|
4
3
|
css: string[];
|
|
5
4
|
}
|
|
6
5
|
export declare function getInitialAssetsFromStats(outputDir: string): Assets;
|
|
7
|
-
export declare function getInitialAssetsFromEndpointPaths(endpoints: NapiWrittenEndpoint[]): Assets;
|
|
@@ -1,15 +1,5 @@
|
|
|
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
|
-
}
|
|
13
3
|
export function getInitialAssetsFromStats(outputDir) {
|
|
14
4
|
const assets = { js: [], css: [] };
|
|
15
5
|
const statsPath = path.join(outputDir, "stats.json");
|
|
@@ -20,11 +10,12 @@ export function getInitialAssetsFromStats(outputDir) {
|
|
|
20
10
|
Object.values(stats.entrypoints).forEach((entrypoint) => {
|
|
21
11
|
var _a;
|
|
22
12
|
(_a = entrypoint.assets) === null || _a === void 0 ? void 0 : _a.forEach((asset) => {
|
|
23
|
-
if (asset.name.endsWith(".js")) {
|
|
24
|
-
|
|
13
|
+
if (asset.name.endsWith(".js") && !assets.js.includes(asset.name)) {
|
|
14
|
+
assets.js.push(asset.name);
|
|
25
15
|
}
|
|
26
|
-
if (asset.name.endsWith(".css")
|
|
27
|
-
|
|
16
|
+
if (asset.name.endsWith(".css") &&
|
|
17
|
+
!assets.css.includes(asset.name)) {
|
|
18
|
+
assets.css.push(asset.name);
|
|
28
19
|
}
|
|
29
20
|
});
|
|
30
21
|
});
|
|
@@ -36,17 +27,3 @@ export function getInitialAssetsFromStats(outputDir) {
|
|
|
36
27
|
}
|
|
37
28
|
return assets;
|
|
38
29
|
}
|
|
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.4",
|
|
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.4",
|
|
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.4",
|
|
100
|
+
"@utoo/pack-darwin-x64": "1.4.12-alpha.4",
|
|
101
|
+
"@utoo/pack-linux-arm64-gnu": "1.4.12-alpha.4",
|
|
102
|
+
"@utoo/pack-linux-arm64-musl": "1.4.12-alpha.4",
|
|
103
|
+
"@utoo/pack-linux-x64-gnu": "1.4.12-alpha.4",
|
|
104
|
+
"@utoo/pack-linux-x64-musl": "1.4.12-alpha.4",
|
|
105
|
+
"@utoo/pack-win32-x64-msvc": "1.4.12-alpha.4"
|
|
106
106
|
}
|
|
107
107
|
}
|