@@ -13,9 +13,10 @@ import {
13
13
BuilderContext ,
14
14
BuilderDescription ,
15
15
} from '@angular-devkit/architect' ;
16
+ import { DevServerResult } from '@angular-devkit/build-webpack' ;
16
17
import { Path , getSystemPath , normalize , resolve , tags } from '@angular-devkit/core' ;
17
18
import { Observable , from , of } from 'rxjs' ;
18
- import { concatMap , take , tap } from 'rxjs/operators' ;
19
+ import { concatMap , map , take , tap } from 'rxjs/operators' ;
19
20
import * as url from 'url' ;
20
21
import { requireProjectModule } from '../angular-cli-files/utilities/require-project-module' ;
21
22
import { DevServerBuilderOptions } from '../dev-server' ;
@@ -70,9 +71,15 @@ export class ProtractorBuilder implements Builder<ProtractorBuilderOptions> {
70
71
71
72
return architect . getBuilderDescription ( builderConfig ) . pipe (
72
73
tap ( description => devServerDescription = description ) ,
73
- concatMap ( devServerDescription => architect . validateBuilderOptions (
74
- builderConfig , devServerDescription ) ) ,
75
- concatMap ( ( ) => {
74
+ concatMap ( devServerDescription =>
75
+ architect . validateBuilderOptions ( builderConfig , devServerDescription ) ) ,
76
+ map ( ( ) => this . context . architect . getBuilder ( devServerDescription , this . context ) ) ,
77
+ concatMap ( builder => builder . run ( builderConfig ) ) ,
78
+ tap ( buildEvent => {
79
+ if ( ! buildEvent . success ) {
80
+ return ;
81
+ }
82
+
76
83
// Compute baseUrl from devServerOptions.
77
84
if ( options . devServerTarget && builderConfig . options . publicHost ) {
78
85
let publicHost = builderConfig . options . publicHost ;
@@ -84,19 +91,18 @@ export class ProtractorBuilder implements Builder<ProtractorBuilderOptions> {
84
91
const clientUrl = url . parse ( publicHost ) ;
85
92
baseUrl = url . format ( clientUrl ) ;
86
93
} else if ( options . devServerTarget ) {
94
+ const result : DevServerResult | undefined = buildEvent . result ;
95
+
87
96
baseUrl = url . format ( {
88
97
protocol : builderConfig . options . ssl ? 'https' : 'http' ,
89
98
hostname : options . host ,
90
- port : builderConfig . options . port . toString ( ) ,
99
+ port : result && result . port . toString ( ) ,
91
100
} ) ;
92
101
}
93
102
94
103
// Save the computed baseUrl back so that Protractor can use it.
95
104
options . baseUrl = baseUrl ;
96
-
97
- return of ( this . context . architect . getBuilder ( devServerDescription , this . context ) ) ;
98
105
} ) ,
99
- concatMap ( builder => builder . run ( builderConfig ) ) ,
100
106
) ;
101
107
}
102
108
0 commit comments