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

fix: cache issue #1862

Merged
merged 6 commits into from Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
anshumanv marked this conversation as resolved.
Show resolved Hide resolved
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',
];

function 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