Repository navigation
fix(@ngtools/webpack): replace bootstrap code under Ivy unless running in JIT mode #14180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,30 +1,66 @@ | ||
| import {join} from 'path'; | ||
| import {readdirSync} from 'fs'; | ||
| import {expectFileToExist, expectFileToMatch} from '../../utils/fs'; | ||
| import {ng} from '../../utils/process'; | ||
| import {expectGitToBeClean} from '../../utils/git'; | ||
| import { statSync } from 'fs'; | ||
| import { join } from 'path'; | ||
| import { getGlobalVariable } from '../../utils/env'; | ||
| import { expectFileToExist, expectFileToMatch, readFile } from '../../utils/fs'; | ||
| import { expectGitToBeClean } from '../../utils/git'; | ||
| import { ng } from '../../utils/process'; | ||
|
|
||
|
|
||
| export default function() { | ||
| function verifySize(bundle: string, baselineBytes: number) { | ||
| const size = statSync(`dist/test-project/${bundle}`).size; | ||
| const percentageBaseline = baselineBytes * 10 / 100; | ||
| const maxSize = baselineBytes + percentageBaseline; | ||
| const minSize = baselineBytes - percentageBaseline; | ||
|
|
||
| if (size >= maxSize) { | ||
| throw new Error( | ||
| `Expected ${bundle} size to be less than ${maxSize / 1024}Kb but it was ${size / 1024}Kb.`, | ||
| ); | ||
| } | ||
|
|
||
| if (size <= minSize) { | ||
| throw new Error( | ||
| `Expected ${bundle} size to be greater than ${minSize / 1024}Kb but it was ${size / 1024}Kb.`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export default async function () { | ||
| // TODO(architect): Delete this test. It is now in devkit/build-angular. | ||
|
|
||
| // Can't use the `ng` helper because somewhere the environment gets | ||
| // stuck to the first build done | ||
| return ng('build', '--prod') | ||
| .then(() => expectFileToExist(join(process.cwd(), 'dist'))) | ||
| // Check for cache busting hash script src | ||
| .then(() => expectFileToMatch('dist/test-project/index.html', /main-es5\.[0-9a-f]{20}\.js/)) | ||
| .then(() => expectFileToMatch('dist/test-project/index.html', /main-es2015\.[0-9a-f]{20}\.js/)) | ||
| .then(() => expectFileToMatch('dist/test-project/index.html', /styles\.[0-9a-f]{20}\.css/)) | ||
| .then(() => expectFileToMatch('dist/test-project/3rdpartylicenses.txt', /MIT/)) | ||
| // Defaults to AoT | ||
| .then(() => { | ||
| const mainES5 = readdirSync('./dist/test-project').find(name => !!name.match(/main-es5.[a-z0-9]+\.js/)); | ||
| expectFileToMatch(`dist/test-project/${mainES5}`, /bootstrapModuleFactory\(/); | ||
|
|
||
| const mainES2015 = readdirSync('./dist/test-project').find(name => !!name.match(/main-es2015.[a-z0-9]+\.js/)); | ||
| expectFileToMatch(`dist/test-project/${mainES5}`, /bootstrapModuleFactory\(/); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This regexp was actually matching the entire contents of the bundle, and in fact this test was not failing for Ivy |
||
| }) | ||
| // Check that the process didn't change local files. | ||
| .then(() => expectGitToBeClean()); | ||
| const argv = getGlobalVariable('argv'); | ||
| const ivyProject = argv['ivy']; | ||
| const bootstrapRegExp = ivyProject | ||
| ? /bootstrapModule\([a-zA-Z]+\)\./ | ||
| : /bootstrapModuleFactory\([a-zA-Z]+\)\./; | ||
|
|
||
| await ng('build', '--prod'); | ||
| await expectFileToExist(join(process.cwd(), 'dist')); | ||
| // Check for cache busting hash script src | ||
| await expectFileToMatch('dist/test-project/index.html', /main-es5\.[0-9a-f]{20}\.js/); | ||
| await expectFileToMatch('dist/test-project/index.html', /main-es2015\.[0-9a-f]{20}\.js/); | ||
| await expectFileToMatch('dist/test-project/index.html', /styles\.[0-9a-f]{20}\.css/); | ||
| await expectFileToMatch('dist/test-project/3rdpartylicenses.txt', /MIT/); | ||
|
|
||
| const indexContent = await readFile('dist/test-project/index.html'); | ||
| const mainES5Path = indexContent.match(/src="(main-es5\.[a-z0-9]{0,32}\.js)"/)[1]; | ||
| const mainES2015Path = indexContent.match(/src="(main-es2015\.[a-z0-9]{0,32}\.js)"/)[1]; | ||
|
|
||
| // Content checks | ||
| await expectFileToMatch(`dist/test-project/${mainES5Path}`, bootstrapRegExp); | ||
| await expectFileToMatch(`dist/test-project/${mainES2015Path}`, bootstrapRegExp); | ||
|
|
||
| // Size checks in bytes | ||
| if (ivyProject) { | ||
| verifySize(mainES5Path, 147789); | ||
| verifySize(mainES2015Path, 130153); | ||
| } else { | ||
| verifySize(mainES5Path, 155523); | ||
| verifySize(mainES2015Path, 135394); | ||
| } | ||
|
|
||
| // Check that the process didn't change local files. | ||
| await expectGitToBeClean(); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.