{"name":"link","version":"1.4.0","keywords":["npm","link","symlink"],"author":{"name":"Hiroki Osame","email":"hiroki.osame@gmail.com"},"license":"MIT","_id":"link@1.4.0","homepage":"https://github.com/privatenumber/link#readme","bugs":{"url":"https://github.com/privatenumber/link/issues"},"bin":{"link":"dist/cli.js"},"dist":{"shasum":"d3974525788b87ec7a0e727ea6ff5340fed07680","tarball":"http://registry-npm.ywwl.com/link/download/link-1.4.0.tgz","fileCount":3,"integrity":"sha512-REfl06BUD4/CqkKdmr2s2pEF1oxaCkLYowmptEaeDrtwd1eAiTymgC2e9+ArLM3gPpNG5/985R7Jhr/zpOr/ng==","signatures":[{"sig":"MEUCICsKdBuv5ITcBItbbf5oeV55XNJQ0iwv36iNnS52qtTCAiEAjmC+Vvha9jMXTRYHEGth5fgT9tXfwe2gSO6zmeky+3k=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":76014,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiZY+RACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoHKQ//UDeOyBBZlh6Dp4J73bZJnXF0vGlWhQNIfxrKtZLeGtXJNous\r\nnrygzUwi2/I2MqCXOcbjPOZMq/sRGYgaXbo8eLhvVnIxXcitAwyJ4w5FtcUF\r\nKOOY8lj2wGkFYQByCoNFj63W1gxgKZnJVA3Jfi9I2E6WLi8CbnfK/1ZHCNFg\r\nhJ2QLj9F2hBi63C8AK/Hp/vxSAU0UKqCVdqwciDLs8kFuOBRmqbHbhrcM2AV\r\ndUbfZkeevJi0csVVUQ7CPqrbx9tUfZbVei82eQGhudzpIjWF6/jddfJVURxl\r\nYpO7/F4nEpK2RlxRTwMUJYiP1N6soZGp37Yn2HYLKkWvNODGxdKxaRyg8NYf\r\nBk0H3k+yDesn8IcQXYUH5KxJserxWQwDoURZhSYfo5kg2B7DMDY2XLVAEENA\r\nDZ4UMkUuKKYSfHIu24fsaVZf6XXiSMlqscsB6GonUi4klfciratXJkIXtxT0\r\nWiilUlgaLbylRmJdzr0BfrFSxNOD4NCw3wBD4ptj/IXcTXBbnoviQwixBVrt\r\nddviVhrerOhyc2PEVJoVXqvskdv1btU/yafJtHDLpsLGhnC5qzpL6ymV91Zu\r\nB2FbyWFd/T+XbZ/pYVK+SPbYcukUov3rkx6lUCs1KMaPT5Rtl3yQokvm6LYq\r\nQ6YlAWKotGZ8mavx6du2pqhgP9e11g/z470=\r\n=eAcM\r\n-----END PGP SIGNATURE-----\r\n","size":23342,"noattachment":false,"key":"/link/-/link-1.4.0.tgz"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"funding":"https://github.com/privatenumber/link?sponsor=1","gitHead":"fd6ad4e5536a85188a3d2f9e8935227b1a1c506a","scripts":{"lint":"eslint --cache .","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":{},"lint-staged":{"*.{js,ts,md,json}":["eslint --cache","npm test"]},"_nodeVersion":"16.14.2","eslintConfig":{"rules":{"@typescript-eslint/no-shadow":["error",{"allow":["describe","test"]}]},"extends":"@pvtnbr","ignorePatterns":["tests/fixtures"]},"_hasShrinkwrap":false,"devDependencies":{"esno":"^0.14.1","cleye":"^1.1.0","execa":"^6.1.0","husky":"^4.3.8","eslint":"^8.13.0","manten":"^0.0.3","pkgroll":"^1.0.4","cmd-shim":"^5.0.0","fs-extra":"^10.1.0","get-node":"^12.1.0","kolorist":"^1.5.1","type-fest":"^2.12.2","typescript":"^4.6.3","@types/node":"^17.0.25","lint-staged":"^12.3.7","@types/cmd-shim":"^5.0.0","@types/fs-extra":"^9.0.13","@pvtnbr/eslint-config":"^0.19.1"},"_npmOperationalInternal":{"tmp":"tmp/link_1.4.0_1650823057186_0.41168991955623535","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":1650823057417,"maintainers":[{"name":"hirokiosame","email":"hiroki.osame@gmail.com"}],"_cnpm_publish_time":1650823057417,"dist-tags":{"latest":"2.1.2"}}