@putout/engine-loader 4.9.1 → 4.10.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/lib/load.js CHANGED
@@ -1,10 +1,20 @@
1
1
  'use strict';
2
2
 
3
+ const {createRequire} = require('module');
4
+ const tryCatch = require('try-catch');
5
+
3
6
  const wrapPlugin = require('./wrap-plugin');
4
- const getModulePath = require('./get-module-path');
5
7
 
8
+ // yarn PnP API
9
+ // https://yarnpkg.com/advanced/rulebook#modules-shouldnt-hardcode-node_modules-paths-to-access-other-modules
10
+ const customRequire = createRequire(__filename);
6
11
  const bigFirst = (a) => `${a[0].toUpperCase()}${a.slice(1)}`;
7
12
 
13
+ const getModulePath = (name) => {
14
+ const [, path] = tryCatch(customRequire.resolve, name);
15
+ return path;
16
+ };
17
+
8
18
  function getPath(namespace, type, name) {
9
19
  let path = getModulePath(`@${namespace}/${type}-${name}`);
10
20
 
@@ -26,7 +36,7 @@ const load = (type) => ({name, namespace}) => {
26
36
  if (!pluginPath)
27
37
  throw Error(`${bigFirst(type)} "${namespace}-${type}-${name}" could not be found!`);
28
38
 
29
- return require(pluginPath);
39
+ return customRequire(pluginPath);
30
40
  };
31
41
 
32
42
  module.exports.loadPlugin = load('plugin');
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ const tryCatch = require('try-catch');
3
4
  const {print} = require('@putout/engine-parser');
5
+
4
6
  const getPositions = require('./get-positions-by-diff');
5
- const getModulePath = require('./get-module-path');
6
7
 
7
8
  const babelTransform = require('./transforms/babel');
8
9
  const jscodeshiftTransform = require('./transforms/jscodeshift');
@@ -11,6 +12,11 @@ const getMessage = (a) => a
11
12
  .replace(/@babel\/plugin-|babel-plugin-/, '')
12
13
  .replace(/-/g, ' ');
13
14
 
15
+ const getModulePath = (name) => {
16
+ const [, path] = tryCatch(require.resolve, name);
17
+ return path;
18
+ };
19
+
14
20
  module.exports = (name, namespace) => {
15
21
  const message = getMessage(name);
16
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/engine-loader",
3
- "version": "4.9.1",
3
+ "version": "4.10.0",
4
4
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
5
  "description": "load plugins and prepare them to run",
6
6
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-loader",
@@ -42,6 +42,7 @@
42
42
  "@putout/plugin-convert-commonjs-to-esm": "*",
43
43
  "@putout/plugin-remove-unused-variables": "*",
44
44
  "@putout/processor-markdown": "*",
45
+ "@putout/processor-javascript": "*",
45
46
  "c8": "^7.5.0",
46
47
  "eslint": "^8.0.1",
47
48
  "eslint-plugin-node": "^11.0.0",
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- const tryCatch = require('try-catch');
4
-
5
- module.exports = (name) => {
6
- const [, path] = tryCatch(require.resolve, name);
7
- return path;
8
- };
9
-