Skip to content

Commit

Permalink
refactor(eas-cli): allow Expo Router server deployments without clien…
Browse files Browse the repository at this point in the history
…t directory (#2597)

* refactor(eas-cli): allow Expo Router server deployments without client directories

* docs: fix changelog entry
  • Loading branch information
byCedric authored Sep 24, 2024
1 parent c0c2755 commit f5df6e6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 13 additions & 9 deletions packages/eas-cli/src/commands/worker/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions packages/eas-cli/src/worker/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ export type AssetMap = Record<string, string>;

/** Creates an asset map of a given target path */
async function createAssetMapAsync(
assetPath: string,
assetPath?: string,
options?: AssetMapOptions
): Promise<AssetMap> {
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;
}
Expand Down

0 comments on commit f5df6e6

Please sign in to comment.