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