@nx/react-native 16.6.0-beta.3 → 16.6.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/migrations.json +78 -0
  2. package/package.json +13 -12
  3. package/plugins/with-nx-metro.d.ts +5 -1
  4. package/plugins/with-nx-metro.js +27 -22
  5. package/src/executors/build-android/build-android.impl.js +18 -32
  6. package/src/executors/build-android/build-android.impl.ts +21 -50
  7. package/src/executors/build-android/schema.d.ts +5 -3
  8. package/src/executors/build-android/schema.json +14 -8
  9. package/src/executors/build-ios/build-ios.impl.d.ts +1 -1
  10. package/src/executors/build-ios/build-ios.impl.js +23 -42
  11. package/src/executors/build-ios/build-ios.impl.ts +26 -64
  12. package/src/executors/build-ios/schema.d.ts +3 -0
  13. package/src/executors/build-ios/schema.json +8 -6
  14. package/src/executors/bundle/bundle.impl.js +19 -17
  15. package/src/executors/bundle/bundle.impl.ts +24 -23
  16. package/src/executors/pod-install/pod-install.impl.js +1 -1
  17. package/src/executors/pod-install/pod-install.impl.ts +1 -1
  18. package/src/executors/pod-install/schema.d.ts +3 -1
  19. package/src/executors/pod-install/schema.json +11 -1
  20. package/src/executors/run-android/run-android.impl.js +47 -26
  21. package/src/executors/run-android/run-android.impl.ts +40 -45
  22. package/src/executors/run-android/schema.d.ts +2 -2
  23. package/src/executors/run-android/schema.json +9 -5
  24. package/src/executors/run-ios/run-ios.impl.js +47 -31
  25. package/src/executors/run-ios/run-ios.impl.ts +42 -56
  26. package/src/executors/run-ios/schema.d.ts +1 -1
  27. package/src/executors/run-ios/schema.json +7 -6
  28. package/src/executors/start/start.impl.d.ts +4 -2
  29. package/src/executors/start/start.impl.js +35 -24
  30. package/src/executors/start/start.impl.ts +42 -35
  31. package/src/executors/storybook/schema.d.ts +1 -1
  32. package/src/generators/application/application.js +1 -3
  33. package/src/generators/application/files/app/Gemfile.template +2 -2
  34. package/src/generators/application/files/app/android/app/build.gradle.template +2 -49
  35. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.java.template +1 -4
  36. package/src/generators/application/files/app/android/app/src/main/res/drawable/rn_edit_text_material.xml +1 -1
  37. package/src/generators/application/files/app/android/build.gradle.template +1 -1
  38. package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  39. package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.properties +2 -1
  40. package/src/generators/application/files/app/android/gradle.properties +1 -1
  41. package/src/generators/application/files/app/android/gradlew.bat +9 -6
  42. package/src/generators/application/files/app/android/gradlew.template +14 -4
  43. package/src/generators/application/files/app/android/settings.gradle.template +1 -2
  44. package/src/generators/application/files/app/ios/Podfile.template +8 -6
  45. package/src/generators/application/files/app/ios/__className__/AppDelegate.mm.template +0 -10
  46. package/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template +6 -2
  47. package/src/generators/application/files/app/metro.config.js.template +32 -35
  48. package/src/generators/application/files/app/package.json.template +1 -0
  49. package/src/generators/application/lib/add-project.js +7 -0
  50. package/src/generators/init/init.js +1 -2
  51. package/src/generators/library/library.js +1 -1
  52. package/src/migrations/update-16-6-0/add-depends-on.d.ts +6 -0
  53. package/src/migrations/update-16-6-0/add-depends-on.js +43 -0
  54. package/src/migrations/update-16-6-0/update-metro-config.d.ts +6 -0
  55. package/src/migrations/update-16-6-0/update-metro-config.js +71 -0
  56. package/src/utils/get-cli-options.js +4 -1
  57. package/src/utils/pod-install-task.d.ts +10 -2
  58. package/src/utils/pod-install-task.js +12 -4
  59. package/src/utils/versions.d.ts +10 -9
  60. package/src/utils/versions.js +11 -10
  61. package/src/generators/application/files/app/.ruby-version +0 -1
  62. /package/src/generators/library/files/lib/{package.json__tmpl__ → package.json.template} +0 -0
  63. /package/src/generators/library/files/lib/src/{index.ts__tmpl__ → index.ts.template} +0 -0
  64. /package/src/generators/library/files/lib/{tsconfig.json__tmpl__ → tsconfig.json.template} +0 -0
  65. /package/src/generators/library/files/lib/{tsconfig.lib.json__tmpl__ → tsconfig.lib.json.template} +0 -0
@@ -4,42 +4,49 @@ const tslib_1 = require("tslib");
4
4
  const path_1 = require("path");
5
5
  const child_process_1 = require("child_process");
6
6
  const os_1 = require("os");
7
- const ensure_node_modules_symlink_1 = require("../../utils/ensure-node-modules-symlink");
8
- const sync_deps_impl_1 = require("../sync-deps/sync-deps.impl");
9
- const pod_install_task_1 = require("../../utils/pod-install-task");
10
7
  const start_impl_1 = require("../start/start.impl");
11
8
  const get_cli_options_1 = require("../../utils/get-cli-options");
12
- let childProcess;
13
9
  function runIosExecutor(options, context) {
14
10
  return tslib_1.__asyncGenerator(this, arguments, function* runIosExecutor_1() {
11
+ var _a, e_1, _b, _c;
15
12
  if ((0, os_1.platform)() !== 'darwin') {
16
13
  throw new Error(`The run-ios build requires Mac to run`);
17
14
  }
18
15
  const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
19
- (0, ensure_node_modules_symlink_1.ensureNodeModulesSymlink)(context.root, projectRoot);
20
- if (options.sync) {
21
- (0, sync_deps_impl_1.displayNewlyAddedDepsMessage)(context.projectName, yield tslib_1.__await((0, sync_deps_impl_1.syncDeps)(context.projectName, projectRoot, context.root, context.projectGraph)));
22
- }
23
- if (options.install) {
24
- yield tslib_1.__await((0, pod_install_task_1.podInstall)((0, path_1.join)(context.root, projectRoot, 'ios'), options.buildFolder));
25
- }
26
- try {
27
- const tasks = [runCliRunIOS(context.root, projectRoot, options)];
28
- if (options.packager && options.mode !== 'Release') {
29
- tasks.push((0, start_impl_1.runCliStart)(context.root, projectRoot, {
30
- port: options.port,
31
- resetCache: options.resetCache,
32
- interactive: options.interactive,
33
- }));
16
+ if (options.packager && options.mode !== 'Release') {
17
+ const startResults = (0, start_impl_1.default)({
18
+ port: options.port,
19
+ resetCache: options.resetCache,
20
+ interactive: true,
21
+ }, context);
22
+ try {
23
+ for (var _d = true, startResults_1 = tslib_1.__asyncValues(startResults), startResults_1_1; startResults_1_1 = yield tslib_1.__await(startResults_1.next()), _a = startResults_1_1.done, !_a; _d = true) {
24
+ _c = startResults_1_1.value;
25
+ _d = false;
26
+ const result = _c;
27
+ if (result.success) {
28
+ yield tslib_1.__await(runCliRunIOS(context.root, projectRoot, options));
29
+ yield yield tslib_1.__await({
30
+ success: true,
31
+ });
32
+ }
33
+ else {
34
+ return yield tslib_1.__await(result);
35
+ }
36
+ }
34
37
  }
35
- yield tslib_1.__await(Promise.all(tasks));
36
- yield yield tslib_1.__await({ success: true });
37
- }
38
- finally {
39
- if (childProcess) {
40
- childProcess.kill();
38
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
39
+ finally {
40
+ try {
41
+ if (!_d && !_a && (_b = startResults_1.return)) yield tslib_1.__await(_b.call(startResults_1));
42
+ }
43
+ finally { if (e_1) throw e_1.error; }
41
44
  }
42
45
  }
46
+ else {
47
+ yield tslib_1.__await(runCliRunIOS(context.root, projectRoot, options));
48
+ }
49
+ yield yield tslib_1.__await({ success: true });
43
50
  });
44
51
  }
45
52
  exports.default = runIosExecutor;
@@ -49,19 +56,28 @@ function runCliRunIOS(workspaceRoot, projectRoot, options) {
49
56
  * Call the react native cli with option `--no-packager`
50
57
  * Not passing '--packager' due to cli will launch start command from the project root
51
58
  */
52
- childProcess = (0, child_process_1.fork)((0, path_1.join)(workspaceRoot, './node_modules/react-native/cli.js'), ['run-ios', ...createRunIOSOptions(options), '--no-packager'], {
53
- cwd: (0, path_1.join)(workspaceRoot, projectRoot),
59
+ const childProcess = (0, child_process_1.fork)(require.resolve('react-native/cli.js'), ['run-ios', ...createRunIOSOptions(options), '--no-packager'], {
60
+ stdio: 'inherit',
61
+ cwd: (0, path_1.resolve)(workspaceRoot, projectRoot),
54
62
  env: Object.assign(Object.assign({}, process.env), { RCT_METRO_PORT: options.port.toString() }),
55
63
  });
56
- // Ensure the child process is killed when the parent exits
57
- process.on('exit', () => childProcess.kill());
58
- process.on('SIGTERM', () => childProcess.kill());
64
+ /**
65
+ * Ensure the child process is killed when the parent exits
66
+ */
67
+ const processExitListener = (signal) => () => {
68
+ childProcess.kill(signal);
69
+ process.exit();
70
+ };
71
+ process.once('exit', (signal) => childProcess.kill(signal));
72
+ process.once('SIGTERM', processExitListener);
73
+ process.once('SIGINT', processExitListener);
74
+ process.once('SIGQUIT', processExitListener);
59
75
  childProcess.on('error', (err) => {
60
76
  reject(err);
61
77
  });
62
78
  childProcess.on('exit', (code) => {
63
79
  if (code === 0) {
64
- resolve(code);
80
+ resolve(childProcess);
65
81
  }
66
82
  else {
67
83
  reject(code);
@@ -1,24 +1,16 @@
1
1
  import { ExecutorContext } from '@nx/devkit';
2
- import { join } from 'path';
2
+ import { resolve as pathResolve } from 'path';
3
3
  import { ChildProcess, fork } from 'child_process';
4
4
  import { platform } from 'os';
5
5
 
6
- import { ensureNodeModulesSymlink } from '../../utils/ensure-node-modules-symlink';
7
- import {
8
- displayNewlyAddedDepsMessage,
9
- syncDeps,
10
- } from '../sync-deps/sync-deps.impl';
11
- import { podInstall } from '../../utils/pod-install-task';
12
- import { ReactNativeRunIosOptions } from './schema';
13
- import { runCliStart } from '../start/start.impl';
6
+ import startExecutor from '../start/start.impl';
14
7
  import { getCliOptions } from '../../utils/get-cli-options';
15
8
 
9
+ import { ReactNativeRunIosOptions } from './schema';
16
10
  export interface ReactNativeRunIosOutput {
17
11
  success: boolean;
18
12
  }
19
13
 
20
- let childProcess: ChildProcess;
21
-
22
14
  export default async function* runIosExecutor(
23
15
  options: ReactNativeRunIosOptions,
24
16
  context: ExecutorContext
@@ -28,77 +20,71 @@ export default async function* runIosExecutor(
28
20
  }
29
21
  const projectRoot =
30
22
  context.projectsConfigurations.projects[context.projectName].root;
31
- ensureNodeModulesSymlink(context.root, projectRoot);
32
- if (options.sync) {
33
- displayNewlyAddedDepsMessage(
34
- context.projectName,
35
- await syncDeps(
36
- context.projectName,
37
- projectRoot,
38
- context.root,
39
- context.projectGraph
40
- )
41
- );
42
- }
43
23
 
44
- if (options.install) {
45
- await podInstall(
46
- join(context.root, projectRoot, 'ios'),
47
- options.buildFolder
24
+ if (options.packager && options.mode !== 'Release') {
25
+ const startResults = startExecutor(
26
+ {
27
+ port: options.port,
28
+ resetCache: options.resetCache,
29
+ interactive: true,
30
+ },
31
+ context
48
32
  );
49
- }
50
-
51
- try {
52
- const tasks = [runCliRunIOS(context.root, projectRoot, options)];
53
- if (options.packager && options.mode !== 'Release') {
54
- tasks.push(
55
- runCliStart(context.root, projectRoot, {
56
- port: options.port,
57
- resetCache: options.resetCache,
58
- interactive: options.interactive,
59
- })
60
- );
61
- }
62
-
63
- await Promise.all(tasks);
64
-
65
- yield { success: true };
66
- } finally {
67
- if (childProcess) {
68
- childProcess.kill();
33
+ for await (const result of startResults) {
34
+ if (result.success) {
35
+ await runCliRunIOS(context.root, projectRoot, options);
36
+ yield {
37
+ success: true,
38
+ };
39
+ } else {
40
+ return result;
41
+ }
69
42
  }
43
+ } else {
44
+ await runCliRunIOS(context.root, projectRoot, options);
70
45
  }
46
+
47
+ yield { success: true };
71
48
  }
72
49
 
73
50
  function runCliRunIOS(
74
51
  workspaceRoot: string,
75
52
  projectRoot: string,
76
53
  options: ReactNativeRunIosOptions
77
- ) {
78
- return new Promise((resolve, reject) => {
54
+ ): Promise<ChildProcess> {
55
+ return new Promise<ChildProcess>((resolve, reject) => {
79
56
  /**
80
57
  * Call the react native cli with option `--no-packager`
81
58
  * Not passing '--packager' due to cli will launch start command from the project root
82
59
  */
83
- childProcess = fork(
84
- join(workspaceRoot, './node_modules/react-native/cli.js'),
60
+ const childProcess = fork(
61
+ require.resolve('react-native/cli.js'),
85
62
  ['run-ios', ...createRunIOSOptions(options), '--no-packager'],
86
63
  {
87
- cwd: join(workspaceRoot, projectRoot),
64
+ stdio: 'inherit',
65
+ cwd: pathResolve(workspaceRoot, projectRoot),
88
66
  env: { ...process.env, RCT_METRO_PORT: options.port.toString() },
89
67
  }
90
68
  );
91
69
 
92
- // Ensure the child process is killed when the parent exits
93
- process.on('exit', () => childProcess.kill());
94
- process.on('SIGTERM', () => childProcess.kill());
70
+ /**
71
+ * Ensure the child process is killed when the parent exits
72
+ */
73
+ const processExitListener = (signal?: number | NodeJS.Signals) => () => {
74
+ childProcess.kill(signal);
75
+ process.exit();
76
+ };
77
+ process.once('exit', (signal) => childProcess.kill(signal));
78
+ process.once('SIGTERM', processExitListener);
79
+ process.once('SIGINT', processExitListener);
80
+ process.once('SIGQUIT', processExitListener);
95
81
 
96
82
  childProcess.on('error', (err) => {
97
83
  reject(err);
98
84
  });
99
85
  childProcess.on('exit', (code) => {
100
86
  if (code === 0) {
101
- resolve(code);
87
+ resolve(childProcess);
102
88
  } else {
103
89
  reject(code);
104
90
  }
@@ -4,7 +4,7 @@ import { ReactNativeStartOptions } from '../start/schema';
4
4
  // part of options form https://github.com/react-native-community/cli/blob/main/packages/cli-platform-ios/src/commands/runIOS/index.ts
5
5
  export interface ReactNativeRunIosOptions extends ReactNativeBuildIosOptions {
6
6
  /**
7
- * @deprecated use mode instead, will be removed in nx 17.
7
+ * @deprecated TODO(v17) use mode instead, will be removed in nx 17.
8
8
  */
9
9
  xcodeConfiguration?: string;
10
10
 
@@ -19,10 +19,6 @@
19
19
  {
20
20
  "name": "Run iOS on a device with udid",
21
21
  "keys": ["udid"]
22
- },
23
- {
24
- "name": "Run `pod install` before building iOS app",
25
- "keys": ["install"]
26
22
  }
27
23
  ],
28
24
  "properties": {
@@ -87,17 +83,22 @@
87
83
  "description": "Explicitly select which scheme and configuration to use before running a build"
88
84
  },
89
85
  "extraParams": {
90
- "type": "string",
86
+ "oneOf": [
87
+ { "type": "array", "items": { "type": "string" } },
88
+ { "type": "string" }
89
+ ],
91
90
  "description": "Custom params that will be passed to xcodebuild command."
92
91
  },
93
92
  "install": {
94
93
  "type": "boolean",
95
94
  "description": "Runs `pod install` for native modules before building iOS app.",
96
- "default": true
95
+ "default": true,
96
+ "x-deprecated": "Add `pod-install` to dependsOn for this target in project.json instead."
97
97
  },
98
98
  "sync": {
99
99
  "type": "boolean",
100
100
  "description": "Syncs npm dependencies to `package.json` (for React Native autolink).",
101
+ "x-deprecated": "Add `sync-deps` to dependsOn for this target in project.json instead.",
101
102
  "default": true
102
103
  },
103
104
  "resetCache": {
@@ -1,8 +1,10 @@
1
+ /// <reference types="node" />
1
2
  import { ExecutorContext } from '@nx/devkit';
3
+ import { ChildProcess } from 'child_process';
2
4
  import { ReactNativeStartOptions } from './schema';
3
5
  export interface ReactNativeStartOutput {
4
- baseUrl?: string;
6
+ port?: number;
5
7
  success: boolean;
6
8
  }
7
9
  export default function startExecutor(options: ReactNativeStartOptions, context: ExecutorContext): AsyncGenerator<ReactNativeStartOutput>;
8
- export declare function runCliStart(workspaceRoot: string, projectRoot: string, options: ReactNativeStartOptions): Promise<void>;
10
+ export declare function runCliStart(workspaceRoot: string, projectRoot: string, options: ReactNativeStartOptions): Promise<ChildProcess>;
@@ -2,33 +2,34 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runCliStart = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const chalk = require("chalk");
6
5
  const devkit_1 = require("@nx/devkit");
7
6
  const child_process_1 = require("child_process");
8
7
  const path_1 = require("path");
9
8
  const ensure_node_modules_symlink_1 = require("../../utils/ensure-node-modules-symlink");
10
9
  const is_packager_running_1 = require("./lib/is-packager-running");
11
- let childProcess;
12
10
  function startExecutor(options, context) {
13
11
  return tslib_1.__asyncGenerator(this, arguments, function* startExecutor_1() {
14
12
  const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
15
13
  (0, ensure_node_modules_symlink_1.ensureNodeModulesSymlink)(context.root, projectRoot);
16
- try {
17
- const baseUrl = `http://localhost:${options.port}`;
18
- const appName = context.projectName;
19
- devkit_1.logger.info(chalk.cyan(`Packager is ready at ${baseUrl}`));
20
- devkit_1.logger.info(`Use ${chalk.bold(`nx run-android ${appName}`)} or ${chalk.bold(`nx run-ios ${appName}`)} to run the native app.`);
21
- yield tslib_1.__await(runCliStart(context.root, projectRoot, options));
22
- yield yield tslib_1.__await({
23
- baseUrl,
24
- success: true,
25
- });
26
- }
27
- finally {
28
- if (childProcess) {
29
- childProcess.kill();
30
- }
14
+ const startProcess = yield tslib_1.__await(runCliStart(context.root, projectRoot, options));
15
+ yield yield tslib_1.__await({
16
+ port: options.port,
17
+ success: true,
18
+ });
19
+ if (!startProcess) {
20
+ return yield tslib_1.__await(void 0);
31
21
  }
22
+ yield tslib_1.__await(new Promise((resolve) => {
23
+ const processExitListener = (signal) => () => {
24
+ startProcess.kill(signal);
25
+ resolve();
26
+ process.exit();
27
+ };
28
+ process.once('exit', (signal) => startProcess.kill(signal));
29
+ process.once('SIGTERM', processExitListener);
30
+ process.once('SIGINT', processExitListener);
31
+ process.once('SIGQUIT', processExitListener);
32
+ }));
32
33
  });
33
34
  }
34
35
  exports.default = startExecutor;
@@ -40,7 +41,7 @@ function runCliStart(workspaceRoot, projectRoot, options) {
40
41
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
41
42
  const result = yield (0, is_packager_running_1.isPackagerRunning)(options.port);
42
43
  if (result === 'running') {
43
- devkit_1.logger.info('JS server already running.');
44
+ devkit_1.logger.info(`JS server already running on port ${options.port}.`);
44
45
  }
45
46
  else if (result === 'unrecognized') {
46
47
  devkit_1.logger.warn('JS server not recognized.');
@@ -49,7 +50,7 @@ function runCliStart(workspaceRoot, projectRoot, options) {
49
50
  // result === 'not_running'
50
51
  devkit_1.logger.info('Starting JS server...');
51
52
  try {
52
- yield startAsync(workspaceRoot, projectRoot, options);
53
+ return yield startAsync(workspaceRoot, projectRoot, options);
53
54
  }
54
55
  catch (error) {
55
56
  devkit_1.logger.error(`Failed to start the packager server. Error details: ${error.message}`);
@@ -61,16 +62,26 @@ function runCliStart(workspaceRoot, projectRoot, options) {
61
62
  exports.runCliStart = runCliStart;
62
63
  function startAsync(workspaceRoot, projectRoot, options) {
63
64
  return new Promise((resolve, reject) => {
64
- childProcess = (0, child_process_1.fork)((0, path_1.join)(workspaceRoot, './node_modules/react-native/cli.js'), ['start', ...createStartOptions(options)], { cwd: (0, path_1.join)(workspaceRoot, projectRoot), env: process.env });
65
- // Ensure the child process is killed when the parent exits
66
- process.on('exit', () => childProcess.kill());
67
- process.on('SIGTERM', () => childProcess.kill());
65
+ const childProcess = (0, child_process_1.fork)(require.resolve('react-native/cli.js'), ['start', ...createStartOptions(options)], {
66
+ cwd: (0, path_1.resolve)(workspaceRoot, projectRoot),
67
+ env: process.env,
68
+ stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
69
+ });
70
+ childProcess.stdout.on('data', (data) => {
71
+ process.stdout.write(data);
72
+ if (data.toString().includes('reload the app')) {
73
+ resolve(childProcess);
74
+ }
75
+ });
76
+ childProcess.stderr.on('data', (data) => {
77
+ process.stderr.write(data);
78
+ });
68
79
  childProcess.on('error', (err) => {
69
80
  reject(err);
70
81
  });
71
82
  childProcess.on('exit', (code) => {
72
83
  if (code === 0) {
73
- resolve(code);
84
+ resolve(childProcess);
74
85
  }
75
86
  else {
76
87
  reject(code);
@@ -1,18 +1,15 @@
1
- import * as chalk from 'chalk';
2
1
  import { ExecutorContext, logger } from '@nx/devkit';
3
2
  import { ChildProcess, fork } from 'child_process';
4
- import { join } from 'path';
3
+ import { resolve as pathResolve } from 'path';
5
4
  import { ensureNodeModulesSymlink } from '../../utils/ensure-node-modules-symlink';
6
5
  import { isPackagerRunning } from './lib/is-packager-running';
7
6
  import { ReactNativeStartOptions } from './schema';
8
7
 
9
8
  export interface ReactNativeStartOutput {
10
- baseUrl?: string;
9
+ port?: number;
11
10
  success: boolean;
12
11
  }
13
12
 
14
- let childProcess: ChildProcess;
15
-
16
13
  export default async function* startExecutor(
17
14
  options: ReactNativeStartOptions,
18
15
  context: ExecutorContext
@@ -21,27 +18,27 @@ export default async function* startExecutor(
21
18
  context.projectsConfigurations.projects[context.projectName].root;
22
19
  ensureNodeModulesSymlink(context.root, projectRoot);
23
20
 
24
- try {
25
- const baseUrl = `http://localhost:${options.port}`;
26
- const appName = context.projectName;
27
- logger.info(chalk.cyan(`Packager is ready at ${baseUrl}`));
28
- logger.info(
29
- `Use ${chalk.bold(`nx run-android ${appName}`)} or ${chalk.bold(
30
- `nx run-ios ${appName}`
31
- )} to run the native app.`
32
- );
21
+ const startProcess = await runCliStart(context.root, projectRoot, options);
33
22
 
34
- await runCliStart(context.root, projectRoot, options);
23
+ yield {
24
+ port: options.port,
25
+ success: true,
26
+ };
35
27
 
36
- yield {
37
- baseUrl,
38
- success: true,
39
- };
40
- } finally {
41
- if (childProcess) {
42
- childProcess.kill();
43
- }
28
+ if (!startProcess) {
29
+ return;
44
30
  }
31
+ await new Promise<void>((resolve) => {
32
+ const processExitListener = (signal?: number | NodeJS.Signals) => () => {
33
+ startProcess.kill(signal);
34
+ resolve();
35
+ process.exit();
36
+ };
37
+ process.once('exit', (signal) => startProcess.kill(signal));
38
+ process.once('SIGTERM', processExitListener);
39
+ process.once('SIGINT', processExitListener);
40
+ process.once('SIGQUIT', processExitListener);
41
+ });
45
42
  }
46
43
 
47
44
  /*
@@ -52,10 +49,10 @@ export async function runCliStart(
52
49
  workspaceRoot: string,
53
50
  projectRoot: string,
54
51
  options: ReactNativeStartOptions
55
- ): Promise<void> {
52
+ ): Promise<ChildProcess> {
56
53
  const result = await isPackagerRunning(options.port);
57
54
  if (result === 'running') {
58
- logger.info('JS server already running.');
55
+ logger.info(`JS server already running on port ${options.port}.`);
59
56
  } else if (result === 'unrecognized') {
60
57
  logger.warn('JS server not recognized.');
61
58
  } else {
@@ -63,7 +60,7 @@ export async function runCliStart(
63
60
  logger.info('Starting JS server...');
64
61
 
65
62
  try {
66
- await startAsync(workspaceRoot, projectRoot, options);
63
+ return await startAsync(workspaceRoot, projectRoot, options);
67
64
  } catch (error) {
68
65
  logger.error(
69
66
  `Failed to start the packager server. Error details: ${error.message}`
@@ -77,24 +74,34 @@ function startAsync(
77
74
  workspaceRoot: string,
78
75
  projectRoot: string,
79
76
  options: ReactNativeStartOptions
80
- ): Promise<number> {
81
- return new Promise((resolve, reject) => {
82
- childProcess = fork(
83
- join(workspaceRoot, './node_modules/react-native/cli.js'),
77
+ ): Promise<ChildProcess> {
78
+ return new Promise<ChildProcess>((resolve, reject) => {
79
+ const childProcess = fork(
80
+ require.resolve('react-native/cli.js'),
84
81
  ['start', ...createStartOptions(options)],
85
- { cwd: join(workspaceRoot, projectRoot), env: process.env }
82
+ {
83
+ cwd: pathResolve(workspaceRoot, projectRoot),
84
+ env: process.env,
85
+ stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
86
+ }
86
87
  );
87
88
 
88
- // Ensure the child process is killed when the parent exits
89
- process.on('exit', () => childProcess.kill());
90
- process.on('SIGTERM', () => childProcess.kill());
89
+ childProcess.stdout.on('data', (data) => {
90
+ process.stdout.write(data);
91
+ if (data.toString().includes('reload the app')) {
92
+ resolve(childProcess);
93
+ }
94
+ });
95
+ childProcess.stderr.on('data', (data) => {
96
+ process.stderr.write(data);
97
+ });
91
98
 
92
99
  childProcess.on('error', (err) => {
93
100
  reject(err);
94
101
  });
95
102
  childProcess.on('exit', (code) => {
96
103
  if (code === 0) {
97
- resolve(code);
104
+ resolve(childProcess);
98
105
  } else {
99
106
  reject(code);
100
107
  }
@@ -3,7 +3,7 @@ export interface ReactNativeStorybookOptions {
3
3
  outputFile: string;
4
4
  pattern: string;
5
5
  /**
6
- * @deprecated going to be removed in 17
6
+ * @deprecated TODO(v17) no longer used going to be removed in 17
7
7
  */
8
8
  silent: boolean;
9
9
  }
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.reactNativeApplicationSchematic = exports.reactNativeApplicationGenerator = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
- const pod_install_task_1 = require("../../utils/pod-install-task");
7
6
  const symlink_task_1 = require("../../utils/symlink-task");
8
7
  const add_linting_1 = require("../../utils/add-linting");
9
8
  const add_jest_1 = require("../../utils/add-jest");
@@ -25,12 +24,11 @@ function reactNativeApplicationGenerator(host, schema) {
25
24
  const jestTask = yield (0, add_jest_1.addJest)(host, options.unitTestRunner, options.projectName, options.appProjectRoot, options.js, options.skipPackageJson);
26
25
  const detoxTask = yield (0, add_detox_1.addDetox)(host, options);
27
26
  const symlinkTask = (0, symlink_task_1.runSymlink)(host.root, options.appProjectRoot);
28
- const podInstallTask = (0, pod_install_task_1.runPodInstall)((0, devkit_1.joinPathFragments)(host.root, options.iosProjectRoot), options.install);
29
27
  const chmodTaskGradlew = (0, chmod_android_gradle_files_1.chmodAndroidGradlewFilesTask)((0, devkit_1.joinPathFragments)(host.root, options.androidProjectRoot));
30
28
  if (!options.skipFormat) {
31
29
  yield (0, devkit_1.formatFiles)(host);
32
30
  }
33
- return (0, devkit_1.runTasksInSerial)(initTask, lintTask, jestTask, detoxTask, symlinkTask, podInstallTask, chmodTaskGradlew);
31
+ return (0, devkit_1.runTasksInSerial)(initTask, lintTask, jestTask, detoxTask, symlinkTask, chmodTaskGradlew);
34
32
  });
35
33
  }
36
34
  exports.reactNativeApplicationGenerator = reactNativeApplicationGenerator;
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4
- ruby File.read(File.join(__dir__, '.ruby-version')).strip
4
+ ruby ">= 2.6.10"
5
5
 
6
- gem 'cocoapods', '~> 1.11', '>= 1.11.3'
6
+ gem 'cocoapods', '~> 1.12'