Package Exports
- load-plugin
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (load-plugin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
load-plugin

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 π
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 toprocess.cwd()
) β Place to search in;global
(boolean
, optional, defaults to whether global is detected) β Whether to look forname
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 require
ing the first path that exists.
Throws
If require
ing 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
β Ifprefix
is given;$cwd/node_modules/$plugin
β Ifprefix
is given;$modules/$plugin
β Ifprefix
is given and inglobal
mode;$root/$name
;$root/$name.js
;$root/node_modules/$name
;$cwd/node_modules/$name
;$modules/$name
β If inglobal
mode.
Where:
$cwd
β Directory to search from (configurable);$root
β Ancestral directory of$cwd
, with apackage.json
;$name
β Givenname
;$plugin
β Whenprefix
is given,prefix
andname
joined together with a hyphen;$modules
β Location of globally installed npm packages.
License
MIT Β© Titus Wormer