@putout/plugin-nodejs 1.1.0 → 3.0.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
@@ -1,12 +1,9 @@
1
- # @putout/plugin-nodejs [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL]
1
+ # @putout/plugin-nodejs [![NPM version][NPMIMGURL]][NPMURL]
2
2
 
3
- [NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-nodejs.svg?style=flat&longCache=true
4
- [NPMURL]: https://npmjs.org/package/@putout/plugin-nodejs"npm"
3
+ [NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-nodejs.svg?style=flat&longCache=true
4
+ [NPMURL]: https://npmjs.org/package/@putout/plugin-nodejs"npm"
5
5
 
6
- [DependencyStatusURL]: https://david-dm.org/coderaiser/putout?path=packages/plugin-nodejs
7
- [DependencyStatusIMGURL]: https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-nodejs
8
-
9
- `putout` plugin adds ability to transform to new [nodejs.org](https://nodejs.io) API and best practices.
6
+ 🐊[`Putout`](https://github.com/coderaiser/putout) plugin adds ability to transform to new [nodejs.org](https://nodejs.io) API and best practices.
10
7
 
11
8
  ## Install
12
9
 
@@ -14,18 +11,22 @@
14
11
  npm i putout @putout/plugin-nodejs -D
15
12
  ```
16
13
 
17
- ## Rules
14
+ ## Options
18
15
 
19
16
  ```json
20
17
  {
21
18
  "rules": {
22
19
  "nodejs/convert-fs-promises": "on",
23
- "nodejs/convert-promisify-to-fs-promises": "on"
20
+ "nodejs/convert-promisify-to-fs-promises": "on",
21
+ "nodejs/convert-dirname-to-url": "on",
22
+ "nodejs/remove-process-exit": "on"
24
23
  }
25
24
  }
26
25
  ```
27
26
 
28
- # convert-fs-promises
27
+ ## Rules
28
+
29
+ ### convert-fs-promises
29
30
 
30
31
  Convert [fs.promises](https://nodejs.org/dist/latest-v15.x/docs/api/fs.html#fs_fs_promises_api) into form that will be simpler to use and convert from in `ESM` to:
31
32
 
@@ -33,34 +34,63 @@ Convert [fs.promises](https://nodejs.org/dist/latest-v15.x/docs/api/fs.html#fs_f
33
34
  import {readFile} from 'fs/promises';
34
35
  ```
35
36
 
36
- ## ❌ Incorrect code example
37
+ #### ❌ Incorrect code example
37
38
 
38
39
  ```js
39
40
  const {readFile} = require('fs').promises;
40
41
  ```
41
42
 
42
- ## ✅ Correct code Example
43
+ #### ✅ Correct code Example
43
44
 
44
45
  ```js
45
46
  const {readFile} = require('fs/promises');
46
47
  ```
47
48
 
48
- # convert-promisify-to-fs-promises
49
+ ### convert-promisify-to-fs-promises
49
50
 
50
- ## ❌ Incorrect code example
51
+ #### ❌ Incorrect code example
51
52
 
52
53
  ```js
53
54
  const fs = require('fs');
54
55
  const readFile = promisify(fs.readFile);
55
56
  ```
56
57
 
57
- ## ✅ Correct code Example
58
+ #### ✅ Correct code Example
58
59
 
59
60
  ```js
60
61
  const {readFile} = require('fs/promises');
61
62
  ```
62
63
 
64
+ ### convert-dirname-to-url
65
+
66
+ Only for `EcmaScript Modules`.
67
+
68
+ #### ❌ Incorrect code example
69
+
70
+ ```js
71
+ import {readFile} from 'fs/promises';
72
+
73
+ const file1 = join(__dirname, '../../package.json');
74
+ const file2 = path.join(__dirname, '../../package.json');
75
+ ```
76
+
77
+ #### ✅ Correct code Example
78
+
79
+ ```js
80
+ import {readFile} from 'fs/promises';
81
+
82
+ const file1 = new URL('../../package.json', import.meta.url);
83
+ const file2 = new URL('../../package.json', import.meta.url);
84
+ ```
85
+
86
+ ### remove-process-exit
87
+
88
+ In most cases `process.exit()` is called from `bin` directory, if not - disable this rule using `match`.
89
+
90
+ ```diff
91
+ -process.exit();
92
+ ```
93
+
63
94
  ## License
64
95
 
65
96
  MIT
66
-
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ const {operator} = require('putout');
4
+ const {isESM} = operator;
5
+
6
+ module.exports.report = () => `Use 'import.meta.url' instead of '__dirname'`;
7
+
8
+ module.exports.filter = isESM;
9
+
10
+ module.exports.replace = () => ({
11
+ 'join(__dirname, __a)': 'new URL(__a, import.meta.url).pathname',
12
+ 'path.join(__dirname, __a)': 'new URL(__a, import.meta.url).pathname',
13
+ });
package/lib/index.js CHANGED
@@ -7,5 +7,7 @@ const getRule = (a) => ({
7
7
  module.exports.rules = {
8
8
  ...getRule('convert-fs-promises'),
9
9
  ...getRule('convert-promisify-to-fs-promises'),
10
+ ...getRule('convert-dirname-to-url'),
11
+ ...getRule('remove-process-exit'),
10
12
  };
11
13
 
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => '"process.exit" should not be used';
4
+
5
+ module.exports.replace = () => ({
6
+ 'process.exit()': '',
7
+ 'process["exit"]()': '',
8
+ });
9
+
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "1.1.0",
3
+ "version": "3.0.1",
4
+ "type": "commonjs",
4
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
6
  "description": "putout plugin adds ability to transform code to new API of Node.js",
6
- "homepage": "http://github.com/coderaiser/putout",
7
+ "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-nodejs#readme",
7
8
  "main": "lib/index.js",
8
9
  "release": false,
9
10
  "tag": false,
@@ -30,20 +31,17 @@
30
31
  "nodejs"
31
32
  ],
32
33
  "devDependencies": {
33
- "@putout/plugin-remove-unused-expressions": "^1.2.1",
34
- "@putout/plugin-strict-mode": "^1.2.1",
35
- "@putout/test": "^3.0.0",
36
- "coveralls": "^3.0.0",
37
- "eslint": "^7.6.0",
34
+ "@putout/test": "^4.0.0",
35
+ "c8": "^7.5.0",
36
+ "eslint": "^8.0.1",
38
37
  "eslint-plugin-node": "^11.0.0",
39
- "eslint-plugin-putout": "^6.0.0",
40
- "lerna": "^3.8.5",
38
+ "eslint-plugin-putout": "^12.0.0",
39
+ "lerna": "^4.0.0",
41
40
  "madrun": "^8.0.1",
42
- "nodemon": "^2.0.1",
43
- "nyc": "^15.0.1"
41
+ "nodemon": "^2.0.1"
44
42
  },
45
43
  "peerDependencies": {
46
- "putout": ">=13"
44
+ "putout": ">=24"
47
45
  },
48
46
  "license": "MIT",
49
47
  "engines": {