@utoo/pack 1.4.5-alpha.4 → 1.4.6-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/core/hmr.js +55 -25
- package/cjs/core/types.d.ts +1 -0
- package/esm/core/hmr.js +55 -25
- package/esm/core/types.d.ts +1 -0
- package/package.json +9 -9
package/cjs/core/hmr.js
CHANGED
|
@@ -31,6 +31,19 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
31
31
|
const createProject = (0, project_1.projectFactory)();
|
|
32
32
|
const persistentCaching = (_a = bundleOptions.config.persistentCaching) !== null && _a !== void 0 ? _a : false;
|
|
33
33
|
const persistentCacheLock = await (0, lockfile_1.acquirePersistentCacheLock)(resolvedProjectPath, "utoo pack dev", persistentCaching);
|
|
34
|
+
const htmlConfigs = [
|
|
35
|
+
...(Array.isArray(bundleOptions.config.html)
|
|
36
|
+
? bundleOptions.config.html
|
|
37
|
+
: bundleOptions.config.html
|
|
38
|
+
? [bundleOptions.config.html]
|
|
39
|
+
: []),
|
|
40
|
+
...bundleOptions.config.entry
|
|
41
|
+
.filter((e) => !!e.html)
|
|
42
|
+
.map((e) => e.html),
|
|
43
|
+
];
|
|
44
|
+
const shouldCreateWebpackStats = Boolean(process.env.ANALYZE) ||
|
|
45
|
+
bundleOptions.config.stats ||
|
|
46
|
+
htmlConfigs.length > 0;
|
|
34
47
|
let project;
|
|
35
48
|
try {
|
|
36
49
|
project = await createProject({
|
|
@@ -44,9 +57,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
44
57
|
config: {
|
|
45
58
|
...bundleOptions.config,
|
|
46
59
|
mode: "development",
|
|
47
|
-
stats:
|
|
48
|
-
bundleOptions.config.stats ||
|
|
49
|
-
bundleOptions.config.entry.some((e) => !!e.html),
|
|
60
|
+
stats: shouldCreateWebpackStats,
|
|
50
61
|
optimization: {
|
|
51
62
|
...bundleOptions.config.optimization,
|
|
52
63
|
minify: false,
|
|
@@ -74,20 +85,11 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
74
85
|
const clients = new Set();
|
|
75
86
|
const clientStates = new WeakMap();
|
|
76
87
|
const backgroundWatchSubscriptions = new Set();
|
|
77
|
-
const htmlConfigs = [
|
|
78
|
-
...(Array.isArray(bundleOptions.config.html)
|
|
79
|
-
? bundleOptions.config.html
|
|
80
|
-
: bundleOptions.config.html
|
|
81
|
-
? [bundleOptions.config.html]
|
|
82
|
-
: []),
|
|
83
|
-
...bundleOptions.config.entry
|
|
84
|
-
.filter((e) => !!e.html)
|
|
85
|
-
.map((e) => e.html),
|
|
86
|
-
];
|
|
87
88
|
let currentWatchedEntrypoints = [];
|
|
88
89
|
let backgroundWatchersStarted = false;
|
|
89
90
|
let backgroundWatchGeneration = 0;
|
|
90
|
-
const
|
|
91
|
+
const backgroundEndpointWriteTasks = new Map();
|
|
92
|
+
let backgroundProjectWriteTask;
|
|
91
93
|
let closed = false;
|
|
92
94
|
let closePromise;
|
|
93
95
|
function sendToClient(client, payload) {
|
|
@@ -136,28 +138,41 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
136
138
|
await plugin.generate(outputDir, assets, publicPath);
|
|
137
139
|
}
|
|
138
140
|
}
|
|
141
|
+
async function writeAllEntrypointsToDisk() {
|
|
142
|
+
const result = await project.writeAllEntrypointsToDisk();
|
|
143
|
+
(0, common_1.processIssues)(result, true, true);
|
|
144
|
+
await regenerateHtml();
|
|
145
|
+
}
|
|
139
146
|
async function writeEntrypointToDisk(entrypoint) {
|
|
140
147
|
const result = await entrypoint.writeToDisk();
|
|
141
148
|
(0, common_1.processIssues)(result, true, true);
|
|
142
149
|
await regenerateHtml();
|
|
143
150
|
}
|
|
144
|
-
async function
|
|
145
|
-
|
|
151
|
+
async function writeOutputToDisk(entrypoint) {
|
|
152
|
+
if (shouldCreateWebpackStats) {
|
|
153
|
+
await writeAllEntrypointsToDisk();
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
await writeEntrypointToDisk(entrypoint);
|
|
157
|
+
}
|
|
146
158
|
}
|
|
147
159
|
async function disposeBackgroundWatchSubscriptions() {
|
|
148
160
|
const subscriptions = [...backgroundWatchSubscriptions];
|
|
149
161
|
backgroundWatchSubscriptions.clear();
|
|
150
|
-
|
|
162
|
+
backgroundEndpointWriteTasks.clear();
|
|
163
|
+
backgroundProjectWriteTask = undefined;
|
|
151
164
|
await Promise.all(subscriptions.map((subscription) => { var _a; return (_a = subscription.return) === null || _a === void 0 ? void 0 : _a.call(subscription); }));
|
|
152
165
|
}
|
|
153
|
-
function
|
|
166
|
+
function scheduleOutputWrite(entrypoint, generation) {
|
|
154
167
|
var _a;
|
|
155
168
|
if (!backgroundWatchersStarted ||
|
|
156
169
|
closed ||
|
|
157
170
|
generation !== backgroundWatchGeneration) {
|
|
158
171
|
return;
|
|
159
172
|
}
|
|
160
|
-
const previousTask =
|
|
173
|
+
const previousTask = shouldCreateWebpackStats
|
|
174
|
+
? (backgroundProjectWriteTask !== null && backgroundProjectWriteTask !== void 0 ? backgroundProjectWriteTask : Promise.resolve())
|
|
175
|
+
: ((_a = backgroundEndpointWriteTasks.get(entrypoint)) !== null && _a !== void 0 ? _a : Promise.resolve());
|
|
161
176
|
const task = previousTask
|
|
162
177
|
.catch(() => { })
|
|
163
178
|
.then(async () => {
|
|
@@ -165,15 +180,25 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
165
180
|
if (closed || generation !== backgroundWatchGeneration) {
|
|
166
181
|
return;
|
|
167
182
|
}
|
|
168
|
-
await
|
|
183
|
+
await writeOutputToDisk(entrypoint);
|
|
169
184
|
hmrEventHappened = true;
|
|
170
185
|
})
|
|
171
186
|
.finally(() => {
|
|
172
|
-
if (
|
|
173
|
-
|
|
187
|
+
if (shouldCreateWebpackStats) {
|
|
188
|
+
if (backgroundProjectWriteTask === task) {
|
|
189
|
+
backgroundProjectWriteTask = undefined;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else if (backgroundEndpointWriteTasks.get(entrypoint) === task) {
|
|
193
|
+
backgroundEndpointWriteTasks.delete(entrypoint);
|
|
174
194
|
}
|
|
175
195
|
});
|
|
176
|
-
|
|
196
|
+
if (shouldCreateWebpackStats) {
|
|
197
|
+
backgroundProjectWriteTask = task;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
backgroundEndpointWriteTasks.set(entrypoint, task);
|
|
201
|
+
}
|
|
177
202
|
}
|
|
178
203
|
async function refreshBackgroundWatchers() {
|
|
179
204
|
const generation = ++backgroundWatchGeneration;
|
|
@@ -203,7 +228,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
203
228
|
return;
|
|
204
229
|
}
|
|
205
230
|
(0, common_1.processIssues)(data, true, true);
|
|
206
|
-
|
|
231
|
+
scheduleOutputWrite(entrypoint, generation);
|
|
207
232
|
}
|
|
208
233
|
}
|
|
209
234
|
catch (error) {
|
|
@@ -272,7 +297,12 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
272
297
|
...((_a = entrypoints.apps) !== null && _a !== void 0 ? _a : []),
|
|
273
298
|
...((_b = entrypoints.libraries) !== null && _b !== void 0 ? _b : []),
|
|
274
299
|
];
|
|
275
|
-
|
|
300
|
+
if (shouldCreateWebpackStats) {
|
|
301
|
+
await writeAllEntrypointsToDisk();
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
await Promise.all(currentWatchedEntrypoints.map((entrypoint) => writeEntrypointToDisk(entrypoint)));
|
|
305
|
+
}
|
|
276
306
|
if (backgroundWatchersStarted) {
|
|
277
307
|
await refreshBackgroundWatchers();
|
|
278
308
|
}
|
package/cjs/core/types.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export interface ProjectOptions extends BundleOptions {
|
|
|
60
60
|
}
|
|
61
61
|
export interface Project {
|
|
62
62
|
update(options: Partial<ProjectOptions>): Promise<void>;
|
|
63
|
+
writeAllEntrypointsToDisk(): Promise<TurbopackResult<RawEntrypoints>>;
|
|
63
64
|
entrypointsSubscribe(): AsyncIterableIterator<TurbopackResult<RawEntrypoints>>;
|
|
64
65
|
hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
|
|
65
66
|
hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<HmrIdentifiers>>;
|
package/esm/core/hmr.js
CHANGED
|
@@ -26,6 +26,19 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
26
26
|
const createProject = projectFactory();
|
|
27
27
|
const persistentCaching = (_a = bundleOptions.config.persistentCaching) !== null && _a !== void 0 ? _a : false;
|
|
28
28
|
const persistentCacheLock = await acquirePersistentCacheLock(resolvedProjectPath, "utoo pack dev", persistentCaching);
|
|
29
|
+
const htmlConfigs = [
|
|
30
|
+
...(Array.isArray(bundleOptions.config.html)
|
|
31
|
+
? bundleOptions.config.html
|
|
32
|
+
: bundleOptions.config.html
|
|
33
|
+
? [bundleOptions.config.html]
|
|
34
|
+
: []),
|
|
35
|
+
...bundleOptions.config.entry
|
|
36
|
+
.filter((e) => !!e.html)
|
|
37
|
+
.map((e) => e.html),
|
|
38
|
+
];
|
|
39
|
+
const shouldCreateWebpackStats = Boolean(process.env.ANALYZE) ||
|
|
40
|
+
bundleOptions.config.stats ||
|
|
41
|
+
htmlConfigs.length > 0;
|
|
29
42
|
let project;
|
|
30
43
|
try {
|
|
31
44
|
project = await createProject({
|
|
@@ -39,9 +52,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
39
52
|
config: {
|
|
40
53
|
...bundleOptions.config,
|
|
41
54
|
mode: "development",
|
|
42
|
-
stats:
|
|
43
|
-
bundleOptions.config.stats ||
|
|
44
|
-
bundleOptions.config.entry.some((e) => !!e.html),
|
|
55
|
+
stats: shouldCreateWebpackStats,
|
|
45
56
|
optimization: {
|
|
46
57
|
...bundleOptions.config.optimization,
|
|
47
58
|
minify: false,
|
|
@@ -69,20 +80,11 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
69
80
|
const clients = new Set();
|
|
70
81
|
const clientStates = new WeakMap();
|
|
71
82
|
const backgroundWatchSubscriptions = new Set();
|
|
72
|
-
const htmlConfigs = [
|
|
73
|
-
...(Array.isArray(bundleOptions.config.html)
|
|
74
|
-
? bundleOptions.config.html
|
|
75
|
-
: bundleOptions.config.html
|
|
76
|
-
? [bundleOptions.config.html]
|
|
77
|
-
: []),
|
|
78
|
-
...bundleOptions.config.entry
|
|
79
|
-
.filter((e) => !!e.html)
|
|
80
|
-
.map((e) => e.html),
|
|
81
|
-
];
|
|
82
83
|
let currentWatchedEntrypoints = [];
|
|
83
84
|
let backgroundWatchersStarted = false;
|
|
84
85
|
let backgroundWatchGeneration = 0;
|
|
85
|
-
const
|
|
86
|
+
const backgroundEndpointWriteTasks = new Map();
|
|
87
|
+
let backgroundProjectWriteTask;
|
|
86
88
|
let closed = false;
|
|
87
89
|
let closePromise;
|
|
88
90
|
function sendToClient(client, payload) {
|
|
@@ -131,28 +133,41 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
131
133
|
await plugin.generate(outputDir, assets, publicPath);
|
|
132
134
|
}
|
|
133
135
|
}
|
|
136
|
+
async function writeAllEntrypointsToDisk() {
|
|
137
|
+
const result = await project.writeAllEntrypointsToDisk();
|
|
138
|
+
processIssues(result, true, true);
|
|
139
|
+
await regenerateHtml();
|
|
140
|
+
}
|
|
134
141
|
async function writeEntrypointToDisk(entrypoint) {
|
|
135
142
|
const result = await entrypoint.writeToDisk();
|
|
136
143
|
processIssues(result, true, true);
|
|
137
144
|
await regenerateHtml();
|
|
138
145
|
}
|
|
139
|
-
async function
|
|
140
|
-
|
|
146
|
+
async function writeOutputToDisk(entrypoint) {
|
|
147
|
+
if (shouldCreateWebpackStats) {
|
|
148
|
+
await writeAllEntrypointsToDisk();
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
await writeEntrypointToDisk(entrypoint);
|
|
152
|
+
}
|
|
141
153
|
}
|
|
142
154
|
async function disposeBackgroundWatchSubscriptions() {
|
|
143
155
|
const subscriptions = [...backgroundWatchSubscriptions];
|
|
144
156
|
backgroundWatchSubscriptions.clear();
|
|
145
|
-
|
|
157
|
+
backgroundEndpointWriteTasks.clear();
|
|
158
|
+
backgroundProjectWriteTask = undefined;
|
|
146
159
|
await Promise.all(subscriptions.map((subscription) => { var _a; return (_a = subscription.return) === null || _a === void 0 ? void 0 : _a.call(subscription); }));
|
|
147
160
|
}
|
|
148
|
-
function
|
|
161
|
+
function scheduleOutputWrite(entrypoint, generation) {
|
|
149
162
|
var _a;
|
|
150
163
|
if (!backgroundWatchersStarted ||
|
|
151
164
|
closed ||
|
|
152
165
|
generation !== backgroundWatchGeneration) {
|
|
153
166
|
return;
|
|
154
167
|
}
|
|
155
|
-
const previousTask =
|
|
168
|
+
const previousTask = shouldCreateWebpackStats
|
|
169
|
+
? (backgroundProjectWriteTask !== null && backgroundProjectWriteTask !== void 0 ? backgroundProjectWriteTask : Promise.resolve())
|
|
170
|
+
: ((_a = backgroundEndpointWriteTasks.get(entrypoint)) !== null && _a !== void 0 ? _a : Promise.resolve());
|
|
156
171
|
const task = previousTask
|
|
157
172
|
.catch(() => { })
|
|
158
173
|
.then(async () => {
|
|
@@ -160,15 +175,25 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
160
175
|
if (closed || generation !== backgroundWatchGeneration) {
|
|
161
176
|
return;
|
|
162
177
|
}
|
|
163
|
-
await
|
|
178
|
+
await writeOutputToDisk(entrypoint);
|
|
164
179
|
hmrEventHappened = true;
|
|
165
180
|
})
|
|
166
181
|
.finally(() => {
|
|
167
|
-
if (
|
|
168
|
-
|
|
182
|
+
if (shouldCreateWebpackStats) {
|
|
183
|
+
if (backgroundProjectWriteTask === task) {
|
|
184
|
+
backgroundProjectWriteTask = undefined;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else if (backgroundEndpointWriteTasks.get(entrypoint) === task) {
|
|
188
|
+
backgroundEndpointWriteTasks.delete(entrypoint);
|
|
169
189
|
}
|
|
170
190
|
});
|
|
171
|
-
|
|
191
|
+
if (shouldCreateWebpackStats) {
|
|
192
|
+
backgroundProjectWriteTask = task;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
backgroundEndpointWriteTasks.set(entrypoint, task);
|
|
196
|
+
}
|
|
172
197
|
}
|
|
173
198
|
async function refreshBackgroundWatchers() {
|
|
174
199
|
const generation = ++backgroundWatchGeneration;
|
|
@@ -198,7 +223,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
198
223
|
return;
|
|
199
224
|
}
|
|
200
225
|
processIssues(data, true, true);
|
|
201
|
-
|
|
226
|
+
scheduleOutputWrite(entrypoint, generation);
|
|
202
227
|
}
|
|
203
228
|
}
|
|
204
229
|
catch (error) {
|
|
@@ -267,7 +292,12 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
267
292
|
...((_a = entrypoints.apps) !== null && _a !== void 0 ? _a : []),
|
|
268
293
|
...((_b = entrypoints.libraries) !== null && _b !== void 0 ? _b : []),
|
|
269
294
|
];
|
|
270
|
-
|
|
295
|
+
if (shouldCreateWebpackStats) {
|
|
296
|
+
await writeAllEntrypointsToDisk();
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
await Promise.all(currentWatchedEntrypoints.map((entrypoint) => writeEntrypointToDisk(entrypoint)));
|
|
300
|
+
}
|
|
271
301
|
if (backgroundWatchersStarted) {
|
|
272
302
|
await refreshBackgroundWatchers();
|
|
273
303
|
}
|
package/esm/core/types.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export interface ProjectOptions extends BundleOptions {
|
|
|
60
60
|
}
|
|
61
61
|
export interface Project {
|
|
62
62
|
update(options: Partial<ProjectOptions>): Promise<void>;
|
|
63
|
+
writeAllEntrypointsToDisk(): Promise<TurbopackResult<RawEntrypoints>>;
|
|
63
64
|
entrypointsSubscribe(): AsyncIterableIterator<TurbopackResult<RawEntrypoints>>;
|
|
64
65
|
hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
|
|
65
66
|
hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<HmrIdentifiers>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/pack",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.6-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.
|
|
44
|
+
"@utoo/pack-shared": "1.4.6-alpha.2",
|
|
45
45
|
"domparser-rs": "^0.0.7",
|
|
46
46
|
"find-up": "4.1.0",
|
|
47
47
|
"get-port": "5.1.1",
|
|
@@ -92,12 +92,12 @@
|
|
|
92
92
|
},
|
|
93
93
|
"repository": "git@github.com:utooland/utoo.git",
|
|
94
94
|
"optionalDependencies": {
|
|
95
|
-
"@utoo/pack-darwin-arm64": "1.4.
|
|
96
|
-
"@utoo/pack-darwin-x64": "1.4.
|
|
97
|
-
"@utoo/pack-linux-arm64-gnu": "1.4.
|
|
98
|
-
"@utoo/pack-linux-arm64-musl": "1.4.
|
|
99
|
-
"@utoo/pack-linux-x64-gnu": "1.4.
|
|
100
|
-
"@utoo/pack-linux-x64-musl": "1.4.
|
|
101
|
-
"@utoo/pack-win32-x64-msvc": "1.4.
|
|
95
|
+
"@utoo/pack-darwin-arm64": "1.4.6-alpha.2",
|
|
96
|
+
"@utoo/pack-darwin-x64": "1.4.6-alpha.2",
|
|
97
|
+
"@utoo/pack-linux-arm64-gnu": "1.4.6-alpha.2",
|
|
98
|
+
"@utoo/pack-linux-arm64-musl": "1.4.6-alpha.2",
|
|
99
|
+
"@utoo/pack-linux-x64-gnu": "1.4.6-alpha.2",
|
|
100
|
+
"@utoo/pack-linux-x64-musl": "1.4.6-alpha.2",
|
|
101
|
+
"@utoo/pack-win32-x64-msvc": "1.4.6-alpha.2"
|
|
102
102
|
}
|
|
103
103
|
}
|