@bobfrankston/npmglobalize 1.0.193 → 1.0.194

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 (4) hide show
  1. package/cli.js +36 -1
  2. package/lib.d.ts +12 -0
  3. package/lib.js +48 -1
  4. package/package.json +1 -1
package/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * npmglobalize CLI - Transform file: dependencies to npm versions for publishing
4
4
  */
5
- import { globalize, globalizeWorkspace, installCleanupHandlers, readConfig, readPackageJson, readUserNpmConfig, writeConfig, writePackageJson, getBuildIssues, clearBuildIssues, ensureFileDepModules, buildProject, buildFileDepsTopologically, reportTs7Deprecations } from './lib.js';
5
+ import { globalize, globalizeWorkspace, installCleanupHandlers, readConfig, readPackageJson, readUserNpmConfig, writeConfig, writePackageJson, getBuildIssues, clearBuildIssues, ensureFileDepModules, buildProject, buildFileDepsTopologically, reportTs7Deprecations, fixTs7Deprecations } from './lib.js';
6
6
  import fs from 'fs';
7
7
  import path from 'path';
8
8
  import { colors } from './colors.js';
@@ -121,6 +121,11 @@ Other Options:
121
121
  compilerOptions removed in TypeScript 7 (deprecated
122
122
  moduleResolution, target es3, deprecated flags). Lists a
123
123
  migration to-do list and exits. Writes nothing.
124
+ -tsfix, -ts7-fix
125
+ Fix-only: apply the TS7 tsconfig migration to this package
126
+ and its file: deps, then exit. Only tsconfig files change —
127
+ no build, no commit, no push, no publish. Use on any local
128
+ directory: npmglobalize <path> -tsfix
124
129
  -show Show package.json dependency changes
125
130
  -package, -pkg Update package.json scripts to use npmglobalize
126
131
  -h, -help Show this help
@@ -161,6 +166,7 @@ function parseArgs(args) {
161
166
  version: false,
162
167
  error: '',
163
168
  ts7Report: false,
169
+ ts7Fix: false,
164
170
  explicitKeys: new Set()
165
171
  };
166
172
  const unrecognized = [];
@@ -182,6 +188,10 @@ function parseArgs(args) {
182
188
  case '-deprecation-report':
183
189
  options.ts7Report = true;
184
190
  break;
191
+ case '-tsfix':
192
+ case '-ts7-fix':
193
+ options.ts7Fix = true;
194
+ break;
185
195
  case '-patch':
186
196
  options.bump = 'patch';
187
197
  break;
@@ -515,6 +525,31 @@ export async function main() {
515
525
  printTs7Report(cwd);
516
526
  process.exit(0);
517
527
  }
528
+ // Fix-only TS7 tsconfig migration (no build / commit / push / publish).
529
+ if (cliOptions.ts7Fix) {
530
+ console.log('');
531
+ console.log(colors.accent('━━━ TypeScript 7 tsconfig fix ━━━'));
532
+ const { changedDirs, remaining } = fixTs7Deprecations(cwd);
533
+ if (changedDirs.length === 0) {
534
+ console.log(colors.success(' ✓ Nothing to fix — no removed-in-TS7 compilerOptions in writable tsconfigs.'));
535
+ }
536
+ else {
537
+ console.log(colors.success(` ✓ Patched tsconfig(s) in ${changedDirs.length} package(s):`));
538
+ for (const dir of changedDirs)
539
+ console.log(` ${dir}`);
540
+ console.log(colors.muted(' Rebuild to validate — NodeNext resolution may surface real import errors the old resolver hid.'));
541
+ }
542
+ if (remaining.length > 0) {
543
+ console.log(colors.warn(` ${remaining.length} item(s) could not be auto-fixed:`));
544
+ for (const f of remaining) {
545
+ console.log(colors.warn(` • ${f.name}: ${f.option}=${JSON.stringify(f.value)} (in ${f.definedIn})`));
546
+ console.log(colors.muted(` → ${f.action}`));
547
+ }
548
+ }
549
+ console.log('');
550
+ printBuildSummary();
551
+ process.exit(remaining.length > 0 ? 1 : 0);
552
+ }
518
553
  // Build file: deps topologically, then the target itself.
519
554
  // Ensures consumers' tsc sees up-to-date `.d.ts` from sibling checkouts
520
555
  // whose source has changed since their last build.
package/lib.d.ts CHANGED
@@ -347,6 +347,18 @@ export interface Ts7Finding {
347
347
  * The same migration `migrateTsconfigDeprecations` applies automatically on a build
348
348
  * failure; this report is the read-only, whole-graph inventory. */
349
349
  export declare function reportTs7Deprecations(cwd: string): Ts7Finding[];
350
+ /** Standalone fix mode (`-tsfix`): apply `migrateTsconfigDeprecations` to `cwd`
351
+ * and every package reachable through its `file:` dep graph — the write
352
+ * counterpart of `reportTs7Deprecations`. No git, no version bump, no publish;
353
+ * only tsconfig files change. After migrating, any `ignoreDeprecations` whose
354
+ * package has nothing deprecated left is deleted too (kept, it would silence
355
+ * the next real TS7-removal error). Returns the dirs whose tsconfigs changed
356
+ * plus the findings that remain (e.g. options inherited from read-only
357
+ * node_modules bases). */
358
+ export declare function fixTs7Deprecations(cwd: string): {
359
+ changedDirs: string[];
360
+ remaining: Ts7Finding[];
361
+ };
350
362
  /** Ensure the workspace-root `node_modules/` is in sync with every member's
351
363
  * declared deps. Workspaces hoist deps to the root, so a dep added to any
352
364
  * member `package.json` without a follow-up `npm install` at the root leaves
package/lib.js CHANGED
@@ -2477,6 +2477,53 @@ export function reportTs7Deprecations(cwd) {
2477
2477
  }
2478
2478
  return findings;
2479
2479
  }
2480
+ /** Standalone fix mode (`-tsfix`): apply `migrateTsconfigDeprecations` to `cwd`
2481
+ * and every package reachable through its `file:` dep graph — the write
2482
+ * counterpart of `reportTs7Deprecations`. No git, no version bump, no publish;
2483
+ * only tsconfig files change. After migrating, any `ignoreDeprecations` whose
2484
+ * package has nothing deprecated left is deleted too (kept, it would silence
2485
+ * the next real TS7-removal error). Returns the dirs whose tsconfigs changed
2486
+ * plus the findings that remain (e.g. options inherited from read-only
2487
+ * node_modules bases). */
2488
+ export function fixTs7Deprecations(cwd) {
2489
+ const changedDirs = [];
2490
+ for (const dir of collectFileDepDirs(cwd)) {
2491
+ if (migrateTsconfigDeprecations(dir))
2492
+ changedDirs.push(dir);
2493
+ }
2494
+ // Drop ignoreDeprecations wherever nothing deprecated remains in that package.
2495
+ let remaining = reportTs7Deprecations(cwd);
2496
+ const igdDirs = new Set(remaining.filter(f => f.option === 'ignoreDeprecations').map(f => f.dir));
2497
+ let removedIgd = false;
2498
+ for (const dir of igdDirs) {
2499
+ if (remaining.some(f => f.dir === dir && f.option !== 'ignoreDeprecations'))
2500
+ continue;
2501
+ const { chain } = resolveTsconfigChain(path.join(dir, 'tsconfig.json'));
2502
+ const igd = effectiveCompilerOption(chain, 'ignoreDeprecations');
2503
+ if (!igd)
2504
+ continue;
2505
+ const def = chain.find(c => c.path === igd.definedIn);
2506
+ if (!def?.writable)
2507
+ continue;
2508
+ try {
2509
+ const text = fs.readFileSync(def.path, 'utf-8');
2510
+ const patched = removeCompilerOptionLine(text, 'ignoreDeprecations');
2511
+ if (patched != null && patched !== text) {
2512
+ fs.writeFileSync(def.path, patched);
2513
+ removedIgd = true;
2514
+ if (!changedDirs.includes(dir))
2515
+ changedDirs.push(dir);
2516
+ console.log(colors.cyan(` Removed "ignoreDeprecations" from ${path.relative(dir, def.path) || 'tsconfig.json'} (${path.basename(dir)})`));
2517
+ }
2518
+ }
2519
+ catch (error) {
2520
+ console.error(colors.yellow(` Could not remove ignoreDeprecations (${def.path}): ${error.message}`));
2521
+ }
2522
+ }
2523
+ if (removedIgd)
2524
+ remaining = reportTs7Deprecations(cwd);
2525
+ return { changedDirs, remaining };
2526
+ }
2480
2527
  /** Ensure the workspace-root `node_modules/` is in sync with every member's
2481
2528
  * declared deps. Workspaces hoist deps to the root, so a dep added to any
2482
2529
  * member `package.json` without a follow-up `npm install` at the root leaves
@@ -2704,7 +2751,7 @@ async function installGlobalWithRetry(pkgSpec, cwd, isNewPackage = false, maxRet
2704
2751
  const combined = `${result.output}\n${result.stderr}`;
2705
2752
  fullLog += `===== attempt ${attempt + 1}: npm install -g ${pkgSpec} =====\n${combined}\n`;
2706
2753
  if (result.success) {
2707
- const added = combined.match(/^added \d+ packages?.*$/m);
2754
+ const added = combined.match(/^(?:added|changed|removed) \d+ packages?.*$/m);
2708
2755
  if (added)
2709
2756
  console.log(colors.dim(` ${added[0]}`));
2710
2757
  warnSkippedScripts(combined);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/npmglobalize",
3
- "version": "1.0.193",
3
+ "version": "1.0.194",
4
4
  "description": "Transform file: dependencies to npm versions for publishing",
5
5
  "main": "index.js",
6
6
  "type": "module",