@putout/plugin-esm 2.3.0 → 3.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,6 +1,4 @@
1
- 'use strict';
2
-
3
- const {types, operator} = require('putout');
1
+ import {types, operator} from 'putout';
4
2
 
5
3
  const {
6
4
  compare,
@@ -8,13 +6,13 @@ const {
8
6
  remove,
9
7
  } = operator;
10
8
 
11
- const {ExportNamespaceSpecifier} = types;
9
+ const {exportNamespaceSpecifier} = types;
12
10
 
13
- module.exports.report = () => `Use 'export *' instead of 'import/export'`;
11
+ export const report = () => `Use 'export *' instead of 'import/export'`;
14
12
 
15
13
  const IMPORT = 'import * as __a from "__b"';
16
14
 
17
- module.exports.fix = ({path, current}) => {
15
+ export const fix = ({path, current}) => {
18
16
  const {exported} = current.node.specifiers[0];
19
17
 
20
18
  current.node.source = path.node.source;
@@ -23,13 +21,13 @@ module.exports.fix = ({path, current}) => {
23
21
  delete current.node.exported;
24
22
 
25
23
  current.node.specifiers = [
26
- ExportNamespaceSpecifier(exported),
24
+ exportNamespaceSpecifier(exported),
27
25
  ];
28
26
 
29
27
  remove(path);
30
28
  };
31
29
 
32
- module.exports.traverse = ({push}) => ({
30
+ export const traverse = ({push}) => ({
33
31
  [IMPORT]: (path) => {
34
32
  const {__a} = getTemplateValues(path, IMPORT);
35
33
  const {name} = __a;
@@ -1,17 +1,15 @@
1
- 'use strict';
2
-
3
1
  const setImportType = (path, type) => {
4
2
  path.node.options.properties[0].key.name = type;
5
3
  };
6
4
 
7
- module.exports.report = () => `Use 'with' instead of 'assert'`;
5
+ export const report = () => `Use 'with' instead of 'assert'`;
8
6
 
9
- module.exports.include = () => [
7
+ export const include = () => [
10
8
  'ImportDeclaration',
11
9
  'import(__a, {assert: {type: "json"}})',
12
10
  ];
13
11
 
14
- module.exports.fix = (path) => {
12
+ export const fix = (path) => {
15
13
  if (path.isImportDeclaration()) {
16
14
  delete path.node.extra.deprecatedAssertSyntax;
17
15
  return;
@@ -20,7 +18,7 @@ module.exports.fix = (path) => {
20
18
  setImportType(path, 'with');
21
19
  };
22
20
 
23
- module.exports.filter = (path) => {
21
+ export const filter = (path) => {
24
22
  const {extra} = path.node;
25
23
 
26
24
  if (path.isImportDeclaration())
@@ -1,6 +1,5 @@
1
- 'use strict';
1
+ import {types, operator} from 'putout';
2
2
 
3
- const {types, operator} = require('putout');
4
3
  const {
5
4
  isImportDeclaration,
6
5
  isExportDeclaration,
@@ -9,9 +8,9 @@ const {
9
8
  const {replaceWith} = operator;
10
9
  const isESMNode = (a) => isImportDeclaration(a) || isExportDeclaration(a);
11
10
 
12
- module.exports.report = () => `Declare imports first`;
11
+ export const report = () => `Declare imports first`;
13
12
 
14
- module.exports.fix = ({path, importPath}) => {
13
+ export const fix = ({path, importPath}) => {
15
14
  let prev = path;
16
15
  let preventInfiniteLoop = 500;
17
16
 
@@ -29,7 +28,7 @@ module.exports.fix = ({path, importPath}) => {
29
28
  }
30
29
  };
31
30
 
32
- module.exports.traverse = ({push, pathStore}) => ({
31
+ export const traverse = ({push, pathStore}) => ({
33
32
  ImportDeclaration: (path) => {
34
33
  pathStore(path);
35
34
  },
@@ -1,7 +1,6 @@
1
- 'use strict';
1
+ import {isDeepStrictEqual} from 'node:util';
2
+ import {types, operator} from 'putout';
2
3
 
3
- const {isDeepStrictEqual} = require('node:util');
4
- const {types, operator} = require('putout');
5
4
  const {isImportDeclaration} = types;
6
5
 
7
6
  const {
@@ -9,9 +8,9 @@ const {
9
8
  remove,
10
9
  } = operator;
11
10
 
12
- module.exports.report = () => `Group imports by source: 'builtins', 'external', 'hashed', 'internal'`;
11
+ export const report = () => `Group imports by source: 'builtins', 'external', 'hashed', 'internal'`;
13
12
 
14
- module.exports.fix = ({grouped}) => {
13
+ export const fix = ({grouped}) => {
15
14
  const [first, ...others] = grouped;
16
15
  const nodes = [first.node];
17
16
 
@@ -24,7 +23,7 @@ module.exports.fix = ({grouped}) => {
24
23
  replaceWithMultiple(first, nodes);
25
24
  };
26
25
 
27
- module.exports.traverse = ({pathStore, push}) => ({
26
+ export const traverse = ({pathStore, push}) => ({
28
27
  ImportDeclaration: pathStore,
29
28
  Program: {
30
29
  exit(path) {
package/lib/index.js CHANGED
@@ -1,16 +1,14 @@
1
- 'use strict';
1
+ import * as declareImportsFirst from './declare-imports-first/index.js';
2
+ import * as groupImportsBySource from './group-imports-by-source/index.js';
3
+ import * as removeQuotesFromImportAssertions from './remove-quotes-from-import-assertions/index.js';
4
+ import * as sortImportsBySpecifiers from './sort-imports-by-specifiers/index.js';
5
+ import * as removeEmptyImport from './remove-empty-import/index.js';
6
+ import * as removeEmptyExport from './remove-empty-export/index.js';
7
+ import * as mergeDuplicateImports from './merge-duplicate-imports/index.js';
8
+ import * as convertAssertToWith from './convert-assert-to-with/index.js';
9
+ import * as applyExportFrom from './apply-export-from/index.js';
2
10
 
3
- const declareImportsFirst = require('./declare-imports-first');
4
- const groupImportsBySource = require('./group-imports-by-source');
5
- const removeQuotesFromImportAssertions = require('./remove-quotes-from-import-assertions');
6
- const sortImportsBySpecifiers = require('./sort-imports-by-specifiers');
7
- const removeEmptyImport = require('./remove-empty-import');
8
- const removeEmptyExport = require('./remove-empty-export');
9
- const mergeDuplicateImports = require('./merge-duplicate-imports');
10
- const convertAssertToWith = require('./convert-assert-to-with');
11
- const applyExportFrom = require('./apply-export-from');
12
-
13
- module.exports.rules = {
11
+ export const rules = {
14
12
  ...mergeDuplicateImports.rules,
15
13
  'declare-imports-first': declareImportsFirst,
16
14
  'group-imports-by-source': groupImportsBySource,
@@ -1,9 +1,7 @@
1
- 'use strict';
1
+ import * as mergeDuplicateImportsJoin from './join/index.js';
2
+ import * as mergeDuplicateImportsRename from './rename/index.js';
2
3
 
3
- const mergeDuplicateImportsJoin = require('./join');
4
- const mergeDuplicateImportsRename = require('./rename');
5
-
6
- module.exports.rules = {
4
+ export const rules = {
7
5
  'merge-duplicate-imports-join': mergeDuplicateImportsJoin,
8
6
  'merge-duplicate-imports-rename': mergeDuplicateImportsRename,
9
7
  };
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- const {types, operator} = require('putout');
1
+ import {types, operator} from 'putout';
4
2
 
5
3
  const {remove, compareAny} = operator;
6
4
  const {values} = Object;
@@ -11,9 +9,9 @@ const {
11
9
  isImportDeclaration,
12
10
  } = types;
13
11
 
14
- module.exports.report = () => `Avoid duplicate imports`;
12
+ export const report = () => `Avoid duplicate imports`;
15
13
 
16
- module.exports.fix = ({path, imports}) => {
14
+ export const fix = ({path, imports}) => {
17
15
  const all = [];
18
16
 
19
17
  for (const imp of imports) {
@@ -37,7 +35,7 @@ module.exports.fix = ({path, imports}) => {
37
35
  path.node.specifiers.push(...all);
38
36
  };
39
37
 
40
- module.exports.traverse = ({push, pathStore}) => ({
38
+ export const traverse = ({push, pathStore}) => ({
41
39
  ImportDeclaration(path) {
42
40
  pathStore(path);
43
41
  },
@@ -1,12 +1,11 @@
1
- 'use strict';
1
+ import {types, operator} from 'putout';
2
2
 
3
- const {types, operator} = require('putout');
4
3
  const {rename, remove} = operator;
5
4
  const {isImportDefaultSpecifier} = types;
6
5
 
7
- module.exports.report = () => 'Avoid duplicate imports';
6
+ export const report = () => 'Avoid duplicate imports';
8
7
 
9
- module.exports.fix = ({path, imports}) => {
8
+ export const fix = ({path, imports}) => {
10
9
  const {name} = path.node.specifiers[0].local;
11
10
  remove(path);
12
11
 
@@ -22,7 +21,7 @@ module.exports.fix = ({path, imports}) => {
22
21
  }
23
22
  };
24
23
 
25
- module.exports.traverse = ({push, uplist}) => ({
24
+ export const traverse = ({push, uplist}) => ({
26
25
  ImportDeclaration: (path) => {
27
26
  const {value} = path.node.source;
28
27
  const [specifier, ...other] = path.node.specifiers;
@@ -1,19 +1,18 @@
1
- 'use strict';
1
+ import {operator} from 'putout';
2
2
 
3
- const {operator} = require('putout');
4
3
  const {remove} = operator;
5
4
 
6
- module.exports.report = () => 'Remove empty export';
5
+ export const report = () => 'Remove empty export';
7
6
 
8
- module.exports.fix = (path) => {
7
+ export const fix = (path) => {
9
8
  remove(path);
10
9
  };
11
10
 
12
- module.exports.include = () => [
11
+ export const include = () => [
13
12
  'ExportNamedDeclaration',
14
13
  ];
15
14
 
16
- module.exports.filter = (path) => {
15
+ export const filter = (path) => {
17
16
  const {specifiers, declaration} = path.node;
18
17
 
19
18
  return !declaration && !specifiers.length;
@@ -1,22 +1,21 @@
1
- 'use strict';
1
+ import {operator} from 'putout';
2
2
 
3
- const {operator} = require('putout');
4
3
  const {remove} = operator;
5
4
 
6
- module.exports.report = () => `Avoid empty 'import' statement`;
5
+ export const report = () => `Avoid empty 'import' statement`;
7
6
 
8
- module.exports.fix = (path) => {
7
+ export const fix = (path) => {
9
8
  remove(path);
10
9
  };
11
10
 
12
11
  const isCSS = (a) => /\.css/.test(a);
13
12
  const isMin = (a) => /\.min\./.test(a);
14
13
 
15
- module.exports.include = () => [
14
+ export const include = () => [
16
15
  'ImportDeclaration',
17
16
  ];
18
17
 
19
- module.exports.filter = (path, {options}) => {
18
+ export const filter = (path, {options}) => {
20
19
  const {specifiers, source} = path.node;
21
20
 
22
21
  const {ignore = []} = options;
@@ -1,7 +1,5 @@
1
- 'use strict';
1
+ export const report = () => 'Remove quotes from import assertions';
2
2
 
3
- module.exports.report = () => 'Remove quotes from import assertions';
4
-
5
- module.exports.replace = () => ({
3
+ export const replace = () => ({
6
4
  'import __imports from "__a" with {"type": "__b"}': 'import __imports from "__a" with {type: "__b"}',
7
5
  });
@@ -1,18 +1,17 @@
1
- 'use strict';
1
+ import {parseImportSpecifiers} from 'parse-import-specifiers';
2
+ import {operator} from 'putout';
2
3
 
3
- const {parseImportSpecifiers} = require('parse-import-specifiers');
4
- const {operator} = require('putout');
5
4
  const {insertBefore, remove} = operator;
6
5
 
7
- module.exports.report = () => `Sort imports by specifiers count`;
6
+ export const report = () => `Sort imports by specifiers count`;
8
7
 
9
- module.exports.fix = ({path, nextPath}) => {
8
+ export const fix = ({path, nextPath}) => {
10
9
  const {node} = nextPath;
11
10
  remove(nextPath);
12
11
  insertBefore(path, node);
13
12
  };
14
13
 
15
- module.exports.traverse = ({push}) => ({
14
+ export const traverse = ({push}) => ({
16
15
  ImportDeclaration(path) {
17
16
  const {node} = path;
18
17
  const {source, specifiers} = node;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@putout/plugin-esm",
3
- "version": "2.3.0",
4
- "type": "commonjs",
3
+ "version": "3.0.0",
4
+ "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin improves ability to transform ESM code",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#readme",
@@ -37,7 +37,7 @@
37
37
  "esm"
38
38
  ],
39
39
  "devDependencies": {
40
- "@putout/eslint-flat": "^2.0.0",
40
+ "@putout/eslint-flat": "^3.0.0",
41
41
  "@putout/plugin-declare": "*",
42
42
  "@putout/plugin-declare-before-reference": "*",
43
43
  "@putout/plugin-nodejs": "*",
@@ -45,22 +45,22 @@
45
45
  "@putout/plugin-reuse-duplicate-init": "*",
46
46
  "@putout/plugin-tape": "*",
47
47
  "@putout/plugin-typescript": "*",
48
- "@putout/test": "^12.0.0",
48
+ "@putout/test": "^13.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": "^25.0.1",
53
- "madrun": "^10.0.0",
52
+ "eslint-plugin-putout": "^26.0.0",
53
+ "madrun": "^11.0.0",
54
54
  "montag": "^1.2.1",
55
55
  "nodemon": "^3.0.1",
56
- "supertape": "^10.8.0"
56
+ "supertape": "^11.0.3"
57
57
  },
58
58
  "peerDependencies": {
59
- "putout": ">=38"
59
+ "putout": ">=39"
60
60
  },
61
61
  "license": "MIT",
62
62
  "engines": {
63
- "node": ">=18"
63
+ "node": ">=20"
64
64
  },
65
65
  "publishConfig": {
66
66
  "access": "public"