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

Ensure new warnings are not ignored when bundling with WebPack #3984

Merged
merged 1 commit into from
Jan 15, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,47 @@ gulp.task("compile", () => {
gulp.task('compile-webviews', async () => spawnAsync('npx', ['webpack', '--config', 'webpack.datascience-ui.config.js', '--mode', 'production']));

gulp.task('webpack', async () => {
await spawnAsync('npx', ['webpack', '--mode', 'production']);
await spawnAsync('npx', ['webpack', '--config', './build/webpack/webpack.extension.sourceMaps.config.js', '--mode', 'production']);
await spawnAsync('npx', ['webpack', '--config', './build/webpack/webpack.extension.config.js', '--mode', 'production']);
await spawnAsync('npx', ['webpack', '--config', './build/webpack/webpack.debugadapter.config.js', '--mode', 'production']);
await buildWebPack('production', []);
await buildWebPack('sourceMaps', ['--config', './build/webpack/webpack.extension.sourceMaps.config.js']);
await buildWebPack('extension', ['--config', './build/webpack/webpack.extension.config.js']);
await buildWebPack('debugAdapter', ['--config', './build/webpack/webpack.debugadapter.config.js']);
});

async function buildWebPack(webpackConfigName, args) {
const allowedWarnings = getAllowedWarningsForWebPack(webpackConfigName);
const stdOut = await spawnAsync('npx', ['webpack', ...args, ...['--mode', 'production']], allowedWarnings);
const warnings = stdOut
.split('\n')
.map(item => item.trim())
.filter(item => item.length > 0)
.filter(item => item.startsWith('WARNING in '))
.filter(item => allowedWarnings.findIndex(allowedWarning => item.startsWith(allowedWarning)) == -1);
if (warnings.length === 0) {
return;
}
throw new Error(`Warnings in ${webpackConfigName}, \n{warnings.join(', ')}\n\n${stdOut}`);
}
function getAllowedWarningsForWebPack(buildConfig) {
switch (buildConfig) {
case 'production':
return [
'WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).',
'WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.',
'WARNING in webpack performance recommendations:',
'WARNING in ./node_modules/encoding/lib/iconv-loader.js',
'WARNING in ./node_modules/ws/lib/BufferUtil.js',
'WARNING in ./node_modules/ws/lib/Validation.js'
];
case 'sourceMaps':
return [];
case 'extension':
return [];
case 'debugAdapter':
return ['WARNING in ./node_modules/vscode-uri/lib/index.js'];
default:
throw new Error('Unknown WebPack Configuration');
}
}
gulp.task('prePublishBundle', gulp.series('checkNativeDependencies', 'check-datascience-dependencies', 'compile', 'clean:cleanExceptTests', 'webpack'));
gulp.task('prePublishNonBundle', gulp.series('checkNativeDependencies', 'check-datascience-dependencies', 'compile', 'compile-webviews'));

Expand All @@ -188,15 +223,17 @@ gulp.task('installPythonLibs', async () => {

function spawnAsync(command, args) {
return new Promise((resolve, reject) => {
let stdOut = '';
const proc = spawn(command, args, { cwd: __dirname });
proc.stdout.on('data', data => {
// Log output on CI (else travis times out when there's not output).
stdOut += data.toString();
if (isCI) {
console.log(data.toString());
}
});
proc.stderr.on('data', data => console.error(data.toString()));
proc.on('close', () => resolve());
proc.on('close', () => resolve(stdOut));
proc.on('error', error => reject(error));
});
}
Expand Down
1 change: 1 addition & 0 deletions news/3 Code Health/3468.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure new warnings are not ignored when bundling the extension with WebPack.