screw-up 1.32.0 → 1.33.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 (34) hide show
  1. package/dist/index.cjs +108 -54
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.mjs +4 -4
  4. package/dist/main.cjs +108 -54
  5. package/dist/main.cjs.map +1 -1
  6. package/dist/main.mjs +5 -5
  7. package/dist/{metadata-file-D79yMa_A.js → metadata-file-Case8fsm.js} +105 -51
  8. package/dist/metadata-file-Case8fsm.js.map +1 -0
  9. package/dist/{packageMetadata-Sm2NpI2b.js → packageMetadata-4rUlIBjt.js} +6 -6
  10. package/dist/{packageMetadata-Sm2NpI2b.js.map → packageMetadata-4rUlIBjt.js.map} +1 -1
  11. package/dist/{packageMetadata-Cwh4Fqmw.cjs → packageMetadata-CaaD3Ehh.cjs} +3 -3
  12. package/dist/{packageMetadata-6po5LHyH.cjs → packageMetadata-k_QXJ2PH.cjs} +5 -5
  13. package/dist/{packageMetadata-6po5LHyH.cjs.map → packageMetadata-k_QXJ2PH.cjs.map} +1 -1
  14. package/dist/src/analyzer.d.ts +2 -2
  15. package/dist/src/analyzer.d.ts.map +1 -1
  16. package/dist/src/cli-internal.d.ts +2 -2
  17. package/dist/src/cli.d.ts +2 -2
  18. package/dist/src/declaration-import-fix.d.ts +2 -2
  19. package/dist/src/default-import-fix.d.ts +2 -2
  20. package/dist/src/fast-tags.d.ts +2 -2
  21. package/dist/src/generated/packageMetadata.d.ts +4 -4
  22. package/dist/src/git-operations.d.ts +2 -2
  23. package/dist/src/git-operations.d.ts.map +1 -1
  24. package/dist/src/git-ref-utils.d.ts +32 -4
  25. package/dist/src/git-ref-utils.d.ts.map +1 -1
  26. package/dist/src/index.d.ts +2 -2
  27. package/dist/src/internal.d.ts +2 -2
  28. package/dist/src/main.d.ts +2 -2
  29. package/dist/src/metadata-file.d.ts +2 -2
  30. package/dist/src/text-edits.d.ts +2 -2
  31. package/dist/src/types.d.ts +2 -2
  32. package/dist/src/vite-plugin.d.ts +2 -2
  33. package/package.json +8 -8
  34. package/dist/metadata-file-D79yMa_A.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.32.0
3
+ * version: 1.33.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: 8a0078c34fa41bdb0cbf2d23837ac5e3217cbf53
8
+ * git.commit.hash: be56ff1901b5073e1b0238a28b80d0c4f3c1e894
9
9
  */
10
10
  //#region \0rolldown/runtime.js
11
11
  var __create = Object.create;
@@ -31,12 +31,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
31
31
  }) : target, mod));
32
32
  //#endregion
33
33
  let fs_promises = require("fs/promises");
34
- fs_promises = __toESM(fs_promises);
34
+ fs_promises = __toESM(fs_promises, 1);
35
35
  let fs = require("fs");
36
36
  let path = require("path");
37
37
  require("glob");
38
38
  let isomorphic_git = require("isomorphic-git");
39
- isomorphic_git = __toESM(isomorphic_git);
39
+ isomorphic_git = __toESM(isomorphic_git, 1);
40
40
  let crypto$1 = require("crypto");
41
41
  let zlib = require("zlib");
42
42
  //#region node_modules/async-primitives/dist/index.mjs
@@ -223,8 +223,8 @@ createLogicalContext(Symbol("[root]"));
223
223
  //#endregion
224
224
  //#region src/generated/packageMetadata.ts
225
225
  var name = "screw-up";
226
- var version = "1.32.0";
227
- var git_commit_hash = "8a0078c34fa41bdb0cbf2d23837ac5e3217cbf53";
226
+ var version = "1.33.0";
227
+ var git_commit_hash = "be56ff1901b5073e1b0238a28b80d0c4f3c1e894";
228
228
  //#endregion
229
229
  //#region node_modules/json5/dist/index.js
230
230
  var require_dist = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -1863,17 +1863,45 @@ var PACKED_OBJECT_TYPE_BY_CODE = new Map([
1863
1863
  [7, "ref-delta"]
1864
1864
  ]);
1865
1865
  /**
1866
- * Resolve the actual Git directory for repositories, worktrees, and submodules.
1866
+ * Resolve Git directory paths for repositories, worktrees, and submodules.
1867
1867
  * @param repoPath - Repository path
1868
- * @returns The resolved Git directory path
1868
+ * @returns The resolved Git directory paths
1869
1869
  */
1870
- var getActualGitDir = async (repoPath) => {
1870
+ var resolveGitDirectoryPaths = async (repoPath) => {
1871
1871
  const gitDir = (0, path.join)(repoPath, ".git");
1872
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]);
1873
+ const resolvedGitDir = !(gitStat === null || gitStat === void 0 ? void 0 : gitStat.isFile()) ? gitDir : await (async () => {
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
+ return {
1879
+ gitDir: resolvedGitDir,
1880
+ commonGitDir: await (0, fs_promises.readFile)((0, path.join)(resolvedGitDir, "commondir"), "utf-8").then((content) => {
1881
+ const commondir = content.trim();
1882
+ if (!commondir) return resolvedGitDir;
1883
+ return (0, path.isAbsolute)(commondir) ? commondir : (0, path.join)(resolvedGitDir, commondir);
1884
+ }).catch((error) => {
1885
+ if ((error === null || error === void 0 ? void 0 : error.code) !== "ENOENT") throw error;
1886
+ return resolvedGitDir;
1887
+ })
1888
+ };
1889
+ };
1890
+ /**
1891
+ * Resolve the worktree-specific Git directory.
1892
+ * @param repoPath - Repository path
1893
+ * @returns The resolved worktree-specific Git directory path
1894
+ */
1895
+ var getActualGitDir = async (repoPath) => {
1896
+ return (await resolveGitDirectoryPaths(repoPath)).gitDir;
1897
+ };
1898
+ /**
1899
+ * Resolve the common Git directory used for refs and objects.
1900
+ * @param repoPath - Repository path
1901
+ * @returns The resolved common Git directory path
1902
+ */
1903
+ var getCommonGitDir = async (repoPath) => {
1904
+ return (await resolveGitDirectoryPaths(repoPath)).commonGitDir;
1877
1905
  };
1878
1906
  var readFixedRange = async (fileHandle, offset, length) => {
1879
1907
  const buffer = Buffer.alloc(length);
@@ -2090,11 +2118,11 @@ var parseTreeEntries = (treeContent) => {
2090
2118
  return entries;
2091
2119
  };
2092
2120
  var createGitObjectResolver = async (repoPath) => {
2093
- const actualGitDir = await getActualGitDir(repoPath);
2121
+ const commonGitDir = await getCommonGitDir(repoPath);
2094
2122
  const resolvedObjects = /* @__PURE__ */ new Map();
2095
2123
  let packStorePromise;
2096
2124
  const getPackStore = async () => {
2097
- if (!packStorePromise) packStorePromise = loadPackStore(actualGitDir);
2125
+ if (!packStorePromise) packStorePromise = loadPackStore(commonGitDir);
2098
2126
  return packStorePromise;
2099
2127
  };
2100
2128
  const readPackedObject = async (location) => {
@@ -2130,7 +2158,7 @@ var createGitObjectResolver = async (repoPath) => {
2130
2158
  const cachedObject = resolvedObjects.get(oid);
2131
2159
  if (cachedObject) return cachedObject;
2132
2160
  const objectPromise = (async () => {
2133
- const looseObject = await readLooseObject(actualGitDir, oid);
2161
+ const looseObject = await readLooseObject(commonGitDir, oid);
2134
2162
  if (looseObject) return looseObject;
2135
2163
  const location = (await getPackStore()).objectByOid.get(oid);
2136
2164
  if (!location) throw new Error(`Git object not found: ${oid}`);
@@ -2275,8 +2303,8 @@ var readLooseTags = async (refsTagsPath) => {
2275
2303
  * @returns Array of all tag names
2276
2304
  */
2277
2305
  var listTagsFast = async (repoPath) => {
2278
- const actualGitDir = await getActualGitDir(repoPath);
2279
- const [packedTags, looseTags] = await Promise.all([parsePackedRefs((0, path.join)(actualGitDir, "packed-refs")), readLooseTags((0, path.join)(actualGitDir, "refs", "tags"))]);
2306
+ const commonGitDir = await getCommonGitDir(repoPath);
2307
+ const [packedTags, looseTags] = await Promise.all([parsePackedRefs((0, path.join)(commonGitDir, "packed-refs")), readLooseTags((0, path.join)(commonGitDir, "refs", "tags"))]);
2280
2308
  const allTags = new Set([...packedTags, ...looseTags]);
2281
2309
  return Array.from(allTags).sort();
2282
2310
  };
@@ -2289,11 +2317,11 @@ var listTagsFast = async (repoPath) => {
2289
2317
  var resolveTagsBatchWithCommit = async (repoPath, tagNames, logger) => {
2290
2318
  const startTime = Date.now();
2291
2319
  const result = /* @__PURE__ */ new Map();
2292
- const actualGitDir = await getActualGitDir(repoPath);
2320
+ const commonGitDir = await getCommonGitDir(repoPath);
2293
2321
  const tagSet = new Set(tagNames);
2294
2322
  const packedRefsStart = Date.now();
2295
2323
  try {
2296
- const lines = (await (0, fs_promises.readFile)((0, path.join)(actualGitDir, "packed-refs"), "utf-8")).split("\n");
2324
+ const lines = (await (0, fs_promises.readFile)((0, path.join)(commonGitDir, "packed-refs"), "utf-8")).split("\n");
2297
2325
  for (let i = 0; i < lines.length; i++) {
2298
2326
  const line = lines[i];
2299
2327
  if (line.startsWith("#") || !line.trim()) continue;
@@ -2317,7 +2345,7 @@ var resolveTagsBatchWithCommit = async (repoPath, tagNames, logger) => {
2317
2345
  if (remainingTags.length > 0) {
2318
2346
  const looseRefsStart = Date.now();
2319
2347
  const looseTagEntries = (await Promise.all(remainingTags.map(async (tagName) => {
2320
- const looseRefPath = (0, path.join)(actualGitDir, "refs", "tags", tagName);
2348
+ const looseRefPath = (0, path.join)(commonGitDir, "refs", "tags", tagName);
2321
2349
  try {
2322
2350
  return {
2323
2351
  tagName,
@@ -2533,16 +2561,26 @@ var formatVersion = (version) => {
2533
2561
  return result;
2534
2562
  };
2535
2563
  /**
2536
- * Get a commit by hash
2564
+ * Build a Git read context that can operate correctly inside worktrees.
2537
2565
  * @param repositoryPath - Local Git repository directory
2566
+ * @returns The resolved Git read context
2567
+ */
2568
+ var createGitReadContext = async (repositoryPath) => ({
2569
+ dir: repositoryPath,
2570
+ gitdir: await getCommonGitDir(repositoryPath)
2571
+ });
2572
+ /**
2573
+ * Get a commit by hash
2574
+ * @param context - Git read context
2538
2575
  * @param hash - The hash of the commit
2539
2576
  * @returns The commit or undefined if the commit is not found
2540
2577
  */
2541
- var getCommit = async (repositoryPath, hash) => {
2578
+ var getCommit = async (context, hash) => {
2542
2579
  try {
2543
2580
  const commit = await isomorphic_git.readCommit({
2544
2581
  fs: fs_promises.default,
2545
- dir: repositoryPath,
2582
+ dir: context.dir,
2583
+ gitdir: context.gitdir,
2546
2584
  oid: hash
2547
2585
  });
2548
2586
  return {
@@ -2559,19 +2597,20 @@ var getCommit = async (repositoryPath, hash) => {
2559
2597
  };
2560
2598
  /**
2561
2599
  * Get the current commit
2562
- * @param repositoryPath - Local Git repository directory
2600
+ * @param context - Git read context
2563
2601
  * @returns The current commit or undefined if the current commit is not found
2564
2602
  */
2565
- var getCurrentCommit = async (repositoryPath) => {
2603
+ var getCurrentCommit = async (context) => {
2566
2604
  try {
2567
2605
  const currentOid = await isomorphic_git.resolveRef({
2568
2606
  fs: fs_promises.default,
2569
- dir: repositoryPath,
2607
+ dir: context.dir,
2570
2608
  ref: "HEAD"
2571
2609
  });
2572
2610
  const commit = await isomorphic_git.readCommit({
2573
2611
  fs: fs_promises.default,
2574
- dir: repositoryPath,
2612
+ dir: context.dir,
2613
+ gitdir: context.gitdir,
2575
2614
  oid: currentOid
2576
2615
  });
2577
2616
  return {
@@ -2597,21 +2636,23 @@ var getRelatedTagsFromMap = (commitToTags, commitHash) => {
2597
2636
  };
2598
2637
  /**
2599
2638
  * Get the commit related branch name.
2600
- * @param repositoryPath - Local Git repository directory
2639
+ * @param context - Git read context
2601
2640
  * @param commitHash - The hash of the commit
2602
2641
  * @returns The commit related branch name or undefined if not found
2603
2642
  */
2604
- var getRelatedBranches = async (repositoryPath, commitHash) => {
2643
+ var getRelatedBranches = async (context, commitHash) => {
2605
2644
  try {
2606
2645
  const branches = await isomorphic_git.listBranches({
2607
2646
  fs: fs_promises.default,
2608
- dir: repositoryPath
2647
+ dir: context.dir,
2648
+ gitdir: context.gitdir
2609
2649
  });
2610
2650
  const relatedBranches = [];
2611
2651
  for (const branch of branches) try {
2612
2652
  if (await isomorphic_git.resolveRef({
2613
2653
  fs: fs_promises.default,
2614
- dir: repositoryPath,
2654
+ dir: context.dir,
2655
+ gitdir: context.gitdir,
2615
2656
  ref: branch
2616
2657
  }) === commitHash) relatedBranches.push(branch);
2617
2658
  } catch (_unused3) {}
@@ -2755,7 +2796,7 @@ var formatModifiedFile = (modifiedFile) => `'${modifiedFile.path}':${modifiedFil
2755
2796
  * @param commitToTags - Map of commit hash to tags for performance
2756
2797
  * @returns The version or undefined if no version is found
2757
2798
  */
2758
- var lookupVersionLabelRecursive = async (cwd, commit, reachedCommits, commitToTags) => {
2799
+ var lookupVersionLabelRecursive = async (context, commit, reachedCommits, commitToTags) => {
2759
2800
  const scheduledStack = [];
2760
2801
  let version = {
2761
2802
  major: 0,
@@ -2779,10 +2820,11 @@ var lookupVersionLabelRecursive = async (cwd, commit, reachedCommits, commitToTa
2779
2820
  try {
2780
2821
  const parentHashes = (await isomorphic_git.readCommit({
2781
2822
  fs: fs_promises.default,
2782
- dir: cwd,
2823
+ dir: context.dir,
2824
+ gitdir: context.gitdir,
2783
2825
  oid: currentCommit.hash
2784
2826
  })).commit.parent || [];
2785
- parentCommits = (await Promise.all(parentHashes.map((parentHash) => getCommit(cwd, parentHash)))).filter((ci) => ci !== void 0);
2827
+ parentCommits = (await Promise.all(parentHashes.map((parentHash) => getCommit(context, parentHash)))).filter((ci) => ci !== void 0);
2786
2828
  } catch (_unused6) {}
2787
2829
  if (parentCommits.length === 0) {
2788
2830
  reachedCommits.set(currentCommit.hash, version);
@@ -2797,7 +2839,7 @@ var lookupVersionLabelRecursive = async (cwd, commit, reachedCommits, commitToTa
2797
2839
  while (scheduledStack.length >= 1) {
2798
2840
  const { commit: scheduledCommit, parents } = scheduledStack.pop();
2799
2841
  if (parents.length >= 2) for (let index = 1; index < parents.length; index++) {
2800
- const alternateParentVersion = await lookupVersionLabelRecursive(cwd, parents[index], reachedCommits, commitToTags);
2842
+ const alternateParentVersion = await lookupVersionLabelRecursive(context, parents[index], reachedCommits, commitToTags);
2801
2843
  if (alternateParentVersion && compareVersions(alternateParentVersion, version) < 0) version = alternateParentVersion;
2802
2844
  }
2803
2845
  version = incrementLastVersionComponent(version);
@@ -2825,12 +2867,31 @@ var getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logger)
2825
2867
  logger.debug(`[screw-up] Total getGitMetadata: ${Date.now() - startTime}ms`);
2826
2868
  return metadata;
2827
2869
  }
2870
+ let gitContext;
2828
2871
  try {
2829
- const currentCommit = await getCurrentCommit(gitRootPath);
2830
- if (!currentCommit) {
2831
- logger.debug(`[screw-up] Total getGitMetadata: ${Date.now() - startTime}ms`);
2832
- return metadata;
2872
+ gitContext = await createGitReadContext(gitRootPath);
2873
+ } catch (error) {
2874
+ logger.warn(`Failed to resolve git metadata context: ${error}`);
2875
+ logger.debug(`[screw-up] Total getGitMetadata: ${Date.now() - startTime}ms`);
2876
+ return metadata;
2877
+ }
2878
+ const currentCommit = await getCurrentCommit(gitContext);
2879
+ if (!currentCommit) {
2880
+ logger.debug(`[screw-up] Total getGitMetadata: ${Date.now() - startTime}ms`);
2881
+ return metadata;
2882
+ }
2883
+ const gitMetadata = {
2884
+ tags: [],
2885
+ branches: [],
2886
+ commit: {
2887
+ hash: currentCommit.hash,
2888
+ shortHash: currentCommit.shortHash,
2889
+ date: dayjs(currentCommit.date).format("YYYY-MM-DDTHH:mm:ssZ"),
2890
+ message: currentCommit.message
2833
2891
  }
2892
+ };
2893
+ metadata.git = gitMetadata;
2894
+ try {
2834
2895
  const buildStart = Date.now();
2835
2896
  const commitToTags = await buildCompleteTagCache(gitRootPath, (tagName) => {
2836
2897
  const version = parseVersion(tagName);
@@ -2838,12 +2899,7 @@ var getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logger)
2838
2899
  }, logger);
2839
2900
  logger.debug(`[screw-up] buildCompleteTagCache: ${Date.now() - buildStart}ms`);
2840
2901
  logger.debug(`Built tag map with ${commitToTags.size} commits`);
2841
- let version = await lookupVersionLabelRecursive(gitRootPath, currentCommit, /* @__PURE__ */ new Map(), commitToTags);
2842
- const gitMetadata = {
2843
- tags: [],
2844
- branches: []
2845
- };
2846
- metadata.git = gitMetadata;
2902
+ let version = await lookupVersionLabelRecursive(gitContext, currentCommit, /* @__PURE__ */ new Map(), commitToTags);
2847
2903
  if (version) {
2848
2904
  if (checkWorkingDirectoryStatus) {
2849
2905
  const modifiedFiles = await getModifiedFiles(gitRootPath, currentCommit.tree);
@@ -2857,16 +2913,14 @@ var getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logger)
2857
2913
  gitMetadata.version = gitVersion;
2858
2914
  metadata.version = gitVersion;
2859
2915
  }
2860
- gitMetadata.commit = {
2861
- hash: currentCommit.hash,
2862
- shortHash: currentCommit.shortHash,
2863
- date: dayjs(currentCommit.date).format("YYYY-MM-DDTHH:mm:ssZ"),
2864
- message: currentCommit.message
2865
- };
2866
2916
  gitMetadata.tags = getRelatedTagsFromMap(commitToTags, currentCommit.hash).map((tag) => tag.name);
2867
- gitMetadata.branches = await getRelatedBranches(gitRootPath, currentCommit.hash);
2868
2917
  } catch (error) {
2869
- logger.warn(`Failed to extract git metadata: ${error}`);
2918
+ logger.warn(`Failed to resolve git versioning metadata: ${error}`);
2919
+ }
2920
+ try {
2921
+ gitMetadata.branches = await getRelatedBranches(gitContext, currentCommit.hash);
2922
+ } catch (error) {
2923
+ logger.warn(`Failed to resolve git branch metadata: ${error}`);
2870
2924
  }
2871
2925
  logger.debug(`[screw-up] Total getGitMetadata: ${Date.now() - startTime}ms`);
2872
2926
  return metadata;