Skip to content

Commit f72614b

Browse files
committed
Remove configureCleanWebpackPlugin and use cleanupOutputBeforeBuild arguments instead
1 parent 90c8565 commit f72614b

File tree

5 files changed

+39
-54
lines changed

5 files changed

+39
-54
lines changed

index.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,26 +102,6 @@ const publicApi = {
102102
return this;
103103
},
104104

105-
/**
106-
* Allows you to configure the paths and the options passed to the clean-webpack-plugin.
107-
* A list of available options can be found at https://github.com/johnagan/clean-webpack-plugin
108-
*
109-
* For example:
110-
*
111-
* Encore.configureCleanWebpackPlugin(['*.js'], (options) => {
112-
* options.dry = true;
113-
* })
114-
*
115-
* @param {Array} paths Paths that should be cleaned, relative to the "root" option
116-
* @param {function} cleanWebpackPluginOptionsCallback
117-
* @returns {exports}
118-
*/
119-
configureCleanWebpackPlugin(paths = ['**/*'], cleanWebpackPluginOptionsCallback = () => {}) {
120-
webpackConfig.configureCleanWebpackPlugin(paths, cleanWebpackPluginOptionsCallback);
121-
122-
return this;
123-
},
124-
125105
/**
126106
* Allows you to configure the options passed to the DefinePlugin.
127107
* A list of available options can be found at https://webpack.js.org/plugins/define-plugin/
@@ -638,10 +618,20 @@ const publicApi = {
638618
* If enabled, the output directory is emptied between
639619
* each build (to remove old files).
640620
*
621+
* A list of available options can be found at https://github.com/johnagan/clean-webpack-plugin
622+
*
623+
* For example:
624+
*
625+
* Encore.cleanupOutputBeforeBuild(['*.js'], (options) => {
626+
* options.dry = true;
627+
* })
628+
*
629+
* @param {Array} paths Paths that should be cleaned, relative to the "root" option
630+
* @param {function} cleanWebpackPluginOptionsCallback
641631
* @returns {exports}
642632
*/
643-
cleanupOutputBeforeBuild() {
644-
webpackConfig.cleanupOutputBeforeBuild();
633+
cleanupOutputBeforeBuild(paths = ['**/*'], cleanWebpackPluginOptionsCallback = () => {}) {
634+
webpackConfig.cleanupOutputBeforeBuild(paths, cleanWebpackPluginOptionsCallback);
645635

646636
return this;
647637
},

lib/WebpackConfig.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,6 @@ class WebpackConfig {
138138
this.manifestKeyPrefix = manifestKeyPrefix;
139139
}
140140

141-
configureCleanWebpackPlugin(paths = ['**/*'], cleanWebpackPluginOptionsCallback = () => {}) {
142-
if (!Array.isArray(paths)) {
143-
throw new Error('Argument 1 to configureCleanWebpackPlugin() must be an Array');
144-
}
145-
146-
if (typeof cleanWebpackPluginOptionsCallback !== 'function') {
147-
throw new Error('Argument 2 to configureCleanWebpackPlugin() must be a callback function');
148-
}
149-
150-
this.cleanWebpackPluginPaths = paths;
151-
this.cleanWebpackPluginOptionsCallback = cleanWebpackPluginOptionsCallback;
152-
}
153-
154141
configureDefinePlugin(definePluginOptionsCallback = () => {}) {
155142
if (typeof definePluginOptionsCallback !== 'function') {
156143
throw new Error('Argument 1 to configureDefinePlugin() must be a callback function');
@@ -384,8 +371,18 @@ class WebpackConfig {
384371
this.configuredFilenames = configuredFilenames;
385372
}
386373

387-
cleanupOutputBeforeBuild() {
374+
cleanupOutputBeforeBuild(paths = ['**/*'], cleanWebpackPluginOptionsCallback = () => {}) {
375+
if (!Array.isArray(paths)) {
376+
throw new Error('Argument 1 to cleanupOutputBeforeBuild() must be an Array');
377+
}
378+
379+
if (typeof cleanWebpackPluginOptionsCallback !== 'function') {
380+
throw new Error('Argument 2 to cleanupOutputBeforeBuild() must be a callback function');
381+
}
382+
388383
this.cleanupOutput = true;
384+
this.cleanWebpackPluginPaths = paths;
385+
this.cleanWebpackPluginOptionsCallback = cleanWebpackPluginOptionsCallback;
389386
}
390387

391388
autoProvideVariables(variables) {

test/WebpackConfig.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,21 @@ describe('WebpackConfig object', () => {
163163
});
164164
});
165165

166-
describe('configureCleanWebpackPlugin', () => {
166+
describe('cleanupOutputBeforeBuild', () => {
167+
it('Enabling it with default settings', () => {
168+
const config = createConfig();
169+
config.cleanupOutputBeforeBuild();
170+
171+
expect(config.cleanupOutput).to.be.true;
172+
expect(config.cleanWebpackPluginPaths).to.deep.equal(['**/*']);
173+
});
174+
167175
it('Setting paths and callback', () => {
168176
const config = createConfig();
169177
const callback = () => {};
170-
config.configureCleanWebpackPlugin(['**/*.js', '**/*.css'], callback);
178+
config.cleanupOutputBeforeBuild(['**/*.js', '**/*.css'], callback);
171179

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

179188
expect(() => {
180-
config.configureCleanWebpackPlugin('foo', () => {});
181-
}).to.throw('Argument 1 to configureCleanWebpackPlugin() must be an Array');
189+
config.cleanupOutputBeforeBuild('foo', () => {});
190+
}).to.throw('Argument 1 to cleanupOutputBeforeBuild() must be an Array');
182191
});
183192

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

187196
expect(() => {
188-
config.configureCleanWebpackPlugin(['**/*'], 'foo');
189-
}).to.throw('Argument 2 to configureCleanWebpackPlugin() must be a callback function');
197+
config.cleanupOutputBeforeBuild(['**/*'], 'foo');
198+
}).to.throw('Argument 2 to cleanupOutputBeforeBuild() must be a callback function');
190199
});
191200
});
192201

test/index.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,6 @@ describe('Public API', () => {
251251

252252
});
253253

254-
describe('configureCleanWebpackPlugin', () => {
255-
256-
it('should return the API object', () => {
257-
const returnedValue = api.configureCleanWebpackPlugin(['**/*.js'], () => {});
258-
expect(returnedValue).to.equal(api);
259-
});
260-
261-
});
262-
263254
describe('configureDefinePlugin', () => {
264255

265256
it('should return the API object', () => {

test/plugins/clean.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ describe('plugins/clean', () => {
4949
const config = createConfig();
5050
const plugins = [];
5151

52-
config.cleanupOutputBeforeBuild();
53-
54-
config.configureCleanWebpackPlugin(['**/*.js', '**/*.css'], (options) => {
52+
config.cleanupOutputBeforeBuild(['**/*.js', '**/*.css'], (options) => {
5553
options.dry = true;
5654
});
5755

0 commit comments

Comments
 (0)