@putout/engine-runner 26.0.5 → 27.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/lib/debug.js CHANGED
@@ -1,9 +1,7 @@
1
- 'use strict';
1
+ import * as obug from 'obug';
2
2
 
3
- const {createDebug} = require('obug');
4
-
5
- module.exports.createDebug = (namespace) => {
6
- const log = createDebug(namespace, {
3
+ export const createDebug = (namespace) => {
4
+ const log = obug.createDebug(namespace, {
7
5
  useColors: true,
8
6
  });
9
7
 
@@ -1,11 +1,9 @@
1
- 'use strict';
2
-
3
- const {declare: index} = require('@putout/operator-declare');
1
+ import {declare as index} from '@putout/operator-declare';
4
2
 
5
3
  const {stringify} = JSON;
6
4
  const isFn = (a) => typeof a === 'function';
7
5
 
8
- module.exports.declare = ({rule, plugin, msg, options}) => {
6
+ export const declare = ({rule, plugin, msg, options}) => {
9
7
  validateDeclare(plugin.declare);
10
8
 
11
9
  return {
@@ -1,9 +1,6 @@
1
- 'use strict';
1
+ export const getPath = (item) => item.path || item[0] || item;
2
2
 
3
- const getPath = (item) => item.path || item[0] || item;
4
-
5
- module.exports.getPath = getPath;
6
- module.exports.getPosition = (path, shebang) => {
3
+ export const getPosition = (path, shebang) => {
7
4
  const parsedPath = getPath(path);
8
5
 
9
6
  validatePath(parsedPath);
@@ -1,14 +1,12 @@
1
- 'use strict';
1
+ import {createDebug} from '../debug.js';
2
+ import maybeArray from '../maybe-array.js';
3
+ import {validate} from '../validate.js';
2
4
 
3
- const {createDebug} = require('../debug');
4
-
5
- const maybeArray = require('../maybe-array');
6
- const {validate} = require('../validate');
7
5
  const log = createDebug('putout:runner:include');
8
6
  const stub = () => [];
9
7
  const good = () => true;
10
8
 
11
- module.exports.include = ({rule, plugin, msg, options}) => {
9
+ export const include = ({rule, plugin, msg, options}) => {
12
10
  const {
13
11
  fix,
14
12
  report,
package/lib/index.js CHANGED
@@ -1,26 +1,22 @@
1
- 'use strict';
1
+ import {traverse as defaultTraverse} from '@putout/babel';
2
+ import once from 'once';
3
+ import {createDebug} from './debug.js';
4
+ import runFix from './run-fix.js';
5
+ import mergeVisitors from './merge-visitors.js';
6
+ import superFind from './super-find.js';
7
+ import template from './template/index.js';
8
+ import {createProgress} from './progress.js';
9
+ import {tryThrowWithReason} from './try-throw-with-reason.js';
10
+ import {include} from './includer/index.js';
11
+ import {replace, clearWatermark} from './replacer/index.js';
12
+ import {declare} from './declarator/index.js';
13
+ import {scan} from './scanner/index.js';
14
+ import {getPath, getPosition} from './get-position.js';
2
15
 
3
- const {traverse: defaultTraverse} = require('@putout/babel');
4
- const once = require('once');
5
- const {createDebug} = require('./debug');
6
-
7
- const runFix = require('./run-fix');
8
- const mergeVisitors = require('./merge-visitors');
9
- const superFind = require('./super-find');
10
- const template = require('./template/index.js');
11
- const {createProgress} = require('./progress');
12
- const {tryThrowWithReason} = require('./try-throw-with-reason');
13
-
14
- const {include} = require('./includer/index.js');
15
- const {replace, clearWatermark} = require('./replacer/index.js');
16
- const {declare} = require('./declarator/index.js');
17
- const {scan} = require('./scanner/index.js');
18
-
19
- const {getPath, getPosition} = require('./get-position');
20
16
  const debug = createDebug('putout:runner:find');
21
17
  const isRemoved = (a) => a?.removed;
22
18
 
23
- module.exports.runPlugins = ({ast, shebang, fix, fixCount = 2, plugins, progress = createProgress(), traverse = defaultTraverse}) => {
19
+ export const runPlugins = ({ast, shebang, fix, fixCount = 2, plugins, progress = createProgress(), traverse = defaultTraverse}) => {
24
20
  let places = [];
25
21
 
26
22
  const merge = once(mergeVisitors);
@@ -54,7 +50,9 @@ module.exports.runPlugins = ({ast, shebang, fix, fixCount = 2, plugins, progress
54
50
  return places;
55
51
  };
56
52
 
57
- module.exports.getPosition = getPosition;
53
+ export {
54
+ getPosition,
55
+ };
58
56
 
59
57
  const run = ({ast, fix, shebang, pluginsFind, pluginsTraverse, template, merge, traverse}) => [
60
58
  ...runWithoutMerge({
@@ -1,9 +1,7 @@
1
- 'use strict';
2
-
3
1
  const {isArray} = Array;
4
2
  const maybeArray = (a) => isArray(a) ? a : [a];
5
3
 
6
- module.exports = (a) => {
4
+ export default (a) => {
7
5
  if (!a)
8
6
  return [];
9
7
 
@@ -1,20 +1,16 @@
1
- 'use strict';
2
-
3
- const {traverse} = require('@putout/babel');
4
- const {generate} = require('@putout/engine-parser');
5
-
6
- const runFix = require('./run-fix');
7
- const {getPosition} = require('./get-position');
8
- const maybeArray = require('./maybe-array');
9
- const {validate} = require('./validate');
10
-
11
- const {
1
+ import {traverse} from '@putout/babel';
2
+ import {generate} from '@putout/engine-parser';
3
+ import runFix from './run-fix.js';
4
+ import {getPosition} from './get-position.js';
5
+ import maybeArray from './maybe-array.js';
6
+ import {validate} from './validate.js';
7
+ import {
12
8
  listStore,
13
9
  mapStore,
14
10
  upStore,
15
11
  upListStore,
16
12
  pathStore,
17
- } = require('./store');
13
+ } from './store.js';
18
14
 
19
15
  const {merge} = traverse.visitors;
20
16
  const {assign} = Object;
@@ -33,7 +29,7 @@ const parse = (name, plugin, options) => {
33
29
  return list;
34
30
  };
35
31
 
36
- module.exports = (pluginsToMerge, {fix, shebang, template}) => {
32
+ export default (pluginsToMerge, {fix, shebang, template}) => {
37
33
  const mergeItems = [];
38
34
  const pushed = {};
39
35
 
package/lib/progress.js CHANGED
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {EventEmitter} from 'node:events';
2
2
 
3
- const {EventEmitter} = require('node:events');
4
-
5
- module.exports.createProgress = () => {
3
+ export const createProgress = () => {
6
4
  let pluginsCount = 0;
7
5
  let pluginsIndex = 0;
8
6
 
@@ -1,9 +1,7 @@
1
- 'use strict';
2
-
3
1
  const {entries} = Object;
4
2
  const {isArray} = Array;
5
3
 
6
- module.exports = (parentPath) => {
4
+ export default (parentPath) => {
7
5
  let current = {
8
6
  parentPath,
9
7
  };
@@ -1,19 +1,19 @@
1
- 'use strict';
2
-
3
- const {template, print} = require('@putout/engine-parser');
4
- const {remove, replaceWith} = require('@putout/operate');
5
- const {types} = require('@putout/babel');
6
-
7
- const {
1
+ import {template, print} from '@putout/engine-parser';
2
+ import {remove, replaceWith} from '@putout/operate';
3
+ import {types} from '@putout/babel';
4
+ import {
8
5
  compare,
9
6
  findVarsWays,
10
7
  getValues,
11
8
  setValues,
12
- } = require('@putout/compare');
9
+ } from '@putout/compare';
10
+ import maybeArray from '../maybe-array.js';
11
+ import {
12
+ REPLACE_WATERMARK,
13
+ watermark,
14
+ } from './watermark.js';
15
+ import {createDebug} from '../debug.js';
13
16
 
14
- const maybeArray = require('../maybe-array');
15
- const watermark = require('./watermark');
16
- const {createDebug} = require('../debug');
17
17
  const debug = createDebug('putout:runner:replace');
18
18
 
19
19
  const log = (from, path) => {
@@ -47,7 +47,7 @@ const stubMatch = () => ({});
47
47
  const packKeys = (a) => () => keys(a);
48
48
  const isObject = (a) => typeof a === 'object';
49
49
 
50
- module.exports.replace = ({rule, plugin, msg, options}) => {
50
+ export const replace = ({rule, plugin, msg, options}) => {
51
51
  const maybeMatch = plugin.match || stubMatch;
52
52
  const match = maybeMatch({
53
53
  options,
@@ -86,8 +86,8 @@ module.exports.replace = ({rule, plugin, msg, options}) => {
86
86
  };
87
87
  };
88
88
 
89
- module.exports.clearWatermark = (ast) => {
90
- delete ast.program[watermark.REPLACE_WATERMARK];
89
+ export const clearWatermark = (ast) => {
90
+ delete ast.program[REPLACE_WATERMARK];
91
91
  };
92
92
 
93
93
  const isFn = (a) => typeof a === 'function';
@@ -1,15 +1,12 @@
1
- 'use strict';
2
-
3
- const wraptile = require('wraptile');
4
-
5
- const {types} = require('@putout/babel');
6
- const findPath = require('./find-path');
1
+ import wraptile from 'wraptile';
2
+ import {types} from '@putout/babel';
3
+ import findPath from './find-path.js';
7
4
 
8
5
  const {isProgram} = types;
9
6
  const name = '__putout_runner_replace';
10
7
  const hasWatermark = (watermark) => (path) => path.node?.[name]?.has(watermark);
11
8
 
12
- module.exports = (from, to, path) => {
9
+ export const watermark = (from, to, path) => {
13
10
  const {watermark, highWatermark} = create(from, to, path);
14
11
  const program = path.findParent(isProgram);
15
12
  const options = {
@@ -26,10 +23,9 @@ module.exports = (from, to, path) => {
26
23
  };
27
24
  };
28
25
 
29
- module.exports.REPLACE_WATERMARK = name;
26
+ export const REPLACE_WATERMARK = name;
30
27
 
31
- module.exports.create = create;
32
- function create(from, to, path) {
28
+ export function create(from, to, path) {
33
29
  const watermark = `${from} -> ${to}`;
34
30
  const highWatermark = `${findPath(path)}: ${watermark}`;
35
31
 
@@ -39,16 +35,14 @@ function create(from, to, path) {
39
35
  };
40
36
  }
41
37
 
42
- module.exports.init = init;
43
- function init({path, program}) {
38
+ export function init({path, program}) {
44
39
  if (path.node)
45
40
  path.node[name] = path.node[name] || new Set();
46
41
 
47
42
  program.node[name] = program.node[name] || new Set();
48
43
  }
49
44
 
50
- module.exports.add = add;
51
- function add({path, program, watermark, highWatermark}) {
45
+ export function add({path, program, watermark, highWatermark}) {
52
46
  init({
53
47
  path,
54
48
  program,
@@ -58,8 +52,7 @@ function add({path, program, watermark, highWatermark}) {
58
52
  program.node[name].add(highWatermark);
59
53
  }
60
54
 
61
- module.exports.has = has;
62
- function has({path, program, watermark, highWatermark}) {
55
+ export function has({path, program, watermark, highWatermark}) {
63
56
  const {node} = path;
64
57
  const {loc} = node;
65
58
 
package/lib/run-fix.js CHANGED
@@ -1,7 +1,5 @@
1
- 'use strict';
2
-
3
- const {tryCatch} = require('try-catch');
4
- const {createDebug} = require('./debug');
1
+ import {tryCatch} from 'try-catch';
2
+ import {createDebug} from './debug.js';
5
3
 
6
4
  const {stringify} = JSON;
7
5
 
@@ -48,7 +46,7 @@ const tryToFix = (fix, {path, pathOptions, position, options}) => {
48
46
  throw e;
49
47
  };
50
48
 
51
- module.exports = (is, fix, {path, pathOptions, rule, position, options}) => {
49
+ export default (is, fix, {path, pathOptions, rule, position, options}) => {
52
50
  if (!is)
53
51
  return;
54
52
 
@@ -1,21 +1,18 @@
1
- 'use strict';
2
-
3
- const fullstore = require('fullstore');
4
- const {compare} = require('@putout/compare');
5
- const {__filesystem_name} = require('@putout/operator-json');
6
-
7
- const {
1
+ import fullstore from 'fullstore';
2
+ import {compare} from '@putout/compare';
3
+ import {__filesystem_name} from '@putout/operator-json';
4
+ import {
8
5
  findFile,
9
6
  pause,
10
7
  start,
11
- } = require('@putout/operator-filesystem');
8
+ } from '@putout/operator-filesystem';
9
+ import fromSimple from '@putout/plugin-filesystem/from-simple';
10
+ import toSimple from '@putout/plugin-filesystem/to-simple';
11
+ import {createDebug} from '../debug.js';
12
12
 
13
- const fromSimple = require('@putout/plugin-filesystem/from-simple');
14
- const toSimple = require('@putout/plugin-filesystem/to-simple');
15
- const {createDebug} = require('../debug');
16
13
  const log = createDebug('putout:runner:scanner');
17
14
 
18
- module.exports.scan = ({rule, plugin, msg, options}, {progress}) => {
15
+ export const scan = ({rule, plugin, msg, options}, {progress}) => {
19
16
  const {
20
17
  scan,
21
18
  report,
package/lib/store.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
1
  const {
4
2
  values,
5
3
  entries,
@@ -11,10 +9,10 @@ const isNotRemoved = (a) => a.node;
11
9
  const notRemoved = (a) => toArray(a).filter(isNotRemoved);
12
10
  const id = (a) => a;
13
11
 
14
- module.exports.listStore = createListStore();
15
- module.exports.pathStore = createListStore(notRemoved);
12
+ export const listStore = createListStore();
13
+ export const pathStore = createListStore(notRemoved);
16
14
 
17
- module.exports.mapStore = createStore({
15
+ export const mapStore = createStore({
18
16
  get(map) {
19
17
  return values(map);
20
18
  },
@@ -23,7 +21,7 @@ module.exports.mapStore = createStore({
23
21
  },
24
22
  });
25
23
 
26
- module.exports.upStore = createStore({
24
+ export const upStore = createStore({
27
25
  get(map) {
28
26
  return values(map);
29
27
  },
@@ -33,7 +31,7 @@ module.exports.upStore = createStore({
33
31
  },
34
32
  });
35
33
 
36
- module.exports.upListStore = createStore({
34
+ export const upListStore = createStore({
37
35
  get(map) {
38
36
  return values(map).map(notRemoved);
39
37
  },
package/lib/super-find.js CHANGED
@@ -1,11 +1,12 @@
1
- 'use strict';
1
+ import {
2
+ traverse as babelTraverse,
3
+ types,
4
+ } from '@putout/babel';
5
+ import {generate} from '@putout/engine-parser';
2
6
 
3
- const {traverse: babelTraverse, types} = require('@putout/babel');
4
-
5
- const {generate} = require('@putout/engine-parser');
6
7
  const {merge} = babelTraverse.visitors;
7
8
 
8
- module.exports = function superFind({rule, find, ast, options, template, traverse = babelTraverse}) {
9
+ export default function superFind({rule, find, ast, options, template, traverse = babelTraverse}) {
9
10
  const pushItems = [];
10
11
 
11
12
  const push = (a) => {
@@ -29,7 +30,7 @@ module.exports = function superFind({rule, find, ast, options, template, travers
29
30
  ...pushItems,
30
31
  ...returnItems || [],
31
32
  ];
32
- };
33
+ }
33
34
 
34
35
  const createTraverse = ({rule, options, template, traverse}) => (ast, visitor) => {
35
36
  const templateVisitors = merge(template({
@@ -1,16 +1,13 @@
1
- 'use strict';
2
-
3
- const {tryCatch} = require('try-catch');
4
-
5
- const {
1
+ import {tryCatch} from 'try-catch';
2
+ import {
6
3
  compareAny,
7
4
  compareAll,
8
5
  parseTemplate,
9
6
  isTemplate,
10
- } = require('@putout/compare');
7
+ } from '@putout/compare';
8
+ import maybeArray from '../maybe-array.js';
9
+ import {createDebug} from '../debug.js';
11
10
 
12
- const maybeArray = require('../maybe-array');
13
- const {createDebug} = require('../debug');
14
11
  const debug = createDebug('putout:runner:template');
15
12
 
16
13
  const {entries} = Object;
@@ -22,7 +19,7 @@ const log = (rule, path) => {
22
19
 
23
20
  const {stringify} = JSON;
24
21
 
25
- module.exports._log = log;
22
+ export const _log = log;
26
23
 
27
24
  const exclude = ({rule, tmpl, fn, nodesExclude}) => {
28
25
  if (!isFn(fn) || !nodesExclude.length)
@@ -42,7 +39,7 @@ const exclude = ({rule, tmpl, fn, nodesExclude}) => {
42
39
  };
43
40
  };
44
41
 
45
- module.exports = ({rule, visitor, options}) => {
42
+ export default ({rule, visitor, options}) => {
46
43
  const parsed = [];
47
44
  const nodesExclude = maybeArray(options.exclude);
48
45
  const nodesInclude = maybeArray(options.include);
@@ -81,8 +78,6 @@ module.exports = ({rule, visitor, options}) => {
81
78
  return parsed;
82
79
  };
83
80
 
84
- module.exports._log = log;
85
-
86
81
  const wrapWithCheck = ({rule, nodesInclude, nodesExclude, fn}) => (path) => {
87
82
  log(rule, path);
88
83
 
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {tryCatch} from 'try-catch';
2
2
 
3
- const {tryCatch} = require('try-catch');
4
-
5
- module.exports.tryThrowWithReason = (fn, ...args) => {
3
+ export const tryThrowWithReason = (fn, ...args) => {
6
4
  const [error, result] = tryCatch(fn, ...args);
7
5
 
8
6
  if (error) {
package/lib/validate.js CHANGED
@@ -1,9 +1,7 @@
1
- 'use strict';
2
-
3
1
  const isFn = (a) => typeof a === 'function';
4
2
  const {stringify} = JSON;
5
3
 
6
- module.exports.validate = (name, fn) => {
4
+ export const validate = (name, fn) => {
7
5
  if (!isFn(fn))
8
6
  throw Error(`☝️ Looks like '${name}' is not a 'function' but '${typeof fn}' with value: '${stringify(fn)}'. More on using Includer: https://git.io/JqcMn`);
9
7
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@putout/engine-runner",
3
- "version": "26.0.5",
4
- "type": "commonjs",
3
+ "version": "27.0.0",
4
+ "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Run 🐊Putout plugins",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-runner#readme",
@@ -57,7 +57,7 @@
57
57
  "eslint-plugin-n": "^17.0.0",
58
58
  "eslint-plugin-putout": "^29.0.0",
59
59
  "just-camel-case": "^6.2.0",
60
- "madrun": "^11.0.0",
60
+ "madrun": "^12.0.0",
61
61
  "montag": "^1.0.0",
62
62
  "nodemon": "^3.0.1",
63
63
  "putout": "*",