@putout/plugin-nodejs 5.0.0 → 6.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 +16 -0
- package/lib/convert-buffer-to-buffer-alloc/index.js +0 -1
- package/lib/convert-fs-promises/index.js +0 -1
- package/lib/convert-promisify-to-fs-promises/index.js +7 -2
- package/lib/convert-top-level-return/index.js +0 -1
- package/lib/declare/index.js +1 -5
- package/lib/declare-after-require/index.js +1 -3
- package/lib/index.js +0 -1
- package/lib/remove-process-exit/index.js +0 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ npm i putout @putout/plugin-nodejs -D
|
|
|
26
26
|
"nodejs/convert-dirname-to-url": "on",
|
|
27
27
|
"nodejs/convert-url-to-dirname": "on",
|
|
28
28
|
"nodejs/convert-top-level-return": "on",
|
|
29
|
+
"nodejs/declare": "on",
|
|
29
30
|
"nodejs/declare-after-require": "on",
|
|
30
31
|
"nodejs/remove-process-exit": "on"
|
|
31
32
|
}
|
|
@@ -179,6 +180,8 @@ Add declarations to built-in node.js modules:
|
|
|
179
180
|
- [util](https://nodejs.org/dist/latest-v18.x/docs/api/util.html);
|
|
180
181
|
- [zlib](https://nodejs.org/dist/latest-v18.x/docs/api/zlib.html);
|
|
181
182
|
|
|
183
|
+
Based on [`@putout/operator-declare`](https://github.com/coderaiser/putout/tree/master/packages/operator-declare#putoutoperator-declare-).
|
|
184
|
+
|
|
182
185
|
#### ❌ Example of incorrect code
|
|
183
186
|
|
|
184
187
|
```js
|
|
@@ -189,9 +192,22 @@ await readFile('hello.txt', 'utf8');
|
|
|
189
192
|
|
|
190
193
|
```js
|
|
191
194
|
import {readFile} from 'fs/promises';
|
|
195
|
+
|
|
192
196
|
await readFile('hello.txt', 'utf8');
|
|
193
197
|
```
|
|
194
198
|
|
|
199
|
+
When you want to skip some declaration use `dismiss`:
|
|
200
|
+
|
|
201
|
+
```json
|
|
202
|
+
{
|
|
203
|
+
"rules": {
|
|
204
|
+
"nodejs/declare": ["on", {
|
|
205
|
+
"dismiss": ["readFile"]
|
|
206
|
+
}]
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
195
211
|
### declare-after-require
|
|
196
212
|
|
|
197
213
|
> **Node.js** follows the **CommonJS** module system, and the builtin `require` function is the easiest way to include modules that exist in separate files. The basic functionality of `require` is that it reads a JavaScript file, executes the file, and then proceeds to return the `exports` object.
|
|
@@ -22,11 +22,17 @@ module.exports.fix = ({path, promisified}) => {
|
|
|
22
22
|
const [declarator] = path.node.declarations;
|
|
23
23
|
const {name} = declarator.id;
|
|
24
24
|
|
|
25
|
-
props.push(t.ObjectProperty(
|
|
25
|
+
props.push(t.ObjectProperty(
|
|
26
|
+
t.Identifier(name),
|
|
27
|
+
t.Identifier(name),
|
|
28
|
+
NOT_COMPUTED,
|
|
29
|
+
SHORTHAND,
|
|
30
|
+
));
|
|
26
31
|
remove(path);
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
const {init} = path.node;
|
|
35
|
+
|
|
30
36
|
init.arguments[0].value = 'fs/promises';
|
|
31
37
|
|
|
32
38
|
replaceWith(path.get('id'), t.ObjectPattern(props));
|
|
@@ -58,4 +64,3 @@ module.exports.find = (ast, {push, traverse}) => {
|
|
|
58
64
|
promisified,
|
|
59
65
|
});
|
|
60
66
|
};
|
|
61
|
-
|
package/lib/declare/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const {declare} = operator;
|
|
5
|
-
|
|
6
|
-
module.exports = declare({
|
|
3
|
+
module.exports.declare = () => ({
|
|
7
4
|
...require('./modules/events'),
|
|
8
5
|
...require('./modules/fs'),
|
|
9
6
|
...require('./modules/fs-promises'),
|
|
@@ -17,4 +14,3 @@ module.exports = declare({
|
|
|
17
14
|
...require('./modules/util'),
|
|
18
15
|
...require('./modules/child_process'),
|
|
19
16
|
});
|
|
20
|
-
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {operator} = require('putout');
|
|
4
|
-
|
|
5
4
|
const {
|
|
6
5
|
remove,
|
|
7
6
|
compareAny,
|
|
@@ -22,7 +21,7 @@ module.exports.report = ({path}) => {
|
|
|
22
21
|
|
|
23
22
|
module.exports.fix = ({path, firstRequire, lastRequire}) => {
|
|
24
23
|
const {node} = path;
|
|
25
|
-
const {comments} =
|
|
24
|
+
const {comments} = node;
|
|
26
25
|
|
|
27
26
|
delete node.loc;
|
|
28
27
|
node.__putoutNodeDeclareAfterRequire = true;
|
|
@@ -124,4 +123,3 @@ function getReferenceLine(path) {
|
|
|
124
123
|
|
|
125
124
|
return firstReference.node.loc.start.line;
|
|
126
125
|
}
|
|
127
|
-
|
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-nodejs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"type": "commonjs",
|
|
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",
|
|
@@ -34,18 +34,18 @@
|
|
|
34
34
|
"@putout/plugin-convert-commonjs-to-esm": "*",
|
|
35
35
|
"@putout/plugin-convert-esm-to-commonjs": "*",
|
|
36
36
|
"@putout/plugin-putout": "*",
|
|
37
|
-
"@putout/test": "^
|
|
37
|
+
"@putout/test": "^6.0.0",
|
|
38
38
|
"c8": "^7.5.0",
|
|
39
39
|
"eslint": "^8.0.1",
|
|
40
|
-
"eslint-plugin-n": "^
|
|
41
|
-
"eslint-plugin-putout": "^
|
|
42
|
-
"lerna": "^
|
|
40
|
+
"eslint-plugin-n": "^16.0.0",
|
|
41
|
+
"eslint-plugin-putout": "^17.0.0",
|
|
42
|
+
"lerna": "^6.0.1",
|
|
43
43
|
"madrun": "^9.0.0",
|
|
44
44
|
"montag": "^1.2.1",
|
|
45
45
|
"nodemon": "^2.0.1"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"putout": ">=
|
|
48
|
+
"putout": ">=29"
|
|
49
49
|
},
|
|
50
50
|
"license": "MIT",
|
|
51
51
|
"engines": {
|