{"id":15693975,"url":"https://github.com/jonschlinkert/resolve-modules","last_synced_at":"2025-05-08T05:58:36.113Z","repository":{"id":57354672,"uuid":"46680200","full_name":"jonschlinkert/resolve-modules","owner":"jonschlinkert","description":"Resolves local and global npm modules that match specified patterns, and returns a configuration object for each resolved module.","archived":false,"fork":false,"pushed_at":"2016-05-19T22:34:37.000Z","size":104,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-08T05:58:31.317Z","etag":null,"topics":["global","modules","npm","resolve"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonschlinkert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-22T21:09:29.000Z","updated_at":"2021-04-12T22:35:32.000Z","dependencies_parsed_at":"2022-09-12T03:40:13.517Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/resolve-modules","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fresolve-modules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fresolve-modules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fresolve-modules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fresolve-modules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/resolve-modules/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253009892,"owners_count":21839714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["global","modules","npm","resolve"],"created_at":"2024-10-03T18:50:50.602Z","updated_at":"2025-05-08T05:58:36.096Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# resolve-modules [![NPM version](https://img.shields.io/npm/v/resolve-modules.svg?style=flat)](https://www.npmjs.com/package/resolve-modules) [![NPM downloads](https://img.shields.io/npm/dm/resolve-modules.svg?style=flat)](https://npmjs.org/package/resolve-modules) [![Build Status](https://img.shields.io/travis/jonschlinkert/resolve-modules.svg?style=flat)](https://travis-ci.org/jonschlinkert/resolve-modules)\n\nResolves local and global npm modules that match specified patterns, and returns a configuration object for each resolved module.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install resolve-modules --save\n```\n\n## Usage\n\n```js\nvar Resolver = require('resolve-modules');\nvar resolver = new Resolver();\n```\n\n## API\n\n### [Resolver](index.js#L28)\n\nIterates over [npm-paths](https://github.com/jonschlinkert/npm-paths) and emits `file` for every resolved filepath, and `match` for files that match any specified [matchers](https://github.com/cezary/matchers). Paths are cached in memory using a few different objects:\n\n* `cache.paths`: array of absolute directory and file paths\n* `cache.names`: object of [vinyl](http://github.com/gulpjs/vinyl) files, where `file.name` is the object key. `file.name` is the basename of the filepath, but it's aliased as `name` so we can use it without touching the getters/setters on the vinyl file.\n* `cache.files`: array of [vinyl](http://github.com/gulpjs/vinyl) files\n\n**Params**\n\n* `options` **{Object}**: Specify a cache to use on `options.cache`.\n\n**Example**\n\n```js\nvar resolver = new Resolver();\nresolver.resolve();\nconsole.log(resolver);\n```\n\n### [.resolve](index.js#L105)\n\nIterates over [npm-paths](https://github.com/jonschlinkert/npm-paths) and returns an array of [vinyl](http://github.com/gulpjs/vinyl) files that match any provided matchers. Also emits `file` for all files, and `match` for matches. Additionally, paths are cached on the first call to `.resolve` so that any subsequent calls during the same process will use the cached filepaths instead of hitting the file system again. You can force `.resolve` to hit the file system again by deleting or nulling `resolver.cache.dirs`.\n\n**Params**\n\n* `fn` **{Function|String|Array|RegExp}**: Optionally specify a matcher value.\n* `options` **{Object}**\n* `returns` **{Array}**: Returns an array of [vinyl](http://github.com/gulpjs/vinyl) files.\n\n**Example**\n\n```js\nresolver.match('verb', function(basename, file) {\n  return basename === 'verb';\n});\n\n// matches\nconsole.log(resolver.resolve());\n\n// all cached paths\nconsole.log(resolver);\n```\n\n### [.find](index.js#L128)\n\nFind a filepath where `file.basename` exactly matches the given `name`. This method is standalone and does not require use of the `.resolve` method or matchers.\n\n**Params**\n\n* `name` **{String}**: Basename of the file to match.\n* `returns` **{String|undefined}**: Returns the absolute filepath if a match is found, otherwise undefined.\n\n**Example**\n\n```js\nvar filepath = resolver.find('foo');\n```\n\n### [.match](index.js#L157)\n\nDefine a matcher to use for matching files when the `resolve` method is called. If a string or array of strings is passed, strict equality is used for comparisons with `file.name`.\n\n**Params**\n\n* `name` **{String|Function|Array|RegExp}**: Optionally provide `name` to emit when a match is found, a matcher function, string to match, array of strings, or regex.\n* `val` **{String|Function|Array|RegExp}**: Matcher function, string to match, array of strings, or regex.\n* `options` **{Object}**: If a string is passed, options may be passed to [micromatch](https://github.com/jonschlinkert/micromatch) to convert the string to regex.\n* `returns` **{Object}**: Returns the instance for chaining.\n\n**Example**\n\n```js\nresolver.match('foo');\n```\n\n### [.filter](index.js#L186)\n\nDefine a filter function, glob, string or regex to use for excluding files before matchers are run.\n\n**Params**\n\n* `val` **{String|RegExp|Function}**\n* `options` **{Object}**\n* `returns` **{Object}**\n\n**Example**\n\n```js\nresolver.filter('*.foo');\n```\n\n### [.contains](index.js#L204)\n\nDefine a matcher to use for matching files when the `resolve` method is called. If a string or array of strings is passed, any `file.name` that contains the given string or strings will return true.\n\n**Params**\n\n* `name` **{String|Function|Array|RegExp}**: Optionally provide `name` to emit when a match is found, a matcher function, string to match, array of strings, or regex.\n* `val` **{String|Function|Array|RegExp}**: Matcher function, string to match, array of strings, or regex.\n* `options` **{Object}**: If a string is passed, options may be passed to [micromatch](https://github.com/jonschlinkert/micromatch) to convert the string to regex.\n* `returns` **{Object}**: Returns the instance for chaining.\n\n**Example**\n\n```js\nresolver.contains('foo');\n```\n\n### [.resolveDirs](index.js#L261)\n\nResolve sub-directories from npm-paths. This method probably doesn't need to be used directly, but it's exposed in case you want to customize behavior. Also note that `options.recurse` must be defined as `true` to recurse into child directories. Alternative, if **any** matcher is a glob pattern with a globstar (double star: `**`), `options.recurse` will automatically be set to `true`.\n\n**Params**\n\n* `fn` **{Function}**: Optionally specify a filter function to use on filepaths. If provided, the function will be called before any matchers are called. `basename` and `file` are exposed to the filter function as arguments, where `file` is an instance of [vinyl](http://github.com/gulpjs/vinyl).\n* `returns` **{Object}**: Returns the [cache](#cache).\n\n**Events**\n\n* `emits`: `ignore` when a file is removed.\n\n**Example**\n\n```js\nresolver.resolveDirs(function(basename, file) {\n  return !/foo/.test(file.path);\n});\n```\n\n## Related projects\n\nYou might also be interested in these projects:\n\n* [global-modules](https://www.npmjs.com/package/global-modules): The directory used by npm for globally installed npm modules. | [homepage](https://github.com/jonschlinkert/global-modules)\n* [global-paths](https://www.npmjs.com/package/global-paths): Returns an array of unique \"global\" directories based on the user's platform and environment. The… [more](https://www.npmjs.com/package/global-paths) | [homepage](https://github.com/jonschlinkert/global-paths)\n* [global-prefix](https://www.npmjs.com/package/global-prefix): Get the npm global path prefix. | [homepage](https://github.com/jonschlinkert/global-prefix)\n* [npm-paths](https://www.npmjs.com/package/npm-paths): Returns an array of unique \"npm\" directories based on the user's platform and environment. | [homepage](https://github.com/jonschlinkert/npm-paths)\n\n## Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/resolve-modules/issues/new).\n\n## Building docs\n\nGenerate readme and API documentation with [verb](https://github.com/verbose/verb):\n\n```sh\n$ npm install verb \u0026\u0026 npm run docs\n```\n\nOr, if [verb](https://github.com/verbose/verb) is installed globally:\n\n```sh\n$ verb\n```\n\n## Running tests\n\nInstall dev dependencies:\n\n```sh\n$ npm install -d \u0026\u0026 npm test\n```\n\n## Author\n\n**Jon Schlinkert**\n\n* [github/jonschlinkert](https://github.com/jonschlinkert)\n* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)\n\n## License\n\nCopyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT license](https://github.com/jonschlinkert/resolve-modules/blob/master/LICENSE).\n\n***\n\n_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on May 19, 2016._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fresolve-modules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fresolve-modules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fresolve-modules/lists"}