Skip to content

Commit c9961ab

Browse files
authored
Merge pull request #593 from primer/fix-dotcom-install
Fix dotcom installs, better script/check-versions reporting
2 parents 375c4df + 818efd1 commit c9961ab

File tree

2 files changed

+50
-41
lines changed

2 files changed

+50
-41
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
save=true
22
save-exact=true
3+
no-package-lock=true

script/check-versions

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env node
2-
const globby = require('globby')
3-
const lernaConfig = require('../lerna.json')
2+
const getPackages = require('./get-packages')
43

54
const DEP_FIELDS = [
65
'dependencies',
@@ -9,54 +8,63 @@ const DEP_FIELDS = [
98
'optionalDependencies',
109
]
1110

12-
globby(lernaConfig.packages)
11+
getPackages()
1312
.then(paths => {
1413
return paths.reduce((packages, path) => {
15-
try {
16-
const pkg = require(`../${path}/package.json`)
17-
pkg.path = path
18-
packages.push(pkg)
19-
} catch (error) {
20-
}
14+
const pkg = require(`../${path}/package.json`)
15+
packages[pkg.name] = pkg
2116
return packages
22-
}, [])
17+
}, {})
2318
})
2419
.then(packages => {
25-
console.log('⏱ checking %d packages...', packages.length)
26-
const map = new Map()
20+
console.log('checking %d packages...', Object.keys(packages).length)
2721
const matches = []
28-
packages.forEach(pkg => map.set(pkg.name, pkg))
29-
packages.forEach(pkg => {
30-
DEP_FIELDS
31-
.filter(field => field in pkg)
32-
.forEach(field => {
33-
const deps = pkg[field]
34-
Object.keys(deps)
35-
.filter(dep => map.has(dep))
36-
.forEach(dep => {
37-
const expected = map.get(dep).version
38-
const actual = deps[dep]
39-
if (expected !== actual) {
40-
throw new Error(
41-
`${pkg.name}.${field} has bad version for ${dep}: ${expected} != ${actual}`
42-
)
43-
} else {
44-
matches.push({
45-
from: pkg.name,
46-
to: dep,
47-
field,
48-
version: expected
49-
})
50-
}
22+
for (const [name, pkg] of Object.entries(packages)) {
23+
for (const field of DEP_FIELDS) {
24+
const deps = pkg[field]
25+
if (deps instanceof Object) {
26+
const keys = Object.keys(deps).filter(dep => dep in packages)
27+
for (const dep of keys) {
28+
const version = deps[dep]
29+
let match = false
30+
const expected = packages[dep].version
31+
if (version.indexOf('file:') === 0) {
32+
console.warn(`${name}.${field}.${dep} uses file specifier: "${version}"`)
33+
match = true
34+
} else {
35+
match = expected === version
36+
}
37+
matches.push({
38+
from: name,
39+
to: dep,
40+
field,
41+
version,
42+
expected,
43+
match
5144
})
52-
})
53-
})
45+
}
46+
}
47+
}
48+
}
5449
return matches
5550
})
51+
.then(matches => {
52+
let fail = 0
53+
for (const item of matches) {
54+
if (!item.match) {
55+
const {from, to, field, expected, version} = item
56+
console.warn(`X ${from}.${field}.${to} is "${version}", but should be "${expected}"`)
57+
fail++
58+
}
59+
}
60+
if (fail > 0) {
61+
console.error('failed %d of %d cross-dependencies', failed, matches.length)
62+
process.exitCode = 1
63+
} else {
64+
console.warn('all %d cross-dependencies checked out!', matches.length)
65+
}
66+
})
5667
.catch(error => {
5768
console.error(error.message)
58-
process.exit(1)
59-
})
60-
.then(matches => {
61-
console.warn('✅ checked %d matching version dependencies', matches.length)
69+
process.exitCode = 1
6270
})

0 commit comments

Comments
 (0)