Skip to content

Commit 10217a6

Browse files
authored
fix(seed): reset seed on each emit (#140)
* fix(seed): reset seed on each emit * test: webpack@4 is returning different result
1 parent 80c01c5 commit 10217a6

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

lib/plugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ ManifestPlugin.prototype.getFileType = function(str) {
3333
};
3434

3535
ManifestPlugin.prototype.apply = function(compiler) {
36-
var seed = this.opts.seed || {};
3736
var moduleAssets = {};
3837

3938
var outputFolder = compiler.options.output.path;
@@ -51,6 +50,8 @@ ManifestPlugin.prototype.apply = function(compiler) {
5150
const emitCount = emitCountMap.get(outputName) - 1
5251
emitCountMap.set(outputName, emitCount);
5352

53+
var seed = this.opts.seed || {};
54+
5455
var publicPath = this.opts.publicPath != null ? this.opts.publicPath : compilation.options.output.publicPath;
5556
var stats = compilation.getStats().toJson();
5657

spec/plugin.integration.spec.js

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,20 @@ describe('ManifestPlugin using real fs', function() {
142142
});
143143

144144
describe('watch mode', function() {
145+
var compiler;
145146
var hashes;
146147

147148
beforeAll(function () {
148149
fse.outputFileSync(path.join(__dirname, 'output/watch-mode/index.js'), 'console.log(\'v1\')');
149150
hashes = [];
150151
});
151152

153+
afterAll(() => {
154+
compiler.close()
155+
})
156+
152157
it('outputs a manifest of one file', function(done) {
153-
const compiler = webpackCompile({
158+
compiler = webpackCompile({
154159
context: __dirname,
155160
output: {
156161
filename: '[name].[hash].js',
@@ -174,7 +179,6 @@ describe('ManifestPlugin using real fs', function() {
174179

175180
if (hashes.length === 2) {
176181
expect(hashes[0]).not.toEqual(hashes[1]);
177-
compiler.close()
178182
return done();
179183
}
180184

@@ -183,6 +187,63 @@ describe('ManifestPlugin using real fs', function() {
183187
});
184188
});
185189

190+
describe('import() update', () => {
191+
let compiler;
192+
let isFirstRun;
193+
194+
beforeAll(() => {
195+
fse.outputFileSync(path.join(__dirname, 'output/watch-import-chunk/chunk1.js'), 'console.log(\'chunk 1\')');
196+
fse.outputFileSync(path.join(__dirname, 'output/watch-import-chunk/chunk2.js'), 'console.log(\'chunk 2\')');
197+
fse.outputFileSync(path.join(__dirname, 'output/watch-import-chunk/index.js'), 'import(\'./chunk1\')\nimport(\'./chunk2\')');
198+
isFirstRun = true;
199+
});
200+
201+
afterAll(() => {
202+
compiler.close()
203+
})
204+
205+
it('outputs a manifest of one file', function(done) {
206+
compiler = webpackCompile({
207+
context: __dirname,
208+
output: {
209+
filename: '[name].js',
210+
path: path.join(__dirname, 'output/watch-import-chunk')
211+
},
212+
entry: './output/watch-import-chunk/index.js',
213+
watch: true,
214+
plugins: [
215+
new ManifestPlugin(),
216+
new webpack.HotModuleReplacementPlugin()
217+
]
218+
}, {}, function(stats) {
219+
var manifest = JSON.parse(fse.readFileSync(path.join(__dirname, 'output/watch-import-chunk/manifest.json')))
220+
221+
expect(manifest).toBeDefined();
222+
223+
if (isFirstRun) {
224+
expect(manifest).toEqual({
225+
'main.js': 'main.js',
226+
'0.js': '0.js',
227+
'1.js': '1.js'
228+
});
229+
230+
isFirstRun = false;
231+
fse.outputFileSync(path.join(__dirname, 'output/watch-import-chunk/index.js'), 'import(\'./chunk1\')');
232+
} else {
233+
expect(manifest).toEqual(isWebpack4({
234+
'main.js': 'main.js',
235+
'1.js': '1.js',
236+
}, {
237+
'main.js': 'main.js',
238+
'3.js': '3.js',
239+
}));
240+
241+
done();
242+
}
243+
});
244+
});
245+
});
246+
186247
describe('multiple compilation', function() {
187248
var nbCompiler = 10;
188249
var originalTimeout;

0 commit comments

Comments
 (0)