@putout/engine-runner 28.1.0 → 28.2.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
@@ -53,7 +53,7 @@ export const replace = () => ({
53
53
  });
54
54
 
55
55
  // optional
56
- export const filter = (path) => {
56
+ export const filter = (path, {options}) => {
57
57
  return true;
58
58
  };
59
59
 
@@ -162,7 +162,7 @@ export const include = () => ['debugger'];
162
162
  export const exclude = () => {};
163
163
 
164
164
  // optional
165
- export const filter = (path) => {
165
+ export const filter = (path, {options}) => {
166
166
  return true;
167
167
  };
168
168
  ```
package/lib/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import {traverse as defaultTraverse} from '@putout/babel';
2
2
  import once from 'once';
3
+ import {clearWatermark} from '@putout/operator-watermark';
3
4
  import {createDebug} from './debug.js';
4
5
  import runFix from './run-fix.js';
5
6
  import mergeVisitors from './merge-visitors.js';
@@ -8,7 +9,7 @@ import template from './template/index.js';
8
9
  import {createProgress} from './progress.js';
9
10
  import {tryThrowWithReason} from './try-throw-with-reason.js';
10
11
  import {include} from './includer/index.js';
11
- import {replace, clearWatermark} from './replacer/index.js';
12
+ import {replace} from './replacer/index.js';
12
13
  import {declare} from './declarator/index.js';
13
14
  import {scan} from './scanner/index.js';
14
15
  import {getPath, getPosition} from './get-position.js';
@@ -43,7 +44,9 @@ export const runPlugins = ({ast, fix, fixCount = 2, plugins, progress = createPr
43
44
  if (!fix || !places.length)
44
45
  return places;
45
46
 
46
- clearWatermark(ast);
47
+ const {program} = ast;
48
+
49
+ clearWatermark(program);
47
50
  }
48
51
 
49
52
  return places;
@@ -98,7 +98,7 @@ function getStore(plugin, {fix, rule, msg, options}) {
98
98
  const push = (path, pathOptions) => {
99
99
  const position = getPosition(path);
100
100
  const message = msg || plugin.report(path, {
101
- ...options,
101
+ options,
102
102
  ...pathOptions,
103
103
  });
104
104
 
@@ -1,6 +1,7 @@
1
1
  import {template, print} from '@putout/engine-parser';
2
2
  import {remove, replaceWith} from '@putout/operate';
3
3
  import {types} from '@putout/babel';
4
+ import {watermark} from '@putout/operator-watermark';
4
5
  import {
5
6
  compare,
6
7
  findVarsWays,
@@ -8,10 +9,6 @@ import {
8
9
  setValues,
9
10
  } from '@putout/compare';
10
11
  import maybeArray from '../maybe-array.js';
11
- import {
12
- REPLACE_WATERMARK,
13
- watermark,
14
- } from './watermark.js';
15
12
  import {createDebug} from '../debug.js';
16
13
 
17
14
  const debug = createDebug('putout:runner:replace');
@@ -86,10 +83,6 @@ export const replace = ({rule, plugin, msg, options}) => {
86
83
  };
87
84
  };
88
85
 
89
- export const clearWatermark = (ast) => {
90
- delete ast.program[REPLACE_WATERMARK];
91
- };
92
-
93
86
  const isFn = (a) => typeof a === 'function';
94
87
 
95
88
  const parseExpression = (nodeFrom, {node}) => {
package/lib/run-fix.js CHANGED
@@ -7,21 +7,12 @@ const isFn = (a) => typeof a === 'function';
7
7
  const getPath = (path) => path.path || path;
8
8
  const debug = createDebug('putout:runner:fix');
9
9
 
10
- const chooseFixArgs = ({path, pathOptions, options}) => {
11
- if (pathOptions)
12
- return [
13
- path,
14
- pathOptions, {
15
- options,
16
- },
17
- ];
18
-
19
- return [
20
- path, {
21
- options,
22
- },
23
- ];
24
- };
10
+ const chooseFixArgs = ({path, pathOptions, options}) => [
11
+ path, {
12
+ options,
13
+ ...pathOptions,
14
+ },
15
+ ];
25
16
 
26
17
  const tryToFix = (fix, {path, pathOptions, position, options}) => {
27
18
  const [e] = tryCatch(fix, ...chooseFixArgs({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/engine-runner",
3
- "version": "28.1.0",
3
+ "version": "28.2.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Run 🐊Putout plugins",
@@ -36,6 +36,7 @@
36
36
  "@putout/operator-filesystem": "^11.0.0",
37
37
  "@putout/operator-json": "^3.0.0",
38
38
  "@putout/plugin-filesystem": "^13.0.0",
39
+ "@putout/operator-watermark": "^1.0.0",
39
40
  "fullstore": "^4.0.0",
40
41
  "obug": "^2.1.1",
41
42
  "once": "^1.4.0",
@@ -61,9 +62,6 @@
61
62
  "putout": "*",
62
63
  "supertape": "^12.0.0"
63
64
  },
64
- "peerDependencies": {
65
- "putout": "*"
66
- },
67
65
  "license": "MIT",
68
66
  "engines": {
69
67
  "node": ">=22"
@@ -1,38 +0,0 @@
1
- const {entries} = Object;
2
- const {isArray} = Array;
3
-
4
- export default (parentPath) => {
5
- let current = {
6
- parentPath,
7
- };
8
-
9
- const path = [];
10
-
11
- while (current = current.parentPath) {
12
- path.unshift(findKey(current, current.parent));
13
- }
14
-
15
- return path.join('.');
16
- };
17
-
18
- function findKey(path, parent) {
19
- const {node} = path;
20
- let key;
21
- let value;
22
-
23
- for ([key, value] of entries(parent)) {
24
- if (isArray(value)) {
25
- const index = value.indexOf(node);
26
-
27
- if (index >= 0)
28
- return `${key}.${index}`;
29
-
30
- continue;
31
- }
32
-
33
- if (value === node)
34
- break;
35
- }
36
-
37
- return key;
38
- }
@@ -1,63 +0,0 @@
1
- import wraptile from 'wraptile';
2
- import {types} from '@putout/babel';
3
- import findPath from './find-path.js';
4
-
5
- const {isProgram} = types;
6
- const name = '__putout_runner_replace';
7
- const hasWatermark = (watermark) => (path) => path.node?.[name]?.has(watermark);
8
-
9
- export const watermark = (from, to, path) => {
10
- const {watermark, highWatermark} = create(from, to, path);
11
- const program = path.findParent(isProgram);
12
- const options = {
13
- watermark,
14
- highWatermark,
15
- program,
16
- path,
17
- };
18
-
19
- return {
20
- init: wraptile(init, options),
21
- has: wraptile(has, options),
22
- add: wraptile(add, options),
23
- };
24
- };
25
-
26
- export const REPLACE_WATERMARK = name;
27
-
28
- export function create(from, to, path) {
29
- const watermark = `${from} -> ${to}`;
30
- const highWatermark = `${findPath(path)}: ${watermark}`;
31
-
32
- return {
33
- watermark,
34
- highWatermark,
35
- };
36
- }
37
-
38
- export function init({path, program}) {
39
- if (path.node)
40
- path.node[name] = path.node[name] || new Set();
41
-
42
- program.node[name] = program.node[name] || new Set();
43
- }
44
-
45
- export function add({path, program, watermark, highWatermark}) {
46
- init({
47
- path,
48
- program,
49
- });
50
-
51
- path?.node[name].add(watermark);
52
- program.node[name].add(highWatermark);
53
- }
54
-
55
- export function has({path, program, watermark, highWatermark}) {
56
- const {node} = path;
57
- const {loc} = node;
58
-
59
- if (node?.[name].has(watermark) || path.findParent(hasWatermark(watermark)) && !loc)
60
- return true;
61
-
62
- return program.node[name].has(highWatermark);
63
- }