@putout/plugin-nodejs 14.0.1 → 15.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.
@@ -1,7 +1,5 @@
1
- 'use strict';
2
-
3
- const {isBuiltin} = require('node:module');
4
- const {types, operator} = require('putout');
1
+ import {isBuiltin} from 'node:module';
2
+ import {types, operator} from 'putout';
5
3
 
6
4
  const {
7
5
  setLiteralValue,
@@ -12,11 +10,11 @@ const {isCallExpression} = types;
12
10
 
13
11
  const REQUIRE = 'require("__a")';
14
12
 
15
- module.exports.report = ({value}) => {
13
+ export const report = ({value}) => {
16
14
  return `Use 'node:${value}' instead of '${value}'`;
17
15
  };
18
16
 
19
- module.exports.fix = ({path, value}) => {
17
+ export const fix = ({path, value}) => {
20
18
  if (isCallExpression(path)) {
21
19
  const arg = path.get('arguments.0');
22
20
  setLiteralValue(arg, `node:${value}`);
@@ -28,7 +26,7 @@ module.exports.fix = ({path, value}) => {
28
26
  setLiteralValue(source, `node:${value}`);
29
27
  };
30
28
 
31
- module.exports.traverse = ({push}) => ({
29
+ export const traverse = ({push}) => ({
32
30
  [REQUIRE](path) {
33
31
  const {__a} = getTemplateValues(path, REQUIRE);
34
32
  const {value} = __a;
@@ -1,10 +1,17 @@
1
- 'use strict';
2
-
3
- const {operator} = require('putout');
4
- const plugin = require('../convert-esm-to-commonjs');
1
+ import {operator} from 'putout';
2
+ import * as plugin from '../convert-esm-to-commonjs/index.js';
5
3
 
6
4
  const {matchFiles} = operator;
7
-
8
- module.exports = matchFiles({
5
+ const {
6
+ report,
7
+ fix,
8
+ scan,
9
+ } = matchFiles({
9
10
  '*.cjs': plugin,
10
11
  });
12
+
13
+ export {
14
+ report,
15
+ fix,
16
+ scan,
17
+ };
@@ -1,13 +1,12 @@
1
- 'use strict';
1
+ import {operator} from 'putout';
2
2
 
3
- const {operator} = require('putout');
4
3
  const {compute} = operator;
5
4
 
6
5
  const isNumber = (a) => typeof a === 'number';
7
6
 
8
- module.exports.report = () => `Use 'Buffer.alloc()' or 'Buffer.from()' instead of 'Buffer()' and 'new Buffer()'`;
7
+ export const report = () => `Use 'Buffer.alloc()' or 'Buffer.from()' instead of 'Buffer()' and 'new Buffer()'`;
9
8
 
10
- module.exports.match = () => ({
9
+ export const match = () => ({
11
10
  'new Buffer(__a)': (vars, path) => {
12
11
  const __aPath = path.get('arguments.0');
13
12
  const [is] = compute(__aPath);
@@ -16,7 +15,7 @@ module.exports.match = () => ({
16
15
  },
17
16
  });
18
17
 
19
- module.exports.replace = () => ({
18
+ export const replace = () => ({
20
19
  'new Buffer(__a)': transform,
21
20
  'new Buffer(__a, __b)': transform,
22
21
  'Buffer(__a)': transform,
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- const {template, operator} = require('putout');
1
+ import {template, operator} from 'putout';
4
2
 
5
3
  const {
6
4
  getPathAfterImports,
@@ -13,9 +11,9 @@ const initCommons = template.ast(`
13
11
  const require = createRequire(import.meta.url);
14
12
  `);
15
13
 
16
- module.exports.report = () => '"__filename", "__dirname" and "require" should be declared in ESM';
14
+ export const report = () => '"__filename", "__dirname" and "require" should be declared in ESM';
17
15
 
18
- module.exports.fix = ({scope}) => {
16
+ export const fix = ({scope}) => {
19
17
  const programScope = scope.getProgramParent();
20
18
  const body = programScope.path.get('body');
21
19
  const afterImportPath = getPathAfterImports(body);
@@ -23,13 +21,13 @@ module.exports.fix = ({scope}) => {
23
21
  insertBefore(afterImportPath, initCommons);
24
22
  };
25
23
 
26
- module.exports.include = () => [
24
+ export const include = () => [
27
25
  '__filename',
28
26
  '__dirname',
29
27
  'require',
30
28
  ];
31
29
 
32
- module.exports.filter = ({scope}) => {
30
+ export const filter = ({scope}) => {
33
31
  const isDirname = scope.hasBinding('__dirname');
34
32
  const isFilename = scope.hasBinding('__filename');
35
33
  const isRequire = scope.hasBinding('require');
@@ -1,20 +1,19 @@
1
- 'use strict';
2
-
3
- const {types, operator} = require('putout');
4
- const {replaceWith} = operator;
1
+ import {types, operator} from 'putout';
5
2
 
6
3
  const {
4
+ exportSpecifier,
7
5
  isIdentifier,
8
- ExportNamedDeclaration,
9
6
  isImportSpecifier,
10
- ExportSpecifier,
7
+ exportNamedDeclaration,
11
8
  } = types;
12
9
 
13
- module.exports.report = () => `Use 'ESM' instead of 'CommonJS'`;
10
+ const {replaceWith} = operator;
11
+
12
+ export const report = () => `Use 'ESM' instead of 'CommonJS'`;
14
13
 
15
- module.exports.exclude = () => ['__, __'];
14
+ export const exclude = () => ['__, __'];
16
15
 
17
- module.exports.match = () => ({
16
+ export const match = () => ({
18
17
  'module.exports.__a = __b': ({__a, __b}, path) => {
19
18
  const {name} = __a;
20
19
 
@@ -36,7 +35,7 @@ module.exports.match = () => ({
36
35
  },
37
36
  });
38
37
 
39
- module.exports.replace = () => ({
38
+ export const replace = () => ({
40
39
  'module.exports = __a': 'export default __a',
41
40
  'module.exports.__a = __b': ({__a, __b}, path) => {
42
41
  const {name} = __a;
@@ -56,10 +55,10 @@ function addExportToBinding(name, path) {
56
55
  if (isImportSpecifier(bindingPath)) {
57
56
  const {imported} = bindingPath.node;
58
57
 
59
- return ExportNamedDeclaration(null, [ExportSpecifier(imported, imported)]);
58
+ return exportNamedDeclaration(null, [exportSpecifier(imported, imported)]);
60
59
  }
61
60
 
62
- const exportNode = ExportNamedDeclaration(bindingPath.node);
61
+ const exportNode = exportNamedDeclaration(bindingPath.node);
63
62
 
64
63
  replaceWith(bindingPath, exportNode);
65
64
 
@@ -1,44 +1,42 @@
1
- 'use strict';
2
-
3
- const justCamelCase = require('just-camel-case');
4
-
5
- const {
1
+ import {
6
2
  types,
7
3
  operator,
8
4
  template,
9
- } = require('putout');
10
-
11
- const {replaceWith, insertBefore} = operator;
5
+ } from 'putout';
6
+ import justCamelCase from 'just-camel-case';
12
7
 
13
8
  const {
9
+ awaitExpression,
10
+ identifier,
11
+ importDeclaration,
14
12
  isFunction,
15
13
  isObjectPattern,
14
+ isArrayPattern,
16
15
  isIdentifier,
17
16
  isStringLiteral,
18
- AwaitExpression,
19
- ImportDeclaration,
20
- ImportDefaultSpecifier,
21
- Identifier,
17
+ importDefaultSpecifier,
22
18
  } = types;
23
19
 
20
+ const {replaceWith, insertBefore} = operator;
21
+
24
22
  const camelCase = (a) => justCamelCase(a.replace('@', ''));
25
23
 
26
- module.exports.report = () => `Use 'ESM' instead of 'CommonJS'`;
24
+ export const report = () => `Use 'ESM' instead of 'CommonJS'`;
27
25
 
28
26
  const __B = 'declarations.0.init.arguments.0';
29
27
 
30
28
  const createImport = ({name, source}) => {
31
29
  const specifiers = [
32
- ImportDefaultSpecifier(name),
30
+ importDefaultSpecifier(name),
33
31
  ];
34
32
 
35
- return ImportDeclaration(specifiers, source);
33
+ return importDeclaration(specifiers, source);
36
34
  };
37
35
 
38
36
  const createFnDeclaration = template('const NAME1 = FN(NAME2)');
39
37
  const isPackage = ({value}) => /package(\.json)?$/.test(value);
40
38
 
41
- module.exports.match = () => ({
39
+ export const match = () => ({
42
40
  'const __a = require(__b)': ({__b}, path) => {
43
41
  // exclude jsons while not supported
44
42
  if (/\.json/.test(__b.value))
@@ -64,9 +62,9 @@ module.exports.match = () => ({
64
62
  'const __a = require("__b").__c(__args)': checkCall,
65
63
  });
66
64
 
67
- module.exports.replace = () => ({
65
+ export const replace = () => ({
68
66
  'const __a = require(".")': 'import __a from "./index.js"',
69
- 'const __a = require(__b).default': 'import __a from "__b"',
67
+ 'const __a = require("__b").default': 'import __a from "__b"',
70
68
  'const __a = require(__b).__c': `{
71
69
  const {__c} = require(__b);
72
70
  const __a = __c;
@@ -103,20 +101,35 @@ module.exports.replace = () => ({
103
101
  return `import {${importsStr}} from "${value}" ${assertion}`;
104
102
  }
105
103
 
104
+ if (isArrayPattern(__a)) {
105
+ const imports = [];
106
+
107
+ for (const [index, value] of __a.elements.entries()) {
108
+ if (!value)
109
+ continue;
110
+
111
+ imports.push(`'${index}' as ${value.name}`);
112
+ }
113
+
114
+ const importsStr = imports.join(',');
115
+
116
+ return `import {${importsStr}} from "${value}" ${assertion}`;
117
+ }
118
+
106
119
  return `import __a from "${value}" ${assertion}`;
107
120
  },
108
121
  'const __a = __b(require(__c))': ({__a, __b, __c}, path) => {
109
122
  const name = `_${__a.name}`;
110
123
 
111
124
  const importNode = createImport({
112
- name: Identifier(name),
125
+ name: identifier(name),
113
126
  source: __c,
114
127
  });
115
128
 
116
129
  const declarationNode = createFnDeclaration({
117
130
  NAME1: __a,
118
131
  FN: __b,
119
- NAME2: Identifier(name),
132
+ NAME2: identifier(name),
120
133
  });
121
134
 
122
135
  insertBefore(path, [importNode]);
@@ -155,7 +168,7 @@ function applyDynamicImport(path) {
155
168
  const {node} = initPath;
156
169
 
157
170
  initPath.node.callee.name = 'import';
158
- replaceWith(initPath, AwaitExpression(node));
171
+ replaceWith(initPath, awaitExpression(node));
159
172
 
160
173
  return path;
161
174
  }
@@ -1,10 +1,8 @@
1
- 'use strict';
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';
2
4
 
3
- const convertCommonjsToEsmExports = require('./convert-commonjs-to-esm-exports');
4
- const convertCommonjsToEsmCommons = require('./convert-commonjs-to-esm-commons');
5
- const convertCommonjsToEsmRequire = require('./convert-commonjs-to-esm-require');
6
-
7
- module.exports.rules = {
5
+ export const rules = {
8
6
  'convert-commonjs-to-esm-exports': convertCommonjsToEsmExports,
9
7
  'convert-commonjs-to-esm-common': convertCommonjsToEsmCommons,
10
8
  'convert-commonjs-to-esm-require': convertCommonjsToEsmRequire,
@@ -1,13 +1,12 @@
1
- 'use strict';
1
+ import {operator} from 'putout';
2
2
 
3
- const {operator} = require('putout');
4
3
  const {isESM} = operator;
5
4
 
6
- module.exports.report = () => `Use 'import.meta.url' instead of '__dirname'`;
5
+ export const report = () => `Use 'import.meta.url' instead of '__dirname'`;
7
6
 
8
- module.exports.filter = isESM;
7
+ export const filter = isESM;
9
8
 
10
- module.exports.replace = () => ({
9
+ export const replace = () => ({
11
10
  'join(__dirname, __a)': 'new URL(__a, import.meta.url).pathname',
12
11
  'path.join(__dirname, __a)': 'new URL(__a, import.meta.url).pathname',
13
12
  });
@@ -1,6 +1,5 @@
1
- 'use strict';
1
+ import {types} from 'putout';
2
2
 
3
- const {types} = require('putout');
4
3
  const {isImportDefaultSpecifier} = types;
5
4
 
6
5
  const BODY = '{__body}';
@@ -9,9 +8,9 @@ const GEN_FN = `function* __a(__args) ${BODY}`;
9
8
  const ASYNC_FN = `async function __a(__args) ${BODY}`;
10
9
  const CLASS = `class __a ${BODY}`;
11
10
 
12
- module.exports.report = () => `Use 'CommonJS' instead of 'ESM'`;
11
+ export const report = () => `Use 'CommonJS' instead of 'ESM'`;
13
12
 
14
- module.exports.replace = () => ({
13
+ export const replace = () => ({
15
14
  'export default __a': 'module.exports = __a',
16
15
  [`export ${CLASS}`]: `module.exports.__a = ${CLASS}`,
17
16
  [`export ${FN}`]: `module.epxorts.__a = ${FN}`,
@@ -1,7 +1,5 @@
1
- 'use strict';
1
+ export const report = () => `Use 'module.exports' instead of 'exports'`;
2
2
 
3
- module.exports.report = () => `Use 'module.exports' instead of 'exports'`;
4
-
5
- module.exports.replace = () => ({
3
+ export const replace = () => ({
6
4
  'exports.__a': 'module.exports.__a',
7
5
  });
@@ -1,7 +1,5 @@
1
- 'use strict';
1
+ export const report = () => '"fs/promises" should be used instead of "fs.promises"';
2
2
 
3
- module.exports.report = () => '"fs/promises" should be used instead of "fs.promises"';
4
-
5
- module.exports.replace = () => ({
3
+ export const replace = () => ({
6
4
  'const __a = require("fs").promises': 'const __a = require("fs/promises")',
7
5
  });
@@ -1,15 +1,16 @@
1
- 'use strict';
2
-
3
- const {types: t, operator} = require('putout');
1
+ import {
2
+ types as t,
3
+ operator,
4
+ } from 'putout';
4
5
 
5
6
  const {replaceWith, remove} = operator;
6
7
 
7
8
  const NOT_COMPUTED = false;
8
9
  const SHORTHAND = true;
9
10
 
10
- module.exports.report = () => `fs.promises should be used instead of fs`;
11
+ export const report = () => `fs.promises should be used instead of fs`;
11
12
 
12
- module.exports.fix = ({path, promisified}) => {
13
+ export const fix = ({path, promisified}) => {
13
14
  const props = [];
14
15
 
15
16
  for (const path of promisified) {
@@ -32,7 +33,7 @@ module.exports.fix = ({path, promisified}) => {
32
33
  replaceWith(path.get('id'), t.ObjectPattern(props));
33
34
  };
34
35
 
35
- module.exports.find = (ast, {push, traverse}) => {
36
+ export const find = (ast, {push, traverse}) => {
36
37
  const fs = [];
37
38
  const promisified = [];
38
39
 
@@ -1,13 +1,12 @@
1
- 'use strict';
1
+ import {types} from 'putout';
2
2
 
3
- const {types} = require('putout');
4
3
  const {isFunction} = types;
5
4
 
6
- module.exports.report = () => `"process.exit" should be used instead of top-level return`;
5
+ export const report = () => `"process.exit" should be used instead of top-level return`;
7
6
 
8
- module.exports.filter = (path) => !path.findParent(isFunction);
7
+ export const filter = (path) => !path.findParent(isFunction);
9
8
 
10
- module.exports.replace = () => ({
9
+ export const replace = () => ({
11
10
  'return __a()': '{__a(); process.exit()}',
12
11
  'return __a': 'process.exit()',
13
12
  'return': 'process.exit()',
@@ -1,13 +1,12 @@
1
- 'use strict';
1
+ import {operator} from 'putout';
2
2
 
3
- const {operator} = require('putout');
4
3
  const {isESM} = operator;
5
4
  const not = (fn) => (...a) => !fn(...a);
6
5
 
7
- module.exports.report = () => `Use __dirname instead of 'import.meta.url' in CommonJS`;
6
+ export const report = () => `Use __dirname instead of 'import.meta.url' in CommonJS`;
8
7
 
9
- module.exports.filter = not(isESM);
8
+ export const filter = not(isESM);
10
9
 
11
- module.exports.replace = () => ({
10
+ export const replace = () => ({
12
11
  'new URL(__a, import.meta.url).pathname': 'join(__dirname, __a)',
13
12
  });
@@ -1,6 +1,8 @@
1
- 'use strict';
1
+ import {createRequire} from 'node:module';
2
2
 
3
- module.exports.declare = () => ({
3
+ const require = createRequire(import.meta.url);
4
+
5
+ export const declare = () => ({
4
6
  ...require('./modules/events'),
5
7
  ...require('./modules/fs'),
6
8
  ...require('./modules/fs-promises'),
@@ -1,6 +1,5 @@
1
- 'use strict';
1
+ import {operator} from 'putout';
2
2
 
3
- const {operator} = require('putout');
4
3
  const {
5
4
  remove,
6
5
  compareAny,
@@ -13,14 +12,14 @@ const REQUIRE_LIST = [
13
12
  'const __a = require(__b).__c',
14
13
  ];
15
14
 
16
- module.exports.report = ({path}) => {
15
+ export const report = ({path}) => {
17
16
  const idPath = path.get('declarations.0.id');
18
17
  const id = String(idPath).replace(/\s+/g, '');
19
18
 
20
19
  return `Declare '${id}' after last 'require()'`;
21
20
  };
22
21
 
23
- module.exports.fix = ({path, lastRequire}) => {
22
+ export const fix = ({path, lastRequire}) => {
24
23
  const {node} = path;
25
24
 
26
25
  delete node.loc;
@@ -30,7 +29,7 @@ module.exports.fix = ({path, lastRequire}) => {
30
29
  insertAfter(lastRequire, node);
31
30
  };
32
31
 
33
- module.exports.traverse = ({push, pathStore}) => ({
32
+ export const traverse = ({push, pathStore}) => ({
34
33
  'const __a = __b': (path) => {
35
34
  if (!path.parentPath.isProgram())
36
35
  return;
@@ -1,15 +1,14 @@
1
- 'use strict';
1
+ import {isDeepStrictEqual} from 'node:util';
2
+ import {operator} from 'putout';
2
3
 
3
- const {isDeepStrictEqual} = require('node:util');
4
- const {operator} = require('putout');
5
4
  const {
6
5
  replaceWithMultiple,
7
6
  remove,
8
7
  } = operator;
9
8
 
10
- module.exports.report = () => 'Group require by id';
9
+ export const report = () => 'Group require by id';
11
10
 
12
- module.exports.fix = ({grouped}) => {
11
+ export const fix = ({grouped}) => {
13
12
  const [first, ...others] = grouped;
14
13
  const nodes = [first.node];
15
14
 
@@ -25,7 +24,7 @@ module.exports.fix = ({grouped}) => {
25
24
  replaceWithMultiple(first, nodes);
26
25
  };
27
26
 
28
- module.exports.traverse = ({pathStore, push}) => ({
27
+ export const traverse = ({pathStore, push}) => ({
29
28
  'const __ = require(__)': (path) => {
30
29
  if (!path.parentPath.isProgram())
31
30
  return;
package/lib/index.js CHANGED
@@ -1,34 +1,27 @@
1
- 'use strict';
1
+ import * as convertBufferToBufferAlloc from './convert-buffer-to-buffer-alloc/index.js';
2
+ import * as convertFsPromises from './convert-fs-promises/index.js';
3
+ import * as convertPromisifyToFsPromises from './convert-promisify-to-fs-promises/index.js';
4
+ import * as convertDirnameToUrl from './convert-dirname-to-url/index.js';
5
+ import * as convertUrlToDirname from './convert-url-to-dirname/index.js';
6
+ import * as convertTopLevelReturn from './convert-top-level-return/index.js';
7
+ import * as declare from './declare/index.js';
8
+ import * as declareAfterRequire from './declare-after-require/index.js';
9
+ import * as removeProcessExit from './remove-process-exit/index.js';
10
+ import * as addNodePrefix from './add-node-prefix/index.js';
11
+ import * as convertExportsToModuleExports from './convert-exports-to-module-exports/index.js';
12
+ import * as convertEsmToCommonjs from './convert-esm-to-commonjs/index.js';
13
+ import * as convertCommonjsToEsmExports from './convert-commonjs-to-esm-exports/index.js';
14
+ import * as convertCommonjsToEsmCommons from './convert-commonjs-to-esm-commons/index.js';
15
+ import * as convertCommonjsToEsmRequire from './convert-commonjs-to-esm-require/index.js';
16
+ import * as cjsFile from './cjs-file/index.js';
17
+ import * as mjsFile from './mjs-file/index.js';
18
+ import * as renameFileCjsToJs from './rename-file-cjs-to-js/index.js';
19
+ import * as renameFileMjsToJs from './rename-file-mjs-to-js/index.js';
20
+ import * as strictMode from './strict-mode/index.js';
21
+ import * as removeUselessPromisify from './remove-useless-promisify/index.js';
22
+ import * as groupRequireById from './group-require-by-id/index.js';
2
23
 
3
- const convertBufferToBufferAlloc = require('./convert-buffer-to-buffer-alloc');
4
- const convertFsPromises = require('./convert-fs-promises');
5
- const convertPromisifyToFsPromises = require('./convert-promisify-to-fs-promises');
6
- const convertDirnameToUrl = require('./convert-dirname-to-url');
7
- const convertUrlToDirname = require('./convert-url-to-dirname');
8
- const convertTopLevelReturn = require('./convert-top-level-return');
9
- const declare = require('./declare');
10
- const declareAfterRequire = require('./declare-after-require');
11
- const removeProcessExit = require('./remove-process-exit');
12
- const addNodePrefix = require('./add-node-prefix');
13
- const convertExportsToModuleExports = require('./convert-exports-to-module-exports');
14
-
15
- const convertEsmToCommonjs = require('./convert-esm-to-commonjs');
16
-
17
- const convertCommonjsToEsmExports = require('./convert-commonjs-to-esm-exports');
18
- const convertCommonjsToEsmCommons = require('./convert-commonjs-to-esm-commons');
19
- const convertCommonjsToEsmRequire = require('./convert-commonjs-to-esm-require');
20
-
21
- const cjsFile = require('./cjs-file');
22
- const mjsFile = require('./mjs-file');
23
-
24
- const renameFileCjsToJs = require('./rename-file-cjs-to-js');
25
- const renameFileMjsToJs = require('./rename-file-mjs-to-js');
26
-
27
- const strictMode = require('./strict-mode');
28
- const removeUselessPromisify = require('./remove-useless-promisify');
29
- const groupRequireById = require('./group-require-by-id');
30
-
31
- module.exports.rules = {
24
+ export const rules = {
32
25
  'convert-buffer-to-buffer-alloc': convertBufferToBufferAlloc,
33
26
  'convert-fs-promises': convertFsPromises,
34
27
  'convert-promisify-to-fs-promises': convertPromisifyToFsPromises,
@@ -1,10 +1,17 @@
1
- 'use strict';
2
-
3
- const {operator} = require('putout');
4
- const plugin = require('../convert-commonjs-to-esm');
1
+ import {operator} from 'putout';
2
+ import * as plugin from '../convert-commonjs-to-esm.js';
5
3
 
6
4
  const {matchFiles} = operator;
7
-
8
- module.exports = matchFiles({
5
+ const {
6
+ report,
7
+ fix,
8
+ scan,
9
+ } = matchFiles({
9
10
  '*.mjs': plugin,
10
11
  });
12
+
13
+ export {
14
+ report,
15
+ fix,
16
+ scan,
17
+ };
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ export const report = () => '"process.exit" should not be used';
2
2
 
3
- module.exports.report = () => '"process.exit" should not be used';
4
-
5
- module.exports.replace = () => ({
3
+ export const replace = () => ({
6
4
  'process.exit()': '',
7
5
  'process["exit"]()': '',
8
6
  });
@@ -1,7 +1,5 @@
1
- 'use strict';
1
+ export const report = () => `Calling 'promisify' on a function that returns a Promise is likely a mistake`;
2
2
 
3
- module.exports.report = () => `Calling 'promisify' on a function that returns a Promise is likely a mistake`;
4
-
5
- module.exports.replace = () => ({
3
+ export const replace = () => ({
6
4
  'promisify(async (__args) => __body)': 'async (__args) => __body',
7
5
  });
@@ -1,12 +1,21 @@
1
- 'use strict';
1
+ import {operator} from 'putout';
2
2
 
3
- const {operator} = require('putout');
4
3
  const {renameFiles} = operator;
5
4
 
6
- module.exports = renameFiles({
5
+ const {
6
+ report,
7
+ fix,
8
+ scan,
9
+ } = renameFiles({
7
10
  type: 'commonjs',
8
11
  mask: '*.cjs',
9
12
  rename(name) {
10
13
  return name.replace(/cjs$/, 'js');
11
14
  },
12
15
  });
16
+
17
+ export {
18
+ report,
19
+ fix,
20
+ scan,
21
+ };
@@ -1,12 +1,20 @@
1
- 'use strict';
1
+ import {operator} from 'putout';
2
2
 
3
- const {operator} = require('putout');
4
3
  const {renameFiles} = operator;
5
-
6
- module.exports = renameFiles({
4
+ const {
5
+ report,
6
+ fix,
7
+ scan,
8
+ } = renameFiles({
7
9
  type: 'module',
8
10
  mask: '*.mjs',
9
11
  rename(name) {
10
12
  return name.replace(/mjs$/, 'js');
11
13
  },
12
14
  });
15
+
16
+ export {
17
+ report,
18
+ fix,
19
+ scan,
20
+ };
@@ -1,18 +1,18 @@
1
- 'use strict';
1
+ import {types} from 'putout';
2
2
 
3
3
  const {
4
4
  isExpressionStatement,
5
- StringLiteral,
6
- ExpressionStatement,
7
- } = require('putout').types;
5
+ stringLiteral,
6
+ expressionStatement,
7
+ } = types;
8
8
 
9
- module.exports.report = () => `Add missing 'use strict' directive on top of CommonJS`;
9
+ export const report = () => `Add missing 'use strict' directive on top of CommonJS`;
10
10
 
11
- module.exports.fix = ({node}) => {
12
- node.body.unshift(ExpressionStatement(StringLiteral('use strict')));
11
+ export const fix = ({node}) => {
12
+ node.body.unshift(expressionStatement(stringLiteral('use strict')));
13
13
  };
14
14
 
15
- module.exports.traverse = ({push, store}) => ({
15
+ export const traverse = ({push, store}) => ({
16
16
  'ImportDeclaration|ExportNamedDeclaration|ExportDefaultDeclaration|ExportAllDeclaration|TypeAlias'() {
17
17
  store('is-module', true);
18
18
  },
@@ -1,10 +1,8 @@
1
- 'use strict';
1
+ import * as addMissing from './add-missing/index.js';
2
+ import * as removeUseless from './remove-useless/index.js';
3
+ import * as removeIllegal from './remove-illegal/index.js';
2
4
 
3
- const addMissing = require('./add-missing');
4
- const removeUseless = require('./remove-useless');
5
- const removeIllegal = require('./remove-illegal');
6
-
7
- module.exports.rules = {
5
+ export const rules = {
8
6
  'add-missing': addMissing,
9
7
  'remove-useless': removeUseless,
10
8
  'remove-illegal': removeIllegal,
@@ -1,6 +1,5 @@
1
- 'use strict';
1
+ import {operator, types} from 'putout';
2
2
 
3
- const {operator, types} = require('putout');
4
3
  const {
5
4
  isArrayPattern,
6
5
  isObjectPattern,
@@ -11,12 +10,12 @@ const {
11
10
 
12
11
  const {remove} = operator;
13
12
 
14
- module.exports.report = () => `Avoid illegal 'use strict'`;
13
+ export const report = () => `Avoid illegal 'use strict'`;
15
14
 
16
- module.exports.fix = (path) => {
15
+ export const fix = (path) => {
17
16
  remove(path);
18
17
  };
19
- module.exports.traverse = ({push}) => ({
18
+ export const traverse = ({push}) => ({
20
19
  DirectiveLiteral(path) {
21
20
  const fnPath = path.parentPath.parentPath.parentPath;
22
21
 
@@ -1,16 +1,15 @@
1
- 'use strict';
1
+ import {types, operator} from 'putout';
2
2
 
3
- const {types, operator} = require('putout');
4
3
  const {remove} = operator;
5
4
  const {isProgram} = types;
6
5
 
7
6
  const isStrictMode = (a) => a.node.value.value === 'use strict';
8
7
 
9
- module.exports.report = () => `Avoid 'use strict' in ESM`;
8
+ export const report = () => `Avoid 'use strict' in ESM`;
10
9
 
11
- module.exports.fix = (path) => remove(path);
10
+ export const fix = (path) => remove(path);
12
11
 
13
- module.exports.traverse = ({push, store}) => ({
12
+ export const traverse = ({push, store}) => ({
14
13
  'await __a(__args)'({scope}) {
15
14
  if (isProgram(scope.block))
16
15
  store('is-module', true);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "14.0.1",
4
- "type": "commonjs",
3
+ "version": "15.0.0",
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",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-nodejs#readme",
@@ -39,28 +39,27 @@
39
39
  "nodejs"
40
40
  ],
41
41
  "devDependencies": {
42
- "@putout/eslint-flat": "^2.0.0",
42
+ "@putout/eslint-flat": "^3.0.0",
43
43
  "@putout/plugin-declare": "*",
44
44
  "@putout/plugin-declare-before-reference": "*",
45
45
  "@putout/plugin-putout": "*",
46
46
  "@putout/plugin-reuse-duplicate-init": "*",
47
47
  "@putout/plugin-typescript": "*",
48
- "@putout/test": "^11.0.0",
48
+ "@putout/test": "^12.0.0",
49
49
  "c8": "^10.0.0",
50
50
  "eslint": "^9.0.0",
51
51
  "eslint-plugin-n": "^17.0.0",
52
- "eslint-plugin-putout": "^24.0.0",
53
- "lerna": "^6.0.1",
54
- "madrun": "^10.0.0",
52
+ "eslint-plugin-putout": "^26.0.0",
53
+ "madrun": "^11.0.0",
55
54
  "montag": "^1.2.1",
56
55
  "nodemon": "^3.0.1"
57
56
  },
58
57
  "peerDependencies": {
59
- "putout": ">=38"
58
+ "putout": ">=39"
60
59
  },
61
60
  "license": "MIT",
62
61
  "engines": {
63
- "node": ">=18.6"
62
+ "node": ">=20"
64
63
  },
65
64
  "publishConfig": {
66
65
  "access": "public"