From 68a8d31cc7b30397ad84bc4e52894e6d6feb07f0 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Thu, 2 Jan 2020 04:37:30 +0200 Subject: [PATCH] perf: don't unnecessarily search for projects --- .../plugin-commands-installation/src/install.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/plugin-commands-installation/src/install.ts b/packages/plugin-commands-installation/src/install.ts index fa4d1e0dfb..3355f93d24 100644 --- a/packages/plugin-commands-installation/src/install.ts +++ b/packages/plugin-commands-installation/src/install.ts @@ -330,12 +330,13 @@ export async function handler ( input = input.filter(Boolean) const dir = opts.dir || process.cwd() + let allProjects = opts.allProjects + let workspacePackages = undefined - const workspacePackages = opts.workspaceDir - ? arrayOfWorkspacePackagesToMap( - await findWorkspacePackages(opts.workspaceDir, opts), - ) - : undefined + if (opts.workspaceDir) { + allProjects = allProjects ?? await findWorkspacePackages(opts.workspaceDir, opts) + workspacePackages = arrayOfWorkspacePackagesToMap(allProjects) + } const store = await createOrConnectStoreController(opts) const installOpts = { @@ -404,9 +405,7 @@ export async function handler ( } if (opts.linkWorkspacePackages && opts.workspaceDir) { - // TODO: reuse somehow the previous read of packages - // this is not optimal - const allProjects = await findWorkspacePackages(opts.workspaceDir, opts) + allProjects = allProjects ?? await findWorkspacePackages(opts.workspaceDir, opts) const selectedProjectsGraph = await filterPkgsBySelectorObjects(allProjects, [ { excludeSelf: true,