Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
364K
increased by2.94%
Maintainers
1
Weekly downloads
 
Created
Source

load-plugin Build Status Coverage Status

Load a submodule / plugin. Accepts a string and looks for files, directories, node modules, optionally global packages too.

Installation

npm:

npm install load-plugin

Usage

Say we have the following project:

project
|-- node_modules
|   |-- load-plugin
|-- package.json
|-- example
    |-- index.js

Where example/index.js looks as follows:

var loadPlugin = require('load-plugin');

console.log(loadPlugin('foo', {prefix: 'bar'}));

And the script is run:

cd example
node index.js

The following paths are checked, in order:

project/node_modules/bar-foo
project/example/node_modules/bar-foo
project/foo
project/foo.js
project/node_modules/foo
project/example/node_modules/foo

And an error is throw because foo isn’t found :worried:

module.js:440
    throw err;
    ^

Error: Cannot find module 'foo'
    at Function.Module._resolveFilename (module.js:438:15)
    at Function.Module._load (module.js:386:25)
    at Module.require (module.js:466:17)
    at require (internal/module.js:20:19)
    at loadPlugin (~/project/node_modules/load-plugin/index.js:126:12)
    at Object.<anonymous> (~/project/example/index.js:3:13)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)

API

loadPlugin(name[, options])

Try to load name. See how ».

Options
  • prefix (string, optional) — Prefix to search for;

  • cwd (string, optional, defaults to process.cwd()) — Place to search in;

  • global (boolean, optional, defaults to whether global is detected) — Whether to look for name in global places. 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.

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.

Algorithm

Looks in the following paths:

  • $root/node_modules/$plugin — If prefix is given;
  • $cwd/node_modules/$plugin — If prefix is given;
  • $modules/$plugin — If prefix is given and in global mode;
  • $root/$name;
  • $root/$name.js;
  • $root/node_modules/$name;
  • $cwd/node_modules/$name;
  • $modules/$name — If in global mode.

Where:

  • $cwd — Directory to search from (configurable);

  • $root — Ancestral directory of $cwd, with a package.json;

  • $name — Given name;

  • $plugin — When prefix is given, prefix and name joined together with a hyphen;

  • $modules — Location of globally installed npm packages.

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 14 Jun 2016

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