@utoo/pack 1.4.12-alpha.0 → 1.4.12-alpha.10

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 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" }
@@ -241,11 +243,6 @@ export interface NapiSourcePos {
241
243
  line: number
242
244
  column: number
243
245
  }
244
- export interface NapiDiagnostic {
245
- category: string
246
- name: string
247
- payload: Record<string, string>
248
- }
249
246
  /**
250
247
  * Initialize tracing subscriber to emit traces. This configures subscribers
251
248
  * for Trace Event Format <https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview>.
@@ -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: Boolean(process.env.ANALYZE) ||
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 = { js: [], css: [] };
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
- 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;
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(((_h = bundleOptions.config.output) === null || _h === void 0 ? void 0 : _h.path) || "dist");
97
+ await analyzeBundle(((_k = bundleOptions.config.output) === null || _k === void 0 ? void 0 : _k.path) || "dist");
102
98
  }
103
99
  }
104
100
  finally {
@@ -234,8 +234,19 @@ async function runDev(options, projectPath, rootPath, serverOptions) {
234
234
  : serveOptsBase.hostname;
235
235
  (0, printServerInfo_1.printServerInfo)(scheme, displayHost, serveOptsBase.port);
236
236
  }
237
- const cleanup = () => {
238
- hotReloader.close();
237
+ let cleanupStarted = false;
238
+ const cleanup = async () => {
239
+ if (cleanupStarted) {
240
+ return;
241
+ }
242
+ cleanupStarted = true;
243
+ try {
244
+ await hotReloader.close();
245
+ }
246
+ catch (err) {
247
+ console.error(err);
248
+ process.exit(1);
249
+ }
239
250
  // We always create HTTP/1.1 server (http or https), so closeAllConnections exists; Hono's
240
251
  // ServerType union includes HTTP/2, so TS does not narrow. Use runtime check to satisfy types.
241
252
  if ("closeAllConnections" in server &&
package/cjs/core/hmr.d.ts CHANGED
@@ -38,7 +38,7 @@ export interface HotReloaderInterface {
38
38
  /** Handle a message from a client (JSON string). */
39
39
  handleClientMessage(ws: WSLike, data: string): void;
40
40
  buildFallbackError(): Promise<void>;
41
- close(): void;
41
+ close(): Promise<void>;
42
42
  }
43
43
  export type ChangeSubscriptions = Map<string, Promise<AsyncIterableIterator<TurbopackResult>>>;
44
44
  export type ReadyIds = Set<string>;
package/cjs/core/hmr.js CHANGED
@@ -74,9 +74,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
74
74
  .filter((e) => !!e.html)
75
75
  .map((e) => e.html),
76
76
  ];
77
- const shouldCreateWebpackStats = Boolean(process.env.ANALYZE) ||
78
- bundleOptions.config.stats ||
79
- htmlConfigs.length > 0;
77
+ const shouldCreateWebpackStats = Boolean(process.env.ANALYZE) || Boolean(bundleOptions.config.stats);
80
78
  let project;
81
79
  try {
82
80
  project = await createProject({
@@ -157,7 +155,6 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
157
155
  const sendEnqueuedMessagesDebounce = (0, common_1.debounce)(sendEnqueuedMessages, 2);
158
156
  function sendTurbopackMessage(payload) {
159
157
  var _a;
160
- payload.diagnostics = [];
161
158
  payload.issues = [];
162
159
  for (const client of clients) {
163
160
  (_a = clientStates.get(client)) === null || _a === void 0 ? void 0 : _a.turbopackUpdates.push(payload);
@@ -165,6 +162,18 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
165
162
  hmrEventHappened = true;
166
163
  sendEnqueuedMessagesDebounce();
167
164
  }
165
+ const writtenEndpointPaths = new Map();
166
+ function updateWrittenEndpointPaths(endpoints, paths) {
167
+ if (!endpoints || !paths) {
168
+ return;
169
+ }
170
+ endpoints.forEach((endpoint, index) => {
171
+ const written = paths[index];
172
+ if (written) {
173
+ writtenEndpointPaths.set(endpoint, written);
174
+ }
175
+ });
176
+ }
168
177
  async function regenerateHtml() {
169
178
  var _a;
170
179
  if (htmlConfigs.length === 0) {
@@ -172,7 +181,9 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
172
181
  }
173
182
  const outputDir = (0, cleanOutput_1.getOutputPath)(bundleOptions.config, resolvedProjectPath);
174
183
  const publicPath = (_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.publicPath;
175
- const assets = (0, getInitialAssets_1.getInitialAssetsFromStats)(outputDir);
184
+ const assets = (0, getInitialAssets_1.getInitialAssetsFromEndpointPaths)([
185
+ ...writtenEndpointPaths.values(),
186
+ ]);
176
187
  for (const config of htmlConfigs) {
177
188
  const plugin = new HtmlPlugin_1.HtmlPlugin(config);
178
189
  await plugin.generate(outputDir, assets, publicPath);
@@ -181,11 +192,14 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
181
192
  async function writeAllEntrypointsToDisk() {
182
193
  const result = await project.writeAllEntrypointsToDisk();
183
194
  (0, common_1.processIssues)(result, true, true);
195
+ updateWrittenEndpointPaths(result.apps, result.appPaths);
196
+ updateWrittenEndpointPaths(result.libraries, result.libraryPaths);
184
197
  await regenerateHtml();
185
198
  }
186
199
  async function writeEntrypointToDisk(entrypoint) {
187
200
  const result = await entrypoint.writeToDisk();
188
201
  (0, common_1.processIssues)(result, true, true);
202
+ writtenEndpointPaths.set(entrypoint, result);
189
203
  await regenerateHtml();
190
204
  }
191
205
  async function writeOutputToDisk(entrypoint) {
@@ -534,11 +548,12 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
534
548
  async buildFallbackError() {
535
549
  // Not implemented yet.
536
550
  },
537
- close() {
551
+ async close() {
538
552
  closed = true;
539
- void disposeBackgroundWatchSubscriptions();
540
- closePromise !== null && closePromise !== void 0 ? closePromise : (closePromise = project
541
- .onExit()
553
+ const disposePromise = disposeBackgroundWatchSubscriptions();
554
+ closePromise !== null && closePromise !== void 0 ? closePromise : (closePromise = (bundleOptions.config.persistentCaching
555
+ ? project.shutdown()
556
+ : project.onExit())
542
557
  .catch((err) => {
543
558
  console.error(err);
544
559
  })
@@ -549,6 +564,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
549
564
  wsClient.close();
550
565
  }
551
566
  clients.clear();
567
+ await Promise.all([disposePromise, closePromise]);
552
568
  },
553
569
  };
554
570
  handleEntrypointsSubscription().catch((err) => {
@@ -37,8 +37,9 @@ 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
- diagnostics: binding.NapiDiagnostic[];
42
43
  }, void, unknown>;
43
44
  hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
44
45
  hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<HmrIdentifiers>>;
@@ -102,7 +102,6 @@ const DEFAULT_OPTIMIZE_PACKAGE_IMPORTS = [
102
102
  "date-fns",
103
103
  "lodash-es",
104
104
  "ramda",
105
- "antd",
106
105
  "react-bootstrap",
107
106
  "ahooks",
108
107
  "@ant-design/icons",
@@ -490,8 +489,9 @@ function projectFactory() {
490
489
  return {
491
490
  apps: (entrypoints.apps || []).map((e) => new EndpointImpl(e)),
492
491
  libraries: (entrypoints.libraries || []).map((e) => new EndpointImpl(e)),
492
+ appPaths: entrypoints.appPaths,
493
+ libraryPaths: entrypoints.libraryPaths,
493
494
  issues: entrypoints.issues,
494
- diagnostics: entrypoints.diagnostics,
495
495
  };
496
496
  }
497
497
  return async function createProject(options, turboEngineOptions) {
@@ -1,9 +1,8 @@
1
- import { HmrIdentifiers, NapiDiagnostic, NapiIssue, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "../binding";
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,6 +73,8 @@ export interface Project {
75
73
  export interface RawEntrypoints {
76
74
  apps?: Endpoint[];
77
75
  libraries?: Endpoint[];
76
+ appPaths?: NapiWrittenEndpoint[];
77
+ libraryPaths?: NapiWrittenEndpoint[];
78
78
  }
79
79
  export interface Endpoint {
80
80
  /** Write files for the endpoint to disk. */
@@ -1,5 +1,7 @@
1
+ import type { NapiWrittenEndpoint } from "../binding";
1
2
  export interface Assets {
2
3
  js: string[];
3
4
  css: string[];
4
5
  }
5
6
  export declare function getInitialAssetsFromStats(outputDir: string): Assets;
7
+ export declare function getInitialAssetsFromEndpointPaths(endpoints: NapiWrittenEndpoint[]): Assets;
@@ -4,8 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getInitialAssetsFromStats = getInitialAssetsFromStats;
7
+ exports.getInitialAssetsFromEndpointPaths = getInitialAssetsFromEndpointPaths;
7
8
  const fs_1 = __importDefault(require("fs"));
8
9
  const path_1 = __importDefault(require("path"));
10
+ function addUniqueAsset(assets, file) {
11
+ if (!assets.includes(file)) {
12
+ assets.push(file);
13
+ }
14
+ }
15
+ function isJavascriptAsset(file) {
16
+ return (file.endsWith(".js") &&
17
+ !file.endsWith(".LICENSE.txt") &&
18
+ !file.endsWith(".map"));
19
+ }
9
20
  function getInitialAssetsFromStats(outputDir) {
10
21
  const assets = { js: [], css: [] };
11
22
  const statsPath = path_1.default.join(outputDir, "stats.json");
@@ -16,12 +27,11 @@ function getInitialAssetsFromStats(outputDir) {
16
27
  Object.values(stats.entrypoints).forEach((entrypoint) => {
17
28
  var _a;
18
29
  (_a = entrypoint.assets) === null || _a === void 0 ? void 0 : _a.forEach((asset) => {
19
- if (asset.name.endsWith(".js") && !assets.js.includes(asset.name)) {
20
- assets.js.push(asset.name);
30
+ if (asset.name.endsWith(".js")) {
31
+ addUniqueAsset(assets.js, asset.name);
21
32
  }
22
- if (asset.name.endsWith(".css") &&
23
- !assets.css.includes(asset.name)) {
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
- if (!file)
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" }
@@ -241,11 +243,6 @@ export interface NapiSourcePos {
241
243
  line: number
242
244
  column: number
243
245
  }
244
- export interface NapiDiagnostic {
245
- category: string
246
- name: string
247
- payload: Record<string, string>
248
- }
249
246
  /**
250
247
  * Initialize tracing subscriber to emit traces. This configures subscribers
251
248
  * for Trace Event Format <https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview>.
@@ -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 { getInitialAssetsFromStats } from "../utils/getInitialAssets.js";
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: Boolean(process.env.ANALYZE) ||
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 = { js: [], css: [] };
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
- 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;
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(((_h = bundleOptions.config.output) === null || _h === void 0 ? void 0 : _h.path) || "dist");
91
+ await analyzeBundle(((_k = bundleOptions.config.output) === null || _k === void 0 ? void 0 : _k.path) || "dist");
96
92
  }
97
93
  }
98
94
  finally {
@@ -228,8 +228,19 @@ async function runDev(options, projectPath, rootPath, serverOptions) {
228
228
  : serveOptsBase.hostname;
229
229
  printServerInfo(scheme, displayHost, serveOptsBase.port);
230
230
  }
231
- const cleanup = () => {
232
- hotReloader.close();
231
+ let cleanupStarted = false;
232
+ const cleanup = async () => {
233
+ if (cleanupStarted) {
234
+ return;
235
+ }
236
+ cleanupStarted = true;
237
+ try {
238
+ await hotReloader.close();
239
+ }
240
+ catch (err) {
241
+ console.error(err);
242
+ process.exit(1);
243
+ }
233
244
  // We always create HTTP/1.1 server (http or https), so closeAllConnections exists; Hono's
234
245
  // ServerType union includes HTTP/2, so TS does not narrow. Use runtime check to satisfy types.
235
246
  if ("closeAllConnections" in server &&
package/esm/core/hmr.d.ts CHANGED
@@ -38,7 +38,7 @@ export interface HotReloaderInterface {
38
38
  /** Handle a message from a client (JSON string). */
39
39
  handleClientMessage(ws: WSLike, data: string): void;
40
40
  buildFallbackError(): Promise<void>;
41
- close(): void;
41
+ close(): Promise<void>;
42
42
  }
43
43
  export type ChangeSubscriptions = Map<string, Promise<AsyncIterableIterator<TurbopackResult>>>;
44
44
  export type ReadyIds = Set<string>;
package/esm/core/hmr.js CHANGED
@@ -4,7 +4,7 @@ import { WebSocketServer } from "ws";
4
4
  import { HtmlPlugin } from "../plugins/HtmlPlugin.js";
5
5
  import { cleanOutput, getOutputPath } from "../utils/cleanOutput.js";
6
6
  import { debounce, getPackPath, processIssues } from "../utils/common.js";
7
- import { getInitialAssetsFromStats } from "../utils/getInitialAssets.js";
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({
@@ -152,7 +150,6 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
152
150
  const sendEnqueuedMessagesDebounce = debounce(sendEnqueuedMessages, 2);
153
151
  function sendTurbopackMessage(payload) {
154
152
  var _a;
155
- payload.diagnostics = [];
156
153
  payload.issues = [];
157
154
  for (const client of clients) {
158
155
  (_a = clientStates.get(client)) === null || _a === void 0 ? void 0 : _a.turbopackUpdates.push(payload);
@@ -160,6 +157,18 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
160
157
  hmrEventHappened = true;
161
158
  sendEnqueuedMessagesDebounce();
162
159
  }
160
+ const writtenEndpointPaths = new Map();
161
+ function updateWrittenEndpointPaths(endpoints, paths) {
162
+ if (!endpoints || !paths) {
163
+ return;
164
+ }
165
+ endpoints.forEach((endpoint, index) => {
166
+ const written = paths[index];
167
+ if (written) {
168
+ writtenEndpointPaths.set(endpoint, written);
169
+ }
170
+ });
171
+ }
163
172
  async function regenerateHtml() {
164
173
  var _a;
165
174
  if (htmlConfigs.length === 0) {
@@ -167,7 +176,9 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
167
176
  }
168
177
  const outputDir = getOutputPath(bundleOptions.config, resolvedProjectPath);
169
178
  const publicPath = (_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.publicPath;
170
- const assets = getInitialAssetsFromStats(outputDir);
179
+ const assets = getInitialAssetsFromEndpointPaths([
180
+ ...writtenEndpointPaths.values(),
181
+ ]);
171
182
  for (const config of htmlConfigs) {
172
183
  const plugin = new HtmlPlugin(config);
173
184
  await plugin.generate(outputDir, assets, publicPath);
@@ -176,11 +187,14 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
176
187
  async function writeAllEntrypointsToDisk() {
177
188
  const result = await project.writeAllEntrypointsToDisk();
178
189
  processIssues(result, true, true);
190
+ updateWrittenEndpointPaths(result.apps, result.appPaths);
191
+ updateWrittenEndpointPaths(result.libraries, result.libraryPaths);
179
192
  await regenerateHtml();
180
193
  }
181
194
  async function writeEntrypointToDisk(entrypoint) {
182
195
  const result = await entrypoint.writeToDisk();
183
196
  processIssues(result, true, true);
197
+ writtenEndpointPaths.set(entrypoint, result);
184
198
  await regenerateHtml();
185
199
  }
186
200
  async function writeOutputToDisk(entrypoint) {
@@ -529,11 +543,12 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
529
543
  async buildFallbackError() {
530
544
  // Not implemented yet.
531
545
  },
532
- close() {
546
+ async close() {
533
547
  closed = true;
534
- void disposeBackgroundWatchSubscriptions();
535
- closePromise !== null && closePromise !== void 0 ? closePromise : (closePromise = project
536
- .onExit()
548
+ const disposePromise = disposeBackgroundWatchSubscriptions();
549
+ closePromise !== null && closePromise !== void 0 ? closePromise : (closePromise = (bundleOptions.config.persistentCaching
550
+ ? project.shutdown()
551
+ : project.onExit())
537
552
  .catch((err) => {
538
553
  console.error(err);
539
554
  })
@@ -544,6 +559,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
544
559
  wsClient.close();
545
560
  }
546
561
  clients.clear();
562
+ await Promise.all([disposePromise, closePromise]);
547
563
  },
548
564
  };
549
565
  handleEntrypointsSubscription().catch((err) => {
@@ -37,8 +37,9 @@ 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
- diagnostics: binding.NapiDiagnostic[];
42
43
  }, void, unknown>;
43
44
  hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
44
45
  hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<HmrIdentifiers>>;
@@ -63,7 +63,6 @@ const DEFAULT_OPTIMIZE_PACKAGE_IMPORTS = [
63
63
  "date-fns",
64
64
  "lodash-es",
65
65
  "ramda",
66
- "antd",
67
66
  "react-bootstrap",
68
67
  "ahooks",
69
68
  "@ant-design/icons",
@@ -451,8 +450,9 @@ export function projectFactory() {
451
450
  return {
452
451
  apps: (entrypoints.apps || []).map((e) => new EndpointImpl(e)),
453
452
  libraries: (entrypoints.libraries || []).map((e) => new EndpointImpl(e)),
453
+ appPaths: entrypoints.appPaths,
454
+ libraryPaths: entrypoints.libraryPaths,
454
455
  issues: entrypoints.issues,
455
- diagnostics: entrypoints.diagnostics,
456
456
  };
457
457
  }
458
458
  return async function createProject(options, turboEngineOptions) {
@@ -1,9 +1,8 @@
1
- import { HmrIdentifiers, NapiDiagnostic, NapiIssue, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "../binding";
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,6 +73,8 @@ export interface Project {
75
73
  export interface RawEntrypoints {
76
74
  apps?: Endpoint[];
77
75
  libraries?: Endpoint[];
76
+ appPaths?: NapiWrittenEndpoint[];
77
+ libraryPaths?: NapiWrittenEndpoint[];
78
78
  }
79
79
  export interface Endpoint {
80
80
  /** Write files for the endpoint to disk. */
@@ -1,5 +1,7 @@
1
+ import type { NapiWrittenEndpoint } from "../binding";
1
2
  export interface Assets {
2
3
  js: string[];
3
4
  css: string[];
4
5
  }
5
6
  export declare function getInitialAssetsFromStats(outputDir: string): Assets;
7
+ export declare function getInitialAssetsFromEndpointPaths(endpoints: NapiWrittenEndpoint[]): Assets;
@@ -1,5 +1,15 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
+ function addUniqueAsset(assets, file) {
4
+ if (!assets.includes(file)) {
5
+ assets.push(file);
6
+ }
7
+ }
8
+ function isJavascriptAsset(file) {
9
+ return (file.endsWith(".js") &&
10
+ !file.endsWith(".LICENSE.txt") &&
11
+ !file.endsWith(".map"));
12
+ }
3
13
  export function getInitialAssetsFromStats(outputDir) {
4
14
  const assets = { js: [], css: [] };
5
15
  const statsPath = path.join(outputDir, "stats.json");
@@ -10,12 +20,11 @@ export function getInitialAssetsFromStats(outputDir) {
10
20
  Object.values(stats.entrypoints).forEach((entrypoint) => {
11
21
  var _a;
12
22
  (_a = entrypoint.assets) === null || _a === void 0 ? void 0 : _a.forEach((asset) => {
13
- if (asset.name.endsWith(".js") && !assets.js.includes(asset.name)) {
14
- assets.js.push(asset.name);
23
+ if (asset.name.endsWith(".js")) {
24
+ addUniqueAsset(assets.js, asset.name);
15
25
  }
16
- if (asset.name.endsWith(".css") &&
17
- !assets.css.includes(asset.name)) {
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
- if (!file)
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.0",
3
+ "version": "1.4.12-alpha.10",
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.0",
44
+ "@utoo/pack-shared": "1.4.12-alpha.10",
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.0",
100
- "@utoo/pack-darwin-x64": "1.4.12-alpha.0",
101
- "@utoo/pack-linux-arm64-gnu": "1.4.12-alpha.0",
102
- "@utoo/pack-linux-arm64-musl": "1.4.12-alpha.0",
103
- "@utoo/pack-linux-x64-gnu": "1.4.12-alpha.0",
104
- "@utoo/pack-linux-x64-musl": "1.4.12-alpha.0",
105
- "@utoo/pack-win32-x64-msvc": "1.4.12-alpha.0"
99
+ "@utoo/pack-darwin-arm64": "1.4.12-alpha.10",
100
+ "@utoo/pack-darwin-x64": "1.4.12-alpha.10",
101
+ "@utoo/pack-linux-arm64-gnu": "1.4.12-alpha.10",
102
+ "@utoo/pack-linux-arm64-musl": "1.4.12-alpha.10",
103
+ "@utoo/pack-linux-x64-gnu": "1.4.12-alpha.10",
104
+ "@utoo/pack-linux-x64-musl": "1.4.12-alpha.10",
105
+ "@utoo/pack-win32-x64-msvc": "1.4.12-alpha.10"
106
106
  }
107
107
  }