Skip to content
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

move device logic before bundler, fix sudden bundler exit if failed #1137

Merged
merged 5 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions packages/core/src/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export const generateContextPaths = (pathObj: RnvContextPathObj, dir: string, co
};

export const createRnvContext = (ctx?: {
program: any;
process: any;
cmd: string;
subCmd: string;
RNV_HOME_DIR: string;
program?: any;
process?: any;
cmd?: string;
subCmd?: string;
RNV_HOME_DIR?: string;
}) => {
if (!ctx && !global.RNV_CONTEXT) {
global.RNV_CONTEXT = generateContextDefaults();
Expand Down
3 changes: 2 additions & 1 deletion packages/engine-rn-macos/src/tasks/task.rnv.start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ Dev server running at: ${url}

return true;
}
executeAsync(c, startCmd, { stdio: 'inherit', silent: true, env: { ...generateEnvVars(c) } });
executeAsync(c, startCmd, { stdio: 'inherit', silent: true, env: { ...generateEnvVars(c) } })
.catch(e => logError(e, true));
return true;
}
default:
Expand Down
8 changes: 5 additions & 3 deletions packages/engine-rn-tvos/src/tasks/task.rnv.run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
shouldSkipTask,
} from '@rnv/core';
import { packageAndroid, runAndroid } from '@rnv/sdk-android';
import { runXcodeProject } from '@rnv/sdk-apple';
import { runXcodeProject, getDeviceToRunOn } from '@rnv/sdk-apple';
import { startBundlerIfRequired, waitForBundlerIfRequired } from '@rnv/sdk-react-native';

export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => {
Expand Down Expand Up @@ -47,15 +47,17 @@ export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => {
}
return runAndroid(c);
case TVOS:
// eslint-disable-next-line no-case-declarations
const runDeviceArgs = await getDeviceToRunOn(c);
if (!c.program.only) {
await startBundlerIfRequired(c, TASK_RUN, originTask);
await runXcodeProject(c);
await runXcodeProject(c, runDeviceArgs);
if (!bundleAssets) {
logSummary('BUNDLER STARTED');
}
return waitForBundlerIfRequired(c);
}
return runXcodeProject(c);
return runXcodeProject(c, runDeviceArgs);
default:
return logErrorPlatform(c);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/engine-rn-tvos/src/tasks/task.rnv.start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ Dev server running at: ${url}

return true;
}
executeAsync(c, startCmd, { stdio: 'inherit', silent: true, env: { ...generateEnvVars(c) } });
executeAsync(c, startCmd, { stdio: 'inherit', silent: true, env: { ...generateEnvVars(c) } })
.catch(e => logError(e, true));
return true;
}
default:
Expand Down
3 changes: 2 additions & 1 deletion packages/engine-rn-windows/src/tasks/task.rnv.start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ Dev server running at: ${url}
return true;
}
// child_process_1.spawn('cmd.exe', ['/C', startCmd], { stdio: 'inherit', silent: true, env: { ...generateEnvVars(c) } });
executeAsync(c, startCmd, { stdio: 'inherit', silent: true, env: { ...generateEnvVars(c) } });
executeAsync(c, startCmd, { stdio: 'inherit', silent: true, env: { ...generateEnvVars(c) } })
.catch(e => logError(e, true));

return true;
}
Expand Down
27 changes: 26 additions & 1 deletion packages/engine-rn/src/__tests__/tasks.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createRnvApi, createRnvContext, getContext } from '@rnv/core';
import taskRnvRun from '../tasks/task.rnv.run';
import taskRnvStart from '../tasks/task.rnv.start';

jest.mock('fs');
jest.mock('axios');
Expand All @@ -17,7 +18,7 @@ afterEach(() => {

const originTask = undefined;

const { executeAsync } = require('@rnv/core');
const { executeAsync, logError } = require('@rnv/core');

test('Execute task.rnv.run', async () => {
const ctx = getContext();
Expand All @@ -26,3 +27,27 @@ test('Execute task.rnv.run', async () => {
await expect(taskRnvRun.fn(ctx, undefined, originTask)).resolves.toEqual(true);
// expect(taskManager.executeTask).toHaveBeenCalledWith(c, 'project configure', 'platform list', originTask);
});

test('Execute task.rnv.start with no parent', async () => {
const ctx = getContext();
executeAsync.mockReturnValue(Promise.resolve('{}'));
await taskRnvStart.fn(ctx, undefined, originTask);
await expect(taskRnvRun.fn(ctx, undefined, originTask)).resolves.toEqual(true);
});

test('Execute task.rnv.start', async () => {
const ctx = getContext();
executeAsync.mockReturnValue(Promise.resolve('{}'));
await taskRnvStart.fn(ctx, 'parent', originTask);
expect(executeAsync).toHaveBeenCalledWith(ctx, 'npx react-native start --port undefined --no-interactive', { env: {}, silent: true, stdio: 'inherit' });
await expect(taskRnvRun.fn(ctx, undefined, originTask)).resolves.toEqual(true);
});

test('Execute task.rnv.start with metro failure', async () => {
const ctx = getContext();
executeAsync.mockReturnValue(new Promise((resolve, reject) => reject('Metro failed')));
await taskRnvStart.fn(ctx, 'parent', originTask);
expect(executeAsync).toHaveBeenCalledWith(ctx, 'npx react-native start --port undefined --no-interactive', { env: {}, silent: true, stdio: 'inherit' });
expect(logError).toHaveBeenCalledWith('Metro failed', true);
await expect(taskRnvRun.fn(ctx, undefined, originTask)).resolves.toEqual(true);
});
8 changes: 5 additions & 3 deletions packages/engine-rn/src/tasks/task.rnv.run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
logSummary,
} from '@rnv/core';
import { packageAndroid, runAndroid } from '@rnv/sdk-android';
import { runXcodeProject } from '@rnv/sdk-apple';
import { runXcodeProject, getDeviceToRunOn } from '@rnv/sdk-apple';
import { startBundlerIfRequired, waitForBundlerIfRequired } from '@rnv/sdk-react-native';

export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => {
Expand All @@ -36,15 +36,17 @@ export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => {
switch (platform) {
case IOS:
case MACOS:
// eslint-disable-next-line no-case-declarations
const runDeviceArgs = await getDeviceToRunOn(c);
if (!c.program.only) {
await startBundlerIfRequired(c, TASK_RUN, originTask);
await runXcodeProject(c);
await runXcodeProject(c, runDeviceArgs);
if (!bundleAssets) {
logSummary('BUNDLER STARTED');
}
return waitForBundlerIfRequired(c);
}
return runXcodeProject(c);
return runXcodeProject(c, runDeviceArgs);
case ANDROID:
case ANDROID_TV:
case FIRE_TV:
Expand Down
3 changes: 2 additions & 1 deletion packages/engine-rn/src/tasks/task.rnv.start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ Dev server running at: ${url}

return true;
}
executeAsync(c, startCmd, { stdio: 'inherit', silent: true, env: { ...generateEnvVars(c) } });
executeAsync(c, startCmd, { stdio: 'inherit', silent: true, env: { ...generateEnvVars(c) } })
.catch(e => logError(e, true));
return true;
}
default:
Expand Down
152 changes: 152 additions & 0 deletions packages/sdk-apple/src/__mocks__/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
export const simctlSimJson = {
"devices" : {
"com.apple.CoreSimulator.SimRuntime.tvOS-16-0" : [
{
"lastBootedAt" : "2023-06-26T16:12:32Z",
"udid" : "9B1DE6B2-F79C-42FE-9924-B7B398B33419",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p",
"state" : "Shutdown",
"name" : "Apple TV"
},
{
"lastBootedAt" : "2023-06-27T15:29:59Z",
"udid" : "80DCD18A-92AB-4D04-BC23-670FA763091D",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-2nd-generation-4K",
"state" : "Shutdown",
"name" : "Apple TV 4K (2nd generation)"
},
{
"udid" : "4D5B6984-4B61-47F6-BFE2-4840E092A57B",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-2nd-generation-1080p",
"state" : "Shutdown",
"name" : "Apple TV 4K (at 1080p) (2nd generation)"
}
],
"com.apple.CoreSimulator.SimRuntime.iOS-16-2" : [
{
"lastBootedAt" : "2023-10-04T15:50:14Z",
"udid" : "A3CE2617-4071-4759-BC87-2F687FEA50A7",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-SE-3rd-generation",
"state" : "Shutdown",
"name" : "iPhone SE (3rd generation)"
},
{
"lastBootedAt" : "2023-10-06T09:46:07Z",
"udid" : "0BEDB188-352D-4215-8471-E9E27C670486",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-14",
"state" : "Shutdown",
"name" : "iPhone 14"
},
{
"udid" : "F48330F4-FAF4-4DDE-B011-1B865B80403D",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-14-Plus",
"state" : "Shutdown",
"name" : "iPhone 14 Plus"
},
{
"lastBootedAt" : "2023-08-24T14:15:42Z",
"udid" : "5E37904F-F486-457F-BC42-6DA72F5435B6",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-14-Pro",
"state" : "Shutdown",
"name" : "iPhone 14 Pro"
},
{
"lastBootedAt" : "2023-10-04T10:20:15Z",
"udid" : "6AE9AC96-1150-4EF6-996B-BEBD0914C6A5",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-14-Pro-Max",
"state" : "Shutdown",
"name" : "iPhone 14 Pro Max"
},
{
"udid" : "E6B35619-9082-4F5C-AADE-F3D441A4182B",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-Air-5th-generation",
"state" : "Shutdown",
"name" : "iPad Air (5th generation)"
},
{
"udid" : "ADE58171-412D-40B2-A02F-C8D9F4486776",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-10th-generation",
"state" : "Shutdown",
"name" : "iPad (10th generation)"
},
{
"udid" : "88761714-71CC-4439-BED3-C4A9933A3C62",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-mini-6th-generation",
"state" : "Shutdown",
"name" : "iPad mini (6th generation)"
},
{
"udid" : "CFEAB0D2-0E45-4287-ADB1-DEDBF690C13D",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-Pro-11-inch-4th-generation-8GB",
"state" : "Shutdown",
"name" : "iPad Pro (11-inch) (4th generation)"
},
{
"udid" : "6E1F3D1F-6B37-4415-B487-5C15E82292C7",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-Pro-12-9-inch-6th-generation-8GB",
"state" : "Shutdown",
"name" : "iPad Pro (12.9-inch) (6th generation)"
}
],
"com.apple.CoreSimulator.SimRuntime.tvOS-16-1" : [
{
"udid" : "741EF5F2-ACA2-440D-ABB4-99B10C0FFFAC",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p",
"state" : "Shutdown",
"name" : "Apple TV"
},
{
"lastBootedAt" : "2023-10-06T13:00:20Z",
"udid" : "B6E2EF0C-EDBF-4FA8-8954-CFBEE7120E17",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-3rd-generation-4K",
"state" : "Shutdown",
"name" : "Apple TV 4K (3rd generation)"
},
{
"udid" : "501C0BBC-26B6-4642-B3FE-43B128FF6F4A",
"isAvailable" : true,
"deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-3rd-generation-1080p",
"state" : "Shutdown",
"name" : "Apple TV 4K (3rd generation) (at 1080p)"
}
],
}
}

export const xctraceDevices = `
== Devices ==
Mihai’s Jacket (741EF5F2-EC1A-352D-457F-2B8E5EA6C10A)

== Simulators ==
Apple TV Simulator (16.0) (9B1DE6B2-F79C-42FE-9924-B7B398B33419)
Apple TV Simulator (16.1) (741EF5F2-ACA2-440D-ABB4-99B10C0FFFAC)
Apple TV 4K (2nd generation) Simulator (16.0) (80DCD18A-92AB-4D04-BC23-670FA763091D)
Apple TV 4K (3rd generation) Simulator (16.1) (B6E2EF0C-EDBF-4FA8-8954-CFBEE7120E17)
Apple TV 4K (3rd generation) (at 1080p) Simulator (16.1) (501C0BBC-26B6-4642-B3FE-43B128FF6F4A)
Apple TV 4K (at 1080p) (2nd generation) Simulator (16.0) (4D5B6984-4B61-47F6-BFE2-4840E092A57B)
iPad (10th generation) Simulator (16.2) (ADE58171-412D-40B2-A02F-C8D9F4486776)
iPad Air (5th generation) Simulator (16.2) (E6B35619-9082-4F5C-AADE-F3D441A4182B)
iPad Pro (11-inch) (4th generation) Simulator (16.2) (CFEAB0D2-0E45-4287-ADB1-DEDBF690C13D)
iPad Pro (12.9-inch) (6th generation) Simulator (16.2) (6E1F3D1F-6B37-4415-B487-5C15E82292C7)
iPad mini (6th generation) Simulator (16.2) (88761714-71CC-4439-BED3-C4A9933A3C62)
iPhone 14 Simulator (16.2) (0BEDB188-352D-4215-8471-E9E27C670486)
iPhone 14 Plus Simulator (16.2) (F48330F4-FAF4-4DDE-B011-1B865B80403D)
iPhone 14 Pro Simulator (16.2) (5E37904F-F486-457F-BC42-6DA72F5435B6)
iPhone 14 Pro Max Simulator (16.2) (6AE9AC96-1150-4EF6-996B-BEBD0914C6A5)
iPhone SE (3rd generation) Simulator (16.2) (A3CE2617-4071-4759-BC87-2F687FEA50A7)
`
Loading