Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
merge resolve plugins just like config
Browse files Browse the repository at this point in the history
  • Loading branch information
Guy committed Aug 4, 2018
1 parent 36a2dd6 commit c47ee2d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -43,3 +43,6 @@ jspm_packages

# Webstorm project metadata
.idea

# macOS
.DS_Store
11 changes: 8 additions & 3 deletions src/Resolve.js
Expand Up @@ -55,16 +55,21 @@ module.exports = class extends ChainedMap {
'extensions',
'mainFields',
'mainFiles',
'modules',
'plugins',
'modules'
];

if (!omit.includes('plugin') && 'plugin' in obj) {
Object.keys(obj.plugin).forEach(name =>
this.plugin(name).merge(obj.plugin[name])
);
}

omissions.forEach(key => {
if (!omit.includes(key) && key in obj) {
this[key].merge(obj[key]);
}
});

return super.merge(obj, [...omit, ...omissions]);
return super.merge(obj, [...omit, ...omissions, 'plugin']);
}
};
32 changes: 32 additions & 0 deletions test/Resolve.js
@@ -1,6 +1,16 @@
import test from 'ava';
import Resolve from '../src/Resolve';

class StringifyPlugin {
constructor(...args) {
this.values = args;
}

apply() {
return JSON.stringify(this.values);
}
}

test('is Chainable', t => {
const parent = { parent: true };
const resolve = new Resolve(parent);
Expand Down Expand Up @@ -123,3 +133,25 @@ test('plugin with name', t => {

t.is(resolve.plugins.get('alpha').name, 'alpha');
});


test('plugin empty', t => {
const resolve = new Resolve();
const instance = resolve
.plugin('stringify')
.use(StringifyPlugin)
.end();

t.is(instance, resolve);
t.true(resolve.plugins.has('stringify'));
t.deepEqual(resolve.plugins.get('stringify').get('args'), []);
});

test('plugin with args', t => {
const resolve = new Resolve();

resolve.plugin('stringify').use(StringifyPlugin, ['alpha', 'beta']);

t.true(resolve.plugins.has('stringify'));
t.deepEqual(resolve.plugins.get('stringify').get('args'), ['alpha', 'beta']);
});

0 comments on commit c47ee2d

Please sign in to comment.