screw-up 1.6.0 → 1.8.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.
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.6.0
3
+ * version: 1.8.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: 10c04af9c9b127002592d48cbb6ec18cfe5048bb
8
+ * git.commit.hash: da96533e5128033ff7a45d59b1cee39e0e819533
9
9
  */
10
10
  "use strict";
11
11
  const fs = require("fs");
@@ -13,8 +13,6 @@ const fs$1 = require("fs/promises");
13
13
  const path = require("path");
14
14
  const glob = require("glob");
15
15
  const git = require("isomorphic-git");
16
- const crypto = require("crypto");
17
- const os = require("os");
18
16
  function _interopNamespaceDefault(e) {
19
17
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
20
18
  if (e) {
@@ -1671,397 +1669,195 @@ function requireDayjs_min() {
1671
1669
  }
1672
1670
  var dayjs_minExports = requireDayjs_min();
1673
1671
  const dayjs = /* @__PURE__ */ getDefaultExportFromCjs(dayjs_minExports);
1674
- const CLEANUP_DELETE_AGE_MS = 10 * 24 * 60 * 60 * 1e3;
1675
- const getCachePath = (repoPath) => {
1676
- const absoluteRepoPath = path.resolve(repoPath);
1677
- const pathHash = crypto.createHash("sha1").update(absoluteRepoPath).digest("hex");
1678
- return path.join(
1679
- os.homedir(),
1680
- ".cache",
1681
- "screw-up",
1682
- "tag-cache",
1683
- `${pathHash}.json`
1684
- );
1685
- };
1686
- const buildCacheValidation = async (repoPath) => {
1687
- const tags = await git__namespace.listTags({ fs: fs$1, dir: repoPath });
1688
- const tagListHash = crypto.createHash("sha256").update(tags.sort().join("\n")).digest("hex");
1689
- const validation = {
1690
- tagListHash,
1691
- tagCount: tags.length
1692
- };
1693
- try {
1694
- const packedRefsPath = path.join(repoPath, ".git", "packed-refs");
1695
- const stats = await fs$1.stat(packedRefsPath);
1696
- validation.packedRefsMtime = stats.mtimeMs;
1697
- } catch (e) {
1698
- }
1699
- try {
1700
- const refsTagsPath = path.join(repoPath, ".git", "refs", "tags");
1701
- const stats = await fs$1.stat(refsTagsPath);
1702
- validation.refsTagsMtime = stats.mtimeMs;
1703
- } catch (e) {
1704
- }
1705
- return validation;
1706
- };
1707
- const isCacheValid = async (cachedData, repoPath) => {
1672
+ const parsePackedRefs = async (packedRefsPath) => {
1708
1673
  try {
1709
- const currentTags = await git__namespace.listTags({ fs: fs$1, dir: repoPath });
1710
- if (currentTags.length !== cachedData.validation.tagCount) {
1711
- return false;
1712
- }
1713
- const tagListHash = crypto.createHash("sha256").update(currentTags.sort().join("\n")).digest("hex");
1714
- if (cachedData.validation.tagListHash !== tagListHash) {
1715
- return false;
1716
- }
1717
- if (cachedData.validation.packedRefsMtime !== void 0) {
1718
- try {
1719
- const packedRefsPath = path.join(repoPath, ".git", "packed-refs");
1720
- const stats = await fs$1.stat(packedRefsPath);
1721
- if (stats.mtimeMs > cachedData.timestamp) {
1722
- return false;
1674
+ const content = await fs$1.readFile(packedRefsPath, "utf-8");
1675
+ const lines = content.split("\n");
1676
+ const tags = [];
1677
+ for (const line2 of lines) {
1678
+ if (line2.startsWith("#") || !line2.trim()) continue;
1679
+ const match = line2.match(/^[0-9a-f]{40}\s+refs\/tags\/(.+)$/);
1680
+ if (match) {
1681
+ const tagName = match[1];
1682
+ if (!tagName.endsWith("^{}")) {
1683
+ tags.push(tagName);
1723
1684
  }
1724
- } catch (e) {
1725
1685
  }
1726
1686
  }
1727
- if (cachedData.validation.refsTagsMtime !== void 0) {
1728
- try {
1729
- const refsTagsPath = path.join(repoPath, ".git", "refs", "tags");
1730
- const stats = await fs$1.stat(refsTagsPath);
1731
- if (stats.mtimeMs > cachedData.timestamp) {
1732
- return false;
1733
- }
1734
- } catch (e) {
1735
- }
1687
+ return tags;
1688
+ } catch (error) {
1689
+ if (error.code === "ENOENT") {
1690
+ return [];
1736
1691
  }
1737
- return true;
1738
- } catch (e) {
1739
- return false;
1692
+ throw error;
1740
1693
  }
1741
1694
  };
1742
- const loadCachedTags = async (repoPath) => {
1695
+ const readLooseTags = async (refsTagsPath) => {
1743
1696
  try {
1744
- const cachePath = getCachePath(repoPath);
1745
- const data = await fs$1.readFile(cachePath, "utf-8");
1746
- const cachedData = JSON.parse(data);
1747
- if (cachedData.version !== "1.0.0") {
1748
- return null;
1749
- }
1750
- return cachedData;
1751
- } catch (e) {
1752
- return null;
1753
- }
1754
- };
1755
- const saveCachedTags = async (repoPath, tagCache, validation) => {
1756
- const cachePath = getCachePath(repoPath);
1757
- const cacheDir = path.dirname(cachePath);
1758
- await fs$1.mkdir(cacheDir, { recursive: true });
1759
- const randomSuffix = crypto.randomBytes(8).toString("hex");
1760
- const tempPath = cachePath.replace(".json", `_${randomSuffix}.json`);
1761
- const data = {
1762
- version: "1.0.0",
1763
- timestamp: Date.now(),
1764
- repository: {
1765
- path: repoPath
1766
- },
1767
- validation,
1768
- tagCache: {
1769
- commitToTags: Object.fromEntries(tagCache.commitToTags)
1697
+ const entries = await fs$1.readdir(refsTagsPath, { withFileTypes: true });
1698
+ const tags = [];
1699
+ for (const entry of entries) {
1700
+ if (entry.isFile()) {
1701
+ tags.push(entry.name);
1702
+ }
1770
1703
  }
1771
- };
1772
- try {
1773
- await fs$1.writeFile(tempPath, JSON.stringify(data, null, 2), "utf-8");
1774
- await fs$1.rename(tempPath, cachePath);
1704
+ return tags;
1775
1705
  } catch (error) {
1776
- try {
1777
- await fs$1.unlink(tempPath);
1778
- } catch (e) {
1706
+ if (error.code === "ENOENT") {
1707
+ return [];
1779
1708
  }
1780
1709
  throw error;
1781
1710
  }
1782
1711
  };
1783
- const reconstructTagCache = (cachedData) => {
1784
- return {
1785
- commitToTags: new Map(Object.entries(cachedData.tagCache.commitToTags)),
1786
- initialized: true
1787
- };
1712
+ const listTagsFast = async (repoPath) => {
1713
+ const gitDir = path.join(repoPath, ".git");
1714
+ const gitStat = await fs$1.stat(gitDir).catch(() => null);
1715
+ let actualGitDir = gitDir;
1716
+ if (gitStat == null ? void 0 : gitStat.isFile()) {
1717
+ const content = await fs$1.readFile(gitDir, "utf-8");
1718
+ const match = content.match(/^gitdir:\s*(.+)$/m);
1719
+ if (match) {
1720
+ actualGitDir = path.isAbsolute(match[1]) ? match[1] : path.join(repoPath, match[1]);
1721
+ }
1722
+ }
1723
+ const [packedTags, looseTags] = await Promise.all([
1724
+ parsePackedRefs(path.join(actualGitDir, "packed-refs")),
1725
+ readLooseTags(path.join(actualGitDir, "refs", "tags"))
1726
+ ]);
1727
+ const allTags = /* @__PURE__ */ new Set([...packedTags, ...looseTags]);
1728
+ return Array.from(allTags).sort();
1788
1729
  };
1789
- const cleanupOldCacheFiles = async (currentCachePath, currentTimestamp) => {
1790
- let deletedCount = 0;
1730
+ const resolveTagsBatchWithCommit = async (repoPath, tagNames, logger) => {
1731
+ const startTime = Date.now();
1732
+ const gitDir = path.join(repoPath, ".git");
1733
+ const result = /* @__PURE__ */ new Map();
1734
+ const gitStat = await fs$1.stat(gitDir).catch(() => null);
1735
+ let actualGitDir = gitDir;
1736
+ if (gitStat == null ? void 0 : gitStat.isFile()) {
1737
+ const content = await fs$1.readFile(gitDir, "utf-8");
1738
+ const match = content.match(/^gitdir:\s*(.+)$/m);
1739
+ if (match) {
1740
+ actualGitDir = path.isAbsolute(match[1]) ? match[1] : path.join(repoPath, match[1]);
1741
+ }
1742
+ }
1743
+ const tagSet = new Set(tagNames);
1744
+ const packedRefsStart = Date.now();
1791
1745
  try {
1792
- const cacheDir = path.dirname(currentCachePath);
1793
- const currentFileName = path.basename(currentCachePath);
1794
- const files = await fs$1.readdir(cacheDir);
1795
- await Promise.all(
1796
- files.map(async (fileName) => {
1797
- if (!fileName.endsWith(".json") || fileName === currentFileName) {
1798
- return;
1746
+ const content = await fs$1.readFile(
1747
+ path.join(actualGitDir, "packed-refs"),
1748
+ "utf-8"
1749
+ );
1750
+ const lines = content.split("\n");
1751
+ for (let i = 0; i < lines.length; i++) {
1752
+ const line2 = lines[i];
1753
+ if (line2.startsWith("#") || !line2.trim()) continue;
1754
+ const match = line2.match(/^([0-9a-f]{40})\s+refs\/tags\/(.+)$/);
1755
+ if (match && tagSet.has(match[2])) {
1756
+ const tagName = match[2];
1757
+ const oid = match[1];
1758
+ let commitOid = oid;
1759
+ if (i + 1 < lines.length && lines[i + 1].startsWith("^")) {
1760
+ commitOid = lines[i + 1].substring(1, 41);
1799
1761
  }
1800
- const filePath = path.join(cacheDir, fileName);
1762
+ result.set(tagName, { oid, commitOid });
1763
+ }
1764
+ }
1765
+ } catch (error) {
1766
+ if (error.code !== "ENOENT") {
1767
+ throw error;
1768
+ }
1769
+ }
1770
+ logger.debug(
1771
+ `[fast-tags] read packed-refs: ${Date.now() - packedRefsStart}ms`
1772
+ );
1773
+ const remainingTags = tagNames.filter((tag) => !result.has(tag));
1774
+ if (remainingTags.length > 0) {
1775
+ const looseRefsStart = Date.now();
1776
+ await Promise.all(
1777
+ remainingTags.map(async (tagName) => {
1778
+ const looseRefPath = path.join(actualGitDir, "refs", "tags", tagName);
1801
1779
  try {
1802
- const stats = await fs$1.stat(filePath);
1803
- const fileAge = currentTimestamp - stats.mtimeMs;
1804
- if (fileAge > CLEANUP_DELETE_AGE_MS) {
1805
- await fs$1.unlink(filePath);
1806
- deletedCount++;
1780
+ const hash = await fs$1.readFile(looseRefPath, "utf-8");
1781
+ const oid = hash.trim();
1782
+ let commitOid = oid;
1783
+ try {
1784
+ const { execSync } = require("child_process");
1785
+ const objectType = execSync(
1786
+ `git -C "${repoPath}" cat-file -t ${oid}`,
1787
+ { encoding: "utf-8" }
1788
+ ).trim();
1789
+ if (objectType === "tag") {
1790
+ const tagContent = execSync(
1791
+ `git -C "${repoPath}" cat-file -p ${oid}`,
1792
+ { encoding: "utf-8" }
1793
+ );
1794
+ const objectMatch = tagContent.match(/^object ([0-9a-f]{40})$/m);
1795
+ if (objectMatch) {
1796
+ commitOid = objectMatch[1];
1797
+ }
1798
+ }
1799
+ } catch (error) {
1800
+ logger.debug(
1801
+ `[fast-tags] Could not determine object type for ${tagName}: ${error}`
1802
+ );
1803
+ }
1804
+ result.set(tagName, { oid, commitOid });
1805
+ } catch (error) {
1806
+ if (error.code !== "ENOENT") {
1807
+ throw error;
1807
1808
  }
1808
- } catch (e) {
1809
1809
  }
1810
1810
  })
1811
1811
  );
1812
- } catch (e) {
1813
- }
1814
- return deletedCount;
1815
- };
1816
- const calculateTagDiff = (cachedTags, currentTagList) => {
1817
- const cachedTagNames = /* @__PURE__ */ new Set();
1818
- for (const tags of cachedTags.values()) {
1819
- for (const tag of tags) {
1820
- cachedTagNames.add(tag.name);
1821
- }
1822
- }
1823
- const currentSet = new Set(currentTagList);
1824
- const added = [];
1825
- const unchanged = [];
1826
- for (const tagName of currentTagList) {
1827
- if (cachedTagNames.has(tagName)) {
1828
- unchanged.push(tagName);
1829
- } else {
1830
- added.push(tagName);
1831
- }
1832
- }
1833
- const deleted = [];
1834
- for (const tagName of cachedTagNames) {
1835
- if (!currentSet.has(tagName)) {
1836
- deleted.push(tagName);
1837
- }
1838
- }
1839
- return { added, deleted, unchanged };
1840
- };
1841
- const removeTagsFromCache = (cache, tagNames) => {
1842
- const tagNamesToRemove = new Set(tagNames);
1843
- const newCache = /* @__PURE__ */ new Map();
1844
- for (const [commitHash, tags] of cache.entries()) {
1845
- const filteredTags = tags.filter((tag) => !tagNamesToRemove.has(tag.name));
1846
- if (filteredTags.length > 0) {
1847
- newCache.set(commitHash, filteredTags);
1848
- }
1849
- }
1850
- return newCache;
1851
- };
1852
- const addTagsToCache = (cache, newTags) => {
1853
- const newCache = new Map(cache);
1854
- for (const tag of newTags) {
1855
- const existing = newCache.get(tag.hash) || [];
1856
- const updated = [...existing, tag];
1857
- updated.sort((a, b) => a.name.localeCompare(b.name));
1858
- newCache.set(tag.hash, updated);
1859
- }
1860
- return newCache;
1861
- };
1862
- const updateTagsInCache = (cache, tagNames, updatedTags) => {
1863
- let newCache = removeTagsFromCache(cache, tagNames);
1864
- newCache = addTagsToCache(newCache, updatedTags);
1865
- return newCache;
1866
- };
1867
- const resolveTagToCommit = async (repoPath, tagOid) => {
1868
- var _a;
1869
- try {
1870
- const tagObject = await git__namespace.readTag({
1871
- fs: fs$1,
1872
- dir: repoPath,
1873
- oid: tagOid
1874
- });
1875
- if ((_a = tagObject == null ? void 0 : tagObject.tag) == null ? void 0 : _a.object) {
1876
- return tagObject.tag.object;
1877
- }
1878
- } catch (e) {
1812
+ logger.debug(
1813
+ `[fast-tags] read loose refs: ${Date.now() - looseRefsStart}ms`
1814
+ );
1879
1815
  }
1880
- return tagOid;
1881
- };
1882
- const getTagsInfo = async (repoPath, tagNames, parseVersion2) => {
1883
- const result = [];
1884
- await Promise.all(
1885
- tagNames.map(async (tagName) => {
1886
- try {
1887
- const oid = await git__namespace.resolveRef({
1888
- fs: fs$1,
1889
- dir: repoPath,
1890
- ref: `refs/tags/${tagName}`
1891
- });
1892
- const commitHash = await resolveTagToCommit(repoPath, oid);
1893
- const version2 = parseVersion2(tagName);
1894
- result.push({
1895
- name: tagName,
1896
- hash: commitHash,
1897
- version: version2
1898
- });
1899
- } catch (error) {
1900
- console.warn(`Failed to get info for tag ${tagName}:`, error);
1901
- }
1902
- })
1903
- );
1816
+ const totalTime = Date.now() - startTime;
1817
+ logger.debug(`[fast-tags] resolveTagsBatchWithCommit total: ${totalTime}ms`);
1818
+ logger.debug(`[fast-tags] Resolved ${result.size}/${tagNames.length} tags`);
1904
1819
  return result;
1905
1820
  };
1906
- const buildCompleteTagCache = async (repoPath, parseVersion2) => {
1821
+ const buildCompleteTagCache = async (repoPath, parseVersion2, logger) => {
1822
+ const totalStart = Date.now();
1907
1823
  const cache = /* @__PURE__ */ new Map();
1908
- const tags = await git__namespace.listTags({ fs: fs$1, dir: repoPath });
1909
- await Promise.all(
1910
- tags.map(async (tagName) => {
1911
- const oid = await git__namespace.resolveRef({
1912
- fs: fs$1,
1913
- dir: repoPath,
1914
- ref: `refs/tags/${tagName}`
1915
- });
1916
- const commitHash = await resolveTagToCommit(repoPath, oid);
1917
- const version2 = parseVersion2(tagName);
1918
- const tagInfo = {
1919
- name: tagName,
1920
- hash: commitHash,
1921
- version: version2
1922
- };
1923
- if (!cache.has(commitHash)) {
1924
- cache.set(commitHash, []);
1925
- }
1926
- cache.get(commitHash).push(tagInfo);
1927
- })
1824
+ const listStart = Date.now();
1825
+ const tags = await listTagsFast(repoPath);
1826
+ logger.debug(`[git-ops] listTagsFast: ${Date.now() - listStart}ms`);
1827
+ logger.debug(`[git-ops] Found ${tags.length} tags`);
1828
+ const resolveStart = Date.now();
1829
+ const tagData = await resolveTagsBatchWithCommit(repoPath, tags, logger);
1830
+ logger.debug(
1831
+ `[git-ops] resolveTagsBatchWithCommit: ${Date.now() - resolveStart}ms`
1928
1832
  );
1833
+ const buildStart = Date.now();
1834
+ for (const tagName of tags) {
1835
+ const data = tagData.get(tagName);
1836
+ if (!data) continue;
1837
+ const { commitOid } = data;
1838
+ const version2 = parseVersion2(tagName);
1839
+ const tagInfo = {
1840
+ name: tagName,
1841
+ hash: commitOid,
1842
+ version: version2
1843
+ };
1844
+ if (!cache.has(commitOid)) {
1845
+ cache.set(commitOid, []);
1846
+ }
1847
+ cache.get(commitOid).push(tagInfo);
1848
+ }
1849
+ logger.debug(`[git-ops] build cache map: ${Date.now() - buildStart}ms`);
1850
+ const sortStart = Date.now();
1929
1851
  for (const tags2 of cache.values()) {
1930
1852
  tags2.sort((a, b) => a.name.localeCompare(b.name));
1931
1853
  }
1932
- return cache;
1933
- };
1934
- const hasTagMoved = async (repoPath, tagName, cachedCommit) => {
1935
- try {
1936
- const oid = await git__namespace.resolveRef({
1937
- fs: fs$1,
1938
- dir: repoPath,
1939
- ref: `refs/tags/${tagName}`
1940
- });
1941
- const currentCommit = await resolveTagToCommit(repoPath, oid);
1942
- return currentCommit !== cachedCommit;
1943
- } catch (e) {
1944
- return true;
1945
- }
1946
- };
1947
- const findModifiedTags = async (repoPath, tagNames, cache) => {
1948
- const modified = [];
1949
- await Promise.all(
1950
- tagNames.map(async (tagName) => {
1951
- let cachedCommit;
1952
- for (const [commit, tags] of cache.entries()) {
1953
- const tag = tags.find((t) => t.name === tagName);
1954
- if (tag) {
1955
- cachedCommit = commit;
1956
- break;
1957
- }
1958
- }
1959
- if (cachedCommit) {
1960
- const moved = await hasTagMoved(repoPath, tagName, cachedCommit);
1961
- if (moved) {
1962
- modified.push(tagName);
1963
- }
1964
- }
1965
- })
1966
- );
1967
- return modified;
1968
- };
1969
- const loadOrBuildTagCache = async (repoPath, parseVersion2, logger) => {
1970
- const startTime = Date.now();
1971
- const cachedData = await loadCachedTags(repoPath);
1972
- const currentTags = await git__namespace.listTags({ fs: fs$1, dir: repoPath });
1973
- if (cachedData && await isCacheValid(cachedData, repoPath)) {
1974
- logger.debug(`Cache valid, performing differential update...`);
1975
- const cache = reconstructTagCache(cachedData);
1976
- const stats = await performDifferentialUpdate(
1977
- repoPath,
1978
- cache.commitToTags,
1979
- currentTags,
1980
- parseVersion2,
1981
- logger
1982
- );
1983
- const validation = await buildCacheValidation(repoPath);
1984
- await saveCachedTags(repoPath, cache, validation);
1985
- if (cachedData && Date.now() - cachedData.timestamp > 24 * 60 * 60 * 1e3) {
1986
- try {
1987
- const cachePath = getCachePath(repoPath);
1988
- const deletedCount = await cleanupOldCacheFiles(cachePath, Date.now());
1989
- if (deletedCount > 0) {
1990
- logger.debug(`Cleaned up ${deletedCount} old cache files`);
1991
- }
1992
- } catch (e) {
1993
- }
1994
- }
1995
- return {
1996
- cache,
1997
- stats: {
1998
- ...stats,
1999
- updateTime: Date.now() - startTime,
2000
- fullRebuild: false
2001
- }
2002
- };
2003
- } else {
2004
- logger.debug(`Cache invalid or missing, building from scratch...`);
2005
- const commitToTags = await buildCompleteTagCache(repoPath, parseVersion2);
2006
- const cache = {
2007
- commitToTags,
2008
- initialized: true
2009
- };
2010
- const validation = await buildCacheValidation(repoPath);
2011
- await saveCachedTags(repoPath, cache, validation);
2012
- return {
2013
- cache,
2014
- stats: {
2015
- added: currentTags.length,
2016
- deleted: 0,
2017
- modified: 0,
2018
- unchanged: 0,
2019
- totalTags: currentTags.length,
2020
- updateTime: Date.now() - startTime,
2021
- fullRebuild: true
2022
- }
2023
- };
2024
- }
2025
- };
2026
- async function performDifferentialUpdate(repoPath, cache, currentTags, parseVersion2, logger) {
2027
- const diff = calculateTagDiff(cache, currentTags);
1854
+ logger.debug(`[git-ops] sort tags: ${Date.now() - sortStart}ms`);
2028
1855
  logger.debug(
2029
- `Tag diff: +${diff.added.length} -${diff.deleted.length} =${diff.unchanged.length}`
1856
+ `[git-ops] buildCompleteTagCache total: ${Date.now() - totalStart}ms`
2030
1857
  );
2031
- const modified = await findModifiedTags(repoPath, diff.unchanged, cache);
2032
- logger.debug(`Found ${modified.length} modified tags`);
2033
- if (diff.deleted.length > 0) {
2034
- const newCache = removeTagsFromCache(cache, diff.deleted);
2035
- cache.clear();
2036
- for (const [k, v] of newCache) {
2037
- cache.set(k, v);
2038
- }
2039
- }
2040
- if (diff.added.length > 0) {
2041
- const newTags = await getTagsInfo(repoPath, diff.added, parseVersion2);
2042
- const newCache = addTagsToCache(cache, newTags);
2043
- cache.clear();
2044
- for (const [k, v] of newCache) {
2045
- cache.set(k, v);
2046
- }
2047
- }
2048
- if (modified.length > 0) {
2049
- const updatedTags = await getTagsInfo(repoPath, modified, parseVersion2);
2050
- const newCache = updateTagsInCache(cache, modified, updatedTags);
2051
- cache.clear();
2052
- for (const [k, v] of newCache) {
2053
- cache.set(k, v);
2054
- }
2055
- }
2056
- const unchangedCount = diff.unchanged.length - modified.length;
2057
- return {
2058
- added: diff.added.length,
2059
- deleted: diff.deleted.length,
2060
- modified: modified.length,
2061
- unchanged: unchangedCount,
2062
- totalTags: currentTags.length
2063
- };
2064
- }
1858
+ logger.debug(`[git-ops] Built cache with ${cache.size} unique commits`);
1859
+ return cache;
1860
+ };
2065
1861
  const parseVersionComponent = (value) => {
2066
1862
  const num = parseInt(value, 10);
2067
1863
  return num < 0 || num > 65535 ? void 0 : num;
@@ -2187,59 +1983,8 @@ const getCurrentCommit = async (repositoryPath) => {
2187
1983
  return void 0;
2188
1984
  }
2189
1985
  };
2190
- const getRelatedTagsFromCache = (cache, commitHash) => {
2191
- if (!cache.initialized) {
2192
- return [];
2193
- }
2194
- return cache.commitToTags.get(commitHash) || [];
2195
- };
2196
- const getRelatedTagsForVersioning = async (repositoryPath, commitHash) => {
2197
- try {
2198
- const tags = await git__namespace.listTags({ fs: fs__namespace, dir: repositoryPath });
2199
- const tagInfos = [];
2200
- for (const tagName of tags) {
2201
- try {
2202
- const tagOid = await git__namespace.resolveRef({
2203
- fs: fs__namespace,
2204
- dir: repositoryPath,
2205
- ref: `refs/tags/${tagName}`
2206
- });
2207
- if (tagOid === commitHash) {
2208
- const version2 = parseVersion(tagName);
2209
- if (version2 && isValidVersion(version2)) {
2210
- tagInfos.push({
2211
- name: tagName,
2212
- hash: commitHash,
2213
- version: version2
2214
- });
2215
- }
2216
- } else {
2217
- try {
2218
- const tagObject = await git__namespace.readTag({
2219
- fs: fs__namespace,
2220
- dir: repositoryPath,
2221
- oid: tagOid
2222
- });
2223
- if (tagObject && tagObject.tag.object === commitHash) {
2224
- const version2 = parseVersion(tagName);
2225
- if (version2 && isValidVersion(version2)) {
2226
- tagInfos.push({
2227
- name: tagName,
2228
- hash: commitHash,
2229
- version: version2
2230
- });
2231
- }
2232
- }
2233
- } catch (e) {
2234
- }
2235
- }
2236
- } catch (e) {
2237
- }
2238
- }
2239
- return tagInfos;
2240
- } catch (e) {
2241
- return [];
2242
- }
1986
+ const getRelatedTagsFromMap = (commitToTags, commitHash) => {
1987
+ return commitToTags.get(commitHash) || [];
2243
1988
  };
2244
1989
  const getRelatedBranches = async (repositoryPath, commitHash) => {
2245
1990
  try {
@@ -2281,7 +2026,7 @@ const getModifiedFiles = async (repositoryPath) => {
2281
2026
  const formatModifiedFile = (modifiedFile) => {
2282
2027
  return `'${modifiedFile[0]}':${modifiedFile[1]}:${modifiedFile[2]}:${modifiedFile[3]}`;
2283
2028
  };
2284
- const lookupVersionLabelRecursive = async (cwd, commit, reachedCommits, tagCache) => {
2029
+ const lookupVersionLabelRecursive = async (cwd, commit, reachedCommits, commitToTags) => {
2285
2030
  const scheduledStack = [];
2286
2031
  let version2 = { major: 0, minor: 0, build: 1, original: "0.0.1" };
2287
2032
  let currentCommit = commit;
@@ -2290,7 +2035,7 @@ const lookupVersionLabelRecursive = async (cwd, commit, reachedCommits, tagCache
2290
2035
  version2 = reachedCommits.get(currentCommit.hash);
2291
2036
  break;
2292
2037
  }
2293
- const relatedTags = tagCache ? getRelatedTagsFromCache(tagCache, currentCommit.hash) : await getRelatedTagsForVersioning(cwd, currentCommit.hash);
2038
+ const relatedTags = getRelatedTagsFromMap(commitToTags, currentCommit.hash);
2294
2039
  const versionCandidates = relatedTags.filter((tag) => tag.version && isValidVersion(tag.version)).filter((tag) => tag.version.minor !== void 0).sort((a, b) => compareVersions(a.version, b.version));
2295
2040
  if (versionCandidates.length >= 1) {
2296
2041
  version2 = versionCandidates[0].version;
@@ -2326,7 +2071,7 @@ const lookupVersionLabelRecursive = async (cwd, commit, reachedCommits, tagCache
2326
2071
  cwd,
2327
2072
  parents[index],
2328
2073
  reachedCommits,
2329
- tagCache
2074
+ commitToTags
2330
2075
  );
2331
2076
  if (alternateParentVersion && compareVersions(alternateParentVersion, version2) < 0) {
2332
2077
  version2 = alternateParentVersion;
@@ -2339,19 +2084,27 @@ const lookupVersionLabelRecursive = async (cwd, commit, reachedCommits, tagCache
2339
2084
  return version2;
2340
2085
  };
2341
2086
  const getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logger) => {
2087
+ const startTime = Date.now();
2342
2088
  const metadata = {};
2343
2089
  let gitRootPath;
2344
2090
  try {
2345
2091
  gitRootPath = await git__namespace.findRoot({ fs: fs__namespace, filepath: repositoryPath });
2346
2092
  } catch (e) {
2093
+ logger.debug(
2094
+ `[screw-up] Total getGitMetadata: ${Date.now() - startTime}ms`
2095
+ );
2347
2096
  return metadata;
2348
2097
  }
2349
2098
  try {
2350
2099
  const currentCommit = await getCurrentCommit(gitRootPath);
2351
2100
  if (!currentCommit) {
2101
+ logger.debug(
2102
+ `[screw-up] Total getGitMetadata: ${Date.now() - startTime}ms`
2103
+ );
2352
2104
  return metadata;
2353
2105
  }
2354
- const { cache: tagCache, stats } = await loadOrBuildTagCache(
2106
+ const buildStart = Date.now();
2107
+ const commitToTags = await buildCompleteTagCache(
2355
2108
  gitRootPath,
2356
2109
  (tagName) => {
2357
2110
  const version22 = parseVersion(tagName);
@@ -2359,21 +2112,16 @@ const getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logge
2359
2112
  },
2360
2113
  logger
2361
2114
  );
2362
- if (stats.fullRebuild) {
2363
- logger.debug(
2364
- `Built new tag cache: ${stats.totalTags} tags in ${stats.updateTime}ms`
2365
- );
2366
- } else {
2367
- logger.debug(
2368
- `Updated cache differentially: +${stats.added} -${stats.deleted} ~${stats.modified} =${stats.unchanged} (${stats.updateTime}ms)`
2369
- );
2370
- }
2115
+ logger.debug(
2116
+ `[screw-up] buildCompleteTagCache: ${Date.now() - buildStart}ms`
2117
+ );
2118
+ logger.debug(`Built tag map with ${commitToTags.size} commits`);
2371
2119
  const reachedCommits = /* @__PURE__ */ new Map();
2372
2120
  let version2 = await lookupVersionLabelRecursive(
2373
2121
  gitRootPath,
2374
2122
  currentCommit,
2375
2123
  reachedCommits,
2376
- tagCache
2124
+ commitToTags
2377
2125
  );
2378
2126
  const gitMetadata = { tags: [], branches: [] };
2379
2127
  metadata.git = gitMetadata;
@@ -2398,7 +2146,7 @@ const getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logge
2398
2146
  date: dayjs(currentCommit.date).format("YYYY-MM-DDTHH:mm:ssZ[Z]"),
2399
2147
  message: currentCommit.message
2400
2148
  };
2401
- const relatedTags = getRelatedTagsFromCache(tagCache, currentCommit.hash);
2149
+ const relatedTags = getRelatedTagsFromMap(commitToTags, currentCommit.hash);
2402
2150
  gitMetadata.tags = relatedTags.map((tag) => tag.name);
2403
2151
  const relatedBranches = await getRelatedBranches(
2404
2152
  gitRootPath,
@@ -2408,6 +2156,7 @@ const getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logge
2408
2156
  } catch (error) {
2409
2157
  logger.warn(`Failed to extract git metadata: ${error}`);
2410
2158
  }
2159
+ logger.debug(`[screw-up] Total getGitMetadata: ${Date.now() - startTime}ms`);
2411
2160
  return metadata;
2412
2161
  };
2413
2162
  const getFetchGitMetadata = (targetDir, checkWorkingDirectoryStatus, logger) => {
@@ -2424,11 +2173,11 @@ const getFetchGitMetadata = (targetDir, checkWorkingDirectoryStatus, logger) =>
2424
2173
  };
2425
2174
  };
2426
2175
  const name = "screw-up";
2427
- const version = "1.6.0";
2176
+ const version = "1.8.0";
2428
2177
  const author = "Kouji Matsui (@kekyo@mi.kekyo.net)";
2429
2178
  const license = "MIT";
2430
2179
  const repository_url = "https://github.com/kekyo/screw-up.git";
2431
- const git_commit_hash = "10c04af9c9b127002592d48cbb6ec18cfe5048bb";
2180
+ const git_commit_hash = "da96533e5128033ff7a45d59b1cee39e0e819533";
2432
2181
  const packageMetadata = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2433
2182
  __proto__: null,
2434
2183
  author,
@@ -2449,4 +2198,4 @@ exports.replacePeerDependenciesWildcards = replacePeerDependenciesWildcards;
2449
2198
  exports.resolvePackageMetadata = resolvePackageMetadata;
2450
2199
  exports.resolveRawPackageJsonObject = resolveRawPackageJsonObject;
2451
2200
  exports.version = version;
2452
- //# sourceMappingURL=packageMetadata-CCW9p12u.cjs.map
2201
+ //# sourceMappingURL=packageMetadata-BwTlrgAe.cjs.map