load-plugin 2.3.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +41 -12
- package/package.json +11 -7
- package/readme.md +3 -3
package/index.js
CHANGED
|
@@ -3,31 +3,59 @@
|
|
|
3
3
|
var fs = require('fs')
|
|
4
4
|
var path = require('path')
|
|
5
5
|
var resolve = require('resolve-from').silent
|
|
6
|
-
var
|
|
6
|
+
var readNpmConfig = require('libnpmconfig').read
|
|
7
7
|
|
|
8
8
|
module.exports = loadPlugin
|
|
9
9
|
loadPlugin.resolve = resolvePlugin
|
|
10
10
|
|
|
11
11
|
var electron = process.versions.electron !== undefined
|
|
12
|
+
var windows = process.platform === 'win32'
|
|
13
|
+
|
|
12
14
|
var argv = process.argv[1] || /* istanbul ignore next */ ''
|
|
13
15
|
var nvm = process.env.NVM_BIN
|
|
16
|
+
var appData = process.env.APPDATA
|
|
17
|
+
|
|
18
|
+
/* istanbul ignore next */
|
|
19
|
+
var globalsLibrary = windows ? '' : 'lib'
|
|
20
|
+
|
|
21
|
+
var builtinNpmConfig
|
|
22
|
+
|
|
23
|
+
// The prefix config defaults to the location where node is installed.
|
|
24
|
+
// On Windows, this is in a place called `%AppData%`, which we have to
|
|
25
|
+
// pass to `libnpmconfig` explicitly:
|
|
26
|
+
/* istanbul ignore next */
|
|
27
|
+
if (windows && appData) {
|
|
28
|
+
builtinNpmConfig = {prefix: path.join(appData, 'npm')}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var npmPrefix = readNpmConfig(null, builtinNpmConfig).prefix
|
|
32
|
+
|
|
33
|
+
// If there is no prefix defined, use the defaults
|
|
34
|
+
// See: <https://github.com/eush77/npm-prefix/blob/master/index.js>
|
|
35
|
+
/* istanbul ignore next */
|
|
36
|
+
if (!npmPrefix) {
|
|
37
|
+
npmPrefix = windows
|
|
38
|
+
? path.dirname(process.execPath)
|
|
39
|
+
: path.resolve(process.execPath, '../..')
|
|
40
|
+
}
|
|
41
|
+
|
|
14
42
|
var globally = electron || argv.indexOf(npmPrefix) === 0
|
|
15
|
-
var
|
|
16
|
-
var prefix = windows ? /* istanbul ignore next */ '' : 'lib'
|
|
17
|
-
var globals = path.resolve(npmPrefix, prefix, 'node_modules')
|
|
43
|
+
var globals = path.resolve(npmPrefix, globalsLibrary, 'node_modules')
|
|
18
44
|
|
|
19
45
|
// If we’re in Electron, we’re running in a modified Node that cannot really
|
|
20
|
-
// install global node modules.
|
|
21
|
-
//
|
|
46
|
+
// install global node modules.
|
|
47
|
+
// To find the actual modules, the user has to set `prefix` somewhere in an
|
|
48
|
+
// `.npmrc` (which is picked up by `libnpmconfig`).
|
|
22
49
|
// Most people don’t do that, and some use NVM instead to manage different
|
|
23
|
-
// versions of Node.
|
|
24
|
-
// pick up on to try
|
|
50
|
+
// versions of Node.
|
|
51
|
+
// Luckily NVM leaks some environment variables that we can pick up on to try
|
|
52
|
+
// and detect the actual modules.
|
|
25
53
|
/* istanbul ignore next */
|
|
26
54
|
if (electron && nvm && !fs.existsSync(globals)) {
|
|
27
|
-
globals = path.resolve(nvm, '..',
|
|
55
|
+
globals = path.resolve(nvm, '..', globalsLibrary, 'node_modules')
|
|
28
56
|
}
|
|
29
57
|
|
|
30
|
-
// Load the
|
|
58
|
+
// Load the plugin found using `resolvePlugin`.
|
|
31
59
|
function loadPlugin(name, options) {
|
|
32
60
|
return require(resolvePlugin(name, options) || name)
|
|
33
61
|
}
|
|
@@ -80,8 +108,9 @@ function resolvePlugin(name, options) {
|
|
|
80
108
|
if (name.charAt(0) === '@') {
|
|
81
109
|
slash = name.indexOf('/')
|
|
82
110
|
|
|
83
|
-
// Let’s keep the algorithm simple.
|
|
84
|
-
// “valid” scope (I think?).
|
|
111
|
+
// Let’s keep the algorithm simple.
|
|
112
|
+
// No need to care if this is a “valid” scope (I think?).
|
|
113
|
+
// But we do check for the slash.
|
|
85
114
|
if (slash !== -1) {
|
|
86
115
|
scope = name.slice(0, slash + 1)
|
|
87
116
|
name = name.slice(slash + 1)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "load-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Load a submodule, plugin, or file",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
],
|
|
12
12
|
"repository": "wooorm/load-plugin",
|
|
13
13
|
"bugs": "https://github.com/wooorm/load-plugin/issues",
|
|
14
|
+
"funding": {
|
|
15
|
+
"type": "github",
|
|
16
|
+
"url": "https://github.com/sponsors/wooorm"
|
|
17
|
+
},
|
|
14
18
|
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
|
15
19
|
"contributors": [
|
|
16
20
|
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
|
@@ -22,17 +26,17 @@
|
|
|
22
26
|
"index.js"
|
|
23
27
|
],
|
|
24
28
|
"dependencies": {
|
|
25
|
-
"
|
|
29
|
+
"libnpmconfig": "^1.0.0",
|
|
26
30
|
"resolve-from": "^5.0.0"
|
|
27
31
|
},
|
|
28
32
|
"devDependencies": {
|
|
29
|
-
"nyc": "^
|
|
30
|
-
"prettier": "^1.
|
|
31
|
-
"remark-cli": "^
|
|
33
|
+
"nyc": "^15.0.0",
|
|
34
|
+
"prettier": "^1.0.0",
|
|
35
|
+
"remark-cli": "^7.0.0",
|
|
32
36
|
"remark-lint": "^6.0.0",
|
|
33
|
-
"remark-preset-wooorm": "^
|
|
37
|
+
"remark-preset-wooorm": "^6.0.0",
|
|
34
38
|
"tape": "^4.0.0",
|
|
35
|
-
"xo": "^0.
|
|
39
|
+
"xo": "^0.25.0"
|
|
36
40
|
},
|
|
37
41
|
"scripts": {
|
|
38
42
|
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
|
package/readme.md
CHANGED
|
@@ -8,18 +8,18 @@ Load a submodule, plugin, or file.
|
|
|
8
8
|
Like Node’s `require` and `require.resolve`, but from one or more places, and
|
|
9
9
|
optionally global too.
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Install
|
|
12
12
|
|
|
13
13
|
[npm][]:
|
|
14
14
|
|
|
15
|
-
```
|
|
15
|
+
```sh
|
|
16
16
|
npm install load-plugin
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
When bundled for the browser, a small [file][browser] is included to warn that,
|
|
20
20
|
when any of the below functions are invoked, the action is unsupported.
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## Use
|
|
23
23
|
|
|
24
24
|
Say we’re in this project (with dependencies installed):
|
|
25
25
|
|