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 {
49
49
normalizeAssetPatterns ,
50
50
normalizeOptimization ,
51
51
normalizeSourceMaps ,
52
+ urlJoin ,
52
53
} from '../utils' ;
53
54
import { BundleActionExecutor } from '../utils/action-executor' ;
54
55
import { findCachePath } from '../utils/cache-path' ;
@@ -695,11 +696,9 @@ export function buildWebpackBrowser(
695
696
for ( const [ locale , outputPath ] of outputPaths . entries ( ) ) {
696
697
let localeBaseHref ;
697
698
if ( i18n . locales [ locale ] && i18n . locales [ locale ] . baseHref !== '' ) {
698
- localeBaseHref = path . posix . join (
699
+ localeBaseHref = urlJoin (
699
700
options . baseHref || '' ,
700
- i18n . locales [ locale ] . baseHref === undefined
701
- ? `/${ locale } /`
702
- : i18n . locales [ locale ] . baseHref ,
701
+ i18n . locales [ locale ] . baseHref ?? `/${ locale } /` ,
703
702
) ;
704
703
}
705
704
@@ -726,11 +725,9 @@ export function buildWebpackBrowser(
726
725
for ( const [ locale , outputPath ] of outputPaths . entries ( ) ) {
727
726
let localeBaseHref ;
728
727
if ( i18n . locales [ locale ] && i18n . locales [ locale ] . baseHref !== '' ) {
729
- localeBaseHref = path . posix . join (
728
+ localeBaseHref = urlJoin (
730
729
options . baseHref || '' ,
731
- i18n . locales [ locale ] . baseHref === undefined
732
- ? `/${ locale } /`
733
- : i18n . locales [ locale ] . baseHref ,
730
+ i18n . locales [ locale ] . baseHref ?? `/${ locale } /` ,
734
731
) ;
735
732
}
736
733
Original file line number Diff line number Diff line change @@ -15,3 +15,4 @@ export * from './normalize-asset-patterns';
15
15
export * from './normalize-source-maps' ;
16
16
export * from './normalize-optimization' ;
17
17
export * 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() {
100
100
server . close ( ) ;
101
101
}
102
102
}
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
+ }
103
110
}
You can’t perform that action at this time.
0 commit comments