|
1 | 1 | /** |
2 | | - * @fileoverview Update script for the SDK. |
3 | | - * Updates dependencies and regenerates lockfile. |
| 2 | + * @fileoverview Monorepo-aware dependency update script - checks and updates dependencies. |
| 3 | + * Uses taze to check for updates across all packages in the monorepo. |
4 | 4 | * |
5 | 5 | * Usage: |
6 | | - * node scripts/update.mjs |
| 6 | + * node scripts/update.mjs [options] |
| 7 | + * |
| 8 | + * Options: |
| 9 | + * --quiet Suppress progress output |
| 10 | + * --verbose Show detailed output |
| 11 | + * --apply Apply updates (default is check-only) |
7 | 12 | */ |
8 | 13 |
|
9 | | -import { getDefaultLogger } from '@socketsecurity/lib/logger' |
10 | | -import { printFooter, printHeader } from '@socketsecurity/lib/stdio/header' |
11 | | - |
12 | | -import { runCommand, runCommandQuiet } from './utils/run-command.mjs' |
| 14 | +import { isQuiet, isVerbose } from '@socketsecurity/lib/argv/flags' |
| 15 | +import loggerPkg from '@socketsecurity/lib/logger' |
| 16 | +import platformPkg from '@socketsecurity/lib/constants/platform' |
| 17 | +import spawnPkg from '@socketsecurity/lib/spawn' |
13 | 18 |
|
14 | | -// Initialize logger |
15 | | -const logger = getDefaultLogger() |
| 19 | +const { getDefaultLogger } = loggerPkg |
| 20 | +const { WIN32 } = platformPkg |
| 21 | +const { spawn } = spawnPkg |
16 | 22 |
|
17 | 23 | async function main() { |
| 24 | + const quiet = isQuiet() |
| 25 | + const verbose = isVerbose() |
| 26 | + const apply = process.argv.includes('--apply') |
| 27 | + const logger = getDefaultLogger() |
| 28 | + |
18 | 29 | try { |
19 | | - printHeader('Updating Dependencies') |
| 30 | + if (!quiet) { |
| 31 | + logger.log('\n🔨 Monorepo Dependency Update\n') |
| 32 | + } |
20 | 33 |
|
21 | | - // Update lockfile. |
22 | | - logger.progress('Updating pnpm-lock.yaml...') |
23 | | - const lockResult = await runCommandQuiet('pnpm', ['install'], { |
24 | | - cwd: process.cwd(), |
25 | | - }) |
| 34 | + // Build taze command with appropriate flags for monorepo. |
| 35 | + const tazeArgs = ['exec', 'taze', '-r'] |
26 | 36 |
|
27 | | - if (lockResult.exitCode !== 0) { |
28 | | - logger.clearLine().error('Failed to update lockfile') |
29 | | - if (lockResult.stderr) { |
30 | | - console.error(lockResult.stderr) |
| 37 | + if (apply) { |
| 38 | + tazeArgs.push('-w') |
| 39 | + if (!quiet) { |
| 40 | + logger.progress('Updating dependencies across monorepo...') |
| 41 | + } |
| 42 | + } else { |
| 43 | + if (!quiet) { |
| 44 | + logger.progress('Checking for updates across monorepo...') |
31 | 45 | } |
32 | | - process.exitCode = 1 |
33 | | - return |
34 | 46 | } |
35 | | - logger.clearLine().done('Updated pnpm-lock.yaml') |
36 | 47 |
|
37 | | - // Update Socket packages. |
38 | | - logger.progress('Updating Socket packages...') |
39 | | - const socketResult = await runCommand( |
40 | | - 'pnpm', |
41 | | - [ |
42 | | - 'update', |
43 | | - '@socketsecurity/*', |
44 | | - '@socketregistry/*', |
45 | | - '--latest', |
46 | | - '--no-workspace', |
47 | | - ], |
48 | | - { |
49 | | - cwd: process.cwd(), |
50 | | - stdio: 'pipe', |
51 | | - }, |
52 | | - ) |
| 48 | + // Run taze at root level (recursive flag will check all packages). |
| 49 | + const result = await spawn('pnpm', tazeArgs, { |
| 50 | + shell: WIN32, |
| 51 | + stdio: quiet ? 'pipe' : 'inherit', |
| 52 | + }) |
53 | 53 |
|
54 | | - if (socketResult !== 0) { |
55 | | - logger.clearLine().error('Failed to update Socket packages') |
56 | | - process.exitCode = 1 |
57 | | - return |
| 54 | + // Clear progress line. |
| 55 | + if (!quiet) { |
| 56 | + process.stdout.write('\r\x1b[K') |
58 | 57 | } |
59 | | - logger.clearLine().done('Updated Socket packages') |
60 | 58 |
|
61 | | - // Update dependencies. |
62 | | - logger.progress('Checking for outdated dependencies...') |
63 | | - const outdatedResult = await runCommandQuiet('pnpm', ['outdated'], { |
64 | | - cwd: process.cwd(), |
65 | | - }) |
| 59 | + // If applying updates, also update Socket packages. |
| 60 | + if (apply && result.code === 0) { |
| 61 | + if (!quiet) { |
| 62 | + logger.progress('Updating Socket packages...') |
| 63 | + } |
66 | 64 |
|
67 | | - if (outdatedResult.stdout?.trim()) { |
68 | | - logger.clearLine() |
69 | | - console.log('\nOutdated dependencies:') |
70 | | - console.log(outdatedResult.stdout) |
71 | | - console.log('\nRun "pnpm run taze" to update them.') |
72 | | - } else { |
73 | | - logger.clearLine().done('All dependencies are up to date') |
| 65 | + const socketResult = await spawn( |
| 66 | + 'pnpm', |
| 67 | + [ |
| 68 | + 'update', |
| 69 | + '@socketsecurity/*', |
| 70 | + '@socketregistry/*', |
| 71 | + '--latest', |
| 72 | + '-r', |
| 73 | + ], |
| 74 | + { |
| 75 | + shell: WIN32, |
| 76 | + stdio: quiet ? 'pipe' : 'inherit', |
| 77 | + }, |
| 78 | + ) |
| 79 | + |
| 80 | + // Clear progress line. |
| 81 | + if (!quiet) { |
| 82 | + process.stdout.write('\r\x1b[K') |
| 83 | + } |
| 84 | + |
| 85 | + if (socketResult.code !== 0) { |
| 86 | + if (!quiet) { |
| 87 | + logger.fail('Failed to update Socket packages') |
| 88 | + } |
| 89 | + process.exitCode = 1 |
| 90 | + return |
| 91 | + } |
74 | 92 | } |
75 | 93 |
|
76 | | - logger.log('') |
77 | | - logger.success('Update complete') |
78 | | - printFooter() |
| 94 | + if (result.code !== 0) { |
| 95 | + if (!quiet) { |
| 96 | + if (apply) { |
| 97 | + logger.fail('Failed to update dependencies') |
| 98 | + } else { |
| 99 | + logger.info('Updates available. Run with --apply to update') |
| 100 | + } |
| 101 | + } |
| 102 | + process.exitCode = apply ? 1 : 0 |
| 103 | + } else { |
| 104 | + if (!quiet) { |
| 105 | + if (apply) { |
| 106 | + logger.success('Dependencies updated across all packages') |
| 107 | + } else { |
| 108 | + logger.success('All packages up to date') |
| 109 | + } |
| 110 | + logger.log('') |
| 111 | + } |
| 112 | + } |
79 | 113 | } catch (error) { |
80 | | - logger.log('') |
81 | | - logger.error(`Update failed: ${error.message}`) |
| 114 | + if (!quiet) { |
| 115 | + logger.fail(`Update failed: ${error.message}`) |
| 116 | + } |
| 117 | + if (verbose) { |
| 118 | + logger.error(error) |
| 119 | + } |
82 | 120 | process.exitCode = 1 |
83 | 121 | } |
84 | 122 | } |
85 | 123 |
|
86 | 124 | main().catch(e => { |
| 125 | + const logger = getDefaultLogger() |
87 | 126 | logger.error(e) |
88 | 127 | process.exitCode = 1 |
89 | 128 | }) |
0 commit comments