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.
Files changed (36) hide show
  1. package/dist/index.cjs +553 -125
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.mjs +34 -10
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/main.cjs +539 -135
  6. package/dist/main.cjs.map +1 -1
  7. package/dist/main.mjs +6 -6
  8. package/dist/{metadata-file-CpFkBJPS.js → metadata-file-D79yMa_A.js} +520 -119
  9. package/dist/metadata-file-D79yMa_A.js.map +1 -0
  10. package/dist/{packageMetadata-Lj9bVuVM.cjs → packageMetadata-6po5LHyH.cjs} +5 -5
  11. package/dist/{packageMetadata-Lj9bVuVM.cjs.map → packageMetadata-6po5LHyH.cjs.map} +1 -1
  12. package/dist/{packageMetadata-zaiRRUve.cjs → packageMetadata-Cwh4Fqmw.cjs} +3 -3
  13. package/dist/{packageMetadata-YWwXZbaj.js → packageMetadata-Sm2NpI2b.js} +6 -6
  14. package/dist/{packageMetadata-YWwXZbaj.js.map → packageMetadata-Sm2NpI2b.js.map} +1 -1
  15. package/dist/src/analyzer.d.ts +2 -2
  16. package/dist/src/analyzer.d.ts.map +1 -1
  17. package/dist/src/cli-internal.d.ts +2 -2
  18. package/dist/src/cli.d.ts +2 -2
  19. package/dist/src/declaration-import-fix.d.ts +2 -2
  20. package/dist/src/default-import-fix.d.ts +2 -2
  21. package/dist/src/fast-tags.d.ts +2 -2
  22. package/dist/src/fast-tags.d.ts.map +1 -1
  23. package/dist/src/generated/packageMetadata.d.ts +4 -4
  24. package/dist/src/git-operations.d.ts +2 -2
  25. package/dist/src/git-operations.d.ts.map +1 -1
  26. package/dist/src/git-ref-utils.d.ts +39 -0
  27. package/dist/src/git-ref-utils.d.ts.map +1 -0
  28. package/dist/src/index.d.ts +2 -2
  29. package/dist/src/internal.d.ts +2 -2
  30. package/dist/src/main.d.ts +2 -2
  31. package/dist/src/metadata-file.d.ts +2 -2
  32. package/dist/src/text-edits.d.ts +2 -2
  33. package/dist/src/types.d.ts +2 -2
  34. package/dist/src/vite-plugin.d.ts +2 -2
  35. package/package.json +7 -7
  36. package/dist/metadata-file-CpFkBJPS.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.30.0
3
+ * version: 1.32.0
4
4
  * description: Simply package metadata inserter on Vite plugin
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/screw-up.git
8
- * git.commit.hash: ac6785ada0880218ecbaef699721d3a169362e76
8
+ * git.commit.hash: 8a0078c34fa41bdb0cbf2d23837ac5e3217cbf53
9
9
  */
10
10
  //#region \0rolldown/runtime.js
11
11
  var __create = Object.create;
@@ -38,15 +38,19 @@ require("glob");
38
38
  let isomorphic_git = require("isomorphic-git");
39
39
  isomorphic_git = __toESM(isomorphic_git);
40
40
  let crypto$1 = require("crypto");
41
+ let zlib = require("zlib");
41
42
  //#region node_modules/async-primitives/dist/index.mjs
42
43
  /*!
43
44
  * name: async-primitives
44
- * version: 1.5.0
45
+ * version: 1.7.0
45
46
  * description: A collection of primitive functions for asynchronous operations
46
47
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
47
48
  * license: MIT
48
49
  * repository.url: https://github.com/kekyo/async-primitives.git
49
- * git.commit.hash: cd35465b7e9b9945049186e7eaeecc0bfba65766
50
+ * git.commit.hash: 9472fbd5310b92690d84aaafb897429a04c013c5
51
+ */
52
+ /**
53
+ * A no-op Releasable object that does nothing when released or disposed
50
54
  */
51
55
  var __NOOP_HANDLER = () => {};
52
56
  var __NOOP_RELEASABLE = {
@@ -58,6 +62,12 @@ var toAbortError = (reason) => {
58
62
  if (typeof reason === "string") return new Error(reason);
59
63
  return /* @__PURE__ */ new Error("Operation aborted");
60
64
  };
65
+ /**
66
+ * Hooks up an abort handler to an AbortSignal and returns a handle for early cleanup
67
+ * @param signal - The AbortSignal to hook up to
68
+ * @param callback - The callback to call when the signal is aborted
69
+ * @returns A Releasable handle that can be used to remove the abort listener early
70
+ */
61
71
  var onAbort = (signal, callback) => {
62
72
  if (!signal) return __NOOP_RELEASABLE;
63
73
  if (signal.aborted) {
@@ -92,11 +102,21 @@ var onAbort = (signal, callback) => {
92
102
  [Symbol.dispose]: release
93
103
  };
94
104
  };
105
+ var runtimeGlobal$1 = globalThis;
95
106
  var defer = (fn) => {
96
- if (typeof setImmediate === "function") setImmediate(fn);
97
- else setTimeout(fn, 0);
107
+ const setImmediateHandler = runtimeGlobal$1.setImmediate;
108
+ if (typeof setImmediateHandler === "function") {
109
+ setImmediateHandler(fn);
110
+ return;
111
+ }
112
+ globalThis.setTimeout(fn, 0);
98
113
  };
99
114
  var ABORTED_ERROR$2 = () => /* @__PURE__ */ new Error("Lock acquisition was aborted");
115
+ /**
116
+ * Creates a new LockHandle instance
117
+ * @param releaseCallback Callback function to release the lock
118
+ * @returns A LockHandle object with release and dispose functionality
119
+ */
100
120
  var createLockHandle = (releaseCallback) => {
101
121
  let isActive = true;
102
122
  const release = () => {
@@ -112,15 +132,20 @@ var createLockHandle = (releaseCallback) => {
112
132
  [Symbol.dispose]: release
113
133
  };
114
134
  };
135
+ /**
136
+ * Creates a new Mutex instance
137
+ * @param maxConsecutiveCalls - The maximum number of consecutive calls to the lockAsync method before yielding control to the next item in the queue
138
+ * @returns A new Mutex for promise-based mutex operations
139
+ */
115
140
  var createMutex = (maxConsecutiveCalls = 20) => {
116
141
  let isLocked = false;
117
142
  const queue = [];
118
143
  let count = 0;
119
144
  const processQueue = () => {
120
- var _a;
145
+ var _item$signal;
121
146
  if (isLocked || queue.length === 0) return;
122
147
  const item = queue.shift();
123
- if ((_a = item.signal) == null ? void 0 : _a.aborted) {
148
+ if ((_item$signal = item.signal) === null || _item$signal === void 0 ? void 0 : _item$signal.aborted) {
124
149
  item.reject(ABORTED_ERROR$2());
125
150
  scheduleNextProcess();
126
151
  return;
@@ -198,8 +223,8 @@ createLogicalContext(Symbol("[root]"));
198
223
  //#endregion
199
224
  //#region src/generated/packageMetadata.ts
200
225
  var name = "screw-up";
201
- var version = "1.30.0";
202
- var git_commit_hash = "ac6785ada0880218ecbaef699721d3a169362e76";
226
+ var version = "1.32.0";
227
+ var git_commit_hash = "8a0078c34fa41bdb0cbf2d23837ac5e3217cbf53";
203
228
  //#endregion
204
229
  //#region node_modules/json5/dist/index.js
205
230
  var require_dist = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -1826,6 +1851,380 @@ var resolvePackageMetadata = async (projectRoot, fetchGitMetadata, alwaysOverrid
1826
1851
  };
1827
1852
  };
1828
1853
  //#endregion
1854
+ //#region src/git-ref-utils.ts
1855
+ var PACK_TRAILER_SIZE = 20;
1856
+ var LOOSE_TAG_RESOLUTION_CONCURRENCY = 4;
1857
+ var PACKED_OBJECT_TYPE_BY_CODE = new Map([
1858
+ [1, "commit"],
1859
+ [2, "tree"],
1860
+ [3, "blob"],
1861
+ [4, "tag"],
1862
+ [6, "ofs-delta"],
1863
+ [7, "ref-delta"]
1864
+ ]);
1865
+ /**
1866
+ * Resolve the actual Git directory for repositories, worktrees, and submodules.
1867
+ * @param repoPath - Repository path
1868
+ * @returns The resolved Git directory path
1869
+ */
1870
+ var getActualGitDir = async (repoPath) => {
1871
+ const gitDir = (0, path.join)(repoPath, ".git");
1872
+ const gitStat = await (0, fs_promises.stat)(gitDir).catch(() => null);
1873
+ if (!(gitStat === null || gitStat === void 0 ? void 0 : gitStat.isFile())) return gitDir;
1874
+ const match = (await (0, fs_promises.readFile)(gitDir, "utf-8")).match(/^gitdir:\s*(.+)$/m);
1875
+ if (!match) return gitDir;
1876
+ return (0, path.isAbsolute)(match[1]) ? match[1] : (0, path.join)(repoPath, match[1]);
1877
+ };
1878
+ var readFixedRange = async (fileHandle, offset, length) => {
1879
+ const buffer = Buffer.alloc(length);
1880
+ const { bytesRead } = await fileHandle.read(buffer, 0, length, offset);
1881
+ if (bytesRead !== length) throw new Error(`Unexpected EOF while reading pack entry at offset ${offset} (expected ${length}, got ${bytesRead})`);
1882
+ return buffer;
1883
+ };
1884
+ var readLooseObject = async (gitDir, oid) => {
1885
+ try {
1886
+ const wrapped = (0, zlib.inflateSync)(await (0, fs_promises.readFile)((0, path.join)(gitDir, "objects", oid.slice(0, 2), oid.slice(2))));
1887
+ const headerEnd = wrapped.indexOf(0);
1888
+ if (headerEnd < 0) throw new Error(`Invalid loose object header: ${oid}`);
1889
+ const header = wrapped.subarray(0, headerEnd).toString("utf-8");
1890
+ const match = header.match(/^(commit|tree|blob|tag) (\d+)$/);
1891
+ if (!match) throw new Error(`Unsupported loose object header: ${header}`);
1892
+ const content = wrapped.subarray(headerEnd + 1);
1893
+ const expectedSize = Number(match[2]);
1894
+ if (content.length !== expectedSize) throw new Error(`Loose object size mismatch: ${oid} (expected ${expectedSize}, got ${content.length})`);
1895
+ return {
1896
+ oid,
1897
+ type: match[1],
1898
+ content
1899
+ };
1900
+ } catch (error) {
1901
+ if (error.code === "ENOENT") return null;
1902
+ throw error;
1903
+ }
1904
+ };
1905
+ var readLargePackOffset = (idxBuffer, largeOffsetsStart, largeOffsetIndex) => {
1906
+ const offset = Number(idxBuffer.readBigUInt64BE(largeOffsetsStart + largeOffsetIndex * 8));
1907
+ if (!Number.isSafeInteger(offset)) throw new Error(`Pack offset exceeds safe integer range: ${offset}`);
1908
+ return offset;
1909
+ };
1910
+ var loadPackIndex = async (idxPath) => {
1911
+ const packPath = idxPath.replace(/\.idx$/, ".pack");
1912
+ const [idxBuffer, packStat, fileHandle] = await Promise.all([
1913
+ (0, fs_promises.readFile)(idxPath),
1914
+ (0, fs_promises.stat)(packPath),
1915
+ (0, fs_promises.open)(packPath, "r")
1916
+ ]);
1917
+ if (idxBuffer.readUInt32BE(0) !== 4285812579) throw new Error(`Unsupported pack index signature: ${idxPath}`);
1918
+ if (idxBuffer.readUInt32BE(4) !== 2) throw new Error(`Unsupported pack index version: ${idxPath}`);
1919
+ const objectCount = idxBuffer.readUInt32BE(1028);
1920
+ const oidStart = 1032;
1921
+ const offsetStart = oidStart + objectCount * 20 + objectCount * 4;
1922
+ const largeOffsetStart = offsetStart + objectCount * 4;
1923
+ const objectByOid = /* @__PURE__ */ new Map();
1924
+ const objectByOffset = /* @__PURE__ */ new Map();
1925
+ const sortedObjects = [];
1926
+ const packIndex = {
1927
+ fileHandle,
1928
+ objectByOid,
1929
+ objectByOffset
1930
+ };
1931
+ for (let index = 0; index < objectCount; index++) {
1932
+ const oidOffset = oidStart + index * 20;
1933
+ const oid = idxBuffer.subarray(oidOffset, oidOffset + 20).toString("hex");
1934
+ const rawOffset = idxBuffer.readUInt32BE(offsetStart + index * 4);
1935
+ const offset = (rawOffset & 2147483648) === 0 ? rawOffset : readLargePackOffset(idxBuffer, largeOffsetStart, rawOffset & 2147483647);
1936
+ sortedObjects.push({
1937
+ oid,
1938
+ offset
1939
+ });
1940
+ }
1941
+ sortedObjects.sort((left, right) => left.offset - right.offset);
1942
+ const packEndOffset = packStat.size - PACK_TRAILER_SIZE;
1943
+ for (let index = 0; index < sortedObjects.length; index++) {
1944
+ var _sortedObjects$offset, _sortedObjects;
1945
+ const currentObject = sortedObjects[index];
1946
+ const nextOffset = (_sortedObjects$offset = (_sortedObjects = sortedObjects[index + 1]) === null || _sortedObjects === void 0 ? void 0 : _sortedObjects.offset) !== null && _sortedObjects$offset !== void 0 ? _sortedObjects$offset : packEndOffset;
1947
+ const location = {
1948
+ oid: currentObject.oid,
1949
+ offset: currentObject.offset,
1950
+ nextOffset,
1951
+ packIndex
1952
+ };
1953
+ objectByOid.set(currentObject.oid, location);
1954
+ objectByOffset.set(currentObject.offset, location);
1955
+ }
1956
+ return packIndex;
1957
+ };
1958
+ var loadPackStore = async (gitDir) => {
1959
+ try {
1960
+ const packDir = (0, path.join)(gitDir, "objects", "pack");
1961
+ const idxPaths = (await (0, fs_promises.readdir)(packDir)).filter((entryName) => entryName.endsWith(".idx")).map((entryName) => (0, path.join)(packDir, entryName));
1962
+ const packs = await Promise.all(idxPaths.map(loadPackIndex));
1963
+ const objectByOid = /* @__PURE__ */ new Map();
1964
+ for (const pack of packs) for (const [oid, location] of pack.objectByOid.entries()) objectByOid.set(oid, location);
1965
+ return {
1966
+ packs,
1967
+ objectByOid
1968
+ };
1969
+ } catch (error) {
1970
+ if (error.code === "ENOENT") return {
1971
+ packs: [],
1972
+ objectByOid: /* @__PURE__ */ new Map()
1973
+ };
1974
+ throw error;
1975
+ }
1976
+ };
1977
+ var decodeOfsDeltaDistance = (buffer, startOffset) => {
1978
+ let cursor = startOffset;
1979
+ let byte = buffer[cursor++];
1980
+ let distance = byte & 127;
1981
+ while (byte & 128) {
1982
+ byte = buffer[cursor++];
1983
+ distance = distance + 1 << 7 | byte & 127;
1984
+ }
1985
+ return {
1986
+ distance,
1987
+ nextOffset: cursor
1988
+ };
1989
+ };
1990
+ var parsePackedEntryHeader = (entryBuffer, objectOffset) => {
1991
+ let cursor = 0;
1992
+ let byte = entryBuffer[cursor++];
1993
+ const packedType = PACKED_OBJECT_TYPE_BY_CODE.get(byte >> 4 & 7);
1994
+ if (!packedType) throw new Error(`Unsupported packed object type at offset ${objectOffset}`);
1995
+ let declaredSize = byte & 15;
1996
+ let shift = 4;
1997
+ while (byte & 128) {
1998
+ byte = entryBuffer[cursor++];
1999
+ declaredSize |= (byte & 127) << shift;
2000
+ shift += 7;
2001
+ }
2002
+ let baseOffset;
2003
+ let baseOid;
2004
+ if (packedType === "ofs-delta") {
2005
+ const decoded = decodeOfsDeltaDistance(entryBuffer, cursor);
2006
+ cursor = decoded.nextOffset;
2007
+ baseOffset = objectOffset - decoded.distance;
2008
+ } else if (packedType === "ref-delta") {
2009
+ baseOid = entryBuffer.subarray(cursor, cursor + 20).toString("hex");
2010
+ cursor += 20;
2011
+ }
2012
+ return {
2013
+ packedType,
2014
+ declaredSize,
2015
+ headerLength: cursor,
2016
+ baseOffset,
2017
+ baseOid
2018
+ };
2019
+ };
2020
+ var readDeltaSize = (buffer, startOffset) => {
2021
+ let cursor = startOffset;
2022
+ let size = 0;
2023
+ let shift = 0;
2024
+ while (cursor < buffer.length) {
2025
+ const byte = buffer[cursor++];
2026
+ size |= (byte & 127) << shift;
2027
+ if ((byte & 128) === 0) return {
2028
+ size,
2029
+ nextOffset: cursor
2030
+ };
2031
+ shift += 7;
2032
+ }
2033
+ throw new Error("Invalid git delta size encoding");
2034
+ };
2035
+ var applyGitDelta = (baseContent, deltaContent) => {
2036
+ const baseSizeInfo = readDeltaSize(deltaContent, 0);
2037
+ if (baseSizeInfo.size !== baseContent.length) throw new Error(`Git delta base size mismatch: expected ${baseSizeInfo.size}, got ${baseContent.length}`);
2038
+ const targetSizeInfo = readDeltaSize(deltaContent, baseSizeInfo.nextOffset);
2039
+ const result = Buffer.alloc(targetSizeInfo.size);
2040
+ let deltaOffset = targetSizeInfo.nextOffset;
2041
+ let resultOffset = 0;
2042
+ while (deltaOffset < deltaContent.length) {
2043
+ const opcode = deltaContent[deltaOffset++];
2044
+ if ((opcode & 128) !== 0) {
2045
+ let copyOffset = 0;
2046
+ let copySize = 0;
2047
+ if (opcode & 1) copyOffset |= deltaContent[deltaOffset++];
2048
+ if (opcode & 2) copyOffset |= deltaContent[deltaOffset++] << 8;
2049
+ if (opcode & 4) copyOffset |= deltaContent[deltaOffset++] << 16;
2050
+ if (opcode & 8) copyOffset |= deltaContent[deltaOffset++] << 24;
2051
+ if (opcode & 16) copySize |= deltaContent[deltaOffset++];
2052
+ if (opcode & 32) copySize |= deltaContent[deltaOffset++] << 8;
2053
+ if (opcode & 64) copySize |= deltaContent[deltaOffset++] << 16;
2054
+ if (copySize === 0) copySize = 65536;
2055
+ baseContent.copy(result, resultOffset, copyOffset, copyOffset + copySize);
2056
+ resultOffset += copySize;
2057
+ continue;
2058
+ }
2059
+ if (opcode === 0) throw new Error("Invalid git delta opcode");
2060
+ deltaContent.copy(result, resultOffset, deltaOffset, deltaOffset + opcode);
2061
+ deltaOffset += opcode;
2062
+ resultOffset += opcode;
2063
+ }
2064
+ if (resultOffset !== result.length) throw new Error(`Git delta size mismatch: expected ${result.length}, got ${resultOffset}`);
2065
+ return result;
2066
+ };
2067
+ var inflatePackedObject = (compressedContent) => Buffer.from((0, zlib.inflateSync)(compressedContent));
2068
+ var parseTagTargetOid = (tagContent) => {
2069
+ const firstLineEnd = tagContent.indexOf(10);
2070
+ const firstLine = firstLineEnd >= 0 ? tagContent.subarray(0, firstLineEnd).toString("utf-8") : tagContent.toString("utf-8");
2071
+ const match = firstLine.match(/^object ([0-9a-f]{40})$/);
2072
+ if (!match) throw new Error(`Invalid annotated tag payload: ${firstLine}`);
2073
+ return match[1];
2074
+ };
2075
+ var parseTreeEntries = (treeContent) => {
2076
+ const entries = [];
2077
+ let offset = 0;
2078
+ while (offset < treeContent.length) {
2079
+ const modeEnd = treeContent.indexOf(32, offset);
2080
+ if (modeEnd < 0) throw new Error("Invalid tree entry mode");
2081
+ const nameEnd = treeContent.indexOf(0, modeEnd + 1);
2082
+ if (nameEnd < 0 || nameEnd + 21 > treeContent.length) throw new Error("Invalid tree entry name");
2083
+ entries.push({
2084
+ mode: treeContent.subarray(offset, modeEnd).toString("utf-8"),
2085
+ name: treeContent.subarray(modeEnd + 1, nameEnd).toString("utf-8"),
2086
+ oid: treeContent.subarray(nameEnd + 1, nameEnd + 21).toString("hex")
2087
+ });
2088
+ offset = nameEnd + 21;
2089
+ }
2090
+ return entries;
2091
+ };
2092
+ var createGitObjectResolver = async (repoPath) => {
2093
+ const actualGitDir = await getActualGitDir(repoPath);
2094
+ const resolvedObjects = /* @__PURE__ */ new Map();
2095
+ let packStorePromise;
2096
+ const getPackStore = async () => {
2097
+ if (!packStorePromise) packStorePromise = loadPackStore(actualGitDir);
2098
+ return packStorePromise;
2099
+ };
2100
+ const readPackedObject = async (location) => {
2101
+ var _location$packIndex$o, _location$packIndex$o2, _header$baseOid;
2102
+ const entryLength = location.nextOffset - location.offset;
2103
+ const entryBuffer = await readFixedRange(location.packIndex.fileHandle, location.offset, entryLength);
2104
+ const header = parsePackedEntryHeader(entryBuffer, location.offset);
2105
+ const compressedContent = entryBuffer.subarray(header.headerLength);
2106
+ if (header.packedType === "commit" || header.packedType === "tree" || header.packedType === "blob" || header.packedType === "tag") {
2107
+ const content = inflatePackedObject(compressedContent);
2108
+ if (content.length !== header.declaredSize) throw new Error(`Packed object size mismatch: ${location.oid} (expected ${header.declaredSize}, got ${content.length})`);
2109
+ return {
2110
+ oid: location.oid,
2111
+ type: header.packedType,
2112
+ content
2113
+ };
2114
+ }
2115
+ const deltaContent = inflatePackedObject(compressedContent);
2116
+ if (deltaContent.length !== header.declaredSize) throw new Error(`Packed delta size mismatch: ${location.oid} (expected ${header.declaredSize}, got ${deltaContent.length})`);
2117
+ 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 : (() => {
2118
+ throw new Error(`Missing ofs-delta base object at offset ${header.baseOffset}`);
2119
+ })()) : await readObject((_header$baseOid = header.baseOid) !== null && _header$baseOid !== void 0 ? _header$baseOid : (() => {
2120
+ throw new Error("Missing ref-delta base object id");
2121
+ })());
2122
+ const content = applyGitDelta(baseObject.content, deltaContent);
2123
+ return {
2124
+ oid: location.oid,
2125
+ type: baseObject.type,
2126
+ content
2127
+ };
2128
+ };
2129
+ const readObject = async (oid) => {
2130
+ const cachedObject = resolvedObjects.get(oid);
2131
+ if (cachedObject) return cachedObject;
2132
+ const objectPromise = (async () => {
2133
+ const looseObject = await readLooseObject(actualGitDir, oid);
2134
+ if (looseObject) return looseObject;
2135
+ const location = (await getPackStore()).objectByOid.get(oid);
2136
+ if (!location) throw new Error(`Git object not found: ${oid}`);
2137
+ return readPackedObject(location);
2138
+ })();
2139
+ resolvedObjects.set(oid, objectPromise);
2140
+ try {
2141
+ return await objectPromise;
2142
+ } catch (error) {
2143
+ resolvedObjects.delete(oid);
2144
+ throw error;
2145
+ }
2146
+ };
2147
+ return {
2148
+ close: async () => {
2149
+ if (!packStorePromise) return;
2150
+ const packStore = await packStorePromise;
2151
+ await Promise.allSettled(packStore.packs.map(async (pack) => {
2152
+ await pack.fileHandle.close();
2153
+ }));
2154
+ },
2155
+ readObject,
2156
+ resolveTagOidToCommit: async (tagOid) => {
2157
+ let currentOid = tagOid;
2158
+ const visitedOids = /* @__PURE__ */ new Set();
2159
+ while (true) {
2160
+ if (visitedOids.has(currentOid)) throw new Error(`Detected cyclic tag reference: ${currentOid}`);
2161
+ visitedOids.add(currentOid);
2162
+ const object = await readObject(currentOid);
2163
+ if (object.type !== "tag") return currentOid;
2164
+ currentOid = parseTagTargetOid(object.content);
2165
+ }
2166
+ }
2167
+ };
2168
+ };
2169
+ var runWithConcurrency = async (values, concurrency, worker) => {
2170
+ let nextIndex = 0;
2171
+ const runWorker = async () => {
2172
+ while (nextIndex < values.length) {
2173
+ const currentIndex = nextIndex;
2174
+ nextIndex += 1;
2175
+ await worker(values[currentIndex]);
2176
+ }
2177
+ };
2178
+ await Promise.all(Array.from({ length: Math.min(concurrency, Math.max(values.length, 1)) }, () => runWorker()));
2179
+ };
2180
+ /**
2181
+ * Resolve multiple tag object OIDs to their peeled commit OIDs.
2182
+ * @param repoPath - Repository path
2183
+ * @param tagOids - Tag or commit OIDs
2184
+ * @returns Map of tag object OID to peeled commit OID
2185
+ */
2186
+ var resolveTagOidsToCommits = async (repoPath, tagOids) => {
2187
+ const resolver = await createGitObjectResolver(repoPath);
2188
+ const result = /* @__PURE__ */ new Map();
2189
+ const uniqueTagOids = Array.from(new Set(tagOids));
2190
+ try {
2191
+ await runWithConcurrency(uniqueTagOids, LOOSE_TAG_RESOLUTION_CONCURRENCY, async (tagOid) => {
2192
+ result.set(tagOid, await resolver.resolveTagOidToCommit(tagOid));
2193
+ });
2194
+ } finally {
2195
+ await resolver.close();
2196
+ }
2197
+ return result;
2198
+ };
2199
+ var collectTreeFiles = async (resolver, treeOid, prefix, files) => {
2200
+ const treeObject = await resolver.readObject(treeOid);
2201
+ if (treeObject.type !== "tree") throw new Error(`Expected tree object: ${treeOid}`);
2202
+ for (const entry of parseTreeEntries(treeObject.content)) {
2203
+ const path$7 = prefix ? `${prefix}/${entry.name}` : entry.name;
2204
+ if (entry.mode === "40000") {
2205
+ await collectTreeFiles(resolver, entry.oid, path$7, files);
2206
+ continue;
2207
+ }
2208
+ if (entry.mode !== "160000") files.set(path$7, entry.oid);
2209
+ }
2210
+ };
2211
+ /**
2212
+ * Collect all tracked file blob OIDs under the specified tree.
2213
+ * @param repoPath - Repository path
2214
+ * @param treeOid - Tree object OID
2215
+ * @returns Map of repository-relative file path to blob OID
2216
+ */
2217
+ var listTreeFiles = async (repoPath, treeOid) => {
2218
+ const resolver = await createGitObjectResolver(repoPath);
2219
+ const files = /* @__PURE__ */ new Map();
2220
+ try {
2221
+ await collectTreeFiles(resolver, treeOid, "", files);
2222
+ } finally {
2223
+ await resolver.close();
2224
+ }
2225
+ return files;
2226
+ };
2227
+ //#endregion
1829
2228
  //#region src/fast-tags.ts
1830
2229
  /**
1831
2230
  * Fast tag listing implementation that reads tags directly from filesystem
@@ -1876,13 +2275,7 @@ var readLooseTags = async (refsTagsPath) => {
1876
2275
  * @returns Array of all tag names
1877
2276
  */
1878
2277
  var listTagsFast = async (repoPath) => {
1879
- const gitDir = (0, path.join)(repoPath, ".git");
1880
- const gitStat = await (0, fs_promises.stat)(gitDir).catch(() => null);
1881
- let actualGitDir = gitDir;
1882
- if (gitStat === null || gitStat === void 0 ? void 0 : gitStat.isFile()) {
1883
- const match = (await (0, fs_promises.readFile)(gitDir, "utf-8")).match(/^gitdir:\s*(.+)$/m);
1884
- if (match) actualGitDir = (0, path.isAbsolute)(match[1]) ? match[1] : (0, path.join)(repoPath, match[1]);
1885
- }
2278
+ const actualGitDir = await getActualGitDir(repoPath);
1886
2279
  const [packedTags, looseTags] = await Promise.all([parsePackedRefs((0, path.join)(actualGitDir, "packed-refs")), readLooseTags((0, path.join)(actualGitDir, "refs", "tags"))]);
1887
2280
  const allTags = new Set([...packedTags, ...looseTags]);
1888
2281
  return Array.from(allTags).sort();
@@ -1895,14 +2288,8 @@ var listTagsFast = async (repoPath) => {
1895
2288
  */
1896
2289
  var resolveTagsBatchWithCommit = async (repoPath, tagNames, logger) => {
1897
2290
  const startTime = Date.now();
1898
- const gitDir = (0, path.join)(repoPath, ".git");
1899
2291
  const result = /* @__PURE__ */ new Map();
1900
- const gitStat = await (0, fs_promises.stat)(gitDir).catch(() => null);
1901
- let actualGitDir = gitDir;
1902
- if (gitStat === null || gitStat === void 0 ? void 0 : gitStat.isFile()) {
1903
- const match = (await (0, fs_promises.readFile)(gitDir, "utf-8")).match(/^gitdir:\s*(.+)$/m);
1904
- if (match) actualGitDir = (0, path.isAbsolute)(match[1]) ? match[1] : (0, path.join)(repoPath, match[1]);
1905
- }
2292
+ const actualGitDir = await getActualGitDir(repoPath);
1906
2293
  const tagSet = new Set(tagNames);
1907
2294
  const packedRefsStart = Date.now();
1908
2295
  try {
@@ -1929,28 +2316,28 @@ var resolveTagsBatchWithCommit = async (repoPath, tagNames, logger) => {
1929
2316
  const remainingTags = tagNames.filter((tag) => !result.has(tag));
1930
2317
  if (remainingTags.length > 0) {
1931
2318
  const looseRefsStart = Date.now();
1932
- await Promise.all(remainingTags.map(async (tagName) => {
2319
+ const looseTagEntries = (await Promise.all(remainingTags.map(async (tagName) => {
1933
2320
  const looseRefPath = (0, path.join)(actualGitDir, "refs", "tags", tagName);
1934
2321
  try {
1935
- const oid = (await (0, fs_promises.readFile)(looseRefPath, "utf-8")).trim();
1936
- let commitOid = oid;
1937
- try {
1938
- const { execSync } = require("child_process");
1939
- if (execSync(`git -C "${repoPath}" cat-file -t ${oid}`, { encoding: "utf-8" }).trim() === "tag") {
1940
- const objectMatch = execSync(`git -C "${repoPath}" cat-file -p ${oid}`, { encoding: "utf-8" }).match(/^object ([0-9a-f]{40})$/m);
1941
- if (objectMatch) commitOid = objectMatch[1];
1942
- }
1943
- } catch (error) {
1944
- logger.debug(`[fast-tags] Could not determine object type for ${tagName}: ${error}`);
1945
- }
2322
+ return {
2323
+ tagName,
2324
+ oid: (await (0, fs_promises.readFile)(looseRefPath, "utf-8")).trim()
2325
+ };
2326
+ } catch (error) {
2327
+ if (error.code !== "ENOENT") throw error;
2328
+ return;
2329
+ }
2330
+ }))).filter((entry) => entry !== void 0);
2331
+ if (looseTagEntries.length > 0) {
2332
+ const commitOids = await resolveTagOidsToCommits(repoPath, looseTagEntries.map((entry) => entry.oid));
2333
+ for (const { tagName, oid } of looseTagEntries) {
2334
+ var _commitOids$get;
1946
2335
  result.set(tagName, {
1947
2336
  oid,
1948
- commitOid
2337
+ commitOid: (_commitOids$get = commitOids.get(oid)) !== null && _commitOids$get !== void 0 ? _commitOids$get : oid
1949
2338
  });
1950
- } catch (error) {
1951
- if (error.code !== "ENOENT") throw error;
1952
2339
  }
1953
- }));
2340
+ }
1954
2341
  logger.debug(`[fast-tags] read loose refs: ${Date.now() - looseRefsStart}ms`);
1955
2342
  }
1956
2343
  const totalTime = Date.now() - startTime;
@@ -2163,7 +2550,8 @@ var getCommit = async (repositoryPath, hash) => {
2163
2550
  shortHash: commit.oid.substring(0, 7),
2164
2551
  date: (/* @__PURE__ */ new Date(commit.commit.author.timestamp * 1e3)).toISOString(),
2165
2552
  message: commit.commit.message.trim(),
2166
- parents: commit.commit.parent || []
2553
+ parents: commit.commit.parent || [],
2554
+ tree: commit.commit.tree
2167
2555
  };
2168
2556
  } catch (_unused) {
2169
2557
  return;
@@ -2191,7 +2579,8 @@ var getCurrentCommit = async (repositoryPath) => {
2191
2579
  shortHash: commit.oid.substring(0, 7),
2192
2580
  date: (/* @__PURE__ */ new Date(commit.commit.author.timestamp * 1e3)).toISOString(),
2193
2581
  message: commit.commit.message.trim(),
2194
- parents: commit.commit.parent || []
2582
+ parents: commit.commit.parent || [],
2583
+ tree: commit.commit.tree
2195
2584
  };
2196
2585
  } catch (_unused2) {
2197
2586
  return;
@@ -2231,94 +2620,133 @@ var getRelatedBranches = async (repositoryPath, commitHash) => {
2231
2620
  return [];
2232
2621
  }
2233
2622
  };
2234
- /**
2235
- * Check if the repository has modified files (following RelaxVersioner logic).
2236
- * Checks for staged files, unstaged files, and untracked files (respecting .gitignore).
2237
- * @param repositoryPath - Local Git repository directory
2238
- * @returns Modified files
2239
- */
2240
- var isModifiedFile = ([, head, workdir, stage]) => {
2241
- return workdir === 2 || stage === 2 || stage === 3 || head === 1 && workdir === 0 || head === 0 && workdir === 1;
2242
- };
2243
- var getStatusRow = async (filepath, entries) => {
2244
- const [head, workdir, stage] = entries;
2245
- const [headType, workdirType, stageType] = await Promise.all([
2246
- head ? head.type() : void 0,
2247
- workdir ? workdir.type() : void 0,
2248
- stage ? stage.type() : void 0
2249
- ]);
2250
- const isBlob = [
2251
- headType,
2252
- workdirType,
2253
- stageType
2254
- ].includes("blob");
2255
- if ((headType === "tree" || headType === "special") && !isBlob) return;
2256
- if (headType === "commit") return;
2257
- if ((workdirType === "tree" || workdirType === "special") && !isBlob) return;
2258
- if (stageType === "commit") return;
2259
- if ((stageType === "tree" || stageType === "special") && !isBlob) return;
2260
- const headOid = headType === "blob" ? await head.oid() : void 0;
2261
- const stageOid = stageType === "blob" ? await stage.oid() : void 0;
2262
- let workdirOid;
2263
- if (headType !== "blob" && workdirType === "blob" && stageType !== "blob") workdirOid = "42";
2264
- else if (workdirType === "blob") workdirOid = await workdir.oid();
2265
- const entry = [
2266
- void 0,
2267
- headOid,
2268
- workdirOid,
2269
- stageOid
2270
- ];
2271
- const statusValues = entry.map((value) => entry.indexOf(value));
2272
- return [
2273
- filepath,
2274
- statusValues[1],
2275
- statusValues[2],
2276
- statusValues[3]
2277
- ];
2278
- };
2279
- var reduceModifiedFiles = async (parent, children) => {
2280
- const modifiedFiles = parent ? [parent] : [];
2281
- for (const child of children) modifiedFiles.push(...child);
2282
- return modifiedFiles;
2283
- };
2284
- var iterateSequentially = async (walk, children) => {
2285
- const results = [];
2286
- for (const child of children) results.push(await walk(child));
2287
- return results;
2288
- };
2289
- var getModifiedFiles = async (repositoryPath) => {
2623
+ var parseGitIndex = async (gitDir) => {
2290
2624
  try {
2291
- return await isomorphic_git.walk({
2292
- fs: fs_promises.default,
2293
- dir: repositoryPath,
2294
- trees: [
2295
- isomorphic_git.TREE({ ref: "HEAD" }),
2296
- isomorphic_git.WORKDIR(),
2297
- isomorphic_git.STAGE()
2298
- ],
2299
- map: async (filepath, entries) => {
2300
- const [head, workdir, stage] = entries;
2301
- if (!head && !stage && workdir) {
2302
- if (await isomorphic_git.isIgnored({
2303
- fs: fs_promises.default,
2304
- dir: repositoryPath,
2305
- filepath
2306
- })) return null;
2625
+ const buffer = await fs_promises.default.readFile((0, path.join)(gitDir, "index"));
2626
+ if (buffer.subarray(0, 4).toString("ascii") !== "DIRC") throw new Error("Unsupported git index signature");
2627
+ const version = buffer.readUInt32BE(4);
2628
+ if (version !== 2 && version !== 3) throw new Error(`Unsupported git index version: ${version}`);
2629
+ const entryCount = buffer.readUInt32BE(8);
2630
+ let offset = 12;
2631
+ const entries = /* @__PURE__ */ new Map();
2632
+ for (let index = 0; index < entryCount; index++) {
2633
+ const entryStart = offset;
2634
+ const size = buffer.readUInt32BE(entryStart + 36);
2635
+ const oid = buffer.subarray(entryStart + 40, entryStart + 60).toString("hex");
2636
+ const flags = buffer.readUInt16BE(entryStart + 60);
2637
+ const stage = flags >> 12 & 3;
2638
+ offset = entryStart + 62;
2639
+ if (version >= 3 && (flags & 16384) !== 0) offset += 2;
2640
+ const pathEnd = buffer.indexOf(0, offset);
2641
+ if (pathEnd < 0) throw new Error("Invalid git index path entry");
2642
+ const path$3 = buffer.subarray(offset, pathEnd).toString("utf-8");
2643
+ offset = pathEnd + 1;
2644
+ while ((offset - entryStart) % 8 !== 0) offset += 1;
2645
+ entries.set(path$3, {
2646
+ path: path$3,
2647
+ oid,
2648
+ size,
2649
+ stage
2650
+ });
2651
+ }
2652
+ return entries;
2653
+ } catch (error) {
2654
+ if (error.code === "ENOENT") return /* @__PURE__ */ new Map();
2655
+ throw error;
2656
+ }
2657
+ };
2658
+ var listTrackedDirectories = (indexEntries) => {
2659
+ const directories = new Set([""]);
2660
+ for (const path$4 of indexEntries.keys()) {
2661
+ const segments = path$4.split("/");
2662
+ let currentPath = "";
2663
+ for (let index = 0; index < segments.length - 1; index++) {
2664
+ currentPath = currentPath ? `${currentPath}/${segments[index]}` : segments[index];
2665
+ directories.add(currentPath);
2666
+ }
2667
+ }
2668
+ return directories;
2669
+ };
2670
+ var listWorkingDirectoryFiles = async (repositoryPath, trackedDirectories, relativePath = "") => {
2671
+ const directoryPath = relativePath ? (0, path.join)(repositoryPath, relativePath) : repositoryPath;
2672
+ const entries = await fs_promises.default.readdir(directoryPath, { withFileTypes: true });
2673
+ const files = [];
2674
+ for (const entry of entries) {
2675
+ if (entry.name === ".git") continue;
2676
+ const entryPath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
2677
+ if (entry.isDirectory()) {
2678
+ if (!trackedDirectories.has(entryPath)) {
2679
+ if (await isomorphic_git.isIgnored({
2680
+ fs: fs_promises.default,
2681
+ dir: repositoryPath,
2682
+ filepath: entryPath
2683
+ })) continue;
2684
+ }
2685
+ files.push(...await listWorkingDirectoryFiles(repositoryPath, trackedDirectories, entryPath));
2686
+ continue;
2687
+ }
2688
+ if (entry.isFile() || entry.isSymbolicLink()) files.push(entryPath);
2689
+ }
2690
+ return files;
2691
+ };
2692
+ var calculateBlobOid = async (filePath) => {
2693
+ const content = await fs_promises.default.readFile(filePath);
2694
+ return (0, crypto$1.createHash)("sha1").update(`blob ${content.length}\0`).update(content).digest("hex");
2695
+ };
2696
+ var getModifiedFiles = async (repositoryPath, headTreeOid) => {
2697
+ try {
2698
+ const gitDir = await getActualGitDir(repositoryPath);
2699
+ const [headFiles, indexEntries] = await Promise.all([listTreeFiles(repositoryPath, headTreeOid), parseGitIndex(gitDir)]);
2700
+ const workdirFiles = await listWorkingDirectoryFiles(repositoryPath, listTrackedDirectories(indexEntries));
2701
+ const modifiedFiles = /* @__PURE__ */ new Map();
2702
+ const rememberModifiedFile = (path$5, reason) => {
2703
+ if (!modifiedFiles.has(path$5)) modifiedFiles.set(path$5, {
2704
+ path: path$5,
2705
+ reason
2706
+ });
2707
+ };
2708
+ for (const [path$6, headOid] of headFiles.entries()) {
2709
+ const indexEntry = indexEntries.get(path$6);
2710
+ if (!indexEntry) rememberModifiedFile(path$6, "staged");
2711
+ else if (indexEntry.stage !== 0 || indexEntry.oid !== headOid) rememberModifiedFile(path$6, "staged");
2712
+ }
2713
+ for (const indexEntry of indexEntries.values()) {
2714
+ if (!headFiles.has(indexEntry.path)) rememberModifiedFile(indexEntry.path, "staged");
2715
+ const absolutePath = (0, path.join)(repositoryPath, indexEntry.path);
2716
+ try {
2717
+ const stats = await fs_promises.default.lstat(absolutePath);
2718
+ if (!stats.isFile() && !stats.isSymbolicLink()) {
2719
+ rememberModifiedFile(indexEntry.path, "worktree");
2720
+ continue;
2307
2721
  }
2308
- const statusRow = await getStatusRow(filepath, entries);
2309
- if (!statusRow || !isModifiedFile(statusRow)) return;
2310
- return statusRow;
2311
- },
2312
- reduce: reduceModifiedFiles,
2313
- iterate: iterateSequentially
2314
- });
2722
+ if (indexEntry.stage !== 0) {
2723
+ rememberModifiedFile(indexEntry.path, "staged");
2724
+ continue;
2725
+ }
2726
+ if (indexEntry.size !== stats.size || await calculateBlobOid(absolutePath) !== indexEntry.oid) rememberModifiedFile(indexEntry.path, "worktree");
2727
+ } catch (error) {
2728
+ if (error.code === "ENOENT") {
2729
+ rememberModifiedFile(indexEntry.path, "worktree");
2730
+ continue;
2731
+ }
2732
+ throw error;
2733
+ }
2734
+ }
2735
+ const trackedPaths = new Set(indexEntries.keys());
2736
+ for (const filepath of workdirFiles) {
2737
+ if (trackedPaths.has(filepath)) continue;
2738
+ if (!await isomorphic_git.isIgnored({
2739
+ fs: fs_promises.default,
2740
+ dir: repositoryPath,
2741
+ filepath
2742
+ })) rememberModifiedFile(filepath, "untracked");
2743
+ }
2744
+ return Array.from(modifiedFiles.values());
2315
2745
  } catch (_unused5) {
2316
2746
  return [];
2317
2747
  }
2318
2748
  };
2319
- var formatModifiedFile = (modifiedFile) => {
2320
- return `'${modifiedFile[0]}':${modifiedFile[1]}:${modifiedFile[2]}:${modifiedFile[3]}`;
2321
- };
2749
+ var formatModifiedFile = (modifiedFile) => `'${modifiedFile.path}':${modifiedFile.reason}`;
2322
2750
  /**
2323
2751
  * Lookup version label recursively core analyzer
2324
2752
  * @param cwd - The directory to check
@@ -2418,7 +2846,7 @@ var getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logger)
2418
2846
  metadata.git = gitMetadata;
2419
2847
  if (version) {
2420
2848
  if (checkWorkingDirectoryStatus) {
2421
- const modifiedFiles = await getModifiedFiles(gitRootPath);
2849
+ const modifiedFiles = await getModifiedFiles(gitRootPath, currentCommit.tree);
2422
2850
  if (modifiedFiles.length >= 1) {
2423
2851
  const newVersion = incrementLastVersionComponent(version);
2424
2852
  logger.debug(`Increased git version by detected modified items: ${formatVersion(version)} ---> ${formatVersion(newVersion)}, Files=[${modifiedFiles.map(formatModifiedFile).join(", ")}]`);