Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(seed): reset seed on each emit #140

Merged
merged 2 commits into from
Apr 8, 2018
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
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