@putout/plugin-nodejs 16.0.0 → 16.2.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/lib/cjs-file/index.js +2 -7
- package/lib/convert-buffer-to-buffer-alloc/index.js +0 -9
- package/lib/convert-commonjs-to-esm-require/index.js +17 -6
- package/lib/mjs-file/index.js +2 -7
- package/lib/rename-file-cjs-to-js/index.js +1 -7
- package/lib/rename-file-mjs-to-js/index.js +2 -7
- package/package.json +1 -1
package/lib/cjs-file/index.js
CHANGED
|
@@ -2,16 +2,11 @@ import {operator} from 'putout';
|
|
|
2
2
|
import * as plugin from '../convert-esm-to-commonjs/index.js';
|
|
3
3
|
|
|
4
4
|
const {matchFiles} = operator;
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
export const {
|
|
6
7
|
report,
|
|
7
8
|
fix,
|
|
8
9
|
scan,
|
|
9
10
|
} = matchFiles({
|
|
10
11
|
'*.cjs': plugin,
|
|
11
12
|
});
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
report,
|
|
15
|
-
fix,
|
|
16
|
-
scan,
|
|
17
|
-
};
|
|
@@ -6,15 +6,6 @@ const isNumber = (a) => typeof a === 'number';
|
|
|
6
6
|
|
|
7
7
|
export const report = () => `Use 'Buffer.alloc()' or 'Buffer.from()' instead of 'Buffer()' and 'new Buffer()'`;
|
|
8
8
|
|
|
9
|
-
export const match = () => ({
|
|
10
|
-
'new Buffer(__a)': (vars, path) => {
|
|
11
|
-
const __aPath = path.get('arguments.0');
|
|
12
|
-
const [is] = compute(__aPath);
|
|
13
|
-
|
|
14
|
-
return is;
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
|
|
18
9
|
export const replace = () => ({
|
|
19
10
|
'new Buffer(__a)': transform,
|
|
20
11
|
'new Buffer(__a, __b)': transform,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import justCamelCase from 'just-camel-case';
|
|
1
2
|
import {
|
|
2
3
|
types,
|
|
3
4
|
operator,
|
|
4
5
|
template,
|
|
5
6
|
} from 'putout';
|
|
6
|
-
import justCamelCase from 'just-camel-case';
|
|
7
7
|
|
|
8
8
|
const {
|
|
9
9
|
awaitExpression,
|
|
@@ -63,12 +63,23 @@ export const match = () => ({
|
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
export const replace = () => ({
|
|
66
|
+
'const __a = require(__b).__c': ({__c}, path) => {
|
|
67
|
+
const {name} = __c;
|
|
68
|
+
|
|
69
|
+
if (name === 'default')
|
|
70
|
+
return 'import __a from "__b"';
|
|
71
|
+
|
|
72
|
+
const bindingPath = path.scope.bindings[name];
|
|
73
|
+
|
|
74
|
+
if (bindingPath)
|
|
75
|
+
return 'const __a = __c';
|
|
76
|
+
|
|
77
|
+
return `{
|
|
78
|
+
const {__c} = require(__b);
|
|
79
|
+
const __a = __c;
|
|
80
|
+
}`;
|
|
81
|
+
},
|
|
66
82
|
'const __a = require(".")': 'import __a from "./index.js"',
|
|
67
|
-
'const __a = require("__b").default': 'import __a from "__b"',
|
|
68
|
-
'const __a = require(__b).__c': `{
|
|
69
|
-
const {__c} = require(__b);
|
|
70
|
-
const __a = __c;
|
|
71
|
-
}`,
|
|
72
83
|
'require("__a")': 'import("__a")',
|
|
73
84
|
'const __a = require(__b)': ({__a}, path) => {
|
|
74
85
|
const {value} = path.get(__B).evaluate();
|
package/lib/mjs-file/index.js
CHANGED
|
@@ -2,16 +2,11 @@ import {operator} from 'putout';
|
|
|
2
2
|
import * as plugin from '../convert-commonjs-to-esm.js';
|
|
3
3
|
|
|
4
4
|
const {matchFiles} = operator;
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
export const {
|
|
6
7
|
report,
|
|
7
8
|
fix,
|
|
8
9
|
scan,
|
|
9
10
|
} = matchFiles({
|
|
10
11
|
'*.mjs': plugin,
|
|
11
12
|
});
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
report,
|
|
15
|
-
fix,
|
|
16
|
-
scan,
|
|
17
|
-
};
|
|
@@ -2,7 +2,7 @@ import {operator} from 'putout';
|
|
|
2
2
|
|
|
3
3
|
const {renameFiles} = operator;
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
export const {
|
|
6
6
|
report,
|
|
7
7
|
fix,
|
|
8
8
|
scan,
|
|
@@ -13,9 +13,3 @@ const {
|
|
|
13
13
|
return name.replace(/cjs$/, 'js');
|
|
14
14
|
},
|
|
15
15
|
});
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
report,
|
|
19
|
-
fix,
|
|
20
|
-
scan,
|
|
21
|
-
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {operator} from 'putout';
|
|
2
2
|
|
|
3
3
|
const {renameFiles} = operator;
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
export const {
|
|
5
6
|
report,
|
|
6
7
|
fix,
|
|
7
8
|
scan,
|
|
@@ -12,9 +13,3 @@ const {
|
|
|
12
13
|
return name.replace(/mjs$/, 'js');
|
|
13
14
|
},
|
|
14
15
|
});
|
|
15
|
-
|
|
16
|
-
export {
|
|
17
|
-
report,
|
|
18
|
-
fix,
|
|
19
|
-
scan,
|
|
20
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-nodejs",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.2.0",
|
|
4
4
|
"type": "module",
|
|
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",
|