Skip to content

Commit

Permalink
fix: Ensure to link binaries on maintained install
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Sep 8, 2024
1 parent 257127e commit 93aed19
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions lib/setup-dependency/setup-local/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ const { dirname, relative } = require("path")
, symlink = require("fs2/symlink")
, semver = require("semver")
, log = require("log").get("npm-cross-link")
, getPackageJson = require("../../get-package-json")
, resolveExternalContext = require("../../resolve-external-context")
, resolveMaintainedPackagePath = require("../../resolve-maintained-package-path")
, installExternal = require("../install-external")
, resolveLogLevel = require("../../utils/resolve-log-level")
, resolveLocalContext = require("../../resolve-local-context");
, resolveLocalContext = require("../../resolve-local-context")
, installExternal = require("../install-external")
, mapBinaries = require("../binary-handler/map")
, isCoherent = require("../binary-handler/is-coherent");

module.exports = async (dependencyContext, userConfiguration, inputOptions, progressData) => {
const { dependentContext, name, path, versionRange, isSemVerVersionRange } = dependencyContext;
Expand Down Expand Up @@ -66,15 +69,21 @@ module.exports = async (dependencyContext, userConfiguration, inputOptions, prog
const linkedPath = relative(
dirname(path), resolveMaintainedPackagePath(name, userConfiguration)
);
if (await isSymlink(path, { linkPath: linkedPath })) return;
log.info(
"%s dependency %s at %s doesn't resemble %s", dependentContext.name, name, path, linkedPath
);
const isInstalled = await lstat(path, { loose: true });
await rm(path, { loose: true, recursive: true, force: true });
await symlink(linkedPath, path, { intermediate: true });
dependentContext.installationJobs.add(
`${ isInstalled ? "update" : "install" }-dependency:${ name }`
);
log.notice("%s linking %s (as maintained package)", dependentContext.name, name);
if (await isSymlink(path, { linkPath: linkedPath })) {
if (await isCoherent(dependencyContext, getPackageJson(path))) return;
log.notice("%s binaries not coherent %s, relinking", dependentContext.name, name);
} else {
log.info(
"%s dependency %s at %s doesn't resemble %s", dependentContext.name, name, path,
linkedPath
);
const isInstalled = await lstat(path, { loose: true });
await rm(path, { loose: true, recursive: true, force: true });
await symlink(linkedPath, path, { intermediate: true });
dependentContext.installationJobs.add(
`${ isInstalled ? "update" : "install" }-dependency:${ name }`
);
log.notice("%s linking %s (as maintained package)", dependentContext.name, name);
}
await mapBinaries(dependencyContext);
};

0 comments on commit 93aed19

Please sign in to comment.