Skip to content

Commit a5a9d85

Browse files
committed
feature: @putout/engine-runner: migrate to ESM
1 parent 53e26ac commit a5a9d85

34 files changed

+172
-248
lines changed

packages/engine-runner/.putout.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"printer": "putout",
32
"match": {
43
"*.md": {
54
"remove-debugger": "off"

packages/engine-runner/lib/debug.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import * as obug from 'obug';
22

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, {
75
useColors: true,
86
});
97

packages/engine-runner/lib/declarator/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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';
42

53
const {stringify} = JSON;
64
const isFn = (a) => typeof a === 'function';
75

8-
module.exports.declare = ({rule, plugin, msg, options}) => {
6+
export const declare = ({rule, plugin, msg, options}) => {
97
validateDeclare(plugin.declare);
108

119
return {

packages/engine-runner/lib/declarator/index.spec.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
2-
3-
const {test} = require('supertape');
4-
const montag = require('montag');
5-
const {tryCatch} = require('try-catch');
6-
const putout = require('putout');
1+
import {test} from 'supertape';
2+
import montag from 'montag';
3+
import {tryCatch} from 'try-catch';
4+
import putout from 'putout';
75

86
test('engine-runner: declare', (t) => {
97
const {code} = putout(`isString('hello')`, {

packages/engine-runner/lib/get-position.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
'use strict';
1+
export const getPath = (item) => item.path || item[0] || item;
22

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) => {
74
const parsedPath = getPath(path);
85

96
validatePath(parsedPath);

packages/engine-runner/lib/includer/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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';
24

3-
const {createDebug} = require('../debug');
4-
5-
const maybeArray = require('../maybe-array');
6-
const {validate} = require('../validate');
75
const log = createDebug('putout:runner:include');
86
const stub = () => [];
97
const good = () => true;
108

11-
module.exports.include = ({rule, plugin, msg, options}) => {
9+
export const include = ({rule, plugin, msg, options}) => {
1210
const {
1311
fix,
1412
report,

packages/engine-runner/lib/index.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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';
215

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');
2016
const debug = createDebug('putout:runner:find');
2117
const isRemoved = (a) => a?.removed;
2218

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}) => {
2420
let places = [];
2521

2622
const merge = once(mergeVisitors);
@@ -54,7 +50,9 @@ module.exports.runPlugins = ({ast, shebang, fix, fixCount = 2, plugins, progress
5450
return places;
5551
};
5652

57-
module.exports.getPosition = getPosition;
53+
export {
54+
getPosition,
55+
};
5856

5957
const run = ({ast, fix, shebang, pluginsFind, pluginsTraverse, template, merge, traverse}) => [
6058
...runWithoutMerge({

packages/engine-runner/lib/maybe-array.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
2-
31
const {isArray} = Array;
42
const maybeArray = (a) => isArray(a) ? a : [a];
53

6-
module.exports = (a) => {
4+
export default (a) => {
75
if (!a)
86
return [];
97

0 commit comments

Comments
 (0)