@nx/react-native 19.2.0-canary.20240604-0594deb → 19.2.0-rc.0
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.
- package/package.json +8 -8
- package/plugins/plugin.js +1 -1
- package/project.json +1 -1
- package/src/executors/build-android/build-android.impl.ts +0 -69
- package/src/executors/build-ios/build-ios.impl.ts +0 -77
- package/src/executors/bundle/bundle.impl.ts +0 -77
- package/src/executors/ensure-symlink/ensure-symlink.impl.ts +0 -22
- package/src/executors/pod-install/pod-install.impl.ts +0 -21
- package/src/executors/run-android/run-android.impl.ts +0 -94
- package/src/executors/run-ios/run-ios.impl.ts +0 -92
- package/src/executors/start/start.impl.ts +0 -111
- package/src/executors/storybook/storybook.impl.ts +0 -93
- package/src/executors/sync-deps/sync-deps.impl.ts +0 -140
- package/src/executors/upgrade/upgrade.impl.ts +0 -64
- package/src/generators/application/application.spec.ts +0 -260
- package/src/generators/application/lib/normalize-options.spec.ts +0 -211
- package/src/generators/component/component.spec.ts +0 -129
- package/src/generators/init/init.spec.ts +0 -40
- package/src/generators/library/library.spec.ts +0 -423
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.spec.ts +0 -37
- package/src/migrations/update-18-0-0/add-web-configuration.spec.ts +0 -39
- package/src/migrations/update-18-0-0/remove-block-list.spec.ts +0 -68
- package/src/migrations/update-18-0-0/remove-symlink-target.spec.ts +0 -40
- package/src/utils/add-linting.spec.ts +0 -42
- package/src/utils/ensure-node-modules-symlink.spec.ts +0 -108
- package/src/utils/find-all-npm-dependencies.spec.ts +0 -103
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/react-native",
|
|
3
|
-
"version": "19.2.0-
|
|
3
|
+
"version": "19.2.0-rc.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for React Native contains generators for managing React Native applications and libraries within an Nx workspace. It provides: \n\n-Integration with libraries such as Jest, Detox, and Storybook.\n-Scaffolding for creating buildable libraries that can be published to npm.\n-Utilities for automatic workspace refactoring.",
|
|
6
6
|
"keywords": [
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"node-fetch": "^2.6.7",
|
|
38
38
|
"tsconfig-paths": "^4.1.2",
|
|
39
39
|
"tslib": "^2.3.0",
|
|
40
|
-
"@nx/devkit": "19.2.0-
|
|
41
|
-
"@nx/jest": "19.2.0-
|
|
42
|
-
"@nx/js": "19.2.0-
|
|
43
|
-
"@nx/eslint": "19.2.0-
|
|
44
|
-
"@nx/react": "19.2.0-
|
|
45
|
-
"@nx/workspace": "19.2.0-
|
|
46
|
-
"@nrwl/react-native": "19.2.0-
|
|
40
|
+
"@nx/devkit": "19.2.0-rc.0",
|
|
41
|
+
"@nx/jest": "19.2.0-rc.0",
|
|
42
|
+
"@nx/js": "19.2.0-rc.0",
|
|
43
|
+
"@nx/eslint": "19.2.0-rc.0",
|
|
44
|
+
"@nx/react": "19.2.0-rc.0",
|
|
45
|
+
"@nx/workspace": "19.2.0-rc.0",
|
|
46
|
+
"@nrwl/react-native": "19.2.0-rc.0"
|
|
47
47
|
},
|
|
48
48
|
"executors": "./executors.json",
|
|
49
49
|
"ng-update": {
|
package/plugins/plugin.js
CHANGED
|
@@ -9,7 +9,7 @@ const fs_1 = require("fs");
|
|
|
9
9
|
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
10
10
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
11
11
|
const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
|
|
12
|
-
const cachePath = (0, path_1.join)(cache_directory_1.
|
|
12
|
+
const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'react-native.hash');
|
|
13
13
|
const targetsCache = readTargetsCache();
|
|
14
14
|
function readTargetsCache() {
|
|
15
15
|
return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
|
package/project.json
CHANGED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
import { join, resolve as pathResolve } from 'path';
|
|
3
|
-
import { ChildProcess, fork } from 'child_process';
|
|
4
|
-
import { ReactNativeBuildAndroidOptions } from './schema';
|
|
5
|
-
import { chmodAndroidGradlewFiles } from '../../utils/chmod-android-gradle-files';
|
|
6
|
-
import { getCliOptions } from '../../utils/get-cli-options';
|
|
7
|
-
|
|
8
|
-
export interface ReactNativeBuildOutput {
|
|
9
|
-
success: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default async function* buildAndroidExecutor(
|
|
13
|
-
options: ReactNativeBuildAndroidOptions,
|
|
14
|
-
context: ExecutorContext
|
|
15
|
-
): AsyncGenerator<ReactNativeBuildOutput> {
|
|
16
|
-
const projectRoot =
|
|
17
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
18
|
-
chmodAndroidGradlewFiles(join(context.root, projectRoot, 'android'));
|
|
19
|
-
|
|
20
|
-
await runCliBuild(context.root, projectRoot, options);
|
|
21
|
-
yield { success: true };
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function runCliBuild(
|
|
25
|
-
workspaceRoot: string,
|
|
26
|
-
projectRoot: string,
|
|
27
|
-
options: ReactNativeBuildAndroidOptions
|
|
28
|
-
) {
|
|
29
|
-
return new Promise<ChildProcess>((res, reject) => {
|
|
30
|
-
const childProcess = fork(
|
|
31
|
-
require.resolve('react-native/cli.js'),
|
|
32
|
-
['build-android', ...createBuildAndroidOptions(options)],
|
|
33
|
-
{
|
|
34
|
-
stdio: 'inherit',
|
|
35
|
-
cwd: pathResolve(workspaceRoot, projectRoot),
|
|
36
|
-
env: { ...process.env, RCT_METRO_PORT: options.port.toString() },
|
|
37
|
-
}
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Ensure the child process is killed when the parent exits
|
|
42
|
-
*/
|
|
43
|
-
const processExitListener = (signal?: number | NodeJS.Signals) => () => {
|
|
44
|
-
childProcess.kill(signal);
|
|
45
|
-
process.exit();
|
|
46
|
-
};
|
|
47
|
-
process.once('exit', (signal) => childProcess.kill(signal));
|
|
48
|
-
process.once('SIGTERM', processExitListener);
|
|
49
|
-
process.once('SIGINT', processExitListener);
|
|
50
|
-
process.once('SIGQUIT', processExitListener);
|
|
51
|
-
|
|
52
|
-
childProcess.on('error', (err) => {
|
|
53
|
-
reject(err);
|
|
54
|
-
});
|
|
55
|
-
childProcess.on('exit', (code) => {
|
|
56
|
-
if (code === 0) {
|
|
57
|
-
res(childProcess);
|
|
58
|
-
} else {
|
|
59
|
-
reject(code);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const startOptions = ['port', 'resetCache'];
|
|
66
|
-
|
|
67
|
-
function createBuildAndroidOptions(options: ReactNativeBuildAndroidOptions) {
|
|
68
|
-
return getCliOptions<ReactNativeBuildAndroidOptions>(options, startOptions);
|
|
69
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
import { resolve as pathResolve } from 'path';
|
|
3
|
-
import { ChildProcess, fork } from 'child_process';
|
|
4
|
-
import { platform } from 'os';
|
|
5
|
-
|
|
6
|
-
import { ReactNativeBuildIosOptions } from './schema';
|
|
7
|
-
import { getCliOptions } from '../../utils/get-cli-options';
|
|
8
|
-
|
|
9
|
-
export interface ReactNativeBuildIosOutput {
|
|
10
|
-
success: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default async function* buildIosExecutor(
|
|
14
|
-
options: ReactNativeBuildIosOptions,
|
|
15
|
-
context: ExecutorContext
|
|
16
|
-
): AsyncGenerator<ReactNativeBuildIosOutput> {
|
|
17
|
-
if (platform() !== 'darwin') {
|
|
18
|
-
throw new Error(`The run-ios build requires Mac to run`);
|
|
19
|
-
}
|
|
20
|
-
const projectRoot =
|
|
21
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
22
|
-
|
|
23
|
-
await runCliBuildIOS(context.root, projectRoot, options);
|
|
24
|
-
return { success: true };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function runCliBuildIOS(
|
|
28
|
-
workspaceRoot: string,
|
|
29
|
-
projectRoot: string,
|
|
30
|
-
options: ReactNativeBuildIosOptions
|
|
31
|
-
): Promise<ChildProcess> {
|
|
32
|
-
return new Promise<ChildProcess>((resolve, reject) => {
|
|
33
|
-
const childProcess = fork(
|
|
34
|
-
require.resolve('react-native/cli.js'),
|
|
35
|
-
[
|
|
36
|
-
'build-ios',
|
|
37
|
-
...createBuildIOSOptions(options),
|
|
38
|
-
...(process.env.NX_VERBOSE_LOGGING === 'true' ? ['--verbose'] : []),
|
|
39
|
-
],
|
|
40
|
-
{
|
|
41
|
-
cwd: pathResolve(workspaceRoot, projectRoot),
|
|
42
|
-
env: { ...process.env, RCT_METRO_PORT: options.port.toString() },
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Ensure the child process is killed when the parent exits
|
|
48
|
-
*/
|
|
49
|
-
const processExitListener = (signal?: number | NodeJS.Signals) => () => {
|
|
50
|
-
childProcess.kill(signal);
|
|
51
|
-
process.exit();
|
|
52
|
-
};
|
|
53
|
-
process.once('exit', (signal) => childProcess.kill(signal));
|
|
54
|
-
process.once('SIGTERM', processExitListener);
|
|
55
|
-
process.once('SIGINT', processExitListener);
|
|
56
|
-
process.once('SIGQUIT', processExitListener);
|
|
57
|
-
|
|
58
|
-
childProcess.on('error', (err) => {
|
|
59
|
-
reject(err);
|
|
60
|
-
});
|
|
61
|
-
childProcess.on('exit', (code) => {
|
|
62
|
-
if (code === 0) {
|
|
63
|
-
resolve(childProcess);
|
|
64
|
-
} else {
|
|
65
|
-
reject(code);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const startOptions = ['port', 'resetCache'];
|
|
72
|
-
|
|
73
|
-
function createBuildIOSOptions(options: ReactNativeBuildIosOptions) {
|
|
74
|
-
return getCliOptions<ReactNativeBuildIosOptions>(options, startOptions, [
|
|
75
|
-
'buildFolder',
|
|
76
|
-
]);
|
|
77
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { createDirectory } from '@nx/workspace/src/utilities/fileutils';
|
|
2
|
-
import { names, ExecutorContext } from '@nx/devkit';
|
|
3
|
-
import { dirname, join, resolve as pathResolve } from 'path';
|
|
4
|
-
import { ChildProcess, fork } from 'child_process';
|
|
5
|
-
|
|
6
|
-
import { ReactNativeBundleOptions } from './schema';
|
|
7
|
-
|
|
8
|
-
export interface ReactNativeBundleOutput {
|
|
9
|
-
success: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default async function* bundleExecutor(
|
|
13
|
-
options: ReactNativeBundleOptions,
|
|
14
|
-
context: ExecutorContext
|
|
15
|
-
): AsyncGenerator<ReactNativeBundleOutput> {
|
|
16
|
-
const projectRoot =
|
|
17
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
18
|
-
|
|
19
|
-
options.bundleOutput = join(context.root, options.bundleOutput);
|
|
20
|
-
|
|
21
|
-
createDirectory(dirname(options.bundleOutput));
|
|
22
|
-
|
|
23
|
-
await runCliBuild(context.root, projectRoot, options);
|
|
24
|
-
yield { success: true };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function runCliBuild(
|
|
28
|
-
workspaceRoot: string,
|
|
29
|
-
projectRoot: string,
|
|
30
|
-
options: ReactNativeBundleOptions
|
|
31
|
-
): Promise<ChildProcess> {
|
|
32
|
-
return new Promise<ChildProcess>((resolve, reject) => {
|
|
33
|
-
const cliOptions = createBundleOptions(options);
|
|
34
|
-
const childProcess = fork(
|
|
35
|
-
require.resolve('react-native/cli.js'),
|
|
36
|
-
['bundle', ...cliOptions],
|
|
37
|
-
{
|
|
38
|
-
stdio: 'inherit',
|
|
39
|
-
cwd: pathResolve(workspaceRoot, projectRoot),
|
|
40
|
-
env: process.env,
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Ensure the child process is killed when the parent exits
|
|
46
|
-
*/
|
|
47
|
-
const processExitListener = (signal?: number | NodeJS.Signals) => () => {
|
|
48
|
-
childProcess.kill(signal);
|
|
49
|
-
process.exit();
|
|
50
|
-
};
|
|
51
|
-
process.once('exit', (signal) => childProcess.kill(signal));
|
|
52
|
-
process.once('SIGTERM', processExitListener);
|
|
53
|
-
process.once('SIGINT', processExitListener);
|
|
54
|
-
process.once('SIGQUIT', processExitListener);
|
|
55
|
-
|
|
56
|
-
childProcess.on('error', (err) => {
|
|
57
|
-
reject(err);
|
|
58
|
-
});
|
|
59
|
-
childProcess.on('exit', (code) => {
|
|
60
|
-
if (code === 0) {
|
|
61
|
-
resolve(childProcess);
|
|
62
|
-
} else {
|
|
63
|
-
reject(code);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function createBundleOptions(options: ReactNativeBundleOptions) {
|
|
70
|
-
return Object.keys(options).reduce((acc, _k) => {
|
|
71
|
-
const v = options[_k];
|
|
72
|
-
const k = names(_k).fileName;
|
|
73
|
-
if (v === undefined) return acc;
|
|
74
|
-
acc.push(`--${k}`, v);
|
|
75
|
-
return acc;
|
|
76
|
-
}, []);
|
|
77
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
import { ensureNodeModulesSymlink } from '../../utils/ensure-node-modules-symlink';
|
|
3
|
-
|
|
4
|
-
export interface ReactNativeEnsureSymlinkOutput {
|
|
5
|
-
success: boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* TODO (@xiongemi): remove this function in v20.
|
|
10
|
-
* @deprecated It is no longer needed for react native 73.
|
|
11
|
-
*/
|
|
12
|
-
export default async function* ensureSymlinkExecutor(
|
|
13
|
-
_,
|
|
14
|
-
context: ExecutorContext
|
|
15
|
-
): AsyncGenerator<ReactNativeEnsureSymlinkOutput> {
|
|
16
|
-
const projectRoot =
|
|
17
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
18
|
-
|
|
19
|
-
ensureNodeModulesSymlink(context.root, projectRoot);
|
|
20
|
-
|
|
21
|
-
yield { success: true };
|
|
22
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { join } from 'path';
|
|
2
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
3
|
-
|
|
4
|
-
import { runPodInstall } from '../../utils/pod-install-task';
|
|
5
|
-
import { ReactNativePodInstallOptions } from './schema';
|
|
6
|
-
|
|
7
|
-
export interface ReactNativePodInstallOutput {
|
|
8
|
-
success: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default async function* podInstall(
|
|
12
|
-
options: ReactNativePodInstallOptions,
|
|
13
|
-
context: ExecutorContext
|
|
14
|
-
): AsyncGenerator<ReactNativePodInstallOutput> {
|
|
15
|
-
const projectRoot =
|
|
16
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
17
|
-
const iosDirectory = join(context.root, projectRoot, 'ios');
|
|
18
|
-
await runPodInstall(iosDirectory, true, options)();
|
|
19
|
-
|
|
20
|
-
yield { success: true };
|
|
21
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
import { join, resolve as pathResolve } from 'path';
|
|
3
|
-
import { ChildProcess, fork } from 'child_process';
|
|
4
|
-
|
|
5
|
-
import { ReactNativeRunAndroidOptions } from './schema';
|
|
6
|
-
import { runCliStart } from '../start/start.impl';
|
|
7
|
-
import { chmodAndroidGradlewFiles } from '../../utils/chmod-android-gradle-files';
|
|
8
|
-
import { getCliOptions } from '../../utils/get-cli-options';
|
|
9
|
-
|
|
10
|
-
export interface ReactNativeRunAndroidOutput {
|
|
11
|
-
success: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let childProcess: ChildProcess;
|
|
15
|
-
|
|
16
|
-
export default async function* runAndroidExecutor(
|
|
17
|
-
options: ReactNativeRunAndroidOptions,
|
|
18
|
-
context: ExecutorContext
|
|
19
|
-
): AsyncGenerator<ReactNativeRunAndroidOutput> {
|
|
20
|
-
const projectRoot =
|
|
21
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
22
|
-
chmodAndroidGradlewFiles(join(context.root, projectRoot, 'android'));
|
|
23
|
-
|
|
24
|
-
const tasks = [runCliRunAndroid(context.root, projectRoot, options)];
|
|
25
|
-
|
|
26
|
-
if (options.mode !== 'Release') {
|
|
27
|
-
tasks.push(
|
|
28
|
-
runCliStart(context.root, projectRoot, {
|
|
29
|
-
port: options.port,
|
|
30
|
-
resetCache: options.resetCache,
|
|
31
|
-
interactive: true,
|
|
32
|
-
})
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
await Promise.all(tasks);
|
|
37
|
-
|
|
38
|
-
yield { success: true };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function runCliRunAndroid(
|
|
42
|
-
workspaceRoot: string,
|
|
43
|
-
projectRoot: string,
|
|
44
|
-
options: ReactNativeRunAndroidOptions
|
|
45
|
-
): Promise<ChildProcess> {
|
|
46
|
-
return new Promise<ChildProcess>((resolve, reject) => {
|
|
47
|
-
/**
|
|
48
|
-
* Call the react native cli with option `--no-packager`
|
|
49
|
-
* Not passing '--packager' due to cli will launch start command from the project root
|
|
50
|
-
*/
|
|
51
|
-
childProcess = fork(
|
|
52
|
-
require.resolve('react-native/cli.js'),
|
|
53
|
-
['run-android', ...createRunAndroidOptions(options), '--no-packager'],
|
|
54
|
-
{
|
|
55
|
-
stdio: 'inherit',
|
|
56
|
-
cwd: pathResolve(workspaceRoot, projectRoot),
|
|
57
|
-
env: { ...process.env, RCT_METRO_PORT: options.port.toString() },
|
|
58
|
-
}
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Ensure the child process is killed when the parent exits
|
|
63
|
-
*/
|
|
64
|
-
const processExitListener = (signal?: number | NodeJS.Signals) => () => {
|
|
65
|
-
childProcess.kill(signal);
|
|
66
|
-
process.exit();
|
|
67
|
-
};
|
|
68
|
-
process.once('exit', (signal) => childProcess.kill(signal));
|
|
69
|
-
process.once('SIGTERM', processExitListener);
|
|
70
|
-
process.once('SIGINT', processExitListener);
|
|
71
|
-
process.once('SIGQUIT', processExitListener);
|
|
72
|
-
|
|
73
|
-
childProcess.on('error', (err) => {
|
|
74
|
-
reject(err);
|
|
75
|
-
});
|
|
76
|
-
childProcess.on('exit', (code) => {
|
|
77
|
-
if (code === 0) {
|
|
78
|
-
resolve(childProcess);
|
|
79
|
-
} else {
|
|
80
|
-
reject(code);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const startOptions = ['port', 'resetCache'];
|
|
87
|
-
|
|
88
|
-
function createRunAndroidOptions(options: ReactNativeRunAndroidOptions) {
|
|
89
|
-
return getCliOptions<ReactNativeRunAndroidOptions>(options, startOptions, [
|
|
90
|
-
'appId',
|
|
91
|
-
'appIdSuffix',
|
|
92
|
-
'deviceId',
|
|
93
|
-
]);
|
|
94
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext, GeneratorCallback, workspaceRoot } from '@nx/devkit';
|
|
2
|
-
import { resolve as pathResolve } from 'path';
|
|
3
|
-
import { ChildProcess, fork } from 'child_process';
|
|
4
|
-
import { platform } from 'os';
|
|
5
|
-
|
|
6
|
-
import { runCliStart } from '../start/start.impl';
|
|
7
|
-
import { getCliOptions } from '../../utils/get-cli-options';
|
|
8
|
-
|
|
9
|
-
import { ReactNativeRunIosOptions } from './schema';
|
|
10
|
-
export interface ReactNativeRunIosOutput {
|
|
11
|
-
success: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default async function* runIosExecutor(
|
|
15
|
-
options: ReactNativeRunIosOptions,
|
|
16
|
-
context: ExecutorContext
|
|
17
|
-
): AsyncGenerator<ReactNativeRunIosOutput> {
|
|
18
|
-
if (platform() !== 'darwin') {
|
|
19
|
-
throw new Error(`The run-ios build requires Mac to run`);
|
|
20
|
-
}
|
|
21
|
-
const projectRoot =
|
|
22
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
23
|
-
|
|
24
|
-
const tasks = [runCliRunIOS(context.root, projectRoot, options)];
|
|
25
|
-
|
|
26
|
-
if (options.mode !== 'Release') {
|
|
27
|
-
tasks.push(
|
|
28
|
-
runCliStart(context.root, projectRoot, {
|
|
29
|
-
port: options.port,
|
|
30
|
-
resetCache: options.resetCache,
|
|
31
|
-
interactive: true,
|
|
32
|
-
})
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
await Promise.all(tasks);
|
|
37
|
-
|
|
38
|
-
yield { success: true };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function runCliRunIOS(
|
|
42
|
-
workspaceRoot: string,
|
|
43
|
-
projectRoot: string,
|
|
44
|
-
options: ReactNativeRunIosOptions
|
|
45
|
-
): Promise<ChildProcess> {
|
|
46
|
-
return new Promise<ChildProcess>((resolve, reject) => {
|
|
47
|
-
/**
|
|
48
|
-
* Call the react native cli with option `--no-packager`
|
|
49
|
-
* Not passing '--packager' due to cli will launch start command from the project root
|
|
50
|
-
*/
|
|
51
|
-
const childProcess = fork(
|
|
52
|
-
require.resolve('react-native/cli.js'),
|
|
53
|
-
['run-ios', ...createRunIOSOptions(options), '--no-packager'],
|
|
54
|
-
{
|
|
55
|
-
stdio: 'inherit',
|
|
56
|
-
cwd: pathResolve(workspaceRoot, projectRoot),
|
|
57
|
-
env: { ...process.env, RCT_METRO_PORT: options.port.toString() },
|
|
58
|
-
}
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Ensure the child process is killed when the parent exits
|
|
63
|
-
*/
|
|
64
|
-
const processExitListener = (signal?: number | NodeJS.Signals) => () => {
|
|
65
|
-
childProcess.kill(signal);
|
|
66
|
-
process.exit();
|
|
67
|
-
};
|
|
68
|
-
process.once('exit', (signal) => childProcess.kill(signal));
|
|
69
|
-
process.once('SIGTERM', processExitListener);
|
|
70
|
-
process.once('SIGINT', processExitListener);
|
|
71
|
-
process.once('SIGQUIT', processExitListener);
|
|
72
|
-
|
|
73
|
-
childProcess.on('error', (err) => {
|
|
74
|
-
reject(err);
|
|
75
|
-
});
|
|
76
|
-
childProcess.on('exit', (code) => {
|
|
77
|
-
if (code === 0) {
|
|
78
|
-
resolve(childProcess);
|
|
79
|
-
} else {
|
|
80
|
-
reject(code);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const startOptions = ['port', 'resetCache'];
|
|
87
|
-
|
|
88
|
-
function createRunIOSOptions(options: ReactNativeRunIosOptions) {
|
|
89
|
-
return getCliOptions<ReactNativeRunIosOptions>(options, startOptions, [
|
|
90
|
-
'buildFolder',
|
|
91
|
-
]);
|
|
92
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext, logger } from '@nx/devkit';
|
|
2
|
-
import { ChildProcess, fork } from 'child_process';
|
|
3
|
-
import { resolve as pathResolve } from 'path';
|
|
4
|
-
import { isPackagerRunning } from './lib/is-packager-running';
|
|
5
|
-
import { ReactNativeStartOptions } from './schema';
|
|
6
|
-
|
|
7
|
-
export interface ReactNativeStartOutput {
|
|
8
|
-
port?: number;
|
|
9
|
-
success: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default async function* startExecutor(
|
|
13
|
-
options: ReactNativeStartOptions,
|
|
14
|
-
context: ExecutorContext
|
|
15
|
-
): AsyncGenerator<ReactNativeStartOutput> {
|
|
16
|
-
const projectRoot =
|
|
17
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
18
|
-
|
|
19
|
-
await runCliStart(context.root, projectRoot, options);
|
|
20
|
-
|
|
21
|
-
yield {
|
|
22
|
-
port: options.port,
|
|
23
|
-
success: true,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/*
|
|
28
|
-
* Starts the JS bundler and checks for "running" status before notifying
|
|
29
|
-
* that packager has started.
|
|
30
|
-
*/
|
|
31
|
-
export async function runCliStart(
|
|
32
|
-
workspaceRoot: string,
|
|
33
|
-
projectRoot: string,
|
|
34
|
-
options: ReactNativeStartOptions
|
|
35
|
-
): Promise<ChildProcess> {
|
|
36
|
-
const result = await isPackagerRunning(options.port);
|
|
37
|
-
if (result === 'running') {
|
|
38
|
-
logger.info(`JS server already running on port ${options.port}.`);
|
|
39
|
-
} else if (result === 'unrecognized') {
|
|
40
|
-
logger.warn('JS server not recognized.');
|
|
41
|
-
} else {
|
|
42
|
-
// result === 'not_running'
|
|
43
|
-
logger.info('Starting JS server...');
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
return await startAsync(workspaceRoot, projectRoot, options);
|
|
47
|
-
} catch (error) {
|
|
48
|
-
logger.error(
|
|
49
|
-
`Failed to start the packager server. Error details: ${
|
|
50
|
-
error.message ?? error
|
|
51
|
-
}`
|
|
52
|
-
);
|
|
53
|
-
throw error;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function startAsync(
|
|
59
|
-
workspaceRoot: string,
|
|
60
|
-
projectRoot: string,
|
|
61
|
-
options: ReactNativeStartOptions
|
|
62
|
-
): Promise<ChildProcess> {
|
|
63
|
-
return new Promise<ChildProcess>((resolve, reject) => {
|
|
64
|
-
const childProcess = fork(
|
|
65
|
-
require.resolve('react-native/cli.js'),
|
|
66
|
-
['start', ...createStartOptions(options)],
|
|
67
|
-
{
|
|
68
|
-
cwd: pathResolve(workspaceRoot, projectRoot),
|
|
69
|
-
env: process.env,
|
|
70
|
-
stdio: 'inherit',
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
childProcess.on('error', (err) => {
|
|
75
|
-
reject(err);
|
|
76
|
-
});
|
|
77
|
-
childProcess.on('exit', (code) => {
|
|
78
|
-
if (code === 0) {
|
|
79
|
-
resolve(childProcess);
|
|
80
|
-
} else {
|
|
81
|
-
reject(code);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const processExitListener = (signal?: number | NodeJS.Signals) => () => {
|
|
86
|
-
childProcess.kill(signal);
|
|
87
|
-
process.exit();
|
|
88
|
-
};
|
|
89
|
-
process.once('exit', (signal) => childProcess.kill(signal));
|
|
90
|
-
process.once('SIGTERM', processExitListener);
|
|
91
|
-
process.once('SIGINT', processExitListener);
|
|
92
|
-
process.once('SIGQUIT', processExitListener);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function createStartOptions(options) {
|
|
97
|
-
return Object.keys(options).reduce((acc, k) => {
|
|
98
|
-
if (k === 'resetCache') {
|
|
99
|
-
if (options[k] === true) {
|
|
100
|
-
acc.push(`--reset-cache`);
|
|
101
|
-
}
|
|
102
|
-
} else if (k === 'interactive') {
|
|
103
|
-
if (options[k] === false) {
|
|
104
|
-
acc.push(`--no-interactive`);
|
|
105
|
-
}
|
|
106
|
-
} else {
|
|
107
|
-
acc.push(`--${k}`, options[k]);
|
|
108
|
-
}
|
|
109
|
-
return acc;
|
|
110
|
-
}, []);
|
|
111
|
-
}
|