From f5df6e6e77b341dc986db26979f7a79ed08f1d06 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Tue, 24 Sep 2024 20:03:19 +0200 Subject: [PATCH] refactor(eas-cli): allow Expo Router server deployments without client directory (#2597) * refactor(eas-cli): allow Expo Router server deployments without client directories * docs: fix changelog entry --- CHANGELOG.md | 1 + .../eas-cli/src/commands/worker/deploy.ts | 22 +++++++++++-------- packages/eas-cli/src/worker/assets.ts | 8 ++++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89302d23df..4fcecee421 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This is the log of notable changes to EAS CLI and related packages. ### 🧹 Chores - Simplify the output of `eas deploy --json`. ([#2596](https://github.com/expo/eas-cli/pull/2596) by [@byCedric](https://github.com/byCedric)) +- Support deploying Expo Router server exports without client directory. ([#2597](https://github.com/expo/eas-cli/pull/2597) by [@byCedric](https://github.com/byCedric)) ## [12.5.0](https://github.com/expo/eas-cli/releases/tag/v12.5.0) - 2024-09-23 diff --git a/packages/eas-cli/src/commands/worker/deploy.ts b/packages/eas-cli/src/commands/worker/deploy.ts index 3d3f9b24b6..ca985c2e86 100644 --- a/packages/eas-cli/src/commands/worker/deploy.ts +++ b/packages/eas-cli/src/commands/worker/deploy.ts @@ -165,6 +165,10 @@ export default class WorkerDeploy extends EasCommand { // TODO(@kitten): Batch and upload multiple files in parallel const uploadParams: UploadParams[] = []; const assetPath = projectDist.type === 'server' ? projectDist.clientPath : projectDist.path; + if (!assetPath) { + return; + } + for await (const asset of WorkerAssets.listAssetMapFilesAsync(assetPath, assetMap)) { const uploadURL = uploads[asset.normalizedPath]; if (uploadURL) { @@ -359,36 +363,36 @@ async function resolveExportedProjectAsync( modifiedAt: Date | null; path: string; serverPath: string; - clientPath: string; + clientPath?: string; } > { const exportPath = path.join(projectDir, flags.exportDir); const serverPath = path.join(exportPath, 'server'); const clientPath = path.join(exportPath, 'client'); - const [hasServerPath, hasClientPath, exportStat] = await Promise.all([ - isDirectory(serverPath), - isDirectory(clientPath), + const [exportDirStat, expoRoutesStat, hasClientDir] = await Promise.all([ fs.promises.stat(exportPath).catch(() => null), + fs.promises.stat(path.join(serverPath, '_expo/routes.json')).catch(() => null), + isDirectory(clientPath), ]); - if (!exportStat?.isDirectory()) { + if (!exportDirStat?.isDirectory()) { throw new Error( `No "${flags.exportDir}/" folder found. Prepare your project for deployment with "npx expo export --platform web"` ); } - if (hasServerPath && hasClientPath) { + if (expoRoutesStat?.isFile()) { return { type: 'server', path: exportPath, - modifiedAt: exportStat.mtime, + modifiedAt: exportDirStat.mtime, serverPath, - clientPath, + clientPath: hasClientDir ? clientPath : undefined, }; } - return { type: 'static', path: exportPath, modifiedAt: exportStat.mtime }; + return { type: 'static', path: exportPath, modifiedAt: exportDirStat.mtime }; } function logExportedProjectInfo( diff --git a/packages/eas-cli/src/worker/assets.ts b/packages/eas-cli/src/worker/assets.ts index b769389d8d..a3f655d138 100644 --- a/packages/eas-cli/src/worker/assets.ts +++ b/packages/eas-cli/src/worker/assets.ts @@ -82,12 +82,14 @@ export type AssetMap = Record; /** Creates an asset map of a given target path */ async function createAssetMapAsync( - assetPath: string, + assetPath?: string, options?: AssetMapOptions ): Promise { const map: AssetMap = Object.create(null); - for await (const file of listFilesRecursively(assetPath)) { - map[file.normalizedPath] = await computeSha512HashAsync(file.path, options?.hashOptions); + if (assetPath) { + for await (const file of listFilesRecursively(assetPath)) { + map[file.normalizedPath] = await computeSha512HashAsync(file.path, options?.hashOptions); + } } return map; }