@putout/plugin-nodejs 11.5.0 → 11.7.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.
|
@@ -1,63 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {operator} = require('putout');
|
|
4
|
-
const {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} = operator;
|
|
14
|
-
|
|
15
|
-
module.exports.report = (file, {cjs, js}) => `Rename '${cjs}' to '${js}'`;
|
|
16
|
-
|
|
17
|
-
module.exports.fix = (file, {js}) => {
|
|
18
|
-
renameFile(file, js);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
module.exports.scan = (path, {push, trackFile}) => {
|
|
22
|
-
for (const file of trackFile(path, '*.cjs')) {
|
|
23
|
-
const packagePath = findUpPackage(file);
|
|
24
|
-
|
|
25
|
-
const cjs = getFilename(file);
|
|
26
|
-
const js = cjs.replace(/cjs$/, 'js');
|
|
27
|
-
|
|
28
|
-
if (!packagePath) {
|
|
29
|
-
push(file, {
|
|
30
|
-
cjs,
|
|
31
|
-
js,
|
|
32
|
-
});
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const packageContent = readFileContent(packagePath);
|
|
37
|
-
|
|
38
|
-
if (!packageContent)
|
|
39
|
-
continue;
|
|
40
|
-
|
|
41
|
-
const {type} = parse(packageContent);
|
|
42
|
-
|
|
43
|
-
if (type === 'module')
|
|
44
|
-
continue;
|
|
45
|
-
|
|
46
|
-
push(file, {
|
|
47
|
-
cjs,
|
|
48
|
-
js,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
function findUpPackage(file) {
|
|
54
|
-
let packageJSON;
|
|
55
|
-
let dirPath = getParentDirectory(file);
|
|
56
|
-
|
|
57
|
-
do {
|
|
58
|
-
const dir = getFilename(dirPath);
|
|
59
|
-
[packageJSON] = findFile(dirPath, join(dir, 'package.json'));
|
|
60
|
-
} while (!packageJSON && (dirPath = getParentDirectory(dirPath)));
|
|
61
|
-
|
|
62
|
-
return packageJSON;
|
|
63
|
-
}
|
|
4
|
+
const {renameFiles} = operator;
|
|
5
|
+
|
|
6
|
+
module.exports = renameFiles({
|
|
7
|
+
type: 'commonjs',
|
|
8
|
+
mask: '*.cjs',
|
|
9
|
+
rename(name) {
|
|
10
|
+
return name.replace(/cjs$/, 'js');
|
|
11
|
+
},
|
|
12
|
+
});
|
|
@@ -1,58 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {operator} = require('putout');
|
|
4
|
-
const {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} = operator;
|
|
14
|
-
|
|
15
|
-
module.exports.report = (file, {mjs, js}) => `Rename '${mjs}' to '${js}'`;
|
|
16
|
-
|
|
17
|
-
module.exports.fix = (file, {js}) => {
|
|
18
|
-
renameFile(file, js);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
module.exports.scan = (path, {push, trackFile}) => {
|
|
22
|
-
for (const file of trackFile(path, '*.mjs')) {
|
|
23
|
-
const packagePath = findUpPackage(file);
|
|
24
|
-
|
|
25
|
-
if (!packagePath)
|
|
26
|
-
continue;
|
|
27
|
-
|
|
28
|
-
const packageContent = readFileContent(packagePath);
|
|
29
|
-
|
|
30
|
-
if (!packageContent)
|
|
31
|
-
continue;
|
|
32
|
-
|
|
33
|
-
const {type} = parse(packageContent);
|
|
34
|
-
|
|
35
|
-
if (type !== 'module')
|
|
36
|
-
continue;
|
|
37
|
-
|
|
38
|
-
const mjs = getFilename(file);
|
|
39
|
-
const js = mjs.replace(/mjs$/, 'js');
|
|
40
|
-
|
|
41
|
-
push(file, {
|
|
42
|
-
mjs,
|
|
43
|
-
js,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
function findUpPackage(file) {
|
|
49
|
-
let packageJSON;
|
|
50
|
-
let dirPath = getParentDirectory(file);
|
|
51
|
-
|
|
52
|
-
do {
|
|
53
|
-
const dir = getFilename(dirPath);
|
|
54
|
-
[packageJSON] = findFile(dirPath, join(dir, 'package.json'));
|
|
55
|
-
} while (!packageJSON && (dirPath = getParentDirectory(dirPath)));
|
|
56
|
-
|
|
57
|
-
return packageJSON;
|
|
58
|
-
}
|
|
4
|
+
const {renameFiles} = operator;
|
|
5
|
+
|
|
6
|
+
module.exports = renameFiles({
|
|
7
|
+
type: 'module',
|
|
8
|
+
mask: '*.mjs',
|
|
9
|
+
rename(name) {
|
|
10
|
+
return name.replace(/mjs$/, 'js');
|
|
11
|
+
},
|
|
12
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-nodejs",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.7.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",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@putout/plugin-typescript": "*",
|
|
45
45
|
"@putout/test": "^9.0.0",
|
|
46
46
|
"c8": "^9.0.0",
|
|
47
|
-
"eslint": "^9.0.0
|
|
47
|
+
"eslint": "^9.0.0",
|
|
48
48
|
"eslint-plugin-n": "^17.0.0-0",
|
|
49
49
|
"eslint-plugin-putout": "^22.0.0",
|
|
50
50
|
"lerna": "^6.0.1",
|