diff --git a/packages/rsc-builder/buildRsc.ts b/packages/rsc-builder/buildRsc.ts index 31a8e86ad8f42c..bc922ea7c20387 100644 --- a/packages/rsc-builder/buildRsc.ts +++ b/packages/rsc-builder/buildRsc.ts @@ -106,53 +106,57 @@ async function findAll( return result.flat(); } -async function run(argv: yargs.ArgumentsCamelCase) { - const grep = argv.grep == null ? null : new RegExp(argv.grep); +// eslint-disable-next-line import/prefer-default-export +export async function resolveProject(project: Project, grep: RegExp | null) { + const projectSrc = path.join(project.rootPath, 'src'); - await PROJECTS.reduce(async (resolvedPromise, project) => { - await resolvedPromise; + let directories = [projectSrc]; - const projectSrc = path.join(project.rootPath, 'src'); + if (Array.isArray(project?.additionalPaths)) { + directories = [ + ...directories, + ...project.additionalPaths.map((p) => path.join(project.rootPath, p)), + ]; + } - let directories = [projectSrc]; + const components = await findAll(directories, grep, findComponents); - if (Array.isArray(project?.additionalPaths)) { - directories = [ - ...directories, - ...project.additionalPaths.map((p) => path.join(project.rootPath, p)), - ]; + components.forEach(async (component) => { + try { + if (!project.ignorePaths?.some((p) => component.filename.includes(p))) { + processFile(component.filename); + } + } catch (error: any) { + error.message = `${path.relative(process.cwd(), component.filename)}: ${error.message}`; + throw error; } + }); - const components = await findAll(directories, grep, findComponents); + const hooks = await findAll(directories, grep, findHooks); - components.forEach(async (component) => { - try { - if (!project.ignorePaths?.some((p) => component.filename.includes(p))) { - processFile(component.filename); - } - } catch (error: any) { - error.message = `${path.relative(process.cwd(), component.filename)}: ${error.message}`; - throw error; - } - }); - - const hooks = await findAll(directories, grep, findHooks); + hooks.forEach(async (hook) => { + try { + processFile(hook.filename); + } catch (error: any) { + error.message = `${path.relative(process.cwd(), hook.filename)}: ${error.message}`; + throw error; + } + }); - hooks.forEach(async (hook) => { - try { - processFile(hook.filename); - } catch (error: any) { - error.message = `${path.relative(process.cwd(), hook.filename)}: ${error.message}`; - throw error; - } + if (Array.isArray(project?.additionalFiles)) { + project.additionalFiles.forEach(async (file) => { + const fullPath = path.join(project.rootPath, file); + processFile(fullPath); }); + } +} +async function run(argv: yargs.ArgumentsCamelCase) { + const grep = argv.grep == null ? null : new RegExp(argv.grep); - if (Array.isArray(project?.additionalFiles)) { - project.additionalFiles.forEach(async (file) => { - const fullPath = path.join(project.rootPath, file); - processFile(fullPath); - }); - } + await PROJECTS.reduce(async (resolvedPromise, project) => { + await resolvedPromise; + + await resolveProject(project, grep); return Promise.resolve(); }, Promise.resolve());