forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(build): hashes in prod builds now changes when ID change.
Fixes angular#2868. Fixes angular#3311.
- Loading branch information
Showing
8 changed files
with
60 additions
and
7 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
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
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,56 @@ | ||
import {oneLine} from 'common-tags'; | ||
import * as fs from 'fs'; | ||
|
||
import {ng} from '../../utils/process'; | ||
import {writeFile} from '../../utils/fs'; | ||
import {addImportToModule} from '../../utils/ast'; | ||
|
||
|
||
export default function() { | ||
const oldHashes: {[module: string]: string} = {}; | ||
const newHashes: {[module: string]: string} = {}; | ||
// First, collect the hashes. | ||
return Promise.resolve() | ||
.then(() => ng('generate', 'module', 'lazy', '--routing')) | ||
.then(() => addImportToModule('src/app/app.module.ts', oneLine` | ||
RouterModule.forRoot([{ path: "lazy", loadChildren: "./lazy/lazy.module#LazyModule" }]) | ||
`, '@angular/router')) | ||
.then(() => ng('build', '--prod')) | ||
.then(() => { | ||
fs.readdirSync('./dist') | ||
.forEach(name => { | ||
if (!name.match(/(main|inline|style|\d+)\.[a-z0-9]+\.bundle\.(js|css)/)) { | ||
return; | ||
} | ||
|
||
const [module, hash] = name.split('.'); | ||
oldHashes[module] = hash; | ||
}); | ||
}) | ||
.then(() => writeFile('src/app/app.component.css', 'h1 { margin: 5px; }')) | ||
.then(() => writeFile('src/styles.css', 'body { background: red; }')) | ||
.then(() => ng('build', '--prod')) | ||
.then(() => { | ||
fs.readdirSync('./dist') | ||
.forEach(name => { | ||
if (!name.match(/(main|inline|style|\d+)\.[a-z0-9]+\.bundle\.(js|css)/)) { | ||
return; | ||
} | ||
|
||
const [module, hash] = name.split('.'); | ||
newHashes[module] = hash; | ||
}); | ||
}) | ||
.then(() => { | ||
console.log(' Validating hashes...'); | ||
console.log(` Old hashes: ${JSON.stringify(oldHashes)}`); | ||
console.log(` New hashes: ${JSON.stringify(newHashes)}`); | ||
|
||
Object.keys(oldHashes) | ||
.forEach(module => { | ||
if (oldHashes[module] == newHashes[module]) { | ||
throw new Error(`Module "${module}" did not change hash (${oldHashes[module]})...`); | ||
} | ||
}); | ||
}); | ||
} |