screw-up 0.16.0 → 0.17.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,14 +1,14 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 0.16.0
3
+ * version: 0.17.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: c5c68d39d1ab116299338d31f0f208c0eb49be5c
8
+ * git.commit.hash: 6ca2d4183d3123c9e0cf7aa444bdb85c1e60e9fb
9
9
  */
10
- import * as fs from "fs";
11
10
  import { existsSync } from "fs";
11
+ import * as fs from "fs/promises";
12
12
  import { readFile } from "fs/promises";
13
13
  import { dirname, join } from "path";
14
14
  import { glob } from "glob";
@@ -1809,10 +1809,10 @@ const getRelatedBranches = async (repositoryPath, commitHash) => {
1809
1809
  return [];
1810
1810
  }
1811
1811
  };
1812
- const hasModifiedFiles = async (repositoryPath) => {
1812
+ const getModifiedFiles = async (repositoryPath) => {
1813
1813
  try {
1814
1814
  const status = await git.statusMatrix({ fs, dir: repositoryPath });
1815
- return status.some(
1815
+ return status.filter(
1816
1816
  ([, head, workdir, stage]) => workdir === 2 || // modified in working directory (unstaged)
1817
1817
  stage === 2 || // modified in stage (staged)
1818
1818
  stage === 3 || // added to stage (staged)
@@ -1821,9 +1821,12 @@ const hasModifiedFiles = async (repositoryPath) => {
1821
1821
  // untracked files (respecting .gitignore)
1822
1822
  );
1823
1823
  } catch (e) {
1824
- return false;
1824
+ return [];
1825
1825
  }
1826
1826
  };
1827
+ const formatModifiedFile = (modifiedFile) => {
1828
+ return `'${modifiedFile[0]}':${modifiedFile[1]}:${modifiedFile[2]}:${modifiedFile[3]}`;
1829
+ };
1827
1830
  const lookupVersionLabelRecursive = async (cwd, commit, reachedCommits) => {
1828
1831
  const scheduledStack = [];
1829
1832
  let version = { major: 0, minor: 0, build: 1, original: "0.0.1" };
@@ -1888,9 +1891,13 @@ const getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logge
1888
1891
  const gitMetadata = { tags: [], branches: [] };
1889
1892
  metadata.git = gitMetadata;
1890
1893
  if (version) {
1891
- const hasModified = checkWorkingDirectoryStatus && await hasModifiedFiles(gitRootPath);
1892
- if (hasModified) {
1893
- version = incrementLastVersionComponent(version);
1894
+ if (checkWorkingDirectoryStatus) {
1895
+ const modifiedFiles = await getModifiedFiles(gitRootPath);
1896
+ if (modifiedFiles.length >= 1) {
1897
+ const newVersion = incrementLastVersionComponent(version);
1898
+ logger.debug(`Increased git version by detected modified items: ${formatVersion(version)} ---> ${formatVersion(newVersion)}, Files=[${modifiedFiles.map(formatModifiedFile).join(", ")}]`);
1899
+ version = newVersion;
1900
+ }
1894
1901
  }
1895
1902
  const gitVersion = formatVersion(version);
1896
1903
  gitMetadata.version = gitVersion;
@@ -1933,4 +1940,4 @@ export {
1933
1940
  getFetchGitMetadata as g,
1934
1941
  resolvePackageMetadata as r
1935
1942
  };
1936
- //# sourceMappingURL=analyzer-CU8VuwpB.js.map
1943
+ //# sourceMappingURL=analyzer-DxAKRQPj.js.map