{"name":"link","version":"2.1.2","description":"A better npm link","keywords":["npm","link","symlink"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/privatenumber/link.git"},"funding":"https://github.com/privatenumber/link?sponsor=1","author":{"name":"Hiroki Osame","email":"hiroki.osame@gmail.com"},"bin":{"link":"dist/cli.js"},"gitHead":"113288e2a5040483fc2d21d1f0d5927c4f48e9fb","_id":"link@2.1.2","bugs":{"url":"https://github.com/privatenumber/link/issues"},"homepage":"https://github.com/privatenumber/link#readme","_nodeVersion":"24.11.0","_npmVersion":"11.6.1","dist":{"integrity":"sha512-n+OitQgtITNBGiWmEMgMiXo/fkf3yeyLm2nXm87vO4DDpaYrx57AZs/PMDk25qJIv+l586V226B2mA1H/n9zvg==","shasum":"59b622c7c4987290a8a45bf742cf81fcf0565980","tarball":"http://registry-npm.ywwl.com/link/download/link-2.1.2.tgz","fileCount":3,"unpackedSize":98368,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/link@2.1.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICvUO2b7EoZJ6rQGAqqjqkknc8mJPrw2Y1LrzAOt7VDRAiAhl5m+eaj7KP7Mc06Qk0QdopG/9rpl3poUbnq3A5NMLA=="}],"size":35474,"noattachment":false,"key":"/link/-/link-2.1.2.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:1850e5e7-0b42-4df7-a626-c35978d9c7ac"}},"directories":{},"maintainers":[{"name":"hirokiosame","email":"hiroki.osame@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/link_2.1.2_1768146631280_0.305857789344006"},"_hasShrinkwrap":false,"readme":"<p align=\"center\">\n\t<img width=\"180\" src=\".github/logo.webp\">\n</p>\n<h1 align=\"center\">\n\t<sup>npx link</sup>\n\t<br>\n\t<a href=\"https://npm.im/link\"><img src=\"https://badgen.net/npm/v/link\"></a> <a href=\"https://npm.im/link\"><img src=\"https://badgen.net/npm/dm/link\"></a>\n</h1>\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://github.com/sponsors/privatenumber/sponsorships?tier_id=398771\"><img width=\"412\" src=\"https://raw.githubusercontent.com/privatenumber/sponsors/master/banners/assets/donate.webp\"></a>\n\t<a href=\"https://github.com/sponsors/privatenumber/sponsorships?tier_id=397608\"><img width=\"412\" src=\"https://raw.githubusercontent.com/privatenumber/sponsors/master/banners/assets/sponsor.webp\"></a>\n</p>\n<p align=\"center\"><sup><i>Already a sponsor?</i> Join the discussion in the <a href=\"https://github.com/pvtnbr/link\">Development repo</a>!</sup></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## 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://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":1768146631414,"_cnpm_publish_time":1768146631414,"dist-tags":{"latest":"2.1.2"}}