@putout/plugin-nodejs 18.16.2 → 19.0.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 +3 -34
- package/lib/{convert-commonjs-to-esm-commons → convert-commonjs-to-esm/commons}/index.js +5 -3
- package/lib/convert-commonjs-to-esm/index.js +9 -0
- package/lib/index.js +4 -8
- package/lib/mjs-file/index.js +1 -1
- package/package.json +2 -2
- package/lib/apply-global-this/index.js +0 -6
- package/lib/convert-commonjs-to-esm.js +0 -9
- /package/lib/{convert-commonjs-to-esm-exports → convert-commonjs-to-esm/exports}/index.js +0 -0
- /package/lib/{convert-commonjs-to-esm-require → convert-commonjs-to-esm/require}/index.js +0 -0
package/README.md
CHANGED
|
@@ -19,7 +19,6 @@ npm i putout @putout/plugin-nodejs -D
|
|
|
19
19
|
|
|
20
20
|
- ✅ [add-node-prefix](#add-node-prefix);
|
|
21
21
|
- ✅ [add-missing-strict-mode](#add-missing-strict-mode);
|
|
22
|
-
- ✅ [apply-global-this](#apply-global-this);
|
|
23
22
|
- ✅ [convert-buffer-to-buffer-alloc](#convert-buffer-to-buffer-alloc);
|
|
24
23
|
- ✅ [convert-commonjs-to-esm](#convert-commonjs-to-esm);
|
|
25
24
|
- ✅ [convert-dirname-to-url](#convert-dirname-to-url);
|
|
@@ -48,7 +47,6 @@ npm i putout @putout/plugin-nodejs -D
|
|
|
48
47
|
"rules": {
|
|
49
48
|
"nodejs/add-missing-strict-mode": "on",
|
|
50
49
|
"nodejs/add-node-prefix": "on",
|
|
51
|
-
"nodejs/apply-global-this": "off",
|
|
52
50
|
"nodejs/convert-commonjs-to-esm": "off",
|
|
53
51
|
"nodejs/convert-esm-to-commonjs": "off",
|
|
54
52
|
"nodejs/cjs-file": "off",
|
|
@@ -106,33 +104,6 @@ Linter | Rule | Fix
|
|
|
106
104
|
🐊 **Putout** | [`add-node-prefix`](https://github.com/coderaiser/putout/tree/master/packages/plugin-nodejs/add-node-prefix#readme) | ✅
|
|
107
105
|
⏣ **ESLint** | [`prefer-node-protocol`](https://github.com/eslint-community/eslint-plugin-n/blob/master/docs/rules/prefer-node-protocol.md#readme) | ✅
|
|
108
106
|
|
|
109
|
-
## apply-global-this
|
|
110
|
-
|
|
111
|
-
> Legacy. Use `globalThis` instead.
|
|
112
|
-
>
|
|
113
|
-
> (c) [nodejs.org](https://nodejs.org/api/globals.html#global)
|
|
114
|
-
|
|
115
|
-
Check out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/c72c8e1b1d0c2b45fd0d15d837dcae52/c7f33d77d19efe962339debbcf20f68bf2159aee).
|
|
116
|
-
|
|
117
|
-
### ❌ Example of incorrect code
|
|
118
|
-
|
|
119
|
-
```js
|
|
120
|
-
global.__putout_debug = debugFn;
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### ✅ Example of correct code
|
|
124
|
-
|
|
125
|
-
```js
|
|
126
|
-
globalThis.__putout_debug = debugFn;
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
### Comparison
|
|
130
|
-
|
|
131
|
-
Linter | Rule | Fix
|
|
132
|
-
-------|------|------------|
|
|
133
|
-
🐊 **Putout** | [`apply-global-this`](https://github.com/coderaiser/putout/tree/master/packages/plugin-nodejs/apply-node-prefix#readme) | ✅
|
|
134
|
-
⏣ **ESLint** | [`no-node-globals`](https://docs.deno.com/lint/rules/no-node-globals/) | ❌
|
|
135
|
-
|
|
136
107
|
## convert-buffer-to-buffer-alloc
|
|
137
108
|
|
|
138
109
|
> The `Buffer()` function and `new Buffer()` constructor are **deprecated** due to API usability issues that can lead to accidental security issues.
|
|
@@ -347,7 +318,7 @@ const {readFile} = require('fs/promises');
|
|
|
347
318
|
const name = 'hello.txt';
|
|
348
319
|
```
|
|
349
320
|
|
|
350
|
-
## convert-commonjs-to-esm
|
|
321
|
+
## convert-commonjs-to-esm/require
|
|
351
322
|
|
|
352
323
|
Convert **CommonJS** **EcmaScript Modules**.
|
|
353
324
|
|
|
@@ -355,8 +326,6 @@ Convert **CommonJS** **EcmaScript Modules**.
|
|
|
355
326
|
>
|
|
356
327
|
> (c) [parceljs](https://parceljs.org/languages/javascript/)
|
|
357
328
|
|
|
358
|
-
### require
|
|
359
|
-
|
|
360
329
|
### ❌ Example of incorrect code
|
|
361
330
|
|
|
362
331
|
```js
|
|
@@ -378,7 +347,7 @@ const args = minimist({
|
|
|
378
347
|
});
|
|
379
348
|
```
|
|
380
349
|
|
|
381
|
-
|
|
350
|
+
## convert-commonjs-to-esm/exports
|
|
382
351
|
|
|
383
352
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/39dd730c35e488db3e2cf8d4b4df0c5a/feb042a49539e6b4b2165558a1c636b705726c47).
|
|
384
353
|
|
|
@@ -394,7 +363,7 @@ module.exports = () => {};
|
|
|
394
363
|
export default () => {};
|
|
395
364
|
```
|
|
396
365
|
|
|
397
|
-
|
|
366
|
+
## convert-commonjs-to-esm/commons
|
|
398
367
|
|
|
399
368
|
### ❌ Example of incorrect code
|
|
400
369
|
|
|
@@ -27,11 +27,13 @@ export const include = () => [
|
|
|
27
27
|
'require',
|
|
28
28
|
];
|
|
29
29
|
|
|
30
|
-
export const filter = (
|
|
31
|
-
if (
|
|
30
|
+
export const filter = ({parentPath, scope}) => {
|
|
31
|
+
if (parentPath.isMemberExpression())
|
|
32
|
+
return false;
|
|
33
|
+
|
|
34
|
+
if (parentPath.isObjectProperty())
|
|
32
35
|
return false;
|
|
33
36
|
|
|
34
|
-
const {scope} = path;
|
|
35
37
|
const isDirname = scope.hasBinding('__dirname');
|
|
36
38
|
const isFilename = scope.hasBinding('__filename');
|
|
37
39
|
const isRequire = scope.hasBinding('require');
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as applyGlobalThis from './apply-global-this/index.js';
|
|
2
1
|
import * as convertBufferToBufferAlloc from './convert-buffer-to-buffer-alloc/index.js';
|
|
3
2
|
import * as convertFsPromises from './convert-fs-promises/index.js';
|
|
4
3
|
import * as convertPromisifyToFsPromises from './convert-promisify-to-fs-promises/index.js';
|
|
@@ -11,9 +10,7 @@ import * as removeProcessExit from './remove-process-exit/index.js';
|
|
|
11
10
|
import * as addNodePrefix from './add-node-prefix/index.js';
|
|
12
11
|
import * as convertExportsToModuleExports from './convert-exports-to-module-exports/index.js';
|
|
13
12
|
import * as convertEsmToCommonjs from './convert-esm-to-commonjs/index.js';
|
|
14
|
-
import * as
|
|
15
|
-
import * as convertCommonjsToEsmCommons from './convert-commonjs-to-esm-commons/index.js';
|
|
16
|
-
import * as convertCommonjsToEsmRequire from './convert-commonjs-to-esm-require/index.js';
|
|
13
|
+
import * as convertCommonjsToEsm from './convert-commonjs-to-esm/index.js';
|
|
17
14
|
import * as cjsFile from './cjs-file/index.js';
|
|
18
15
|
import * as mjsFile from './mjs-file/index.js';
|
|
19
16
|
import * as renameFileCjsToJs from './rename-file-cjs-to-js/index.js';
|
|
@@ -36,9 +33,9 @@ export const rules = {
|
|
|
36
33
|
'convert-exports-to-module-exports': convertExportsToModuleExports,
|
|
37
34
|
|
|
38
35
|
'convert-esm-to-commonjs': ['off', convertEsmToCommonjs],
|
|
39
|
-
'convert-commonjs-to-esm
|
|
40
|
-
'convert-commonjs-to-esm
|
|
41
|
-
'convert-commonjs-to-esm
|
|
36
|
+
'convert-commonjs-to-esm/exports': ['off', convertCommonjsToEsm.rules.exports],
|
|
37
|
+
'convert-commonjs-to-esm/common': ['off', convertCommonjsToEsm.rules.commons],
|
|
38
|
+
'convert-commonjs-to-esm/require': ['off', convertCommonjsToEsm.rules.require],
|
|
42
39
|
|
|
43
40
|
'cjs-file': ['off', cjsFile],
|
|
44
41
|
'mjs-file': ['off', mjsFile],
|
|
@@ -51,5 +48,4 @@ export const rules = {
|
|
|
51
48
|
'remove-illegal-strict-mode': strictMode.rules['remove-illegal'],
|
|
52
49
|
'remove-useless-promisify': removeUselessPromisify,
|
|
53
50
|
'group-require-by-id': groupRequireById,
|
|
54
|
-
'apply-global-this': applyGlobalThis,
|
|
55
51
|
};
|
package/lib/mjs-file/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-nodejs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "19.0.1",
|
|
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",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
".": "./lib/index.js",
|
|
11
11
|
"./strict-mode": "./lib/strict-mode/index.js",
|
|
12
12
|
"./convert-esm-to-commonjs": "./lib/convert-esm-to-commonjs/index.js",
|
|
13
|
-
"./convert-commonjs-to-esm": "./lib/convert-commonjs-to-esm.js"
|
|
13
|
+
"./convert-commonjs-to-esm": "./lib/convert-commonjs-to-esm/index.js"
|
|
14
14
|
},
|
|
15
15
|
"release": false,
|
|
16
16
|
"tag": false,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as convertCommonjsToEsmExports from './convert-commonjs-to-esm-exports/index.js';
|
|
2
|
-
import * as convertCommonjsToEsmCommons from './convert-commonjs-to-esm-commons/index.js';
|
|
3
|
-
import * as convertCommonjsToEsmRequire from './convert-commonjs-to-esm-require/index.js';
|
|
4
|
-
|
|
5
|
-
export const rules = {
|
|
6
|
-
'convert-commonjs-to-esm-exports': convertCommonjsToEsmExports,
|
|
7
|
-
'convert-commonjs-to-esm-common': convertCommonjsToEsmCommons,
|
|
8
|
-
'convert-commonjs-to-esm-require': convertCommonjsToEsmRequire,
|
|
9
|
-
};
|
|
File without changes
|
|
File without changes
|