Skip to content

Commit 7a4cc9d

Browse files
author
Sebastian McKenzie
committed
make strict kpm check check that installed modules match the satisfied versions - fixes #115
1 parent 01d7fd7 commit 7a4cc9d

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/cli/commands/check.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import * as constants from "../../constants.js";
1818
import * as fs from "../../util/fs.js";
1919
import * as util from "../../util/misc.js";
2020

21-
let path = require("path");
21+
let semver = require("semver");
22+
let path = require("path");
2223

2324
export let noArguments = true;
2425

@@ -80,10 +81,37 @@ export async function run(
8081
// check if any of the node_modules are out of sync
8182
let res = await install.linker.initCopyModules(rawPatterns);
8283
for (let [loc] of res) {
84+
let human = path.relative(path.join(process.cwd(), "node_modules"), loc);
85+
human = human.replace(/node_modules/g, " > ");
86+
8387
if (!(await fs.exists(loc))) {
84-
reporter.error(`Module not installed: ${path.relative(process.cwd(), loc)}`);
88+
reporter.error(`Module not installed: ${human}`);
8589
valid = false;
8690
}
91+
92+
let pkg = await fs.readJson(path.join(loc, "package.json"));
93+
94+
let deps = Object.assign({}, pkg.dependencies, pkg.devDependencies, pkg.peerDependencies);
95+
96+
for (let name in deps) {
97+
let range = deps[name];
98+
if (!semver.validRange(range)) continue; // exotic
99+
100+
let depPkgLoc = path.join(loc, "node_modules", name, "package.json");
101+
if (!(await fs.exists(depPkgLoc))) {
102+
// we'll hit the module not install error above when this module is hit
103+
continue;
104+
}
105+
106+
let depPkg = await fs.readJson(depPkgLoc);
107+
if (semver.satisfies(depPkg.version, range)) continue;
108+
109+
// module isn't correct semver
110+
reporter.error(
111+
`Module ${human} depends on ${name} with the range ${range} but it doesn't match the ` +
112+
`installed version of ${depPkg.version}`
113+
);
114+
}
87115
}
88116
}
89117

0 commit comments

Comments
 (0)