Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect rendered exports when generating chunk hashes (#2695)
* Create hash test type and red test * Consider actually exported names in hash, resolve #2692 * Add tests for other hashing situations and fix addon hashing * Rework test to check hashes and contents of all files and throw if two files with different content share the same hash; fix another issue for exports that was uncovered by this. * Remove unnecessary expectations
- Loading branch information
1 parent
14a17af
commit 4d082b0
Showing
60 changed files
with
252 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-0d1fa73e-amd.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
define(['./chunk-main2-0a527b43-amd.js'], function (main2) { 'use strict'; | ||
|
||
main2.log(main2.dep); | ||
|
||
}); |
5 changes: 0 additions & 5 deletions
5
test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-a0f4fde5-amd.js
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-236b789c-amd.js
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-adf6abe8-amd.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
define(['./chunk-main2-0a527b43-amd.js'], function (main2) { 'use strict'; | ||
|
||
|
||
|
||
return main2.log; | ||
|
||
}); |
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main1-0dfd3e0e-cjs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
var main2 = require('./chunk-main2-328c93f2-cjs.js'); | ||
|
||
main2.log(main2.dep); |
5 changes: 0 additions & 5 deletions
5
test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main1-3cd10506-cjs.js
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main2-64fa0b57-cjs.js
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main2-b34781c2-cjs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
var main2 = require('./chunk-main2-328c93f2-cjs.js'); | ||
|
||
|
||
|
||
module.exports = main2.log; |
File renamed without changes.
3 changes: 0 additions & 3 deletions
3
test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-5a1ab158-esm.js
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-a2c4132e-esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { a as log, b as dep } from './chunk-main2-d7d48284-esm.js'; | ||
|
||
log(dep); |
1 change: 0 additions & 1 deletion
1
test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-52329ca1-esm.js
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-bc7681ae-esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { a as default } from './chunk-main2-d7d48284-esm.js'; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ted/system/entry-main1-2422e801-system.js → ...ted/system/entry-main1-4e36d280-system.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ted/system/entry-main2-45e98bef-system.js → ...ted/system/entry-main2-ebb140d8-system.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const path = require('path'); | ||
const rollup = require('../../dist/rollup'); | ||
const { extend, runTestSuiteWithSamples } = require('../utils.js'); | ||
const assert = require('assert'); | ||
|
||
runTestSuiteWithSamples('file hashes', path.resolve(__dirname, 'samples'), (dir, config) => { | ||
(config.skip ? describe.skip : config.solo ? describe.only : describe)( | ||
path.basename(dir) + ': ' + config.description, | ||
() => { | ||
it(`generates correct hashes`, () => { | ||
process.chdir(dir); | ||
return Promise.all( | ||
[config.options1, config.options2].map(options => | ||
rollup | ||
.rollup(options) | ||
.then(bundle => | ||
bundle.generate( | ||
extend( | ||
{ format: 'esm', chunkFileNames: '[hash]', entryFileNames: '[hash]' }, | ||
options.output | ||
) | ||
) | ||
) | ||
) | ||
).then(([generated1, generated2]) => { | ||
const fileContentsByHash = new Map(); | ||
addAndCheckFileContentsByHash(fileContentsByHash, generated1); | ||
addAndCheckFileContentsByHash(fileContentsByHash, generated2); | ||
}); | ||
}); | ||
} | ||
); | ||
}); | ||
|
||
function addAndCheckFileContentsByHash(fileContentsByHash, generated) { | ||
for (const chunk of generated.output) { | ||
const hash = chunk.fileName; | ||
if (fileContentsByHash.has(hash)) { | ||
assert.equal( | ||
fileContentsByHash.get(hash), | ||
chunk.code, | ||
'Two chunks contained different code even though the hashes were the same.' | ||
); | ||
} | ||
fileContentsByHash.set(hash, chunk.code); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
description: 'creates different hashes if the banner differs', | ||
options1: { | ||
input: 'main', | ||
output: { | ||
banner: 'console.log(1);' | ||
} | ||
}, | ||
options2: { | ||
input: 'main', | ||
output: { | ||
banner: 'console.log(2);' | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('main'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
description: 'creates different hashes if the content differs', | ||
options1: { | ||
input: { main: 'main1', dep: 'dep1' } | ||
}, | ||
options2: { | ||
input: { main: 'main2', dep: 'dep2' } | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('dep'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('dep'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './dep1'; | ||
|
||
console.log('main1'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './dep2'; | ||
|
||
console.log('main2'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
description: 'creates different hashes if the content of dependencies differs', | ||
options1: { | ||
input: { main: 'main1', dep: 'dep1' } | ||
}, | ||
options2: { | ||
input: { main: 'main2', dep: 'dep2' } | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('dep1'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('dep2'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './dep1'; | ||
|
||
console.log('main'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './dep2'; | ||
|
||
console.log('main'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
description: 'creates different hashes if the generated exports differ', | ||
options1: { | ||
input: ['main1', 'other'] | ||
}, | ||
options2: { | ||
input: ['main2', 'other'] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const mightNotBeImported = 42; | ||
console.log(mightNotBeImported); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {mightNotBeImported} from './dep'; | ||
|
||
console.log('main1', mightNotBeImported); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './dep'; | ||
|
||
console.log('main2'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './dep'; | ||
|
||
console.log('other'); |
11 changes: 11 additions & 0 deletions
11
test/file-hashes/samples/external-dependency-names/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
description: 'creates different hashes if the names of external dependencies differ', | ||
options1: { | ||
input: { mainA: 'main1a', mainB: 'main1b' }, | ||
external: ['external', 'external1'] | ||
}, | ||
options2: { | ||
input: { mainA: 'main2a', mainB: 'main2b' }, | ||
external: ['external', 'external2'] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import 'external'; | ||
|
||
console.log('main'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import 'external1'; | ||
|
||
console.log('main'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import 'external'; | ||
|
||
console.log('main'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import 'external2'; | ||
|
||
console.log('main'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
description: 'creates different hashes if the footer differs', | ||
options1: { | ||
input: 'main', | ||
output: { | ||
footer: 'console.log(1);' | ||
} | ||
}, | ||
options2: { | ||
input: 'main', | ||
output: { | ||
footer: 'console.log(2);' | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('main'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
description: 'creates different hashes if the format differs', | ||
options1: { | ||
input: 'main', | ||
output: { | ||
format: 'esm' | ||
} | ||
}, | ||
options2: { | ||
input: 'main', | ||
output: { | ||
format: 'cjs' | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const x = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
description: 'creates different hashes if the intro differs', | ||
options1: { | ||
input: 'main', | ||
output: { | ||
intro: 'console.log(1);' | ||
} | ||
}, | ||
options2: { | ||
input: 'main', | ||
output: { | ||
intro: 'console.log(2);' | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('main'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
description: 'creates different hashes if the outro differs', | ||
options1: { | ||
input: 'main', | ||
output: { | ||
outro: 'console.log(1);' | ||
} | ||
}, | ||
options2: { | ||
input: 'main', | ||
output: { | ||
outro: 'console.log(2);' | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('main'); |
Oops, something went wrong.