Skip to content
Myr

fix: resolve symbol links until their are no more symbolic links

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Depending on your npm / yarn set up a global install may have to resolve through several symlinks before it correctly arrives the the baseDir that actually contains the other subcommands. The changes the resolution logic to resolve symlinks until their are no more to resolve by using realpath which will resolve links all the way to the final destination.

authored by Samuel Attard · committed by Samuel Attard · parent 291fc04 · Browse files · 6 files+27 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+27 added−7 removed

  • tests:+23 added−0 removed
  • other:+4 added−7 removed

6 files+27 added−7 removed

added:test/fixtures/another-dir/pm+1 added
1../other-dir/pm
added:test/fixtures/other-dir/pm+1 added
1../pm
modified:test/test.command.executableSubcommand.js+7 added
modified:test/test.command.executableSubcommandAlias.js+7 added
modified:test/test.command.executableSubcommandDefault.js+7 added
modified:index.js+4 added-7 removed
525 unmodified lines
526 var bin = basename(f, path.extname(f)) + '-' + args[0];527528 // In case of globally installed, get the base dir where executable529 // subcommand file should be located at530 var baseDir,531 link = fs.lstatSync(f).isSymbolicLink() ? fs.readlinkSync(f) : f;530 var baseDir;531533 // when symbolink is relative path534 if (link !== f && link.charAt(0) !== '/') {535 link = path.join(dirname(f), link);536 }537 baseDir = dirname(link);532 var resolvedLink = fs.realpathSync(f);533534 baseDir = dirname(resolvedLink);535536 // prefer local `./<bin>` to bin in the $PATH537 var localBin = path.join(baseDir, bin);538539 // whether bin file is a js script with explicit `.js` or `.ts` extension
685 unmodified lines