ts-repo-utils 7.3.1 → 7.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.
package/README.md CHANGED
@@ -394,6 +394,39 @@ type Ret = Result<
394
394
  >;
395
395
  ```
396
396
 
397
+ #### Build Optimization Utilities
398
+
399
+ ##### `checkShouldRunTypeChecks(options?): Promise<boolean>`
400
+
401
+ Checks whether TypeScript type checks should run based on file changes from the base branch. Optimizes CI/CD pipelines by skipping type checks when only non-TypeScript files have changed.
402
+ (Function version of the `check-should-run-type-checks` command)
403
+
404
+ ```typescript
405
+ import { checkShouldRunTypeChecks } from 'ts-repo-utils';
406
+
407
+ // Use default settings (compare against origin/main)
408
+ const shouldRun = await checkShouldRunTypeChecks();
409
+
410
+ if (shouldRun) {
411
+ await $('npm run type-check');
412
+ }
413
+
414
+ // Custom ignore patterns and base branch
415
+ const shouldRun2 = await checkShouldRunTypeChecks({
416
+ pathsIgnore: ['.eslintrc.json', 'docs/', '**.md', 'scripts/'],
417
+ baseBranch: 'origin/develop',
418
+ });
419
+ ```
420
+
421
+ **Options:**
422
+
423
+ - `pathsIgnore?` - Patterns to ignore when checking if type checks should run:
424
+ - Exact file matches: `.cspell.json`
425
+ - Directory prefixes: `docs/` (matches any file in docs directory)
426
+ - File extensions: `**.md` (matches any markdown file)
427
+ - Default: `['LICENSE', '.editorconfig', '.gitignore', '.cspell.json', '.markdownlint-cli2.mjs', '.npmignore', '.prettierignore', '.prettierrc', 'docs/', '**.md', '**.txt']`
428
+ - `baseBranch?` - Base branch to compare against (default: `origin/main`)
429
+
397
430
  ### Code Formatting Utilities
398
431
 
399
432
  #### `formatFilesGlob(pathGlob: string, options?): Promise<Result<undefined, unknown>>`
@@ -690,7 +723,10 @@ import 'ts-repo-utils';
690
723
 
691
724
  // Now these functions are globally available
692
725
 
693
- await $('npm test');
726
+ const result = await $('npm test');
727
+ if (Result.isErr(result)) {
728
+ console.error(result.value);
729
+ }
694
730
 
695
731
  echo('Building project...');
696
732
 
@@ -708,6 +744,7 @@ if (isDirectlyExecuted(import.meta.url)) {
708
744
  ```
709
745
 
710
746
  - `$` - The command execution utility described above.
747
+ - `Result` - A utility for Result pattern (from [ts-data-forge](https://github.com/noshiro-pf/ts-data-forge#readme))
711
748
  - `echo` - Equivalent to `console.log`
712
749
  - `path` - `node:path`
713
750
  - `fs` - `node:fs/promises`
@@ -11,7 +11,7 @@ import 'child_process';
11
11
 
12
12
  const cmdDef = cmd.command({
13
13
  name: 'assert-repo-is-clean-cli',
14
- version: '7.3.1',
14
+ version: '7.5.0',
15
15
  args: {
16
16
  silent: cmd.flag({
17
17
  long: 'silent',
@@ -11,7 +11,7 @@ import 'child_process';
11
11
 
12
12
  const cmdDef = cmd.command({
13
13
  name: 'check-should-run-type-checks-cli',
14
- version: '7.3.1',
14
+ version: '7.5.0',
15
15
  args: {
16
16
  pathsIgnore: cmd.multioption({
17
17
  long: 'paths-ignore',
@@ -10,7 +10,7 @@ import 'child_process';
10
10
 
11
11
  const cmdDef = cmd.command({
12
12
  name: 'format-diff-from-cli',
13
- version: '7.3.1',
13
+ version: '7.5.0',
14
14
  args: {
15
15
  base: cmd.positional({
16
16
  type: cmd.string,
@@ -10,7 +10,7 @@ import 'child_process';
10
10
 
11
11
  const cmdDef = cmd.command({
12
12
  name: 'format-uncommitted-cli',
13
- version: '7.3.1',
13
+ version: '7.5.0',
14
14
  args: {
15
15
  excludeUntracked: cmd.flag({
16
16
  long: 'exclude-untracked',
@@ -29,7 +29,7 @@ const nonEmptyArray = (t, commandName) => cmd.extendType(cmd.array(t), {
29
29
  });
30
30
  const cmdDef = cmd.command({
31
31
  name: 'gen-index-ts-cli',
32
- version: '7.3.1',
32
+ version: '7.5.0',
33
33
  args: {
34
34
  // required args
35
35
  targetDirectory: cmd.positional({
@@ -56,5 +56,5 @@ import '../node-global.mjs';
56
56
  export declare const checkShouldRunTypeChecks: (options?: Readonly<{
57
57
  pathsIgnore?: readonly string[];
58
58
  baseBranch?: string;
59
- }>) => Promise<void>;
59
+ }>) => Promise<boolean>;
60
60
  //# sourceMappingURL=should-run.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"should-run.d.mts","sourceRoot":"","sources":["../../src/functions/should-run.mts"],"names":[],"mappings":"AACA,OAAO,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,eAAO,MAAM,wBAAwB,GACnC,UAAU,QAAQ,CAAC;IACjB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC,KACD,OAAO,CAAC,IAAI,CAmDd,CAAC"}
1
+ {"version":3,"file":"should-run.d.mts","sourceRoot":"","sources":["../../src/functions/should-run.mts"],"names":[],"mappings":"AACA,OAAO,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,eAAO,MAAM,wBAAwB,GACnC,UAAU,QAAQ,CAAC;IACjB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC,KACD,OAAO,CAAC,OAAO,CAqDjB,CAAC"}
@@ -96,6 +96,7 @@ const checkShouldRunTypeChecks = async (options) => {
96
96
  if (GITHUB_OUTPUT !== undefined) {
97
97
  await fs.appendFile(GITHUB_OUTPUT, `should_run=${shouldRunTsChecks}\n`);
98
98
  }
99
+ return shouldRunTsChecks;
99
100
  };
100
101
 
101
102
  export { checkShouldRunTypeChecks };
@@ -1 +1 @@
1
- {"version":3,"file":"should-run.mjs","sources":["../../src/functions/should-run.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDG;MACU,wBAAwB,GAAG,OACtC,OAGE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AC7B,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACnC,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;QAChD;AAEA,QAAA,OAAO,KAAK;IACd,CAAC,CAAC,CACH;AAED,IAAA,IAAI,aAAa,KAAK,SAAS,EAAE;QAC/B,MAAM,EAAE,CAAC,UAAU,CAAC,aAAa,EAAE,CAAA,WAAA,EAAc,iBAAiB,CAAA,EAAA,CAAI,CAAC;IACzE;AAEA,IAAA,OAAO,iBAAiB;AAC1B;;;;"}
@@ -1,6 +1,7 @@
1
1
  import { default as glob_ } from 'fast-glob';
2
2
  import * as fs_ from 'node:fs/promises';
3
3
  import * as path_ from 'node:path';
4
+ import { Result as Result_ } from 'ts-data-forge';
4
5
  import { $ as $_ } from './functions/exec-async.mjs';
5
6
  import { isDirectlyExecuted as isDirectlyExecuted_ } from './functions/is-directly-executed.mjs';
6
7
  declare global {
@@ -10,5 +11,7 @@ declare global {
10
11
  const fs: typeof fs_;
11
12
  const glob: typeof glob_;
12
13
  const isDirectlyExecuted: typeof isDirectlyExecuted_;
14
+ const Result: typeof Result_;
15
+ type Result<S, E> = Result_<S, E>;
13
16
  }
14
17
  //# sourceMappingURL=node-global.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-global.d.mts","sourceRoot":"","sources":["../src/node-global.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,kBAAkB,IAAI,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAejG,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IACnB,MAAM,IAAI,EAAE,OAAO,OAAO,CAAC,GAAG,CAAC;IAE/B,MAAM,IAAI,EAAE,OAAO,KAAK,CAAC;IACzB,MAAM,EAAE,EAAE,OAAO,GAAG,CAAC;IACrB,MAAM,IAAI,EAAE,OAAO,KAAK,CAAC;IACzB,MAAM,kBAAkB,EAAE,OAAO,mBAAmB,CAAC;CACtD"}
1
+ {"version":3,"file":"node-global.d.mts","sourceRoot":"","sources":["../src/node-global.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,kBAAkB,IAAI,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAgBjG,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IACnB,MAAM,IAAI,EAAE,OAAO,OAAO,CAAC,GAAG,CAAC;IAE/B,MAAM,IAAI,EAAE,OAAO,KAAK,CAAC;IACzB,MAAM,EAAE,EAAE,OAAO,GAAG,CAAC;IACrB,MAAM,IAAI,EAAE,OAAO,KAAK,CAAC;IACzB,MAAM,kBAAkB,EAAE,OAAO,mBAAmB,CAAC;IACrD,MAAM,MAAM,EAAE,OAAO,OAAO,CAAC;IAC7B,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACnC"}
@@ -1,6 +1,7 @@
1
1
  import glob_ from 'fast-glob';
2
2
  import * as fs_ from 'node:fs/promises';
3
3
  import * as path_ from 'node:path';
4
+ import { Result } from 'ts-data-forge';
4
5
  import { $ } from './functions/exec-async.mjs';
5
6
  import { isDirectlyExecuted } from './functions/is-directly-executed.mjs';
6
7
 
@@ -12,6 +13,7 @@ const globalsDef = {
12
13
  fs: fs_,
13
14
  glob: glob_,
14
15
  isDirectlyExecuted: isDirectlyExecuted,
16
+ Result: Result,
15
17
  };
16
18
  // eslint-disable-next-line functional/immutable-data
17
19
  Object.assign(globalThis, globalsDef);
@@ -1 +1 @@
1
- {"version":3,"file":"node-global.mjs","sources":["../src/node-global.mts"],"sourcesContent":[null],"names":["$_","isDirectlyExecuted_"],"mappings":";;;;;;AAAA;AAOA,MAAM,UAAU,GAAG;AACjB,IAAA,CAAC,EAAEA,CAAE;IACL,IAAI,EAAE,OAAO,CAAC,GAAG;AAEjB,IAAA,IAAI,EAAE,KAAK;AACX,IAAA,EAAE,EAAE,GAAG;AACP,IAAA,IAAI,EAAE,KAAK;AACX,IAAA,kBAAkB,EAAEC,kBAAmB;CAC/B;AAEV;AACA,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC"}
1
+ {"version":3,"file":"node-global.mjs","sources":["../src/node-global.mts"],"sourcesContent":[null],"names":["$_","isDirectlyExecuted_","Result_"],"mappings":";;;;;;;AAAA;AAQA,MAAM,UAAU,GAAG;AACjB,IAAA,CAAC,EAAEA,CAAE;IACL,IAAI,EAAE,OAAO,CAAC,GAAG;AAEjB,IAAA,IAAI,EAAE,KAAK;AACX,IAAA,EAAE,EAAE,GAAG;AACP,IAAA,IAAI,EAAE,KAAK;AACX,IAAA,kBAAkB,EAAEC,kBAAmB;AACvC,IAAA,MAAM,EAAEC,MAAO;CACP;AAEV;AACA,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-repo-utils",
3
- "version": "7.3.1",
3
+ "version": "7.5.0",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "typescript"
@@ -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: '7.3.1',
8
+ version: '7.5.0',
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: '7.3.1',
8
+ version: '7.5.0',
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: '7.3.1',
9
+ version: '7.5.0',
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: '7.3.1',
9
+ version: '7.5.0',
10
10
  args: {
11
11
  excludeUntracked: cmd.flag({
12
12
  long: 'exclude-untracked',
@@ -38,7 +38,7 @@ const nonEmptyArray = <T extends cmd.Type<any, any>>(
38
38
 
39
39
  const cmdDef = cmd.command({
40
40
  name: 'gen-index-ts-cli',
41
- version: '7.3.1',
41
+ version: '7.5.0',
42
42
  args: {
43
43
  // required args
44
44
  targetDirectory: cmd.positional({
@@ -61,7 +61,7 @@ export const checkShouldRunTypeChecks = async (
61
61
  pathsIgnore?: readonly string[];
62
62
  baseBranch?: string;
63
63
  }>,
64
- ): Promise<void> => {
64
+ ): Promise<boolean> => {
65
65
  const pathsIgnore = options?.pathsIgnore ?? [
66
66
  'LICENSE',
67
67
  '.editorconfig',
@@ -112,4 +112,6 @@ export const checkShouldRunTypeChecks = async (
112
112
  if (GITHUB_OUTPUT !== undefined) {
113
113
  await fs.appendFile(GITHUB_OUTPUT, `should_run=${shouldRunTsChecks}\n`);
114
114
  }
115
+
116
+ return shouldRunTsChecks;
115
117
  };
@@ -2,6 +2,7 @@
2
2
  import { default as glob_ } from 'fast-glob';
3
3
  import * as fs_ from 'node:fs/promises';
4
4
  import * as path_ from 'node:path';
5
+ import { Result as Result_ } from 'ts-data-forge';
5
6
  import { $ as $_ } from './functions/exec-async.mjs';
6
7
  import { isDirectlyExecuted as isDirectlyExecuted_ } from './functions/is-directly-executed.mjs';
7
8
 
@@ -13,6 +14,7 @@ const globalsDef = {
13
14
  fs: fs_,
14
15
  glob: glob_,
15
16
  isDirectlyExecuted: isDirectlyExecuted_,
17
+ Result: Result_,
16
18
  } as const;
17
19
 
18
20
  // eslint-disable-next-line functional/immutable-data
@@ -26,4 +28,6 @@ declare global {
26
28
  const fs: typeof fs_;
27
29
  const glob: typeof glob_;
28
30
  const isDirectlyExecuted: typeof isDirectlyExecuted_;
31
+ const Result: typeof Result_;
32
+ type Result<S, E> = Result_<S, E>;
29
33
  }