Skip to content

fix(@angular-devkit/build-angular): close dev-server on error #23197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,67 +107,66 @@ export async function execute(

let baseUrl = options.baseUrl;
let server;
if (options.devServerTarget) {
const target = targetFromTargetString(options.devServerTarget);
const serverOptions = await context.getTargetOptions(target);

const overrides = {
watch: false,
liveReload: false,
} as DevServerBuilderOptions & json.JsonObject;

if (options.host !== undefined) {
overrides.host = options.host;
} else if (typeof serverOptions.host === 'string') {
options.host = serverOptions.host;
} else {
options.host = overrides.host = 'localhost';
}

if (options.port !== undefined) {
overrides.port = options.port;
} else if (typeof serverOptions.port === 'number') {
options.port = serverOptions.port;
}
try {
if (options.devServerTarget) {
const target = targetFromTargetString(options.devServerTarget);
const serverOptions = await context.getTargetOptions(target);

const overrides = {
watch: false,
liveReload: false,
} as DevServerBuilderOptions & json.JsonObject;

if (options.host !== undefined) {
overrides.host = options.host;
} else if (typeof serverOptions.host === 'string') {
options.host = serverOptions.host;
} else {
options.host = overrides.host = 'localhost';
}

server = await context.scheduleTarget(target, overrides);
const result = await server.result;
if (!result.success) {
return { success: false };
}
if (options.port !== undefined) {
overrides.port = options.port;
} else if (typeof serverOptions.port === 'number') {
options.port = serverOptions.port;
}

if (typeof serverOptions.publicHost === 'string') {
let publicHost = serverOptions.publicHost as string;
if (!/^\w+:\/\//.test(publicHost)) {
publicHost = `${serverOptions.ssl ? 'https' : 'http'}://${publicHost}`;
server = await context.scheduleTarget(target, overrides);
const result = await server.result;
if (!result.success) {
return { success: false };
}

if (typeof serverOptions.publicHost === 'string') {
let publicHost = serverOptions.publicHost;
if (!/^\w+:\/\//.test(publicHost)) {
publicHost = `${serverOptions.ssl ? 'https' : 'http'}://${publicHost}`;
}
const clientUrl = url.parse(publicHost);
baseUrl = url.format(clientUrl);
} else if (typeof result.baseUrl === 'string') {
baseUrl = result.baseUrl;
} else if (typeof result.port === 'number') {
baseUrl = url.format({
protocol: serverOptions.ssl ? 'https' : 'http',
hostname: options.host,
port: result.port.toString(),
});
}
const clientUrl = url.parse(publicHost);
baseUrl = url.format(clientUrl);
} else if (typeof result.baseUrl === 'string') {
baseUrl = result.baseUrl;
} else if (typeof result.port === 'number') {
baseUrl = url.format({
protocol: serverOptions.ssl ? 'https' : 'http',
hostname: options.host,
port: result.port.toString(),
});
}
}

// Like the baseUrl in protractor config file when using the API we need to add
// a trailing slash when provide to the baseUrl.
if (baseUrl && !baseUrl.endsWith('/')) {
baseUrl += '/';
}
// Like the baseUrl in protractor config file when using the API we need to add
// a trailing slash when provide to the baseUrl.
if (baseUrl && !baseUrl.endsWith('/')) {
baseUrl += '/';
}

try {
return await runProtractor(context.workspaceRoot, { ...options, baseUrl });
} catch {
return { success: false };
} finally {
if (server) {
await server.stop();
}
await server?.stop();
}
}

Expand Down