@putout/plugin-nodejs 20.2.0 → 20.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/README.md CHANGED
@@ -33,7 +33,7 @@ npm i putout @putout/plugin-nodejs -D
33
33
  - ✅ [group-require-by-id](#group-require-by-id);
34
34
  - ✅ [remove-process-exit](#remove-process-exit);
35
35
  - ✅ [remove-useless-promisify](#remove-useless-promisify);
36
- - ✅ [remove-useless-process-exit](#remove-useless-process-exit);
36
+ - ✅ [remove-top-level-process-exit](#remove-top-level-process-exit);
37
37
  - ✅ [remove-useless-strict-mode](#remove-useless-strict-mode);
38
38
  - ✅ [remove-illegal-strict-mode](#remove-useless-strict-mode);
39
39
 
@@ -71,7 +71,8 @@ npm i putout @putout/plugin-nodejs -D
71
71
  "nodejs/remove-process-exit": "on",
72
72
  "nodejs/remove-useless-strict-mode": "on",
73
73
  "nodejs/remove-illegal-strict-mode": "on",
74
- "nodejs/remove-useless-promisify": "on"
74
+ "nodejs/remove-useless-promisify": "on",
75
+ "nodejs/remove-top-level-process-exit": "on"
75
76
  }
76
77
  }
77
78
  ```
@@ -224,10 +225,11 @@ In most cases `process.exit()` is called from `bin` directory, if not - disable
224
225
  -process.exit();
225
226
  ```
226
227
 
227
- ## remove-useless-process-exit
228
+ ## remove-top-level-process-exit
228
229
 
229
- Top level `process.exit()` have no sense.
230
- Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/3aa8331269e49266d60914984027f9ed/6866eb78a0c1dd7f6e1f1e722c7c581b92f3b477).
230
+ Top-level `process.exit()` has no sense (except debugging).
231
+
232
+ Checkout in ✅[**Putout Editor**](https://putout.cloudcmd.io/#/gist/3aa8331269e49266d60914984027f9ed/9909ac2c07534299f64fee5ebf95cfc37ef04f11).
231
233
 
232
234
  ```diff
233
235
  -process.exit();
@@ -1,4 +1,13 @@
1
- import {template, operator} from 'putout';
1
+ import {
2
+ template,
3
+ operator,
4
+ types,
5
+ } from 'putout';
6
+
7
+ const {
8
+ isProgram,
9
+ isCallExpression,
10
+ } = types;
2
11
 
3
12
  const {
4
13
  getPathAfterImports,
@@ -24,14 +33,13 @@ export const fix = ({scope}) => {
24
33
  export const include = () => [
25
34
  '__filename',
26
35
  '__dirname',
27
- 'require',
36
+ 'require(__b)',
28
37
  ];
29
38
 
30
- export const filter = ({parentPath, scope}) => {
31
- if (parentPath.isMemberExpression())
32
- return false;
39
+ export const filter = (path) => {
40
+ const {scope} = path;
33
41
 
34
- if (parentPath.isObjectProperty())
42
+ if (isCallExpression(path) && isProgram(scope.block))
35
43
  return false;
36
44
 
37
45
  const isDirname = scope.hasBinding('__dirname');
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import * as removeUselessProcessExit from './remove-useless-process-exit/index.js';
1
+ import * as removeTopLevelProcessExit from './remove-top-level-process-exit/index.js';
2
2
  import * as applyPrivatelyRequiredFiles from './apply-privately-required-file/index.js';
3
3
  import * as convertBufferToBufferAlloc from './convert-buffer-to-buffer-alloc/index.js';
4
4
  import * as convertFsPromises from './convert-fs-promises/index.js';
@@ -51,5 +51,5 @@ export const rules = {
51
51
  'remove-illegal-strict-mode': strictMode.rules['remove-illegal'],
52
52
  'remove-useless-promisify': removeUselessPromisify,
53
53
  'group-require-by-id': groupRequireById,
54
- 'remove-useless-process-exit': removeUselessProcessExit,
54
+ 'remove-top-level-process-exit': removeTopLevelProcessExit,
55
55
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "20.2.0",
3
+ "version": "20.3.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to transform code to new API of Node.js",