Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace globby with fast-glob #1373

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 10 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 17 additions & 21 deletions src/lib/getAllPackages.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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<PnpmWorkspaces | null> => {
const pnpmWorkspacesPath = path.join(path.dirname(pkgPath), 'pnpm-workspace.yaml')
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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]
}
Expand Down Expand Up @@ -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(
Expand Down
Loading