{"name":"link","version":"1.0.0","keywords":["npm","link","symlink"],"author":{"name":"Hiroki Osame","email":"hiroki.osame@gmail.com"},"license":"MIT","_id":"link@1.0.0","homepage":"https://github.com/privatenumber/link#readme","bugs":{"url":"https://github.com/privatenumber/link/issues"},"bin":{"link":"dist/cli.js"},"dist":{"shasum":"6b57d301333f2056c47a8fd06df028296074d7be","tarball":"http://registry-npm.ywwl.com/link/download/link-1.0.0.tgz","fileCount":3,"integrity":"sha512-LUVacH8PlfzMd8C2Jg0Hu2F0Jf2THQyuXOWPL0je2odWeO3y6sSWS42lea0d4bQw5JI7yLDqlBR/YwbuxAHGyA==","signatures":[{"sig":"MEQCIHy3QZblD6+la1o65OFBUC+n9Sbp7v5RCxuG3GlNwqpXAiBA5wdnLHNUKbLI3Um04Lw2ZW3QXX2G22XJYSDbIv3RyQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":166771,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiXDk4ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqapA//YRvlO2dvnPYyL42ipeBMzpR5vJs/XURkzvWqtIEDmoEb6dCI\r\n0URRUHkkA0dddHWzzj2pdt1HTIRSyZNL8NABJP02EAzFvpopX3kQhuvphOw9\r\n40khVQAORgloLyHekFtWXQ77dpiN3XWZm2m++7aNLOXab0TFDpYS+oZ2qBMp\r\nzxxB1Oydy+nrVssu3a65kdWGkm9Zz5q6bRC5nugIqTbbflvHacUZ3yY2IB8I\r\nUTl6bqUI3mhi37g1XwDi5Y9RtY3YbR/2QWiMkaJoPlE8ropBy2uq7QbwIXRv\r\nSa344OKh+uJ4H6K9GEvToRd5L3oUOLMHfUJ/vn6S+Xkcae5aQukwTRD4D7tP\r\nH+ra0oFaeoXNJ4n6xpcG6paI85R9C4+WTwWgz1h3RzC4ubSwFA3AXcNIGHjN\r\nssBxcI94+dtSPrmdWcX4ON5Gpa1o0hzqhp7VzyRV5sDcdwywLPoJXvcOIZ5Z\r\nNjlcD8qJ0USeLpCf68XMAZAHTVeyL1lq5hgIxnWJkMRijecmNvTfdIbPqRYS\r\nw8vfr5SkhOzM/Os5KAnpM97MkNufKGMDCc7jB8F/s9/PIIzOER9mLv/gL1f5\r\nT7CDHndjsQ+vdB2tqkXEAv+2wbbZ/2T1upL8WPVW47jIHg/WlFq6fXljGK9C\r\nvKg5UtmZQtlNCGpjrcXxdBnH28bwOGkN3xM=\r\n=VZnO\r\n-----END PGP SIGNATURE-----\r\n","size":48902,"noattachment":false,"key":"/link/-/link-1.0.0.tgz"},"funding":"https://github.com/privatenumber/link?sponsor=1","gitHead":"c5d71ad6a49c6241ef06413f3bc9ac86dfae020c","scripts":{"lint":"eslint .","test":"esno tests/index.ts","build":"pkgroll --minify","pretest":"npm run build"},"_npmUser":{"name":"hirokiosame","email":"hiroki.osame@gmail.com"},"repository":{"url":"git+https://github.com/privatenumber/link.git","type":"git"},"_npmVersion":"8.5.0","description":"A better npm link","directories":{},"_nodeVersion":"16.14.2","eslintConfig":{"rules":{"@typescript-eslint/no-shadow":["error",{"allow":["describe","test"]}]},"extends":"@pvtnbr","ignorePatterns":["tests/fixtures"]},"_hasShrinkwrap":false,"devDependencies":{"del":"^6.0.0","esno":"^0.14.1","cleye":"^1.1.0","execa":"^6.1.0","eslint":"^8.13.0","manten":"^0.0.3","pkgroll":"^1.0.3","get-node":"^12.1.0","kolorist":"^1.5.1","type-fest":"^2.12.2","typescript":"^4.6.3","@types/node":"^17.0.23","@pvtnbr/eslint-config":"^0.19.1"},"_npmOperationalInternal":{"tmp":"tmp/link_1.0.0_1650211127841_0.48788879742208113","host":"s3://npm-registry-packages"},"readme":"# npx link\n\nA safer and enhanced version of [`npm link`](https://docs.npmjs.com/cli/v8/commands/npm-link).\n\nWhy is `npm link` unsafe? Read the [blog post](https://hirok.io/posts/avoid-npm-link).\n\n### Features\n- 🔗 Link dependencies without removing previous links\n- 🛡 Only resolves to local paths\n- 🔥 Config file quickly linking multiple packages\n- 💫 Deep linking for quickling linking multilple packages\n\n<br>\n\n<p align=\"center\">\n\t<a href=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=platinum\">\n\t\t<picture>\n\t\t\t<source width=\"830\" media=\"(prefers-color-scheme: dark)\" srcset=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=platinum&image=dark\">\n\t\t\t<source width=\"830\" media=\"(prefers-color-scheme: light)\" srcset=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=platinum&image\">\n\t\t\t<img width=\"830\" src=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=platinum&image\" alt=\"Premium sponsor banner\">\n\t\t</picture>\n\t</a>\n</p>\n\n## Terminology\n\n- **Dependency package**\n\n\tThe package getting linked. This is usually a library.\n\n- **Consuming package**\n\n\tThe project you want to link the _Dependency package_ as a dependency of. This is usually an application.\n\n\t`consuming-package/node_modules/dependency-package` → `dependency-package`\n\n\n## Usage\n\n### Linking a package\n\nFrom the _Consuming package_ directory, link the _Dependency package_:\n\n```sh\nnpx link <dependency-package-path>\n```\n\nThis creates a symbolic link inside the `node_modules` of _Consuming package_, referencing the _Dependency package_.\n\n\n> **🛡️ Secure linking**\n>\n> Unlike `npm link`, it doesn't install the _Dependency package_ globally or re-install project dependencies.\n\n### Publish mode\n\nUsing symbolic links may not replicate the exact environment you get from a standard `npm install`. This discrepancy primarily arises from symlinked packages retaining their development `node_modules` directory. This can lead to issues, especially when multiple packages depend on the same library.\n\n<details>\n\t<summary>Here's an example</summary>\n\t<br>\n\nIn a production environment, `npm install` detects common dependencies and installs only one instance of a shared dependency. However, when there's a symbolic link to the development directory of a dependency, separate copies of those dependencies are resolved from the development `node_modules`.\n\nLet's say there's an _App A_ with a dependency on _Package B_, and they both depend on _Library C_:\n\n- Production environment\n\n\t`npm install` detects that both _App A_ and _Package B_ depends on _Library C_, and only installs one copy of _Library C_ for them to share.\n\n- Symbolic link environment\n\n\t_App A_ has its copy of _Library C_, and _Package B_ also has its development copy of _Library C_—possibly with different versions. Consequently, when you run the application, it will load two different versions of _Library C_, leading to unexpected outcomes.\n\n</details>\n\n_Publish mode_ helps replicate the production environment in your development setup.\n\n#### Setup instructions\n\n1. In the _Dependency package_, run `npm pack` to create a tarball:\n\n\t```sh\n\tcd dependency-package-path\n\tnpm pack\n\t```\n\n\tThis generates a tarball (`.tgz`) file in the current directory. Installing from this simulates the conditions of a published package without actually publishing it.\n\n\t> **Tip:** You can skip this step if this dependency is already installed from npm and there are no changes to the dependency's `package.json`\n\n2. In the _Consuming package_\n\n\t1. Install the Dependency tarball from _Step 1_\n\n\t\t```sh\n\t\tnpm install --no-save <dependency-tarball-path>\n\t\t```\n\n\t\tThis sets up the same `node_modules` tree used in a production environment.\n\n\t2. Link the _Dependency package_\n\n\t\t```sh\n\t\tnpx link publish <dependency-package-path>\n\t\t```\n\n\t\tThis creates hard links in `node_modules/dependency` to the specific publish assets of the _Dependency package_.\n\n\t\t<details>\n\t\t<summary><em>Why hard links instead of symbolic links?</em></summary>\n\t\t<br>\n\n\t\tAnother issue with the symlink approach is that Node.js, and popular bundlers, looks up the `node_module` directory relative to a module's realpath rather than the import path (symlink path). By using hard links, we can prevent this behavior and ensure that the `node_modules` directory is resolved using the production tree we set up in _Step 2_.\n\t\t</details>\n\n4. Start developing!\n\n\tAny changes you make to the _Dependency package_ will be reflected in the `node_modules` directory of the _Consuming package_.\n\n\t> **Note:** If the _Dependency package_ emits new files, you'll need to re-run `npx link publish <dependency-package-path>` to create new hard links.\n\t\n### Configuration file\n\nCreate a `link.config.json` (or `link.config.js`) configuration file at the root of the _Consuming package_ to automatically setup links to multiple _Dependency packages_.\n\nExample _link.config.json_:\n```json5\n{\n    \"packages\": [\n        \"/path/to/dependency-path-a\",\n        \"../dependency-path-b\"\n    ]\n}\n```\n\nThe configuration has the following type schema:\n```ts\ntype LinkConfig = {\n\n    // Whether to run `npx link` on dependency packages with link.config.json\n    deepLink?: boolean\n\n    // List of dependency packages to link\n    packages?: string[]\n}\n```\n\n> **Note:** It's not recommended to commit this file to source control since this is for local development with local paths.\n\n\nTo link the dependencies defined in `link.config.json`, run:\n```sh\nnpx link\n```\n\n### Deep linking\n\nBy default, `npx link` only links packages in the _Consuming package_. However, there are cases where the _Dependency packages_ also needs linking setup.\n\nDeep linking recursively runs link on every linked dependency that has a `link.config.json` file.\n\nEnable with the `--deep` flag or `deepLink` property in `link.config.json`.\n\n```sh\nnpx link --deep\n```\n\n<br>\n\n<p align=\"center\">\n\t<a href=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=gold\">\n\t\t<picture>\n\t\t\t<source width=\"830\" media=\"(prefers-color-scheme: dark)\" srcset=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=gold&image=dark\">\n\t\t\t<source width=\"830\" media=\"(prefers-color-scheme: light)\" srcset=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=gold&image\">\n\t\t\t<img width=\"830\" src=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=gold&image\" alt=\"Premium sponsor banner\">\n\t\t</picture>\n\t</a>\n</p>\n\n## FAQ\n\n### Why should I use `npx link` over `npm link`?\nBecause `npm link` [is complicated and dangerous to use](https://hirok.io/posts/avoid-npm-link). And `npx link` offers more features such as _Publish mode_.\n\n### How do I remove the links?\nRun `npm install` and it should remove them.\n\n`npm install` enforces the integrity of `node_modules` by making sure all packages are correctly installed. Reverting the links is a side effect of this.\n\n### Why does `npx link` point to `ln`?\n\nYou must use npx v7 or higher. Check the version with `npx -v`.\n\nIn the obsolete npx v6, local binaries take precedence over npm modules so  `npx link` can point to the native `link`/`ln` command:\n```\n$ npx link\nusage: ln [-s [-F] | -L | -P] [-f | -i] [-hnv] source_file [target_file]\n       ln [-s [-F] | -L | -P] [-f | -i] [-hnv] source_file ... target_dir\n       link source_file target_file\n```\n\nTo work around this, install `link` globally first:\n```sh\n$ npm i -g link\n$ npx link\n```\n\n## Related\n\n- [`npx ci`](https://github.com/privatenumber/ci) - A better `npm ci`.\n\n\n## Sponsors\n\n<p align=\"center\">\n\t<a href=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver1\">\n\t\t<picture>\n\t\t\t<source width=\"410\" media=\"(prefers-color-scheme: dark)\" srcset=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver1&image=dark\">\n\t\t\t<source width=\"410\" media=\"(prefers-color-scheme: light)\" srcset=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver1&image\">\n\t\t\t<img width=\"410\" src=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver1&image\" alt=\"Premium sponsor banner\">\n\t\t</picture>\n\t</a>\n\t<a href=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver2\">\n\t\t<picture>\n\t\t\t<source width=\"410\" media=\"(prefers-color-scheme: dark)\" srcset=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver2&image=dark\">\n\t\t\t<source width=\"410\" media=\"(prefers-color-scheme: light)\" srcset=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver2&image\">\n\t\t\t<img width=\"410\" src=\"https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver2&image\" alt=\"Premium sponsor banner\">\n\t\t</picture>\n\t</a>\n</p>\n\n<p align=\"center\">\n\t<a href=\"https://github.com/sponsors/privatenumber\">\n\t\t<img src=\"https://cdn.jsdelivr.net/gh/privatenumber/sponsors/sponsorkit/sponsors.svg\">\n\t</a>\n</p>\n","publish_time":1650211128053,"maintainers":[{"name":"hirokiosame","email":"hiroki.osame@gmail.com"}],"_cnpm_publish_time":1650211128053,"dist-tags":{"latest":"2.1.2"}}