Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: assign config paths in build dependencies in cache config #1900

Merged
merged 10 commits into from Oct 10, 2020
25 changes: 12 additions & 13 deletions packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -46,20 +46,19 @@ class WebpackCLI extends GroupHelper {
* @returns {void}
*/
_handleCoreFlags(parsedArgs) {
if (!this.groupMap.has('core')) {
return;
if (this.groupMap.has('core')) {
const coreFlags = this.groupMap.get('core');

// convert all the flags from map to single object
const coreConfig = coreFlags.reduce((allFlag, curFlag) => ({ ...allFlag, ...curFlag }), {});
const coreCliHelper = require('webpack').cli;
const coreCliArgs = coreCliHelper.getArguments();
// Merge the core flag config with the compilerConfiguration
coreCliHelper.processArguments(coreCliArgs, this.compilerConfiguration, coreConfig);
// Assign some defaults to core flags
}
const coreFlags = this.groupMap.get('core');

// convert all the flags from map to single object
const coreConfig = coreFlags.reduce((allFlag, curFlag) => ({ ...allFlag, ...curFlag }), {});
const coreCliHelper = require('webpack').cli;
const coreCliArgs = coreCliHelper.getArguments();
// Merge the core flag config with the compilerConfiguration
coreCliHelper.processArguments(coreCliArgs, this.compilerConfiguration, coreConfig);
// Assign some defaults to core flags
const configWithAppliedDefaults = assignFlagDefaults(this.compilerConfiguration, parsedArgs);
this._mergeOptionsToConfiguration(configWithAppliedDefaults);
const configWithDefaults = assignFlagDefaults(this.compilerConfiguration, parsedArgs);
this._mergeOptionsToConfiguration(configWithDefaults);
}

async _baseResolver(cb, parsedArgs, strategy) {
Expand Down
12 changes: 12 additions & 0 deletions test/core-flags/cache-flags.test.js
Expand Up @@ -81,6 +81,18 @@ describe('cache related flags from core', () => {
expect(newRun.exitCode).toEqual(0);
});

it('should assign cache build dependencies correctly when cache type is filesystem in config', () => {
const { stderr, stdout } = run(__dirname, ['-c', './webpack.cache.config.js']);
expect(stderr).toBeFalsy();
expect(stdout).toContain('buildDependencies: { config: [Array]');
anshumanv marked this conversation as resolved.
Show resolved Hide resolved
expect(stdout).not.toContain('[cached] 1 module');
// Run again to check for cache
const newRun = run(__dirname, ['-c', './webpack.cache.config.js']);
expect(newRun.stdout).toContain('[cached] 1 module');
expect(newRun.stderr).toBeFalsy();
expect(newRun.exitCode).toEqual(0);
});

it('should invalidate cache when config changes', () => {
// Creating a temporary webpack config
writeFileSync(resolve(__dirname, './webpack.test.config.js'), 'module.exports = {mode: "none"}');
Expand Down
11 changes: 11 additions & 0 deletions test/core-flags/webpack.cache.config.js
@@ -0,0 +1,11 @@
const WebpackCLITestPlugin = require('../utils/webpack-cli-test-plugin');

module.exports = {
entry: './src/main.js',
mode: 'development',
cache: {
type: 'filesystem',
},
name: 'compiler',
plugins: [new WebpackCLITestPlugin(['module', 'entry', 'resolve', 'resolveLoader'])],
};