Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): handle base tag endOffset in inde…
Browse files Browse the repository at this point in the history
…x.html generation

* fix endOffset if the base tag is already present
* add test case for this

Closes #18381
  • Loading branch information
Ayudh authored and clydin committed Aug 25, 2020
1 parent 7b8e217 commit 61701ab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Expand Up @@ -179,7 +179,7 @@ export async function augmentIndexHtml(params: AugmentIndexHtmlOptions): Promise
treeAdapter.setTemplateContent(baseFragment, baseElement);
indexSource.replace(
baseElement.sourceCodeLocation.startOffset,
baseElement.sourceCodeLocation.endOffset,
baseElement.sourceCodeLocation.endOffset - 1,
parse5.serialize(baseFragment, { treeAdapter }),
);
}
Expand Down
Expand Up @@ -49,6 +49,24 @@ describe('augment-index-html', () => {
`);
});

it('should replace base href value', async () => {
const source = augmentIndexHtml({
...indexGeneratorOptions,
inputContent: '<html><head><base href="/"></head><body></body></html>',
baseHref: '/Apps/',
});

const html = await source;
expect(html).toEqual(oneLineHtml`
<html>
<head><base href="/Apps/">
</head>
<body>
</body>
</html>
`);
});

it(`should emit correct script tags when having 'module' and 'non-module' js`, async () => {
const es2015JsFiles: FileInfo[] = [
{ file: 'runtime-es2015.js', extension: '.js', name: 'main' },
Expand Down
Expand Up @@ -235,7 +235,7 @@ describe('Browser Builder service worker', () => {
hashTable: {
'/foo/bar/favicon.ico': '84161b857f5c547e3699ddfbffc6d8d737542e01',
'/foo/bar/assets/folder-asset.txt': '617f202968a6a81050aa617c2e28e1dca11ce8d4',
'/foo/bar/index.html': 'a5359e8e1a516683b32bbb2f9e8bf402dae4738e',
'/foo/bar/index.html': 'e92a780dba6f6099adafb72d7611f6660a91a70b',
},
}));

Expand Down

0 comments on commit 61701ab

Please sign in to comment.