knarr 0.2.0 → 0.3.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/README.md +65 -106
- package/dist/{add-Clbi3vJ2.mjs → add-B_xzUp5y.mjs} +1 -1
- package/dist/add-flow-cvrMO_aV.mjs +5 -0
- package/dist/{batch-push-pVkjhRbp.mjs → batch-push-DXtZxRx0.mjs} +1 -1
- package/dist/build-detect-BTHh2OBm.mjs +3 -0
- package/dist/{bundler-detect-Cx8_R2hT.mjs → bundler-detect-Dq-QAbQj.mjs} +1 -1
- package/dist/check-CbVdpTsw.mjs +3 -0
- package/dist/clean-CyDDqbBD.mjs +3 -0
- package/dist/cli.mjs +3 -3
- package/dist/{config-CQpgsGyL.mjs → config-BJsL6NqN.mjs} +1 -1
- package/dist/console-CIiXr7ge.mjs +3 -0
- package/dist/{console-BxhMcj-D.mjs → console-CyaBcUd-.mjs} +19 -2
- package/dist/{dev-DeOwxr_7.mjs → dev-kqgY9NjI.mjs} +1 -1
- package/dist/doctor-D-S1P0UG.mjs +6 -0
- package/dist/{dry-run-BxVjpNqJ.mjs → dry-run-BkdMYSIx.mjs} +1 -1
- package/dist/errors-BlOfexcH.mjs +3 -0
- package/dist/explain-9Y4SZHjC.mjs +3 -0
- package/dist/{fs-DUcoWJ1g.mjs → fs-C4juVCTd.mjs} +1 -1
- package/dist/fs-CPnWm9CR.mjs +3 -0
- package/dist/{fs-BjaNhdzt.mjs → fs-DzsciYAL.mjs} +147 -73
- package/dist/{bell-UNNirKkz.mjs → history-DRhLwzhq.mjs} +1 -1
- package/dist/history-vS3w4EGu.mjs +3 -0
- package/dist/index.d.ts +17 -14
- package/dist/index.mjs +158 -80
- package/dist/init-TN84d5jM.mjs +4 -0
- package/dist/init-helpers-CYYWQm-P.mjs +15 -0
- package/dist/injector-nt40JxVt.mjs +3 -0
- package/dist/json-DbSkpxtr.mjs +3 -0
- package/dist/list-9hWJjw19.mjs +3 -0
- package/dist/{logger-DlikgOlh.mjs → logger-9C6B9Na8.mjs} +1 -1
- package/dist/migrate-Co4qcFt6.mjs +5 -0
- package/dist/{nextjs-config-BfHv8mBE.mjs → nextjs-config-BQgTWZ96.mjs} +1 -1
- package/dist/{nextjs-config-CA4N_9VY.mjs → nextjs-config-dUw2J6B9.mjs} +1 -1
- package/dist/{output-BxyRer_F.mjs → output-BxR2v-jn.mjs} +1 -1
- package/dist/{package-manager-DBBQ0XtZ.mjs → package-manager-DJ8CE0zL.mjs} +1 -1
- package/dist/{preflight-B8ypfoKV.mjs → preflight-BDsxR2Ct.mjs} +1 -1
- package/dist/{preflight-B17VQJs0.mjs → preflight-MzNjLXiy.mjs} +1 -1
- package/dist/{publish-BLk5_qx1.mjs → publish-C7ZUvHkE.mjs} +1 -1
- package/dist/publisher-CvXTbkLP.mjs +4 -0
- package/dist/{push-C6UFcNGO.mjs → push-B5KrkILW.mjs} +1 -1
- package/dist/push-engine-BpNr8qXR.mjs +3 -0
- package/dist/{remove-Bz9dNgDM.mjs → remove-DkOgVQMZ.mjs} +1 -1
- package/dist/remove-J5tY_BFk.mjs +3 -0
- package/dist/{reset--AuvAPTc.mjs → reset-ClGouUb5.mjs} +1 -1
- package/dist/{restore-CIBe2F1d.mjs → restore-Bx2V59SL.mjs} +1 -1
- package/dist/rollback-RPjHZWtG.mjs +3 -0
- package/dist/status-Rnvw6dG2.mjs +3 -0
- package/dist/store-DjPdOKqg.mjs +3 -0
- package/dist/{tailwind-source-Cgva0Hte.mjs → tailwind-source-D1cUiG-t.mjs} +1 -1
- package/dist/{history-BZS2YUIt.mjs → tracker-89eW0ArT.mjs} +1 -1
- package/dist/tracker-B3Fqx94J.mjs +3 -0
- package/dist/{update-Dacjzw4f.mjs → update-CAKFICZu.mjs} +1 -1
- package/dist/{use-BSCV4IQ5.mjs → use-CCx6J0mc.mjs} +1 -1
- package/dist/{vite-config-DqxvL5TW.mjs → vite-config-BHmawlD2.mjs} +1 -1
- package/dist/{vite-config-CbYEhn5K.mjs → vite-config-BRlYc4ni.mjs} +1 -1
- package/dist/{watch-orchestrator-CghvwrNS.mjs → watch-orchestrator-BfuCaZLA.mjs} +1 -1
- package/dist/watcher-T123sBDg.mjs +3 -0
- package/dist/workspace-CdLSxPFS.mjs +3 -0
- package/dist/{workspace-D4vhzpO4.mjs → workspace-DBxNrowu.mjs} +1 -1
- package/package.json +3 -2
- package/dist/add-flow-DdDziP5M.mjs +0 -5
- package/dist/bell-BJuCym_5.mjs +0 -11
- package/dist/bell-CIzHg0kw.mjs +0 -3
- package/dist/build-detect-mSo9jKXK.mjs +0 -3
- package/dist/check-Boh8WU_W.mjs +0 -3
- package/dist/clean-DHh6fpmR.mjs +0 -3
- package/dist/console-X31Y_QS5.mjs +0 -3
- package/dist/doctor-XEdsr84Q.mjs +0 -6
- package/dist/errors-CV7G61Hr.mjs +0 -3
- package/dist/explain-BBv3U-D3.mjs +0 -3
- package/dist/fs-Cf1JTFyh.mjs +0 -3
- package/dist/history-C5ehozRy.mjs +0 -3
- package/dist/init-Dwf-EIG3.mjs +0 -4
- package/dist/init-helpers-BfDosqvf.mjs +0 -15
- package/dist/injector-XwK_LBUh.mjs +0 -3
- package/dist/json-C6XtcMC4.mjs +0 -46
- package/dist/json-CWzEb9Rt.mjs +0 -3
- package/dist/list-DcREV9JM.mjs +0 -3
- package/dist/migrate-DW5KQeDq.mjs +0 -5
- package/dist/publisher-Br4Od-iL.mjs +0 -4
- package/dist/push-engine-D3rfg2Tj.mjs +0 -3
- package/dist/remove-DMj6k2PK.mjs +0 -3
- package/dist/rollback-CFLIncnW.mjs +0 -3
- package/dist/rolldown-runtime-D3KUYPsf.mjs +0 -12
- package/dist/status-Dy-e_RtI.mjs +0 -3
- package/dist/store-BNeGfW_b.mjs +0 -3
- package/dist/tracker-DXSo5wXO.mjs +0 -3
- package/dist/tracker-DofCXLTP.mjs +0 -3
- package/dist/watcher-Bw_qcI0M.mjs +0 -3
- package/dist/workspace-DVY5o1g8.mjs +0 -3
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import { constants, copyFile, cp, lstat, mkdir, readFile, readdir, realpath, rename, rm, stat, symlink, utimes, writeFile } from "node:fs/promises";
|
|
1
|
+
import { t as consola } from "./console-CyaBcUd-.mjs";
|
|
2
|
+
import { constants, copyFile, cp, lstat, mkdir, readFile, readdir, realpath, rename, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
4
3
|
import { dirname, isAbsolute, join, parse, relative, resolve, sep } from "node:path";
|
|
5
4
|
import { availableParallelism, homedir } from "node:os";
|
|
6
|
-
import { createHash } from "node:crypto";
|
|
5
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
6
|
+
import { setTimeout } from "node:timers/promises";
|
|
7
|
+
// \0rolldown/runtime.js
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __exportAll = (all, flags) => {
|
|
10
|
+
let target = Object.setPrototypeOf({}, null);
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
+
return flags & 2 ? target : Object.preventExtensions(target);
|
|
17
|
+
};
|
|
7
18
|
// src/utils/concurrency.ts
|
|
8
19
|
/**
|
|
9
20
|
* Minimal p-limit replacement using a promise queue.
|
|
@@ -46,6 +57,55 @@ function pLimit(concurrency) {
|
|
|
46
57
|
} else queue.push(run);
|
|
47
58
|
});
|
|
48
59
|
}
|
|
60
|
+
// src/utils/json.ts
|
|
61
|
+
function ownRecord(source) {
|
|
62
|
+
const record = Object.create(null);
|
|
63
|
+
if (source) for (const [key, value] of Object.entries(source)) record[key] = value;
|
|
64
|
+
return record;
|
|
65
|
+
}
|
|
66
|
+
function isJsonObject(value) {
|
|
67
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
68
|
+
}
|
|
69
|
+
/** Parse JSON to `unknown`; callers must validate before use. */
|
|
70
|
+
function parseJson(text) {
|
|
71
|
+
return JSON.parse(text);
|
|
72
|
+
}
|
|
73
|
+
/** Parse JSON that must be an object (package.json, state files). Throws otherwise. */
|
|
74
|
+
function parseJsonObject(text, label = "JSON") {
|
|
75
|
+
const value = parseJson(text);
|
|
76
|
+
if (!isJsonObject(value)) throw new Error(`${label} must contain a JSON object`);
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
async function readJsonObject(path, label = path) {
|
|
80
|
+
return parseJsonObject(await readFile(path, "utf-8"), label);
|
|
81
|
+
}
|
|
82
|
+
/** `obj[key]` when it is a string. */
|
|
83
|
+
function stringField(obj, key) {
|
|
84
|
+
const value = obj[key];
|
|
85
|
+
return typeof value === "string" ? value : void 0;
|
|
86
|
+
}
|
|
87
|
+
/** `obj[key]` when it is a JSON object. */
|
|
88
|
+
function objectField(obj, key) {
|
|
89
|
+
const value = obj[key];
|
|
90
|
+
return isJsonObject(value) ? value : void 0;
|
|
91
|
+
}
|
|
92
|
+
/** The string-valued entries of `obj[key]` (e.g. package.json "scripts"). */
|
|
93
|
+
function stringRecordField(obj, key) {
|
|
94
|
+
const value = objectField(obj, key);
|
|
95
|
+
const result = ownRecord();
|
|
96
|
+
if (!value) return result;
|
|
97
|
+
for (const [k, v] of Object.entries(value)) if (typeof v === "string") result[k] = v;
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Narrow a parsed package.json to `PackageJson`. `name` and `version` (the
|
|
102
|
+
* identity used for store paths) must be strings. Other fields stay as parsed
|
|
103
|
+
* and must be checked where they are used.
|
|
104
|
+
*/
|
|
105
|
+
function asPackageJson(obj) {
|
|
106
|
+
if (typeof obj["name"] !== "string" || typeof obj["version"] !== "string") return null;
|
|
107
|
+
return obj;
|
|
108
|
+
}
|
|
49
109
|
// src/utils/validators.ts
|
|
50
110
|
const PACKAGE_NAME_RE = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
|
|
51
111
|
const SEMVER_RE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
@@ -83,25 +143,29 @@ function isLinkEntry(value) {
|
|
|
83
143
|
"bun"
|
|
84
144
|
].includes(v.packageManager) && (v.buildId === void 0 || typeof v.buildId === "string");
|
|
85
145
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (typeof value !== "object" || value === null) return false;
|
|
89
|
-
const v = value;
|
|
90
|
-
if (v.version !== "1") return false;
|
|
91
|
-
if (typeof v.links !== "object" || v.links === null) return false;
|
|
92
|
-
const links = v.links;
|
|
93
|
-
for (const entry of Object.values(links)) if (!isLinkEntry(entry)) return false;
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
/** Check if a value is a valid ConsumersRegistry */
|
|
97
|
-
function isConsumersRegistry(value) {
|
|
98
|
-
if (typeof value !== "object" || value === null) return false;
|
|
146
|
+
function parseConsumerState(value) {
|
|
147
|
+
if (typeof value !== "object" || value === null) return null;
|
|
99
148
|
const v = value;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
149
|
+
if (v.version !== "1") return null;
|
|
150
|
+
if (typeof v.links !== "object" || v.links === null) return null;
|
|
151
|
+
const links = ownRecord();
|
|
152
|
+
for (const [name, entry] of Object.entries(v.links)) {
|
|
153
|
+
if (!isLinkEntry(entry)) return null;
|
|
154
|
+
links[name] = entry;
|
|
103
155
|
}
|
|
104
|
-
return
|
|
156
|
+
return {
|
|
157
|
+
...v,
|
|
158
|
+
links
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function parseConsumersRegistry(value) {
|
|
162
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
163
|
+
const registry = ownRecord();
|
|
164
|
+
for (const [name, consumers] of Object.entries(value)) {
|
|
165
|
+
if (!Array.isArray(consumers) || !consumers.every((item) => typeof item === "string")) return null;
|
|
166
|
+
registry[name] = consumers;
|
|
167
|
+
}
|
|
168
|
+
return registry;
|
|
105
169
|
}
|
|
106
170
|
// src/utils/paths.ts
|
|
107
171
|
function assertInside(root, target, label) {
|
|
@@ -219,49 +283,27 @@ function getXXHash() {
|
|
|
219
283
|
const STREAM_THRESHOLD = 1048576;
|
|
220
284
|
/** Concurrency limit for parallel file reads in computeContentHash */
|
|
221
285
|
const limit = pLimit(Math.max(availableParallelism(), 8));
|
|
222
|
-
const _contentCache = /* @__PURE__ */ new Map();
|
|
223
286
|
/**
|
|
224
287
|
* Compute a SHA-256 content hash for a list of files.
|
|
225
288
|
* The hash is deterministic: sorted by relative path, each entry is `path\0content`.
|
|
226
289
|
* Reads files in parallel (up to CPU count concurrent) then feeds into hash in sorted order.
|
|
227
|
-
*
|
|
228
|
-
* In watch mode, unchanged files are served from an in-memory cache (validated
|
|
229
|
-
* by mtime + size) so only modified files trigger actual disk reads.
|
|
230
290
|
*/
|
|
231
291
|
async function computeContentHash(files, baseDir, contentOverrides = /* @__PURE__ */ new Map()) {
|
|
232
292
|
const fileByRel = new Map(files.map((file) => [normalizePath(relative(baseDir, file)), file]));
|
|
233
293
|
for (const rel of contentOverrides.keys()) if (!fileByRel.has(rel)) fileByRel.set(rel, join(baseDir, rel));
|
|
234
294
|
const sorted = [...fileByRel.entries()].sort(([relA], [relB]) => relA.localeCompare(relB));
|
|
235
|
-
const currentFiles = new Set(fileByRel.values());
|
|
236
|
-
let cacheHits = 0;
|
|
237
295
|
const contents = await Promise.all(sorted.map(([rel, file]) => limit(async () => {
|
|
238
296
|
const override = contentOverrides.get(rel);
|
|
239
297
|
if (override !== void 0) return {
|
|
240
298
|
rel,
|
|
241
299
|
content: Buffer.isBuffer(override) ? override : Buffer.from(override)
|
|
242
300
|
};
|
|
243
|
-
const s = await stat(file);
|
|
244
|
-
const cached = _contentCache.get(file);
|
|
245
|
-
if (cached && cached.mtimeMs === s.mtimeMs && cached.size === s.size) {
|
|
246
|
-
cacheHits++;
|
|
247
|
-
return {
|
|
248
|
-
rel,
|
|
249
|
-
content: cached.content
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
const content = await readFile(file);
|
|
253
|
-
_contentCache.set(file, {
|
|
254
|
-
mtimeMs: s.mtimeMs,
|
|
255
|
-
size: s.size,
|
|
256
|
-
content
|
|
257
|
-
});
|
|
258
301
|
return {
|
|
259
302
|
rel,
|
|
260
|
-
content
|
|
303
|
+
content: await readFile(file)
|
|
261
304
|
};
|
|
262
305
|
})));
|
|
263
|
-
|
|
264
|
-
`${sorted.length}${cacheHits}`;
|
|
306
|
+
`${sorted.length}`;
|
|
265
307
|
const hash = createHash("sha256");
|
|
266
308
|
const lenBuf = Buffer.alloc(4);
|
|
267
309
|
for (const { rel, content } of contents) {
|
|
@@ -404,10 +446,9 @@ function volumeRoot(filePath) {
|
|
|
404
446
|
* for reflink support. If it fails, caches the result and all subsequent
|
|
405
447
|
* copies on that volume go straight to a plain copy — no wasted syscalls.
|
|
406
448
|
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
* breaking change detection.
|
|
449
|
+
* Writes to a temp sibling and renames it over `dest`, so `dest` always gets a
|
|
450
|
+
* new inode. Package managers (pnpm, Bun) hardlink installed files to a global
|
|
451
|
+
* store; overwriting in place would change every project sharing that inode.
|
|
411
452
|
*/
|
|
412
453
|
async function copyWithCoW(src, dest, options) {
|
|
413
454
|
if (isDryRun()) {
|
|
@@ -420,7 +461,52 @@ async function copyWithCoW(src, dest, options) {
|
|
|
420
461
|
return;
|
|
421
462
|
}
|
|
422
463
|
if (options?.ensureParent !== false) await mkdir(dirname(dest), { recursive: true });
|
|
423
|
-
const
|
|
464
|
+
const tmp = `${dest}${COPY_TEMP_MARKER}${process.pid}-${randomUUID()}`;
|
|
465
|
+
try {
|
|
466
|
+
await copyToFreshFile(src, tmp, volumeRoot(dest));
|
|
467
|
+
await renameOverLockedTarget(tmp, dest);
|
|
468
|
+
} catch (err) {
|
|
469
|
+
await rm(tmp, { force: true });
|
|
470
|
+
throw err;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
const COPY_TEMP_MARKER = ".knarr-tmp-";
|
|
474
|
+
const COPY_TEMP_PATTERN = /\.knarr-tmp-(\d+)-[0-9a-f-]{36}$/;
|
|
475
|
+
function isInFlightCopyTemp(path) {
|
|
476
|
+
const pid = COPY_TEMP_PATTERN.exec(path)?.[1];
|
|
477
|
+
if (pid === void 0) return false;
|
|
478
|
+
try {
|
|
479
|
+
process.kill(Number(pid), 0);
|
|
480
|
+
return true;
|
|
481
|
+
} catch (err) {
|
|
482
|
+
return isNodeError(err) && err.code === "EPERM";
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
const RENAME_RETRY_DELAYS_MS = [
|
|
486
|
+
10,
|
|
487
|
+
20,
|
|
488
|
+
40,
|
|
489
|
+
80,
|
|
490
|
+
160,
|
|
491
|
+
300,
|
|
492
|
+
400
|
|
493
|
+
];
|
|
494
|
+
const WINDOWS_LOCK_CODES = /* @__PURE__ */ new Set([
|
|
495
|
+
"EPERM",
|
|
496
|
+
"EACCES",
|
|
497
|
+
"EBUSY"
|
|
498
|
+
]);
|
|
499
|
+
async function renameOverLockedTarget(from, to) {
|
|
500
|
+
for (const delay of RENAME_RETRY_DELAYS_MS) try {
|
|
501
|
+
await rename(from, to);
|
|
502
|
+
return;
|
|
503
|
+
} catch (err) {
|
|
504
|
+
if (process.platform !== "win32" || !isNodeError(err) || !WINDOWS_LOCK_CODES.has(err.code ?? "")) throw err;
|
|
505
|
+
await setTimeout(delay);
|
|
506
|
+
}
|
|
507
|
+
await rename(from, to);
|
|
508
|
+
}
|
|
509
|
+
async function copyToFreshFile(src, dest, root) {
|
|
424
510
|
const supportsReflink = reflinkSupported.get(root);
|
|
425
511
|
if (supportsReflink === false) {
|
|
426
512
|
await copyFile(src, dest);
|
|
@@ -504,19 +590,11 @@ async function incrementalCopy(srcDir, destDir, options = {}) {
|
|
|
504
590
|
const rel = relative(srcDir, srcFile);
|
|
505
591
|
const destFile = join(destDir, rel);
|
|
506
592
|
let needsCopy = true;
|
|
507
|
-
let srcTimes = null;
|
|
508
593
|
if (options.force) `${rel}`;
|
|
509
594
|
else try {
|
|
510
595
|
const [srcStat, destStat] = await Promise.all([stat(srcFile), stat(destFile)]);
|
|
511
|
-
srcTimes = {
|
|
512
|
-
atime: srcStat.atime,
|
|
513
|
-
mtime: srcStat.mtime
|
|
514
|
-
};
|
|
515
596
|
if (srcStat.size !== destStat.size) `${rel}${srcStat.size}${destStat.size}`;
|
|
516
|
-
else
|
|
517
|
-
needsCopy = false;
|
|
518
|
-
`${rel}`;
|
|
519
|
-
} else {
|
|
597
|
+
else {
|
|
520
598
|
const [srcHash, destHash] = await Promise.all([hashFile(srcFile, srcStat.size), hashFile(destFile, destStat.size)]);
|
|
521
599
|
if (srcHash === destHash) {
|
|
522
600
|
needsCopy = false;
|
|
@@ -530,15 +608,6 @@ async function incrementalCopy(srcDir, destDir, options = {}) {
|
|
|
530
608
|
if (needsCopy) {
|
|
531
609
|
await removeDestinationConflicts(destDir, rel);
|
|
532
610
|
await copyWithCoW(srcFile, destFile);
|
|
533
|
-
if (isDryRun()) return "copied";
|
|
534
|
-
if (!srcTimes) {
|
|
535
|
-
const s = await stat(srcFile);
|
|
536
|
-
srcTimes = {
|
|
537
|
-
atime: s.atime,
|
|
538
|
-
mtime: s.mtime
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
await utimes(destFile, srcTimes.atime, srcTimes.mtime);
|
|
542
611
|
return "copied";
|
|
543
612
|
}
|
|
544
613
|
return "skipped";
|
|
@@ -546,7 +615,7 @@ async function incrementalCopy(srcDir, destDir, options = {}) {
|
|
|
546
615
|
for (const r of results) if (r === "copied") copied++;
|
|
547
616
|
else skipped++;
|
|
548
617
|
const srcRelPaths = new Set(srcFiles.map((f) => relative(srcDir, f)));
|
|
549
|
-
const filesToRemove = destFiles.filter((f) => !srcRelPaths.has(relative(destDir, f)));
|
|
618
|
+
const filesToRemove = destFiles.filter((f) => !srcRelPaths.has(relative(destDir, f)) && !isInFlightCopyTemp(f));
|
|
550
619
|
await Promise.all(filesToRemove.map((destFile) => ioLimit(async () => {
|
|
551
620
|
`${relative(destDir, destFile)}`;
|
|
552
621
|
if (isDryRun()) recordMutation({
|
|
@@ -655,9 +724,14 @@ async function atomicWriteFile(filePath, data) {
|
|
|
655
724
|
});
|
|
656
725
|
return;
|
|
657
726
|
}
|
|
658
|
-
const tmpPath = filePath
|
|
659
|
-
|
|
660
|
-
|
|
727
|
+
const tmpPath = `${filePath}.tmp-${process.pid}-${randomUUID()}`;
|
|
728
|
+
try {
|
|
729
|
+
await writeFile(tmpPath, data);
|
|
730
|
+
await rename(tmpPath, filePath);
|
|
731
|
+
} catch (err) {
|
|
732
|
+
await rm(tmpPath, { force: true });
|
|
733
|
+
throw err;
|
|
734
|
+
}
|
|
661
735
|
}
|
|
662
736
|
/** Copy an entire directory recursively using native fs.cp */
|
|
663
737
|
async function copyDir(src, dest) {
|
|
@@ -680,4 +754,4 @@ async function copyDir(src, dest) {
|
|
|
680
754
|
await symlink(target, dest, "junction");
|
|
681
755
|
}
|
|
682
756
|
}
|
|
683
|
-
export {
|
|
757
|
+
export { getStoreMetaPath as A, isJsonObject as B, getConsumerKnarrDir as C, getNodeModulesPackagePath as D, getHistoryEntryPath as E, parseConsumerState as F, readJsonObject as G, ownRecord as H, parseConsumersRegistry as I, pLimit as J, stringField as K, validatePackageIdentity as L, getStorePath as M, normalizePath as N, getStoreEntryPath as O, isKnarrMeta as P, validatePackageName as R, getConsumerBackupPath as S, getConsumersPath as T, parseJson as U, objectField as V, parseJsonObject as W, __exportAll as Y, computeContentHash as _, ensurePrivateDir as a, verbose as b, incrementalCopy as c, removeDir as d, getMutations as f, resetMutations as g, recordMutation as h, ensureDir as i, getStorePackagePath as j, getStoreHistoryPath as k, isNodeError as l, printDryRunReport as m, copyDir as n, exists as o, markDryRunJsonReportPrinted as p, stringRecordField as q, copyWithCoW as r, fs_exports as s, atomicWriteFile as t, moveDir as u, isDryRun as v, getConsumerStatePath as w, decodePackageName as x, isJsonOutput as y, asPackageJson as z };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{createRequire as __cr}from"node:module";globalThis.require=__cr(import.meta.url);
|
|
3
|
+
import"./rolldown-runtime-BZbIAPMk.mjs";import{C as e,O as t,S as n,b as r,c as i,d as a,f as o,o as s,t as c}from"./fs-CPnWm9CR.mjs";import{i as l}from"./logger-9C6B9Na8.mjs";import{o as u}from"./json-DbSkpxtr.mjs";import{readFile as d,readdir as f}from"node:fs/promises";import{join as p}from"node:path";async function readMetaFile(e){let n=u(await d(e,`utf-8`));if(!t(n))throw Error(`Invalid build metadata: ${e}`);return n}async function captureHistory(t,n,u,d){let f=p(u,`.knarr-meta.json`),m;try{m=await readMetaFile(f)}catch{l(`[history] Could not read meta from ${f}, skipping history capture`);return}let h=m.buildId;if(!h){l(`[history] No buildId in meta, skipping history capture`);return}let g=e(t,n),_=r(t,n,h);if(await i(_)){l(`[history] Build ${h} already in history, skipping`);return}await s(g);let v=_+`.tmp-${process.pid}`;try{await s(v);let e=p(u,`package`);await i(e)&&await a(e,p(v,`package`)),await c(p(v,`.knarr-meta.json`),JSON.stringify(m,null,2)),await a(v,_),l(`[history] Captured build ${h} to history`)}catch(e){l(`[history] Failed to capture history: ${e instanceof Error?e.message:String(e)}`),await o(v)}await pruneHistory(t,n,d??3)}async function listHistory(t,n){let r=e(t,n);if(!await i(r))return[];let a;try{a=await f(r)}catch{return[]}let o=[];for(let e of a){let t=p(r,e),n=p(t,`.knarr-meta.json`);try{let r=await readMetaFile(n);o.push({buildId:r.buildId??e,contentHash:r.contentHash,publishedAt:r.publishedAt,sourcePath:r.sourcePath,packageDir:p(t,`package`)})}catch{}}return o.sort((e,t)=>new Date(t.publishedAt).getTime()-new Date(e.publishedAt).getTime()),o}async function getHistoryEntry(e,t,n){let i=r(e,t,n),a=p(i,`.knarr-meta.json`);try{let e=await readMetaFile(a);return{buildId:e.buildId??n,contentHash:e.contentHash,publishedAt:e.publishedAt,sourcePath:e.sourcePath,packageDir:p(i,`package`)}}catch{return null}}async function restoreHistoryEntry(e,t,u,f){let m=await getHistoryEntry(e,t,u);if(!m)return null;let h=n(e,t),g=r(e,t,u),_=p(g,`package`),v=p(g,`.knarr-meta.json`),y=await d(v,`utf-8`),b=p(h,`package`),x=p(h,`.knarr-meta.json`);if(!await i(_))throw Error(`History entry ${u} is missing its package directory`);let S=await d(x,`utf-8`).catch(()=>null),C=h+`.restore-old-${process.pid}-${Date.now()}`,w=p(C,`package`),T=!1,E=!1;try{if((await i(b)||S)&&(await s(C),await i(b)&&await a(b,w),S&&await c(p(C,`.knarr-meta.json`),S),T=!0),await a(_,b),E=!0,await c(x,y),await o(g),T)try{await captureHistory(e,t,C,f)}finally{await o(C)}}catch(e){throw E&&await i(b)?(await s(g),await a(b,_)):T&&await i(b)&&await o(b),T&&await i(w)&&await a(w,b),S&&await c(x,S),await o(C),e}return l(`[history] Restored build ${u} as current`),m}async function pruneHistory(e,t,n){if(n<0)return 0;let i=await listHistory(e,t);if(i.length<=n)return 0;let a=i.slice(n),s=0;for(let n of a){let i=r(e,t,n.buildId);try{await o(i),s++,l(`[history] Pruned old build ${n.buildId}`)}catch{}}return s}function resolveHistoryLimit(e){return e??3}export{resolveHistoryLimit as a,pruneHistory as i,getHistoryEntry as n,restoreHistoryEntry as o,listHistory as r,captureHistory as t};
|
package/dist/index.d.ts
CHANGED
|
@@ -55,18 +55,27 @@ interface LinkEntry {
|
|
|
55
55
|
/** 8-char hex ID. Missing in pre-buildId state files. */
|
|
56
56
|
buildId?: string;
|
|
57
57
|
}
|
|
58
|
+
declare const nullPrototype: unique symbol;
|
|
59
|
+
/**
|
|
60
|
+
* A map keyed by untrusted strings (package names, catalog names). It has no
|
|
61
|
+
* prototype, so keys such as `constructor` or `__proto__` are plain data.
|
|
62
|
+
* A `{}` literal does not type-check as one; create it with `ownRecord()`
|
|
63
|
+
* from `src/utils/json.ts`.
|
|
64
|
+
*/
|
|
65
|
+
type OwnRecord<V> = {
|
|
66
|
+
[key: string]: V;
|
|
67
|
+
} & {
|
|
68
|
+
readonly [nullPrototype]: true;
|
|
69
|
+
};
|
|
58
70
|
/** Consumer project state file (.knarr/state.json) */
|
|
59
71
|
interface ConsumerState {
|
|
60
72
|
version: "1";
|
|
61
73
|
packageManager?: PackageManager;
|
|
62
74
|
role?: "consumer" | "library";
|
|
63
|
-
links:
|
|
64
|
-
}
|
|
65
|
-
/** Global consumers registry (~/.knarr/consumers.json) */
|
|
66
|
-
interface ConsumersRegistry {
|
|
67
|
-
/** Maps package name → array of consumer project paths */
|
|
68
|
-
[packageName: string]: string[];
|
|
75
|
+
links: OwnRecord<LinkEntry>;
|
|
69
76
|
}
|
|
77
|
+
/** Global consumers registry (~/.knarr/consumers.json): package name → consumer project paths */
|
|
78
|
+
type ConsumersRegistry = OwnRecord<string[]>;
|
|
70
79
|
type PackageManager = "npm" | "pnpm" | "yarn" | "bun";
|
|
71
80
|
/** A historical build stored in the store's history directory */
|
|
72
81
|
interface HistoryEntry {
|
|
@@ -203,13 +212,7 @@ export declare function getConsumers(packageName: string): Promise<string[]>;
|
|
|
203
212
|
* Clean stale consumers — remove registrations for directories that no longer exist.
|
|
204
213
|
* Returns the number of stale entries removed.
|
|
205
214
|
*/
|
|
206
|
-
export declare function cleanStaleConsumers(
|
|
207
|
-
removedConsumers: number;
|
|
208
|
-
removedPackages: number;
|
|
209
|
-
removedMissingLinks: number;
|
|
210
|
-
skippedUnreliableConsumers: number;
|
|
211
|
-
}>;
|
|
212
|
-
export declare function cleanStaleConsumers(options: {
|
|
215
|
+
export declare function cleanStaleConsumers(options?: {
|
|
213
216
|
removeMissingLinks?: boolean;
|
|
214
217
|
}): Promise<{
|
|
215
218
|
removedConsumers: number;
|
|
@@ -474,4 +477,4 @@ export declare function isComplexConfig(content: string): {
|
|
|
474
477
|
complex: boolean;
|
|
475
478
|
reason?: string;
|
|
476
479
|
};
|
|
477
|
-
export type { ConsumerState, ConsumersRegistry, DryRunMutation, HistoryEntry, InjectOptions, InjectResult, KnarrConfig, KnarrMeta, LinkEntry, MutationType, PackageJson, PackageManager, PackageManagerDetection, PackageManagerDetectionSource, PreflightIssue, PreflightSeverity, PublishOptions, PublishResult, PushOptions, StoreEntry, WatchOptions, WorkspaceGraph, WorkspacePackage };
|
|
480
|
+
export type { ConsumerState, ConsumersRegistry, DryRunMutation, HistoryEntry, InjectOptions, InjectResult, KnarrConfig, KnarrMeta, LinkEntry, MutationType, OwnRecord, PackageJson, PackageManager, PackageManagerDetection, PackageManagerDetectionSource, PreflightIssue, PreflightSeverity, PublishOptions, PublishResult, PushOptions, StoreEntry, WatchOptions, WorkspaceGraph, WorkspacePackage };
|