@putout/plugin-nodejs 11.7.0 β 11.8.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 +9 -2
- package/lib/add-node-prefix/index.js +54 -14
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ npm i putout @putout/plugin-nodejs -D
|
|
|
25
25
|
"nodejs/cjs-file": "off",
|
|
26
26
|
"nodejs/mjs-file": "off",
|
|
27
27
|
"nodejs/rename-file-cjs-to-js": "off",
|
|
28
|
+
"nodejs/rename-file-mjs-to-js": "off",
|
|
28
29
|
"nodejs/add-node-prefix": "on",
|
|
29
30
|
"nodejs/convert-buffer-to-buffer-alloc": "on",
|
|
30
31
|
"nodejs/convert-fs-promises": "on",
|
|
@@ -55,12 +56,18 @@ Check out in π[Putout Editor](https://putout.cloudcmd.io/#/gist/534093e0bf0a4
|
|
|
55
56
|
|
|
56
57
|
```js
|
|
57
58
|
import fs from 'fs';
|
|
59
|
+
|
|
60
|
+
const path = require('path');
|
|
61
|
+
await import('path');
|
|
58
62
|
```
|
|
59
63
|
|
|
60
64
|
### β
Example of correct code
|
|
61
65
|
|
|
62
66
|
```js
|
|
63
67
|
import fs from 'node:fs';
|
|
68
|
+
|
|
69
|
+
const path = require('node:path');
|
|
70
|
+
await import('node:path');
|
|
64
71
|
```
|
|
65
72
|
|
|
66
73
|
### Comparison
|
|
@@ -381,7 +388,7 @@ Check out in π[Putout Editor](https://putout.cloudcmd.io/#/gist/779e7fb720af5
|
|
|
381
388
|
|
|
382
389
|
## rename-file-cjs-to-js
|
|
383
390
|
|
|
384
|
-
Rename `*.cjs` files when `
|
|
391
|
+
Rename `*.cjs` files when `type === "commonjs"`:
|
|
385
392
|
|
|
386
393
|
```diff
|
|
387
394
|
/
|
|
@@ -395,7 +402,7 @@ Check out in π[Putout Editor](https://putout.cloudcmd.io/#/gist/8d8f3cd6662b7
|
|
|
395
402
|
|
|
396
403
|
## rename-file-mjs-to-js
|
|
397
404
|
|
|
398
|
-
Rename `*.mjs` files when `
|
|
405
|
+
Rename `*.mjs` files when `type === "module"`:
|
|
399
406
|
|
|
400
407
|
```diff
|
|
401
408
|
/
|
|
@@ -1,28 +1,68 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {operator} = require('putout');
|
|
4
|
-
const {isBuiltin} = require('module');
|
|
5
|
-
const {
|
|
3
|
+
const {types, operator} = require('putout');
|
|
4
|
+
const {isBuiltin} = require('node:module');
|
|
5
|
+
const {
|
|
6
|
+
setLiteralValue,
|
|
7
|
+
getTemplateValues,
|
|
8
|
+
} = operator;
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
const {isCallExpression} = types;
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
const REQUIRE = 'require("__a")';
|
|
13
|
+
const IMPORT = 'import("__a")';
|
|
14
|
+
|
|
15
|
+
module.exports.report = ({value}) => {
|
|
16
|
+
return `Use 'node:${value}' instead of '${value}'`;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports.fix = ({path, value}) => {
|
|
20
|
+
if (isCallExpression(path)) {
|
|
21
|
+
const arg = path.get('arguments.0');
|
|
22
|
+
setLiteralValue(arg, `node:${value}`);
|
|
23
|
+
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
12
26
|
|
|
27
|
+
const {source} = path.node;
|
|
13
28
|
setLiteralValue(source, `node:${value}`);
|
|
14
29
|
};
|
|
15
30
|
|
|
16
31
|
module.exports.traverse = ({push}) => ({
|
|
17
|
-
|
|
18
|
-
const {
|
|
32
|
+
[IMPORT](path) {
|
|
33
|
+
const {__a} = getTemplateValues(path, IMPORT);
|
|
34
|
+
const {value} = __a;
|
|
19
35
|
|
|
20
|
-
if (value
|
|
21
|
-
|
|
36
|
+
if (check(value))
|
|
37
|
+
push({
|
|
38
|
+
path,
|
|
39
|
+
value,
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
[REQUIRE](path) {
|
|
43
|
+
const {__a} = getTemplateValues(path, REQUIRE);
|
|
44
|
+
const {value} = __a;
|
|
22
45
|
|
|
23
|
-
if (
|
|
24
|
-
|
|
46
|
+
if (check(value))
|
|
47
|
+
push({
|
|
48
|
+
path,
|
|
49
|
+
value,
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
ImportDeclaration(path) {
|
|
53
|
+
const {value} = path.node.source;
|
|
25
54
|
|
|
26
|
-
|
|
55
|
+
if (check(value))
|
|
56
|
+
push({
|
|
57
|
+
path,
|
|
58
|
+
value,
|
|
59
|
+
});
|
|
27
60
|
},
|
|
28
61
|
});
|
|
62
|
+
|
|
63
|
+
function check(value) {
|
|
64
|
+
if (value.startsWith('node:'))
|
|
65
|
+
return false;
|
|
66
|
+
|
|
67
|
+
return isBuiltin(value);
|
|
68
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-nodejs",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.8.0",
|
|
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",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@putout/test": "^9.0.0",
|
|
46
46
|
"c8": "^9.0.0",
|
|
47
47
|
"eslint": "^9.0.0",
|
|
48
|
-
"eslint-plugin-n": "^17.0.0
|
|
48
|
+
"eslint-plugin-n": "^17.0.0",
|
|
49
49
|
"eslint-plugin-putout": "^22.0.0",
|
|
50
50
|
"lerna": "^6.0.1",
|
|
51
51
|
"madrun": "^10.0.0",
|