@putout/engine-loader 11.2.0 → 11.4.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/README.md CHANGED
@@ -59,6 +59,22 @@ const plugins = loadPlugins({
59
59
  });
60
60
  ```
61
61
 
62
+ #### `import`
63
+
64
+ You can also use schema like this one:
65
+
66
+ ```
67
+ import:escover/plugin
68
+ ```
69
+
70
+ ```js
71
+ const plugins = loadPlugins({
72
+ pluginNames: [
73
+ 'import:commonjs-putout-plugin',
74
+ ],
75
+ });
76
+ ```
77
+
62
78
  ### loadPluginsAsync
63
79
 
64
80
  Load **ESM** plugins:
@@ -14,7 +14,7 @@ module.exports.createAsyncLoader = (type) => nanomemoize(async (name, load) => {
14
14
  if (name.startsWith('import:')) {
15
15
  const shortName = name.replace('import:', '');
16
16
 
17
- return await cleverLoad([shortName], load);
17
+ return await cleverLoad([require.resolve(shortName)], load);
18
18
  }
19
19
 
20
20
  return await cleverLoad([`@putout/${type}-${name}`, `putout-${type}-${name}`], load);
package/lib/index.js CHANGED
@@ -5,7 +5,7 @@ const {nanomemoize} = require('nano-memoize');
5
5
  const isEnabled = require('./is-enabled');
6
6
  const {loadPlugin} = require('./load');
7
7
  const {createAsyncLoader} = require('./async-loader');
8
- const parsePluginNames = require('./parse-plugin-names');
8
+ const {parsePluginNames} = require('./parse-plugin-names');
9
9
  const parseProcessorNames = require('./parse-processor-names');
10
10
  const parseRules = require('./parse-rules');
11
11
  const validateRules = require('./validate-rules');
@@ -1,9 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ const {basename} = require('path');
4
+
3
5
  const isEnabled = require('./is-enabled');
4
6
  const parseRules = require('./parse-rules');
5
7
  const {createAsyncLoader} = require('./async-loader');
6
- const parsePluginNames = require('./parse-plugin-names');
8
+ const {parsePluginNames} = require('./parse-plugin-names');
7
9
  const validateRules = require('./validate-rules');
8
10
  const validatePlugin = require('./validate-plugin');
9
11
  const {mergeRules} = require('./merge-rules');
@@ -68,7 +70,7 @@ async function loadPlugins({items, loadedRules}) {
68
70
  const [name] = splitRule(rule);
69
71
  const plugin = itemPlugin || loadPluginAsync(name);
70
72
 
71
- enabledRules.push(rule);
73
+ enabledRules.push(parseRuleName(rule));
72
74
  promises.push(plugin);
73
75
  }
74
76
 
@@ -131,3 +133,13 @@ function checkRule(rule) {
131
133
  if (!isString(rule))
132
134
  throw Error(`☝️ Looks like plugin name type is not 'string', but: '${typeof rule}'`);
133
135
  }
136
+
137
+ function parseRuleName(rule) {
138
+ if (rule.startsWith('import:')) {
139
+ const shortName = basename(rule.replace('import:', ''));
140
+
141
+ return shortName.replace('plugin-', '');
142
+ }
143
+
144
+ return rule;
145
+ }
package/lib/load.js CHANGED
@@ -20,6 +20,9 @@ module.exports.loadPlugin = load('plugin');
20
20
  module.exports.loadProcessor = load('processor');
21
21
 
22
22
  function getPath(namespace, type, name) {
23
+ if (name.startsWith('import:'))
24
+ return getModulePath(name.replace('import:', ''));
25
+
23
26
  let [path, customRequire] = getModulePath(`@${namespace}/${type}-${name}`);
24
27
 
25
28
  if (!path)
@@ -4,7 +4,7 @@ const isStr = (a) => typeof a === 'string';
4
4
  const {isArray} = Array;
5
5
  const {entries} = Object;
6
6
 
7
- module.exports = (plugins) => {
7
+ module.exports.parsePluginNames = (plugins) => {
8
8
  const result = [];
9
9
 
10
10
  for (const plugin of plugins) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/engine-loader",
3
- "version": "11.2.0",
3
+ "version": "11.4.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "load plugins and prepare them to run",