Skip to content

Commit 81ad5ba

Browse files
authored
Fix caching source-less modules (#279)
* chore: Add failing prefetch test PrefetchPlugin can build modules that are then not included in the output chunks, leaving them without rendered source. hard-source must cache module's that do not have a source. * chore: Fix caching source-less modules * chore: Extend base-es2015 and plugin-concatenated test trees
1 parent e6a735d commit 81ad5ba

File tree

16 files changed

+52
-4
lines changed

16 files changed

+52
-4
lines changed

lib/util/serial.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,19 @@ const assigned = exports.assigned = (members) => ({
101101

102102
const created = exports.created = (members) => ({
103103
freeze(arg, module, extra, methods) {
104+
if (!arg) {
105+
return null;
106+
}
104107
const out = {};
105108
for (const key in members) {
106109
out[key] = members[key].freeze(arg[key], module, extra, methods);
107110
}
108111
return out;
109112
},
110113
thaw(arg, frozen, extra, methods) {
114+
if (!arg) {
115+
return null;
116+
}
111117
const out = {};
112118
for (const key in members) {
113119
out[key] = members[key].thaw(arg[key], frozen, extra, methods);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import b from './b';
2+
export {b};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'key';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import fib from './fib';
2-
let key = 'obj';
2+
import {b as key} from './a';
33
export {key, fib};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import b from './b';
2+
export {b};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'a key';
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import fib from './fib';
2-
import {b} from './a'
3-
let key = b;
2+
import {b as key} from './a';
43
export {key, fib};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import b from './b';
2+
export {b};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'key';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function(n) {
2+
return n + (n > 0 ? n - 1 : 0);
3+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {key} from './obj';
2+
3+
console.log(key);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import fib from './fib';
2+
import {b as key} from './a';
3+
export {key, fib};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import b from './b';
2+
export {b};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var webpack = require('webpack');
2+
var HardSourceWebpackPlugin = require('../../..');
3+
4+
module.exports = {
5+
context: __dirname,
6+
entry: './index.js',
7+
output: {
8+
path: __dirname + '/tmp',
9+
filename: 'main.js',
10+
},
11+
plugins: [
12+
new webpack.PrefetchPlugin('./unused.js'),
13+
new HardSourceWebpackPlugin({
14+
cacheDirectory: 'cache',
15+
environmentHash: {
16+
root: __dirname + '/../../..',
17+
},
18+
}),
19+
],
20+
};

tests/plugins-webpack-1.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ describe('plugin webpack use', function() {
3737
itCompilesTwice('plugin-source-map-1dep');
3838
itCompilesTwice.skipIf([c.uglify])('plugin-uglify-devtool-source-map');
3939
itCompilesTwice.skipIf([c.uglify])('plugin-uglify-devtool-source-map', {exportStats: true});
40+
itCompilesTwice('plugin-prefetch-es2015');
41+
itCompilesTwice('plugin-prefetch-es2015', {exportStats: true});
4042

4143
itCompilesHardModules('plugin-dll', ['./fib.js']);
4244
itCompilesHardModules('plugin-dll-reference', ['./index.js']);
4345
itCompilesHardModules('plugin-dll-reference-scope', ['./index.js']);
4446
itCompilesHardModules.skipIf([c.html])('plugin-html-lodash', [/lodash\/lodash\.js$/, /\!\.\/index\.html$/]);
4547
itCompilesHardModules('plugin-serializer-json-base-1dep', ['./fib.js', './index.js']);
48+
itCompilesHardModules('plugin-prefetch-es2015', ['./unused.js']);
4649

4750
});
4851

tests/plugins-webpack-3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describeWP(3)('plugin webpack 3 use', function() {
1414
itCompilesHardModules('plugin-concatenated-module', function(out) {
1515
out.run2.compilation.modules.forEach(function(module) {
1616
if (module.modules) {
17-
expect(module.modules.length).to.equal(2);
17+
expect(module.modules.length).to.equal(4);
1818
module.modules.forEach(function(usedModule) {
1919
expect(usedModule.cacheItem).to.be.ok;
2020
});

0 commit comments

Comments
 (0)