@putout/engine-loader 7.0.0 → 7.1.1

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
@@ -65,13 +65,14 @@ const plugins = loadPlugins({
65
65
 
66
66
  ```js
67
67
  const {loadProcessors} = require('@putout/engine-loader');
68
+ const optionalLoad = async (a) => await import(a);
68
69
 
69
70
  const plugins = await loadProcessorsAsync({
70
71
  processors: [
71
72
  ['javascript', 'on'],
72
73
  ['markdown', 'off'],
73
74
  ],
74
- });
75
+ }, optionalLoad);
75
76
  ```
76
77
 
77
78
  ### createAsyncLoader
@@ -84,6 +85,11 @@ const {loadProcessor} = createAsyncLoader('processor');
84
85
 
85
86
  await loadProcessors('markdown');
86
87
  // loads @putout/processor-markdown
88
+
89
+ await loadProcess('json', () => {
90
+ return Promise.resolve(`will be called instead of 'import'`);
91
+ });
92
+ // loads @putout/processor-json using custom loader
87
93
  ```
88
94
 
89
95
  ## License
@@ -1,19 +1,19 @@
1
1
  'use strict';
2
2
 
3
3
  const tryToCatch = require('try-to-catch');
4
- const {simpleImportDefault} = require('./simple-import');
4
+ const {simpleImport} = require('./simple-import');
5
5
 
6
6
  const {assign} = Object;
7
7
  const stub = () => () => {};
8
8
 
9
- module.exports.createAsyncLoader = (type) => async (name) => {
9
+ module.exports.createAsyncLoader = (type) => async (name, load) => {
10
10
  if (name === 'none')
11
11
  return stub();
12
12
 
13
13
  const [e, reporter] = await cleverLoad([
14
14
  `@putout/${type}-${name}`,
15
15
  `putout-${type}-${name}`,
16
- ]);
16
+ ], load);
17
17
 
18
18
  if (e)
19
19
  throw e;
@@ -21,12 +21,12 @@ module.exports.createAsyncLoader = (type) => async (name) => {
21
21
  return reporter;
22
22
  };
23
23
 
24
- async function cleverLoad(names) {
24
+ async function cleverLoad(names, load = simpleImport) {
25
25
  let e;
26
26
  let reporter;
27
27
 
28
28
  for (const name of names) {
29
- [e, reporter] = await tryToCatch(simpleImportDefault, name);
29
+ [e, reporter] = await tryToCatch(load, name);
30
30
 
31
31
  if (!e)
32
32
  return [null, reporter];
@@ -47,3 +47,4 @@ async function cleverLoad(names) {
47
47
 
48
48
  return [e];
49
49
  }
50
+
package/lib/index.js CHANGED
@@ -38,7 +38,7 @@ const mergeRules = ([rule, plugin], rules) => {
38
38
  };
39
39
  };
40
40
 
41
- module.exports.loadProcessorsAsync = memo(async (options) => {
41
+ module.exports.loadProcessorsAsync = memo(async (options, load) => {
42
42
  check(options);
43
43
 
44
44
  const {
@@ -56,7 +56,7 @@ module.exports.loadProcessorsAsync = memo(async (options) => {
56
56
  continue;
57
57
  }
58
58
 
59
- list.push(loadProcessor(name));
59
+ list.push(loadProcessor(name, load));
60
60
  }
61
61
 
62
62
  return await Promise.all(list);
@@ -1,5 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  // How in other way to mock import using mock require in CommonJS?
4
- module.exports.simpleImportDefault = async (url) => (await import(url)).default;
4
+ module.exports.simpleImport = async (url) => {
5
+ const result = await import(url);
6
+ return result.default || result;
7
+ };
5
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/engine-loader",
3
- "version": "7.0.0",
3
+ "version": "7.1.1",
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",
@@ -37,9 +37,11 @@
37
37
  "putout-engine",
38
38
  "loader"
39
39
  ],
40
+ "peerDependencies": {
41
+ "putout": "*"
42
+ },
40
43
  "devDependencies": {
41
44
  "@babel/plugin-codemod-object-assign-to-object-spread": "^7.7.4",
42
- "@cloudcmd/stub": "^3.0.0",
43
45
  "@putout/formatter-progress": "*",
44
46
  "@putout/plugin-convert-commonjs-to-esm": "*",
45
47
  "@putout/plugin-remove-unused-variables": "*",
@@ -51,7 +53,7 @@
51
53
  "eslint-plugin-putout": "^15.0.0",
52
54
  "estrace": "*",
53
55
  "just-camel-case": "^4.0.2",
54
- "lerna": "^4.0.0",
56
+ "lerna": "^5.0.0",
55
57
  "madrun": "^9.0.0",
56
58
  "mock-require": "^3.0.3",
57
59
  "montag": "^1.0.0",