From 1b8c1590f51e4418f99c9e5fbdbd56f8fd5aece9 Mon Sep 17 00:00:00 2001 From: Torathion Date: Fri, 8 Mar 2024 13:32:23 +0100 Subject: [PATCH] change: replace globby with fast-glob --- package.json | 2 +- src/lib/getAllPackages.ts | 38 +++++++++++++++++--------------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 24adc4f4..f80f7239 100644 --- a/package.json +++ b/package.json @@ -63,11 +63,11 @@ "chalk": "^5.3.0", "cli-table3": "^0.6.3", "commander": "^11.1.0", + "fast-glob": "^3.3.2", "fast-memoize": "^2.5.2", "find-up": "5.0.0", "fp-and-or": "^1.0.2", "get-stdin": "^8.0.0", - "globby": "^11.0.4", "hosted-git-info": "^5.1.0", "ini": "^4.1.1", "js-yaml": "^4.1.0", diff --git a/src/lib/getAllPackages.ts b/src/lib/getAllPackages.ts index fac81dff..2f9f2fa0 100644 --- a/src/lib/getAllPackages.ts +++ b/src/lib/getAllPackages.ts @@ -1,5 +1,5 @@ +import glob, { type Options as GlobOptions } from 'fast-glob' import fs from 'fs/promises' -import globby from 'globby' import yaml from 'js-yaml' import path from 'path' import untildify from 'untildify' @@ -12,6 +12,10 @@ import programError from './programError' type PnpmWorkspaces = string[] | { packages: string[] } +const globOptions: GlobOptions = { + ignore: ['**/node_modules/**'], +} + /** Reads, parses, and resolves workspaces from a pnpm-workspace file at the same path as the package file. */ const readPnpmWorkspaces = async (pkgPath: string): Promise => { const pnpmWorkspacesPath = path.join(path.dirname(pkgPath), 'pnpm-workspace.yaml') @@ -64,11 +68,7 @@ async function getWorkspacePackageInfos( ) // e.g. [packages/a/package.json, ...] - const allWorkspacePackageFilepaths: string[] = [ - ...globby.sync(workspacePackageGlob, { - ignore: ['**/node_modules/**'], - }), - ] + const allWorkspacePackageFilepaths: string[] = glob.sync(workspacePackageGlob, globOptions) // Get the package names from the package files. // If a package does not have a name, use the folder name. @@ -97,21 +97,19 @@ async function getWorkspacePackageInfos( // add workspace packages // --workspace - const selectedWorkspacePackageInfos: PackageInfo[] = allWorkspacePackageInfos.filter( - (packageInfo: PackageInfo) => + const selectedWorkspacePackageInfos: PackageInfo[] = allWorkspacePackageInfos.filter((packageInfo: PackageInfo) => + /* ignore coverage on optional-chaining */ + /* c8 ignore next */ + options.workspace?.some((workspace: string) => /* ignore coverage on optional-chaining */ /* c8 ignore next */ - options.workspace?.some( - (workspace: string) => - /* ignore coverage on optional-chaining */ - /* c8 ignore next */ - workspaces?.some( - (workspacePattern: string) => - packageInfo.name === workspace || - packageInfo.filepath === - path.join(cwd, path.dirname(workspacePattern), workspace, defaultPackageFilename).replace(/\\/g, '/'), - ), + workspaces?.some( + (workspacePattern: string) => + packageInfo.name === workspace || + packageInfo.filepath === + path.join(cwd, path.dirname(workspacePattern), workspace, defaultPackageFilename).replace(/\\/g, '/'), ), + ), ) return [selectedWorkspacePackageInfos, allWorkspacePackageNames] } @@ -140,9 +138,7 @@ async function getAllPackages(options: Options): Promise<[PackageInfo[], string[ // * NOT a workspace // * a workspace and have requested an upgrade of the workspace-root const globPattern = rootPackageFile.replace(/\\/g, '/') - const rootPackagePaths = globby.sync(globPattern, { - ignore: ['**/node_modules/**'], - }) + const rootPackagePaths = glob.sync(globPattern, globOptions) // realistically there should only be zero or one const rootPackages = [ ...(await Promise.all(