inup 1.4.9 → 1.4.10

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
@@ -14,6 +14,12 @@ Upgrade your dependencies interactively. Works with npm, yarn, pnpm, and bun.
14
14
  npx inup
15
15
  ```
16
16
 
17
+ Scan deeper package layouts:
18
+
19
+ ```bash
20
+ npx inup --max-depth 15
21
+ ```
22
+
17
23
  Or install globally:
18
24
 
19
25
  ```bash
@@ -50,7 +56,10 @@ inup [options]
50
56
 
51
57
  -d, --dir <path> Run in specific directory
52
58
  -e, --exclude <patterns> Skip directories (comma-separated regex)
59
+ -i, --ignore <packages> Ignore packages (comma-separated, glob supported)
60
+ --max-depth <number> Maximum scan depth for package discovery (default: 10)
53
61
  --package-manager <name> Force package manager (npm, yarn, pnpm, bun)
62
+ --debug Write verbose debug logs
54
63
  ```
55
64
 
56
65
  ## 🔒 Privacy
package/dist/cli.js CHANGED
@@ -21,12 +21,11 @@ program
21
21
  .option('-d, --dir <directory>', 'specify directory to run in', process.cwd())
22
22
  .option('-e, --exclude <patterns>', 'exclude paths matching regex patterns (comma-separated)', '')
23
23
  .option('-i, --ignore <packages>', 'ignore packages (comma-separated, supports glob patterns like @babel/*)')
24
+ .option('--max-depth <number>', 'maximum directory depth for package.json discovery', '10')
24
25
  .option('--package-manager <name>', 'manually specify package manager (npm, yarn, pnpm, bun)')
25
26
  .option('--debug', 'write verbose debug log to /tmp/inup-debug-YYYY-MM-DD.log')
26
27
  .action(async (options) => {
27
28
  console.log(chalk_1.default.bold.blue(`🚀 `) + chalk_1.default.bold.red(`i`) + chalk_1.default.bold.yellow(`n`) + chalk_1.default.bold.blue(`u`) + chalk_1.default.bold.magenta(`p`) + `\n`);
28
- // Check for updates in the background (non-blocking)
29
- const updateCheckPromise = (0, services_1.checkForUpdateAsync)('inup', packageJson.version);
30
29
  const cwd = (0, path_1.resolve)(options.dir);
31
30
  if (options.debug || process.env.INUP_DEBUG === '1') {
32
31
  (0, utils_1.enableDebugLogging)();
@@ -49,6 +48,14 @@ program
49
48
  .filter(Boolean)
50
49
  : [];
51
50
  const ignorePackages = [...new Set([...cliIgnorePatterns, ...(projectConfig.ignore || [])])];
51
+ const maxDepth = Number.parseInt(options.maxDepth, 10);
52
+ if (!Number.isInteger(maxDepth) || maxDepth < 0) {
53
+ console.error(chalk_1.default.red(`Invalid max depth: ${options.maxDepth}`));
54
+ console.error(chalk_1.default.yellow('Expected a non-negative integer, for example: --max-depth 10'));
55
+ process.exit(1);
56
+ }
57
+ // Check for updates in the background (non-blocking)
58
+ const updateCheckPromise = (0, services_1.checkForUpdateAsync)('inup', packageJson.version);
52
59
  // Validate package manager if provided
53
60
  let packageManager;
54
61
  if (options.packageManager) {
@@ -63,6 +70,7 @@ program
63
70
  const upgrader = new index_1.UpgradeRunner({
64
71
  cwd,
65
72
  excludePatterns,
73
+ maxDepth,
66
74
  ignorePackages,
67
75
  packageManager,
68
76
  debug: options.debug || process.env.INUP_DEBUG === '1',
@@ -47,6 +47,7 @@ class PackageDetector {
47
47
  this.cwd = options?.cwd || process.cwd();
48
48
  this.excludePatterns = options?.excludePatterns || [];
49
49
  this.ignorePackages = options?.ignorePackages || [];
50
+ this.maxDepth = options?.maxDepth ?? 10;
50
51
  this.packageJsonPath = (0, utils_1.findPackageJson)(this.cwd);
51
52
  if (this.packageJsonPath) {
52
53
  this.packageJson = (0, utils_1.readPackageJson)(this.packageJsonPath);
@@ -65,7 +66,7 @@ class PackageDetector {
65
66
  // Always check all package.json files recursively with timeout protection
66
67
  this.showProgress('🔍 Scanning repository for package.json files...');
67
68
  const tScan = Date.now();
68
- const allPackageJsonFiles = this.findPackageJsonFilesWithTimeout(30000); // 30 second timeout
69
+ const allPackageJsonFiles = await this.findPackageJsonFilesWithTimeout(30000); // 30 second timeout
69
70
  utils_3.debugLog.perf('PackageDetector', `file scan (${allPackageJsonFiles.length} files)`, tScan, {
70
71
  files: allPackageJsonFiles,
71
72
  });
@@ -199,15 +200,29 @@ class PackageDetector {
199
200
  throw error;
200
201
  }
201
202
  }
202
- findPackageJsonFilesWithTimeout(timeoutMs) {
203
- // Synchronous file search with depth limiting and symlink protection
204
- // The timeout parameter is kept for future async implementation
203
+ async findPackageJsonFilesWithTimeout(timeoutMs) {
205
204
  try {
206
- return (0, utils_1.findAllPackageJsonFiles)(this.cwd, this.excludePatterns, 10, (currentDir, foundCount) => {
207
- // Show scanning progress with current directory and count
208
- const truncatedDir = currentDir.length > 50 ? '...' + currentDir.slice(-47) : currentDir;
209
- this.showProgress(`🔍 Scanning ${truncatedDir} (found ${foundCount})`);
210
- });
205
+ let timeoutId;
206
+ try {
207
+ return await Promise.race([
208
+ (0, utils_1.findAllPackageJsonFilesAsync)(this.cwd, this.excludePatterns, this.maxDepth, (currentDir, foundCount) => {
209
+ // Show scanning progress with current directory and count
210
+ const truncatedDir = currentDir.length > 50 ? '...' + currentDir.slice(-47) : currentDir;
211
+ this.showProgress(`🔍 Scanning ${truncatedDir} (found ${foundCount})`);
212
+ }),
213
+ new Promise((_, reject) => {
214
+ timeoutId = setTimeout(() => {
215
+ reject(new Error(`Scan timed out after ${timeoutMs}ms`));
216
+ }, timeoutMs);
217
+ timeoutId.unref?.();
218
+ }),
219
+ ]);
220
+ }
221
+ finally {
222
+ if (timeoutId) {
223
+ clearTimeout(timeoutId);
224
+ }
225
+ }
211
226
  }
212
227
  catch (err) {
213
228
  throw new Error(`Failed to scan for package.json files: ${err}. Try using --exclude patterns to skip problematic directories.`);
@@ -7,6 +7,7 @@ exports.readPackageJsonAsync = readPackageJsonAsync;
7
7
  exports.collectAllDependencies = collectAllDependencies;
8
8
  exports.collectAllDependenciesAsync = collectAllDependenciesAsync;
9
9
  exports.findAllPackageJsonFiles = findAllPackageJsonFiles;
10
+ exports.findAllPackageJsonFilesAsync = findAllPackageJsonFilesAsync;
10
11
  const fs_1 = require("fs");
11
12
  const fs_2 = require("fs");
12
13
  const path_1 = require("path");
@@ -55,6 +56,20 @@ async function readPackageJsonAsync(path) {
55
56
  throw new Error(`Failed to read package.json: ${error}`);
56
57
  }
57
58
  }
59
+ const SKIP_DIRS = new Set([
60
+ 'node_modules',
61
+ 'dist',
62
+ 'build',
63
+ 'coverage',
64
+ 'out',
65
+ 'lib',
66
+ 'es',
67
+ 'esm',
68
+ 'cjs',
69
+ ]);
70
+ function shouldSkipDirectory(name) {
71
+ return name.startsWith('.') || SKIP_DIRS.has(name);
72
+ }
58
73
  /**
59
74
  * Collects all dependencies from multiple package.json files.
60
75
  * Always includes regular dependencies and devDependencies.
@@ -135,11 +150,24 @@ function findAllPackageJsonFiles(rootDir = process.cwd(), excludePatterns = [],
135
150
  const packageJsonFiles = [];
136
151
  const visitedPaths = new Set();
137
152
  let directoriesScanned = 0;
153
+ let lastProgressAt = 0;
154
+ const progressIntervalMs = 250;
138
155
  // Compile regex patterns for exclude filtering
139
156
  const excludeRegexes = excludePatterns.map((pattern) => new RegExp(pattern, 'i'));
140
157
  function shouldExcludePath(relativePath) {
141
158
  return excludeRegexes.some((regex) => regex.test(relativePath));
142
159
  }
160
+ function reportProgress(currentDir, force = false) {
161
+ if (!onProgress)
162
+ return;
163
+ const now = Date.now();
164
+ if (!force && now - lastProgressAt < progressIntervalMs) {
165
+ return;
166
+ }
167
+ lastProgressAt = now;
168
+ const relativePath = (0, path_1.relative)(rootDir, currentDir) || '.';
169
+ onProgress(relativePath, packageJsonFiles.length);
170
+ }
143
171
  function traverseDirectory(dir, depth = 0) {
144
172
  // Prevent infinite recursion with depth limit
145
173
  if (depth > maxDepth) {
@@ -155,11 +183,11 @@ function findAllPackageJsonFiles(rootDir = process.cwd(), excludePatterns = [],
155
183
  directoriesScanned++;
156
184
  // Report progress every 10 directories or on first scan
157
185
  if (onProgress && (directoriesScanned % 10 === 0 || directoriesScanned === 1)) {
158
- const relativePath = (0, path_1.relative)(rootDir, dir) || '.';
159
- onProgress(relativePath, packageJsonFiles.length);
186
+ reportProgress(dir, true);
160
187
  }
161
188
  const files = (0, fs_1.readdirSync)(dir);
162
189
  for (const file of files) {
190
+ reportProgress(dir);
163
191
  const fullPath = (0, path_1.join)(dir, file);
164
192
  const relativePath = (0, path_1.relative)(rootDir, fullPath);
165
193
  // Skip if path matches exclude patterns
@@ -174,26 +202,7 @@ function findAllPackageJsonFiles(rootDir = process.cwd(), excludePatterns = [],
174
202
  // Skip files/dirs we can't stat (broken symlinks, permission issues)
175
203
  continue;
176
204
  }
177
- // Skip common build and dependency directories
178
- const skipDirs = [
179
- 'node_modules',
180
- '.git',
181
- 'dist',
182
- 'build',
183
- '.next',
184
- 'coverage',
185
- '.cache',
186
- 'out',
187
- '.output',
188
- '.nuxt',
189
- '.vercel',
190
- '.netlify',
191
- 'lib',
192
- 'es',
193
- 'esm',
194
- 'cjs',
195
- ];
196
- if (stat.isDirectory() && !file.startsWith('.') && !skipDirs.includes(file)) {
205
+ if (stat.isDirectory() && !shouldSkipDirectory(file)) {
197
206
  traverseDirectory(fullPath, depth + 1);
198
207
  }
199
208
  else if (file === 'package.json' && stat.isFile()) {
@@ -208,4 +217,122 @@ function findAllPackageJsonFiles(rootDir = process.cwd(), excludePatterns = [],
208
217
  traverseDirectory(rootDir);
209
218
  return packageJsonFiles;
210
219
  }
220
+ /**
221
+ * Find all package.json files recursively with bounded parallel directory traversal.
222
+ */
223
+ async function findAllPackageJsonFilesAsync(rootDir = process.cwd(), excludePatterns = [], maxDepth = 10, onProgress, options = {}) {
224
+ const packageJsonFiles = [];
225
+ const visitedPaths = new Set();
226
+ let directoriesScanned = 0;
227
+ let lastProgressAt = 0;
228
+ const progressIntervalMs = 250;
229
+ const concurrency = Math.max(1, Math.min(options.concurrency ?? 16, 64));
230
+ const excludeRegexes = excludePatterns.map((pattern) => new RegExp(pattern, 'i'));
231
+ function shouldExcludePath(relativePath) {
232
+ return excludeRegexes.some((regex) => regex.test(relativePath));
233
+ }
234
+ function reportProgress(currentDir, force = false) {
235
+ if (!onProgress)
236
+ return;
237
+ const now = Date.now();
238
+ if (!force && now - lastProgressAt < progressIntervalMs) {
239
+ return;
240
+ }
241
+ lastProgressAt = now;
242
+ const relativePath = (0, path_1.relative)(rootDir, currentDir) || '.';
243
+ onProgress(relativePath, packageJsonFiles.length);
244
+ }
245
+ const pending = [];
246
+ let activeTasks = 0;
247
+ let failedError = null;
248
+ let resolveDone = null;
249
+ let rejectDone = null;
250
+ const done = new Promise((resolve, reject) => {
251
+ resolveDone = resolve;
252
+ rejectDone = reject;
253
+ });
254
+ function finishIfIdle() {
255
+ if (pending.length === 0 && activeTasks === 0) {
256
+ resolveDone?.();
257
+ }
258
+ }
259
+ function schedule(dir, depth) {
260
+ pending.push({ dir, depth });
261
+ pump();
262
+ }
263
+ async function processDirectory(dir, depth) {
264
+ if (depth > maxDepth) {
265
+ return;
266
+ }
267
+ let realPath;
268
+ try {
269
+ realPath = await fs_2.promises.realpath(dir);
270
+ }
271
+ catch {
272
+ return;
273
+ }
274
+ if (visitedPaths.has(realPath)) {
275
+ return;
276
+ }
277
+ visitedPaths.add(realPath);
278
+ directoriesScanned++;
279
+ if (directoriesScanned % 10 === 0 || directoriesScanned === 1) {
280
+ reportProgress(dir, true);
281
+ }
282
+ let files;
283
+ try {
284
+ files = await fs_2.promises.readdir(dir);
285
+ }
286
+ catch {
287
+ return;
288
+ }
289
+ for (const file of files) {
290
+ reportProgress(dir);
291
+ const fullPath = (0, path_1.join)(dir, file);
292
+ const relativePath = (0, path_1.relative)(rootDir, fullPath);
293
+ if (shouldExcludePath(relativePath)) {
294
+ continue;
295
+ }
296
+ let stat;
297
+ try {
298
+ stat = await fs_2.promises.stat(fullPath);
299
+ }
300
+ catch {
301
+ continue;
302
+ }
303
+ if (stat.isDirectory() && !shouldSkipDirectory(file)) {
304
+ schedule(fullPath, depth + 1);
305
+ }
306
+ else if (file === 'package.json' && stat.isFile()) {
307
+ packageJsonFiles.push(fullPath);
308
+ }
309
+ }
310
+ }
311
+ function pump() {
312
+ while (activeTasks < concurrency && pending.length > 0 && !failedError) {
313
+ const next = pending.shift();
314
+ if (!next)
315
+ break;
316
+ activeTasks++;
317
+ void processDirectory(next.dir, next.depth)
318
+ .catch((error) => {
319
+ if (!failedError) {
320
+ failedError = error;
321
+ rejectDone?.(error);
322
+ }
323
+ })
324
+ .finally(() => {
325
+ activeTasks--;
326
+ if (failedError) {
327
+ return;
328
+ }
329
+ pump();
330
+ finishIfIdle();
331
+ });
332
+ }
333
+ }
334
+ schedule(rootDir, 0);
335
+ await done;
336
+ return packageJsonFiles;
337
+ }
211
338
  //# sourceMappingURL=filesystem.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inup",
3
- "version": "1.4.9",
3
+ "version": "1.4.10",
4
4
  "description": "Interactive CLI tool for upgrading dependencies with ease. Auto-detects and works with npm, yarn, pnpm, and bun. Inspired by yarn upgrade-interactive. Supports monorepos, workspaces, and batch upgrades.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -38,12 +38,12 @@
38
38
  "devDependencies": {
39
39
  "@types/inquirer": "^9.0.9",
40
40
  "@types/keypress.js": "^2.1.3",
41
- "@types/node": "^24.10.1",
41
+ "@types/node": "^24.12.0",
42
42
  "@types/semver": "^7.7.1",
43
- "@vitest/coverage-v8": "^3.2.4",
43
+ "@vitest/coverage-v8": "^4.1.0",
44
44
  "prettier": "^3.8.1",
45
45
  "typescript": "^5.9.3",
46
- "vitest": "^3.2.4"
46
+ "vitest": "^4.1.0"
47
47
  },
48
48
  "dependencies": {
49
49
  "chalk": "^5.6.2",