-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathupdate.mjs
More file actions
106 lines (93 loc) · 2.37 KB
/
update.mjs
File metadata and controls
106 lines (93 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* @fileoverview Monorepo-aware dependency update script.
* Uses taze to update dependencies across all packages in the monorepo.
*
* Usage:
* node scripts/update.mjs [options]
*
* Options:
* --quiet Suppress progress output
* --verbose Show detailed output
*/
import { isQuiet, isVerbose } from '@socketsecurity/lib/argv/flags'
import { WIN32 } from '@socketsecurity/lib/constants/platform'
import { getDefaultLogger } from '@socketsecurity/lib/logger'
import { spawn } from '@socketsecurity/lib/spawn'
async function main() {
const quiet = isQuiet()
const verbose = isVerbose()
const logger = getDefaultLogger()
try {
if (!quiet) {
logger.log('\n🔨 Dependency Update\n')
}
// Build taze command with appropriate flags for monorepo
const tazeArgs = ['exec', 'taze', '-r', '-w']
if (!quiet) {
logger.progress('Updating dependencies...')
}
// Run taze at root level (recursive flag will check all packages).
const result = await spawn('pnpm', tazeArgs, {
shell: WIN32,
stdio: quiet ? 'pipe' : 'inherit',
})
// Clear progress line.
if (!quiet) {
process.stdout.write('\r\x1b[K')
}
// Always update Socket packages (bypass taze maturity period).
if (!quiet) {
logger.progress('Updating Socket packages...')
}
const socketResult = await spawn(
'pnpm',
[
'update',
'@socketsecurity/*',
'@socketregistry/*',
'@socketbin/*',
'--latest',
'-r',
],
{
shell: WIN32,
stdio: quiet ? 'pipe' : 'inherit',
},
)
// Clear progress line.
if (!quiet) {
process.stdout.write('\r\x1b[K')
}
if (socketResult.code !== 0) {
if (!quiet) {
logger.fail('Failed to update Socket packages')
}
process.exitCode = 1
return
}
if (result.code !== 0) {
if (!quiet) {
logger.fail('Failed to update dependencies')
}
process.exitCode = 1
} else {
if (!quiet) {
logger.success('Dependencies updated')
logger.log('')
}
}
} catch (error) {
if (!quiet) {
logger.fail(`Update failed: ${error.message}`)
}
if (verbose) {
logger.error(error)
}
process.exitCode = 1
}
}
main().catch(e => {
const logger = getDefaultLogger()
logger.error(e)
process.exitCode = 1
})