Skip to content

Commit 305c188

Browse files
authored
fix: cache issue (#1862)
1 parent a0d260b commit 305c188

File tree

6 files changed

+68
-5
lines changed

6 files changed

+68
-5
lines changed

packages/webpack-cli/lib/utils/Compiler.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,15 @@ class Compiler {
8787
// eslint-disable-next-line no-async-promise-executor
8888
return new Promise(async (resolve) => {
8989
await this.compiler.run((err, stats) => {
90-
const content = this.compilerCallback(err, stats, lastHash, options, outputOptions);
91-
resolve(content);
90+
if (this.compiler.close) {
91+
this.compiler.close(() => {
92+
const content = this.compilerCallback(err, stats, lastHash, options, outputOptions);
93+
resolve(content);
94+
});
95+
} else {
96+
const content = this.compilerCallback(err, stats, lastHash, options, outputOptions);
97+
resolve(content);
98+
}
9299
});
93100
});
94101
}

scripts/cleanupTest.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@ const rimraf = require('rimraf');
33
const { join } = require('path');
44
const collectTestFolders = require('./utils');
55

6-
const outputDirectories = ['bin', 'binary', 'dist', 'test', 'test-assets', 'test-plugin', 'test-loader', 'stats.json'];
6+
const outputDirectories = [
7+
'bin',
8+
'binary',
9+
'dist',
10+
'test',
11+
'test-assets',
12+
'test-plugin',
13+
'test-loader',
14+
'test-cache-path',
15+
'test-locate-cache',
16+
'stats.json',
17+
];
718

819
const folderStrategy = (stats, file) => {
920
return stats.isDirectory() && outputDirectories.includes(file);

test/cache/cache.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const { run, isWebpack5 } = require('../utils/test-utils');
4+
5+
describe('cache related tests', () => {
6+
it('should log warning in case of single compiler', () => {
7+
let { stderr, stdout } = run(__dirname, ['-c', 'webpack.config.js'], false);
8+
// run 2nd compilation
9+
({ stderr, stdout } = run(__dirname, ['-c', 'webpack.config.js'], false));
10+
11+
if (isWebpack5) {
12+
expect(stderr).toContain('starting to restore cache content');
13+
expect(stdout).toContain('[cached] 1 module');
14+
}
15+
});
16+
});

test/cache/src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('tehghgst cache');

test/cache/webpack.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
cache: {
5+
type: 'filesystem',
6+
buildDependencies: {
7+
config: [__filename],
8+
},
9+
},
10+
infrastructureLogging: {
11+
debug: /webpack\.cache/,
12+
},
13+
entry: {
14+
app: './src/main.js',
15+
},
16+
devtool: 'inline-source-map',
17+
plugins: [],
18+
output: {
19+
filename: '[name].bundle.js',
20+
chunkFilename: '[name].bundle.js',
21+
path: path.resolve(__dirname, 'dist'),
22+
publicPath: '/',
23+
},
24+
};

test/core-flags/cache-flags.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

33
const { run } = require('../utils/test-utils');
4+
const { existsSync } = require('fs');
5+
const { resolve } = require('path');
46

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

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

3032
expect(stderr).toBeFalsy();
3133
expect(stdout).toContain('test-cache-path');
34+
expect(existsSync(resolve(__dirname, './test-cache-path'))).toBeTruthy();
3235
});
3336

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

3740
expect(stderr).toBeFalsy();
3841
expect(stdout).toContain('test-locate-cache');
42+
expect(existsSync(resolve(__dirname, './test-locate-cache'))).toBeTruthy();
3943
});
4044

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

0 commit comments

Comments
 (0)