Skip to content

Commit

Permalink
Remove configureCleanWebpackPlugin and use cleanupOutputBeforeBuild a…
Browse files Browse the repository at this point in the history
…rguments instead
  • Loading branch information
Lyrkan committed Sep 12, 2017
1 parent 90c8565 commit f72614b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 54 deletions.
34 changes: 12 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,6 @@ const publicApi = {
return this;
},

/**
* Allows you to configure the paths and the options passed to the clean-webpack-plugin.
* A list of available options can be found at https://github.com/johnagan/clean-webpack-plugin
*
* For example:
*
* Encore.configureCleanWebpackPlugin(['*.js'], (options) => {
* options.dry = true;
* })
*
* @param {Array} paths Paths that should be cleaned, relative to the "root" option
* @param {function} cleanWebpackPluginOptionsCallback
* @returns {exports}
*/
configureCleanWebpackPlugin(paths = ['**/*'], cleanWebpackPluginOptionsCallback = () => {}) {
webpackConfig.configureCleanWebpackPlugin(paths, cleanWebpackPluginOptionsCallback);

return this;
},

/**
* Allows you to configure the options passed to the DefinePlugin.
* A list of available options can be found at https://webpack.js.org/plugins/define-plugin/
Expand Down Expand Up @@ -638,10 +618,20 @@ const publicApi = {
* If enabled, the output directory is emptied between
* each build (to remove old files).
*
* A list of available options can be found at https://github.com/johnagan/clean-webpack-plugin
*
* For example:
*
* Encore.cleanupOutputBeforeBuild(['*.js'], (options) => {
* options.dry = true;
* })
*
* @param {Array} paths Paths that should be cleaned, relative to the "root" option
* @param {function} cleanWebpackPluginOptionsCallback
* @returns {exports}
*/
cleanupOutputBeforeBuild() {
webpackConfig.cleanupOutputBeforeBuild();
cleanupOutputBeforeBuild(paths = ['**/*'], cleanWebpackPluginOptionsCallback = () => {}) {
webpackConfig.cleanupOutputBeforeBuild(paths, cleanWebpackPluginOptionsCallback);

return this;
},
Expand Down
25 changes: 11 additions & 14 deletions lib/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,6 @@ class WebpackConfig {
this.manifestKeyPrefix = manifestKeyPrefix;
}

configureCleanWebpackPlugin(paths = ['**/*'], cleanWebpackPluginOptionsCallback = () => {}) {
if (!Array.isArray(paths)) {
throw new Error('Argument 1 to configureCleanWebpackPlugin() must be an Array');
}

if (typeof cleanWebpackPluginOptionsCallback !== 'function') {
throw new Error('Argument 2 to configureCleanWebpackPlugin() must be a callback function');
}

this.cleanWebpackPluginPaths = paths;
this.cleanWebpackPluginOptionsCallback = cleanWebpackPluginOptionsCallback;
}

configureDefinePlugin(definePluginOptionsCallback = () => {}) {
if (typeof definePluginOptionsCallback !== 'function') {
throw new Error('Argument 1 to configureDefinePlugin() must be a callback function');
Expand Down Expand Up @@ -384,8 +371,18 @@ class WebpackConfig {
this.configuredFilenames = configuredFilenames;
}

cleanupOutputBeforeBuild() {
cleanupOutputBeforeBuild(paths = ['**/*'], cleanWebpackPluginOptionsCallback = () => {}) {
if (!Array.isArray(paths)) {
throw new Error('Argument 1 to cleanupOutputBeforeBuild() must be an Array');
}

if (typeof cleanWebpackPluginOptionsCallback !== 'function') {
throw new Error('Argument 2 to cleanupOutputBeforeBuild() must be a callback function');
}

this.cleanupOutput = true;
this.cleanWebpackPluginPaths = paths;
this.cleanWebpackPluginOptionsCallback = cleanWebpackPluginOptionsCallback;
}

autoProvideVariables(variables) {
Expand Down
21 changes: 15 additions & 6 deletions test/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,21 @@ describe('WebpackConfig object', () => {
});
});

describe('configureCleanWebpackPlugin', () => {
describe('cleanupOutputBeforeBuild', () => {
it('Enabling it with default settings', () => {
const config = createConfig();
config.cleanupOutputBeforeBuild();

expect(config.cleanupOutput).to.be.true;
expect(config.cleanWebpackPluginPaths).to.deep.equal(['**/*']);
});

it('Setting paths and callback', () => {
const config = createConfig();
const callback = () => {};
config.configureCleanWebpackPlugin(['**/*.js', '**/*.css'], callback);
config.cleanupOutputBeforeBuild(['**/*.js', '**/*.css'], callback);

expect(config.cleanupOutput).to.be.true;
expect(config.cleanWebpackPluginPaths).to.deep.equal(['**/*.js', '**/*.css']);
expect(config.cleanWebpackPluginOptionsCallback).to.equal(callback);
});
Expand All @@ -177,16 +186,16 @@ describe('WebpackConfig object', () => {
const config = createConfig();

expect(() => {
config.configureCleanWebpackPlugin('foo', () => {});
}).to.throw('Argument 1 to configureCleanWebpackPlugin() must be an Array');
config.cleanupOutputBeforeBuild('foo', () => {});
}).to.throw('Argument 1 to cleanupOutputBeforeBuild() must be an Array');
});

it('Setting invalid callback argument', () => {
const config = createConfig();

expect(() => {
config.configureCleanWebpackPlugin(['**/*'], 'foo');
}).to.throw('Argument 2 to configureCleanWebpackPlugin() must be a callback function');
config.cleanupOutputBeforeBuild(['**/*'], 'foo');
}).to.throw('Argument 2 to cleanupOutputBeforeBuild() must be a callback function');
});
});

Expand Down
9 changes: 0 additions & 9 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,6 @@ describe('Public API', () => {

});

describe('configureCleanWebpackPlugin', () => {

it('should return the API object', () => {
const returnedValue = api.configureCleanWebpackPlugin(['**/*.js'], () => {});
expect(returnedValue).to.equal(api);
});

});

describe('configureDefinePlugin', () => {

it('should return the API object', () => {
Expand Down
4 changes: 1 addition & 3 deletions test/plugins/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ describe('plugins/clean', () => {
const config = createConfig();
const plugins = [];

config.cleanupOutputBeforeBuild();

config.configureCleanWebpackPlugin(['**/*.js', '**/*.css'], (options) => {
config.cleanupOutputBeforeBuild(['**/*.js', '**/*.css'], (options) => {
options.dry = true;
});

Expand Down

0 comments on commit f72614b

Please sign in to comment.