{"id":15413528,"url":"https://github.com/wooorm/load-plugin","last_synced_at":"2025-04-14T16:23:10.581Z","repository":{"id":8785289,"uuid":"59748623","full_name":"wooorm/load-plugin","owner":"wooorm","description":"Load a submodule / plugin","archived":false,"fork":false,"pushed_at":"2024-04-12T12:41:04.000Z","size":129,"stargazers_count":15,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-14T16:08:59.646Z","etag":null,"topics":["global","load","plugin","prefix","require","resolve"],"latest_commit_sha":null,"homepage":"","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/wooorm.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":"funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"wooorm"}},"created_at":"2016-05-26T12:31:19.000Z","updated_at":"2024-04-16T14:53:45.798Z","dependencies_parsed_at":"2024-04-16T15:04:05.112Z","dependency_job_id":null,"html_url":"https://github.com/wooorm/load-plugin","commit_stats":{"total_commits":126,"total_committers":4,"mean_commits":31.5,"dds":0.0714285714285714,"last_synced_commit":"916a27549526379333f7a88dd2c79c48a940e804"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fload-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fload-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fload-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fload-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wooorm","download_url":"https://codeload.github.com/wooorm/load-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248914587,"owners_count":21182442,"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","load","plugin","prefix","require","resolve"],"created_at":"2024-10-01T16:57:37.258Z","updated_at":"2025-04-14T16:23:10.559Z","avatar_url":"https://github.com/wooorm.png","language":"JavaScript","readme":"# load-plugin\n\n[![Build][badge-build-image]][badge-build-url]\n[![Coverage][badge-coverage-image]][badge-coverage-url]\n[![Downloads][badge-downloads-image]][badge-downloads-url]\n\nLoad a submodule, plugin, or file.\n\n## Contents\n\n* [What is this?](#what-is-this)\n* [When to use this?](#when-to-use-this)\n* [Install](#install)\n* [Use](#use)\n* [API](#api)\n  * [`loadPlugin(name[, options])`](#loadpluginname-options)\n  * [`resolvePlugin(name[, options])`](#resolvepluginname-options)\n  * [`LoadOptions`](#loadoptions)\n  * [`ResolveOptions`](#resolveoptions)\n* [Compatibility](#compatibility)\n* [Security](#security)\n* [Contribute](#contribute)\n* [License](#license)\n\n## What is this?\n\nThis package is useful when you want to load plugins.\nIt resolves things like Node.js does,\nbut supports a prefix (when given a prefix `remark` and the user provided value\n`gfm` it can find `remark-gfm`),\ncan load from several places,\nand optionally global too.\n\n## When to use this?\n\nThis package is particularly useful when you want users to configure something\nwith plugins.\nOne example is `remark-cli` which can load remark plugins from configuration\nfiles.\n\n## Install\n\nThis package is [ESM only][github-gist-esm].\nIn Node.js (version 16+),\ninstall with [npm][npm-install]:\n\n```sh\nnpm install load-plugin\n```\n\n## Use\n\nSay we’re in this project (with dependencies installed):\n\n```js\nimport {loadPlugin, resolvePlugin} from 'load-plugin'\n\nconsole.log(await resolvePlugin('lint', {prefix: 'remark'}))\n// =\u003e 'file:///Users/tilde/Projects/oss/load-plugin/node_modules/remark-lint/index.js'\n\nconsole.log(\n  await resolvePlugin('validator-identifier', {prefix: '@babel/helper'})\n)\n// =\u003e 'file:///Users/tilde/Projects/oss/load-plugin/node_modules/@babel/helper-validator-identifier/lib/index.js'\n\nconsole.log(await resolvePlugin('./index.js', {prefix: 'remark'}))\n// =\u003e 'file:///Users/tilde/Projects/oss/load-plugin/index.js'\n\nconsole.log(await loadPlugin('lint', {prefix: 'remark'}))\n// =\u003e [Function: remarkLint]\n```\n\n## API\n\nThis package exports the identifiers\n[`loadPlugin`][api-load-plugin] and [`resolvePlugin`][api-resolve-plugin].\nThere is no default export.\n\nIt exports the [TypeScript][] types\n[`LoadOptions`][api-load-options] and [`ResolveOptions`][api-resolve-options].\n\n### `loadPlugin(name[, options])`\n\nImport `name` from `from` (and optionally the global `node_modules` directory).\n\nUses the Node.js [resolution algorithm][nodejs-resolution-algo] (through\n[`import-meta-resolve`][github-import-meta-resolve]) to resolve CJS and ESM\npackages and files.\n\nIf a `prefix` is given and `name` is not a path,\n`$prefix-$name` is also searched (preferring these over non-prefixed\nmodules).\nIf `name` starts with a scope (`@scope/name`),\nthe prefix is applied after it: `@scope/$prefix-name`.\n\n###### Parameters\n\n* `name` (`string`)\n  — specifier\n* `options` ([`LoadOptions`][api-load-options], optional)\n  — configuration\n\n###### Returns\n\nPromise to a whole module or specific export (`Promise\u003cunknown\u003e`).\n\n### `resolvePlugin(name[, options])`\n\nResolve `name` from `from`.\n\n###### Parameters\n\n* `name` (`string`)\n  — specifier\n* `options` ([`ResolveOptions`][api-resolve-options], optional)\n  — configuration\n\n###### Returns\n\nPromise to a file URL (`Promise\u003cstring\u003e`).\n\n### `LoadOptions`\n\nConfiguration for `loadPlugin` (TypeScript type).\n\nThis type extends `ResolveOptions` and adds:\n\n###### Fields\n\n* `key` (`boolean` or `string`, default: `'default'`)\n  — identifier to take from the exports;\n  for example when given `'x'`,\n  the value of `export const x = 1` will be returned;\n  when given `'default'`,\n  the value of `export default …` is used,\n  and when `false` the whole module object is returned\n\n### `ResolveOptions`\n\nConfiguration for `resolvePlugin` (TypeScript type).\n\n###### Fields\n\n* `from` (`Array\u003cURL | string\u003e | URL | string`, optional)\n  — place or places to search from;\n  defaults to the current working directory\n* `global` (`boolean`, default: whether global is detected)\n  — whether to look for `name` in [global places][npm-node-modules];\n  if this is nullish,\n  `load-plugin` will detect if it’s currently running in global mode: either\n  because it’s in Electron or because a globally installed package is running\n  it;\n  note that Electron runs its own version of Node instead of your system Node,\n  meaning global packages cannot be found,\n  unless you’ve set-up a [`prefix`][npm-prefix] in your `.npmrc` or are using\n  [nvm][github-nvm] to manage your system node\n* `prefix` (`string`, optional)\n  — prefix to search for\n\n## Compatibility\n\nThis projects is compatible with maintained versions of Node.js.\n\nWhen we cut a new major release,\nwe drop support for unmaintained versions of Node.\nThis means we try to keep the current release line,\n`load-plugin@6`,\ncompatible with Node.js 16.\n\n## Security\n\nThis package reads the file system and imports things into Node.js.\n\n## Contribute\n\nYes please!\nSee [How to Contribute to Open Source][open-source-guide-contribute].\n\n## License\n\n[MIT][file-license] © [Titus Wormer][wooorm]\n\n\u003c!-- Definitions --\u003e\n\n[api-load-plugin]: #loadpluginname-options\n\n[api-load-options]: #loadoptions\n\n[api-resolve-plugin]: #resolvepluginname-options\n\n[api-resolve-options]: #resolveoptions\n\n[badge-build-image]: https://github.com/wooorm/load-plugin/workflows/main/badge.svg\n\n[badge-build-url]: https://github.com/wooorm/load-plugin/actions\n\n[badge-coverage-image]: https://img.shields.io/codecov/c/github/wooorm/load-plugin.svg\n\n[badge-coverage-url]: https://codecov.io/github/wooorm/load-plugin\n\n[badge-downloads-image]: https://img.shields.io/npm/dm/load-plugin.svg\n\n[badge-downloads-url]: https://www.npmjs.com/package/load-plugin\n\n[file-license]: license\n\n[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[github-import-meta-resolve]: https://github.com/wooorm/import-meta-resolve\n\n[github-nvm]: https://github.com/nvm-sh/nvm\n\n[nodejs-resolution-algo]: https://nodejs.org/api/esm.html#esm_resolution_algorithm\n\n[npm-install]: https://docs.npmjs.com/cli/install\n\n[npm-node-modules]: https://docs.npmjs.com/cli/v10/configuring-npm/folders#node-modules\n\n[npm-prefix]: https://docs.npmjs.com/cli/v10/using-npm/config\n\n[open-source-guide-contribute]: https://opensource.guide/how-to-contribute/\n\n[typescript]: https://www.typescriptlang.org\n\n[wooorm]: https://wooorm.com\n","funding_links":["https://github.com/sponsors/wooorm"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fload-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwooorm%2Fload-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fload-plugin/lists"}