ts-repo-utils 10.1.0 → 10.1.2

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.
@@ -14,7 +14,7 @@ import '@sindresorhus/is';
14
14
 
15
15
  const cmdDef = cmd.command({
16
16
  name: 'assert-repo-is-clean-cli',
17
- version: '10.1.0',
17
+ version: '10.1.2',
18
18
  args: {
19
19
  silent: cmd.flag({
20
20
  long: 'silent',
@@ -14,7 +14,7 @@ import '@sindresorhus/is';
14
14
 
15
15
  const cmdDef = cmd.command({
16
16
  name: 'check-should-run-type-checks-cli',
17
- version: '10.1.0',
17
+ version: '10.1.2',
18
18
  args: {
19
19
  pathsIgnore: cmd.multioption({
20
20
  long: 'paths-ignore',
@@ -13,7 +13,7 @@ import '@sindresorhus/is';
13
13
 
14
14
  const cmdDef = cmd.command({
15
15
  name: 'format-diff-from-cli',
16
- version: '10.1.0',
16
+ version: '10.1.2',
17
17
  args: {
18
18
  base: cmd.positional({
19
19
  type: cmd.string,
@@ -13,7 +13,7 @@ import '@sindresorhus/is';
13
13
 
14
14
  const cmdDef = cmd.command({
15
15
  name: 'format-uncommitted-cli',
16
- version: '10.1.0',
16
+ version: '10.1.2',
17
17
  args: {
18
18
  excludeUntracked: cmd.flag({
19
19
  long: 'exclude-untracked',
@@ -35,7 +35,7 @@ cmd.array(t), {
35
35
  });
36
36
  const cmdDef = cmd.command({
37
37
  name: 'gen-index-ts-cli',
38
- version: '10.1.0',
38
+ version: '10.1.2',
39
39
  args: {
40
40
  // required args
41
41
  targetDirectory: cmd.positional({
@@ -68,7 +68,15 @@ const cmdResultToFiles = async ({ cmd, cmdOptionToExcludeDeleted, cmdOptionToInc
68
68
  : cmdOptionToIncludeDeleted,
69
69
  ]
70
70
  .filter((s) => s !== '')
71
- .join(' '), { silent: options?.silent ?? false });
71
+ .join(' '), {
72
+ silent: options?.silent ?? false,
73
+ // Run git from the repository root so that `git ls-files` (which
74
+ // defaults to cwd-relative paths) and other commands return paths
75
+ // relative to the repository root, matching the `path.join(gitRoot, …)`
76
+ // computation below regardless of the caller's current working
77
+ // directory.
78
+ cwd: gitRoot,
79
+ });
72
80
  if (Result.isErr(result)) {
73
81
  return result;
74
82
  }
@@ -1 +1 @@
1
- {"version":3,"file":"diff.mjs","sources":["../../src/functions/diff.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAKA;;AAEG;MACU,UAAU,GAAG,OACxB,OAAwC,KACkC;AAC1E,IAAA,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,+BAA+B,EAAE;AACtD,QAAA,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,KAAK;AACjC,KAAA,CAAC;AAEF,IAAA,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;AACxB,QAAA,OAAO,MAAM;IACf;AAEA,IAAA,OAAO,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AAC9C;AAEA;;;AAGG;AACI,MAAM,iBAAiB,GAAG,OAC/B,OAKE,KAIF,gBAAgB,CAAC;AACf,IAAA,GAAG,EAAE,CAAA,wCAAA,CAA0C;AAC/C,IAAA,yBAAyB,EAAE,EAAE;AAC7B,IAAA,yBAAyB,EAAE,WAAW;IACtC,OAAO;AACR,CAAA;AAEH;;;AAGG;AACI,MAAM,gBAAgB,GAAG,OAC9B,OAKE,KAIF,gBAAgB,CAAC;AACf,IAAA,GAAG,EAAE,CAAA,oBAAA,CAAsB;IAC3B,yBAAyB,EAAE,iBAAiB;AAC5C,IAAA,yBAAyB,EAAE,EAAE;IAC7B,OAAO;AACR,CAAA;AAEH;;;AAGG;AACI,MAAM,cAAc,GAAG,OAC5B,OAKE,KAIF,gBAAgB,CAAC;AACf,IAAA,GAAG,EAAE,CAAA,6BAAA,CAA+B;IACpC,yBAAyB,EAAE,iBAAiB;AAC5C,IAAA,yBAAyB,EAAE,EAAE;IAC7B,OAAO;AACR,CAAA;AAEH;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IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;AAE1D,IAAA,OAAO,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC;AACzB,CAAC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-repo-utils",
3
- "version": "10.1.0",
3
+ "version": "10.1.2",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "typescript"
@@ -49,7 +49,7 @@
49
49
  "codemod:uncommitted:readonly": "convert-to-readonly --uncommitted '{src,scripts,samples}/**/*.{mts,tsx}'",
50
50
  "cspell": "cspell \"**\" --gitignore --gitignore-root ./ --no-progress",
51
51
  "doc": "tsx ./scripts/cmd/gen-docs.mts",
52
- "doc:embed": "tsx ./scripts/cmd/embed-samples.mts",
52
+ "doc:embed": "tsx ./scripts/cmd/embed-examples.mts",
53
53
  "doc:preview": "vite preview --config ./configs/vite.doc.config.mts",
54
54
  "doc:watch": "typedoc --options ./configs/typedoc.config.mjs --watch",
55
55
  "fmt": "pnpm run z:format-uncommitted",
@@ -88,7 +88,7 @@
88
88
  },
89
89
  "dependencies": {
90
90
  "@nodelib/fs.walk": "^3.0.1",
91
- "@sindresorhus/is": "^8.0.0",
91
+ "@sindresorhus/is": "^8.1.0",
92
92
  "@types/micromatch": "^4.0.10",
93
93
  "cmd-ts": "^0.15.0",
94
94
  "fast-glob": "^3.3.3",
@@ -5,7 +5,7 @@ import { assertRepoIsClean } from '../functions/index.mjs';
5
5
 
6
6
  const cmdDef = cmd.command({
7
7
  name: 'assert-repo-is-clean-cli',
8
- version: '10.1.0',
8
+ version: '10.1.2',
9
9
  args: {
10
10
  silent: cmd.flag({
11
11
  long: 'silent',
@@ -5,7 +5,7 @@ import { checkShouldRunTypeChecks } from '../functions/index.mjs';
5
5
 
6
6
  const cmdDef = cmd.command({
7
7
  name: 'check-should-run-type-checks-cli',
8
- version: '10.1.0',
8
+ version: '10.1.2',
9
9
  args: {
10
10
  pathsIgnore: cmd.multioption({
11
11
  long: 'paths-ignore',
@@ -6,7 +6,7 @@ import { formatDiffFrom } from '../functions/index.mjs';
6
6
 
7
7
  const cmdDef = cmd.command({
8
8
  name: 'format-diff-from-cli',
9
- version: '10.1.0',
9
+ version: '10.1.2',
10
10
  args: {
11
11
  base: cmd.positional({
12
12
  type: cmd.string,
@@ -6,7 +6,7 @@ import { formatUncommittedFiles } from '../functions/index.mjs';
6
6
 
7
7
  const cmdDef = cmd.command({
8
8
  name: 'format-uncommitted-cli',
9
- version: '10.1.0',
9
+ version: '10.1.2',
10
10
  args: {
11
11
  excludeUntracked: cmd.flag({
12
12
  long: 'exclude-untracked',
@@ -46,7 +46,7 @@ const nonEmptyArray = <T extends cmd.Type<any, any>>(
46
46
 
47
47
  const cmdDef = cmd.command({
48
48
  name: 'gen-index-ts-cli',
49
- version: '10.1.0',
49
+ version: '10.1.2',
50
50
  args: {
51
51
  // required args
52
52
  targetDirectory: cmd.positional({
@@ -141,7 +141,15 @@ const cmdResultToFiles = async ({
141
141
  ]
142
142
  .filter((s) => s !== '')
143
143
  .join(' '),
144
- { silent: options?.silent ?? false },
144
+ {
145
+ silent: options?.silent ?? false,
146
+ // Run git from the repository root so that `git ls-files` (which
147
+ // defaults to cwd-relative paths) and other commands return paths
148
+ // relative to the repository root, matching the `path.join(gitRoot, …)`
149
+ // computation below regardless of the caller's current working
150
+ // directory.
151
+ cwd: gitRoot,
152
+ },
145
153
  );
146
154
 
147
155
  if (Result.isErr(result)) {
@@ -143,6 +143,48 @@ describe('diff', () => {
143
143
  }
144
144
  });
145
145
 
146
+ test('should resolve paths correctly when invoked from a subdirectory', async () => {
147
+ const { repoPath, cleanup } = await createTempRepo();
148
+
149
+ try {
150
+ // Create a subdirectory and an untracked file inside it
151
+ const subDir = path.join(repoPath, 'sub');
152
+
153
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
154
+ await fs.mkdir(subDir);
155
+
156
+ const testFileName =
157
+ `test-untracked-${crypto.randomUUID()}.tmp` as const;
158
+
159
+ const testFilePath = path.join(subDir, testFileName);
160
+
161
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
162
+ await fs.writeFile(testFilePath, 'test content');
163
+
164
+ // Invoke getUntrackedFiles from the subdirectory (not from repo root).
165
+ // Without the cwd fix, git ls-files would return paths relative to
166
+ // the subdirectory, which would then be incorrectly joined with
167
+ // gitRoot.
168
+ const originalCwd = process.cwd();
169
+
170
+ process.chdir(subDir);
171
+
172
+ try {
173
+ const result = await getUntrackedFiles({ silent: true });
174
+
175
+ assert.isTrue(Result.isOk(result));
176
+
177
+ if (Result.isOk(result)) {
178
+ expect(result.value).toContain(testFilePath);
179
+ }
180
+ } finally {
181
+ process.chdir(originalCwd);
182
+ }
183
+ } finally {
184
+ await cleanup();
185
+ }
186
+ });
187
+
146
188
  test('should detect modified existing files', async () => {
147
189
  const { repoPath, cleanup, execInRepo } = await createTempRepo();
148
190