Skip to content

Commit ea6e173

Browse files
committed
Move concurrent compilation error to separate class
1 parent 9f60f50 commit ea6e173

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

lib/Compiler.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const ResolverFactory = require("./ResolverFactory");
2222

2323
const RequestShortener = require("./RequestShortener");
2424
const makePathsRelative = require("./util/identifier").makePathsRelative;
25+
const ConcurrentCompilationError = require("./ConcurrentCompilationError");
2526

2627
class Compiler extends Tapable {
2728
constructor(context) {
@@ -134,12 +135,7 @@ class Compiler extends Tapable {
134135
}
135136

136137
watch(watchOptions, handler) {
137-
if (this.running)
138-
return handler(
139-
new Error(
140-
"You ran Webpack twice. Each instance only supports a single concurrent compilation at a time."
141-
)
142-
);
138+
if (this.running) return handler(new ConcurrentCompilationError());
143139

144140
this.running = true;
145141
this.fileTimestamps = new Map();
@@ -148,12 +144,7 @@ class Compiler extends Tapable {
148144
}
149145

150146
run(callback) {
151-
if (this.running)
152-
return callback(
153-
new Error(
154-
"You ran Webpack twice. Each instance only supports a single concurrent compilation at a time."
155-
)
156-
);
147+
if (this.running) return callback(new ConcurrentCompilationError());
157148

158149
const finalCallback = (err, stats) => {
159150
this.running = false;

lib/ConcurrentCompilationError.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Maksim Nazarjev @acupofspirt
4+
*/
5+
"use strict";
6+
7+
const WebpackError = require("./WebpackError");
8+
9+
module.exports = class ConcurrentCompilationError extends WebpackError {
10+
constructor() {
11+
super();
12+
13+
this.name = "ConcurrentCompilationError";
14+
this.message =
15+
"You ran Webpack twice. Each instance only supports a single concurrent compilation at a time.";
16+
17+
Error.captureStackTrace(this, this.constructor);
18+
}
19+
};

lib/MultiCompiler.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const MultiHook = require("tapable").MultiHook;
1010
const asyncLib = require("neo-async");
1111
const MultiWatching = require("./MultiWatching");
1212
const MultiStats = require("./MultiStats");
13+
const ConcurrentCompilationError = require("./ConcurrentCompilationError");
1314

1415
module.exports = class MultiCompiler extends Tapable {
1516
constructor(compilers) {
@@ -186,12 +187,7 @@ module.exports = class MultiCompiler extends Tapable {
186187
}
187188

188189
watch(watchOptions, handler) {
189-
if (this.running)
190-
return handler(
191-
new Error(
192-
"You ran Webpack twice. Each instance only supports a single concurrent compilation at a time."
193-
)
194-
);
190+
if (this.running) return handler(new ConcurrentCompilationError());
195191

196192
const finalHandler = (err, stats) => {
197193
this.running = false;
@@ -245,12 +241,7 @@ module.exports = class MultiCompiler extends Tapable {
245241
}
246242

247243
run(callback) {
248-
if (this.running)
249-
return callback(
250-
new Error(
251-
"You ran Webpack twice. Each instance only supports a single concurrent compilation at a time."
252-
)
253-
);
244+
if (this.running) return callback(new ConcurrentCompilationError());
254245

255246
const finalCallback = (err, stats) => {
256247
this.running = false;

0 commit comments

Comments
 (0)