-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
269 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// @flow | ||
const {getManifest} = require('../utils/get-manifest.js'); | ||
const {getAllDependencies} = require('../utils/get-all-dependencies.js'); | ||
const {read, write} = require('../utils/node-helpers.js'); | ||
const {install} = require('./install.js'); | ||
|
||
/*:: | ||
type AlignArgs = { | ||
root: string, | ||
cwd: string, | ||
} | ||
type Align = (AlignArgs) => Promise<void> | ||
*/ | ||
const align /*: Align */ = async ({root, cwd}) => { | ||
const {projects, versionPolicy} = /*:: await */ await getManifest({root}); | ||
if (versionPolicy) { | ||
const deps = await getAllDependencies({root, projects}); | ||
const meta = JSON.parse(await read(`${cwd}/package.json`, 'utf8')); | ||
const others = deps.filter(dep => dep.meta.name !== meta.name); | ||
const types = ['dependencies', 'devDependencies', 'resolutions']; | ||
let changed = false; | ||
for (const type of types) { | ||
if (meta[type]) { | ||
for (const name in meta[type]) { | ||
if (shouldSyncVersions({versionPolicy, name})) { | ||
const version = getVersion({name, deps: others}); | ||
if (version !== null) { | ||
meta[type][name] = version; | ||
changed = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (changed) { | ||
const modified = JSON.stringify(meta, null, 2) + '\n'; | ||
await write(`${cwd}/package.json`, modified, 'utf8'); | ||
} | ||
} | ||
await install({root, cwd}); | ||
}; | ||
|
||
const shouldSyncVersions = ({versionPolicy, name}) => { | ||
const {lockstep = false, exceptions = []} = versionPolicy; | ||
return ( | ||
(lockstep && !exceptions.includes(name)) || | ||
(!lockstep && exceptions.includes(name)) | ||
); | ||
}; | ||
|
||
const getVersion = ({name, deps}) => { | ||
const types = ['dependencies', 'devDependencies', 'resolutions']; | ||
for (const {meta} of deps) { | ||
for (const type of types) { | ||
for (const key in meta[type]) { | ||
if (name === key) return meta[type][key]; | ||
} | ||
} | ||
} | ||
return null; | ||
}; | ||
|
||
module.exports = {align}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// @flow | ||
const {getManifest} = require('../utils/get-manifest.js'); | ||
const {getAllDependencies} = require('../utils/get-all-dependencies.js'); | ||
const {exec} = require('../utils/node-helpers.js'); | ||
const {node, yarn} = require('../utils/binary-paths.js'); | ||
const {minVersion, gt} = require('semver'); | ||
|
||
/*:: | ||
type OutdatedArgs = { | ||
root: string, | ||
}; | ||
type Outdated = (OutdatedArgs) => Promise<void> | ||
*/ | ||
const outdated /*: Outdated */ = async ({root}) => { | ||
const {projects} = await getManifest({root}); | ||
const locals = await getAllDependencies({root, projects}); | ||
const map = {}; | ||
const types = ['dependencies', 'devDependencies']; | ||
for (const local of locals) { | ||
for (const type of types) { | ||
if (local.meta[type]) { | ||
for (const name in local.meta[type]) { | ||
if (!map[name]) map[name] = new Set(); | ||
map[name].add(local.meta[type][name]); | ||
} | ||
} | ||
} | ||
} | ||
// report local discrepancies | ||
for (const name in map) { | ||
const local = locals.find(local => local.meta.name === name); | ||
if (local) { | ||
const {version} = local.meta; | ||
for (const range of map[name]) { | ||
if (version !== range) console.log(name, range, version); | ||
} | ||
} | ||
} | ||
// then report registry discrepancies | ||
for (const name in map) { | ||
const local = locals.find(local => local.meta.name === name); | ||
if (!local) { | ||
const query = `${node} ${yarn} info ${name} version --json 2>/dev/null`; | ||
const registryVersion = await exec(query); | ||
if (registryVersion) { | ||
const latest = JSON.parse(registryVersion).data; | ||
for (const range of map[name]) { | ||
if (gt(latest, minVersion(range))) console.log(name, range, latest); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
module.exports = {outdated}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.