From 6bf7e28fc74df95e426ac975c5f1efb4943aff5d Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 10 Sep 2024 16:54:50 +0200 Subject: [PATCH] [draft] Reuse buildrsc --- packages/rsc-builder/buildRsc.ts | 78 +++++++++++++++++--------------- 1 file changed, 41 insertions(+), 37 deletions(-) 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());