-
Notifications
You must be signed in to change notification settings - Fork 12k
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. (#3609)
- Loading branch information
Showing
11 changed files
with
68 additions
and
21 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
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|styles|\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|styles|\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]})...`); | ||
} | ||
}); | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,18 +1,14 @@ | ||
import {normalize} from 'path'; | ||
import {createProjectFromAsset} from '../../../utils/assets'; | ||
import {exec} from '../../../utils/process'; | ||
import {expectFileSizeToBeUnder} from '../../../utils/fs'; | ||
|
||
|
||
export default function(skipCleaning: () => void) { | ||
if (process.platform.startsWith('win')) { | ||
// Disable the test on Windows. | ||
return Promise.resolve(); | ||
} | ||
|
||
return Promise.resolve() | ||
.then(() => createProjectFromAsset('webpack/test-app')) | ||
.then(() => exec('node_modules/.bin/webpack', '-p')) | ||
.then(() => expectFileSizeToBeUnder('dist/app.main.js', 400000)) | ||
.then(() => exec(normalize('node_modules/.bin/webpack'), '-p')) | ||
.then(() => expectFileSizeToBeUnder('dist/app.main.js', 420000)) | ||
.then(() => expectFileSizeToBeUnder('dist/0.app.main.js', 40000)) | ||
.then(() => skipCleaning()); | ||
} |
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