Skip to content

Commit b44e078

Browse files
committed
Merge branch 'master' of https://github.com/doctolib/extract-text-webpack-plugin into doctolib-master
# Conflicts: # index.js # loader.js # test/TestCases.test.js
2 parents d23f5c8 + 2928346 commit b44e078

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

example/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var fs = require('fs');
12
var webpack = require("webpack");
23
var ExtractTextPlugin = require("../");
34
module.exports = {
@@ -8,7 +9,7 @@ module.exports = {
89
output: {
910
filename: "[name].js?[hash]-[chunkhash]",
1011
chunkFilename: "[name].js?[hash]-[chunkhash]",
11-
path: __dirname + "/assets",
12+
path: fs.realpathSync(__dirname) + "/assets",
1213
publicPath: "/assets/"
1314
},
1415
module: {

index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5+
var fs = require('fs');
56
var ConcatSource = require("webpack-sources").ConcatSource;
67
var async = require("async");
78
var ExtractedModule = require("./ExtractedModule");
@@ -205,16 +206,16 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
205206
compiler.plugin("this-compilation", function(compilation) {
206207
var extractCompilation = new ExtractTextPluginCompilation();
207208
compilation.plugin("normal-module-loader", function(loaderContext, module) {
208-
loaderContext[__dirname] = function(content, opt) {
209+
loaderContext[fs.realpathSync(__dirname)] = function(content, opt) {
209210
if(options.disable)
210211
return false;
211212
if(!Array.isArray(content) && content != null)
212213
throw new Error("Exported value was not extracted as an array: " + JSON.stringify(content));
213-
module.meta[__dirname] = {
214+
module.meta[fs.realpathSync(__dirname)] = {
214215
content: content,
215216
options: opt || {}
216217
};
217-
return options.allChunks || module.meta[__dirname + "/extract"]; // eslint-disable-line no-path-concat
218+
return options.allChunks || module.meta[fs.realpathSync(__dirname) + "/extract"]; // eslint-disable-line no-path-concat
218219
};
219220
});
220221
var filename = this.filename;
@@ -241,17 +242,17 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
241242
var extractedChunk = extractedChunks[chunks.indexOf(chunk)];
242243
var shouldExtract = !!(options.allChunks || chunk.isInitial());
243244
async.forEach(chunk.modules.slice(), function(module, callback) {
244-
var meta = module.meta && module.meta[__dirname];
245+
var meta = module.meta && module.meta[fs.realpathSync(__dirname)];
245246
if(meta && (!meta.options.id || meta.options.id === id)) {
246247
var wasExtracted = Array.isArray(meta.content);
247248
if(shouldExtract !== wasExtracted) {
248-
module.meta[__dirname + "/extract"] = shouldExtract; // eslint-disable-line no-path-concat
249+
module.meta[fs.realpathSync(__dirname) + "/extract"] = shouldExtract; // eslint-disable-line no-path-concat
249250
compilation.rebuildModule(module, function(err) {
250251
if(err) {
251252
compilation.errors.push(err);
252253
return callback();
253254
}
254-
meta = module.meta[__dirname];
255+
meta = module.meta[fs.realpathSync(__dirname)];
255256
if(!Array.isArray(meta.content)) {
256257
err = new Error(module.identifier() + " doesn't export content");
257258
compilation.errors.push(err);

loader.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ module.exports.pitch = function(request) {
1717
var query = loaderUtils.parseQuery(this.query);
1818
this.addDependency(this.resourcePath);
1919
// We already in child compiler, return empty bundle
20-
if(this[__dirname] === undefined) {
20+
if(this[fs.realpathSync(__dirname)] === undefined) {
2121
throw new Error(
2222
'"extract-text-webpack-plugin" loader is used without the corresponding plugin, ' +
2323
'refer to https://github.com/webpack/extract-text-webpack-plugin for the usage example'
2424
);
25-
} else if(this[__dirname] === false) {
25+
} else if(this[fs.realpathSync(__dirname)] === false) {
2626
return "";
27-
} else if(this[__dirname](null, query)) {
27+
} else if(this[fs.realpathSync(__dirname)](null, query)) {
2828
if(query.omit) {
2929
this.loaderIndex += +query.omit + 1;
3030
request = request.split("!").slice(+query.omit).join("!");
@@ -48,19 +48,19 @@ module.exports.pitch = function(request) {
4848
childCompiler.apply(new NodeTargetPlugin());
4949
childCompiler.apply(new SingleEntryPlugin(this.context, "!!" + request));
5050
childCompiler.apply(new LimitChunkCountPlugin({ maxChunks: 1 }));
51-
var subCache = "subcache " + __dirname + " " + request; // eslint-disable-line no-path-concat
51+
var subCache = "subcache " + fs.realpathSync(__dirname) + " " + request; // eslint-disable-line no-path-concat
5252
childCompiler.plugin("compilation", function(compilation) {
5353
if(compilation.cache) {
5454
if(!compilation.cache[subCache])
5555
compilation.cache[subCache] = {};
5656
compilation.cache = compilation.cache[subCache];
5757
}
5858
});
59-
// We set loaderContext[__dirname] = false to indicate we already in
59+
// We set loaderContext[fs.realpathSync(__dirname)] = false to indicate we already in
6060
// a child compiler so we don't spawn another child compilers from there.
6161
childCompiler.plugin("this-compilation", function(compilation) {
6262
compilation.plugin("normal-module-loader", function(loaderContext) {
63-
loaderContext[__dirname] = false;
63+
loaderContext[fs.realpathSync(__dirname)] = false;
6464
});
6565
});
6666
var source;
@@ -103,7 +103,7 @@ module.exports.pitch = function(request) {
103103
item[0] = module.identifier();
104104
});
105105
});
106-
this[__dirname](text, query);
106+
this[fs.realpathSync(__dirname)](text, query);
107107
if(text.locals && typeof resultSource !== "undefined") {
108108
resultSource += "\nmodule.exports = " + JSON.stringify(text.locals) + ";";
109109
}

test/TestCases.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ var webpack = require("webpack");
55
var should = require("should");
66
var ExtractTextPlugin = require("../");
77

8-
var cases = process.env.CASES ? process.env.CASES.split(",") : fs.readdirSync(path.join(__dirname, "cases"));
8+
var cases = process.env.CASES ? process.env.CASES.split(",") : fs.readdirSync(path.join(fs.realpathSync(__dirname), "cases"));
99

1010
describe("TestCases", function() {
1111
cases.forEach(function(testCase) {
1212
it(testCase, function(done) {
13-
var testDirectory = path.join(__dirname, "cases", testCase);
14-
var outputDirectory = path.join(__dirname, "js", testCase);
13+
var testDirectory = path.join(fs.realpathSync(__dirname), "cases", testCase);
14+
var outputDirectory = path.join(fs.realpathSync(__dirname), "js", testCase);
1515
var options = { entry: { test: "./index.js" } };
1616
var configFile = path.join(testDirectory, "webpack.config.js");
1717
if(fs.existsSync(configFile))

0 commit comments

Comments
 (0)