Skip to content

Fix #105 #135

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

Merged
merged 4 commits into from
Jun 12, 2017
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
31 changes: 20 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ HardSourceWebpackPlugin.prototype.apply = function(compiler) {
{
id: 'environment-paths-deprecated'
},
'HardSourceWebpackPlugin: environmentPaths is deprecated, please use ' +
'environmentHash. environmentHash accepts the same options.'
'environmentPaths is deprecated, please use environmentHash. ' +
'environmentHash accepts the same options.'
);
if (options.environmentPaths === false) {
environmentHasher = function() {
Expand All @@ -346,9 +346,11 @@ HardSourceWebpackPlugin.prototype.apply = function(compiler) {
if (typeof options.environmentHash !== 'undefined') {
if (environmentHasher) {
loggerCore.warn(
{},
'HardSourceWebpackPlugin: environmentHash is a new option replacing ' +
'environmentPaths. Please use only environmentHash.'
{
id: 'environment-paths-and-hash-defined'
},
'environmentHash is a new option replacing environmentPaths. Please ' +
'use only environmentHash.'
);
}
if (options.environmentHash === false) {
Expand Down Expand Up @@ -380,13 +382,14 @@ HardSourceWebpackPlugin.prototype.apply = function(compiler) {
if (compiler.options.recordsInputPath || compiler.options.recordsPath) {
loggerCore.error(
{
id: 'records-input-path-set-in-root-config',
webpackRecordsInputPath: compiler.options.recordsInputPath,
webpackRecordsPath: compiler.options.recordsPath,
hardSourceRecordsInputPath: options.recordsInputPath,
hardSourceRecordsPath: options.recordsPath,
},
'HardSourceWebpackPlugin will not set recordsInputPath when it is ' +
'already set. Using current value: ' +
'Can not set recordsInputPath when it is already set. Using current ' +
'value: ' +
(compiler.options.recordsInputPath || compiler.options.recordsPath)
);
}
Expand All @@ -406,13 +409,14 @@ HardSourceWebpackPlugin.prototype.apply = function(compiler) {
if (compiler.options.recordsOutputPath || compiler.options.recordsPath) {
loggerCore.error(
{
id: 'records-output-path-set-in-root-config',
webpackRecordsOutputPath: compiler.options.recordsInputPath,
webpackRecordsPath: compiler.options.recordsPath,
hardSourceRecordsOutputPath: options.recordsOutputPath,
hardSourceRecordsPath: options.recordsPath,
},
'HardSourceWebpackPlugin will not set recordsOutputPath when it is ' +
'already set. Using current value: ' +
'Can not set recordsOutputPath when it is already set. Using current ' +
'value: ' +
(compiler.options.recordsOutputPath || compiler.options.recordsPath)
);
}
Expand Down Expand Up @@ -470,8 +474,10 @@ HardSourceWebpackPlugin.prototype.apply = function(compiler) {
!compiler.recordsInputPath || !compiler.recordsOutputPath
) {
loggerCore.error(
{},
'HardSourceWebpackPlugin requires recordsPath to be set.'
{
id: 'no-records-path'
},
'recordsPath must be set.'
);
active = false;
}
Expand Down Expand Up @@ -1841,6 +1847,9 @@ HardSourceWebpackPlugin.prototype.apply = function(compiler) {

if (assets.length) {
assetOps = assetOps.concat(assets);
assets.forEach(function(op) {
assetCache[op.key] = op.value;
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/base-resolve-missing/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
plugins: [
new HardSourceWebpackPlugin({
cacheDirectory: 'cache',
environmentPaths: {
environmentHash: {
root: __dirname + '/../../..',
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
plugins: [
new HardSourceWebpackPlugin({
cacheDirectory: 'cache',
environmentPaths: {
environmentHash: {
root: __dirname + '/../../..',
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
plugins: [
new HardSourceWebpackPlugin({
cacheDirectory: 'cache',
environmentPaths: {
environmentHash: {
root: __dirname + '/../../..',
},
}),
Expand Down
Binary file added tests/fixtures/loader-file-move/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/fixtures/loader-file-move/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./image.png');
25 changes: 25 additions & 0 deletions tests/fixtures/loader-file-move/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var HardSourceWebpackPlugin = require('../../..');

module.exports = {
context: __dirname,
entry: './index.js',
output: {
path: __dirname + '/tmp',
filename: 'main.js',
},
cache: true,
recordsPath: __dirname + '/tmp/cache/records.json',
module: {
loaders: [
{
test: /\.png$/,
loader: 'file-loader',
},
],
},
plugins: [
new HardSourceWebpackPlugin({
cacheDirectory: 'cache',
}),
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
new HardSourceWebpackPlugin({
cacheDirectory: __dirname + '/tmp/cache',
recordsPath: __dirname + '/tmp/cache/records.json',
environmentPaths: {
environmentHash: {
root: __dirname + '/../../..',
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
plugins: [
new HardSourceWebpackPlugin({
cacheDirectory: 'cache',
environmentPaths: {
environmentHash: {
root: __dirname + '/../../..',
},
}),
Expand Down
49 changes: 49 additions & 0 deletions tests/loaders.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
var expect = require('chai').expect;

var util = require('./util');
var itCompiles = util.itCompiles;
var itCompilesTwice = util.itCompilesTwice;
var itCompilesChange = util.itCompilesChange;
var itCompilesHardModules = util.itCompilesHardModules;
var clean = util.clean;
var compile = util.compile;
var writeFiles = util.writeFiles;

describe('loader webpack use', function() {

Expand Down Expand Up @@ -178,4 +180,51 @@ describe('loader webpack use - builds changes', function() {
expect(output.run2['main.js'].toString()).to.match(/n - 2/);
});

itCompiles('loader-file-move', 'loader-file-move',
function() {
return writeFiles('loader-file-move', {
'index.js': 'require(\'./image.png\');\n',
})
.then(function() {
return {
exportCompilation: true,
};
});
},
function(run1) {
return new Promise(function(resolve) {setTimeout(resolve, 1000);})
.then(function() {
return writeFiles('loader-file-move', {
'index.js': '// require(\'./image.png\');\n',
})
})
.then(function() {
return {
compiler: run1.compiler,
exportCompilation: true,
};
});
},
function(run2) {
return new Promise(function(resolve) {setTimeout(resolve, 1000);})
.then(function() {
return writeFiles('loader-file-move', {
'index.js': 'require(\'./image.png\');\n',
})
})
.then(function() {
return {
compiler: run2.compiler,
exportCompilation: true,
};
});
},
function(output) {
expect(output.runs[0].compiler).to.equal(output.runs[1].compiler);
expect(output.runs[0].compiler).to.equal(output.runs[2].compiler);
expect(output.runs[0].out).to.not.eql(output.runs[1].out);
expect(output.runs[0].out).to.eql(output.runs[2].out);
}
);

});
83 changes: 49 additions & 34 deletions tests/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ function callModule(fn, filename) {

exports.compile = function(fixturePath, options) {
var configPath = path.join(__dirname, '..', 'fixtures', fixturePath, 'webpack.config.js');
var compiler = webpack(callModule(vm.runInThisContext(wrapModule(fs.readFileSync(configPath, 'utf8')), {filename: configPath}), configPath));
var compiler = (options || {}).compiler ||
webpack(callModule(vm.runInThisContext(
wrapModule(fs.readFileSync(configPath, 'utf8')),
{filename: configPath}
), configPath));

compiler.inputFileSystem.purge();
var outputfs = compiler.outputFileSystem = new MemoryFS();

var readdir = Promise.promisify(outputfs.readdir, {context: outputfs});
var readFile = Promise.promisify(outputfs.readFile, {context: outputfs});
var stat = Promise.promisify(outputfs.stat, {context: outputfs});
Expand Down Expand Up @@ -79,6 +86,7 @@ exports.compile = function(fixturePath, options) {
return carry;
}, {})
.then(function(carry) {
// console.log(stats.toJson());
if (options && options.exportStats) {
var statsJson = stats.toJson({
errors: true,
Expand All @@ -94,6 +102,7 @@ exports.compile = function(fixturePath, options) {
return {
out: carry,
compilation: stats.compilation,
compiler: stats.compilation.compiler,
};
}
else {
Expand Down Expand Up @@ -176,21 +185,23 @@ exports.readFiles = function(outputPath) {
}, {});
};

exports.itCompiles = function(name, fixturePath, fnA, fnB, expectHandle) {
if (!fnA) {
exports.itCompiles = function(name, fixturePath, fns, expectHandle) {
if (!fns) {
expectHandle = fixturePath;
fixturePath = name;
fnB = function() {};
fnA = function() {};
fns = [function() {}, function() {}];
}
if (!fnB) {
expectHandle = fnA;
fnB = function() {};
fnA = function() {};
else if (!expectHandle) {
expectHandle = fns;
fns = [function() {}, function() {}];
}
if (!expectHandle) {
expectHandle = fnB;
fnB = fnA;
else if (arguments.length === 4) {
expectHandle = arguments[3];
fns = fns[arguments[2], arguments[2]];
}
else if (arguments.length > 4) {
fns = [].slice.call(arguments, 2, arguments.length - 1);
expectHandle = arguments[arguments.length - 1];
}

before(function() {
Expand All @@ -200,35 +211,39 @@ exports.itCompiles = function(name, fixturePath, fnA, fnB, expectHandle) {
it(name, function() {
this.timeout(20000);
this.slow(4000);
var run1;
var setup1, setup2;
var runs = [];
var setups = [];
var runIndex = 0;
function doRun() {
return Promise.resolve()
.then(function() {})
.then(function() {
return fns[runIndex](runs[runIndex - 1]);
})
.then(function(_setup) {
setups[runIndex] = _setup;
return exports.compile(fixturePath, _setup);
})
.then(function(run) {
runs[runIndex] = run;
runIndex++;
if (runIndex < fns.length) {
return doRun();
}
});
}
return Promise.resolve()
.then(function() {
return fnA();
})
.then(function(_setup1) {
setup1 = _setup1;
run1 = exports.compile(fixturePath, setup1);
return run1;
})
// Delay enough time so that file timestamps are different.
.then(function() {
// return new Promise(function(resolve) {setTimeout(resolve, 1000);});
return doRun();
})
.then(function() {
return fnB();
})
.then(function(_setup2) {
setup2 = _setup2;
var run2 = exports.compile(fixturePath, setup2);
return Promise.all([run1, run2]);
})
.then(function(runs) {
expectHandle({
run1: runs[0],
run2: runs[1],
setup1: setup1,
setup2: setup2,
runs: runs,
setup1: setups[0],
setup2: setups[1],
setups: setups,
});
});
});
Expand Down