Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Upgrade your dependencies interactively. Works with npm, yarn, pnpm, and bun.
npx inup
```

Scan deeper package layouts:

```bash
npx inup --max-depth 15
```

Or install globally:

```bash
Expand Down Expand Up @@ -50,7 +56,10 @@ inup [options]

-d, --dir <path> Run in specific directory
-e, --exclude <patterns> Skip directories (comma-separated regex)
-i, --ignore <packages> Ignore packages (comma-separated, glob supported)
--max-depth <number> Maximum scan depth for package discovery (default: 10)
--package-manager <name> Force package manager (npm, yarn, pnpm, bun)
--debug Write verbose debug logs
```

## 🔒 Privacy
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
"devDependencies": {
"@types/inquirer": "^9.0.9",
"@types/keypress.js": "^2.1.3",
"@types/node": "^24.10.1",
"@types/node": "^24.12.0",
"@types/semver": "^7.7.1",
"@vitest/coverage-v8": "^3.2.4",
"@vitest/coverage-v8": "^4.1.0",
"prettier": "^3.8.1",
"typescript": "^5.9.3",
"vitest": "^3.2.4"
"vitest": "^4.1.0"
},
"dependencies": {
"chalk": "^5.6.2",
Expand Down
807 changes: 205 additions & 602 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ program
.option('-d, --dir <directory>', 'specify directory to run in', process.cwd())
.option('-e, --exclude <patterns>', 'exclude paths matching regex patterns (comma-separated)', '')
.option('-i, --ignore <packages>', 'ignore packages (comma-separated, supports glob patterns like @babel/*)')
.option('--max-depth <number>', 'maximum directory depth for package.json discovery', '10')
.option('--package-manager <name>', 'manually specify package manager (npm, yarn, pnpm, bun)')
.option('--debug', 'write verbose debug log to /tmp/inup-debug-YYYY-MM-DD.log')
.action(async (options) => {
console.log(chalk.bold.blue(`🚀 `) + chalk.bold.red(`i`) + chalk.bold.yellow(`n`) + chalk.bold.blue(`u`) + chalk.bold.magenta(`p`) + `\n`)

// Check for updates in the background (non-blocking)
const updateCheckPromise = checkForUpdateAsync('inup', packageJson.version)

const cwd = resolve(options.dir)

if (options.debug || process.env.INUP_DEBUG === '1') {
Expand Down Expand Up @@ -56,6 +54,16 @@ program
: []
const ignorePackages = [...new Set([...cliIgnorePatterns, ...(projectConfig.ignore || [])])]

const maxDepth = Number.parseInt(options.maxDepth, 10)
if (!Number.isInteger(maxDepth) || maxDepth < 0) {
console.error(chalk.red(`Invalid max depth: ${options.maxDepth}`))
console.error(chalk.yellow('Expected a non-negative integer, for example: --max-depth 10'))
process.exit(1)
}

// Check for updates in the background (non-blocking)
const updateCheckPromise = checkForUpdateAsync('inup', packageJson.version)

// Validate package manager if provided
let packageManager: PackageManager | undefined
if (options.packageManager) {
Expand All @@ -71,6 +79,7 @@ program
const upgrader = new UpgradeRunner({
cwd,
excludePatterns,
maxDepth,
ignorePackages,
packageManager,
debug: options.debug || process.env.INUP_DEBUG === '1',
Expand Down
45 changes: 31 additions & 14 deletions src/core/package-detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PackageInfo, PackageJson, UpgradeOptions } from '../types'
import {
findPackageJson,
readPackageJson,
findAllPackageJsonFiles,
findAllPackageJsonFilesAsync,
collectAllDependenciesAsync,
findClosestMinorVersion,
} from '../utils'
Expand All @@ -18,11 +18,13 @@ export class PackageDetector {
private cwd: string
private excludePatterns: string[]
private ignorePackages: string[]
private maxDepth: number

constructor(options?: UpgradeOptions) {
this.cwd = options?.cwd || process.cwd()
this.excludePatterns = options?.excludePatterns || []
this.ignorePackages = options?.ignorePackages || []
this.maxDepth = options?.maxDepth ?? 10
this.packageJsonPath = findPackageJson(this.cwd)
if (this.packageJsonPath) {
this.packageJson = readPackageJson(this.packageJsonPath)
Expand All @@ -45,7 +47,7 @@ export class PackageDetector {
// Always check all package.json files recursively with timeout protection
this.showProgress('🔍 Scanning repository for package.json files...')
const tScan = Date.now()
const allPackageJsonFiles = this.findPackageJsonFilesWithTimeout(30000) // 30 second timeout
const allPackageJsonFiles = await this.findPackageJsonFilesWithTimeout(30000) // 30 second timeout
debugLog.perf('PackageDetector', `file scan (${allPackageJsonFiles.length} files)`, tScan, {
files: allPackageJsonFiles,
})
Expand Down Expand Up @@ -222,20 +224,35 @@ export class PackageDetector {
}
}

private findPackageJsonFilesWithTimeout(timeoutMs: number): string[] {
// Synchronous file search with depth limiting and symlink protection
// The timeout parameter is kept for future async implementation
private async findPackageJsonFilesWithTimeout(timeoutMs: number): Promise<string[]> {
try {
return findAllPackageJsonFiles(
this.cwd,
this.excludePatterns,
10,
(currentDir: string, foundCount: number) => {
// Show scanning progress with current directory and count
const truncatedDir = currentDir.length > 50 ? '...' + currentDir.slice(-47) : currentDir
this.showProgress(`🔍 Scanning ${truncatedDir} (found ${foundCount})`)
let timeoutId: NodeJS.Timeout | undefined

try {
return await Promise.race([
findAllPackageJsonFilesAsync(
this.cwd,
this.excludePatterns,
this.maxDepth,
(currentDir: string, foundCount: number) => {
// Show scanning progress with current directory and count
const truncatedDir =
currentDir.length > 50 ? '...' + currentDir.slice(-47) : currentDir
this.showProgress(`🔍 Scanning ${truncatedDir} (found ${foundCount})`)
}
),
new Promise<string[]>((_, reject) => {
timeoutId = setTimeout(() => {
reject(new Error(`Scan timed out after ${timeoutMs}ms`))
}, timeoutMs)
timeoutId.unref?.()
}),
])
} finally {
if (timeoutId) {
clearTimeout(timeoutId)
}
)
}
} catch (err) {
throw new Error(
`Failed to scan for package.json files: ${err}. Try using --exclude patterns to skip problematic directories.`
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export interface PackageManagerInfo {
export interface UpgradeOptions {
cwd?: string
excludePatterns?: string[]
maxDepth?: number // Maximum package.json scan depth, defaults to 10
packageManager?: PackageManager // Manual override for package manager
ignorePackages?: string[] // Package names/patterns to ignore (from .inuprc or --ignore flag)
debug?: boolean // Write verbose debug log to /tmp/inup-debug-YYYY-MM-DD.log
Expand Down
Loading
Loading