@putout/plugin-nodejs 11.6.0 → 11.7.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
|
@@ -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",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-nodejs",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.7.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",
|
|
@@ -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",
|
package/lib/rename-files.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {operator} = require('putout');
|
|
4
|
-
const {join} = require('path');
|
|
5
|
-
|
|
6
|
-
const {parse} = JSON;
|
|
7
|
-
const {
|
|
8
|
-
getParentDirectory,
|
|
9
|
-
getFilename,
|
|
10
|
-
readFileContent,
|
|
11
|
-
findFile,
|
|
12
|
-
renameFile,
|
|
13
|
-
} = operator;
|
|
14
|
-
|
|
15
|
-
module.exports.renameFiles = ({type, mask, rename}) => ({
|
|
16
|
-
report,
|
|
17
|
-
fix,
|
|
18
|
-
scan: scan({
|
|
19
|
-
type,
|
|
20
|
-
mask,
|
|
21
|
-
rename,
|
|
22
|
-
}),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const report = (file, {from, to}) => `Rename '${from}' to '${to}'`;
|
|
26
|
-
|
|
27
|
-
const fix = (file, {to}) => {
|
|
28
|
-
renameFile(file, to);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const scan = ({type, mask, rename}) => (path, {push, trackFile}) => {
|
|
32
|
-
for (const file of trackFile(path, mask)) {
|
|
33
|
-
if (type && !checkType(type, file))
|
|
34
|
-
continue;
|
|
35
|
-
|
|
36
|
-
const from = getFilename(file);
|
|
37
|
-
const to = rename(from);
|
|
38
|
-
|
|
39
|
-
push(file, {
|
|
40
|
-
from,
|
|
41
|
-
to,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
function checkType(type, file) {
|
|
47
|
-
const packagePath = findUpPackage(file);
|
|
48
|
-
|
|
49
|
-
if (type === 'commonjs' && !packagePath)
|
|
50
|
-
return true;
|
|
51
|
-
|
|
52
|
-
if (!packagePath)
|
|
53
|
-
return false;
|
|
54
|
-
|
|
55
|
-
const packageContent = readFileContent(packagePath);
|
|
56
|
-
|
|
57
|
-
if (!packageContent)
|
|
58
|
-
return false;
|
|
59
|
-
|
|
60
|
-
const info = parse(packageContent);
|
|
61
|
-
const infoType = info.type || 'commonjs';
|
|
62
|
-
|
|
63
|
-
return infoType === type;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function findUpPackage(file) {
|
|
67
|
-
let packageJSON;
|
|
68
|
-
let dirPath = getParentDirectory(file);
|
|
69
|
-
|
|
70
|
-
do {
|
|
71
|
-
const dir = getFilename(dirPath);
|
|
72
|
-
[packageJSON] = findFile(dirPath, join(dir, 'package.json'));
|
|
73
|
-
} while (!packageJSON && (dirPath = getParentDirectory(dirPath)));
|
|
74
|
-
|
|
75
|
-
return packageJSON;
|
|
76
|
-
}
|