Skip to content

Commit d68faf1

Browse files
committed
feat(cordova): handle lack of port forwarding in ios
We still default --address to localhost, even for Cordova, but we warn about the potential issue running on iOS hardware devices.
1 parent d917e8e commit d68faf1

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

packages/ionic/src/lib/build.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export abstract class BuildRunner<T extends BuildOptions<any>> implements Runner
8181
}
8282

8383
async run(options: T): Promise<void> {
84+
debug('build options: %O', options);
85+
8486
if (options.engine === 'cordova' && !options.platform) {
8587
this.e.log.warn(`Cordova engine chosen without a target platform. This could cause issues. Please use the ${input('--platform')} option.`);
8688
}

packages/ionic/src/lib/integrations/cordova/utils.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,21 @@ export function filterArgumentsForCordova(metadata: CommandMetadata, options: Co
4242
}
4343

4444
export function generateOptionsForCordovaBuild(metadata: CommandMetadata, inputs: CommandLineInputs, options: CommandLineOptions): CommandLineOptions {
45-
const [ platform ] = inputs;
45+
const platform = inputs[0] ? inputs[0] : (options['platform'] ? String(options['platform']) : undefined);
46+
47+
// iOS does not support port forwarding out-of-the-box like Android does.
48+
// See https://github.com/ionic-team/native-run/issues/20
49+
const externalAddressRequired = platform === 'ios' || !options['native-run'];
50+
4651
const includesAppScriptsGroup = OptionFilters.includesGroups('app-scripts');
4752
const excludesCordovaGroup = OptionFilters.excludesGroups('cordova-cli');
4853
const results = filterCommandLineOptions(metadata.options ? metadata.options : [], options, o => excludesCordovaGroup(o) || includesAppScriptsGroup(o));
4954

5055
return {
5156
...results,
52-
externalAddressRequired: options['native-run'] ? false : true,
57+
externalAddressRequired,
5358
nobrowser: true,
5459
engine: 'cordova',
55-
platform: platform ? platform : (options['platform'] ? String(options['platform']) : undefined),
60+
platform,
5661
};
5762
}

packages/ionic/src/lib/serve.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ export abstract class ServeRunner<T extends ServeOptions> implements Runner<T, S
183183
}
184184

185185
async run(options: T): Promise<ServeDetails> {
186+
debug('serve options: %O', options);
187+
186188
await this.beforeServe(options);
187189

188190
const details = await this.serveProject(options);
@@ -220,6 +222,7 @@ export abstract class ServeRunner<T extends ServeOptions> implements Runner<T, S
220222
}
221223

222224
emit('serve:ready', details);
225+
debug('serve details: %O', details);
223226

224227
this.scheduleAfterServe(options, details);
225228

@@ -381,6 +384,12 @@ export abstract class ServeRunner<T extends ServeOptions> implements Runner<T, S
381384
}
382385
}
383386
}
387+
} else if (options.externalAddressRequired && LOCAL_ADDRESSES.includes(options.address)) {
388+
this.e.log.warn(
389+
'An external host may be required to serve for this target device/platform.\n' +
390+
'If you get connection issues on your device or emulator, try connecting the device to the same Wi-Fi network and selecting an accessible IP address for your computer on that network.\n\n' +
391+
`You can use ${input('--address=0.0.0.0')} to run the dev server on all network interfaces, in which case an external address will be selected.\n`
392+
);
384393
}
385394

386395
return [ chosenIP, availableInterfaces ];

0 commit comments

Comments
 (0)