Skip to content

Commit 73d8c44

Browse files
committed
webpack - let build fail when webpack generates an error or a warning
1 parent 7fd5812 commit 73d8c44

2 files changed

Lines changed: 47 additions & 21 deletions

File tree

build/lib/extensions.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ var __assign = (this && this.__assign) || Object.assign || function(t) {
1313
};
1414
Object.defineProperty(exports, "__esModule", { value: true });
1515
var es = require("event-stream");
16+
var fs = require("fs");
17+
var glob = require("glob");
18+
var gulp = require("gulp");
19+
var path = require("path");
20+
var File = require("vinyl");
21+
var vsce = require("vsce");
22+
var util2 = require("./util");
1623
var assign = require("object-assign");
1724
var remote = require("gulp-remote-src");
1825
var flatmap = require('gulp-flatmap');
@@ -24,13 +31,6 @@ var buffer = require('gulp-buffer');
2431
var json = require('gulp-json-editor');
2532
var webpack = require('webpack');
2633
var webpackGulp = require('webpack-stream');
27-
var fs = require("fs");
28-
var path = require("path");
29-
var vsce = require("vsce");
30-
var File = require("vinyl");
31-
var glob = require("glob");
32-
var gulp = require("gulp");
33-
var util2 = require("./util");
3434
var root = path.resolve(path.join(__dirname, '..', '..'));
3535
function fromLocal(extensionPath, sourceMappingURLBase) {
3636
var result = es.through();
@@ -67,11 +67,23 @@ function fromLocal(extensionPath, sourceMappingURLBase) {
6767
return data;
6868
}))
6969
.pipe(packageJsonFilter.restore);
70+
var webpackDone_1 = function (err, stats) {
71+
if (err) {
72+
result.emit('error', err);
73+
}
74+
var compilation = stats.compilation;
75+
if (compilation.errors.length > 0) {
76+
result.emit('error', compilation.errors.join('\n'));
77+
}
78+
if (compilation.warnings.length > 0) {
79+
result.emit('error', compilation.warnings.join('\n'));
80+
}
81+
};
7082
var webpackStreams = webpackConfigLocations.map(function (webpackConfigPath) {
71-
var webpackConfig = __assign({}, require(webpackConfigPath), { mode: 'production', stats: 'errors-only' });
83+
util.log("Bundling extension: " + util.colors.yellow(path.basename(extensionPath)) + "...");
84+
var webpackConfig = __assign({}, require(webpackConfigPath), { mode: 'production' });
7285
var relativeOutputPath = path.relative(extensionPath, webpackConfig.output.path);
73-
var webpackBaseDir = path.dirname(webpackConfigPath);
74-
return webpackGulp(webpackConfig, webpack)
86+
return webpackGulp(webpackConfig, webpack, webpackDone_1)
7587
.pipe(es.through(function (data) {
7688
data.stat = data.stat || {};
7789
data.base = extensionPath;

build/lib/extensions.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as es from 'event-stream';
7+
import * as fs from 'fs';
8+
import * as glob from 'glob';
9+
import * as gulp from 'gulp';
10+
import * as path from 'path';
711
import { Stream } from 'stream';
12+
import * as File from 'vinyl';
13+
import * as vsce from 'vsce';
14+
import * as util2 from './util';
815
import assign = require('object-assign');
916
import remote = require('gulp-remote-src');
1017
const flatmap = require('gulp-flatmap');
@@ -16,13 +23,6 @@ const buffer = require('gulp-buffer');
1623
const json = require('gulp-json-editor');
1724
const webpack = require('webpack');
1825
const webpackGulp = require('webpack-stream');
19-
import * as fs from 'fs';
20-
import * as path from 'path';
21-
import * as vsce from 'vsce';
22-
import * as File from 'vinyl';
23-
import * as glob from 'glob';
24-
import * as gulp from 'gulp';
25-
import * as util2 from './util';
2626

2727
const root = path.resolve(path.join(__dirname, '..', '..'));
2828

@@ -67,15 +67,29 @@ export function fromLocal(extensionPath: string, sourceMappingURLBase?: string):
6767
}))
6868
.pipe(packageJsonFilter.restore);
6969

70+
const webpackDone = (err, stats) => {
71+
if (err) {
72+
result.emit('error', err);
73+
}
74+
const { compilation } = stats;
75+
if (compilation.errors.length > 0) {
76+
result.emit('error', compilation.errors.join('\n'));
77+
}
78+
if (compilation.warnings.length > 0) {
79+
result.emit('error', compilation.warnings.join('\n'));
80+
}
81+
};
82+
7083
const webpackStreams = webpackConfigLocations.map(webpackConfigPath => {
84+
util.log(`Bundling extension: ${util.colors.yellow(path.basename(extensionPath))}...`);
85+
7186
const webpackConfig = {
7287
...require(webpackConfigPath),
73-
...{ mode: 'production', stats: 'errors-only' }
88+
...{ mode: 'production' }
7489
};
7590
let relativeOutputPath = path.relative(extensionPath, webpackConfig.output.path);
76-
let webpackBaseDir = path.dirname(webpackConfigPath);
7791

78-
return webpackGulp(webpackConfig, webpack)
92+
return webpackGulp(webpackConfig, webpack, webpackDone)
7993
.pipe(es.through(function (data) {
8094
data.stat = data.stat || {};
8195
data.base = extensionPath;
@@ -260,4 +274,4 @@ export function packageExtensionsStream(opts?: IPackageExtensionsOptions): NodeJ
260274
return es.merge(localExtensions, localExtensionDependencies, marketplaceExtensions)
261275
.pipe(util2.setExecutableBit(['**/*.sh']))
262276
.pipe(filter(['**', '!**/*.js.map']));
263-
}
277+
}

0 commit comments

Comments
 (0)