@putout/plugin-nodejs 18.16.1 → 19.0.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 +3 -5
- package/lib/{convert-commonjs-to-esm-commons → convert-commonjs-to-esm/commons}/index.js +6 -4
- package/lib/convert-commonjs-to-esm/index.js +9 -0
- package/lib/index.js +4 -6
- package/lib/mjs-file/index.js +1 -1
- package/package.json +2 -2
- 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
|
@@ -347,7 +347,7 @@ const {readFile} = require('fs/promises');
|
|
|
347
347
|
const name = 'hello.txt';
|
|
348
348
|
```
|
|
349
349
|
|
|
350
|
-
## convert-commonjs-to-esm
|
|
350
|
+
## convert-commonjs-to-esm/require
|
|
351
351
|
|
|
352
352
|
Convert **CommonJS** **EcmaScript Modules**.
|
|
353
353
|
|
|
@@ -355,8 +355,6 @@ Convert **CommonJS** **EcmaScript Modules**.
|
|
|
355
355
|
>
|
|
356
356
|
> (c) [parceljs](https://parceljs.org/languages/javascript/)
|
|
357
357
|
|
|
358
|
-
### require
|
|
359
|
-
|
|
360
358
|
### ❌ Example of incorrect code
|
|
361
359
|
|
|
362
360
|
```js
|
|
@@ -378,7 +376,7 @@ const args = minimist({
|
|
|
378
376
|
});
|
|
379
377
|
```
|
|
380
378
|
|
|
381
|
-
|
|
379
|
+
## convert-commonjs-to-esm/exports
|
|
382
380
|
|
|
383
381
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/39dd730c35e488db3e2cf8d4b4df0c5a/feb042a49539e6b4b2165558a1c636b705726c47).
|
|
384
382
|
|
|
@@ -394,7 +392,7 @@ module.exports = () => {};
|
|
|
394
392
|
export default () => {};
|
|
395
393
|
```
|
|
396
394
|
|
|
397
|
-
|
|
395
|
+
## convert-commonjs-to-esm/commons
|
|
398
396
|
|
|
399
397
|
### ❌ Example of incorrect code
|
|
400
398
|
|
|
@@ -11,7 +11,7 @@ const initCommons = template.ast(`
|
|
|
11
11
|
const require = createRequire(import.meta.url);
|
|
12
12
|
`);
|
|
13
13
|
|
|
14
|
-
export const report = () => '
|
|
14
|
+
export const report = () => `Declare '__filename', '__dirname' and 'require' in ESM`;
|
|
15
15
|
|
|
16
16
|
export const fix = ({scope}) => {
|
|
17
17
|
const programScope = scope.getProgramParent();
|
|
@@ -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
|
@@ -11,9 +11,7 @@ import * as removeProcessExit from './remove-process-exit/index.js';
|
|
|
11
11
|
import * as addNodePrefix from './add-node-prefix/index.js';
|
|
12
12
|
import * as convertExportsToModuleExports from './convert-exports-to-module-exports/index.js';
|
|
13
13
|
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';
|
|
14
|
+
import * as convertCommonjsToEsm from './convert-commonjs-to-esm/index.js';
|
|
17
15
|
import * as cjsFile from './cjs-file/index.js';
|
|
18
16
|
import * as mjsFile from './mjs-file/index.js';
|
|
19
17
|
import * as renameFileCjsToJs from './rename-file-cjs-to-js/index.js';
|
|
@@ -36,9 +34,9 @@ export const rules = {
|
|
|
36
34
|
'convert-exports-to-module-exports': convertExportsToModuleExports,
|
|
37
35
|
|
|
38
36
|
'convert-esm-to-commonjs': ['off', convertEsmToCommonjs],
|
|
39
|
-
'convert-commonjs-to-esm
|
|
40
|
-
'convert-commonjs-to-esm
|
|
41
|
-
'convert-commonjs-to-esm
|
|
37
|
+
'convert-commonjs-to-esm/exports': ['off', convertCommonjsToEsm.rules.exports],
|
|
38
|
+
'convert-commonjs-to-esm/common': ['off', convertCommonjsToEsm.rules.commons],
|
|
39
|
+
'convert-commonjs-to-esm/require': ['off', convertCommonjsToEsm.rules.require],
|
|
42
40
|
|
|
43
41
|
'cjs-file': ['off', cjsFile],
|
|
44
42
|
'mjs-file': ['off', mjsFile],
|
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.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",
|
|
@@ -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
|