From f49fdb6093ef961877894499e9724faa3dcd149a Mon Sep 17 00:00:00 2001
From: Thomas Sileghem
Date: Sun, 8 Apr 2018 14:48:37 +0100
Subject: [PATCH 1/2] fix(seed): reset seed on each emit
---
lib/plugin.js | 3 +-
spec/plugin.integration.spec.js | 62 +++++++++++++++++++++++++++++++--
2 files changed, 62 insertions(+), 3 deletions(-)
diff --git a/lib/plugin.js b/lib/plugin.js
index 52eff33..6298349 100644
--- a/lib/plugin.js
+++ b/lib/plugin.js
@@ -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;
@@ -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();
diff --git a/spec/plugin.integration.spec.js b/spec/plugin.integration.spec.js
index 61b7ad9..4fe1e32 100644
--- a/spec/plugin.integration.spec.js
+++ b/spec/plugin.integration.spec.js
@@ -142,6 +142,7 @@ describe('ManifestPlugin using real fs', function() {
});
describe('watch mode', function() {
+ var compiler;
var hashes;
beforeAll(function () {
@@ -149,8 +150,12 @@ describe('ManifestPlugin using real fs', function() {
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',
@@ -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();
}
@@ -183,6 +187,60 @@ 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({
+ 'main.js': 'main.js',
+ '3.js': '3.js',
+ });
+
+ done();
+ }
+ });
+ });
+ });
+
describe('multiple compilation', function() {
var nbCompiler = 10;
var originalTimeout;
From 7bbad428a50976b78a9b869c398d2c478dd55ab8 Mon Sep 17 00:00:00 2001
From: Thomas Sileghem
Date: Sun, 8 Apr 2018 14:58:38 +0100
Subject: [PATCH 2/2] test: webpack@4 is returning different result
---
spec/plugin.integration.spec.js | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/spec/plugin.integration.spec.js b/spec/plugin.integration.spec.js
index 4fe1e32..013ef79 100644
--- a/spec/plugin.integration.spec.js
+++ b/spec/plugin.integration.spec.js
@@ -230,10 +230,13 @@ describe('ManifestPlugin using real fs', function() {
isFirstRun = false;
fse.outputFileSync(path.join(__dirname, 'output/watch-import-chunk/index.js'), 'import(\'./chunk1\')');
} else {
- expect(manifest).toEqual({
+ expect(manifest).toEqual(isWebpack4({
+ 'main.js': 'main.js',
+ '1.js': '1.js',
+ }, {
'main.js': 'main.js',
'3.js': '3.js',
- });
+ }));
done();
}