screw-up 1.30.0 → 1.32.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/dist/index.cjs +553 -125
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +34 -10
- package/dist/index.mjs.map +1 -1
- package/dist/main.cjs +539 -135
- package/dist/main.cjs.map +1 -1
- package/dist/main.mjs +6 -6
- package/dist/{metadata-file-CpFkBJPS.js → metadata-file-D79yMa_A.js} +520 -119
- package/dist/metadata-file-D79yMa_A.js.map +1 -0
- package/dist/{packageMetadata-Lj9bVuVM.cjs → packageMetadata-6po5LHyH.cjs} +5 -5
- package/dist/{packageMetadata-Lj9bVuVM.cjs.map → packageMetadata-6po5LHyH.cjs.map} +1 -1
- package/dist/{packageMetadata-zaiRRUve.cjs → packageMetadata-Cwh4Fqmw.cjs} +3 -3
- package/dist/{packageMetadata-YWwXZbaj.js → packageMetadata-Sm2NpI2b.js} +6 -6
- package/dist/{packageMetadata-YWwXZbaj.js.map → packageMetadata-Sm2NpI2b.js.map} +1 -1
- package/dist/src/analyzer.d.ts +2 -2
- package/dist/src/analyzer.d.ts.map +1 -1
- package/dist/src/cli-internal.d.ts +2 -2
- package/dist/src/cli.d.ts +2 -2
- package/dist/src/declaration-import-fix.d.ts +2 -2
- package/dist/src/default-import-fix.d.ts +2 -2
- package/dist/src/fast-tags.d.ts +2 -2
- package/dist/src/fast-tags.d.ts.map +1 -1
- package/dist/src/generated/packageMetadata.d.ts +4 -4
- package/dist/src/git-operations.d.ts +2 -2
- package/dist/src/git-operations.d.ts.map +1 -1
- package/dist/src/git-ref-utils.d.ts +39 -0
- package/dist/src/git-ref-utils.d.ts.map +1 -0
- package/dist/src/index.d.ts +2 -2
- package/dist/src/internal.d.ts +2 -2
- package/dist/src/main.d.ts +2 -2
- package/dist/src/metadata-file.d.ts +2 -2
- package/dist/src/text-edits.d.ts +2 -2
- package/dist/src/types.d.ts +2 -2
- package/dist/src/vite-plugin.d.ts +2 -2
- package/package.json +7 -7
- package/dist/metadata-file-CpFkBJPS.js.map +0 -1
package/dist/main.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/*!
|
|
3
3
|
* name: screw-up
|
|
4
|
-
* version: 1.
|
|
4
|
+
* version: 1.32.0
|
|
5
5
|
* description: Simply package metadata inserter on Vite plugin
|
|
6
6
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
7
7
|
* license: MIT
|
|
8
8
|
* repository.url: https://github.com/kekyo/screw-up.git
|
|
9
|
-
* git.commit.hash:
|
|
9
|
+
* git.commit.hash: 8a0078c34fa41bdb0cbf2d23837ac5e3217cbf53
|
|
10
10
|
*/
|
|
11
11
|
//#region \0rolldown/runtime.js
|
|
12
12
|
var __create = Object.create;
|
|
@@ -31,7 +31,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
31
31
|
enumerable: true
|
|
32
32
|
}) : target, mod));
|
|
33
33
|
//#endregion
|
|
34
|
-
const require_packageMetadata = require("./packageMetadata-
|
|
34
|
+
const require_packageMetadata = require("./packageMetadata-6po5LHyH.cjs");
|
|
35
35
|
let path = require("path");
|
|
36
36
|
let fs = require("fs");
|
|
37
37
|
let fs_promises = require("fs/promises");
|
|
@@ -44,6 +44,7 @@ let stream_promises = require("stream/promises");
|
|
|
44
44
|
let glob = require("glob");
|
|
45
45
|
let isomorphic_git = require("isomorphic-git");
|
|
46
46
|
isomorphic_git = __toESM(isomorphic_git);
|
|
47
|
+
let crypto = require("crypto");
|
|
47
48
|
//#region node_modules/tar-vern/dist/index.js
|
|
48
49
|
/*!
|
|
49
50
|
* name: tar-vern
|
|
@@ -62,7 +63,7 @@ var getUName = (candidateName, candidateId, reflectStat) => {
|
|
|
62
63
|
var getBuffer = (data) => {
|
|
63
64
|
return Buffer.isBuffer(data) ? data : Buffer.from(data, "utf8");
|
|
64
65
|
};
|
|
65
|
-
var createDirectoryItem = async (path$
|
|
66
|
+
var createDirectoryItem = async (path$8, reflectStat, options, signal) => {
|
|
66
67
|
const rs = reflectStat !== null && reflectStat !== void 0 ? reflectStat : "none";
|
|
67
68
|
if (rs !== "none" && (options === null || options === void 0 ? void 0 : options.directoryPath)) {
|
|
68
69
|
var _options$mode, _options$uid, _options$gid, _options$date;
|
|
@@ -74,7 +75,7 @@ var createDirectoryItem = async (path$3, reflectStat, options, signal) => {
|
|
|
74
75
|
const date = (_options$date = options === null || options === void 0 ? void 0 : options.date) !== null && _options$date !== void 0 ? _options$date : stats.mtime;
|
|
75
76
|
return {
|
|
76
77
|
kind: "directory",
|
|
77
|
-
path: path$
|
|
78
|
+
path: path$8,
|
|
78
79
|
mode,
|
|
79
80
|
uname: getUName(options === null || options === void 0 ? void 0 : options.uname, stats.uid, rs),
|
|
80
81
|
gname: getUName(options === null || options === void 0 ? void 0 : options.gname, stats.gid, rs),
|
|
@@ -90,7 +91,7 @@ var createDirectoryItem = async (path$3, reflectStat, options, signal) => {
|
|
|
90
91
|
const date = (_options$date2 = options === null || options === void 0 ? void 0 : options.date) !== null && _options$date2 !== void 0 ? _options$date2 : /* @__PURE__ */ new Date();
|
|
91
92
|
return {
|
|
92
93
|
kind: "directory",
|
|
93
|
-
path: path$
|
|
94
|
+
path: path$8,
|
|
94
95
|
mode,
|
|
95
96
|
uname: getUName(options === null || options === void 0 ? void 0 : options.uname, void 0, rs),
|
|
96
97
|
gname: getUName(options === null || options === void 0 ? void 0 : options.gname, void 0, rs),
|
|
@@ -100,7 +101,7 @@ var createDirectoryItem = async (path$3, reflectStat, options, signal) => {
|
|
|
100
101
|
};
|
|
101
102
|
}
|
|
102
103
|
};
|
|
103
|
-
var createReadableFileItem = async (path$
|
|
104
|
+
var createReadableFileItem = async (path$10, readable, options, signal) => {
|
|
104
105
|
var _options$mode4, _options$uid4, _options$gid4, _options$date4, _options$uname2, _options$gname2;
|
|
105
106
|
const mode = (_options$mode4 = options === null || options === void 0 ? void 0 : options.mode) !== null && _options$mode4 !== void 0 ? _options$mode4 : 420;
|
|
106
107
|
const uid = (_options$uid4 = options === null || options === void 0 ? void 0 : options.uid) !== null && _options$uid4 !== void 0 ? _options$uid4 : 0;
|
|
@@ -120,7 +121,7 @@ var createReadableFileItem = async (path$5, readable, options, signal) => {
|
|
|
120
121
|
}
|
|
121
122
|
return {
|
|
122
123
|
kind: "file",
|
|
123
|
-
path: path$
|
|
124
|
+
path: path$10,
|
|
124
125
|
mode,
|
|
125
126
|
uname,
|
|
126
127
|
gname,
|
|
@@ -135,7 +136,7 @@ var createReadableFileItem = async (path$5, readable, options, signal) => {
|
|
|
135
136
|
};
|
|
136
137
|
} else return {
|
|
137
138
|
kind: "file",
|
|
138
|
-
path: path$
|
|
139
|
+
path: path$10,
|
|
139
140
|
mode,
|
|
140
141
|
uname,
|
|
141
142
|
gname,
|
|
@@ -149,7 +150,7 @@ var createReadableFileItem = async (path$5, readable, options, signal) => {
|
|
|
149
150
|
}
|
|
150
151
|
};
|
|
151
152
|
};
|
|
152
|
-
var createReadFileItem = async (path$
|
|
153
|
+
var createReadFileItem = async (path$12, filePath, reflectStat, options, signal) => {
|
|
153
154
|
var _options$mode6, _options$uid6, _options$gid6, _options$date6;
|
|
154
155
|
const rs = reflectStat !== null && reflectStat !== void 0 ? reflectStat : "exceptName";
|
|
155
156
|
signal === null || signal === void 0 || signal.throwIfAborted();
|
|
@@ -161,7 +162,7 @@ var createReadFileItem = async (path$7, filePath, reflectStat, options, signal)
|
|
|
161
162
|
const date = (_options$date6 = options === null || options === void 0 ? void 0 : options.date) !== null && _options$date6 !== void 0 ? _options$date6 : rs !== "none" ? stats.mtime : void 0;
|
|
162
163
|
const uname = getUName(options === null || options === void 0 ? void 0 : options.uname, stats.uid, rs);
|
|
163
164
|
const gname = getUName(options === null || options === void 0 ? void 0 : options.gname, stats.gid, rs);
|
|
164
|
-
return await createReadableFileItem(path$
|
|
165
|
+
return await createReadableFileItem(path$12, reader, {
|
|
165
166
|
length: stats.size,
|
|
166
167
|
mode,
|
|
167
168
|
uname,
|
|
@@ -171,8 +172,8 @@ var createReadFileItem = async (path$7, filePath, reflectStat, options, signal)
|
|
|
171
172
|
date
|
|
172
173
|
}, signal);
|
|
173
174
|
};
|
|
174
|
-
var storeReaderToFile = async (reader, path$
|
|
175
|
-
await (0, stream_promises.pipeline)(reader, (0, fs.createWriteStream)(path$
|
|
175
|
+
var storeReaderToFile = async (reader, path$13, signal) => {
|
|
176
|
+
await (0, stream_promises.pipeline)(reader, (0, fs.createWriteStream)(path$13, { signal }), { signal });
|
|
176
177
|
};
|
|
177
178
|
var getAllFilesInDirectory = async (baseDir, signal) => {
|
|
178
179
|
const collectFiles = async (currentDir, relativePath) => {
|
|
@@ -254,13 +255,13 @@ var truncateUtf8Safe = (str, maxBytes) => {
|
|
|
254
255
|
}
|
|
255
256
|
return str.slice(0, i);
|
|
256
257
|
};
|
|
257
|
-
var splitPath = (path$
|
|
258
|
+
var splitPath = (path$14) => {
|
|
258
259
|
var _parts$pop;
|
|
259
|
-
if (utf8ByteLength(path$
|
|
260
|
+
if (utf8ByteLength(path$14) <= MAX_NAME) return {
|
|
260
261
|
prefix: "",
|
|
261
|
-
name: path$
|
|
262
|
+
name: path$14
|
|
262
263
|
};
|
|
263
|
-
const parts = path$
|
|
264
|
+
const parts = path$14.split("/");
|
|
264
265
|
let name = (_parts$pop = parts.pop()) !== null && _parts$pop !== void 0 ? _parts$pop : "";
|
|
265
266
|
let prefix = parts.join("/");
|
|
266
267
|
if (utf8ByteLength(name) > MAX_NAME) name = truncateUtf8Safe(name, MAX_NAME);
|
|
@@ -280,9 +281,9 @@ var getPaddedBytes = (buffer) => {
|
|
|
280
281
|
else return Buffer.concat([buffer, Buffer.alloc(512 - extra, 0)]);
|
|
281
282
|
};
|
|
282
283
|
var terminatorBytes = Buffer.alloc(1024, 0);
|
|
283
|
-
var createTarHeader = (type, path$
|
|
284
|
+
var createTarHeader = (type, path$15, size, mode, uname, gname, uid, gid, date) => {
|
|
284
285
|
const buffer = Buffer.alloc(512, 0);
|
|
285
|
-
const { name, prefix } = splitPath(path$
|
|
286
|
+
const { name, prefix } = splitPath(path$15);
|
|
286
287
|
buffer.write(name, 0, 100, "utf8");
|
|
287
288
|
getOctalBytes(mode & 4095, 8).copy(buffer, 100);
|
|
288
289
|
getOctalBytes(uid, 8).copy(buffer, 108);
|
|
@@ -425,11 +426,11 @@ var parseTarHeader = (buffer) => {
|
|
|
425
426
|
for (let i = 0; i < 512; i++) if (i >= 148 && i < 156) calculatedSum += 32;
|
|
426
427
|
else calculatedSum += buffer[i];
|
|
427
428
|
if (calculatedSum !== checksum) throw new Error(`Invalid checksum: expected ${checksum}, got ${calculatedSum}`);
|
|
428
|
-
let path$
|
|
429
|
-
if (path$
|
|
429
|
+
let path$16 = prefix ? `${prefix}/${name}` : name;
|
|
430
|
+
if (path$16.endsWith("/")) path$16 = path$16.slice(0, -1);
|
|
430
431
|
return {
|
|
431
432
|
kind: typeflag === "5" ? "directory" : "file",
|
|
432
|
-
path: path$
|
|
433
|
+
path: path$16,
|
|
433
434
|
size,
|
|
434
435
|
mode,
|
|
435
436
|
uid,
|
|
@@ -2404,6 +2405,380 @@ var resolveRawPackageJsonObject = async (projectRoot, fetchGitMetadata, alwaysOv
|
|
|
2404
2405
|
};
|
|
2405
2406
|
};
|
|
2406
2407
|
//#endregion
|
|
2408
|
+
//#region src/git-ref-utils.ts
|
|
2409
|
+
var PACK_TRAILER_SIZE = 20;
|
|
2410
|
+
var LOOSE_TAG_RESOLUTION_CONCURRENCY = 4;
|
|
2411
|
+
var PACKED_OBJECT_TYPE_BY_CODE = new Map([
|
|
2412
|
+
[1, "commit"],
|
|
2413
|
+
[2, "tree"],
|
|
2414
|
+
[3, "blob"],
|
|
2415
|
+
[4, "tag"],
|
|
2416
|
+
[6, "ofs-delta"],
|
|
2417
|
+
[7, "ref-delta"]
|
|
2418
|
+
]);
|
|
2419
|
+
/**
|
|
2420
|
+
* Resolve the actual Git directory for repositories, worktrees, and submodules.
|
|
2421
|
+
* @param repoPath - Repository path
|
|
2422
|
+
* @returns The resolved Git directory path
|
|
2423
|
+
*/
|
|
2424
|
+
var getActualGitDir = async (repoPath) => {
|
|
2425
|
+
const gitDir = (0, path.join)(repoPath, ".git");
|
|
2426
|
+
const gitStat = await (0, fs_promises.stat)(gitDir).catch(() => null);
|
|
2427
|
+
if (!(gitStat === null || gitStat === void 0 ? void 0 : gitStat.isFile())) return gitDir;
|
|
2428
|
+
const match = (await (0, fs_promises.readFile)(gitDir, "utf-8")).match(/^gitdir:\s*(.+)$/m);
|
|
2429
|
+
if (!match) return gitDir;
|
|
2430
|
+
return (0, path.isAbsolute)(match[1]) ? match[1] : (0, path.join)(repoPath, match[1]);
|
|
2431
|
+
};
|
|
2432
|
+
var readFixedRange = async (fileHandle, offset, length) => {
|
|
2433
|
+
const buffer = Buffer.alloc(length);
|
|
2434
|
+
const { bytesRead } = await fileHandle.read(buffer, 0, length, offset);
|
|
2435
|
+
if (bytesRead !== length) throw new Error(`Unexpected EOF while reading pack entry at offset ${offset} (expected ${length}, got ${bytesRead})`);
|
|
2436
|
+
return buffer;
|
|
2437
|
+
};
|
|
2438
|
+
var readLooseObject = async (gitDir, oid) => {
|
|
2439
|
+
try {
|
|
2440
|
+
const wrapped = (0, zlib.inflateSync)(await (0, fs_promises.readFile)((0, path.join)(gitDir, "objects", oid.slice(0, 2), oid.slice(2))));
|
|
2441
|
+
const headerEnd = wrapped.indexOf(0);
|
|
2442
|
+
if (headerEnd < 0) throw new Error(`Invalid loose object header: ${oid}`);
|
|
2443
|
+
const header = wrapped.subarray(0, headerEnd).toString("utf-8");
|
|
2444
|
+
const match = header.match(/^(commit|tree|blob|tag) (\d+)$/);
|
|
2445
|
+
if (!match) throw new Error(`Unsupported loose object header: ${header}`);
|
|
2446
|
+
const content = wrapped.subarray(headerEnd + 1);
|
|
2447
|
+
const expectedSize = Number(match[2]);
|
|
2448
|
+
if (content.length !== expectedSize) throw new Error(`Loose object size mismatch: ${oid} (expected ${expectedSize}, got ${content.length})`);
|
|
2449
|
+
return {
|
|
2450
|
+
oid,
|
|
2451
|
+
type: match[1],
|
|
2452
|
+
content
|
|
2453
|
+
};
|
|
2454
|
+
} catch (error) {
|
|
2455
|
+
if (error.code === "ENOENT") return null;
|
|
2456
|
+
throw error;
|
|
2457
|
+
}
|
|
2458
|
+
};
|
|
2459
|
+
var readLargePackOffset = (idxBuffer, largeOffsetsStart, largeOffsetIndex) => {
|
|
2460
|
+
const offset = Number(idxBuffer.readBigUInt64BE(largeOffsetsStart + largeOffsetIndex * 8));
|
|
2461
|
+
if (!Number.isSafeInteger(offset)) throw new Error(`Pack offset exceeds safe integer range: ${offset}`);
|
|
2462
|
+
return offset;
|
|
2463
|
+
};
|
|
2464
|
+
var loadPackIndex = async (idxPath) => {
|
|
2465
|
+
const packPath = idxPath.replace(/\.idx$/, ".pack");
|
|
2466
|
+
const [idxBuffer, packStat, fileHandle] = await Promise.all([
|
|
2467
|
+
(0, fs_promises.readFile)(idxPath),
|
|
2468
|
+
(0, fs_promises.stat)(packPath),
|
|
2469
|
+
(0, fs_promises.open)(packPath, "r")
|
|
2470
|
+
]);
|
|
2471
|
+
if (idxBuffer.readUInt32BE(0) !== 4285812579) throw new Error(`Unsupported pack index signature: ${idxPath}`);
|
|
2472
|
+
if (idxBuffer.readUInt32BE(4) !== 2) throw new Error(`Unsupported pack index version: ${idxPath}`);
|
|
2473
|
+
const objectCount = idxBuffer.readUInt32BE(1028);
|
|
2474
|
+
const oidStart = 1032;
|
|
2475
|
+
const offsetStart = oidStart + objectCount * 20 + objectCount * 4;
|
|
2476
|
+
const largeOffsetStart = offsetStart + objectCount * 4;
|
|
2477
|
+
const objectByOid = /* @__PURE__ */ new Map();
|
|
2478
|
+
const objectByOffset = /* @__PURE__ */ new Map();
|
|
2479
|
+
const sortedObjects = [];
|
|
2480
|
+
const packIndex = {
|
|
2481
|
+
fileHandle,
|
|
2482
|
+
objectByOid,
|
|
2483
|
+
objectByOffset
|
|
2484
|
+
};
|
|
2485
|
+
for (let index = 0; index < objectCount; index++) {
|
|
2486
|
+
const oidOffset = oidStart + index * 20;
|
|
2487
|
+
const oid = idxBuffer.subarray(oidOffset, oidOffset + 20).toString("hex");
|
|
2488
|
+
const rawOffset = idxBuffer.readUInt32BE(offsetStart + index * 4);
|
|
2489
|
+
const offset = (rawOffset & 2147483648) === 0 ? rawOffset : readLargePackOffset(idxBuffer, largeOffsetStart, rawOffset & 2147483647);
|
|
2490
|
+
sortedObjects.push({
|
|
2491
|
+
oid,
|
|
2492
|
+
offset
|
|
2493
|
+
});
|
|
2494
|
+
}
|
|
2495
|
+
sortedObjects.sort((left, right) => left.offset - right.offset);
|
|
2496
|
+
const packEndOffset = packStat.size - PACK_TRAILER_SIZE;
|
|
2497
|
+
for (let index = 0; index < sortedObjects.length; index++) {
|
|
2498
|
+
var _sortedObjects$offset, _sortedObjects;
|
|
2499
|
+
const currentObject = sortedObjects[index];
|
|
2500
|
+
const nextOffset = (_sortedObjects$offset = (_sortedObjects = sortedObjects[index + 1]) === null || _sortedObjects === void 0 ? void 0 : _sortedObjects.offset) !== null && _sortedObjects$offset !== void 0 ? _sortedObjects$offset : packEndOffset;
|
|
2501
|
+
const location = {
|
|
2502
|
+
oid: currentObject.oid,
|
|
2503
|
+
offset: currentObject.offset,
|
|
2504
|
+
nextOffset,
|
|
2505
|
+
packIndex
|
|
2506
|
+
};
|
|
2507
|
+
objectByOid.set(currentObject.oid, location);
|
|
2508
|
+
objectByOffset.set(currentObject.offset, location);
|
|
2509
|
+
}
|
|
2510
|
+
return packIndex;
|
|
2511
|
+
};
|
|
2512
|
+
var loadPackStore = async (gitDir) => {
|
|
2513
|
+
try {
|
|
2514
|
+
const packDir = (0, path.join)(gitDir, "objects", "pack");
|
|
2515
|
+
const idxPaths = (await (0, fs_promises.readdir)(packDir)).filter((entryName) => entryName.endsWith(".idx")).map((entryName) => (0, path.join)(packDir, entryName));
|
|
2516
|
+
const packs = await Promise.all(idxPaths.map(loadPackIndex));
|
|
2517
|
+
const objectByOid = /* @__PURE__ */ new Map();
|
|
2518
|
+
for (const pack of packs) for (const [oid, location] of pack.objectByOid.entries()) objectByOid.set(oid, location);
|
|
2519
|
+
return {
|
|
2520
|
+
packs,
|
|
2521
|
+
objectByOid
|
|
2522
|
+
};
|
|
2523
|
+
} catch (error) {
|
|
2524
|
+
if (error.code === "ENOENT") return {
|
|
2525
|
+
packs: [],
|
|
2526
|
+
objectByOid: /* @__PURE__ */ new Map()
|
|
2527
|
+
};
|
|
2528
|
+
throw error;
|
|
2529
|
+
}
|
|
2530
|
+
};
|
|
2531
|
+
var decodeOfsDeltaDistance = (buffer, startOffset) => {
|
|
2532
|
+
let cursor = startOffset;
|
|
2533
|
+
let byte = buffer[cursor++];
|
|
2534
|
+
let distance = byte & 127;
|
|
2535
|
+
while (byte & 128) {
|
|
2536
|
+
byte = buffer[cursor++];
|
|
2537
|
+
distance = distance + 1 << 7 | byte & 127;
|
|
2538
|
+
}
|
|
2539
|
+
return {
|
|
2540
|
+
distance,
|
|
2541
|
+
nextOffset: cursor
|
|
2542
|
+
};
|
|
2543
|
+
};
|
|
2544
|
+
var parsePackedEntryHeader = (entryBuffer, objectOffset) => {
|
|
2545
|
+
let cursor = 0;
|
|
2546
|
+
let byte = entryBuffer[cursor++];
|
|
2547
|
+
const packedType = PACKED_OBJECT_TYPE_BY_CODE.get(byte >> 4 & 7);
|
|
2548
|
+
if (!packedType) throw new Error(`Unsupported packed object type at offset ${objectOffset}`);
|
|
2549
|
+
let declaredSize = byte & 15;
|
|
2550
|
+
let shift = 4;
|
|
2551
|
+
while (byte & 128) {
|
|
2552
|
+
byte = entryBuffer[cursor++];
|
|
2553
|
+
declaredSize |= (byte & 127) << shift;
|
|
2554
|
+
shift += 7;
|
|
2555
|
+
}
|
|
2556
|
+
let baseOffset;
|
|
2557
|
+
let baseOid;
|
|
2558
|
+
if (packedType === "ofs-delta") {
|
|
2559
|
+
const decoded = decodeOfsDeltaDistance(entryBuffer, cursor);
|
|
2560
|
+
cursor = decoded.nextOffset;
|
|
2561
|
+
baseOffset = objectOffset - decoded.distance;
|
|
2562
|
+
} else if (packedType === "ref-delta") {
|
|
2563
|
+
baseOid = entryBuffer.subarray(cursor, cursor + 20).toString("hex");
|
|
2564
|
+
cursor += 20;
|
|
2565
|
+
}
|
|
2566
|
+
return {
|
|
2567
|
+
packedType,
|
|
2568
|
+
declaredSize,
|
|
2569
|
+
headerLength: cursor,
|
|
2570
|
+
baseOffset,
|
|
2571
|
+
baseOid
|
|
2572
|
+
};
|
|
2573
|
+
};
|
|
2574
|
+
var readDeltaSize = (buffer, startOffset) => {
|
|
2575
|
+
let cursor = startOffset;
|
|
2576
|
+
let size = 0;
|
|
2577
|
+
let shift = 0;
|
|
2578
|
+
while (cursor < buffer.length) {
|
|
2579
|
+
const byte = buffer[cursor++];
|
|
2580
|
+
size |= (byte & 127) << shift;
|
|
2581
|
+
if ((byte & 128) === 0) return {
|
|
2582
|
+
size,
|
|
2583
|
+
nextOffset: cursor
|
|
2584
|
+
};
|
|
2585
|
+
shift += 7;
|
|
2586
|
+
}
|
|
2587
|
+
throw new Error("Invalid git delta size encoding");
|
|
2588
|
+
};
|
|
2589
|
+
var applyGitDelta = (baseContent, deltaContent) => {
|
|
2590
|
+
const baseSizeInfo = readDeltaSize(deltaContent, 0);
|
|
2591
|
+
if (baseSizeInfo.size !== baseContent.length) throw new Error(`Git delta base size mismatch: expected ${baseSizeInfo.size}, got ${baseContent.length}`);
|
|
2592
|
+
const targetSizeInfo = readDeltaSize(deltaContent, baseSizeInfo.nextOffset);
|
|
2593
|
+
const result = Buffer.alloc(targetSizeInfo.size);
|
|
2594
|
+
let deltaOffset = targetSizeInfo.nextOffset;
|
|
2595
|
+
let resultOffset = 0;
|
|
2596
|
+
while (deltaOffset < deltaContent.length) {
|
|
2597
|
+
const opcode = deltaContent[deltaOffset++];
|
|
2598
|
+
if ((opcode & 128) !== 0) {
|
|
2599
|
+
let copyOffset = 0;
|
|
2600
|
+
let copySize = 0;
|
|
2601
|
+
if (opcode & 1) copyOffset |= deltaContent[deltaOffset++];
|
|
2602
|
+
if (opcode & 2) copyOffset |= deltaContent[deltaOffset++] << 8;
|
|
2603
|
+
if (opcode & 4) copyOffset |= deltaContent[deltaOffset++] << 16;
|
|
2604
|
+
if (opcode & 8) copyOffset |= deltaContent[deltaOffset++] << 24;
|
|
2605
|
+
if (opcode & 16) copySize |= deltaContent[deltaOffset++];
|
|
2606
|
+
if (opcode & 32) copySize |= deltaContent[deltaOffset++] << 8;
|
|
2607
|
+
if (opcode & 64) copySize |= deltaContent[deltaOffset++] << 16;
|
|
2608
|
+
if (copySize === 0) copySize = 65536;
|
|
2609
|
+
baseContent.copy(result, resultOffset, copyOffset, copyOffset + copySize);
|
|
2610
|
+
resultOffset += copySize;
|
|
2611
|
+
continue;
|
|
2612
|
+
}
|
|
2613
|
+
if (opcode === 0) throw new Error("Invalid git delta opcode");
|
|
2614
|
+
deltaContent.copy(result, resultOffset, deltaOffset, deltaOffset + opcode);
|
|
2615
|
+
deltaOffset += opcode;
|
|
2616
|
+
resultOffset += opcode;
|
|
2617
|
+
}
|
|
2618
|
+
if (resultOffset !== result.length) throw new Error(`Git delta size mismatch: expected ${result.length}, got ${resultOffset}`);
|
|
2619
|
+
return result;
|
|
2620
|
+
};
|
|
2621
|
+
var inflatePackedObject = (compressedContent) => Buffer.from((0, zlib.inflateSync)(compressedContent));
|
|
2622
|
+
var parseTagTargetOid = (tagContent) => {
|
|
2623
|
+
const firstLineEnd = tagContent.indexOf(10);
|
|
2624
|
+
const firstLine = firstLineEnd >= 0 ? tagContent.subarray(0, firstLineEnd).toString("utf-8") : tagContent.toString("utf-8");
|
|
2625
|
+
const match = firstLine.match(/^object ([0-9a-f]{40})$/);
|
|
2626
|
+
if (!match) throw new Error(`Invalid annotated tag payload: ${firstLine}`);
|
|
2627
|
+
return match[1];
|
|
2628
|
+
};
|
|
2629
|
+
var parseTreeEntries = (treeContent) => {
|
|
2630
|
+
const entries = [];
|
|
2631
|
+
let offset = 0;
|
|
2632
|
+
while (offset < treeContent.length) {
|
|
2633
|
+
const modeEnd = treeContent.indexOf(32, offset);
|
|
2634
|
+
if (modeEnd < 0) throw new Error("Invalid tree entry mode");
|
|
2635
|
+
const nameEnd = treeContent.indexOf(0, modeEnd + 1);
|
|
2636
|
+
if (nameEnd < 0 || nameEnd + 21 > treeContent.length) throw new Error("Invalid tree entry name");
|
|
2637
|
+
entries.push({
|
|
2638
|
+
mode: treeContent.subarray(offset, modeEnd).toString("utf-8"),
|
|
2639
|
+
name: treeContent.subarray(modeEnd + 1, nameEnd).toString("utf-8"),
|
|
2640
|
+
oid: treeContent.subarray(nameEnd + 1, nameEnd + 21).toString("hex")
|
|
2641
|
+
});
|
|
2642
|
+
offset = nameEnd + 21;
|
|
2643
|
+
}
|
|
2644
|
+
return entries;
|
|
2645
|
+
};
|
|
2646
|
+
var createGitObjectResolver = async (repoPath) => {
|
|
2647
|
+
const actualGitDir = await getActualGitDir(repoPath);
|
|
2648
|
+
const resolvedObjects = /* @__PURE__ */ new Map();
|
|
2649
|
+
let packStorePromise;
|
|
2650
|
+
const getPackStore = async () => {
|
|
2651
|
+
if (!packStorePromise) packStorePromise = loadPackStore(actualGitDir);
|
|
2652
|
+
return packStorePromise;
|
|
2653
|
+
};
|
|
2654
|
+
const readPackedObject = async (location) => {
|
|
2655
|
+
var _location$packIndex$o, _location$packIndex$o2, _header$baseOid;
|
|
2656
|
+
const entryLength = location.nextOffset - location.offset;
|
|
2657
|
+
const entryBuffer = await readFixedRange(location.packIndex.fileHandle, location.offset, entryLength);
|
|
2658
|
+
const header = parsePackedEntryHeader(entryBuffer, location.offset);
|
|
2659
|
+
const compressedContent = entryBuffer.subarray(header.headerLength);
|
|
2660
|
+
if (header.packedType === "commit" || header.packedType === "tree" || header.packedType === "blob" || header.packedType === "tag") {
|
|
2661
|
+
const content = inflatePackedObject(compressedContent);
|
|
2662
|
+
if (content.length !== header.declaredSize) throw new Error(`Packed object size mismatch: ${location.oid} (expected ${header.declaredSize}, got ${content.length})`);
|
|
2663
|
+
return {
|
|
2664
|
+
oid: location.oid,
|
|
2665
|
+
type: header.packedType,
|
|
2666
|
+
content
|
|
2667
|
+
};
|
|
2668
|
+
}
|
|
2669
|
+
const deltaContent = inflatePackedObject(compressedContent);
|
|
2670
|
+
if (deltaContent.length !== header.declaredSize) throw new Error(`Packed delta size mismatch: ${location.oid} (expected ${header.declaredSize}, got ${deltaContent.length})`);
|
|
2671
|
+
const baseObject = header.packedType === "ofs-delta" ? await readObject((_location$packIndex$o = (_location$packIndex$o2 = location.packIndex.objectByOffset.get(header.baseOffset)) === null || _location$packIndex$o2 === void 0 ? void 0 : _location$packIndex$o2.oid) !== null && _location$packIndex$o !== void 0 ? _location$packIndex$o : (() => {
|
|
2672
|
+
throw new Error(`Missing ofs-delta base object at offset ${header.baseOffset}`);
|
|
2673
|
+
})()) : await readObject((_header$baseOid = header.baseOid) !== null && _header$baseOid !== void 0 ? _header$baseOid : (() => {
|
|
2674
|
+
throw new Error("Missing ref-delta base object id");
|
|
2675
|
+
})());
|
|
2676
|
+
const content = applyGitDelta(baseObject.content, deltaContent);
|
|
2677
|
+
return {
|
|
2678
|
+
oid: location.oid,
|
|
2679
|
+
type: baseObject.type,
|
|
2680
|
+
content
|
|
2681
|
+
};
|
|
2682
|
+
};
|
|
2683
|
+
const readObject = async (oid) => {
|
|
2684
|
+
const cachedObject = resolvedObjects.get(oid);
|
|
2685
|
+
if (cachedObject) return cachedObject;
|
|
2686
|
+
const objectPromise = (async () => {
|
|
2687
|
+
const looseObject = await readLooseObject(actualGitDir, oid);
|
|
2688
|
+
if (looseObject) return looseObject;
|
|
2689
|
+
const location = (await getPackStore()).objectByOid.get(oid);
|
|
2690
|
+
if (!location) throw new Error(`Git object not found: ${oid}`);
|
|
2691
|
+
return readPackedObject(location);
|
|
2692
|
+
})();
|
|
2693
|
+
resolvedObjects.set(oid, objectPromise);
|
|
2694
|
+
try {
|
|
2695
|
+
return await objectPromise;
|
|
2696
|
+
} catch (error) {
|
|
2697
|
+
resolvedObjects.delete(oid);
|
|
2698
|
+
throw error;
|
|
2699
|
+
}
|
|
2700
|
+
};
|
|
2701
|
+
return {
|
|
2702
|
+
close: async () => {
|
|
2703
|
+
if (!packStorePromise) return;
|
|
2704
|
+
const packStore = await packStorePromise;
|
|
2705
|
+
await Promise.allSettled(packStore.packs.map(async (pack) => {
|
|
2706
|
+
await pack.fileHandle.close();
|
|
2707
|
+
}));
|
|
2708
|
+
},
|
|
2709
|
+
readObject,
|
|
2710
|
+
resolveTagOidToCommit: async (tagOid) => {
|
|
2711
|
+
let currentOid = tagOid;
|
|
2712
|
+
const visitedOids = /* @__PURE__ */ new Set();
|
|
2713
|
+
while (true) {
|
|
2714
|
+
if (visitedOids.has(currentOid)) throw new Error(`Detected cyclic tag reference: ${currentOid}`);
|
|
2715
|
+
visitedOids.add(currentOid);
|
|
2716
|
+
const object = await readObject(currentOid);
|
|
2717
|
+
if (object.type !== "tag") return currentOid;
|
|
2718
|
+
currentOid = parseTagTargetOid(object.content);
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
};
|
|
2722
|
+
};
|
|
2723
|
+
var runWithConcurrency = async (values, concurrency, worker) => {
|
|
2724
|
+
let nextIndex = 0;
|
|
2725
|
+
const runWorker = async () => {
|
|
2726
|
+
while (nextIndex < values.length) {
|
|
2727
|
+
const currentIndex = nextIndex;
|
|
2728
|
+
nextIndex += 1;
|
|
2729
|
+
await worker(values[currentIndex]);
|
|
2730
|
+
}
|
|
2731
|
+
};
|
|
2732
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, Math.max(values.length, 1)) }, () => runWorker()));
|
|
2733
|
+
};
|
|
2734
|
+
/**
|
|
2735
|
+
* Resolve multiple tag object OIDs to their peeled commit OIDs.
|
|
2736
|
+
* @param repoPath - Repository path
|
|
2737
|
+
* @param tagOids - Tag or commit OIDs
|
|
2738
|
+
* @returns Map of tag object OID to peeled commit OID
|
|
2739
|
+
*/
|
|
2740
|
+
var resolveTagOidsToCommits = async (repoPath, tagOids) => {
|
|
2741
|
+
const resolver = await createGitObjectResolver(repoPath);
|
|
2742
|
+
const result = /* @__PURE__ */ new Map();
|
|
2743
|
+
const uniqueTagOids = Array.from(new Set(tagOids));
|
|
2744
|
+
try {
|
|
2745
|
+
await runWithConcurrency(uniqueTagOids, LOOSE_TAG_RESOLUTION_CONCURRENCY, async (tagOid) => {
|
|
2746
|
+
result.set(tagOid, await resolver.resolveTagOidToCommit(tagOid));
|
|
2747
|
+
});
|
|
2748
|
+
} finally {
|
|
2749
|
+
await resolver.close();
|
|
2750
|
+
}
|
|
2751
|
+
return result;
|
|
2752
|
+
};
|
|
2753
|
+
var collectTreeFiles = async (resolver, treeOid, prefix, files) => {
|
|
2754
|
+
const treeObject = await resolver.readObject(treeOid);
|
|
2755
|
+
if (treeObject.type !== "tree") throw new Error(`Expected tree object: ${treeOid}`);
|
|
2756
|
+
for (const entry of parseTreeEntries(treeObject.content)) {
|
|
2757
|
+
const path$7 = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
2758
|
+
if (entry.mode === "40000") {
|
|
2759
|
+
await collectTreeFiles(resolver, entry.oid, path$7, files);
|
|
2760
|
+
continue;
|
|
2761
|
+
}
|
|
2762
|
+
if (entry.mode !== "160000") files.set(path$7, entry.oid);
|
|
2763
|
+
}
|
|
2764
|
+
};
|
|
2765
|
+
/**
|
|
2766
|
+
* Collect all tracked file blob OIDs under the specified tree.
|
|
2767
|
+
* @param repoPath - Repository path
|
|
2768
|
+
* @param treeOid - Tree object OID
|
|
2769
|
+
* @returns Map of repository-relative file path to blob OID
|
|
2770
|
+
*/
|
|
2771
|
+
var listTreeFiles = async (repoPath, treeOid) => {
|
|
2772
|
+
const resolver = await createGitObjectResolver(repoPath);
|
|
2773
|
+
const files = /* @__PURE__ */ new Map();
|
|
2774
|
+
try {
|
|
2775
|
+
await collectTreeFiles(resolver, treeOid, "", files);
|
|
2776
|
+
} finally {
|
|
2777
|
+
await resolver.close();
|
|
2778
|
+
}
|
|
2779
|
+
return files;
|
|
2780
|
+
};
|
|
2781
|
+
//#endregion
|
|
2407
2782
|
//#region src/fast-tags.ts
|
|
2408
2783
|
/**
|
|
2409
2784
|
* Fast tag listing implementation that reads tags directly from filesystem
|
|
@@ -2454,13 +2829,7 @@ var readLooseTags = async (refsTagsPath) => {
|
|
|
2454
2829
|
* @returns Array of all tag names
|
|
2455
2830
|
*/
|
|
2456
2831
|
var listTagsFast = async (repoPath) => {
|
|
2457
|
-
const
|
|
2458
|
-
const gitStat = await (0, fs_promises.stat)(gitDir).catch(() => null);
|
|
2459
|
-
let actualGitDir = gitDir;
|
|
2460
|
-
if (gitStat === null || gitStat === void 0 ? void 0 : gitStat.isFile()) {
|
|
2461
|
-
const match = (await (0, fs_promises.readFile)(gitDir, "utf-8")).match(/^gitdir:\s*(.+)$/m);
|
|
2462
|
-
if (match) actualGitDir = (0, path.isAbsolute)(match[1]) ? match[1] : (0, path.join)(repoPath, match[1]);
|
|
2463
|
-
}
|
|
2832
|
+
const actualGitDir = await getActualGitDir(repoPath);
|
|
2464
2833
|
const [packedTags, looseTags] = await Promise.all([parsePackedRefs((0, path.join)(actualGitDir, "packed-refs")), readLooseTags((0, path.join)(actualGitDir, "refs", "tags"))]);
|
|
2465
2834
|
const allTags = new Set([...packedTags, ...looseTags]);
|
|
2466
2835
|
return Array.from(allTags).sort();
|
|
@@ -2473,14 +2842,8 @@ var listTagsFast = async (repoPath) => {
|
|
|
2473
2842
|
*/
|
|
2474
2843
|
var resolveTagsBatchWithCommit = async (repoPath, tagNames, logger) => {
|
|
2475
2844
|
const startTime = Date.now();
|
|
2476
|
-
const gitDir = (0, path.join)(repoPath, ".git");
|
|
2477
2845
|
const result = /* @__PURE__ */ new Map();
|
|
2478
|
-
const
|
|
2479
|
-
let actualGitDir = gitDir;
|
|
2480
|
-
if (gitStat === null || gitStat === void 0 ? void 0 : gitStat.isFile()) {
|
|
2481
|
-
const match = (await (0, fs_promises.readFile)(gitDir, "utf-8")).match(/^gitdir:\s*(.+)$/m);
|
|
2482
|
-
if (match) actualGitDir = (0, path.isAbsolute)(match[1]) ? match[1] : (0, path.join)(repoPath, match[1]);
|
|
2483
|
-
}
|
|
2846
|
+
const actualGitDir = await getActualGitDir(repoPath);
|
|
2484
2847
|
const tagSet = new Set(tagNames);
|
|
2485
2848
|
const packedRefsStart = Date.now();
|
|
2486
2849
|
try {
|
|
@@ -2507,28 +2870,28 @@ var resolveTagsBatchWithCommit = async (repoPath, tagNames, logger) => {
|
|
|
2507
2870
|
const remainingTags = tagNames.filter((tag) => !result.has(tag));
|
|
2508
2871
|
if (remainingTags.length > 0) {
|
|
2509
2872
|
const looseRefsStart = Date.now();
|
|
2510
|
-
await Promise.all(remainingTags.map(async (tagName) => {
|
|
2873
|
+
const looseTagEntries = (await Promise.all(remainingTags.map(async (tagName) => {
|
|
2511
2874
|
const looseRefPath = (0, path.join)(actualGitDir, "refs", "tags", tagName);
|
|
2512
2875
|
try {
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2876
|
+
return {
|
|
2877
|
+
tagName,
|
|
2878
|
+
oid: (await (0, fs_promises.readFile)(looseRefPath, "utf-8")).trim()
|
|
2879
|
+
};
|
|
2880
|
+
} catch (error) {
|
|
2881
|
+
if (error.code !== "ENOENT") throw error;
|
|
2882
|
+
return;
|
|
2883
|
+
}
|
|
2884
|
+
}))).filter((entry) => entry !== void 0);
|
|
2885
|
+
if (looseTagEntries.length > 0) {
|
|
2886
|
+
const commitOids = await resolveTagOidsToCommits(repoPath, looseTagEntries.map((entry) => entry.oid));
|
|
2887
|
+
for (const { tagName, oid } of looseTagEntries) {
|
|
2888
|
+
var _commitOids$get;
|
|
2524
2889
|
result.set(tagName, {
|
|
2525
2890
|
oid,
|
|
2526
|
-
commitOid
|
|
2891
|
+
commitOid: (_commitOids$get = commitOids.get(oid)) !== null && _commitOids$get !== void 0 ? _commitOids$get : oid
|
|
2527
2892
|
});
|
|
2528
|
-
} catch (error) {
|
|
2529
|
-
if (error.code !== "ENOENT") throw error;
|
|
2530
2893
|
}
|
|
2531
|
-
}
|
|
2894
|
+
}
|
|
2532
2895
|
logger.debug(`[fast-tags] read loose refs: ${Date.now() - looseRefsStart}ms`);
|
|
2533
2896
|
}
|
|
2534
2897
|
const totalTime = Date.now() - startTime;
|
|
@@ -2741,7 +3104,8 @@ var getCommit = async (repositoryPath, hash) => {
|
|
|
2741
3104
|
shortHash: commit.oid.substring(0, 7),
|
|
2742
3105
|
date: (/* @__PURE__ */ new Date(commit.commit.author.timestamp * 1e3)).toISOString(),
|
|
2743
3106
|
message: commit.commit.message.trim(),
|
|
2744
|
-
parents: commit.commit.parent || []
|
|
3107
|
+
parents: commit.commit.parent || [],
|
|
3108
|
+
tree: commit.commit.tree
|
|
2745
3109
|
};
|
|
2746
3110
|
} catch (_unused) {
|
|
2747
3111
|
return;
|
|
@@ -2769,7 +3133,8 @@ var getCurrentCommit = async (repositoryPath) => {
|
|
|
2769
3133
|
shortHash: commit.oid.substring(0, 7),
|
|
2770
3134
|
date: (/* @__PURE__ */ new Date(commit.commit.author.timestamp * 1e3)).toISOString(),
|
|
2771
3135
|
message: commit.commit.message.trim(),
|
|
2772
|
-
parents: commit.commit.parent || []
|
|
3136
|
+
parents: commit.commit.parent || [],
|
|
3137
|
+
tree: commit.commit.tree
|
|
2773
3138
|
};
|
|
2774
3139
|
} catch (_unused2) {
|
|
2775
3140
|
return;
|
|
@@ -2809,94 +3174,133 @@ var getRelatedBranches = async (repositoryPath, commitHash) => {
|
|
|
2809
3174
|
return [];
|
|
2810
3175
|
}
|
|
2811
3176
|
};
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
workdirOid,
|
|
2847
|
-
stageOid
|
|
2848
|
-
];
|
|
2849
|
-
const statusValues = entry.map((value) => entry.indexOf(value));
|
|
2850
|
-
return [
|
|
2851
|
-
filepath,
|
|
2852
|
-
statusValues[1],
|
|
2853
|
-
statusValues[2],
|
|
2854
|
-
statusValues[3]
|
|
2855
|
-
];
|
|
3177
|
+
var parseGitIndex = async (gitDir) => {
|
|
3178
|
+
try {
|
|
3179
|
+
const buffer = await fs_promises.default.readFile((0, path.join)(gitDir, "index"));
|
|
3180
|
+
if (buffer.subarray(0, 4).toString("ascii") !== "DIRC") throw new Error("Unsupported git index signature");
|
|
3181
|
+
const version = buffer.readUInt32BE(4);
|
|
3182
|
+
if (version !== 2 && version !== 3) throw new Error(`Unsupported git index version: ${version}`);
|
|
3183
|
+
const entryCount = buffer.readUInt32BE(8);
|
|
3184
|
+
let offset = 12;
|
|
3185
|
+
const entries = /* @__PURE__ */ new Map();
|
|
3186
|
+
for (let index = 0; index < entryCount; index++) {
|
|
3187
|
+
const entryStart = offset;
|
|
3188
|
+
const size = buffer.readUInt32BE(entryStart + 36);
|
|
3189
|
+
const oid = buffer.subarray(entryStart + 40, entryStart + 60).toString("hex");
|
|
3190
|
+
const flags = buffer.readUInt16BE(entryStart + 60);
|
|
3191
|
+
const stage = flags >> 12 & 3;
|
|
3192
|
+
offset = entryStart + 62;
|
|
3193
|
+
if (version >= 3 && (flags & 16384) !== 0) offset += 2;
|
|
3194
|
+
const pathEnd = buffer.indexOf(0, offset);
|
|
3195
|
+
if (pathEnd < 0) throw new Error("Invalid git index path entry");
|
|
3196
|
+
const path$3 = buffer.subarray(offset, pathEnd).toString("utf-8");
|
|
3197
|
+
offset = pathEnd + 1;
|
|
3198
|
+
while ((offset - entryStart) % 8 !== 0) offset += 1;
|
|
3199
|
+
entries.set(path$3, {
|
|
3200
|
+
path: path$3,
|
|
3201
|
+
oid,
|
|
3202
|
+
size,
|
|
3203
|
+
stage
|
|
3204
|
+
});
|
|
3205
|
+
}
|
|
3206
|
+
return entries;
|
|
3207
|
+
} catch (error) {
|
|
3208
|
+
if (error.code === "ENOENT") return /* @__PURE__ */ new Map();
|
|
3209
|
+
throw error;
|
|
3210
|
+
}
|
|
2856
3211
|
};
|
|
2857
|
-
var
|
|
2858
|
-
const
|
|
2859
|
-
for (const
|
|
2860
|
-
|
|
3212
|
+
var listTrackedDirectories = (indexEntries) => {
|
|
3213
|
+
const directories = new Set([""]);
|
|
3214
|
+
for (const path$4 of indexEntries.keys()) {
|
|
3215
|
+
const segments = path$4.split("/");
|
|
3216
|
+
let currentPath = "";
|
|
3217
|
+
for (let index = 0; index < segments.length - 1; index++) {
|
|
3218
|
+
currentPath = currentPath ? `${currentPath}/${segments[index]}` : segments[index];
|
|
3219
|
+
directories.add(currentPath);
|
|
3220
|
+
}
|
|
3221
|
+
}
|
|
3222
|
+
return directories;
|
|
3223
|
+
};
|
|
3224
|
+
var listWorkingDirectoryFiles = async (repositoryPath, trackedDirectories, relativePath = "") => {
|
|
3225
|
+
const directoryPath = relativePath ? (0, path.join)(repositoryPath, relativePath) : repositoryPath;
|
|
3226
|
+
const entries = await fs_promises.default.readdir(directoryPath, { withFileTypes: true });
|
|
3227
|
+
const files = [];
|
|
3228
|
+
for (const entry of entries) {
|
|
3229
|
+
if (entry.name === ".git") continue;
|
|
3230
|
+
const entryPath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
|
3231
|
+
if (entry.isDirectory()) {
|
|
3232
|
+
if (!trackedDirectories.has(entryPath)) {
|
|
3233
|
+
if (await isomorphic_git.isIgnored({
|
|
3234
|
+
fs: fs_promises.default,
|
|
3235
|
+
dir: repositoryPath,
|
|
3236
|
+
filepath: entryPath
|
|
3237
|
+
})) continue;
|
|
3238
|
+
}
|
|
3239
|
+
files.push(...await listWorkingDirectoryFiles(repositoryPath, trackedDirectories, entryPath));
|
|
3240
|
+
continue;
|
|
3241
|
+
}
|
|
3242
|
+
if (entry.isFile() || entry.isSymbolicLink()) files.push(entryPath);
|
|
3243
|
+
}
|
|
3244
|
+
return files;
|
|
2861
3245
|
};
|
|
2862
|
-
var
|
|
2863
|
-
const
|
|
2864
|
-
|
|
2865
|
-
return results;
|
|
3246
|
+
var calculateBlobOid = async (filePath) => {
|
|
3247
|
+
const content = await fs_promises.default.readFile(filePath);
|
|
3248
|
+
return (0, crypto.createHash)("sha1").update(`blob ${content.length}\0`).update(content).digest("hex");
|
|
2866
3249
|
};
|
|
2867
|
-
var getModifiedFiles = async (repositoryPath) => {
|
|
3250
|
+
var getModifiedFiles = async (repositoryPath, headTreeOid) => {
|
|
2868
3251
|
try {
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
3252
|
+
const gitDir = await getActualGitDir(repositoryPath);
|
|
3253
|
+
const [headFiles, indexEntries] = await Promise.all([listTreeFiles(repositoryPath, headTreeOid), parseGitIndex(gitDir)]);
|
|
3254
|
+
const workdirFiles = await listWorkingDirectoryFiles(repositoryPath, listTrackedDirectories(indexEntries));
|
|
3255
|
+
const modifiedFiles = /* @__PURE__ */ new Map();
|
|
3256
|
+
const rememberModifiedFile = (path$5, reason) => {
|
|
3257
|
+
if (!modifiedFiles.has(path$5)) modifiedFiles.set(path$5, {
|
|
3258
|
+
path: path$5,
|
|
3259
|
+
reason
|
|
3260
|
+
});
|
|
3261
|
+
};
|
|
3262
|
+
for (const [path$6, headOid] of headFiles.entries()) {
|
|
3263
|
+
const indexEntry = indexEntries.get(path$6);
|
|
3264
|
+
if (!indexEntry) rememberModifiedFile(path$6, "staged");
|
|
3265
|
+
else if (indexEntry.stage !== 0 || indexEntry.oid !== headOid) rememberModifiedFile(path$6, "staged");
|
|
3266
|
+
}
|
|
3267
|
+
for (const indexEntry of indexEntries.values()) {
|
|
3268
|
+
if (!headFiles.has(indexEntry.path)) rememberModifiedFile(indexEntry.path, "staged");
|
|
3269
|
+
const absolutePath = (0, path.join)(repositoryPath, indexEntry.path);
|
|
3270
|
+
try {
|
|
3271
|
+
const stats = await fs_promises.default.lstat(absolutePath);
|
|
3272
|
+
if (!stats.isFile() && !stats.isSymbolicLink()) {
|
|
3273
|
+
rememberModifiedFile(indexEntry.path, "worktree");
|
|
3274
|
+
continue;
|
|
2885
3275
|
}
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
3276
|
+
if (indexEntry.stage !== 0) {
|
|
3277
|
+
rememberModifiedFile(indexEntry.path, "staged");
|
|
3278
|
+
continue;
|
|
3279
|
+
}
|
|
3280
|
+
if (indexEntry.size !== stats.size || await calculateBlobOid(absolutePath) !== indexEntry.oid) rememberModifiedFile(indexEntry.path, "worktree");
|
|
3281
|
+
} catch (error) {
|
|
3282
|
+
if (error.code === "ENOENT") {
|
|
3283
|
+
rememberModifiedFile(indexEntry.path, "worktree");
|
|
3284
|
+
continue;
|
|
3285
|
+
}
|
|
3286
|
+
throw error;
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
const trackedPaths = new Set(indexEntries.keys());
|
|
3290
|
+
for (const filepath of workdirFiles) {
|
|
3291
|
+
if (trackedPaths.has(filepath)) continue;
|
|
3292
|
+
if (!await isomorphic_git.isIgnored({
|
|
3293
|
+
fs: fs_promises.default,
|
|
3294
|
+
dir: repositoryPath,
|
|
3295
|
+
filepath
|
|
3296
|
+
})) rememberModifiedFile(filepath, "untracked");
|
|
3297
|
+
}
|
|
3298
|
+
return Array.from(modifiedFiles.values());
|
|
2893
3299
|
} catch (_unused5) {
|
|
2894
3300
|
return [];
|
|
2895
3301
|
}
|
|
2896
3302
|
};
|
|
2897
|
-
var formatModifiedFile = (modifiedFile) => {
|
|
2898
|
-
return `'${modifiedFile[0]}':${modifiedFile[1]}:${modifiedFile[2]}:${modifiedFile[3]}`;
|
|
2899
|
-
};
|
|
3303
|
+
var formatModifiedFile = (modifiedFile) => `'${modifiedFile.path}':${modifiedFile.reason}`;
|
|
2900
3304
|
/**
|
|
2901
3305
|
* Lookup version label recursively core analyzer
|
|
2902
3306
|
* @param cwd - The directory to check
|
|
@@ -2996,7 +3400,7 @@ var getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logger)
|
|
|
2996
3400
|
metadata.git = gitMetadata;
|
|
2997
3401
|
if (version) {
|
|
2998
3402
|
if (checkWorkingDirectoryStatus) {
|
|
2999
|
-
const modifiedFiles = await getModifiedFiles(gitRootPath);
|
|
3403
|
+
const modifiedFiles = await getModifiedFiles(gitRootPath, currentCommit.tree);
|
|
3000
3404
|
if (modifiedFiles.length >= 1) {
|
|
3001
3405
|
const newVersion = incrementLastVersionComponent(version);
|
|
3002
3406
|
logger.debug(`Increased git version by detected modified items: ${formatVersion(version)} ---> ${formatVersion(newVersion)}, Files=[${modifiedFiles.map(formatModifiedFile).join(", ")}]`);
|
|
@@ -3913,7 +4317,7 @@ var publishCommand = async (args, logger) => {
|
|
|
3913
4317
|
}
|
|
3914
4318
|
};
|
|
3915
4319
|
var showHelp = async () => {
|
|
3916
|
-
const { author, license, repository_url, version, git_commit_hash } = await Promise.resolve().then(() => require("./packageMetadata-
|
|
4320
|
+
const { author, license, repository_url, version, git_commit_hash } = await Promise.resolve().then(() => require("./packageMetadata-Cwh4Fqmw.cjs"));
|
|
3917
4321
|
console.info(`screw-up [${version}-${git_commit_hash}]
|
|
3918
4322
|
Easy package metadata inserter CLI
|
|
3919
4323
|
Copyright (c) ${author}
|