{"_id":"@abxvn/resolve","_rev":"1-e5fa9f8f990f67e9242016e66714b46a","name":"@abxvn/resolve","dist-tags":{"latest":"2.0.1"},"versions":{"2.0.0":{"name":"@abxvn/resolve","version":"2.0.0","description":"Async resolve with pnp supports","license":"MIT","main":"index.js","bin":{"resolve":"cli/index.js"},"types":"index.d.ts","repository":{"type":"git","url":"git+https://github.com/abxvnvn/source.git","directory":"packages/resolve"},"keywords":["abx","source","resolve","async","fast","pnp"],"author":{"name":"Hung Luu","email":"hungluu2106@gmail.com"},"bugs":{"url":"https://github.com/abxvnvn/source/issues?q=is%3Aopen+is%3Aissue+label%3A%22package%3Aresolve%22"},"homepage":"https://github.com/abxvnvn/source/tree/main/packages/resolve#readme","dependencies":{"commander":"^10.0.1","fs-extra":"^11.1.1","global-dirs":"^3.0.1","@abxvn/resolve":"^2.0.0"},"devDependencies":{"@types/fs-extra":"^11.0.1","@types/jest":"^29.5.1","@types/node":"^18.16.0"},"_id":"@abxvn/resolve@2.0.0","_integrity":"sha512-qaJ4z4LhPKEYvpVHMiwt8g9WYbLuJBkz6HCNeD2An897e2a5Md7oZxuHi6X91Z21G/brFUSFKGJVaEofp1Gtog==","_resolved":"/private/var/folders/0_/q3400kzn4kbflmypl6nnsf4m0000gn/T/03b0f130c9dc5215c6bb413535e22d87/abxvn-resolve-2.0.0.tgz","_from":"file:abxvn-resolve-2.0.0.tgz","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-qaJ4z4LhPKEYvpVHMiwt8g9WYbLuJBkz6HCNeD2An897e2a5Md7oZxuHi6X91Z21G/brFUSFKGJVaEofp1Gtog==","shasum":"6297c9b5862212ae1804c3c46e67eb3f2bb1b382","tarball":"https://registry.npmjs.org/@abxvn/resolve/-/resolve-2.0.0.tgz","fileCount":6,"unpackedSize":74042,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDCQR69j03EyHbgmmnT1hXXWmPpOtR1rHpVjicfN5b8UAIhAOizZzNyqFZk/7WKwBOwo4AkNC14ORqGXoG8IGaJXg4o"}]},"_npmUser":{"name":"hungluu","email":"luuhug@gmail.com"},"directories":{},"maintainers":[{"name":"hungluu","email":"luuhug@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/resolve_2.0.0_1703651717120_0.045492369589485104"},"_hasShrinkwrap":false},"2.0.1":{"name":"@abxvn/resolve","version":"2.0.1","description":"Async resolve with pnp supports","license":"MIT","main":"index.js","bin":{"resolve":"cli/index.js"},"types":"index.d.ts","repository":{"type":"git","url":"git+https://github.com/abxvn/source.git","directory":"packages/resolve"},"keywords":["abx","source","resolve","async","fast","pnp"],"author":{"name":"Hung Luu","email":"hungluu2106@gmail.com"},"bugs":{"url":"https://github.com/abxvn/source/issues?q=is%3Aopen+is%3Aissue+label%3A%22package%3Aresolve%22"},"homepage":"https://github.com/abxvn/source/tree/main/packages/resolve#readme","dependencies":{"commander":"^10.0.1","fs-extra":"^11.1.1","global-dirs":"^3.0.1","@abxvn/resolve":"^2.0.1"},"devDependencies":{"@types/fs-extra":"^11.0.1","@types/jest":"^29.5.1","@types/node":"^18.16.0"},"_id":"@abxvn/resolve@2.0.1","_integrity":"sha512-UsiBYMgBFmvvC7DBFM9W9nEL7jbcxRXSYwQ09vazxCo9mJQz97U8wyuERra2W3dbYjVzusCjwxupVAL+iIsIjw==","_resolved":"/private/var/folders/0_/q3400kzn4kbflmypl6nnsf4m0000gn/T/1763097441ff6b5733f515cc9845f4b2/abxvn-resolve-2.0.1.tgz","_from":"file:abxvn-resolve-2.0.1.tgz","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-UsiBYMgBFmvvC7DBFM9W9nEL7jbcxRXSYwQ09vazxCo9mJQz97U8wyuERra2W3dbYjVzusCjwxupVAL+iIsIjw==","shasum":"bd79d4db0f8c1d3fcbb0ee485e4add6b0eea7908","tarball":"https://registry.npmjs.org/@abxvn/resolve/-/resolve-2.0.1.tgz","fileCount":6,"unpackedSize":74064,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDM0HEtpx/c++6GL91EdLJY8OgbgR+MGrNi+4UlMwax/gIgBzY6VQdSdWXZ54cQkJsgbOMrzjl2sEktNKrRGcz0YCI="}]},"_npmUser":{"name":"hungluu","email":"luuhug@gmail.com"},"directories":{},"maintainers":[{"name":"hungluu","email":"luuhug@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/resolve_2.0.1_1703656741834_0.3917076387948002"},"_hasShrinkwrap":false}},"time":{"created":"2023-12-27T04:35:17.012Z","2.0.0":"2023-12-27T04:35:17.286Z","modified":"2023-12-27T05:59:02.270Z","2.0.1":"2023-12-27T05:59:02.010Z"},"maintainers":[{"name":"hungluu","email":"luuhug@gmail.com"}],"description":"Async resolve with pnp supports","homepage":"https://github.com/abxvn/source/tree/main/packages/resolve#readme","keywords":["abx","source","resolve","async","fast","pnp"],"repository":{"type":"git","url":"git+https://github.com/abxvn/source.git","directory":"packages/resolve"},"author":{"name":"Hung Luu","email":"hungluu2106@gmail.com"},"bugs":{"url":"https://github.com/abxvn/source/issues?q=is%3Aopen+is%3Aissue+label%3A%22package%3Aresolve%22"},"license":"MIT","readme":"@abxvn/resolve\n=====\n[![build][badge-build]][changelog]\n[![version][npm-version-badge]][npm-url]\n[![downloads][npm-downloads-badge]][npm-url]\n[![code style][code-style-badge]][code-style-url]\n\nProvide an async [`node require.resolve algorithmn`](https://nodejs.org/api/modules.html#modules_all_together), with **extra features:**\n  - ⚡ Blazingly faster comparing to vanilla [require.resolve](https://nodejs.org/api/moduleshtml#modules_require_resolve_request_options) ([bench](#benchmarks)) (Especially when you need to work with large amount of modules)\n  - 🌟 Supports resolving with [Yarn PnP API](https://yarnpkg.com/features/pnp)\n  - 🌇 Supports resolving local packages, Yarn and Npm global packages, symlinks, workspaces, directory and files\n  - _Allow multiple module resolving using wildcard (*) (coming soon)_\n  - _Allow advanced search using file contents search (coming soon)_\n\n**Table of contents**\n* [Installation](#installation)\n* [Usage](#usage)\n  + [Resolve in async way](#resolve-in-async-way)\n  + [Resolve modules](#resolve-modules)\n  + [Options](#options)\n  + [Play with CLI](#play-with-cli)\n  + [Resolve in classic way](#resolve-in-classic-way)\n* [Benchmarks](#benchmarks)\n* [Changelog](#changelog)\n* [Contribution](#contribution)\n\nInstallation\n-----\nPick **one of** these commands to install:\n```\npnpm add @abxvn/resolve\nyarn add @abxvn/resolve\nnpm install --save @abxvn/resolve\n```\n\nUsage\n----\n### Resolve in async way\nThe `resolve` supports asynchronously resolving:\n- full path to a file\n- or a module's main (entry) path, to be used with `require`\n\n```ts\nimport { resolve } from `@abxvn/resolve`\n\n// Entry point / main to require\n// pnp: <dir>/.yarn/cache/.../packageA/index.js\n// non-pnp: <dir>/node_modules/packageA/index.js\nconsole.log(resolve('packageA'))\n\n// full path <dir>/src/index.js\nconsole.log(resolve('./src/index.js'))\n\n// full path <dir>/packages/workspaceA/main.js\n// (main.js) is defined in workspaceA's package.json\nconsole.log(resolve('workspaceA'))\nconsole.log(resolve('../localWorkspaceB'))\n```\n### Resolve modules\n\nThe `resolveModule` supports asynchronously resolving module metadata\n\n```ts\nimport { resolveModule } from `@abxvn/resolve`\n\nconsole.log(resolveModule('packageA')) // => IModule\nconsole.log(resolveModule('workspaceA')) // => IModule\nconsole.log(resolveModule('../localWorkspaceB')) // => IModule\n```\n\nThe resolved module metadata is:\n```ts\ninterface IModule {\n  // whether the module exists or not\n  exists: boolean\n  // input resolve query\n  query: string\n  // module dir path\n  path: string\n  // module main (entry) script\n  main: string\n  // module name\n  name: string\n  // module version\n  version: string\n  // module dependencies\n  dependencies: string[]\n  // error while resolving module\n  error?: Error\n}\n```\n\n### Options\nWe can pass custom options into the resolver:\n\n```js\nimport { resolve } from `@abxvn/resolve`\n\nresolve('moduleB', options)\n```\n\nAll options are optional (We already provided a good configuration for you):\n|        **Name**       | **Type** |                                                            **Description**                                                            |            **Default**           |\n|:---------------------:|:--------:|:-------------------------------------------------------------------------------------------------------------------------------------:|:--------------------------------:|\n| callerPath           | string   | Base path to resolve requested modules | current script path (or working directory)                            |\n| moduleDirs | string[] | _(non pnp)_ node_modules paths | resolving up algorithm including global npm or yarn packages |\n\n### Play with CLI\n\nYou can quickly get any modules or files requirable path by this command:\n\n```bash\nresolve <...paths>\n```\n\nif you want CLI to search for module metadata, please call with flag `-m` or `--metadata`, for example:\n\n```bash\nresolve @abxvn/resolve lodash -m\n```\n\n### Resolve in classic way\nYou can also `resolve` in classic, I mean synchronously resolving, but with this tool's extra features as mentioned earlier:\n- Custom caller path for starting point of resolving\n- Custom list of node_modules dirs for searching\n\n```ts\nimport { resolveSync } from `@abxvn/resolve`\n\n// Entry point / main to require\n// pnp: <dir>/.yarn/cache/.../packageA/index.js\n// non-pnp: <dir>/node_modules/packageA/index.js\nconsole.log(resolveSync('packageA'))\n\n// full path <dir>/src/index.js\nconsole.log(resolveSync('./src/index.js'))\n```\n\nBenchmarks\n-----\nWe tested with 2 cases, to compare speed using vanilla `require.resolve` and this library's resolver. Here are the results:\n\n**Test loading 10 packages**\n\n<img width=\"494\" alt=\"Screen Shot 2021-03-23 at 00 08 01\" src=\"https://user-images.githubusercontent.com/13363340/112029482-e1251f00-8b6b-11eb-9cf8-8074f72de6ab.png\">\n\n**Test loading 80 packages**\n\n<img width=\"494\" alt=\"Screen Shot 2021-03-23 at 00 07 18\" src=\"https://user-images.githubusercontent.com/13363340/112029502-e6826980-8b6b-11eb-9e16-bd6c790d003b.png\">\n\nAll tests were done on my Mac intel i5 10th (2020), RAM 16 GB\n\nChangelog\n-----\nSee [CHANGELOG.md][changelog]\n\nContribution\n-----\n\nAll PRs and ideas for improvement are welcomed. \n\nIf you got any issues using this package, don't hesitate to create new [🐞 Bug report][issues] with a proper `package:<name>` label.\n\nFeel free to clone this project, make changes that your feel necessary and pull request anytime you want.\n\nInstall dependencies and run development build:\n```\nyarn install\nyarn start\n```\n\n**Working on your first Pull Request?**\n\nYou can learn how from this free video series: [How to Contribute to an Open Source Project on GitHub](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github)\n\nTo help you get your feet wet and get you familiar with our contribution process, we have a list of good first issues that contain bugs that have a relatively limited scope. This is a great place to get started.\n\n-----\nCheers 🍻\n\n[changelog]: https://github.com/abxvn/source/blob/main/packages/resolve/CHANGELOG.md\n[issues]: https://github.com/abxvn/source/issues?q=is%3Aopen+is%3Aissue+label%3Apackage%3Aresolve\n[good-first]: https://github.com/abxvn/source/issues?q=is%3Aopen+is%3Aissue+label%3Aflag%3Agood-first\n[badge-build]: https://github.com/abxvn/source/actions/workflows/build.yaml/badge.svg\n[npm-url]: https://www.npmjs.com/package/@abxvn/resolve\n[npm-downloads-badge]: https://img.shields.io/npm/dw/@abxvn/resolve\n[npm-version-badge]: https://img.shields.io/npm/v/@abxvn/resolve\n[code-style-badge]: https://img.shields.io/badge/code_style-standard-brightgreen.svg\n[code-style-url]: https://standardjs.com\n","readmeFilename":"README.md"}