File tree Expand file tree Collapse file tree 5 files changed +60
-8
lines changed
packages/angular_devkit/build_angular/src
tests/legacy-cli/e2e/tests/i18n Expand file tree Collapse file tree 5 files changed +60
-8
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ import {
4949 normalizeAssetPatterns ,
5050 normalizeOptimization ,
5151 normalizeSourceMaps ,
52+ urlJoin ,
5253} from '../utils' ;
5354import { BundleActionExecutor } from '../utils/action-executor' ;
5455import { findCachePath } from '../utils/cache-path' ;
@@ -695,11 +696,9 @@ export function buildWebpackBrowser(
695696 for ( const [ locale , outputPath ] of outputPaths . entries ( ) ) {
696697 let localeBaseHref ;
697698 if ( i18n . locales [ locale ] && i18n . locales [ locale ] . baseHref !== '' ) {
698- localeBaseHref = path . posix . join (
699+ localeBaseHref = urlJoin (
699700 options . baseHref || '' ,
700- i18n . locales [ locale ] . baseHref === undefined
701- ? `/${ locale } /`
702- : i18n . locales [ locale ] . baseHref ,
701+ i18n . locales [ locale ] . baseHref ?? `/${ locale } /` ,
703702 ) ;
704703 }
705704
@@ -726,11 +725,9 @@ export function buildWebpackBrowser(
726725 for ( const [ locale , outputPath ] of outputPaths . entries ( ) ) {
727726 let localeBaseHref ;
728727 if ( i18n . locales [ locale ] && i18n . locales [ locale ] . baseHref !== '' ) {
729- localeBaseHref = path . posix . join (
728+ localeBaseHref = urlJoin (
730729 options . baseHref || '' ,
731- i18n . locales [ locale ] . baseHref === undefined
732- ? `/${ locale } /`
733- : i18n . locales [ locale ] . baseHref ,
730+ i18n . locales [ locale ] . baseHref ?? `/${ locale } /` ,
734731 ) ;
735732 }
736733
Original file line number Diff line number Diff line change @@ -15,3 +15,4 @@ export * from './normalize-asset-patterns';
1515export * from './normalize-source-maps' ;
1616export * from './normalize-optimization' ;
1717export * from './normalize-builder-schema' ;
18+ export * from './url' ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @license
3+ * Copyright Google Inc. All Rights Reserved.
4+ *
5+ * Use of this source code is governed by an MIT-style license that can be
6+ * found in the LICENSE file at https://angular.io/license
7+ */
8+
9+
10+ export function urlJoin ( ...parts : string [ ] ) : string {
11+ const [ p , ...rest ] = parts ;
12+
13+ // Remove trailing slash from first part
14+ // Join all parts with `/`
15+ // Dedupe double slashes from path names
16+ return p . replace ( / \/ $ / , '' ) + ( '/' + rest . join ( '/' ) ) . replace ( / \/ \/ + / g, '/' ) ;
17+ }
Original file line number Diff line number Diff line change 1+ /**
2+ * @license
3+ * Copyright Google Inc. All Rights Reserved.
4+ *
5+ * Use of this source code is governed by an MIT-style license that can be
6+ * found in the LICENSE file at https://angular.io/license
7+ */
8+ import { urlJoin } from './url' ;
9+
10+ describe ( 'urlJoin' , ( ) => {
11+ it ( 'should work with absolute url with trailing slash' , ( ) => {
12+ expect ( urlJoin ( 'http://foo.com/' , '/one/' ) ) . toBe ( 'http://foo.com/one/' ) ;
13+ } ) ;
14+
15+ it ( 'should work with absolute url without trailing slash' , ( ) => {
16+ expect ( urlJoin ( 'http://foo.com' , '/one' ) ) . toBe ( 'http://foo.com/one' ) ;
17+ } ) ;
18+
19+ it ( 'should work with absolute url without slashes' , ( ) => {
20+ expect ( urlJoin ( 'http://foo.com' , 'one' , 'two' ) ) . toBe ( 'http://foo.com/one/two' ) ;
21+ } ) ;
22+
23+ it ( 'should work with relative url without slashes' , ( ) => {
24+ expect ( urlJoin ( 'one' , 'two' , 'three' ) ) . toBe ( 'one/two/three' ) ;
25+ } ) ;
26+
27+ it ( 'should keep trailing slash if empty path is provided' , ( ) => {
28+ expect ( urlJoin ( 'one/' , '' ) ) . toBe ( 'one/' ) ;
29+ } ) ;
30+ } ) ;
Original file line number Diff line number Diff line change @@ -100,4 +100,11 @@ export default async function() {
100100 server . close ( ) ;
101101 }
102102 }
103+
104+ // Test absolute base href.
105+ await ng ( 'build' , '--base-href' , 'http://www.domain.com/' ) ;
106+ for ( const { lang, outputPath } of langTranslations ) {
107+ // Verify the HTML base HREF attribute is present
108+ await expectFileToMatch ( `${ outputPath } /index.html` , `href="http://www.domain.com${ baseHrefs [ lang ] || '/' } "` ) ;
109+ }
103110}
You can’t perform that action at this time.
0 commit comments