Skip to content

Commit

Permalink
change: replace globby with fast-glob
Browse files Browse the repository at this point in the history
  • Loading branch information
Torathion committed Mar 8, 2024
1 parent 48bd306 commit 1b8c159
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
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

0 comments on commit 1b8c159

Please sign in to comment.