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

Handle eas build locally thorugh buildCommand in launch.json #833

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix lint
maciekstosio committed Jan 13, 2025
commit beb4e2bcc0ff76bf6a175947adec084a6e4015ca
7 changes: 6 additions & 1 deletion packages/vscode-extension/src/builders/buildAndroid.ts
Original file line number Diff line number Diff line change
@@ -93,7 +93,12 @@ export async function buildAndroid(
getTelemetryReporter().sendTelemetryEvent("build:custom-build-requested", {
platform: DevicePlatform.Android,
});
const apkPath = await runExternalBuild(cancelToken, customBuild.android.buildCommand, env, DevicePlatform.Android);
const apkPath = await runExternalBuild(
cancelToken,
customBuild.android.buildCommand,
env,
DevicePlatform.Android
);
if (!apkPath) {
throw new Error("Failed to build Android app using custom script.");
}
7 changes: 6 additions & 1 deletion packages/vscode-extension/src/builders/buildIOS.ts
Original file line number Diff line number Diff line change
@@ -93,7 +93,12 @@ export async function buildIos(
});
// We don't autoinstall Pods here to make custom build scripts more flexible

const appPath = await runExternalBuild(cancelToken, customBuild.ios.buildCommand, env, DevicePlatform.IOS);
const appPath = await runExternalBuild(
cancelToken,
customBuild.ios.buildCommand,
env,
DevicePlatform.IOS
);
if (!appPath) {
throw new Error("Failed to build iOS app using custom script.");
}
19 changes: 10 additions & 9 deletions packages/vscode-extension/src/builders/customBuild.ts
Original file line number Diff line number Diff line change
@@ -8,14 +8,19 @@
import { getAppRootFolder } from "../utilities/extensionContext";
import { extractTarApp, isApkFile, isAppFile } from "./utils";
import { DevicePlatform } from "../common/DeviceManager";
import { Platform } from "../utilities/platform";

Check failure on line 11 in packages/vscode-extension/src/builders/customBuild.ts

GitHub Actions / check

'Platform' is defined but never used. Allowed unused vars must match /^_/u

type Env = Record<string, string> | undefined;

// Extracts all paths from the last line, both Unix and Windows format
const BUILD_PATH_REGEX = /(\/.*?\.\S*)|([a-zA-Z]:\\.*?\.\S*)/g;

export async function runExternalBuild(cancelToken: CancelToken, buildCommand: string, env: Env, platform: DevicePlatform) {
export async function runExternalBuild(
cancelToken: CancelToken,
buildCommand: string,
env: Env,
platform: DevicePlatform
) {
const output = await runExternalScript(buildCommand, env, cancelToken);

if (!output) {
@@ -41,25 +46,21 @@
if (shouldExtractArchive) {
const tmpDirectory = await mkdtemp(path.join(os.tmpdir(), "rn-ide-custom-build-"));
const extractedFile = await extractTarApp(binaryPath, tmpDirectory, cancelToken, platform);

Logger.info(`External script: ${buildCommand} output app path: ${binaryPath}`);
return extractedFile;
}

if (platform === DevicePlatform.Android && !isApkFile(binaryPath)) {
Logger.error(
`External script: ${buildCommand} failed to output .apk file, got: ${binaryPath}`
);
Logger.error(`External script: ${buildCommand} failed to output .apk file, got: ${binaryPath}`);
return undefined;
}

if (platform === DevicePlatform.IOS && !isAppFile(binaryPath)) {
Logger.error(
`External script: ${buildCommand} failed to output .app file, got: ${binaryPath}`
);
Logger.error(`External script: ${buildCommand} failed to output .app file, got: ${binaryPath}`);
return undefined;
}

Logger.info(`External script: ${buildCommand} output app path: ${binaryPath}`);
return binaryPath;
}
10 changes: 8 additions & 2 deletions packages/vscode-extension/src/builders/utils.ts
Original file line number Diff line number Diff line change
@@ -29,9 +29,15 @@ export async function extractTarApp(
}

// assuming that the archive contains only one app file
const appName = (await readdir(pathToExtract)).find(platform === DevicePlatform.Android ? isApkFile : isAppFile);
const appName = (await readdir(pathToExtract)).find(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of having this here both here and in runExternalBuild maybe we should just make this metod return a single extracted file and then only make the file extension checks in runExternalBuild

platform === DevicePlatform.Android ? isApkFile : isAppFile
);
if (!appName) {
Logger.error(`Failed to find the ${platform === DevicePlatform.Android ? '.apk' : '.app'} file in extracted archive '${binaryPath}'.`);
Logger.error(
`Failed to find the ${
platform === DevicePlatform.Android ? ".apk" : ".app"
} file in extracted archive '${binaryPath}'.`
);
return undefined;
}