forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetPackagesVersionsForTag.mjs
78 lines (65 loc) · 1.9 KB
/
getPackagesVersionsForTag.mjs
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
/* eslint-env node */
import { execSync } from 'node:child_process'
import { basename } from 'node:path'
const TAGS = ['latest', 'rc', 'next', 'canary', 'experimental']
async function main() {
const [_nodeBinPath, scriptPath, tag = 'latest'] = process.argv
const targetVersion = process.argv[3]
if (['help', '-h', '--help'].includes(tag)) {
console.log(
[
'',
`yarn node tasks/${basename(scriptPath)} [tag] [expectedVersion]`,
'',
`Valid tags: ${TAGS.join(', ')}`,
'If no tag is provided, defaults to latest',
'',
`'expectedVersion' [not required, string]`,
'If provided, will ONLY display packages where current version != expectedVersion',
'',
'',
].join('\n')
)
return
}
if (!TAGS.includes(tag)) {
console.log(`Invalid tag. Must be one of: ${TAGS.join(', ')}`)
process.exitCode = 1
return
}
const workspaceListJson =
'[' +
execSync('yarn workspaces list --json', {
encoding: 'utf-8',
})
.trim()
.split('\n')
.join(',') +
']'
const workspacePackages = JSON.parse(workspaceListJson)
.map((workspace) => workspace.name)
// Get rid of the root workspace, which has no name.
.filter(Boolean)
const namesToVersions = {}
for (const packageName of workspacePackages) {
try {
const { version } = JSON.parse(
execSync(
`yarn npm info ${packageName}@${tag} --fields version --json`,
{
encoding: 'utf-8',
}
)
)
namesToVersions[packageName] = version
if (!targetVersion || version !== targetVersion) {
console.log(`Latest @${tag} version for ${packageName}: ${version}`)
} else {
console.log('found matching version...')
}
} catch (error) {
console.error(`Error fetching information for ${packageName}:`, error)
}
}
}
main()