Skip to content

Commit

Permalink
fix(seed): reset seed on each emit (#140)
Browse files Browse the repository at this point in the history
* fix(seed): reset seed on each emit

* test: webpack@4 is returning different result
  • Loading branch information
mastilver authored Apr 8, 2018
1 parent 80c01c5 commit 10217a6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ ManifestPlugin.prototype.getFileType = function(str) {
};

ManifestPlugin.prototype.apply = function(compiler) {
var seed = this.opts.seed || {};
var moduleAssets = {};

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

var seed = this.opts.seed || {};

var publicPath = this.opts.publicPath != null ? this.opts.publicPath : compilation.options.output.publicPath;
var stats = compilation.getStats().toJson();

Expand Down
65 changes: 63 additions & 2 deletions spec/plugin.integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,20 @@ describe('ManifestPlugin using real fs', function() {
});

describe('watch mode', function() {
var compiler;
var hashes;

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

afterAll(() => {
compiler.close()
})

it('outputs a manifest of one file', function(done) {
const compiler = webpackCompile({
compiler = webpackCompile({
context: __dirname,
output: {
filename: '[name].[hash].js',
Expand All @@ -174,7 +179,6 @@ describe('ManifestPlugin using real fs', function() {

if (hashes.length === 2) {
expect(hashes[0]).not.toEqual(hashes[1]);
compiler.close()
return done();
}

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

describe('import() update', () => {
let compiler;
let isFirstRun;

beforeAll(() => {
fse.outputFileSync(path.join(__dirname, 'output/watch-import-chunk/chunk1.js'), 'console.log(\'chunk 1\')');
fse.outputFileSync(path.join(__dirname, 'output/watch-import-chunk/chunk2.js'), 'console.log(\'chunk 2\')');
fse.outputFileSync(path.join(__dirname, 'output/watch-import-chunk/index.js'), 'import(\'./chunk1\')\nimport(\'./chunk2\')');
isFirstRun = true;
});

afterAll(() => {
compiler.close()
})

it('outputs a manifest of one file', function(done) {
compiler = webpackCompile({
context: __dirname,
output: {
filename: '[name].js',
path: path.join(__dirname, 'output/watch-import-chunk')
},
entry: './output/watch-import-chunk/index.js',
watch: true,
plugins: [
new ManifestPlugin(),
new webpack.HotModuleReplacementPlugin()
]
}, {}, function(stats) {
var manifest = JSON.parse(fse.readFileSync(path.join(__dirname, 'output/watch-import-chunk/manifest.json')))

expect(manifest).toBeDefined();

if (isFirstRun) {
expect(manifest).toEqual({
'main.js': 'main.js',
'0.js': '0.js',
'1.js': '1.js'
});

isFirstRun = false;
fse.outputFileSync(path.join(__dirname, 'output/watch-import-chunk/index.js'), 'import(\'./chunk1\')');
} else {
expect(manifest).toEqual(isWebpack4({
'main.js': 'main.js',
'1.js': '1.js',
}, {
'main.js': 'main.js',
'3.js': '3.js',
}));

done();
}
});
});
});

describe('multiple compilation', function() {
var nbCompiler = 10;
var originalTimeout;
Expand Down

0 comments on commit 10217a6

Please sign in to comment.