@utoo/pack 1.4.7-alpha.2 → 1.4.8-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/core/hmr.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type HMR_ACTION_TYPES } from "@utoo/pack-shared";
1
+ import { type EntryIssuesMap, type HMR_ACTION_TYPES } from "@utoo/pack-shared";
2
2
  import { IncomingMessage } from "http";
3
3
  import { Duplex } from "stream";
4
4
  import { BundleOptions } from "../config/types";
@@ -47,6 +47,7 @@ export type ClientState = {
47
47
  hmrPayloads: Map<string, HMR_ACTION_TYPES>;
48
48
  turbopackUpdates: TurbopackUpdate[];
49
49
  subscriptions: Map<string, AsyncIterator<any>>;
50
+ clientIssues: EntryIssuesMap;
50
51
  };
51
52
  export type SendHmr = (id: string, payload: HMR_ACTION_TYPES) => void;
52
53
  export declare const FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
package/cjs/core/hmr.js CHANGED
@@ -21,6 +21,39 @@ const sessionId = Math.floor(Number.MAX_SAFE_INTEGER * Math.random());
21
21
  var pack_shared_2 = require("@utoo/pack-shared");
22
22
  Object.defineProperty(exports, "HMR_ACTIONS_SENT_TO_BROWSER", { enumerable: true, get: function () { return pack_shared_2.HMR_ACTIONS_SENT_TO_BROWSER; } });
23
23
  exports.FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
24
+ function hasBlockingIssues(issues) {
25
+ for (const issueMap of issues.values()) {
26
+ for (const issue of issueMap.values()) {
27
+ if (issue.severity !== "warning") {
28
+ return true;
29
+ }
30
+ }
31
+ }
32
+ return false;
33
+ }
34
+ function hasBlockingResultIssues(result) {
35
+ return result.issues.some((issue) => issue.severity === "error" || issue.severity === "fatal");
36
+ }
37
+ function addIssuesToErrors(errors, issues) {
38
+ for (const issueMap of issues.values()) {
39
+ for (const [key, issue] of issueMap) {
40
+ if (issue.severity === "warning") {
41
+ continue;
42
+ }
43
+ errors.set(key, {
44
+ message: (0, pack_shared_1.formatIssue)(issue, false),
45
+ });
46
+ }
47
+ }
48
+ }
49
+ function getCompilationErrors(issues) {
50
+ const errors = new Map();
51
+ addIssuesToErrors(errors, issues);
52
+ return [...errors.values()];
53
+ }
54
+ function getClientIssueKey(id) {
55
+ return `client:${id}`;
56
+ }
24
57
  async function createHotReloader(bundleOptions, projectPath, rootPath) {
25
58
  var _a, _b, _c, _d, _e, _f, _g;
26
59
  const resolvedProjectPath = projectPath || process.cwd();
@@ -84,6 +117,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
84
117
  let hmrHash = 0;
85
118
  const clients = new Set();
86
119
  const clientStates = new WeakMap();
120
+ const currentEntryIssues = new Map();
87
121
  const backgroundWatchSubscriptions = new Set();
88
122
  let currentWatchedEntrypoints = [];
89
123
  let backgroundWatchersStarted = false;
@@ -96,11 +130,17 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
96
130
  client.send(JSON.stringify(payload));
97
131
  }
98
132
  function sendEnqueuedMessages() {
133
+ if (hasBlockingIssues(currentEntryIssues)) {
134
+ return;
135
+ }
99
136
  for (const client of clients) {
100
137
  const state = clientStates.get(client);
101
138
  if (!state) {
102
139
  continue;
103
140
  }
141
+ if (hasBlockingIssues(state.clientIssues)) {
142
+ return;
143
+ }
104
144
  for (const payload of state.hmrPayloads.values()) {
105
145
  sendToClient(client, payload);
106
146
  }
@@ -159,6 +199,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
159
199
  async function disposeBackgroundWatchSubscriptions() {
160
200
  const subscriptions = [...backgroundWatchSubscriptions];
161
201
  backgroundWatchSubscriptions.clear();
202
+ currentEntryIssues.clear();
162
203
  backgroundEndpointWriteTasks.clear();
163
204
  backgroundProjectWriteTask = undefined;
164
205
  await Promise.all(subscriptions.map((subscription) => { var _a; return (_a = subscription.return) === null || _a === void 0 ? void 0 : _a.call(subscription); }));
@@ -221,13 +262,18 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
221
262
  }
222
263
  backgroundWatchSubscriptions.add(clientChanges);
223
264
  backgroundWatchSubscriptions.add(serverChanges);
224
- const watchChanges = async (subscription) => {
265
+ const watchChanges = async (subscription, issueKey) => {
225
266
  try {
226
267
  for await (const data of subscription) {
227
268
  if (closed || generation !== backgroundWatchGeneration) {
228
269
  return;
229
270
  }
230
- (0, common_1.processIssues)(data, true, true);
271
+ (0, common_1.processIssues)(currentEntryIssues, issueKey, data, false, true);
272
+ if (hasBlockingResultIssues(data)) {
273
+ hmrEventHappened = true;
274
+ sendEnqueuedMessagesDebounce();
275
+ continue;
276
+ }
231
277
  scheduleOutputWrite(entrypoint, generation);
232
278
  }
233
279
  }
@@ -239,10 +285,12 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
239
285
  }
240
286
  finally {
241
287
  backgroundWatchSubscriptions.delete(subscription);
288
+ currentEntryIssues.delete(issueKey);
242
289
  }
243
290
  };
244
- void watchChanges(clientChanges);
245
- void watchChanges(serverChanges);
291
+ const entrypointIndex = currentWatchedEntrypoints.indexOf(entrypoint);
292
+ void watchChanges(clientChanges, `entrypoint:${entrypointIndex}:client`);
293
+ void watchChanges(serverChanges, `entrypoint:${entrypointIndex}:server`);
246
294
  }));
247
295
  }
248
296
  async function subscribeToHmrEvents(client, id) {
@@ -252,12 +300,13 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
252
300
  }
253
301
  const subscription = project.hmrEvents(id);
254
302
  state.subscriptions.set(id, subscription);
303
+ const issueKey = getClientIssueKey(id);
255
304
  // The subscription will always emit once, which is the initial
256
305
  // computation. This is not a change, so swallow it.
257
306
  try {
258
307
  await subscription.next();
259
308
  for await (const data of subscription) {
260
- (0, common_1.processIssues)(data, true, true);
309
+ (0, common_1.processIssues)(state.clientIssues, issueKey, data, false, true);
261
310
  if (data.type !== "issues") {
262
311
  sendTurbopackMessage(data);
263
312
  }
@@ -284,6 +333,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
284
333
  }
285
334
  const subscription = state.subscriptions.get(id);
286
335
  subscription === null || subscription === void 0 ? void 0 : subscription.return();
336
+ state.clientIssues.delete(getClientIssueKey(id));
287
337
  }
288
338
  async function handleEntrypointsSubscription() {
289
339
  var _a, _b;
@@ -322,6 +372,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
322
372
  hmrPayloads: new Map(),
323
373
  turbopackUpdates: [],
324
374
  subscriptions,
375
+ clientIssues: new Map(),
325
376
  });
326
377
  client.on("close", () => {
327
378
  var _a;
@@ -377,7 +428,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
377
428
  data: { sessionId },
378
429
  };
379
430
  sendToClient(client, turbopackConnected);
380
- const errors = [];
431
+ const errors = getCompilationErrors(currentEntryIssues);
381
432
  (async function () {
382
433
  const sync = {
383
434
  action: pack_shared_1.HMR_ACTIONS_SENT_TO_BROWSER.SYNC,
@@ -396,13 +447,14 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
396
447
  hmrPayloads: new Map(),
397
448
  turbopackUpdates: [],
398
449
  subscriptions,
450
+ clientIssues: new Map(),
399
451
  });
400
452
  const turbopackConnected = {
401
453
  action: pack_shared_1.HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED,
402
454
  data: { sessionId },
403
455
  };
404
456
  sendToClient(ws, turbopackConnected);
405
- const errors = [];
457
+ const errors = getCompilationErrors(currentEntryIssues);
406
458
  const sync = {
407
459
  action: pack_shared_1.HMR_ACTIONS_SENT_TO_BROWSER.SYNC,
408
460
  errors,
@@ -515,12 +567,14 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
515
567
  case "end": {
516
568
  sendEnqueuedMessages();
517
569
  const errors = new Map();
570
+ addIssuesToErrors(errors, currentEntryIssues);
518
571
  for (const client of clients) {
519
572
  const state = clientStates.get(client);
520
573
  if (!state) {
521
574
  continue;
522
575
  }
523
576
  const clientErrors = new Map(errors);
577
+ addIssuesToErrors(clientErrors, state.clientIssues);
524
578
  sendToClient(client, {
525
579
  action: pack_shared_1.HMR_ACTIONS_SENT_TO_BROWSER.BUILT,
526
580
  hash: String(++hmrHash),
package/esm/core/hmr.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type HMR_ACTION_TYPES } from "@utoo/pack-shared";
1
+ import { type EntryIssuesMap, type HMR_ACTION_TYPES } from "@utoo/pack-shared";
2
2
  import { IncomingMessage } from "http";
3
3
  import { Duplex } from "stream";
4
4
  import { BundleOptions } from "../config/types";
@@ -47,6 +47,7 @@ export type ClientState = {
47
47
  hmrPayloads: Map<string, HMR_ACTION_TYPES>;
48
48
  turbopackUpdates: TurbopackUpdate[];
49
49
  subscriptions: Map<string, AsyncIterator<any>>;
50
+ clientIssues: EntryIssuesMap;
50
51
  };
51
52
  export type SendHmr = (id: string, payload: HMR_ACTION_TYPES) => void;
52
53
  export declare const FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
package/esm/core/hmr.js CHANGED
@@ -1,4 +1,4 @@
1
- import { HMR_ACTIONS_SENT_TO_BROWSER, } from "@utoo/pack-shared";
1
+ import { formatIssue, HMR_ACTIONS_SENT_TO_BROWSER, } from "@utoo/pack-shared";
2
2
  import { nanoid } from "nanoid";
3
3
  import { WebSocketServer } from "ws";
4
4
  import { HtmlPlugin } from "../plugins/HtmlPlugin.js";
@@ -16,6 +16,39 @@ const sessionId = Math.floor(Number.MAX_SAFE_INTEGER * Math.random());
16
16
  // Re-export HMR types from pack-shared for backward compatibility
17
17
  export { HMR_ACTIONS_SENT_TO_BROWSER, } from "@utoo/pack-shared";
18
18
  export const FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
19
+ function hasBlockingIssues(issues) {
20
+ for (const issueMap of issues.values()) {
21
+ for (const issue of issueMap.values()) {
22
+ if (issue.severity !== "warning") {
23
+ return true;
24
+ }
25
+ }
26
+ }
27
+ return false;
28
+ }
29
+ function hasBlockingResultIssues(result) {
30
+ return result.issues.some((issue) => issue.severity === "error" || issue.severity === "fatal");
31
+ }
32
+ function addIssuesToErrors(errors, issues) {
33
+ for (const issueMap of issues.values()) {
34
+ for (const [key, issue] of issueMap) {
35
+ if (issue.severity === "warning") {
36
+ continue;
37
+ }
38
+ errors.set(key, {
39
+ message: formatIssue(issue, false),
40
+ });
41
+ }
42
+ }
43
+ }
44
+ function getCompilationErrors(issues) {
45
+ const errors = new Map();
46
+ addIssuesToErrors(errors, issues);
47
+ return [...errors.values()];
48
+ }
49
+ function getClientIssueKey(id) {
50
+ return `client:${id}`;
51
+ }
19
52
  export async function createHotReloader(bundleOptions, projectPath, rootPath) {
20
53
  var _a, _b, _c, _d, _e, _f, _g;
21
54
  const resolvedProjectPath = projectPath || process.cwd();
@@ -79,6 +112,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
79
112
  let hmrHash = 0;
80
113
  const clients = new Set();
81
114
  const clientStates = new WeakMap();
115
+ const currentEntryIssues = new Map();
82
116
  const backgroundWatchSubscriptions = new Set();
83
117
  let currentWatchedEntrypoints = [];
84
118
  let backgroundWatchersStarted = false;
@@ -91,11 +125,17 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
91
125
  client.send(JSON.stringify(payload));
92
126
  }
93
127
  function sendEnqueuedMessages() {
128
+ if (hasBlockingIssues(currentEntryIssues)) {
129
+ return;
130
+ }
94
131
  for (const client of clients) {
95
132
  const state = clientStates.get(client);
96
133
  if (!state) {
97
134
  continue;
98
135
  }
136
+ if (hasBlockingIssues(state.clientIssues)) {
137
+ return;
138
+ }
99
139
  for (const payload of state.hmrPayloads.values()) {
100
140
  sendToClient(client, payload);
101
141
  }
@@ -154,6 +194,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
154
194
  async function disposeBackgroundWatchSubscriptions() {
155
195
  const subscriptions = [...backgroundWatchSubscriptions];
156
196
  backgroundWatchSubscriptions.clear();
197
+ currentEntryIssues.clear();
157
198
  backgroundEndpointWriteTasks.clear();
158
199
  backgroundProjectWriteTask = undefined;
159
200
  await Promise.all(subscriptions.map((subscription) => { var _a; return (_a = subscription.return) === null || _a === void 0 ? void 0 : _a.call(subscription); }));
@@ -216,13 +257,18 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
216
257
  }
217
258
  backgroundWatchSubscriptions.add(clientChanges);
218
259
  backgroundWatchSubscriptions.add(serverChanges);
219
- const watchChanges = async (subscription) => {
260
+ const watchChanges = async (subscription, issueKey) => {
220
261
  try {
221
262
  for await (const data of subscription) {
222
263
  if (closed || generation !== backgroundWatchGeneration) {
223
264
  return;
224
265
  }
225
- processIssues(data, true, true);
266
+ processIssues(currentEntryIssues, issueKey, data, false, true);
267
+ if (hasBlockingResultIssues(data)) {
268
+ hmrEventHappened = true;
269
+ sendEnqueuedMessagesDebounce();
270
+ continue;
271
+ }
226
272
  scheduleOutputWrite(entrypoint, generation);
227
273
  }
228
274
  }
@@ -234,10 +280,12 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
234
280
  }
235
281
  finally {
236
282
  backgroundWatchSubscriptions.delete(subscription);
283
+ currentEntryIssues.delete(issueKey);
237
284
  }
238
285
  };
239
- void watchChanges(clientChanges);
240
- void watchChanges(serverChanges);
286
+ const entrypointIndex = currentWatchedEntrypoints.indexOf(entrypoint);
287
+ void watchChanges(clientChanges, `entrypoint:${entrypointIndex}:client`);
288
+ void watchChanges(serverChanges, `entrypoint:${entrypointIndex}:server`);
241
289
  }));
242
290
  }
243
291
  async function subscribeToHmrEvents(client, id) {
@@ -247,12 +295,13 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
247
295
  }
248
296
  const subscription = project.hmrEvents(id);
249
297
  state.subscriptions.set(id, subscription);
298
+ const issueKey = getClientIssueKey(id);
250
299
  // The subscription will always emit once, which is the initial
251
300
  // computation. This is not a change, so swallow it.
252
301
  try {
253
302
  await subscription.next();
254
303
  for await (const data of subscription) {
255
- processIssues(data, true, true);
304
+ processIssues(state.clientIssues, issueKey, data, false, true);
256
305
  if (data.type !== "issues") {
257
306
  sendTurbopackMessage(data);
258
307
  }
@@ -279,6 +328,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
279
328
  }
280
329
  const subscription = state.subscriptions.get(id);
281
330
  subscription === null || subscription === void 0 ? void 0 : subscription.return();
331
+ state.clientIssues.delete(getClientIssueKey(id));
282
332
  }
283
333
  async function handleEntrypointsSubscription() {
284
334
  var _a, _b;
@@ -317,6 +367,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
317
367
  hmrPayloads: new Map(),
318
368
  turbopackUpdates: [],
319
369
  subscriptions,
370
+ clientIssues: new Map(),
320
371
  });
321
372
  client.on("close", () => {
322
373
  var _a;
@@ -372,7 +423,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
372
423
  data: { sessionId },
373
424
  };
374
425
  sendToClient(client, turbopackConnected);
375
- const errors = [];
426
+ const errors = getCompilationErrors(currentEntryIssues);
376
427
  (async function () {
377
428
  const sync = {
378
429
  action: HMR_ACTIONS_SENT_TO_BROWSER.SYNC,
@@ -391,13 +442,14 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
391
442
  hmrPayloads: new Map(),
392
443
  turbopackUpdates: [],
393
444
  subscriptions,
445
+ clientIssues: new Map(),
394
446
  });
395
447
  const turbopackConnected = {
396
448
  action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED,
397
449
  data: { sessionId },
398
450
  };
399
451
  sendToClient(ws, turbopackConnected);
400
- const errors = [];
452
+ const errors = getCompilationErrors(currentEntryIssues);
401
453
  const sync = {
402
454
  action: HMR_ACTIONS_SENT_TO_BROWSER.SYNC,
403
455
  errors,
@@ -510,12 +562,14 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
510
562
  case "end": {
511
563
  sendEnqueuedMessages();
512
564
  const errors = new Map();
565
+ addIssuesToErrors(errors, currentEntryIssues);
513
566
  for (const client of clients) {
514
567
  const state = clientStates.get(client);
515
568
  if (!state) {
516
569
  continue;
517
570
  }
518
571
  const clientErrors = new Map(errors);
572
+ addIssuesToErrors(clientErrors, state.clientIssues);
519
573
  sendToClient(client, {
520
574
  action: HMR_ACTIONS_SENT_TO_BROWSER.BUILT,
521
575
  hash: String(++hmrHash),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "1.4.7-alpha.2",
3
+ "version": "1.4.8-alpha.0",
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.7-alpha.2",
44
+ "@utoo/pack-shared": "1.4.8-alpha.0",
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.7-alpha.2",
96
- "@utoo/pack-darwin-x64": "1.4.7-alpha.2",
97
- "@utoo/pack-linux-arm64-gnu": "1.4.7-alpha.2",
98
- "@utoo/pack-linux-arm64-musl": "1.4.7-alpha.2",
99
- "@utoo/pack-linux-x64-gnu": "1.4.7-alpha.2",
100
- "@utoo/pack-linux-x64-musl": "1.4.7-alpha.2",
101
- "@utoo/pack-win32-x64-msvc": "1.4.7-alpha.2"
95
+ "@utoo/pack-darwin-arm64": "1.4.8-alpha.0",
96
+ "@utoo/pack-darwin-x64": "1.4.8-alpha.0",
97
+ "@utoo/pack-linux-arm64-gnu": "1.4.8-alpha.0",
98
+ "@utoo/pack-linux-arm64-musl": "1.4.8-alpha.0",
99
+ "@utoo/pack-linux-x64-gnu": "1.4.8-alpha.0",
100
+ "@utoo/pack-linux-x64-musl": "1.4.8-alpha.0",
101
+ "@utoo/pack-win32-x64-msvc": "1.4.8-alpha.0"
102
102
  }
103
103
  }