Skip to content

Commit cd9e008

Browse files
committed
move dev server startup and add repack support
1 parent 2b5f2d9 commit cd9e008

File tree

4 files changed

+83
-88
lines changed

4 files changed

+83
-88
lines changed

packages/platform-android/src/lib/commands/runAndroid/runAndroid.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,6 @@ export async function runAndroid(
8383
sourceDir: androidProject.sourceDir,
8484
});
8585

86-
logger.info('Starting dev server...');
87-
startDevServer({
88-
root: projectRoot,
89-
reactNativePath,
90-
reactNativeVersion,
91-
platforms,
92-
args: {
93-
interactive: isInteractive(),
94-
clientLogs: args.clientLogs ?? true,
95-
},
96-
});
97-
9886
if (device) {
9987
if (!(await getDevices()).find((d) => d === device.deviceId)) {
10088
// deviceId is undefined until it's launched, hence overwriting it here
@@ -106,6 +94,18 @@ export async function runAndroid(
10694
}
10795
await runOnDevice({ device, androidProject, args, tasks, binaryPath });
10896
}
97+
98+
logger.info('Starting dev serverhhhh...');
99+
startDevServer({
100+
root: projectRoot,
101+
reactNativePath,
102+
reactNativeVersion,
103+
platforms,
104+
args: {
105+
interactive: isInteractive(),
106+
clientLogs: args.clientLogs ?? true,
107+
},
108+
});
109109
} else {
110110
if ((await getDevices()).length === 0) {
111111
if (isInteractive()) {
@@ -127,6 +127,17 @@ export async function runAndroid(
127127
await runOnDevice({ device, androidProject, args, tasks, binaryPath });
128128
}
129129
}
130+
logger.info('Starting dev server...');
131+
startDevServer({
132+
root: projectRoot,
133+
reactNativePath,
134+
reactNativeVersion,
135+
platforms,
136+
args: {
137+
interactive: isInteractive(),
138+
clientLogs: args.clientLogs ?? true,
139+
},
140+
});
130141
}
131142

132143
outro('Success 🎉.');

packages/platform-apple-helpers/src/lib/commands/run/createRun.ts

Lines changed: 26 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,22 @@ export const createRun = async ({
4848
reactNativePath: string;
4949
reactNativeVersion: string;
5050
platforms: { [platform: string]: object };
51-
startDevServer?: (options: StartDevServerArgs) => void;
51+
startDevServer: (options: StartDevServerArgs) => void;
5252
}) => {
53+
54+
const startDevServerHelper = () => {
55+
logger.info('Starting dev server...');
56+
startDevServer({
57+
root: projectRoot,
58+
reactNativePath,
59+
reactNativeVersion,
60+
platforms,
61+
args: {
62+
interactive: isInteractive(),
63+
clientLogs: args.clientLogs ?? true,
64+
},
65+
});
66+
};
5367
validateArgs(args, projectRoot);
5468

5569
const deviceOrSimulator = args.destination
@@ -100,21 +114,10 @@ export const createRun = async ({
100114
fingerprintOptions,
101115
});
102116

103-
if (startDevServer) {
104-
logger.info('Starting dev server...');
105-
startDevServer({
106-
root: projectRoot,
107-
reactNativePath,
108-
reactNativeVersion,
109-
platforms,
110-
args: {
111-
interactive: isInteractive(),
112-
clientLogs: args.clientLogs ?? true,
113-
},
114-
});
115-
}
117+
116118

117119
await runOnMac(appPath);
120+
startDevServerHelper();
118121
return;
119122
} else if (args.catalyst) {
120123
const { appPath, scheme } = await buildApp({
@@ -131,23 +134,11 @@ export const createRun = async ({
131134
fingerprintOptions,
132135
});
133136

134-
// Start dev server after build completes to avoid log clashing
135-
if (startDevServer) {
136-
logger.info('Starting dev server...');
137-
startDevServer({
138-
root: projectRoot,
139-
reactNativePath,
140-
reactNativeVersion,
141-
platforms,
142-
args: {
143-
interactive: isInteractive(),
144-
clientLogs: args.clientLogs ?? true,
145-
},
146-
});
147-
}
148-
137+
138+
149139
if (scheme) {
150140
await runOnMacCatalyst(appPath, scheme);
141+
startDevServerHelper();
151142
return;
152143
} else {
153144
throw new RockError('Failed to get project scheme');
@@ -194,22 +185,10 @@ ${devices
194185
}),
195186
]);
196187

197-
// Start dev server after build completes to avoid log clashing
198-
if (startDevServer) {
199-
logger.info('Starting dev server...');
200-
startDevServer({
201-
root: projectRoot,
202-
reactNativePath,
203-
reactNativeVersion,
204-
platforms,
205-
args: {
206-
interactive: isInteractive(),
207-
clientLogs: args.clientLogs ?? true,
208-
},
209-
});
210-
}
211-
188+
189+
212190
await runOnSimulator(device, appPath, infoPlistPath);
191+
startDevServerHelper();
213192
} else if (device.type === 'device') {
214193
const { appPath, bundleIdentifier } = await buildApp({
215194
args,
@@ -224,27 +203,14 @@ ${devices
224203
fingerprintOptions,
225204
});
226205

227-
// Start dev server after build completes to avoid log clashing
228-
if (startDevServer) {
229-
logger.info('Starting dev server...');
230-
startDevServer({
231-
root: projectRoot,
232-
reactNativePath,
233-
reactNativeVersion,
234-
platforms,
235-
args: {
236-
interactive: isInteractive(),
237-
clientLogs: args.clientLogs ?? true,
238-
},
239-
});
240-
}
241-
242206
await runOnDevice(
243207
device,
244208
appPath,
245209
projectConfig.sourceDir,
246210
bundleIdentifier,
247211
);
212+
startDevServerHelper();
213+
248214
}
249215
return;
250216
} else {
@@ -294,21 +260,6 @@ ${devices
294260
}),
295261
]);
296262

297-
// Start dev server after build completes to avoid log clashing
298-
if (startDevServer) {
299-
logger.info('Starting dev server...');
300-
startDevServer({
301-
root: projectRoot,
302-
reactNativePath,
303-
reactNativeVersion,
304-
platforms,
305-
args: {
306-
interactive: isInteractive(),
307-
clientLogs: args.clientLogs ?? true,
308-
},
309-
});
310-
}
311-
312263
if (bootedDevice.type === 'simulator') {
313264
await runOnSimulator(bootedDevice, appPath, infoPlistPath);
314265
} else {
@@ -320,6 +271,7 @@ ${devices
320271
);
321272
}
322273
}
274+
startDevServerHelper();
323275
}
324276
};
325277

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './lib/pluginRepack.js';
2+
export { startDevServer } from './lib/pluginRepack.js';

packages/plugin-repack/src/lib/pluginRepack.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import commands from '@callstack/repack/commands/rspack';
2-
import type { PluginApi, PluginOutput } from '@rock-js/config';
2+
import type { BundlerPluginOutput, PluginApi, StartDevServerArgs } from '@rock-js/config';
33
import {
44
colorLink,
55
findDevServerPort,
@@ -25,9 +25,39 @@ type BundleArgs = Parameters<NonNullable<typeof bundleCommand>['func']>[2] & {
2525
const startCommand = commands.find((command) => command.name === 'start');
2626
const bundleCommand = commands.find((command) => command.name === 'bundle');
2727

28+
export async function startDevServer({
29+
root,
30+
args,
31+
reactNativeVersion: _reactNativeVersion,
32+
reactNativePath,
33+
platforms,
34+
}: StartDevServerArgs, pluginConfig: PluginConfig = {}) {
35+
const { port, startDevServer } = await findDevServerPort(
36+
args.port ? Number(args.port) : 8081,
37+
root
38+
);
39+
40+
if (!startDevServer) {
41+
return;
42+
}
43+
44+
if (!startCommand) {
45+
throw new RockError('Re.Pack "start" command not found.');
46+
}
47+
48+
logger.info('Starting Re.Pack dev server...');
49+
50+
startCommand.func(
51+
[],
52+
// @ts-expect-error TODO fix getPlatforms type
53+
{ reactNativePath, root, platforms, ...pluginConfig },
54+
{ ...args, port },
55+
);
56+
}
57+
2858
export const pluginRepack =
2959
(pluginConfig: PluginConfig = {}) =>
30-
(api: PluginApi): PluginOutput => {
60+
(api: PluginApi): BundlerPluginOutput => {
3161
if (!startCommand) {
3262
throw new RockError('Re.Pack "start" command not found.');
3363
}
@@ -117,6 +147,7 @@ export const pluginRepack =
117147
return {
118148
name: '@rock-js/plugin-repack',
119149
description: 'Rock plugin for Re.Pack toolkit with Rspack.',
150+
start: startDevServer,
120151
};
121152
};
122153

0 commit comments

Comments
 (0)