Socket
Socket
Sign inDemoInstall

load-plugin

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

load-plugin

Load a submodule, plugin, or file


Version published
Maintainers
1
Created
Source

load-plugin

Build Coverage Downloads

Load a submodule, plugin, or file. Like Node’s require and require.resolve, but from one or more places, and optionally global too.

Installation

npm:

npm install load-plugin

When bundled for the browser, a small file is included to warn that, when any of the below functions are invoked, the action is unsupported.

Usage

Say we’re in this project (with dependencies installed):

var load = require('load-plugin')

load.resolve('lint', {prefix: 'remark'})
// => '/Users/tilde/projects/oss/load-plugin/node_modules/remark-lint/index.js'

load.resolve('@babel/function-name', {prefix: 'helper'})
// => '/Users/tilde/projects/oss/load-plugin/node_modules/@babel/helper-function-name/index.js'

load.resolve('./index.js', {prefix: 'remark'})
// => '/Users/tilde/projects/oss/load-plugin/index.js'

load.require('lint', {prefix: 'remark'})
// => [Function: lint]

API

loadPlugin(name[, options])

Uses the standard node module loading strategy to require 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
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 nully, 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.

Returns

The results of requireing the first path that exists.

Throws

If requireing an existing path fails, or if no existing path exists.

loadPlugin.resolve(name[, options])

Search for name. Accepts the same parameters as loadPlugin but returns an absolute path for name instead of requiring it, and null if it cannot be found.

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 15 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc