Skip to content

Commit

Permalink
Fix an issue where the same hash was generated when different variables
Browse files Browse the repository at this point in the history
where exported under the same name
  • Loading branch information
lukastaegert committed Mar 6, 2019
1 parent d27c0f6 commit bce6a71
Show file tree
Hide file tree
Showing 36 changed files with 105 additions and 32 deletions.
10 changes: 9 additions & 1 deletion src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,15 @@ export default class Chunk {
if (!this.renderedSource) return '';
const hash = sha256();
hash.update(this.renderedSource.toString());
hash.update(Object.keys(this.exportNames).join(','));
hash.update(
Object.keys(this.exportNames)
.map(exportName => {
const variable = this.exportNames[exportName];
console.log('XX', variable.module.id);
return `${variable.module.id}:${variable.name}:${exportName}`;
})
.join(',')
);
return (this.renderedHash = hash.digest('hex'));
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
define(['./chunk-main2-73b654c7-amd.js'], function (main2) { 'use strict';

main2.log(main2.dep);

});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
define(['./chunk-main2-73b654c7-amd.js'], function (main2) { 'use strict';



return main2.log;

});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

var main2 = require('./chunk-main2-54621bac-cjs.js');

main2.log(main2.dep);

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

var main2 = require('./chunk-main2-54621bac-cjs.js');



module.exports = main2.log;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { a as log, b as dep } from './chunk-main2-80914649-esm.js';

log(dep);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { a as default } from './chunk-main2-80914649-esm.js';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['./chunk-main2-d134c6d9-system.js'], function (exports, module) {
System.register(['./chunk-main2-89018d06-system.js'], function (exports, module) {
'use strict';
var log, dep;
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['./chunk-main2-d134c6d9-system.js'], function (exports, module) {
System.register(['./chunk-main2-89018d06-system.js'], function (exports, module) {
'use strict';
return {
setters: [function (module) {
Expand Down
9 changes: 9 additions & 0 deletions test/file-hashes/samples/export-order-2/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
description: 'creates different hashes if different variables are exported under the same name',
options1: {
input: ['main1', 'dep']
},
options2: {
input: ['main2', 'dep']
}
};
1 change: 1 addition & 0 deletions test/file-hashes/samples/export-order-2/dep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const a = 3;
7 changes: 7 additions & 0 deletions test/file-hashes/samples/export-order-2/main1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { a as b } from './dep.js';

const a = 1;

console.log(a, b);

export { a };
7 changes: 7 additions & 0 deletions test/file-hashes/samples/export-order-2/main2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { a as b } from './dep.js';

const a = 1;

console.log(a, b);

export { b as a };
9 changes: 9 additions & 0 deletions test/file-hashes/samples/export-order/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
description: 'creates different hashes if different variables are exported under the same name',
options1: {
input: ['main1']
},
options2: {
input: ['main2']
}
};
6 changes: 6 additions & 0 deletions test/file-hashes/samples/export-order/main1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const a = 1;
const b = 2;

console.log(a, b);

export { a };
6 changes: 6 additions & 0 deletions test/file-hashes/samples/export-order/main2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const a = 1;
const b = 2;

console.log(a, b);

export { b as a };
9 changes: 9 additions & 0 deletions test/file-hashes/samples/internal-exports/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
description: 'creates different hashes if generated internal exports differ',
options1: {
input: ['main1', 'other']
},
options2: {
input: ['main2', 'other']
}
};
2 changes: 2 additions & 0 deletions test/file-hashes/samples/internal-exports/dep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const a = 1;
export const b = 2;
3 changes: 3 additions & 0 deletions test/file-hashes/samples/internal-exports/main1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { b } from './dep.js';

console.log(b);
3 changes: 3 additions & 0 deletions test/file-hashes/samples/internal-exports/main2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { a } from './dep.js';

console.log(a);
3 changes: 3 additions & 0 deletions test/file-hashes/samples/internal-exports/other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { a, b } from './dep.js';

console.log(a, b);
2 changes: 1 addition & 1 deletion test/misc/bundle-information.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('The bundle object', () => {
.then(({ output }) => {
assert.deepEqual(
output.map(chunk => chunk.fileName),
['input1-eebe7cfb.js', 'input2-370063a6.js', 'generated-chunk-e9283962.js'],
['input1-91cf8b5e.js', 'input2-28e1210a.js', 'generated-chunk-e9283962.js'],
'fileName'
);
assert.deepEqual(
Expand Down

0 comments on commit bce6a71

Please sign in to comment.