screw-up 1.3.0 → 1.5.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.3.0
3
+ * version: 1.5.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: eaf2f91941a8c1d085b1c493a55e0041b39f0cb3
8
+ * git.commit.hash: 72fd5b88656bc400ba3fed500895826208e23217
9
9
  */
10
10
  "use strict";
11
11
  const fs = require("fs");
@@ -1138,8 +1138,7 @@ const createConsoleLogger = (prefix, driver) => {
1138
1138
  };
1139
1139
  const flattenObject = (obj, prefix, map) => {
1140
1140
  for (const [key2, value] of Object.entries(obj)) {
1141
- if (!value)
1142
- continue;
1141
+ if (!value) continue;
1143
1142
  const fullKey = prefix ? `${prefix}.${key2}` : key2;
1144
1143
  if (typeof value === "string") {
1145
1144
  map[fullKey] = value;
@@ -1164,7 +1163,9 @@ const findWorkspaceRoot = async (startPath, logger) => {
1164
1163
  return currentPath;
1165
1164
  }
1166
1165
  } catch (error) {
1167
- logger.warn(`Failed to parse package.json at ${packageJsonPath}: ${error}`);
1166
+ logger.warn(
1167
+ `Failed to parse package.json at ${packageJsonPath}: ${error}`
1168
+ );
1168
1169
  }
1169
1170
  }
1170
1171
  currentPath = path.dirname(currentPath);
@@ -1209,12 +1210,16 @@ const collectWorkspaceSiblings = async (workspaceRoot, fetchGitMetadata, alwaysO
1209
1210
  });
1210
1211
  }
1211
1212
  } catch (error) {
1212
- logger.warn(`Failed to resolve package.json from ${packageJsonPath}: ${error}`);
1213
+ logger.warn(
1214
+ `Failed to resolve package.json from ${packageJsonPath}: ${error}`
1215
+ );
1213
1216
  }
1214
1217
  }
1215
1218
  }
1216
1219
  } catch (error) {
1217
- logger.warn(`Failed to collect workspace siblings from ${workspaceRoot}: ${error}`);
1220
+ logger.warn(
1221
+ `Failed to collect workspace siblings from ${workspaceRoot}: ${error}`
1222
+ );
1218
1223
  }
1219
1224
  return siblings;
1220
1225
  };
@@ -1223,7 +1228,9 @@ const replacePeerDependenciesWildcards = (packageJson, siblings, versionPrefix)
1223
1228
  if (!modifiedPackageJson.peerDependencies || typeof modifiedPackageJson.peerDependencies !== "object") {
1224
1229
  return modifiedPackageJson;
1225
1230
  }
1226
- for (const [depName, depVersion] of Object.entries(modifiedPackageJson.peerDependencies)) {
1231
+ for (const [depName, depVersion] of Object.entries(
1232
+ modifiedPackageJson.peerDependencies
1233
+ )) {
1227
1234
  if (depVersion === "*" && siblings.has(depName)) {
1228
1235
  const sibling = siblings.get(depName);
1229
1236
  modifiedPackageJson.peerDependencies[depName] = `${versionPrefix}${sibling.version}`;
@@ -1334,7 +1341,12 @@ const resolvePackageMetadata = async (projectRoot, fetchGitMetadata, alwaysOverr
1334
1341
  projectRoot,
1335
1342
  logger,
1336
1343
  readPackageMetadata.bind(void 0, logger),
1337
- mergePackageMetadata.bind(void 0, fetchGitMetadata, alwaysOverrideVersionFromGit, sourceMap)
1344
+ mergePackageMetadata.bind(
1345
+ void 0,
1346
+ fetchGitMetadata,
1347
+ alwaysOverrideVersionFromGit,
1348
+ sourceMap
1349
+ )
1338
1350
  );
1339
1351
  return {
1340
1352
  metadata,
@@ -1356,7 +1368,13 @@ const resolveRawPackageJsonObject = async (projectRoot, fetchGitMetadata, always
1356
1368
  projectRoot,
1357
1369
  logger,
1358
1370
  readRawPackageJson.bind(void 0, logger),
1359
- mergeRawPackageJson.bind(void 0, fetchGitMetadata, alwaysOverrideVersionFromGit, inheritableFields, sourceMap)
1371
+ mergeRawPackageJson.bind(
1372
+ void 0,
1373
+ fetchGitMetadata,
1374
+ alwaysOverrideVersionFromGit,
1375
+ inheritableFields,
1376
+ sourceMap
1377
+ )
1360
1378
  );
1361
1379
  return {
1362
1380
  metadata: packageJson,
@@ -1755,8 +1773,16 @@ const getCommit = async (repositoryPath, hash) => {
1755
1773
  };
1756
1774
  const getCurrentCommit = async (repositoryPath) => {
1757
1775
  try {
1758
- const currentOid = await git__namespace.resolveRef({ fs: fs__namespace, dir: repositoryPath, ref: "HEAD" });
1759
- const commit = await git__namespace.readCommit({ fs: fs__namespace, dir: repositoryPath, oid: currentOid });
1776
+ const currentOid = await git__namespace.resolveRef({
1777
+ fs: fs__namespace,
1778
+ dir: repositoryPath,
1779
+ ref: "HEAD"
1780
+ });
1781
+ const commit = await git__namespace.readCommit({
1782
+ fs: fs__namespace,
1783
+ dir: repositoryPath,
1784
+ oid: currentOid
1785
+ });
1760
1786
  return {
1761
1787
  hash: commit.oid,
1762
1788
  shortHash: commit.oid.substring(0, 7),
@@ -1768,44 +1794,72 @@ const getCurrentCommit = async (repositoryPath) => {
1768
1794
  return void 0;
1769
1795
  }
1770
1796
  };
1771
- const getRelatedTags = async (repositoryPath, commitHash) => {
1797
+ const buildTagCache = async (repositoryPath) => {
1798
+ const cache = {
1799
+ commitToTags: /* @__PURE__ */ new Map(),
1800
+ initialized: true
1801
+ };
1772
1802
  try {
1773
1803
  const tags = await git__namespace.listTags({ fs: fs__namespace, dir: repositoryPath });
1774
- const tagInfos = [];
1775
- for (const tagName of tags) {
1776
- try {
1777
- const tagOid = await git__namespace.resolveRef({ fs: fs__namespace, dir: repositoryPath, ref: `refs/tags/${tagName}` });
1778
- let targetCommitOid = tagOid;
1804
+ await Promise.all(
1805
+ tags.map(async (tagName) => {
1779
1806
  try {
1780
- const tagObject = await git__namespace.readTag({ fs: fs__namespace, dir: repositoryPath, oid: tagOid });
1781
- if (tagObject && tagObject.tag.object) {
1782
- targetCommitOid = tagObject.tag.object;
1783
- }
1784
- } catch (e) {
1785
- }
1786
- if (targetCommitOid === commitHash) {
1807
+ const tagOid = await git__namespace.resolveRef({
1808
+ fs: fs__namespace,
1809
+ dir: repositoryPath,
1810
+ ref: `refs/tags/${tagName}`
1811
+ });
1787
1812
  const version2 = parseVersion(tagName);
1788
- if (version2 && isValidVersion(version2)) {
1789
- tagInfos.push({
1790
- name: tagName,
1791
- hash: commitHash,
1792
- version: version2
1793
- });
1794
- } else {
1795
- tagInfos.push({
1796
- name: tagName,
1797
- hash: commitHash,
1798
- version: void 0
1813
+ const tagInfo = {
1814
+ name: tagName,
1815
+ hash: tagOid,
1816
+ // This will be updated for annotated tags
1817
+ version: version2 && isValidVersion(version2) ? version2 : void 0
1818
+ };
1819
+ if (!cache.commitToTags.has(tagOid)) {
1820
+ cache.commitToTags.set(tagOid, []);
1821
+ }
1822
+ cache.commitToTags.get(tagOid).push({ ...tagInfo, hash: tagOid });
1823
+ try {
1824
+ const tagObject = await git__namespace.readTag({
1825
+ fs: fs__namespace,
1826
+ dir: repositoryPath,
1827
+ oid: tagOid
1799
1828
  });
1829
+ if (tagObject && tagObject.tag.object) {
1830
+ const commitOid = tagObject.tag.object;
1831
+ const lightweightTags = cache.commitToTags.get(tagOid);
1832
+ if (lightweightTags) {
1833
+ const index = lightweightTags.findIndex(
1834
+ (t) => t.name === tagName
1835
+ );
1836
+ if (index >= 0) {
1837
+ lightweightTags.splice(index, 1);
1838
+ if (lightweightTags.length === 0) {
1839
+ cache.commitToTags.delete(tagOid);
1840
+ }
1841
+ }
1842
+ }
1843
+ if (!cache.commitToTags.has(commitOid)) {
1844
+ cache.commitToTags.set(commitOid, []);
1845
+ }
1846
+ cache.commitToTags.get(commitOid).push({ ...tagInfo, hash: commitOid });
1847
+ }
1848
+ } catch (e) {
1800
1849
  }
1850
+ } catch (e) {
1801
1851
  }
1802
- } catch (e) {
1803
- }
1804
- }
1805
- return tagInfos.sort((a, b) => a.name.localeCompare(b.name));
1852
+ })
1853
+ );
1806
1854
  } catch (e) {
1855
+ }
1856
+ return cache;
1857
+ };
1858
+ const getRelatedTagsFromCache = (cache, commitHash) => {
1859
+ if (!cache.initialized) {
1807
1860
  return [];
1808
1861
  }
1862
+ return cache.commitToTags.get(commitHash) || [];
1809
1863
  };
1810
1864
  const getRelatedTagsForVersioning = async (repositoryPath, commitHash) => {
1811
1865
  try {
@@ -1813,16 +1867,12 @@ const getRelatedTagsForVersioning = async (repositoryPath, commitHash) => {
1813
1867
  const tagInfos = [];
1814
1868
  for (const tagName of tags) {
1815
1869
  try {
1816
- const tagOid = await git__namespace.resolveRef({ fs: fs__namespace, dir: repositoryPath, ref: `refs/tags/${tagName}` });
1817
- let targetCommitOid = tagOid;
1818
- try {
1819
- const tagObject = await git__namespace.readTag({ fs: fs__namespace, dir: repositoryPath, oid: tagOid });
1820
- if (tagObject && tagObject.tag.object) {
1821
- targetCommitOid = tagObject.tag.object;
1822
- }
1823
- } catch (e) {
1824
- }
1825
- if (targetCommitOid === commitHash) {
1870
+ const tagOid = await git__namespace.resolveRef({
1871
+ fs: fs__namespace,
1872
+ dir: repositoryPath,
1873
+ ref: `refs/tags/${tagName}`
1874
+ });
1875
+ if (tagOid === commitHash) {
1826
1876
  const version2 = parseVersion(tagName);
1827
1877
  if (version2 && isValidVersion(version2)) {
1828
1878
  tagInfos.push({
@@ -1831,6 +1881,25 @@ const getRelatedTagsForVersioning = async (repositoryPath, commitHash) => {
1831
1881
  version: version2
1832
1882
  });
1833
1883
  }
1884
+ } else {
1885
+ try {
1886
+ const tagObject = await git__namespace.readTag({
1887
+ fs: fs__namespace,
1888
+ dir: repositoryPath,
1889
+ oid: tagOid
1890
+ });
1891
+ if (tagObject && tagObject.tag.object === commitHash) {
1892
+ const version2 = parseVersion(tagName);
1893
+ if (version2 && isValidVersion(version2)) {
1894
+ tagInfos.push({
1895
+ name: tagName,
1896
+ hash: commitHash,
1897
+ version: version2
1898
+ });
1899
+ }
1900
+ }
1901
+ } catch (e) {
1902
+ }
1834
1903
  }
1835
1904
  } catch (e) {
1836
1905
  }
@@ -1846,7 +1915,11 @@ const getRelatedBranches = async (repositoryPath, commitHash) => {
1846
1915
  const relatedBranches = [];
1847
1916
  for (const branch of branches) {
1848
1917
  try {
1849
- const branchOid = await git__namespace.resolveRef({ fs: fs__namespace, dir: repositoryPath, ref: branch });
1918
+ const branchOid = await git__namespace.resolveRef({
1919
+ fs: fs__namespace,
1920
+ dir: repositoryPath,
1921
+ ref: branch
1922
+ });
1850
1923
  if (branchOid === commitHash) {
1851
1924
  relatedBranches.push(branch);
1852
1925
  }
@@ -1863,7 +1936,7 @@ const getModifiedFiles = async (repositoryPath) => {
1863
1936
  const status = await git__namespace.statusMatrix({ fs: fs__namespace, dir: repositoryPath });
1864
1937
  return status.filter(
1865
1938
  ([, head, workdir, stage]) => workdir === 2 || // modified in working directory (unstaged)
1866
- stage === 2 || // modified in stage (staged)
1939
+ stage === 2 || // modified in stage (staged)
1867
1940
  stage === 3 || // added to stage (staged)
1868
1941
  head === 1 && workdir === 0 || // deleted from working directory
1869
1942
  head === 0 && workdir === 1
@@ -1876,7 +1949,7 @@ const getModifiedFiles = async (repositoryPath) => {
1876
1949
  const formatModifiedFile = (modifiedFile) => {
1877
1950
  return `'${modifiedFile[0]}':${modifiedFile[1]}:${modifiedFile[2]}:${modifiedFile[3]}`;
1878
1951
  };
1879
- const lookupVersionLabelRecursive = async (cwd, commit, reachedCommits) => {
1952
+ const lookupVersionLabelRecursive = async (cwd, commit, reachedCommits, tagCache) => {
1880
1953
  const scheduledStack = [];
1881
1954
  let version2 = { major: 0, minor: 0, build: 1, original: "0.0.1" };
1882
1955
  let currentCommit = commit;
@@ -1885,7 +1958,7 @@ const lookupVersionLabelRecursive = async (cwd, commit, reachedCommits) => {
1885
1958
  version2 = reachedCommits.get(currentCommit.hash);
1886
1959
  break;
1887
1960
  }
1888
- const relatedTags = await getRelatedTagsForVersioning(cwd, currentCommit.hash);
1961
+ const relatedTags = tagCache ? getRelatedTagsFromCache(tagCache, currentCommit.hash) : await getRelatedTagsForVersioning(cwd, currentCommit.hash);
1889
1962
  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));
1890
1963
  if (versionCandidates.length >= 1) {
1891
1964
  version2 = versionCandidates[0].version;
@@ -1894,9 +1967,15 @@ const lookupVersionLabelRecursive = async (cwd, commit, reachedCommits) => {
1894
1967
  }
1895
1968
  let parentCommits = [];
1896
1969
  try {
1897
- const commitObj = await git__namespace.readCommit({ fs: fs__namespace, dir: cwd, oid: currentCommit.hash });
1970
+ const commitObj = await git__namespace.readCommit({
1971
+ fs: fs__namespace,
1972
+ dir: cwd,
1973
+ oid: currentCommit.hash
1974
+ });
1898
1975
  const parentHashes = commitObj.commit.parent || [];
1899
- parentCommits = (await Promise.all(parentHashes.map((parentHash) => getCommit(cwd, parentHash)))).filter((ci) => ci !== void 0);
1976
+ parentCommits = (await Promise.all(
1977
+ parentHashes.map((parentHash) => getCommit(cwd, parentHash))
1978
+ )).filter((ci) => ci !== void 0);
1900
1979
  } catch (e) {
1901
1980
  }
1902
1981
  if (parentCommits.length === 0) {
@@ -1911,7 +1990,12 @@ const lookupVersionLabelRecursive = async (cwd, commit, reachedCommits) => {
1911
1990
  const { commit: scheduledCommit, parents } = scheduled;
1912
1991
  if (parents.length >= 2) {
1913
1992
  for (let index = 1; index < parents.length; index++) {
1914
- const alternateParentVersion = await lookupVersionLabelRecursive(cwd, parents[index], reachedCommits);
1993
+ const alternateParentVersion = await lookupVersionLabelRecursive(
1994
+ cwd,
1995
+ parents[index],
1996
+ reachedCommits,
1997
+ tagCache
1998
+ );
1915
1999
  if (alternateParentVersion && compareVersions(alternateParentVersion, version2) < 0) {
1916
2000
  version2 = alternateParentVersion;
1917
2001
  }
@@ -1935,8 +2019,17 @@ const getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logge
1935
2019
  if (!currentCommit) {
1936
2020
  return metadata;
1937
2021
  }
2022
+ const tagCache = await buildTagCache(gitRootPath);
2023
+ logger.debug(
2024
+ `Built tag cache with ${tagCache.commitToTags.size} commit entries`
2025
+ );
1938
2026
  const reachedCommits = /* @__PURE__ */ new Map();
1939
- let version2 = await lookupVersionLabelRecursive(gitRootPath, currentCommit, reachedCommits);
2027
+ let version2 = await lookupVersionLabelRecursive(
2028
+ gitRootPath,
2029
+ currentCommit,
2030
+ reachedCommits,
2031
+ tagCache
2032
+ );
1940
2033
  const gitMetadata = { tags: [], branches: [] };
1941
2034
  metadata.git = gitMetadata;
1942
2035
  if (version2) {
@@ -1944,7 +2037,9 @@ const getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logge
1944
2037
  const modifiedFiles = await getModifiedFiles(gitRootPath);
1945
2038
  if (modifiedFiles.length >= 1) {
1946
2039
  const newVersion = incrementLastVersionComponent(version2);
1947
- logger.debug(`Increased git version by detected modified items: ${formatVersion(version2)} ---> ${formatVersion(newVersion)}, Files=[${modifiedFiles.map(formatModifiedFile).join(", ")}]`);
2040
+ logger.debug(
2041
+ `Increased git version by detected modified items: ${formatVersion(version2)} ---> ${formatVersion(newVersion)}, Files=[${modifiedFiles.map(formatModifiedFile).join(", ")}]`
2042
+ );
1948
2043
  version2 = newVersion;
1949
2044
  }
1950
2045
  }
@@ -1958,9 +2053,12 @@ const getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logge
1958
2053
  date: dayjs(currentCommit.date).format("YYYY-MM-DDTHH:mm:ssZ[Z]"),
1959
2054
  message: currentCommit.message
1960
2055
  };
1961
- const relatedTags = await getRelatedTags(gitRootPath, currentCommit.hash);
2056
+ const relatedTags = getRelatedTagsFromCache(tagCache, currentCommit.hash);
1962
2057
  gitMetadata.tags = relatedTags.map((tag) => tag.name);
1963
- const relatedBranches = await getRelatedBranches(gitRootPath, currentCommit.hash);
2058
+ const relatedBranches = await getRelatedBranches(
2059
+ gitRootPath,
2060
+ currentCommit.hash
2061
+ );
1964
2062
  gitMetadata.branches = relatedBranches;
1965
2063
  } catch (error) {
1966
2064
  logger.warn(`Failed to extract git metadata: ${error}`);
@@ -1981,11 +2079,11 @@ const getFetchGitMetadata = (targetDir, checkWorkingDirectoryStatus, logger) =>
1981
2079
  };
1982
2080
  };
1983
2081
  const name = "screw-up";
1984
- const version = "1.3.0";
2082
+ const version = "1.5.0";
1985
2083
  const author = "Kouji Matsui (@kekyo@mi.kekyo.net)";
1986
2084
  const license = "MIT";
1987
2085
  const repository_url = "https://github.com/kekyo/screw-up.git";
1988
- const git_commit_hash = "eaf2f91941a8c1d085b1c493a55e0041b39f0cb3";
2086
+ const git_commit_hash = "72fd5b88656bc400ba3fed500895826208e23217";
1989
2087
  const packageMetadata = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1990
2088
  __proto__: null,
1991
2089
  author,
@@ -2006,4 +2104,4 @@ exports.replacePeerDependenciesWildcards = replacePeerDependenciesWildcards;
2006
2104
  exports.resolvePackageMetadata = resolvePackageMetadata;
2007
2105
  exports.resolveRawPackageJsonObject = resolveRawPackageJsonObject;
2008
2106
  exports.version = version;
2009
- //# sourceMappingURL=packageMetadata-C9hcegXk.cjs.map
2107
+ //# sourceMappingURL=packageMetadata-CbqTWPYD.cjs.map