@utoo/pack 1.4.12-alpha.0 → 1.4.12-alpha.2
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/core/hmr.js +19 -4
- 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/cjs/utils/normalizePath.js +1 -9
- package/esm/binding.d.ts +2 -0
- package/esm/commands/build.js +10 -14
- package/esm/core/hmr.js +20 -5
- 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/esm/utils/normalizePath.js +1 -9
- 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/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({
|
|
@@ -165,6 +163,18 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
165
163
|
hmrEventHappened = true;
|
|
166
164
|
sendEnqueuedMessagesDebounce();
|
|
167
165
|
}
|
|
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
|
+
}
|
|
168
178
|
async function regenerateHtml() {
|
|
169
179
|
var _a;
|
|
170
180
|
if (htmlConfigs.length === 0) {
|
|
@@ -172,7 +182,9 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
172
182
|
}
|
|
173
183
|
const outputDir = (0, cleanOutput_1.getOutputPath)(bundleOptions.config, resolvedProjectPath);
|
|
174
184
|
const publicPath = (_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.publicPath;
|
|
175
|
-
const assets = (0, getInitialAssets_1.
|
|
185
|
+
const assets = (0, getInitialAssets_1.getInitialAssetsFromEndpointPaths)([
|
|
186
|
+
...writtenEndpointPaths.values(),
|
|
187
|
+
]);
|
|
176
188
|
for (const config of htmlConfigs) {
|
|
177
189
|
const plugin = new HtmlPlugin_1.HtmlPlugin(config);
|
|
178
190
|
await plugin.generate(outputDir, assets, publicPath);
|
|
@@ -181,11 +193,14 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
181
193
|
async function writeAllEntrypointsToDisk() {
|
|
182
194
|
const result = await project.writeAllEntrypointsToDisk();
|
|
183
195
|
(0, common_1.processIssues)(result, true, true);
|
|
196
|
+
updateWrittenEndpointPaths(result.apps, result.appPaths);
|
|
197
|
+
updateWrittenEndpointPaths(result.libraries, result.libraryPaths);
|
|
184
198
|
await regenerateHtml();
|
|
185
199
|
}
|
|
186
200
|
async function writeEntrypointToDisk(entrypoint) {
|
|
187
201
|
const result = await entrypoint.writeToDisk();
|
|
188
202
|
(0, common_1.processIssues)(result, true, true);
|
|
203
|
+
writtenEndpointPaths.set(entrypoint, result);
|
|
189
204
|
await regenerateHtml();
|
|
190
205
|
}
|
|
191
206
|
async function writeOutputToDisk(entrypoint) {
|
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
|
diagnostics: binding.NapiDiagnostic[];
|
|
42
44
|
}, void, unknown>;
|
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
|
diagnostics: entrypoints.diagnostics,
|
|
495
497
|
};
|
package/cjs/core/types.d.ts
CHANGED
|
@@ -75,6 +75,8 @@ export interface Project {
|
|
|
75
75
|
export interface RawEntrypoints {
|
|
76
76
|
apps?: Endpoint[];
|
|
77
77
|
libraries?: Endpoint[];
|
|
78
|
+
appPaths?: NapiWrittenEndpoint[];
|
|
79
|
+
libraryPaths?: NapiWrittenEndpoint[];
|
|
78
80
|
}
|
|
79
81
|
export interface Endpoint {
|
|
80
82
|
/** 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
|
+
}
|
|
@@ -4,15 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.normalizePath = normalizePath;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
7
|
const path_1 = __importDefault(require("path"));
|
|
9
8
|
function normalizePath(file) {
|
|
10
|
-
|
|
11
|
-
return file;
|
|
12
|
-
let normalized = path_1.default.resolve(file);
|
|
13
|
-
try {
|
|
14
|
-
normalized = fs_1.default.realpathSync.native(normalized);
|
|
15
|
-
}
|
|
16
|
-
catch (_a) { }
|
|
17
|
-
return path_1.default.sep === "\\" ? normalized.replace(/\\/g, "/") : normalized;
|
|
9
|
+
return path_1.default.sep === "\\" ? file.replace(/\\/g, "/") : file;
|
|
18
10
|
}
|
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/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({
|
|
@@ -160,6 +158,18 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
160
158
|
hmrEventHappened = true;
|
|
161
159
|
sendEnqueuedMessagesDebounce();
|
|
162
160
|
}
|
|
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
|
+
}
|
|
163
173
|
async function regenerateHtml() {
|
|
164
174
|
var _a;
|
|
165
175
|
if (htmlConfigs.length === 0) {
|
|
@@ -167,7 +177,9 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
167
177
|
}
|
|
168
178
|
const outputDir = getOutputPath(bundleOptions.config, resolvedProjectPath);
|
|
169
179
|
const publicPath = (_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.publicPath;
|
|
170
|
-
const assets =
|
|
180
|
+
const assets = getInitialAssetsFromEndpointPaths([
|
|
181
|
+
...writtenEndpointPaths.values(),
|
|
182
|
+
]);
|
|
171
183
|
for (const config of htmlConfigs) {
|
|
172
184
|
const plugin = new HtmlPlugin(config);
|
|
173
185
|
await plugin.generate(outputDir, assets, publicPath);
|
|
@@ -176,11 +188,14 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
176
188
|
async function writeAllEntrypointsToDisk() {
|
|
177
189
|
const result = await project.writeAllEntrypointsToDisk();
|
|
178
190
|
processIssues(result, true, true);
|
|
191
|
+
updateWrittenEndpointPaths(result.apps, result.appPaths);
|
|
192
|
+
updateWrittenEndpointPaths(result.libraries, result.libraryPaths);
|
|
179
193
|
await regenerateHtml();
|
|
180
194
|
}
|
|
181
195
|
async function writeEntrypointToDisk(entrypoint) {
|
|
182
196
|
const result = await entrypoint.writeToDisk();
|
|
183
197
|
processIssues(result, true, true);
|
|
198
|
+
writtenEndpointPaths.set(entrypoint, result);
|
|
184
199
|
await regenerateHtml();
|
|
185
200
|
}
|
|
186
201
|
async function writeOutputToDisk(entrypoint) {
|
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
|
diagnostics: binding.NapiDiagnostic[];
|
|
42
44
|
}, void, unknown>;
|
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
|
diagnostics: entrypoints.diagnostics,
|
|
456
458
|
};
|
package/esm/core/types.d.ts
CHANGED
|
@@ -75,6 +75,8 @@ export interface Project {
|
|
|
75
75
|
export interface RawEntrypoints {
|
|
76
76
|
apps?: Endpoint[];
|
|
77
77
|
libraries?: Endpoint[];
|
|
78
|
+
appPaths?: NapiWrittenEndpoint[];
|
|
79
|
+
libraryPaths?: NapiWrittenEndpoint[];
|
|
78
80
|
}
|
|
79
81
|
export interface Endpoint {
|
|
80
82
|
/** 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
|
+
}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
1
|
import path from "path";
|
|
3
2
|
export function normalizePath(file) {
|
|
4
|
-
|
|
5
|
-
return file;
|
|
6
|
-
let normalized = path.resolve(file);
|
|
7
|
-
try {
|
|
8
|
-
normalized = fs.realpathSync.native(normalized);
|
|
9
|
-
}
|
|
10
|
-
catch (_a) { }
|
|
11
|
-
return path.sep === "\\" ? normalized.replace(/\\/g, "/") : normalized;
|
|
3
|
+
return path.sep === "\\" ? file.replace(/\\/g, "/") : file;
|
|
12
4
|
}
|
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.2",
|
|
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.2",
|
|
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.2",
|
|
100
|
+
"@utoo/pack-darwin-x64": "1.4.12-alpha.2",
|
|
101
|
+
"@utoo/pack-linux-arm64-gnu": "1.4.12-alpha.2",
|
|
102
|
+
"@utoo/pack-linux-arm64-musl": "1.4.12-alpha.2",
|
|
103
|
+
"@utoo/pack-linux-x64-gnu": "1.4.12-alpha.2",
|
|
104
|
+
"@utoo/pack-linux-x64-musl": "1.4.12-alpha.2",
|
|
105
|
+
"@utoo/pack-win32-x64-msvc": "1.4.12-alpha.2"
|
|
106
106
|
}
|
|
107
107
|
}
|