Skip to content

Commit

Permalink
fix: Ensure to check coherency for non semver dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jul 10, 2020
1 parent faccc70 commit 2d0cd55
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions lib/private/setup-dependency/install-external/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ const mapBinaries = async ({ name, path, dependentContext }) => {
);
};

const isCoherent = async ({ path, dependentContext, name }, dependencyPackageJson) => {
const binDict = resolveBinariesDict(path);
return (
await Promise.all([
...Object.keys(dependencyPackageJson.dependencies || {}).map(packageName =>
isDirectory(resolve(path, "node_modules", packageName))
),
...Object.entries(binDict || {}).map(async ([targetName, linkedPath]) => {
const targetPath = resolve(dependentContext.path, "node_modules/.bin", targetName);
return binaryHandler.has(join("../", name, linkedPath), targetPath);
})
])
).every(Boolean);
};

module.exports = async dependencyContext => {
const {
name,
Expand All @@ -40,38 +55,28 @@ module.exports = async dependencyContext => {
if (optionalChaining(packageJson, "version") === latestSupportedPublishedVersion) {
// Seems up to date, but let's follow with quick sanity check and confirm whether
// there are corresponding folders for subdependencies
const binDict = resolveBinariesDict(path);
if (
(
await Promise.all([
...Object.keys(packageJson.dependencies || {}).map(packageName =>
isDirectory(resolve(path, "node_modules", packageName))
),
...Object.entries(binDict || {}).map(async ([targetName, linkedPath]) => {
const targetPath = resolve(
dependentContext.path, "node_modules/.bin", targetName
);
return binaryHandler.has(join("../", name, linkedPath), targetPath);
})
])
).every(Boolean)
) {
return;
}
if (await isCoherent(dependencyContext, packageJson)) return;
log.notice("%s not coherent %s, reinstalling", dependentContext.name, name);
}
}
const targetVersion = latestSupportedPublishedVersion || versionRange;
const sourceDirname = await muteErrorIfOptional(dependencyContext, () =>
prepareDependency(name, targetVersion, externalContext)
);
if (!sourceDirname) return;
if (isInstalled && packageJson && packageJson._npmCrossLinkCacheName) {
if (
!latestSupportedPublishedVersion &&
isInstalled &&
packageJson &&
packageJson._npmCrossLinkCacheName
) {
const cachePackageJson = getPackageJson(sourceDirname);
if (
cachePackageJson &&
packageJson._npmCrossLinkCacheName === cachePackageJson._npmCrossLinkCacheName
) {
return;
if (await isCoherent(dependencyContext, packageJson)) return;
log.notice("%s not coherent %s, reinstalling", dependentContext.name, name);
}
}
await rm(path, { loose: true, recursive: true, force: true });
Expand Down

0 comments on commit 2d0cd55

Please sign in to comment.