Skip to content

Commit

Permalink
fix: Fix setup of binaries with linked approach
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Apr 14, 2024
1 parent 0321878 commit 6bc1da6
Showing 1 changed file with 45 additions and 43 deletions.
88 changes: 45 additions & 43 deletions lib/setup-dependency/install-external/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,56 +48,58 @@ module.exports = async (dependencyContext, userConfiguration, progressData) => {

if (isToBeLinked) {
const linkedPath = relative(dirname(path), sourceDirname);
if (await isSymlink(path, { linkPath: linkedPath })) return;
const isInstalled = await lstat(path, { loose: true });
if (isInstalled) await rm(path, { loose: true, recursive: true, force: true });
log.notice("%s linking %s @ %s", dependentContext.name, name, targetVersion);
await symlink(linkedPath, path, { intermediate: true });
dependentContext.installationJobs.add(
`${ isInstalled ? "update" : "install" }-dependency:${ name }`
);

return;
}

const isInstalled = await isDirectory(path);
const dependencyPackageJson = isInstalled ? getPackageJson(path) : null;
if (latestSupportedPublishedVersion && isInstalled) {
if (
optionalChaining(dependencyPackageJson, "version") === latestSupportedPublishedVersion
) {
// Seems up to date, but let's follow with quick sanity check and confirm whether
// there are corresponding folders for subdependencies
if (await isCoherent(dependencyContext, dependencyPackageJson)) return;
log.notice("%s not coherent %s, reinstalling", dependentContext.name, name);
if (!(await isSymlink(path, { linkPath: linkedPath }))) {
const isInstalled = await lstat(path, { loose: true });
if (isInstalled) await rm(path, { loose: true, recursive: true, force: true });
log.notice("%s linking %s @ %s", dependentContext.name, name, targetVersion);
await symlink(linkedPath, path, { intermediate: true });
dependentContext.installationJobs.add(
`${ isInstalled ? "update" : "install" }-dependency:${ name }`
);
}
if (await isCoherent(dependencyContext, getPackageJson(path))) return;
log.notice("%s not coherent %s, relinking binaries", dependentContext.name, name);
} else {
const isInstalled = await isDirectory(path);
const dependencyPackageJson = isInstalled ? getPackageJson(path) : null;
if (latestSupportedPublishedVersion && isInstalled) {
if (
optionalChaining(dependencyPackageJson, "version") ===
latestSupportedPublishedVersion
) {
// Seems up to date, but let's follow with quick sanity check and confirm whether
// there are corresponding folders for subdependencies
if (await isCoherent(dependencyContext, dependencyPackageJson)) return;
log.notice("%s not coherent %s, reinstalling", dependentContext.name, name);
}
}
}

if (
!latestSupportedPublishedVersion &&
isInstalled &&
dependencyPackageJson &&
dependencyPackageJson._npmCrossLinkCacheName
) {
const cachedDependencyPackageJson = getPackageJson(sourceDirname);
if (
cachedDependencyPackageJson &&
dependencyPackageJson._npmCrossLinkCacheName ===
cachedDependencyPackageJson._npmCrossLinkCacheName
!latestSupportedPublishedVersion &&
isInstalled &&
dependencyPackageJson &&
dependencyPackageJson._npmCrossLinkCacheName
) {
if (await isCoherent(dependencyContext, dependencyPackageJson)) return;
log.notice("%s not coherent %s, reinstalling", dependentContext.name, name);
const cachedDependencyPackageJson = getPackageJson(sourceDirname);
if (
cachedDependencyPackageJson &&
dependencyPackageJson._npmCrossLinkCacheName ===
cachedDependencyPackageJson._npmCrossLinkCacheName
) {
if (await isCoherent(dependencyContext, dependencyPackageJson)) return;
log.notice("%s not coherent %s, reinstalling", dependentContext.name, name);
}
}
}
await rm(path, { loose: true, recursive: true, force: true });
log.notice("%s installing %s @ %s", dependentContext.name, name, targetVersion);
await rm(path, { loose: true, recursive: true, force: true });
log.notice("%s installing %s @ %s", dependentContext.name, name, targetVersion);

dependentContext.installationJobs.add(
`${ isInstalled ? "update" : "install" }-dependency:${ name }`
);
dependentContext.installationJobs.add(
`${ isInstalled ? "update" : "install" }-dependency:${ name }`
);

log.debug("%s copy dependency from %s to %s", dependentContext.name, sourceDirname, path);
await copyDir(sourceDirname, path);
log.debug("%s copy dependency from %s to %s", dependentContext.name, sourceDirname, path);
await copyDir(sourceDirname, path);
}

log.debug(
"%s map binaries %s %s", dependentContext.name, dependencyContext.name,
Expand Down

0 comments on commit 6bc1da6

Please sign in to comment.