@stackline/load-plugin
v1.0.4
Published
Resolve and load plugins, submodules, and files with the load-plugin 5 Promise API
Maintainers
Readme
@stackline/load-plugin
Resolve and load plugins, submodules, and files with the load-plugin 5 Promise API.
Documentation | npm | Issues | Repository
Current package version: 1.0.4
Why this package?
Maintained MIT-licensed fork of [email protected]. Preserves its cwd, prefix, global, and key options and Promise API. Requires Node.js 20.19+ on the 20.x line, or Node.js 22.12+.
Uses @npmcli/[email protected] and [email protected] to remove deprecated glob dependencies and the old resolver's fs.Stats warning. Missing-file and directory errors retain the previous fallback behavior. Global prefix detection does not load npm configuration or alter the host environment.
Development: npm ci, npm run build, npm test, npm run lint. The upstream integration tests and global-prefix/fallback regressions run locally; declarations are generated from the preserved public JSDoc API.
Load submodules, plugins, or files.
What is this?
This package is useful when you want to load plugins.
It resolves things like Node.js does, but supports a prefix (e.g., when given a
prefix remark and the user provided value gfm, it can find remark-gfm),
can load from several places, and optionally global too.
When to use this?
This package is particularly useful when you want users to configure something
with plugins.
One example is remark-cli which can load remark plugins from configuration
files.
Compatibility
| Item | Value |
| --- | --- |
| Package | @stackline/[email protected] |
| Supported Node.js | ^20.19.0 || >=22.12.0 |
| Module entry | index.js (ES modules) |
| Runtime dependencies | 2 direct dependencies |
| Types | index.d.ts |
The supported Node.js versions for this fork are declared in package.json.
This fork supports Node.js 20.19+ on the 20.x line, and Node.js 22.12+.
It also works in Deno and modern browsers.
Installation
npm install @stackline/load-pluginThis package is ESM only. In Node.js (20.19+ on the 20.x line, or 22.12+), install with npm:
npm install @stackline/load-pluginUsage
import {resolvePlugin} from '@stackline/load-plugin';
console.log(await resolvePlugin('./index.js', { cwd: process.cwd() }));Say we’re in this project (with dependencies installed):
import {loadPlugin, resolvePlugin} from '@stackline/load-plugin'
console.log(await resolvePlugin('lint', {prefix: 'remark'}))
// => '/Users/tilde/projects/oss/load-plugin/node_modules/remark-lint/index.js'
console.log(await resolvePlugin('validator-identifier', {prefix: '@babel/helper'}))
// => '/Users/tilde/Projects/oss/load-plugin/node_modules/@babel/helper-validator-identifier/lib/index.js'
console.log(await resolvePlugin('./index.js', {prefix: 'remark'}))
// => '/Users/tilde/projects/oss/load-plugin/index.js'
console.log(await loadPlugin('lint', {prefix: 'remark'}))
// => [Function: remarkLint]Security
Resolved plugins execute JavaScript when loaded. Use trusted plugin names and configuration; global-prefix detection itself does not load npm configuration or change the host environment.
API Surface
This package exports the identifiers loadPlugin and resolvePlugin.
There is no default export.
loadPlugin(name[, options])
Uses Node’s resolution algorithm (through
import-meta-resolve) to load CJS and ESM packages and
files to import name in each given cwd (and optionally the global
node_modules directory).
If a prefix is given and name is not a path, $prefix-$name is also
searched (preferring these over non-prefixed modules).
If name starts with a scope (@scope/name), the prefix is applied after it:
@scope/$prefix-name.
options
Configuration (optional).
options.prefix
Prefix to search for (string, optional).
options.cwd
Place or places to search from (string, Array<string>, default:
process.cwd()).
options.global
Whether to look for name in global places (boolean, optional,
defaults to whether global is detected).
If this is nullish, load-plugin will detect if it’s currently running in
global mode: either because it’s in Electron, or because a globally installed
package is running it.
Note: Electron runs its own version of Node instead of your system Node.
That means global packages cannot be found, unless you’ve set-up a prefix
in your .npmrc or are using nvm to manage your system node.
options.key
Identifier to take from the exports (string or false, default: 'default').
For example when given 'whatever', the value of export const whatever = 1
will be returned, when given 'default', the value of export default … is
used, and when false the whole module object is returned.
Returns
Promise yielding the results of importing the first path that exists
(Promise<unknown>).
The promise rejects if importing an existing path fails, or if no existing
path exists.
resolvePlugin(name[, options])
Search for name.
Accepts the same parameters as loadPlugin (except key) but
returns a promise resolving to an absolute URL (string) for name instead of
importing it.
Throws if name cannot be found.
Types
This package is fully typed with TypeScript.
It exports the additional types ResolveOptions and LoadOptions.
Local Development
Clone the repository and run the following commands from its root:
npm ci
npm run build
npm test
npm run lintThe retained upstream development notes below include historical tooling; the commands above are the maintained package checks.
Contribute
Yes please! See How to Contribute to Open Source.
Release Checklist
- Update the package version, lockfile, generated version fields, and changelog together.
- Run the development checks above and audit both
npm auditandnpm audit --omit=dev. - Use the GitHub publish workflow with its
Prodenvironment to publish the exact CI tarball. - Verify public npm bytes, package identity, provenance, and the immutable GitHub release evidence.
License
MIT. Original copyright notices and upstream attribution are retained.
See NOTICE for retained attribution.
Dependency maintenance for this release is documented in DEPENDENCY_UPDATES.md. import-meta-resolve and the development plugin remark-lint retain their original import keys and use exact verified Stackline aliases.
Credits and original authors
- Original project: load-plugin.
- Titus Wormer.
- Copyright (c) 2016 Titus Wormer [email protected].
- Stackline modifications Copyright 2026 Stackline contributors.
- Stackline maintenance: Alexandro Paixao Marques and Stackline contributors.
Original copyright, license notices and contributor acknowledgements remain part of this distribution. Stackline maintenance does not replace authorship of the original work.
Community and Links
Use this repository's issue tracker for reproducible bugs and feature requests. Join r/Stackline for examples, usage questions and release discussions.
