Skip to content

Commit

Permalink
feature(putout) add merge
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jul 18, 2019
1 parent 966abc1 commit a1e24be
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
10 changes: 1 addition & 9 deletions packages/putout/bin/putout.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ const cwd = process.cwd();
const once = require('once');
const glob = require('glob');
const tryCatch = require('try-catch');
const deepmerge = require('deepmerge');
const arrayUnion = require('array-union');

const defaultOptions = require('../putout.json');

const putout = require('..');
const {merge} = putout;
const parseMatch = require('../lib/parse-match');
const getRelativePath = require('../lib/get-relative-path');
const report = require('../lib/report')();
Expand Down Expand Up @@ -246,13 +245,6 @@ function exit(e) {
process.exit(1);
}

function merge(...args) {
const arrayMerge = (a, b) => arrayUnion(b, a);
return deepmerge.all(args, {
arrayMerge,
});
}

function getOptions(cwd) {
const putoutPath = findUp.sync('.putout.json', {
cwd,
Expand Down
13 changes: 13 additions & 0 deletions packages/putout/lib/merge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const deepmerge = require('deepmerge');
const arrayUnion = require('array-union');

const arrayMerge = (a, b) => arrayUnion(b, a);

module.exports = (...args) => {
return deepmerge.all(args, {
arrayMerge,
});
}

29 changes: 29 additions & 0 deletions packages/putout/lib/merge.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const test = require('supertape');
const merge = require('./merge');

test('merge', (t) => {
const defaultConfig = {
plugins: [
'remove-unused-variables',
]
};

const result = merge(defaultConfig, {
plugins: [
'extract-sequence-expressions',
]
});

const expected = {
plugins: [
'extract-sequence-expressions',
'remove-unused-variables',
]
};

t.deepEqual(result, expected);
t.end();
});

9 changes: 7 additions & 2 deletions packages/putout/lib/putout.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = (source, opts) => {

const places = transform(ast, source, opts);
const printed = print(ast);
const code = fixStrictMode(`${shebang}${printed}`);
const code = `${shebang}${printed}`;

return {
code,
Expand Down Expand Up @@ -135,12 +135,17 @@ function print(ast) {
objectCurlySpacing: false,
};

return recast.print(ast, printOptions).code;
const printed = recast.print(ast, printOptions).code;
const code = fixStrictMode(printed);

return code;
}

module.exports.traverse = traverse;
module.exports.types = types;
module.exports.template = template;
module.exports.generate = generate;
module.exports.initReport = require('./report');
module.exports.merge = require('./merge');
module.exports.operate = require('@putout/operate');

0 comments on commit a1e24be

Please sign in to comment.