load-plugin 2.2.2 → 2.3.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 CHANGED
@@ -16,34 +16,33 @@ var windows = process.platform === 'win32'
16
16
  var prefix = windows ? /* istanbul ignore next */ '' : 'lib'
17
17
  var globals = path.resolve(npmPrefix, prefix, 'node_modules')
18
18
 
19
- /* istanbul ignore next - If we’re in Electron, we’re running in a modified
20
- * Node that cannot really install global node modules. To find the actual
21
- * modules, the user has to either set `prefix` in their `.npmrc` (which is
22
- * picked up by `npm-prefix`). Most people don’t do that, and some use NVM
23
- * instead to manage different versions of Node. Luckily NVM leaks some
24
- * environment variables that we can pick up on to try and detect the actual
25
- * modules. */
19
+ // If we’re in Electron, we’re running in a modified Node that cannot really
20
+ // install global node modules. To find the actual modules, the user has to
21
+ // either set `prefix` in their `.npmrc` (which is picked up by `npm-prefix`).
22
+ // Most people don’t do that, and some use NVM instead to manage different
23
+ // versions of Node. Luckily NVM leaks some environment variables that we can
24
+ // pick up on to try and detect the actual modules.
25
+ /* istanbul ignore next */
26
26
  if (electron && nvm && !fs.existsSync(globals)) {
27
27
  globals = path.resolve(nvm, '..', prefix, 'node_modules')
28
28
  }
29
29
 
30
- /* Load the plug-in found using `resolvePlugin`. */
30
+ // Load the plug-in found using `resolvePlugin`.
31
31
  function loadPlugin(name, options) {
32
32
  return require(resolvePlugin(name, options) || name)
33
33
  }
34
34
 
35
- /* Find a plugin.
36
- *
37
- * See also:
38
- * <https://docs.npmjs.com/files/folders#node-modules>
39
- * <https://github.com/sindresorhus/resolve-from>
40
- *
41
- * Uses the standard node module loading strategy to find $name
42
- * in each given `cwd` (and optionally the global node_modules
43
- * directory).
44
- *
45
- * If a prefix is given and $name is not a path, `$prefix-$name`
46
- * is also searched (preferring these over non-prefixed modules). */
35
+ // Find a plugin.
36
+ //
37
+ // See also:
38
+ // <https://docs.npmjs.com/files/folders#node-modules>
39
+ // <https://github.com/sindresorhus/resolve-from>
40
+ //
41
+ // Uses the standard node module loading strategy to find $name in each given
42
+ // `cwd` (and optionally the global `node_modules` directory).
43
+ //
44
+ // If a prefix is given and $name is not a path, `$prefix-$name` is also
45
+ // searched (preferring these over non-prefixed modules).
47
46
  function resolvePlugin(name, options) {
48
47
  var settings = options || {}
49
48
  var prefix = settings.prefix
@@ -53,6 +52,8 @@ function resolvePlugin(name, options) {
53
52
  var length
54
53
  var index
55
54
  var plugin
55
+ var slash
56
+ var scope = ''
56
57
 
57
58
  if (cwd && typeof cwd === 'object') {
58
59
  sources = cwd.concat()
@@ -60,19 +61,33 @@ function resolvePlugin(name, options) {
60
61
  sources = [cwd || process.cwd()]
61
62
  }
62
63
 
63
- /* Non-path. */
64
- if (name.indexOf(path.sep) === -1 && name.charAt(0) !== '.') {
64
+ // Non-path.
65
+ if (name.charAt(0) !== '.') {
65
66
  if (settings.global == null ? globally : settings.global) {
66
67
  sources.push(globals)
67
68
  }
68
69
 
69
- /* Unprefix module. */
70
+ // Unprefix module.
70
71
  if (prefix) {
71
72
  prefix = prefix.charAt(prefix.length - 1) === '-' ? prefix : prefix + '-'
72
73
 
74
+ // Scope?
75
+ if (name.charAt(0) === '@') {
76
+ slash = name.indexOf('/')
77
+
78
+ // Let’s keep the algorithm simple. No need to care if this is a
79
+ // “valid” scope (I think?). But we do check for the slash.
80
+ if (slash !== -1) {
81
+ scope = name.slice(0, slash + 1)
82
+ name = name.slice(slash + 1)
83
+ }
84
+ }
85
+
73
86
  if (name.slice(0, prefix.length) !== prefix) {
74
- plugin = prefix + name
87
+ plugin = scope + prefix + name
75
88
  }
89
+
90
+ name = scope + name
76
91
  }
77
92
  }
78
93
 
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "load-plugin",
3
- "version": "2.2.2",
3
+ "version": "2.3.0",
4
4
  "description": "Load a submodule, plugin, or file",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -26,16 +26,16 @@
26
26
  "resolve-from": "^4.0.0"
27
27
  },
28
28
  "devDependencies": {
29
- "nyc": "^11.0.0",
29
+ "nyc": "^13.0.0",
30
30
  "prettier": "^1.12.0",
31
- "remark-cli": "^5.0.0",
31
+ "remark-cli": "^6.0.0",
32
32
  "remark-lint": "^6.0.0",
33
33
  "remark-preset-wooorm": "^4.0.0",
34
34
  "tape": "^4.0.0",
35
- "xo": "^0.20.0"
35
+ "xo": "^0.23.0"
36
36
  },
37
37
  "scripts": {
38
- "format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
38
+ "format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
39
39
  "test-api": "node test",
40
40
  "test-coverage": "nyc --reporter lcov tape test/index.js",
41
41
  "test": "npm run format && npm run test-coverage"
@@ -52,9 +52,6 @@
52
52
  "prettier": true,
53
53
  "esnext": false,
54
54
  "rules": {
55
- "import/no-dynamic-require": "off",
56
- "no-var": "off",
57
- "prefer-arrow-callback": "off",
58
55
  "no-eq-null": "off",
59
56
  "eqeqeq": "off"
60
57
  }
package/readme.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # load-plugin [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]
2
2
 
3
- Load a submodule, plugin, or file. Like Node’s `require` and
4
- `require.resolve`, but from one or more places, and optionally
5
- global too.
3
+ Load a submodule, plugin, or file.
4
+ Like Node’s `require` and `require.resolve`, but from one or more places, and
5
+ optionally global too.
6
6
 
7
7
  ## Installation
8
8
 
@@ -12,9 +12,8 @@ global too.
12
12
  npm install load-plugin
13
13
  ```
14
14
 
15
- When bundled for the browser, a small [file][browser] is included to
16
- warn that, when any of the below functions are invoked, the action is
17
- unsupported.
15
+ When bundled for the browser, a small [file][browser] is included to warn that,
16
+ when any of the below functions are invoked, the action is unsupported.
18
17
 
19
18
  ## Usage
20
19
 
@@ -26,6 +25,9 @@ var load = require('load-plugin')
26
25
  load.resolve('lint', {prefix: 'remark'})
27
26
  // => '/Users/tilde/projects/oss/load-plugin/node_modules/remark-lint/index.js'
28
27
 
28
+ load.resolve('@babel/function-name', {prefix: 'helper'})
29
+ // => '/Users/tilde/projects/oss/load-plugin/node_modules/@babel/helper-function-name/index.js'
30
+
29
31
  load.resolve('./index.js', {prefix: 'remark'})
30
32
  // => '/Users/tilde/projects/oss/load-plugin/index.js'
31
33
 
@@ -37,12 +39,13 @@ load.require('lint', {prefix: 'remark'})
37
39
 
38
40
  ### `loadPlugin(name[, options])`
39
41
 
40
- Uses the standard node module loading strategy to require `name`
41
- in each given `cwd` (and optionally the global `node_modules`
42
- directory).
42
+ Uses the standard node module loading strategy to require `name` in each given
43
+ `cwd` (and optionally the global `node_modules` directory).
43
44
 
44
- If a prefix is given and `name` is not a path, `prefix-name`
45
- is also searched (preferring these over non-prefixed modules).
45
+ If a prefix is given and `name` is not a path, `prefix-name` is also searched
46
+ (preferring these over non-prefixed modules).
47
+ If name starts with a scope (`@scope/name`), the prefix is applied after it:
48
+ `@scope/prefix-name`.
46
49
 
47
50
  ##### `options`
48
51
 
@@ -58,9 +61,10 @@ Place or places to search from (`string`, `Array.<string>`, default:
58
61
  ###### `options.global`
59
62
 
60
63
  Whether to look for `name` in [global places][global] (`boolean`, optional,
61
- defaults to whether global is detected). If this is nully, `load-plugin`
62
- will detect if it’s currently running in global mode: either because it’s
63
- in Electron, or because a globally installed package is running it.
64
+ defaults to whether global is detected).
65
+ If this is nully, `load-plugin` will detect if it’s currently running in global
66
+ mode: either because it’s in Electron, or because a globally installed package
67
+ is running it.
64
68
 
65
69
  Note: Electron runs its own version of Node instead of your system Node.
66
70
  That means global packages cannot be found, unless you’ve [set-up][] a [`prefix`
@@ -76,9 +80,10 @@ If `require`ing an existing path fails, or if no existing path exists.
76
80
 
77
81
  ### `loadPlugin.resolve(name[, options])`
78
82
 
79
- Search for `name`. Accepts the same parameters as [`loadPlugin`][load-plugin]
80
- but returns an absolute path for `name` instead of requiring it,
81
- and `null` if it cannot be found.
83
+ Search for `name`.
84
+ Accepts the same parameters as [`loadPlugin`][load-plugin] but returns an
85
+ absolute path for `name` instead of requiring it, and `null` if it cannot be
86
+ found.
82
87
 
83
88
  ## License
84
89
 
@@ -96,7 +101,7 @@ and `null` if it cannot be found.
96
101
 
97
102
  [npm]: https://docs.npmjs.com/cli/install
98
103
 
99
- [license]: LICENSE
104
+ [license]: license
100
105
 
101
106
  [author]: http://wooorm.com
102
107