@utoo/pack 1.4.4-alpha.1 → 1.4.5-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/binding.d.ts CHANGED
@@ -9,11 +9,6 @@ export declare class ExternalObject<T> {
9
9
  [K: symbol]: T
10
10
  }
11
11
  }
12
- export type Lockfile = { __napiType: "Lockfile" }
13
- export declare function lockfileTryAcquireSync(path: string, content?: string | undefined | null): Lockfile | null
14
- export declare function lockfileTryAcquire(path: string, content?: string | undefined | null): Promise<Lockfile | null>
15
- export declare function lockfileUnlockSync(lockfile: Lockfile): void
16
- export declare function lockfileUnlock(lockfile: Lockfile): Promise<void>
17
12
  export declare function registerWorkerScheduler(creator: (arg: NapiWorkerCreation) => any, terminator: (arg: NapiWorkerTermination) => any): void
18
13
  export declare function workerCreated(workerId: number): void
19
14
  export interface NapiWorkerCreation {
package/cjs/binding.js CHANGED
@@ -319,11 +319,7 @@ if (!nativeBinding) {
319
319
  }
320
320
  throw new Error(`Failed to load native binding`);
321
321
  }
322
- const { lockfileTryAcquireSync, lockfileTryAcquire, lockfileUnlockSync, lockfileUnlock, registerWorkerScheduler, workerCreated, recvTaskMessageInWorker, sendTaskMessage, endpointWriteToDisk, endpointServerChangedSubscribe, endpointClientChangedSubscribe, projectNew, projectUpdate, projectOnExit, projectShutdown, projectWriteAllEntrypointsToDisk, projectEntrypointsSubscribe, projectHmrEvents, projectHmrIdentifiersSubscribe, projectUpdateInfoSubscribe, projectTraceSource, projectGetSourceForAsset, projectGetSourceMap, projectGetSourceMapSync, rootTaskDispose, initCustomTraceSubscriber, teardownTraceSubscriber } = nativeBinding;
323
- module.exports.lockfileTryAcquireSync = lockfileTryAcquireSync;
324
- module.exports.lockfileTryAcquire = lockfileTryAcquire;
325
- module.exports.lockfileUnlockSync = lockfileUnlockSync;
326
- module.exports.lockfileUnlock = lockfileUnlock;
322
+ const { registerWorkerScheduler, workerCreated, recvTaskMessageInWorker, sendTaskMessage, endpointWriteToDisk, endpointServerChangedSubscribe, endpointClientChangedSubscribe, projectNew, projectUpdate, projectOnExit, projectShutdown, projectWriteAllEntrypointsToDisk, projectEntrypointsSubscribe, projectHmrEvents, projectHmrIdentifiersSubscribe, projectUpdateInfoSubscribe, projectTraceSource, projectGetSourceForAsset, projectGetSourceMap, projectGetSourceMapSync, rootTaskDispose, initCustomTraceSubscriber, teardownTraceSubscriber } = nativeBinding;
327
323
  module.exports.registerWorkerScheduler = registerWorkerScheduler;
328
324
  module.exports.workerCreated = workerCreated;
329
325
  module.exports.recvTaskMessageInWorker = recvTaskMessageInWorker;
@@ -17,7 +17,6 @@ const common_1 = require("../utils/common");
17
17
  const findRoot_1 = require("../utils/findRoot");
18
18
  const getInitialAssets_1 = require("../utils/getInitialAssets");
19
19
  const htmlEntry_1 = require("../utils/htmlEntry");
20
- const lockfile_1 = require("../utils/lockfile");
21
20
  const normalizePath_1 = require("../utils/normalizePath");
22
21
  const runtimePluginStratety_1 = require("../utils/runtimePluginStratety");
23
22
  const validateEntry_1 = require("../utils/validateEntry");
@@ -31,7 +30,7 @@ function build(options, projectPath, rootPath) {
31
30
  return buildInternal(bundleOptions, projectPath, rootPath);
32
31
  }
33
32
  async function buildInternal(bundleOptions, projectPath, rootPath) {
34
- var _a, _b, _c, _d, _e, _f, _g, _h;
33
+ var _a, _b, _c, _d, _e, _f, _g;
35
34
  (0, common_1.blockStdout)();
36
35
  if (process.env.XCODE_PROFILE) {
37
36
  await (0, xcodeProfile_1.xcodeProfilingReady)();
@@ -43,68 +42,61 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
43
42
  (0, validateEntry_1.validateEntryPaths)(bundleOptions.config, resolvedProjectPath);
44
43
  await (0, cleanOutput_1.cleanOutput)(bundleOptions.config, resolvedProjectPath);
45
44
  const createProject = (0, project_1.projectFactory)();
46
- const persistentCacheLock = await (0, lockfile_1.acquirePersistentCacheLock)(resolvedProjectPath, "utoo pack build", persistentCaching);
47
- let project;
48
- try {
49
- project = await createProject({
50
- processEnv: (_b = bundleOptions.processEnv) !== null && _b !== void 0 ? _b : {},
51
- watch: {
52
- enable: false,
53
- },
54
- dev: (_c = bundleOptions.dev) !== null && _c !== void 0 ? _c : false,
55
- buildId: bundleOptions.buildId || (0, nanoid_1.nanoid)(),
56
- tracing: (_d = bundleOptions.tracing) !== null && _d !== void 0 ? _d : true,
57
- config: {
58
- ...bundleOptions.config,
59
- stats: Boolean(process.env.ANALYZE) ||
60
- bundleOptions.config.stats ||
61
- bundleOptions.config.entry.some((e) => !!e.html),
62
- pluginRuntimeStrategy: (_f = (_e = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.config) === null || _e === void 0 ? void 0 : _e.pluginRuntimeStrategy) !== null && _f !== void 0 ? _f : ((0, runtimePluginStratety_1.useWorkerThreads)() ? "workerThreads" : "childProcesses"),
63
- },
64
- projectPath: (0, normalizePath_1.normalizePath)(resolvedProjectPath),
65
- rootPath: resolvedRootPath,
66
- packPath: (0, common_1.getPackPath)(),
67
- }, {
68
- persistentCaching,
69
- // Build mode is a short-lived, one-shot compilation, so avoid paying
70
- // dependency graph bookkeeping cost unless the persistent cache needs it.
71
- dependencyTracking: persistentCaching,
72
- isShortSession: true,
73
- });
74
- const entrypoints = await project.writeAllEntrypointsToDisk();
75
- (0, pack_shared_1.handleIssues)(entrypoints.issues);
76
- const htmlConfigs = [
77
- ...(Array.isArray(bundleOptions.config.html)
78
- ? bundleOptions.config.html
79
- : bundleOptions.config.html
80
- ? [bundleOptions.config.html]
81
- : []),
82
- ...bundleOptions.config.entry
83
- .filter((e) => !!e.html)
84
- .map((e) => e.html),
85
- ];
86
- if (htmlConfigs.length > 0) {
87
- const assets = { js: [], css: [] };
88
- 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;
95
- for (const config of htmlConfigs) {
96
- const plugin = new HtmlPlugin_1.HtmlPlugin(config);
97
- await plugin.generate(outputDir, assets, publicPath);
98
- }
45
+ const project = await createProject({
46
+ processEnv: (_b = bundleOptions.processEnv) !== null && _b !== void 0 ? _b : {},
47
+ watch: {
48
+ enable: false,
49
+ },
50
+ dev: (_c = bundleOptions.dev) !== null && _c !== void 0 ? _c : false,
51
+ buildId: bundleOptions.buildId || (0, nanoid_1.nanoid)(),
52
+ tracing: (_d = bundleOptions.tracing) !== null && _d !== void 0 ? _d : true,
53
+ config: {
54
+ ...bundleOptions.config,
55
+ stats: Boolean(process.env.ANALYZE) ||
56
+ bundleOptions.config.stats ||
57
+ bundleOptions.config.entry.some((e) => !!e.html),
58
+ 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"),
59
+ },
60
+ projectPath: (0, normalizePath_1.normalizePath)(resolvedProjectPath),
61
+ rootPath: resolvedRootPath,
62
+ packPath: (0, common_1.getPackPath)(),
63
+ }, {
64
+ persistentCaching,
65
+ // Build mode is a short-lived, one-shot compilation, so avoid paying
66
+ // dependency graph bookkeeping cost unless the persistent cache needs it.
67
+ dependencyTracking: persistentCaching,
68
+ isShortSession: true,
69
+ });
70
+ const entrypoints = await project.writeAllEntrypointsToDisk();
71
+ (0, pack_shared_1.handleIssues)(entrypoints.issues);
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
+ if (htmlConfigs.length > 0) {
83
+ const assets = { js: [], css: [] };
84
+ const outputDir = (0, cleanOutput_1.getOutputPath)(bundleOptions.config, resolvedProjectPath);
85
+ if (assets.js.length === 0 && assets.css.length === 0) {
86
+ const discovered = (0, getInitialAssets_1.getInitialAssetsFromStats)(outputDir);
87
+ assets.js.push(...discovered.js);
88
+ assets.css.push(...discovered.css);
99
89
  }
100
- if (process.env.ANALYZE) {
101
- await analyzeBundle(((_h = bundleOptions.config.output) === null || _h === void 0 ? void 0 : _h.path) || "dist");
90
+ const publicPath = (_g = bundleOptions.config.output) === null || _g === void 0 ? void 0 : _g.publicPath;
91
+ for (const config of htmlConfigs) {
92
+ const plugin = new HtmlPlugin_1.HtmlPlugin(config);
93
+ await plugin.generate(outputDir, assets, publicPath);
102
94
  }
103
95
  }
104
- finally {
105
- await (project === null || project === void 0 ? void 0 : project.shutdown());
106
- persistentCacheLock === null || persistentCacheLock === void 0 ? void 0 : persistentCacheLock.unlockSync();
96
+ if (process.env.ANALYZE) {
97
+ await analyzeBundle((0, cleanOutput_1.getOutputPath)(bundleOptions.config, resolvedProjectPath));
107
98
  }
99
+ await project.shutdown();
108
100
  // TODO: Maybe run tasks in worker is a better way, see
109
101
  // https://github.com/vercel/next.js/blob/512d8283054407ab92b2583ecce3b253c3be7b85/packages/next/src/lib/worker.ts
110
102
  }
package/cjs/core/hmr.js CHANGED
@@ -10,7 +10,6 @@ const cleanOutput_1 = require("../utils/cleanOutput");
10
10
  const common_1 = require("../utils/common");
11
11
  const getInitialAssets_1 = require("../utils/getInitialAssets");
12
12
  const htmlEntry_1 = require("../utils/htmlEntry");
13
- const lockfile_1 = require("../utils/lockfile");
14
13
  const normalizePath_1 = require("../utils/normalizePath");
15
14
  const runtimePluginStratety_1 = require("../utils/runtimePluginStratety");
16
15
  const validateEntry_1 = require("../utils/validateEntry");
@@ -29,43 +28,34 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
29
28
  (0, validateEntry_1.validateEntryPaths)(bundleOptions.config, resolvedProjectPath);
30
29
  await (0, cleanOutput_1.cleanOutput)(bundleOptions.config, resolvedProjectPath);
31
30
  const createProject = (0, project_1.projectFactory)();
32
- const persistentCaching = (_a = bundleOptions.config.persistentCaching) !== null && _a !== void 0 ? _a : false;
33
- const persistentCacheLock = await (0, lockfile_1.acquirePersistentCacheLock)(resolvedProjectPath, "utoo pack dev", persistentCaching);
34
- let project;
35
- try {
36
- project = await createProject({
37
- processEnv: (_b = bundleOptions.processEnv) !== null && _b !== void 0 ? _b : {},
38
- watch: {
39
- enable: true,
40
- },
41
- dev: true,
42
- buildId: bundleOptions.buildId || (0, nanoid_1.nanoid)(),
43
- tracing: (_c = bundleOptions.tracing) !== null && _c !== void 0 ? _c : true,
44
- config: {
45
- ...bundleOptions.config,
46
- mode: "development",
47
- stats: Boolean(process.env.ANALYZE) ||
48
- bundleOptions.config.stats ||
49
- bundleOptions.config.entry.some((e) => !!e.html),
50
- optimization: {
51
- ...bundleOptions.config.optimization,
52
- minify: false,
53
- moduleIds: "named",
54
- },
55
- persistentCaching: (_e = (_d = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.config) === null || _d === void 0 ? void 0 : _d.persistentCaching) !== null && _e !== void 0 ? _e : true,
56
- pluginRuntimeStrategy: (_g = (_f = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.config) === null || _f === void 0 ? void 0 : _f.pluginRuntimeStrategy) !== null && _g !== void 0 ? _g : ((0, runtimePluginStratety_1.useWorkerThreads)() ? "workerThreads" : "childProcesses"),
31
+ const project = await createProject({
32
+ processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
33
+ watch: {
34
+ enable: true,
35
+ },
36
+ dev: true,
37
+ buildId: bundleOptions.buildId || (0, nanoid_1.nanoid)(),
38
+ tracing: (_b = bundleOptions.tracing) !== null && _b !== void 0 ? _b : true,
39
+ config: {
40
+ ...bundleOptions.config,
41
+ mode: "development",
42
+ stats: Boolean(process.env.ANALYZE) ||
43
+ bundleOptions.config.stats ||
44
+ bundleOptions.config.entry.some((e) => !!e.html),
45
+ optimization: {
46
+ ...bundleOptions.config.optimization,
47
+ minify: false,
48
+ moduleIds: "named",
57
49
  },
58
- projectPath: (0, normalizePath_1.normalizePath)(resolvedProjectPath),
59
- rootPath: resolvedRootPath,
60
- packPath: (0, common_1.getPackPath)(),
61
- }, {
62
- persistentCaching,
63
- });
64
- }
65
- catch (error) {
66
- persistentCacheLock === null || persistentCacheLock === void 0 ? void 0 : persistentCacheLock.unlockSync();
67
- throw error;
68
- }
50
+ persistentCaching: (_d = (_c = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.config) === null || _c === void 0 ? void 0 : _c.persistentCaching) !== null && _d !== void 0 ? _d : true,
51
+ 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"),
52
+ },
53
+ projectPath: (0, normalizePath_1.normalizePath)(resolvedProjectPath),
54
+ rootPath: resolvedRootPath,
55
+ packPath: (0, common_1.getPackPath)(),
56
+ }, {
57
+ persistentCaching: (_g = bundleOptions.config.persistentCaching) !== null && _g !== void 0 ? _g : false,
58
+ });
69
59
  const entrypointsSubscription = project.entrypointsSubscribe();
70
60
  let currentEntriesHandlingResolve;
71
61
  let currentEntriesHandling = new Promise((resolve) => (currentEntriesHandlingResolve = resolve));
@@ -89,7 +79,6 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
89
79
  let backgroundWatchGeneration = 0;
90
80
  const backgroundWriteTasks = new Map();
91
81
  let closed = false;
92
- let closePromise;
93
82
  function sendToClient(client, payload) {
94
83
  client.send(JSON.stringify(payload));
95
84
  }
@@ -261,7 +250,6 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
261
250
  subscription === null || subscription === void 0 ? void 0 : subscription.return();
262
251
  }
263
252
  async function handleEntrypointsSubscription() {
264
- var _a, _b;
265
253
  for await (const entrypoints of entrypointsSubscription) {
266
254
  if (!currentEntriesHandlingResolve) {
267
255
  currentEntriesHandling = new Promise(
@@ -269,8 +257,8 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
269
257
  (resolve) => (currentEntriesHandlingResolve = resolve));
270
258
  }
271
259
  currentWatchedEntrypoints = [
272
- ...((_a = entrypoints.apps) !== null && _a !== void 0 ? _a : []),
273
- ...((_b = entrypoints.libraries) !== null && _b !== void 0 ? _b : []),
260
+ ...entrypoints.apps,
261
+ ...entrypoints.libraries,
274
262
  ];
275
263
  await writeEntrypointsToDisk(currentWatchedEntrypoints);
276
264
  if (backgroundWatchersStarted) {
@@ -455,14 +443,6 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
455
443
  close() {
456
444
  closed = true;
457
445
  void disposeBackgroundWatchSubscriptions();
458
- closePromise !== null && closePromise !== void 0 ? closePromise : (closePromise = project
459
- .onExit()
460
- .catch((err) => {
461
- console.error(err);
462
- })
463
- .finally(() => {
464
- persistentCacheLock === null || persistentCacheLock === void 0 ? void 0 : persistentCacheLock.unlockSync();
465
- }));
466
446
  for (const wsClient of clients) {
467
447
  wsClient.close();
468
448
  }
package/esm/binding.d.ts CHANGED
@@ -9,11 +9,6 @@ export declare class ExternalObject<T> {
9
9
  [K: symbol]: T
10
10
  }
11
11
  }
12
- export type Lockfile = { __napiType: "Lockfile" }
13
- export declare function lockfileTryAcquireSync(path: string, content?: string | undefined | null): Lockfile | null
14
- export declare function lockfileTryAcquire(path: string, content?: string | undefined | null): Promise<Lockfile | null>
15
- export declare function lockfileUnlockSync(lockfile: Lockfile): void
16
- export declare function lockfileUnlock(lockfile: Lockfile): Promise<void>
17
12
  export declare function registerWorkerScheduler(creator: (arg: NapiWorkerCreation) => any, terminator: (arg: NapiWorkerTermination) => any): void
18
13
  export declare function workerCreated(workerId: number): void
19
14
  export interface NapiWorkerCreation {
package/esm/binding.js CHANGED
@@ -319,11 +319,7 @@ if (!nativeBinding) {
319
319
  }
320
320
  throw new Error(`Failed to load native binding`);
321
321
  }
322
- const { lockfileTryAcquireSync, lockfileTryAcquire, lockfileUnlockSync, lockfileUnlock, registerWorkerScheduler, workerCreated, recvTaskMessageInWorker, sendTaskMessage, endpointWriteToDisk, endpointServerChangedSubscribe, endpointClientChangedSubscribe, projectNew, projectUpdate, projectOnExit, projectShutdown, projectWriteAllEntrypointsToDisk, projectEntrypointsSubscribe, projectHmrEvents, projectHmrIdentifiersSubscribe, projectUpdateInfoSubscribe, projectTraceSource, projectGetSourceForAsset, projectGetSourceMap, projectGetSourceMapSync, rootTaskDispose, initCustomTraceSubscriber, teardownTraceSubscriber } = nativeBinding;
323
- module.exports.lockfileTryAcquireSync = lockfileTryAcquireSync;
324
- module.exports.lockfileTryAcquire = lockfileTryAcquire;
325
- module.exports.lockfileUnlockSync = lockfileUnlockSync;
326
- module.exports.lockfileUnlock = lockfileUnlock;
322
+ const { registerWorkerScheduler, workerCreated, recvTaskMessageInWorker, sendTaskMessage, endpointWriteToDisk, endpointServerChangedSubscribe, endpointClientChangedSubscribe, projectNew, projectUpdate, projectOnExit, projectShutdown, projectWriteAllEntrypointsToDisk, projectEntrypointsSubscribe, projectHmrEvents, projectHmrIdentifiersSubscribe, projectUpdateInfoSubscribe, projectTraceSource, projectGetSourceForAsset, projectGetSourceMap, projectGetSourceMapSync, rootTaskDispose, initCustomTraceSubscriber, teardownTraceSubscriber } = nativeBinding;
327
323
  module.exports.registerWorkerScheduler = registerWorkerScheduler;
328
324
  module.exports.workerCreated = workerCreated;
329
325
  module.exports.recvTaskMessageInWorker = recvTaskMessageInWorker;
@@ -11,7 +11,6 @@ import { blockStdout, getPackPath } from "../utils/common.js";
11
11
  import { findRootDir } from "../utils/findRoot.js";
12
12
  import { getInitialAssetsFromStats } from "../utils/getInitialAssets.js";
13
13
  import { processHtmlEntry } from "../utils/htmlEntry.js";
14
- import { acquirePersistentCacheLock } from "../utils/lockfile.js";
15
14
  import { normalizePath } from "../utils/normalizePath.js";
16
15
  import { useWorkerThreads } from "../utils/runtimePluginStratety.js";
17
16
  import { validateEntryPaths } from "../utils/validateEntry.js";
@@ -25,7 +24,7 @@ export function build(options, projectPath, rootPath) {
25
24
  return buildInternal(bundleOptions, projectPath, rootPath);
26
25
  }
27
26
  async function buildInternal(bundleOptions, projectPath, rootPath) {
28
- var _a, _b, _c, _d, _e, _f, _g, _h;
27
+ var _a, _b, _c, _d, _e, _f, _g;
29
28
  blockStdout();
30
29
  if (process.env.XCODE_PROFILE) {
31
30
  await xcodeProfilingReady();
@@ -37,68 +36,61 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
37
36
  validateEntryPaths(bundleOptions.config, resolvedProjectPath);
38
37
  await cleanOutput(bundleOptions.config, resolvedProjectPath);
39
38
  const createProject = projectFactory();
40
- const persistentCacheLock = await acquirePersistentCacheLock(resolvedProjectPath, "utoo pack build", persistentCaching);
41
- let project;
42
- try {
43
- project = await createProject({
44
- processEnv: (_b = bundleOptions.processEnv) !== null && _b !== void 0 ? _b : {},
45
- watch: {
46
- enable: false,
47
- },
48
- dev: (_c = bundleOptions.dev) !== null && _c !== void 0 ? _c : false,
49
- buildId: bundleOptions.buildId || nanoid(),
50
- tracing: (_d = bundleOptions.tracing) !== null && _d !== void 0 ? _d : true,
51
- config: {
52
- ...bundleOptions.config,
53
- stats: Boolean(process.env.ANALYZE) ||
54
- bundleOptions.config.stats ||
55
- bundleOptions.config.entry.some((e) => !!e.html),
56
- pluginRuntimeStrategy: (_f = (_e = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.config) === null || _e === void 0 ? void 0 : _e.pluginRuntimeStrategy) !== null && _f !== void 0 ? _f : (useWorkerThreads() ? "workerThreads" : "childProcesses"),
57
- },
58
- projectPath: normalizePath(resolvedProjectPath),
59
- rootPath: resolvedRootPath,
60
- packPath: getPackPath(),
61
- }, {
62
- persistentCaching,
63
- // Build mode is a short-lived, one-shot compilation, so avoid paying
64
- // dependency graph bookkeeping cost unless the persistent cache needs it.
65
- dependencyTracking: persistentCaching,
66
- isShortSession: true,
67
- });
68
- const entrypoints = await project.writeAllEntrypointsToDisk();
69
- handleIssues(entrypoints.issues);
70
- const htmlConfigs = [
71
- ...(Array.isArray(bundleOptions.config.html)
72
- ? bundleOptions.config.html
73
- : bundleOptions.config.html
74
- ? [bundleOptions.config.html]
75
- : []),
76
- ...bundleOptions.config.entry
77
- .filter((e) => !!e.html)
78
- .map((e) => e.html),
79
- ];
80
- if (htmlConfigs.length > 0) {
81
- const assets = { js: [], css: [] };
82
- 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;
89
- for (const config of htmlConfigs) {
90
- const plugin = new HtmlPlugin(config);
91
- await plugin.generate(outputDir, assets, publicPath);
92
- }
39
+ const project = await createProject({
40
+ processEnv: (_b = bundleOptions.processEnv) !== null && _b !== void 0 ? _b : {},
41
+ watch: {
42
+ enable: false,
43
+ },
44
+ dev: (_c = bundleOptions.dev) !== null && _c !== void 0 ? _c : false,
45
+ buildId: bundleOptions.buildId || nanoid(),
46
+ tracing: (_d = bundleOptions.tracing) !== null && _d !== void 0 ? _d : true,
47
+ config: {
48
+ ...bundleOptions.config,
49
+ stats: Boolean(process.env.ANALYZE) ||
50
+ bundleOptions.config.stats ||
51
+ bundleOptions.config.entry.some((e) => !!e.html),
52
+ 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"),
53
+ },
54
+ projectPath: normalizePath(resolvedProjectPath),
55
+ rootPath: resolvedRootPath,
56
+ packPath: getPackPath(),
57
+ }, {
58
+ persistentCaching,
59
+ // Build mode is a short-lived, one-shot compilation, so avoid paying
60
+ // dependency graph bookkeeping cost unless the persistent cache needs it.
61
+ dependencyTracking: persistentCaching,
62
+ isShortSession: true,
63
+ });
64
+ const entrypoints = await project.writeAllEntrypointsToDisk();
65
+ handleIssues(entrypoints.issues);
66
+ const htmlConfigs = [
67
+ ...(Array.isArray(bundleOptions.config.html)
68
+ ? bundleOptions.config.html
69
+ : bundleOptions.config.html
70
+ ? [bundleOptions.config.html]
71
+ : []),
72
+ ...bundleOptions.config.entry
73
+ .filter((e) => !!e.html)
74
+ .map((e) => e.html),
75
+ ];
76
+ if (htmlConfigs.length > 0) {
77
+ const assets = { js: [], css: [] };
78
+ const outputDir = getOutputPath(bundleOptions.config, resolvedProjectPath);
79
+ if (assets.js.length === 0 && assets.css.length === 0) {
80
+ const discovered = getInitialAssetsFromStats(outputDir);
81
+ assets.js.push(...discovered.js);
82
+ assets.css.push(...discovered.css);
93
83
  }
94
- if (process.env.ANALYZE) {
95
- await analyzeBundle(((_h = bundleOptions.config.output) === null || _h === void 0 ? void 0 : _h.path) || "dist");
84
+ const publicPath = (_g = bundleOptions.config.output) === null || _g === void 0 ? void 0 : _g.publicPath;
85
+ for (const config of htmlConfigs) {
86
+ const plugin = new HtmlPlugin(config);
87
+ await plugin.generate(outputDir, assets, publicPath);
96
88
  }
97
89
  }
98
- finally {
99
- await (project === null || project === void 0 ? void 0 : project.shutdown());
100
- persistentCacheLock === null || persistentCacheLock === void 0 ? void 0 : persistentCacheLock.unlockSync();
90
+ if (process.env.ANALYZE) {
91
+ await analyzeBundle(getOutputPath(bundleOptions.config, resolvedProjectPath));
101
92
  }
93
+ await project.shutdown();
102
94
  // TODO: Maybe run tasks in worker is a better way, see
103
95
  // https://github.com/vercel/next.js/blob/512d8283054407ab92b2583ecce3b253c3be7b85/packages/next/src/lib/worker.ts
104
96
  }
package/esm/core/hmr.js CHANGED
@@ -6,7 +6,6 @@ import { cleanOutput, getOutputPath } from "../utils/cleanOutput.js";
6
6
  import { debounce, getPackPath, processIssues } from "../utils/common.js";
7
7
  import { getInitialAssetsFromStats } from "../utils/getInitialAssets.js";
8
8
  import { processHtmlEntry } from "../utils/htmlEntry.js";
9
- import { acquirePersistentCacheLock } from "../utils/lockfile.js";
10
9
  import { normalizePath } from "../utils/normalizePath.js";
11
10
  import { useWorkerThreads } from "../utils/runtimePluginStratety.js";
12
11
  import { validateEntryPaths } from "../utils/validateEntry.js";
@@ -24,43 +23,34 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
24
23
  validateEntryPaths(bundleOptions.config, resolvedProjectPath);
25
24
  await cleanOutput(bundleOptions.config, resolvedProjectPath);
26
25
  const createProject = projectFactory();
27
- const persistentCaching = (_a = bundleOptions.config.persistentCaching) !== null && _a !== void 0 ? _a : false;
28
- const persistentCacheLock = await acquirePersistentCacheLock(resolvedProjectPath, "utoo pack dev", persistentCaching);
29
- let project;
30
- try {
31
- project = await createProject({
32
- processEnv: (_b = bundleOptions.processEnv) !== null && _b !== void 0 ? _b : {},
33
- watch: {
34
- enable: true,
35
- },
36
- dev: true,
37
- buildId: bundleOptions.buildId || nanoid(),
38
- tracing: (_c = bundleOptions.tracing) !== null && _c !== void 0 ? _c : true,
39
- config: {
40
- ...bundleOptions.config,
41
- mode: "development",
42
- stats: Boolean(process.env.ANALYZE) ||
43
- bundleOptions.config.stats ||
44
- bundleOptions.config.entry.some((e) => !!e.html),
45
- optimization: {
46
- ...bundleOptions.config.optimization,
47
- minify: false,
48
- moduleIds: "named",
49
- },
50
- persistentCaching: (_e = (_d = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.config) === null || _d === void 0 ? void 0 : _d.persistentCaching) !== null && _e !== void 0 ? _e : true,
51
- pluginRuntimeStrategy: (_g = (_f = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.config) === null || _f === void 0 ? void 0 : _f.pluginRuntimeStrategy) !== null && _g !== void 0 ? _g : (useWorkerThreads() ? "workerThreads" : "childProcesses"),
26
+ const project = await createProject({
27
+ processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
28
+ watch: {
29
+ enable: true,
30
+ },
31
+ dev: true,
32
+ buildId: bundleOptions.buildId || nanoid(),
33
+ tracing: (_b = bundleOptions.tracing) !== null && _b !== void 0 ? _b : true,
34
+ config: {
35
+ ...bundleOptions.config,
36
+ mode: "development",
37
+ stats: Boolean(process.env.ANALYZE) ||
38
+ bundleOptions.config.stats ||
39
+ bundleOptions.config.entry.some((e) => !!e.html),
40
+ optimization: {
41
+ ...bundleOptions.config.optimization,
42
+ minify: false,
43
+ moduleIds: "named",
52
44
  },
53
- projectPath: normalizePath(resolvedProjectPath),
54
- rootPath: resolvedRootPath,
55
- packPath: getPackPath(),
56
- }, {
57
- persistentCaching,
58
- });
59
- }
60
- catch (error) {
61
- persistentCacheLock === null || persistentCacheLock === void 0 ? void 0 : persistentCacheLock.unlockSync();
62
- throw error;
63
- }
45
+ persistentCaching: (_d = (_c = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.config) === null || _c === void 0 ? void 0 : _c.persistentCaching) !== null && _d !== void 0 ? _d : true,
46
+ 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"),
47
+ },
48
+ projectPath: normalizePath(resolvedProjectPath),
49
+ rootPath: resolvedRootPath,
50
+ packPath: getPackPath(),
51
+ }, {
52
+ persistentCaching: (_g = bundleOptions.config.persistentCaching) !== null && _g !== void 0 ? _g : false,
53
+ });
64
54
  const entrypointsSubscription = project.entrypointsSubscribe();
65
55
  let currentEntriesHandlingResolve;
66
56
  let currentEntriesHandling = new Promise((resolve) => (currentEntriesHandlingResolve = resolve));
@@ -84,7 +74,6 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
84
74
  let backgroundWatchGeneration = 0;
85
75
  const backgroundWriteTasks = new Map();
86
76
  let closed = false;
87
- let closePromise;
88
77
  function sendToClient(client, payload) {
89
78
  client.send(JSON.stringify(payload));
90
79
  }
@@ -256,7 +245,6 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
256
245
  subscription === null || subscription === void 0 ? void 0 : subscription.return();
257
246
  }
258
247
  async function handleEntrypointsSubscription() {
259
- var _a, _b;
260
248
  for await (const entrypoints of entrypointsSubscription) {
261
249
  if (!currentEntriesHandlingResolve) {
262
250
  currentEntriesHandling = new Promise(
@@ -264,8 +252,8 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
264
252
  (resolve) => (currentEntriesHandlingResolve = resolve));
265
253
  }
266
254
  currentWatchedEntrypoints = [
267
- ...((_a = entrypoints.apps) !== null && _a !== void 0 ? _a : []),
268
- ...((_b = entrypoints.libraries) !== null && _b !== void 0 ? _b : []),
255
+ ...entrypoints.apps,
256
+ ...entrypoints.libraries,
269
257
  ];
270
258
  await writeEntrypointsToDisk(currentWatchedEntrypoints);
271
259
  if (backgroundWatchersStarted) {
@@ -450,14 +438,6 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
450
438
  close() {
451
439
  closed = true;
452
440
  void disposeBackgroundWatchSubscriptions();
453
- closePromise !== null && closePromise !== void 0 ? closePromise : (closePromise = project
454
- .onExit()
455
- .catch((err) => {
456
- console.error(err);
457
- })
458
- .finally(() => {
459
- persistentCacheLock === null || persistentCacheLock === void 0 ? void 0 : persistentCacheLock.unlockSync();
460
- }));
461
441
  for (const wsClient of clients) {
462
442
  wsClient.close();
463
443
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "1.4.4-alpha.1",
3
+ "version": "1.4.5-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.4-alpha.1",
44
+ "@utoo/pack-shared": "1.4.5-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.4-alpha.1",
96
- "@utoo/pack-darwin-x64": "1.4.4-alpha.1",
97
- "@utoo/pack-linux-arm64-gnu": "1.4.4-alpha.1",
98
- "@utoo/pack-linux-arm64-musl": "1.4.4-alpha.1",
99
- "@utoo/pack-linux-x64-gnu": "1.4.4-alpha.1",
100
- "@utoo/pack-linux-x64-musl": "1.4.4-alpha.1",
101
- "@utoo/pack-win32-x64-msvc": "1.4.4-alpha.1"
95
+ "@utoo/pack-darwin-arm64": "1.4.5-alpha.0",
96
+ "@utoo/pack-darwin-x64": "1.4.5-alpha.0",
97
+ "@utoo/pack-linux-arm64-gnu": "1.4.5-alpha.0",
98
+ "@utoo/pack-linux-arm64-musl": "1.4.5-alpha.0",
99
+ "@utoo/pack-linux-x64-gnu": "1.4.5-alpha.0",
100
+ "@utoo/pack-linux-x64-musl": "1.4.5-alpha.0",
101
+ "@utoo/pack-win32-x64-msvc": "1.4.5-alpha.0"
102
102
  }
103
103
  }
@@ -1,10 +0,0 @@
1
- export declare class PersistentCacheLock {
2
- private listener;
3
- private nativeLockfile;
4
- private constructor();
5
- static tryAcquire(lockPath: string, content?: string): PersistentCacheLock | undefined;
6
- static acquireWithRetries(lockPath: string, processName: string): Promise<PersistentCacheLock>;
7
- unlock(): Promise<void>;
8
- unlockSync(): void;
9
- }
10
- export declare function acquirePersistentCacheLock(projectPath: string, processName: string, persistentCaching: boolean): Promise<PersistentCacheLock | undefined>;
@@ -1,121 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.PersistentCacheLock = void 0;
40
- exports.acquirePersistentCacheLock = acquirePersistentCacheLock;
41
- const fs_1 = __importDefault(require("fs"));
42
- const path_1 = __importDefault(require("path"));
43
- const picocolors_1 = __importDefault(require("picocolors"));
44
- const binding = __importStar(require("../binding"));
45
- const RETRY_DELAY_MS = 10;
46
- const MAX_RETRY_MS = 1000;
47
- class PersistentCacheLock {
48
- constructor(nativeLockfile) {
49
- this.nativeLockfile = nativeLockfile;
50
- this.listener = () => this.unlockSync();
51
- process.on("exit", this.listener);
52
- }
53
- static tryAcquire(lockPath, content) {
54
- const nativeLockfile = binding.lockfileTryAcquireSync(lockPath, content);
55
- return nativeLockfile ? new PersistentCacheLock(nativeLockfile) : undefined;
56
- }
57
- static async acquireWithRetries(lockPath, processName) {
58
- const content = JSON.stringify({
59
- pid: process.pid,
60
- processName,
61
- startedAt: Date.now(),
62
- });
63
- const startMs = Date.now();
64
- let lockfile;
65
- while (Date.now() - startMs < MAX_RETRY_MS) {
66
- lockfile = PersistentCacheLock.tryAcquire(lockPath, content);
67
- if (lockfile) {
68
- return lockfile;
69
- }
70
- await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS));
71
- }
72
- throw new Error(formatLockError(lockPath, processName));
73
- }
74
- async unlock() {
75
- const lockfile = this.nativeLockfile;
76
- this.nativeLockfile = undefined;
77
- if (this.listener) {
78
- process.off("exit", this.listener);
79
- this.listener = undefined;
80
- }
81
- if (lockfile) {
82
- await binding.lockfileUnlock(lockfile);
83
- }
84
- }
85
- unlockSync() {
86
- const lockfile = this.nativeLockfile;
87
- this.nativeLockfile = undefined;
88
- if (this.listener) {
89
- process.off("exit", this.listener);
90
- this.listener = undefined;
91
- }
92
- if (lockfile) {
93
- binding.lockfileUnlockSync(lockfile);
94
- }
95
- }
96
- }
97
- exports.PersistentCacheLock = PersistentCacheLock;
98
- async function acquirePersistentCacheLock(projectPath, processName, persistentCaching) {
99
- if (!persistentCaching) {
100
- return undefined;
101
- }
102
- const internalDir = path_1.default.join(path_1.default.resolve(projectPath), ".turbopack");
103
- fs_1.default.mkdirSync(internalDir, { recursive: true });
104
- return PersistentCacheLock.acquireWithRetries(path_1.default.join(internalDir, "lock"), processName);
105
- }
106
- function formatLockError(lockPath, processName) {
107
- let owner = "";
108
- try {
109
- const data = JSON.parse(fs_1.default.readFileSync(lockPath, "utf-8"));
110
- if (data.pid) {
111
- const killCommand = process.platform === "win32"
112
- ? `taskkill /PID ${data.pid} /F`
113
- : `kill ${data.pid}`;
114
- owner = `\nExisting process: ${data.processName || "unknown"} (PID ${data.pid}).\nStop it with ${picocolors_1.default.cyan(killCommand)} if it is stale.`;
115
- }
116
- }
117
- catch (_a) {
118
- // The lock holder might be a version that did not write metadata.
119
- }
120
- return `Unable to acquire ${processName} persistent cache lock at ${picocolors_1.default.cyan(lockPath)}. Another utoo pack process may be using the same .turbopack cache.${owner}`;
121
- }
@@ -1,10 +0,0 @@
1
- export declare class PersistentCacheLock {
2
- private listener;
3
- private nativeLockfile;
4
- private constructor();
5
- static tryAcquire(lockPath: string, content?: string): PersistentCacheLock | undefined;
6
- static acquireWithRetries(lockPath: string, processName: string): Promise<PersistentCacheLock>;
7
- unlock(): Promise<void>;
8
- unlockSync(): void;
9
- }
10
- export declare function acquirePersistentCacheLock(projectPath: string, processName: string, persistentCaching: boolean): Promise<PersistentCacheLock | undefined>;
@@ -1,80 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import pc from "picocolors";
4
- import * as binding from "../binding.js";
5
- const RETRY_DELAY_MS = 10;
6
- const MAX_RETRY_MS = 1000;
7
- export class PersistentCacheLock {
8
- constructor(nativeLockfile) {
9
- this.nativeLockfile = nativeLockfile;
10
- this.listener = () => this.unlockSync();
11
- process.on("exit", this.listener);
12
- }
13
- static tryAcquire(lockPath, content) {
14
- const nativeLockfile = binding.lockfileTryAcquireSync(lockPath, content);
15
- return nativeLockfile ? new PersistentCacheLock(nativeLockfile) : undefined;
16
- }
17
- static async acquireWithRetries(lockPath, processName) {
18
- const content = JSON.stringify({
19
- pid: process.pid,
20
- processName,
21
- startedAt: Date.now(),
22
- });
23
- const startMs = Date.now();
24
- let lockfile;
25
- while (Date.now() - startMs < MAX_RETRY_MS) {
26
- lockfile = PersistentCacheLock.tryAcquire(lockPath, content);
27
- if (lockfile) {
28
- return lockfile;
29
- }
30
- await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS));
31
- }
32
- throw new Error(formatLockError(lockPath, processName));
33
- }
34
- async unlock() {
35
- const lockfile = this.nativeLockfile;
36
- this.nativeLockfile = undefined;
37
- if (this.listener) {
38
- process.off("exit", this.listener);
39
- this.listener = undefined;
40
- }
41
- if (lockfile) {
42
- await binding.lockfileUnlock(lockfile);
43
- }
44
- }
45
- unlockSync() {
46
- const lockfile = this.nativeLockfile;
47
- this.nativeLockfile = undefined;
48
- if (this.listener) {
49
- process.off("exit", this.listener);
50
- this.listener = undefined;
51
- }
52
- if (lockfile) {
53
- binding.lockfileUnlockSync(lockfile);
54
- }
55
- }
56
- }
57
- export async function acquirePersistentCacheLock(projectPath, processName, persistentCaching) {
58
- if (!persistentCaching) {
59
- return undefined;
60
- }
61
- const internalDir = path.join(path.resolve(projectPath), ".turbopack");
62
- fs.mkdirSync(internalDir, { recursive: true });
63
- return PersistentCacheLock.acquireWithRetries(path.join(internalDir, "lock"), processName);
64
- }
65
- function formatLockError(lockPath, processName) {
66
- let owner = "";
67
- try {
68
- const data = JSON.parse(fs.readFileSync(lockPath, "utf-8"));
69
- if (data.pid) {
70
- const killCommand = process.platform === "win32"
71
- ? `taskkill /PID ${data.pid} /F`
72
- : `kill ${data.pid}`;
73
- owner = `\nExisting process: ${data.processName || "unknown"} (PID ${data.pid}).\nStop it with ${pc.cyan(killCommand)} if it is stale.`;
74
- }
75
- }
76
- catch (_a) {
77
- // The lock holder might be a version that did not write metadata.
78
- }
79
- return `Unable to acquire ${processName} persistent cache lock at ${pc.cyan(lockPath)}. Another utoo pack process may be using the same .turbopack cache.${owner}`;
80
- }