@@ -160,11 +160,7 @@ export async function runAppBuilder(
160160 if ( await hasImportedAppWorkspace ( sandbox , workspace . dir ) ) {
161161 return restoreImportedWorkspace ( workspaceOptions ) ;
162162 }
163- const shouldBootstrap = ! ( await hasExistingAppBuilderWorkspace (
164- sandbox ,
165- workspace . dir ,
166- workspace . mobile ,
167- ) ) ;
163+ const shouldBootstrap = ! ( await hasExistingAppBuilderWorkspace ( sandbox , workspace . dir ) ) ;
168164 if ( shouldBootstrap && input . importRepoUrl ) {
169165 return importRepoWorkspace ( { ...workspaceOptions , repoUrl : input . importRepoUrl } ) ;
170166 }
@@ -200,13 +196,15 @@ async function prepareTemplateWorkspace(
200196 setRunStage ( mobile ? "Preparing the Expo workspace." : "Preparing the Next.js workspace." ) ;
201197 if ( ! shouldBootstrap ) {
202198 setRunStage ( "Restoring the app workspace." ) ;
203- await installAppBuilderDependencies ( sandbox , logger , workspace . dir , mobile ) ;
199+ if ( ! ( await hasInstalledAppBuilderDependencies ( sandbox , workspace . dir ) ) ) {
200+ await installAppBuilderDependencies ( sandbox , logger , workspace . dir , mobile ) ;
201+ }
204202 if ( mobile ) {
205203 await ensureExpoWebSupport ( sandbox , workspace . dir ) ;
206204 }
207205 return ;
208206 }
209- await resetAppBuilderDirectory ( sandbox , workspace . dir ) ;
207+ await resetTemplateAppBuilderDirectory ( sandbox , workspace . dir ) ;
210208 throwIfRunCanceled ( options . abortSignal ) ;
211209 if ( mobile ) {
212210 await scaffoldExpoApp ( sandbox , logger , workspace . dir ) ;
@@ -583,12 +581,28 @@ async function startAppBuilderDevServer(
583581async function hasExistingAppBuilderWorkspace (
584582 sandbox : ProjectSandboxStub ,
585583 dir : string ,
586- mobile : boolean ,
587584) : Promise < boolean > {
588- const appDir = mobile ? "app" : "src/app" ;
585+ const appDirs = [ "src/app" , "app" ] ;
586+ const result = await executeShellTerminal (
587+ {
588+ command :
589+ `test -f ${ dir } /package.json && ` +
590+ `(test -d ${ dir } /${ appDirs [ 0 ] } || test -d ${ dir } /${ appDirs [ 1 ] } )` ,
591+ cwd : "/workspace" ,
592+ timeoutMs : 10_000 ,
593+ } ,
594+ { sandbox } ,
595+ ) ;
596+ return result . success ;
597+ }
598+
599+ async function hasInstalledAppBuilderDependencies (
600+ sandbox : ProjectSandboxStub ,
601+ dir : string ,
602+ ) : Promise < boolean > {
589603 const result = await executeShellTerminal (
590604 {
591- command : `test -f ${ dir } /package.json && test - d ${ dir } /${ appDir } ` ,
605+ command : `test -d ${ dir } /node_modules/.pnpm ` ,
592606 cwd : "/workspace" ,
593607 timeoutMs : 10_000 ,
594608 } ,
@@ -604,6 +618,36 @@ async function resetAppBuilderDirectory(sandbox: ProjectSandboxStub, dir: string
604618 ) ;
605619}
606620
621+ async function resetTemplateAppBuilderDirectory (
622+ sandbox : ProjectSandboxStub ,
623+ dir : string ,
624+ ) : Promise < void > {
625+ await executeShellExec (
626+ {
627+ command : [
628+ "find" ,
629+ dir ,
630+ "-mindepth" ,
631+ "1" ,
632+ "-maxdepth" ,
633+ "1" ,
634+ "!" ,
635+ "-name" ,
636+ "uploads" ,
637+ "-exec" ,
638+ "rm" ,
639+ "-rf" ,
640+ "--" ,
641+ "{}" ,
642+ "+" ,
643+ ] ,
644+ cwd : "/workspace" ,
645+ timeoutMs : 120_000 ,
646+ } ,
647+ { sandbox } ,
648+ ) ;
649+ }
650+
607651async function clearBuildCache (
608652 sandbox : ProjectSandboxStub ,
609653 dir : string ,
0 commit comments