@@ -107,67 +107,66 @@ export async function execute(
107
107
108
108
let baseUrl = options . baseUrl ;
109
109
let server ;
110
- if ( options . devServerTarget ) {
111
- const target = targetFromTargetString ( options . devServerTarget ) ;
112
- const serverOptions = await context . getTargetOptions ( target ) ;
113
-
114
- const overrides = {
115
- watch : false ,
116
- liveReload : false ,
117
- } as DevServerBuilderOptions & json . JsonObject ;
118
-
119
- if ( options . host !== undefined ) {
120
- overrides . host = options . host ;
121
- } else if ( typeof serverOptions . host === 'string' ) {
122
- options . host = serverOptions . host ;
123
- } else {
124
- options . host = overrides . host = 'localhost' ;
125
- }
126
110
127
- if ( options . port !== undefined ) {
128
- overrides . port = options . port ;
129
- } else if ( typeof serverOptions . port === 'number' ) {
130
- options . port = serverOptions . port ;
131
- }
111
+ try {
112
+ if ( options . devServerTarget ) {
113
+ const target = targetFromTargetString ( options . devServerTarget ) ;
114
+ const serverOptions = await context . getTargetOptions ( target ) ;
115
+
116
+ const overrides = {
117
+ watch : false ,
118
+ liveReload : false ,
119
+ } as DevServerBuilderOptions & json . JsonObject ;
120
+
121
+ if ( options . host !== undefined ) {
122
+ overrides . host = options . host ;
123
+ } else if ( typeof serverOptions . host === 'string' ) {
124
+ options . host = serverOptions . host ;
125
+ } else {
126
+ options . host = overrides . host = 'localhost' ;
127
+ }
132
128
133
- server = await context . scheduleTarget ( target , overrides ) ;
134
- const result = await server . result ;
135
- if ( ! result . success ) {
136
- return { success : false } ;
137
- }
129
+ if ( options . port !== undefined ) {
130
+ overrides . port = options . port ;
131
+ } else if ( typeof serverOptions . port === 'number' ) {
132
+ options . port = serverOptions . port ;
133
+ }
138
134
139
- if ( typeof serverOptions . publicHost === 'string' ) {
140
- let publicHost = serverOptions . publicHost as string ;
141
- if ( ! / ^ \w + : \/ \/ / . test ( publicHost ) ) {
142
- publicHost = `${ serverOptions . ssl ? 'https' : 'http' } ://${ publicHost } ` ;
135
+ server = await context . scheduleTarget ( target , overrides ) ;
136
+ const result = await server . result ;
137
+ if ( ! result . success ) {
138
+ return { success : false } ;
139
+ }
140
+
141
+ if ( typeof serverOptions . publicHost === 'string' ) {
142
+ let publicHost = serverOptions . publicHost ;
143
+ if ( ! / ^ \w + : \/ \/ / . test ( publicHost ) ) {
144
+ publicHost = `${ serverOptions . ssl ? 'https' : 'http' } ://${ publicHost } ` ;
145
+ }
146
+ const clientUrl = url . parse ( publicHost ) ;
147
+ baseUrl = url . format ( clientUrl ) ;
148
+ } else if ( typeof result . baseUrl === 'string' ) {
149
+ baseUrl = result . baseUrl ;
150
+ } else if ( typeof result . port === 'number' ) {
151
+ baseUrl = url . format ( {
152
+ protocol : serverOptions . ssl ? 'https' : 'http' ,
153
+ hostname : options . host ,
154
+ port : result . port . toString ( ) ,
155
+ } ) ;
143
156
}
144
- const clientUrl = url . parse ( publicHost ) ;
145
- baseUrl = url . format ( clientUrl ) ;
146
- } else if ( typeof result . baseUrl === 'string' ) {
147
- baseUrl = result . baseUrl ;
148
- } else if ( typeof result . port === 'number' ) {
149
- baseUrl = url . format ( {
150
- protocol : serverOptions . ssl ? 'https' : 'http' ,
151
- hostname : options . host ,
152
- port : result . port . toString ( ) ,
153
- } ) ;
154
157
}
155
- }
156
158
157
- // Like the baseUrl in protractor config file when using the API we need to add
158
- // a trailing slash when provide to the baseUrl.
159
- if ( baseUrl && ! baseUrl . endsWith ( '/' ) ) {
160
- baseUrl += '/' ;
161
- }
159
+ // Like the baseUrl in protractor config file when using the API we need to add
160
+ // a trailing slash when provide to the baseUrl.
161
+ if ( baseUrl && ! baseUrl . endsWith ( '/' ) ) {
162
+ baseUrl += '/' ;
163
+ }
162
164
163
- try {
164
165
return await runProtractor ( context . workspaceRoot , { ...options , baseUrl } ) ;
165
166
} catch {
166
167
return { success : false } ;
167
168
} finally {
168
- if ( server ) {
169
- await server . stop ( ) ;
170
- }
169
+ await server ?. stop ( ) ;
171
170
}
172
171
}
173
172
0 commit comments