@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 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
- ### exports
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
- ### Commons
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 = () => 'In ESM declare "__filename", "__dirname" and "require"';
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 = (path) => {
31
- if (path.parentPath.isObjectProperty())
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');
@@ -0,0 +1,9 @@
1
+ import * as exports from './exports/index.js';
2
+ import * as commons from './commons/index.js';
3
+ import * as require from './require/index.js';
4
+
5
+ export const rules = {
6
+ exports,
7
+ commons,
8
+ require,
9
+ };
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 convertCommonjsToEsmExports from './convert-commonjs-to-esm-exports/index.js';
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-exports': ['off', convertCommonjsToEsmExports],
40
- 'convert-commonjs-to-esm-common': ['off', convertCommonjsToEsmCommons],
41
- 'convert-commonjs-to-esm-require': ['off', convertCommonjsToEsmRequire],
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],
@@ -1,5 +1,5 @@
1
1
  import {operator} from 'putout';
2
- import * as plugin from '../convert-commonjs-to-esm.js';
2
+ import * as plugin from '../convert-commonjs-to-esm/index.js';
3
3
 
4
4
  const {matchFiles} = operator;
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "18.16.1",
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
- };