Skip to content

Commit

Permalink
fix: cache issue (#1862)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Oct 5, 2020
1 parent a0d260b commit 305c188
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 5 deletions.
11 changes: 9 additions & 2 deletions packages/webpack-cli/lib/utils/Compiler.js
Expand Up @@ -87,8 +87,15 @@ class Compiler {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
await this.compiler.run((err, stats) => {
const content = this.compilerCallback(err, stats, lastHash, options, outputOptions);
resolve(content);
if (this.compiler.close) {
this.compiler.close(() => {
const content = this.compilerCallback(err, stats, lastHash, options, outputOptions);
resolve(content);
});
} else {
const content = this.compilerCallback(err, stats, lastHash, options, outputOptions);
resolve(content);
}
});
});
}
Expand Down
13 changes: 12 additions & 1 deletion scripts/cleanupTest.js
Expand Up @@ -3,7 +3,18 @@ const rimraf = require('rimraf');
const { join } = require('path');
const collectTestFolders = require('./utils');

const outputDirectories = ['bin', 'binary', 'dist', 'test', 'test-assets', 'test-plugin', 'test-loader', 'stats.json'];
const outputDirectories = [
'bin',
'binary',
'dist',
'test',
'test-assets',
'test-plugin',
'test-loader',
'test-cache-path',
'test-locate-cache',
'stats.json',
];

const folderStrategy = (stats, file) => {
return stats.isDirectory() && outputDirectories.includes(file);
Expand Down
16 changes: 16 additions & 0 deletions test/cache/cache.test.js
@@ -0,0 +1,16 @@
'use strict';

const { run, isWebpack5 } = require('../utils/test-utils');

describe('cache related tests', () => {
it('should log warning in case of single compiler', () => {
let { stderr, stdout } = run(__dirname, ['-c', 'webpack.config.js'], false);
// run 2nd compilation
({ stderr, stdout } = run(__dirname, ['-c', 'webpack.config.js'], false));

if (isWebpack5) {
expect(stderr).toContain('starting to restore cache content');
expect(stdout).toContain('[cached] 1 module');
}
});
});
1 change: 1 addition & 0 deletions test/cache/src/main.js
@@ -0,0 +1 @@
console.log('tehghgst cache');
24 changes: 24 additions & 0 deletions test/cache/webpack.config.js
@@ -0,0 +1,24 @@
const path = require('path');

module.exports = {
cache: {
type: 'filesystem',
buildDependencies: {
config: [__filename],
},
},
infrastructureLogging: {
debug: /webpack\.cache/,
},
entry: {
app: './src/main.js',
},
devtool: 'inline-source-map',
plugins: [],
output: {
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
},
};
8 changes: 6 additions & 2 deletions test/core-flags/cache-flags.test.js
@@ -1,6 +1,8 @@
'use strict';

const { run } = require('../utils/test-utils');
const { existsSync } = require('fs');
const { resolve } = require('path');

describe('cache related flags from core', () => {
it('should be successful with --cache ', () => {
Expand All @@ -25,17 +27,19 @@ describe('cache related flags from core', () => {
});

it('should set cache.cacheDirectory with --cache-cache-directory', () => {
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-cache-directory', '/test-cache-path']);
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-cache-directory', './test-cache-path']);

expect(stderr).toBeFalsy();
expect(stdout).toContain('test-cache-path');
expect(existsSync(resolve(__dirname, './test-cache-path'))).toBeTruthy();
});

it('should set cache.cacheLocation with --cache-cache-locations', () => {
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-cache-location', '/test-locate-cache']);
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-cache-location', './test-locate-cache']);

expect(stderr).toBeFalsy();
expect(stdout).toContain('test-locate-cache');
expect(existsSync(resolve(__dirname, './test-locate-cache'))).toBeTruthy();
});

it('should set cache.hashAlgorithm with --cache-hash-algorithm', () => {
Expand Down

0 comments on commit 305c188

Please sign in to comment.