Skip to content
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
7 changes: 7 additions & 0 deletions fixtures/config-bail/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "fixture",
"version": "1.0.0",
"jest": {
"bail": true
}
}
5 changes: 5 additions & 0 deletions fixtures/config-bail/src/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var fact = function(n) {
return n > 0 ? fact(n - 1) + n : 0;
};

module.exports = fact;
3 changes: 3 additions & 0 deletions fixtures/config-bail/src/entry.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('fails', () => {throw new Error();});

it('passes', () => {});
3 changes: 3 additions & 0 deletions fixtures/config-bail/src/entry2.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('fails', () => {throw new Error();});

it('passes', () => {});
3 changes: 3 additions & 0 deletions fixtures/config-bail/src/entry3.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('fails', () => {throw new Error();});

it('passes', () => {});
3 changes: 3 additions & 0 deletions fixtures/config-bail/src/entry4.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('fails', () => {throw new Error();});

it('passes', () => {});
14 changes: 14 additions & 0 deletions fixtures/config-bail/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var join = require('path').join;
var HardSourceWebpackPlugin = require('hard-source-webpack-plugin');

module.exports = {
context: __dirname,
entry: './src/entry',
output: {
path: join(__dirname, 'dist'),
filename: '[name].js'
},
plugins: [
new HardSourceWebpackPlugin()
]
};
4 changes: 4 additions & 0 deletions fixtures/flags-bail/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "fixture",
"version": "1.0.0"
}
5 changes: 5 additions & 0 deletions fixtures/flags-bail/src/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var fact = function(n) {
return n > 0 ? fact(n - 1) + n : 0;
};

module.exports = fact;
3 changes: 3 additions & 0 deletions fixtures/flags-bail/src/entry.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('fails', () => {throw new Error();});

it('passes', () => {});
3 changes: 3 additions & 0 deletions fixtures/flags-bail/src/entry2.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('fails', () => {throw new Error();});

it('passes', () => {});
3 changes: 3 additions & 0 deletions fixtures/flags-bail/src/entry3.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('fails', () => {throw new Error();});

it('passes', () => {});
3 changes: 3 additions & 0 deletions fixtures/flags-bail/src/entry4.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('fails', () => {throw new Error();});

it('passes', () => {});
14 changes: 14 additions & 0 deletions fixtures/flags-bail/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var join = require('path').join;
var HardSourceWebpackPlugin = require('hard-source-webpack-plugin');

module.exports = {
context: __dirname,
entry: './src/entry',
output: {
path: join(__dirname, 'dist'),
filename: '[name].js'
},
plugins: [
new HardSourceWebpackPlugin()
]
};
10 changes: 9 additions & 1 deletion fixtures/module-multiple-loaders-test/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
var join = require('path').join;
var HardSourceWebpackPlugin = require('hard-source-webpack-plugin');

module.exports = {
context: __dirname,
entry: './src/entry',
output: {
path: join(__dirname, 'dist'),
filename: '[name].js'
}
},
plugins: [
new HardSourceWebpackPlugin({
// cacheDirectory: __dirname + '/node_modules/.cache/hard-source/[confighash]',
// recordsPath: __dirname + '/node_modules/.cache/hard-source/[confighash]/records.json',
// configHash: require('node-object-hash')({sort: false}).hash,
})
]
};
9 changes: 8 additions & 1 deletion fixtures/module-multiple-loaders/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
var join = require('path').join;
var HardSourceWebpackPlugin = require('hard-source-webpack-plugin');

module.exports = {
context: __dirname,
entry: './src/entry',
output: {
path: join(__dirname, 'dist'),
filename: '[name].js'
}
},
plugins: [
new HardSourceWebpackPlugin({
cacheDirectory: __dirname + '/node_modules/.cache/hard-source/[confighash]',
configHash: require('node-object-hash')({sort: false}).hash,
})
]
};
4 changes: 4 additions & 0 deletions fixtures/test-entries-src-babel/webpack.config.babel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {join} = require('path');
var HardSourceWebpackPlugin = require('hard-source-webpack-plugin');

module.exports = {
context: __dirname,
Expand All @@ -7,4 +8,7 @@ module.exports = {
path: join(__dirname, 'dist'),
filename: '[name].js',
},
plugins: [
new HardSourceWebpackPlugin()
]
};
6 changes: 5 additions & 1 deletion fixtures/test-entries-src/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
var join = require('path').join;
var HardSourceWebpackPlugin = require('hard-source-webpack-plugin');

module.exports = {
context: __dirname,
entry: './src/entry',
output: {
path: join(__dirname, 'dist'),
filename: '[name].js'
}
},
plugins: [
new HardSourceWebpackPlugin()
]
};
4 changes: 2 additions & 2 deletions fixtures/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const clean = async fullFixturePath => {
await rimraf(fullFixturePath);
};

const run = async fixturePath => {
const run = async (fixturePath, args = []) => {
// These paths need to escape the jest-webpack cache.
const jestWebpackBin = findUp.sync('jest-webpack.js', {
cwd: __dirname,
Expand All @@ -66,7 +66,7 @@ const run = async fixturePath => {

const child = spawn(process.argv[0], [
jestWebpackBin,
], {
].concat(args), {
cwd: fullFixturePath,
stdio: 'pipe',
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"scripts": {
"build": "webpack",
"test": "node ./jest-webpack.js",
"test": "node ./jest-webpack.js --runInBand",
"prepublishOnly": "NODE_ENV=production npm run build && npm test"
},
"keywords": [],
Expand Down
7 changes: 7 additions & 0 deletions src/common-config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const {run, itBuilt, itSkips} = require('../fixtures/utils');

it('bail', () => {
return run('config-bail')
.then(itBuilt(['src/entry.test.js']))
.then(itSkips(['passes']));
}, 30000);
7 changes: 7 additions & 0 deletions src/common-flags.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const {run, itBuilt, itSkips} = require('../fixtures/utils');

it('--bail', () => {
return run('flags-bail', ['--bail'])
.then(itBuilt(['src/entry.test.js']))
.then(itSkips(['passes']));
}, 30000);
4 changes: 4 additions & 0 deletions src/entry-reference-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class EntryReferenceModule extends Module {
}

addData(dep) {
const index = this.dependencies.findIndex(_dep => _dep.request === dep.request);
if (index !== -1) {
this.dependencies.splice(index, 1);
}
this.dependencies.push(dep);
}
}
Expand Down
43 changes: 27 additions & 16 deletions src/entry-reference-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ class EntryReferencePlugin {
normalModuleFactory.plugin('resolver', resolver => (result, callback) => {
const dependency = result.dependency || result.dependencies[0];

// if (dependency instanceof EntryReferenceTransformDependency) {
// return callback(null, dependency.request);
// }
if (dependency instanceof EntryReferenceDependency) {
return callback(null, options.data.entries[dependency.request]);
}
Expand All @@ -52,25 +49,35 @@ class EntryReferencePlugin {
return callback(err);
}
if (typeof data.source === 'function') {
return callback(err, data);
return options.data.compileFile(data.resource, () => {
const dep = new EntryReferenceTransformDependency(data.request);
dep.userRequest = data.userRequest;
dep.module = data;
options.data.entries[data.resource].addData(dep);
callback(err, data);
});
}

if (dependency instanceof EntryReferenceTransformDependency) {
return callback(null, data);
}

if (data.loaders.length === 0 && exclude(data.resource)) {
// return callback(err, data);
return callback(err, new ExternalModule(data.rawRequest, 'commonjs2'));
}

// if (dependency instanceof SingleEntryDependency) {
// referenceModules[data.resource] = new EntryReferenceModule(data);
// return callback(null, referenceModules[data.resource]);
// }

options.data.compileModule(data.request, data.resource, (err, dep) => {
callback(null, new ReferenceEntryModule(data, dep));
if (err) {
return callback(err);
}

const shortResource = relative(compilation.compiler.options.context, data.resource);
if (compilation.compiler.name === shortResource) {
callback(null, data);
}
else {
callback(null, new ReferenceEntryModule(data, dep));
}
});
});
});
Expand All @@ -88,6 +95,15 @@ class EntryReferencePlugin {
refModule.selfModule = entryModule;
});
}

// Ensure modules are in the compilation modules list.
module.dependencies.forEach(dep => {
if (compilation.modules.indexOf(dep.module) === -1) {
dep.module = compilation.modules.find(module => (
module.identifier() === dep.module.identifier()
)``);
}
});
}
else if (module instanceof ReferenceEntryModule) {
refs[module.resource] =
Expand All @@ -100,11 +116,6 @@ class EntryReferencePlugin {
}
}
});
// compilation.modules.forEach(module => {
// if (module instanceof ReferenceEntryModule) {
// module.cacheable = !module.isSelfReference;
// }
// });
});
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/entry-reference-plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ const utils = require('../fixtures/utils');

it('builds multiple versions of a dependency', () => {
return utils.run('module-multiple-loaders')
.then(utils.itPasses)
.then(utils.itBuilt(['src/entry.js']))
.then(utils.itTests(['src/entry.test.js']));
.then(utils.itTests(['src/entry.test.js']))
.then(utils.itPasses);
}, 30000);

it('builds multiple versions of a test file', () => {
return utils.run('module-multiple-loaders-test')
.then(utils.itPasses)
.then(utils.itBuilt(['src/entry.test.js']))
.then(utils.itTests(['src/entry.test.js']));
.then(utils.itTests(['src/entry.test.js']))
.then(utils.itPasses);
}, 30000);
2 changes: 1 addition & 1 deletion src/run-jest-when-done-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class RunJestWhenDone {
jestPath,
// ['--config', join(config.context, 'jest.config.json')],
// ['--rootDir', join(config.context, '.cache/jest/webpack')],
[],
process.argv.slice(2),
{
cwd: join(config.context, '.cache/jest-webpack'),
env: Object.assign({}, process.env, {
Expand Down
19 changes: 12 additions & 7 deletions src/shared-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class SharedData {
const _this = this;

const child = this.compilation.compiler.createChildCompiler(this.compilation, shortResource);
child.records = this.compilation.compiler.records[shortResource][0];
[
new NodeTemplatePlugin({
asyncChunkLoading: false,
Expand All @@ -129,18 +130,18 @@ class SharedData {
new LibraryTemplatePlugin(this.compilation.compiler.options.output.library, this.compilation.compiler.options.output.libraryTarget, this.compilation.compiler.options.output.umdNamedDefine, this.compilation.compiler.options.output.auxiliaryComment || ""),
{
apply(compiler) {
compiler.plugin('this-compilation', compilation => {
compiler.plugin('make', (compilation, cb) => {
// Store compilation to add transforms to later.
_this.compilations[resource] = compilation;

// Use or create a cache for this compilation in the parent cache.
if (compilation.cache) {
if (!compilation.cache[name]) {
compilation.cache[name] = {};
if (!compilation.cache[shortResource]) {
compilation.cache[shortResource] = {};
}
compilation.cache = compilation.cache[name];
compilation.cache = compilation.cache[shortResource];
}
});

compiler.plugin('make', (compilation, cb) => {
_this.startEntry(resource, cb);
return compilation.addEntry(
// context
Expand Down Expand Up @@ -171,12 +172,12 @@ class SharedData {
this.startModule(request);

const dep = new EntryReferenceTransformDependency(request);
this.entries[resource].addData(dep);

this.compilations[resource]
._addModuleChain(dirname(resource), dep, module => {
dep.module = module;
dep.request = module.request;
this.entries[resource].addData(dep);
if (isEntry) {
this.entries[resource].isEntry = true;
this.entries[resource].entryRequest = module.request;
Expand All @@ -187,6 +188,10 @@ class SharedData {

callback(null, dep);
}
else {
const dep = this.entries[resource].dependencies.find(dep => dep.request === request);
callback(null, dep);
}
}, isEntry);
}

Expand Down