|
| 1 | +import * as fs from 'fs'; |
| 2 | + |
| 3 | +import {ng} from '../../utils/process'; |
| 4 | +import {writeFile} from '../../utils/fs'; |
| 5 | + |
| 6 | + |
| 7 | +export default function() { |
| 8 | + const oldHashes: {[module: string]: string} = {}; |
| 9 | + const newHashes: {[module: string]: string} = {}; |
| 10 | + // First, collect the hashes. |
| 11 | + return ng('build', '--prod') |
| 12 | + .then(() => { |
| 13 | + fs.readdirSync('./dist') |
| 14 | + .forEach(name => { |
| 15 | + if (!name.match(/(main|inline|vendor)\.[a-z0-9]+\.bundle\.js/)) { |
| 16 | + return; |
| 17 | + } |
| 18 | + |
| 19 | + const [module, hash] = name.split('.'); |
| 20 | + oldHashes[module] = hash; |
| 21 | + }); |
| 22 | + }) |
| 23 | + .then(() => writeFile('src/app/app.component.css', 'body { background: red; }')) |
| 24 | + .then(() => ng('build', '--prod')) |
| 25 | + .then(() => { |
| 26 | + fs.readdirSync('./dist') |
| 27 | + .forEach(name => { |
| 28 | + if (!name.match(/(main|inline|vendor)\.[a-z0-9]+\.bundle\.js/)) { |
| 29 | + return; |
| 30 | + } |
| 31 | + |
| 32 | + const [module, hash] = name.split('.'); |
| 33 | + newHashes[module] = hash; |
| 34 | + }); |
| 35 | + }) |
| 36 | + .then(() => { |
| 37 | + console.log(' Validating hashes...'); |
| 38 | + console.log(` Old hashes: ${JSON.stringify(oldHashes)}`); |
| 39 | + console.log(` New hashes: ${JSON.stringify(newHashes)}`); |
| 40 | + |
| 41 | + Object.keys(oldHashes) |
| 42 | + .forEach(module => { |
| 43 | + if (oldHashes[module] == newHashes[module]) { |
| 44 | + throw new Error(`Module "${module}" did not change hash (${oldHashes[module]})...`); |
| 45 | + } |
| 46 | + }); |
| 47 | + }); |
| 48 | +} |
0 commit comments