Skip to content

Commit 7ed2bd2

Browse files
authored
Merge pull request webpack#6213 from webpack/bugfix/override-post
`-!` keeps post loader instead of pre loader
2 parents 1886b7a + cf1d7b8 commit 7ed2bd2

File tree

9 files changed

+106
-3
lines changed

9 files changed

+106
-3
lines changed

lib/NormalModuleFactory.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class NormalModuleFactory extends Tapable {
143143

144144
const noAutoLoaders = /^-?!/.test(request);
145145
const noPrePostAutoLoaders = /^!!/.test(request);
146-
const noPostAutoLoaders = /^-!/.test(request);
146+
const noPreAutoLoaders = /^-!/.test(request);
147147
let elements = request.replace(/^-?!+/, "").replace(/!!+/g, "!").split("!");
148148
let resource = elements.pop();
149149
elements = elements.map(identToLoaderRequest);
@@ -220,9 +220,9 @@ class NormalModuleFactory extends Tapable {
220220
const useLoadersPre = [];
221221
result.forEach(r => {
222222
if(r.type === "use") {
223-
if(r.enforce === "post" && !noPostAutoLoaders && !noPrePostAutoLoaders)
223+
if(r.enforce === "post" && !noPrePostAutoLoaders)
224224
useLoadersPost.push(r.value);
225-
else if(r.enforce === "pre" && !noPrePostAutoLoaders)
225+
else if(r.enforce === "pre" && !noPreAutoLoaders && !noPrePostAutoLoaders)
226226
useLoadersPre.push(r.value);
227227
else if(!r.enforce && !noAutoLoaders && !noPrePostAutoLoaders)
228228
useLoaders.push(r.value);

test/Compiler.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const sinon = require("sinon");
88
const webpack = require("../");
99
const WebpackOptionsDefaulter = require("../lib/WebpackOptionsDefaulter");
1010
const Compiler = require("../lib/Compiler");
11+
const MemoryFs = require("memory-fs");
1112

1213
describe("Compiler", () => {
1314
function compile(entry, options, callback) {
@@ -242,6 +243,24 @@ describe("Compiler", () => {
242243
});
243244
});
244245
});
246+
it("should not emit on errors", function(done) {
247+
const compiler = webpack({
248+
context: __dirname,
249+
mode: "production",
250+
entry: "./missing",
251+
output: {
252+
path: "/",
253+
filename: "bundle.js"
254+
}
255+
});
256+
compiler.outputFileSystem = new MemoryFs();
257+
compiler.run((err, stats) => {
258+
if(err) return done(err);
259+
if(compiler.outputFileSystem.existsSync("/bundle.js"))
260+
return done(new Error("Bundle should not be created on error"));
261+
done();
262+
});
263+
});
245264
describe("Watching", () => {
246265
let compiler;
247266
beforeEach(() => {

test/Stats.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*globals describe it */
2+
"use strict";
3+
4+
require("should");
5+
6+
const webpack = require("../lib/webpack");
7+
const MemoryFs = require("memory-fs");
8+
9+
describe("Stats", () => {
10+
it("should print env string in stats", function(done) {
11+
const compiler = webpack({
12+
context: __dirname,
13+
entry: "./fixtures/a"
14+
});
15+
compiler.outputFileSystem = new MemoryFs();
16+
compiler.run((err, stats) => {
17+
if(err) return done(err);
18+
try {
19+
stats.toString({
20+
all: false,
21+
env: true,
22+
_env: "production"
23+
}).should.be.eql(
24+
"Environment (--env): \"production\""
25+
);
26+
stats.toString({
27+
all: false,
28+
env: true,
29+
_env: {
30+
prod: ["foo", "bar"],
31+
baz: true
32+
}
33+
}).should.be.eql(
34+
"Environment (--env): {\n" +
35+
" \"prod\": [\n" +
36+
" \"foo\",\n" +
37+
" \"bar\"\n" +
38+
" ],\n" +
39+
" \"baz\": true\n" +
40+
"}"
41+
);
42+
done();
43+
} catch(e) {
44+
done(e);
45+
}
46+
});
47+
});
48+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "resource";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
it("should apply pre and post loaders correctly", function() {
2+
require("./a").should.be.eql("resource loader2 loader1 loader3");
3+
require("!./a").should.be.eql("resource loader2 loader3");
4+
require("!!./a").should.be.eql("resource");
5+
require("-!./a").should.be.eql("resource loader3");
6+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function(source) {
2+
return source + "module.exports += \" loader1\";\n";
3+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function(source) {
2+
return source + "module.exports += \" loader2\";\n";
3+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function(source) {
2+
return source + "module.exports += \" loader3\";\n";
3+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
module: {
3+
rules: [
4+
{
5+
test: /a\.js$/,
6+
use: "./loader1",
7+
},
8+
{
9+
test: /a\.js$/,
10+
use: "./loader2",
11+
enforce: "pre"
12+
},
13+
{
14+
test: /a\.js$/,
15+
use: "./loader3",
16+
enforce: "post"
17+
}
18+
]
19+
}
20+
};

0 commit comments

Comments
 (0)