fg-devkit 1.17.0 → 1.17.1

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
@@ -152,11 +152,12 @@ Fix one or more vulnerability overrides interactively, prune unused overrides, a
152
152
  pnpm exec fgd audit-override-commit
153
153
  ```
154
154
 
155
- Report or remove workspace overrides that no longer change `pnpm audit`:
155
+ Report, remove, or remove and auto-commit workspace overrides that no longer change `pnpm audit`:
156
156
 
157
157
  ```bash
158
158
  pnpm exec fgd prune-overrides
159
159
  pnpm exec fgd prune-overrides --fix
160
+ pnpm exec fgd prune-overrides --commit
160
161
  ```
161
162
 
162
163
  ## tsconfig in consuming repos
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fg-devkit",
3
- "version": "1.17.0",
3
+ "version": "1.17.1",
4
4
  "description": "Shared configs, scripts, and DX tooling for Vue / TypeScript frontend repos",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -32,7 +32,7 @@
32
32
  "@intlify/unplugin-vue-i18n": "11.2.5",
33
33
  "@tanstack/vue-query-devtools": "6.1.48",
34
34
  "@types/node": "22.16.5",
35
- "fg-devkit": "1.17.0",
35
+ "fg-devkit": "1.17.1",
36
36
  "@vitejs/plugin-vue": "6.0.9",
37
37
  "tailwindcss": "4.3.3",
38
38
  "tsx": "4.23.13",
@@ -17,7 +17,7 @@
17
17
  * pnpm exec fg-devkit policy-upgrade [policy-file] [ncu-args...]
18
18
  * pnpm exec fg-devkit policy-upgrade-commit [--prune-overrides] [ncu-args...]
19
19
  * pnpm exec fg-devkit audit-override-commit [pnpm-audit-args...]
20
- * pnpm exec fg-devkit prune-overrides [--fix]
20
+ * pnpm exec fg-devkit prune-overrides [--fix] [--commit]
21
21
  * pnpm exec fg-devkit sync-project-configs (VS Code + tooling sync; overwrites config files)
22
22
  * pnpm exec fg-devkit sync-tooling-configs (tooling sync only; overwrites config files)
23
23
  * pnpm exec fg-devkit sync-vscode-settings
@@ -539,7 +539,8 @@ Commands:
539
539
  --prune-overrides also drops unused workspace overrides in a second commit
540
540
  audit-override-commit [pnpm-audit-args...]
541
541
  Fix vulnerability overrides via pnpm audit, prune unused ones, auto-commit
542
- prune-overrides [--fix] Report (or --fix remove) workspace overrides that no longer affect pnpm audit
542
+ prune-overrides [--fix] [--commit]
543
+ Report unused workspace overrides; --fix removes them; --commit also auto-commits
543
544
  sync-project-configs VS Code + tooling sync (overwrites config files)
544
545
  sync-tooling-configs Tooling sync only (overwrites config files)
545
546
  sync-vscode-settings Copy shared VS Code settings into .vscode/settings.json
@@ -818,7 +819,7 @@ async function runInteractiveMenu() {
818
819
  { name: 'Upgrade package.json packages and auto-commit', value: 'upgrade-commit' },
819
820
  { name: 'Upgrade package.json packages, prune overrides, and auto-commit', value: 'upgrade-commit-prune' },
820
821
  { name: 'Fix vulnerability overrides and auto-commit', value: 'audit-override-commit' },
821
- { name: 'Prune unused vulnerability overrides', value: 'prune-overrides' },
822
+ { name: 'Prune unused vulnerability overrides and auto-commit', value: 'prune-overrides' },
822
823
  { name: 'Cancel', value: 'cancel' },
823
824
  ],
824
825
  default: 'check',
@@ -839,7 +840,7 @@ async function runInteractiveMenu() {
839
840
  return runSelectedAction(() => runNode('audit-override-commit.mjs'))
840
841
  }
841
842
  if (choice === 'prune-overrides') {
842
- return runSelectedAction(() => runNode('prune-overrides.mjs', ['--fix']))
843
+ return runSelectedAction(() => runNode('prune-overrides.mjs', ['--commit']))
843
844
  }
844
845
  return 1
845
846
  }
@@ -8,8 +8,9 @@
8
8
  * dropped just because each is redundant while the others exist.
9
9
  *
10
10
  * Usage:
11
- * pnpm exec fg-devkit prune-overrides # report only
12
- * pnpm exec fg-devkit prune-overrides --fix # drop the prunable entries
11
+ * pnpm exec fg-devkit prune-overrides # report only
12
+ * pnpm exec fg-devkit prune-overrides --fix # drop the prunable entries
13
+ * pnpm exec fg-devkit prune-overrides --commit # drop them and auto-commit
13
14
  */
14
15
 
15
16
  import { mkdtempSync, rmSync, cpSync, readFileSync, writeFileSync, existsSync } from 'node:fs'
@@ -17,6 +18,12 @@ import { tmpdir } from 'node:os'
17
18
  import { join } from 'node:path'
18
19
  import { spawnSync } from 'node:child_process'
19
20
  import { parseArgs } from 'node:util'
21
+ import {
22
+ buildOverrideCommitMessage,
23
+ collectOverrideChanges,
24
+ collectOverrides,
25
+ formatOverrideValue,
26
+ } from './override-changes.mjs'
20
27
 
21
28
  const ROOT = process.cwd()
22
29
  const WORKSPACE_FILE = 'pnpm-workspace.yaml'
@@ -25,19 +32,71 @@ const COPIED_FILES = ['package.json', 'pnpm-lock.yaml', WORKSPACE_FILE, '.npmrc'
25
32
  const { values: args } = parseArgs({
26
33
  options: {
27
34
  fix: { type: 'boolean', default: false },
35
+ commit: { type: 'boolean', default: false },
28
36
  help: { type: 'boolean', short: 'h', default: false },
29
37
  },
30
38
  strict: true,
31
39
  })
32
40
 
33
41
  if (args.help) {
34
- console.log(`Usage: pnpm exec fg-devkit prune-overrides [--fix]
42
+ console.log(`Usage: pnpm exec fg-devkit prune-overrides [--fix] [--commit]
35
43
 
36
44
  Reports workspace overrides that can be removed without introducing new
37
- pnpm audit findings. Pass --fix to delete those entries in place.`)
45
+ pnpm audit findings. Pass --fix to delete those entries in place.
46
+ Pass --commit to apply the deletions and auto-commit.`)
38
47
  process.exit(0)
39
48
  }
40
49
 
50
+ const shouldFix = args.fix || args.commit
51
+
52
+ function runGit(gitArgs) {
53
+ const result = spawnSync('git', gitArgs, {
54
+ stdio: 'inherit',
55
+ cwd: ROOT,
56
+ env: process.env,
57
+ })
58
+ if (result.error) {
59
+ console.error('[prune-overrides]', result.error.message)
60
+ return 1
61
+ }
62
+ return result.status ?? 1
63
+ }
64
+
65
+ function commitOverrideChanges(beforeOverrides, afterOverrides) {
66
+ const changed = collectOverrideChanges(beforeOverrides, afterOverrides)
67
+ if (changed.length === 0) {
68
+ console.log('[prune-overrides] No override changes to commit.')
69
+ return 0
70
+ }
71
+
72
+ console.log('[prune-overrides] Override changes detected:')
73
+ for (const item of changed) {
74
+ const fromLabel = item.from ?? '(missing)'
75
+ console.log(` - ${item.name}: ${fromLabel} -> ${formatOverrideValue(item.to)}`)
76
+ }
77
+
78
+ const files = ['package.json', 'pnpm-lock.yaml', WORKSPACE_FILE].filter((file) =>
79
+ existsSync(join(ROOT, file)),
80
+ )
81
+ if (files.length === 0) {
82
+ console.error('[prune-overrides] No files to stage.')
83
+ return 1
84
+ }
85
+
86
+ const stageExitCode = runGit(['add', '--', ...files])
87
+ if (stageExitCode !== 0) {
88
+ return stageExitCode
89
+ }
90
+
91
+ const { subject, body } = buildOverrideCommitMessage(changed)
92
+ console.log(`[prune-overrides] Auto-committing: ${subject}`)
93
+ if (body) {
94
+ console.log(body)
95
+ }
96
+ const commitArgs = body ? ['commit', '-m', subject, '-m', body] : ['commit', '-m', subject]
97
+ return runGit(commitArgs)
98
+ }
99
+
41
100
  function runPnpm(cwd, pnpmArgs, { allowFailure = false } = {}) {
42
101
  const result = spawnSync('pnpm', pnpmArgs, {
43
102
  cwd,
@@ -252,16 +311,22 @@ function main() {
252
311
  console.log(` - ${key}`)
253
312
  }
254
313
 
255
- if (!args.fix) {
256
- console.log('\nRe-run with --fix to remove them from pnpm-workspace.yaml.')
314
+ if (!shouldFix) {
315
+ console.log('\nRe-run with --fix to remove them, or --commit to remove and auto-commit.')
257
316
  return 0
258
317
  }
259
318
 
319
+ const beforeOverrides = collectOverrides(ROOT)
260
320
  writeFileSync(workspacePath, writeOverrides(original, remaining.keys()))
261
321
  console.log('\nUpdated pnpm-workspace.yaml. Refreshing lockfile…')
262
322
  runPnpm(ROOT, ['install', '--no-frozen-lockfile', '--ignore-scripts'])
263
- console.log('Done.')
264
- return 0
323
+
324
+ if (!args.commit) {
325
+ console.log('Done.')
326
+ return 0
327
+ }
328
+
329
+ return commitOverrideChanges(beforeOverrides, collectOverrides(ROOT))
265
330
  } finally {
266
331
  rmSync(tempDir, { recursive: true, force: true })
267
332
  }