@utoo/pack 1.4.5-alpha.1 → 1.4.5-alpha.3
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 +5 -0
- package/cjs/binding.js +5 -1
- package/cjs/commands/build.js +60 -52
- package/cjs/core/hmr.js +49 -29
- package/cjs/utils/lockfile.d.ts +10 -0
- package/cjs/utils/lockfile.js +121 -0
- package/esm/binding.d.ts +5 -0
- package/esm/binding.js +5 -1
- package/esm/commands/build.js +60 -52
- package/esm/core/hmr.js +49 -29
- package/esm/utils/lockfile.d.ts +10 -0
- package/esm/utils/lockfile.js +80 -0
- package/package.json +9 -9
package/cjs/binding.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ 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>
|
|
12
17
|
export declare function registerWorkerScheduler(creator: (arg: NapiWorkerCreation) => any, terminator: (arg: NapiWorkerTermination) => any): void
|
|
13
18
|
export declare function workerCreated(workerId: number): void
|
|
14
19
|
export interface NapiWorkerCreation {
|
package/cjs/binding.js
CHANGED
|
@@ -319,7 +319,11 @@ if (!nativeBinding) {
|
|
|
319
319
|
}
|
|
320
320
|
throw new Error(`Failed to load native binding`);
|
|
321
321
|
}
|
|
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;
|
|
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;
|
|
323
327
|
module.exports.registerWorkerScheduler = registerWorkerScheduler;
|
|
324
328
|
module.exports.workerCreated = workerCreated;
|
|
325
329
|
module.exports.recvTaskMessageInWorker = recvTaskMessageInWorker;
|
package/cjs/commands/build.js
CHANGED
|
@@ -17,6 +17,7 @@ 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");
|
|
20
21
|
const normalizePath_1 = require("../utils/normalizePath");
|
|
21
22
|
const runtimePluginStratety_1 = require("../utils/runtimePluginStratety");
|
|
22
23
|
const validateEntry_1 = require("../utils/validateEntry");
|
|
@@ -30,7 +31,7 @@ function build(options, projectPath, rootPath) {
|
|
|
30
31
|
return buildInternal(bundleOptions, projectPath, rootPath);
|
|
31
32
|
}
|
|
32
33
|
async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
33
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
34
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
34
35
|
(0, common_1.blockStdout)();
|
|
35
36
|
if (process.env.XCODE_PROFILE) {
|
|
36
37
|
await (0, xcodeProfile_1.xcodeProfilingReady)();
|
|
@@ -42,61 +43,68 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
42
43
|
(0, validateEntry_1.validateEntryPaths)(bundleOptions.config, resolvedProjectPath);
|
|
43
44
|
await (0, cleanOutput_1.cleanOutput)(bundleOptions.config, resolvedProjectPath);
|
|
44
45
|
const createProject = (0, project_1.projectFactory)();
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
bundleOptions.config
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
assets.
|
|
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
|
+
}
|
|
89
99
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const plugin = new HtmlPlugin_1.HtmlPlugin(config);
|
|
93
|
-
await plugin.generate(outputDir, assets, publicPath);
|
|
100
|
+
if (process.env.ANALYZE) {
|
|
101
|
+
await analyzeBundle(((_h = bundleOptions.config.output) === null || _h === void 0 ? void 0 : _h.path) || "dist");
|
|
94
102
|
}
|
|
95
103
|
}
|
|
96
|
-
|
|
97
|
-
await
|
|
104
|
+
finally {
|
|
105
|
+
await (project === null || project === void 0 ? void 0 : project.shutdown());
|
|
106
|
+
persistentCacheLock === null || persistentCacheLock === void 0 ? void 0 : persistentCacheLock.unlockSync();
|
|
98
107
|
}
|
|
99
|
-
await project.shutdown();
|
|
100
108
|
// TODO: Maybe run tasks in worker is a better way, see
|
|
101
109
|
// https://github.com/vercel/next.js/blob/512d8283054407ab92b2583ecce3b253c3be7b85/packages/next/src/lib/worker.ts
|
|
102
110
|
}
|
package/cjs/core/hmr.js
CHANGED
|
@@ -10,6 +10,7 @@ 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");
|
|
13
14
|
const normalizePath_1 = require("../utils/normalizePath");
|
|
14
15
|
const runtimePluginStratety_1 = require("../utils/runtimePluginStratety");
|
|
15
16
|
const validateEntry_1 = require("../utils/validateEntry");
|
|
@@ -28,34 +29,43 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
28
29
|
(0, validateEntry_1.validateEntryPaths)(bundleOptions.config, resolvedProjectPath);
|
|
29
30
|
await (0, cleanOutput_1.cleanOutput)(bundleOptions.config, resolvedProjectPath);
|
|
30
31
|
const createProject = (0, project_1.projectFactory)();
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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",
|
|
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,
|
|
49
40
|
},
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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"),
|
|
57
|
+
},
|
|
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
|
+
}
|
|
59
69
|
const entrypointsSubscription = project.entrypointsSubscribe();
|
|
60
70
|
let currentEntriesHandlingResolve;
|
|
61
71
|
let currentEntriesHandling = new Promise((resolve) => (currentEntriesHandlingResolve = resolve));
|
|
@@ -79,6 +89,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
79
89
|
let backgroundWatchGeneration = 0;
|
|
80
90
|
const backgroundWriteTasks = new Map();
|
|
81
91
|
let closed = false;
|
|
92
|
+
let closePromise;
|
|
82
93
|
function sendToClient(client, payload) {
|
|
83
94
|
client.send(JSON.stringify(payload));
|
|
84
95
|
}
|
|
@@ -250,6 +261,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
250
261
|
subscription === null || subscription === void 0 ? void 0 : subscription.return();
|
|
251
262
|
}
|
|
252
263
|
async function handleEntrypointsSubscription() {
|
|
264
|
+
var _a, _b;
|
|
253
265
|
for await (const entrypoints of entrypointsSubscription) {
|
|
254
266
|
if (!currentEntriesHandlingResolve) {
|
|
255
267
|
currentEntriesHandling = new Promise(
|
|
@@ -257,8 +269,8 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
257
269
|
(resolve) => (currentEntriesHandlingResolve = resolve));
|
|
258
270
|
}
|
|
259
271
|
currentWatchedEntrypoints = [
|
|
260
|
-
...entrypoints.apps,
|
|
261
|
-
...entrypoints.libraries,
|
|
272
|
+
...((_a = entrypoints.apps) !== null && _a !== void 0 ? _a : []),
|
|
273
|
+
...((_b = entrypoints.libraries) !== null && _b !== void 0 ? _b : []),
|
|
262
274
|
];
|
|
263
275
|
await writeEntrypointsToDisk(currentWatchedEntrypoints);
|
|
264
276
|
if (backgroundWatchersStarted) {
|
|
@@ -443,6 +455,14 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
443
455
|
close() {
|
|
444
456
|
closed = true;
|
|
445
457
|
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
|
+
}));
|
|
446
466
|
for (const wsClient of clients) {
|
|
447
467
|
wsClient.close();
|
|
448
468
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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>;
|
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
}
|
package/esm/binding.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ 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>
|
|
12
17
|
export declare function registerWorkerScheduler(creator: (arg: NapiWorkerCreation) => any, terminator: (arg: NapiWorkerTermination) => any): void
|
|
13
18
|
export declare function workerCreated(workerId: number): void
|
|
14
19
|
export interface NapiWorkerCreation {
|
package/esm/binding.js
CHANGED
|
@@ -319,7 +319,11 @@ if (!nativeBinding) {
|
|
|
319
319
|
}
|
|
320
320
|
throw new Error(`Failed to load native binding`);
|
|
321
321
|
}
|
|
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;
|
|
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;
|
|
323
327
|
module.exports.registerWorkerScheduler = registerWorkerScheduler;
|
|
324
328
|
module.exports.workerCreated = workerCreated;
|
|
325
329
|
module.exports.recvTaskMessageInWorker = recvTaskMessageInWorker;
|
package/esm/commands/build.js
CHANGED
|
@@ -11,6 +11,7 @@ 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";
|
|
14
15
|
import { normalizePath } from "../utils/normalizePath.js";
|
|
15
16
|
import { useWorkerThreads } from "../utils/runtimePluginStratety.js";
|
|
16
17
|
import { validateEntryPaths } from "../utils/validateEntry.js";
|
|
@@ -24,7 +25,7 @@ export function build(options, projectPath, rootPath) {
|
|
|
24
25
|
return buildInternal(bundleOptions, projectPath, rootPath);
|
|
25
26
|
}
|
|
26
27
|
async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
27
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
28
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
28
29
|
blockStdout();
|
|
29
30
|
if (process.env.XCODE_PROFILE) {
|
|
30
31
|
await xcodeProfilingReady();
|
|
@@ -36,61 +37,68 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
36
37
|
validateEntryPaths(bundleOptions.config, resolvedProjectPath);
|
|
37
38
|
await cleanOutput(bundleOptions.config, resolvedProjectPath);
|
|
38
39
|
const createProject = projectFactory();
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
bundleOptions.config
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
assets.
|
|
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
|
+
}
|
|
83
93
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const plugin = new HtmlPlugin(config);
|
|
87
|
-
await plugin.generate(outputDir, assets, publicPath);
|
|
94
|
+
if (process.env.ANALYZE) {
|
|
95
|
+
await analyzeBundle(((_h = bundleOptions.config.output) === null || _h === void 0 ? void 0 : _h.path) || "dist");
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
|
-
|
|
91
|
-
await
|
|
98
|
+
finally {
|
|
99
|
+
await (project === null || project === void 0 ? void 0 : project.shutdown());
|
|
100
|
+
persistentCacheLock === null || persistentCacheLock === void 0 ? void 0 : persistentCacheLock.unlockSync();
|
|
92
101
|
}
|
|
93
|
-
await project.shutdown();
|
|
94
102
|
// TODO: Maybe run tasks in worker is a better way, see
|
|
95
103
|
// https://github.com/vercel/next.js/blob/512d8283054407ab92b2583ecce3b253c3be7b85/packages/next/src/lib/worker.ts
|
|
96
104
|
}
|
package/esm/core/hmr.js
CHANGED
|
@@ -6,6 +6,7 @@ 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";
|
|
9
10
|
import { normalizePath } from "../utils/normalizePath.js";
|
|
10
11
|
import { useWorkerThreads } from "../utils/runtimePluginStratety.js";
|
|
11
12
|
import { validateEntryPaths } from "../utils/validateEntry.js";
|
|
@@ -23,34 +24,43 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
23
24
|
validateEntryPaths(bundleOptions.config, resolvedProjectPath);
|
|
24
25
|
await cleanOutput(bundleOptions.config, resolvedProjectPath);
|
|
25
26
|
const createProject = projectFactory();
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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",
|
|
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,
|
|
44
35
|
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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"),
|
|
52
|
+
},
|
|
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
|
+
}
|
|
54
64
|
const entrypointsSubscription = project.entrypointsSubscribe();
|
|
55
65
|
let currentEntriesHandlingResolve;
|
|
56
66
|
let currentEntriesHandling = new Promise((resolve) => (currentEntriesHandlingResolve = resolve));
|
|
@@ -74,6 +84,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
74
84
|
let backgroundWatchGeneration = 0;
|
|
75
85
|
const backgroundWriteTasks = new Map();
|
|
76
86
|
let closed = false;
|
|
87
|
+
let closePromise;
|
|
77
88
|
function sendToClient(client, payload) {
|
|
78
89
|
client.send(JSON.stringify(payload));
|
|
79
90
|
}
|
|
@@ -245,6 +256,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
245
256
|
subscription === null || subscription === void 0 ? void 0 : subscription.return();
|
|
246
257
|
}
|
|
247
258
|
async function handleEntrypointsSubscription() {
|
|
259
|
+
var _a, _b;
|
|
248
260
|
for await (const entrypoints of entrypointsSubscription) {
|
|
249
261
|
if (!currentEntriesHandlingResolve) {
|
|
250
262
|
currentEntriesHandling = new Promise(
|
|
@@ -252,8 +264,8 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
252
264
|
(resolve) => (currentEntriesHandlingResolve = resolve));
|
|
253
265
|
}
|
|
254
266
|
currentWatchedEntrypoints = [
|
|
255
|
-
...entrypoints.apps,
|
|
256
|
-
...entrypoints.libraries,
|
|
267
|
+
...((_a = entrypoints.apps) !== null && _a !== void 0 ? _a : []),
|
|
268
|
+
...((_b = entrypoints.libraries) !== null && _b !== void 0 ? _b : []),
|
|
257
269
|
];
|
|
258
270
|
await writeEntrypointsToDisk(currentWatchedEntrypoints);
|
|
259
271
|
if (backgroundWatchersStarted) {
|
|
@@ -438,6 +450,14 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
438
450
|
close() {
|
|
439
451
|
closed = true;
|
|
440
452
|
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
|
+
}));
|
|
441
461
|
for (const wsClient of clients) {
|
|
442
462
|
wsClient.close();
|
|
443
463
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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>;
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/pack",
|
|
3
|
-
"version": "1.4.5-alpha.
|
|
3
|
+
"version": "1.4.5-alpha.3",
|
|
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.5-alpha.
|
|
44
|
+
"@utoo/pack-shared": "1.4.5-alpha.3",
|
|
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.5-alpha.
|
|
96
|
-
"@utoo/pack-darwin-x64": "1.4.5-alpha.
|
|
97
|
-
"@utoo/pack-linux-arm64-gnu": "1.4.5-alpha.
|
|
98
|
-
"@utoo/pack-linux-arm64-musl": "1.4.5-alpha.
|
|
99
|
-
"@utoo/pack-linux-x64-gnu": "1.4.5-alpha.
|
|
100
|
-
"@utoo/pack-linux-x64-musl": "1.4.5-alpha.
|
|
101
|
-
"@utoo/pack-win32-x64-msvc": "1.4.5-alpha.
|
|
95
|
+
"@utoo/pack-darwin-arm64": "1.4.5-alpha.3",
|
|
96
|
+
"@utoo/pack-darwin-x64": "1.4.5-alpha.3",
|
|
97
|
+
"@utoo/pack-linux-arm64-gnu": "1.4.5-alpha.3",
|
|
98
|
+
"@utoo/pack-linux-arm64-musl": "1.4.5-alpha.3",
|
|
99
|
+
"@utoo/pack-linux-x64-gnu": "1.4.5-alpha.3",
|
|
100
|
+
"@utoo/pack-linux-x64-musl": "1.4.5-alpha.3",
|
|
101
|
+
"@utoo/pack-win32-x64-msvc": "1.4.5-alpha.3"
|
|
102
102
|
}
|
|
103
103
|
}
|