Skip to content

Commit

Permalink
feat: ensure to link dependency if link is not rigth
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Nov 9, 2018
1 parent d030445 commit 51ffd5b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/setup-npm-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
const { basename, resolve } = require("path")
, log = require("log4").get("dev-package")
, rm = require("fs2/rm")
, isSymbolicLink = require("./is-symbolic-link")
, realpath = require("fs2/realpath")
, getNpmModulesPath = require("./get-npm-modules-path")
, runProgram = require("./run-program");

module.exports = async (packagePath, dependencyName) => {
const dependencyLinkPath = resolve(packagePath, "node_modules", dependencyName);
if (await isSymbolicLink(dependencyLinkPath)) return;
const linkedPath = resolve(await getNpmModulesPath(), dependencyName);
if ((await realpath(dependencyLinkPath, { loose: true })) === linkedPath) return;
log.info("link %s in %s", dependencyName, basename(packagePath));
await rm(dependencyLinkPath, { loose: true, recursive: true, force: true });
await runProgram("npm", ["link", dependencyName], {
Expand Down

0 comments on commit 51ffd5b

Please sign in to comment.