Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*/
let details: ServeDetails | undefined;
let serverUrl = options['livereload-url'] ? String(options['livereload-url']) : undefined;
if (!serverUrl) {
details = await runner.run(runnerOpts);
if (details.externallyAccessible === false && !options['native-run']) {
const extra = LOCAL_ADDRESSES.includes(details.externalAddress) ? '\nEnsure you have proper port forwarding setup from your device to your computer.' : '';
this.env.log.warn(`Your device or emulator may not be able to access ${strong(details.externalAddress)}.${extra}\n\n`);
}
serverUrl = `${details.protocol || 'http'}://${details.externalAddress}:${details.port}`;
}
onBeforeExit(async () => {
conf.resetContentSrc();
await conf.save();
});
conf.writeContentSrc(serverUrl);
await conf.save();
const cordovalogws = createPrefixedWriteStream(this.env.log, weak(`[cordova]`));
const buildOpts: IShellRunOptions = { stream: cordovalogws };
// ignore very verbose compiler output on stdout unless --verbose
buildOpts.stdio = options['verbose'] ? 'inherit' : ['pipe', 'ignore', 'pipe'];
if (options['native-run']) {
const [ platform ] = inputs;
const packagePath = await getPackagePath(conf.getProjectInfo().name, platform, { emulator: !options['device'], release: !!options['release'] });
const forwardedPorts = details ? runner.getUsedPorts(runnerOpts, details) : [];
promise.p.stdout.pipe(s);
}
if (promise.p.stderr) {
const s = combineStreams(split2(), ws);
// TODO: https://github.com/angular/angular-cli/issues/10922
s.on('error', (err: Error) => {
debug('Error in subprocess stderr pipe: %o', err);
});
promise.p.stderr.pipe(s);
}
if (killOnExit) {
onBeforeExit(async () => {
if (promise.p.pid) {
await killProcessTree(promise.p.pid);
}
});
}
await promise;
} catch (e) {
if (e instanceof SubprocessError && e.code === ERROR_COMMAND_NOT_FOUND) {
if (fatalOnNotFound) {
throw new FatalException(`Command not found: ${input(command)}`, 127);
} else {
throw e;
}
}
let serverUrl = options['livereload-url'] ? String(options['livereload-url']) : undefined;
if (!serverUrl) {
const details = await runner.run(runnerOpts);
if (details.externallyAccessible === false) {
const extra = LOCAL_ADDRESSES.includes(details.externalAddress) ? '\nEnsure you have proper port forwarding setup from your device to your computer.' : '';
this.env.log.warn(`Your device or emulator may not be able to access ${strong(details.externalAddress)}.${extra}\n\n`);
}
serverUrl = `${details.protocol || 'http'}://${details.externalAddress}:${details.port}`;
}
const conf = new CapacitorConfig(path.resolve(this.project.directory, CAPACITOR_CONFIG_FILE));
onBeforeExit(async () => {
conf.resetServerUrl();
});
conf.setServerUrl(serverUrl);
}