privatenumber / link

🔗 A better `npm link`
193 stars 8 forks source link

"Failed to symlink" a scoped package's bin executable #10

Closed wesleyboar closed 2 years ago

wesleyboar commented 2 years ago

I am pleased with this package thus far. It has solved npm link linked package dependency problems for me.

But I think this package does not successfully link bin executables for scoped package. If I am incorrect, I welcome any direction to solve my problem.

Short Version

I truncate my actual directory structure as /Users/.../repos/.

A. ⚠️ When I run npx link to install a directory with a scoped packages, a symlink can not be created for any bin executable.

{
  "name": "@tacc/core-styles",
  "bin": "src/cli.js",
  // ...
}
> pwd
/Users/.../repos/core-cms
> npx link ../core-styles
✖ Failed to symlink /Users/.../repos/core-styles with error: ENOENT: no such file or directory, symlink '/Users/.../repos/core-styles/src/cli.js' -> 'node_modules/.bin/@tacc/core-styles'

B. ✅ When I run npx link to install a directory with a not-scoped package, a symlink is created for any bin executable.

{
  "name": "core-styles",
  "bin": "src/cli.js",
  // ...
}
> pwd
/Users/.../repos/core-cms
> npx link ../core-styles
✔ Symlinked core-styles: /Users/.../repos/core-cms/node_modules/core-styles → ../../core-styles

Long Version

I truncate my actual directory structure as /Users/.../repos/.

A. ⚠️ Scoped Package (click to toggle details) 1. Given a package with a scope `@tacc/core-styles`: ```js { "name": "@tacc/core-styles", "version": "0.7.0", // ... "main": "src/main.js", "bin": "src/cli.js", // ... } ``` 2. I link the `core-styles` package into `core-cms`. ```shell > pwd /Users/.../repos/core-cms > npx link ../core-styles ✖ Failed to symlink /Users/.../repos/core-styles with error: ENOENT: no such file or directory, symlink '/Users/.../repos/core-styles/src/cli.js' -> 'node_modules/.bin/@tacc/core-styles' ``` 3. The scoped directory for the bin executable (as `link` package expects) in `core-cms` does **not** exist. ```shell > pwd /Users/.../repos/core-cms > ls -la node_modules/.bin/@tacc ls: node_modules/.bin/@tacc: No such file or directory ``` 5. I think [NPM does **not** install there by design (old info)](https://github.com/npm/npm/issues/8640#issuecomment-131235858). Indeed, NPM (v8.12.1) puts the bin executable for a scoped package `@frctl/fractal` (dependency of `core-cms`) directly in `.bin`: ```shell > pwd /Users/.../repos/core-cms > ls -la node_modules/.bin/fractal lrwxr-xr-x 1 ... staff 32 Jul 18 11:22 node_modules/.bin/fractal -> ../@frctl/fractal/bin/fractal.js ``` 6. The bin executable (as NPM creates for scoped packages) in `core-cms` does **not** exist. ```shell > pwd /Users/.../repos/core-cms > ls -la node_modules/.bin/core-styles ls: node_modules/.bin/core-styles: No such file or directory ```
B. ✅ Not-Scoped Package (click to toggle details) 1. Given a package with **no** scope, `core-styles`: ```js { "name": "core-styles", "version": "0.7.0", // ... "main": "src/main.js", "bin": "src/cli.js", // ... } ``` 2. I link the `core-styles` package into `core-cms`. ```shell > pwd /Users/.../repos/core-cms > npx link ../core-styles ✔ Symlinked core-styles: /Users/.../repos/core-cms/node_modules/core-styles → ../../core-styles ``` 3. The bin executable (as NPM creates for scoped packages) in `core-cms` _does_ exist. ```shell > pwd /Users/.../repos/core-cms > ls -la node_modules/.bin/core-styles lrwxr-xr-x 1 ... staff 78 Jul 18 12:30 node_modules/.bin/core-styles -> /Users/.../repos/core-styles/src/cli.js ```
privatenumber commented 2 years ago

Thanks for the issue @wesleyboar

I wasn't able to reproduce it with your snippets.

Can you provide a minimal reproduction repository containing the packages? (It's fine to delete the JS content as long as the bug is still reproducible.)

wesleyboar commented 2 years ago

Yes. But I might not deliver until later this week or month.

wesleyboar commented 2 years ago

I just tested my (non-minimal) repo with v1.5.0 and v1.5.1.

v1.5.1. indeed fixes the problem. Nice work, thanks.

I am sorry I did not provide a minimal repo to start with.