perf: switch to tinyglobby (#9169)

This commit is contained in:
Ben McCann
2025-03-01 18:06:12 -08:00
committed by GitHub
parent 8b3cfe24fe
commit b8b0c687f2
14 changed files with 108 additions and 58 deletions

View File

@@ -0,0 +1,10 @@
---
"@pnpm/plugin-commands-publishing": patch
"@pnpm/plugin-commands-patching": patch
"@pnpm/package-bins": patch
"@pnpm/fs.find-packages": patch
"@pnpm/cache.api": patch
"pnpm": patch
---
`fast-glob` replace with `tinyglobby` to reduce the size of the pnpm CLI dependencies [#9169](https://github.com/pnpm/pnpm/pull/9169).

View File

@@ -35,7 +35,7 @@
"@pnpm/npm-resolver": "workspace:*",
"@pnpm/store.cafs": "workspace:*",
"encode-registry": "catalog:",
"fast-glob": "catalog:"
"tinyglobby": "catalog:"
},
"peerDependencies": {
"@pnpm/logger": ">=5.1.0 <1001.0.0"

View File

@@ -1,6 +1,6 @@
import fs from 'fs'
import getRegistryName from 'encode-registry'
import fastGlob from 'fast-glob'
import { glob } from 'tinyglobby'
export async function cacheListRegistries (opts: { cacheDir: string, registry?: string, registries?: boolean }): Promise<string> {
return fs.readdirSync(opts.cacheDir).sort().join('\n')
@@ -14,8 +14,9 @@ export async function cacheList (opts: { cacheDir: string, registry?: string, re
export async function findMetadataFiles (opts: { cacheDir: string, registry?: string }, filter: string[]): Promise<string[]> {
const prefix = opts.registry ? `${getRegistryName(opts.registry)}` : '*'
const patterns = filter.length ? filter.map((filter) => `${prefix}/${filter}.json`) : [`${prefix}/**`]
const metaFiles = await fastGlob(patterns, {
const metaFiles = await glob(patterns, {
cwd: opts.cacheDir,
expandDirectories: false,
})
return metaFiles
}

View File

@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'
import fastGlob from 'fast-glob'
import { glob } from 'tinyglobby'
import { getIndexFilePathInCafs } from '@pnpm/store.cafs'
import { type PackageMeta } from '@pnpm/npm-resolver'
import getRegistryName from 'encode-registry'
@@ -14,8 +14,9 @@ interface CachedVersions {
export async function cacheView (opts: { cacheDir: string, storeDir: string, registry?: string }, packageName: string): Promise<string> {
const prefix = opts.registry ? `${getRegistryName(opts.registry)}` : '*'
const metaFilePaths = (await fastGlob(`${prefix}/${packageName}.json`, {
const metaFilePaths = (await glob(`${prefix}/${packageName}.json`, {
cwd: opts.cacheDir,
expandDirectories: false,
})).sort()
const metaFilesByPath: Record<string, CachedVersions> = {}
for (const filePath of metaFilePaths) {

View File

@@ -35,8 +35,8 @@
"@pnpm/read-project-manifest": "workspace:*",
"@pnpm/types": "workspace:*",
"@pnpm/util.lex-comparator": "catalog:",
"fast-glob": "catalog:",
"p-filter": "catalog:"
"p-filter": "catalog:",
"tinyglobby": "catalog:"
},
"devDependencies": {
"@pnpm/fs.find-packages": "workspace:*"

View File

@@ -4,7 +4,7 @@ import util from 'util'
import { readExactProjectManifest } from '@pnpm/read-project-manifest'
import { type Project, type ProjectRootDir, type ProjectRootDirRealPath } from '@pnpm/types'
import { lexCompare } from '@pnpm/util.lex-comparator'
import fastGlob from 'fast-glob'
import { glob } from 'tinyglobby'
import pFilter from 'p-filter'
const DEFAULT_IGNORE = [
@@ -22,16 +22,17 @@ export interface Options {
export async function findPackages (root: string, opts?: Options): Promise<Project[]> {
opts = opts ?? {}
const globOpts = { ...opts, cwd: root }
const globOpts = { ...opts, cwd: root, expandDirectories: false }
globOpts.ignore = opts.ignore ?? DEFAULT_IGNORE
const patterns = normalizePatterns(opts.patterns ?? ['.', '**'])
const paths: string[] = await fastGlob(patterns, globOpts)
delete globOpts.patterns
const paths: string[] = await glob(patterns, globOpts)
if (opts.includeRoot) {
// Always include the workspace root (https://github.com/pnpm/pnpm/issues/1986)
Array.prototype.push.apply(
paths,
await fastGlob(normalizePatterns(['.']), globOpts)
await glob(normalizePatterns(['.']), globOpts)
)
}

View File

@@ -52,7 +52,6 @@
"chalk": "catalog:",
"enquirer": "catalog:",
"escape-string-regexp": "catalog:",
"fast-glob": "catalog:",
"is-windows": "catalog:",
"make-empty-dir": "catalog:",
"normalize-path": "catalog:",
@@ -62,7 +61,8 @@
"safe-execa": "catalog:",
"semver": "catalog:",
"tempy": "catalog:",
"terminal-link": "catalog:"
"terminal-link": "catalog:",
"tinyglobby": "catalog:"
},
"peerDependencies": {
"@pnpm/logger": ">=5.1.0 <1001.0.0"

View File

@@ -8,7 +8,7 @@ import { install } from '@pnpm/plugin-commands-installation'
import { readPackageJsonFromDir } from '@pnpm/read-package-json'
import { tryReadProjectManifest } from '@pnpm/read-project-manifest'
import { type ProjectRootDir } from '@pnpm/types'
import glob from 'fast-glob'
import { glob } from 'tinyglobby'
import normalizePath from 'normalize-path'
import pick from 'ramda/src/pick'
import equals from 'ramda/src/equals'
@@ -206,6 +206,7 @@ async function preparePkgFilesForDiff (src: string): Promise<string> {
async function areAllFilesInPkg (files: string[], basePath: string): Promise<boolean> {
const allFiles = await glob('**', {
cwd: basePath,
expandDirectories: false,
})
return equals(allFiles.sort(), files.sort())
}

View File

@@ -33,8 +33,8 @@
},
"dependencies": {
"@pnpm/types": "workspace:*",
"fast-glob": "catalog:",
"is-subdir": "catalog:"
"is-subdir": "catalog:",
"tinyglobby": "catalog:"
},
"devDependencies": {
"@pnpm/package-bins": "workspace:*",

View File

@@ -1,6 +1,6 @@
import path from 'path'
import { type DependencyManifest, type PackageBin } from '@pnpm/types'
import fastGlob from 'fast-glob'
import { glob } from 'tinyglobby'
import isSubdir from 'is-subdir'
export interface Command {
@@ -25,10 +25,11 @@ export async function getBinsFromPackageManifest (manifest: DependencyManifest,
async function findFiles (dir: string): Promise<string[]> {
try {
return await fastGlob('**', {
return await glob('**', {
cwd: dir,
onlyFiles: true,
followSymbolicLinks: false,
expandDirectories: false,
})
} catch (err: any) { // eslint-disable-line
if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {

107
pnpm-lock.yaml generated
View File

@@ -603,6 +603,9 @@ catalogs:
terminal-link:
specifier: ^2.1.1
version: 2.1.1
tinyglobby:
specifier: ^0.2.12
version: 0.2.12
touch:
specifier: 3.1.0
version: 3.1.0
@@ -1093,9 +1096,9 @@ importers:
encode-registry:
specifier: 'catalog:'
version: 3.0.1
fast-glob:
tinyglobby:
specifier: 'catalog:'
version: 3.3.2
version: 0.2.12
devDependencies:
'@pnpm/cache.api':
specifier: workspace:*
@@ -2859,12 +2862,12 @@ importers:
'@pnpm/util.lex-comparator':
specifier: 'catalog:'
version: 3.0.0
fast-glob:
specifier: 'catalog:'
version: 3.3.2
p-filter:
specifier: 'catalog:'
version: 2.1.0
tinyglobby:
specifier: 'catalog:'
version: 0.2.12
devDependencies:
'@pnpm/fs.find-packages':
specifier: workspace:*
@@ -4187,9 +4190,6 @@ importers:
escape-string-regexp:
specifier: 'catalog:'
version: 4.0.0
fast-glob:
specifier: 'catalog:'
version: 3.3.2
is-windows:
specifier: 'catalog:'
version: 1.0.2
@@ -4220,6 +4220,9 @@ importers:
terminal-link:
specifier: 'catalog:'
version: 2.1.1
tinyglobby:
specifier: 'catalog:'
version: 0.2.12
devDependencies:
'@pnpm/logger':
specifier: workspace:*
@@ -5064,12 +5067,12 @@ importers:
'@pnpm/types':
specifier: workspace:*
version: link:../../packages/types
fast-glob:
specifier: 'catalog:'
version: 3.3.2
is-subdir:
specifier: 'catalog:'
version: 1.2.0
tinyglobby:
specifier: 'catalog:'
version: 0.2.12
devDependencies:
'@pnpm/package-bins':
specifier: workspace:*
@@ -6377,9 +6380,6 @@ importers:
execa:
specifier: 'catalog:'
version: safe-execa@0.1.2
fast-glob:
specifier: 'catalog:'
version: 3.3.2
p-filter:
specifier: 'catalog:'
version: 2.1.0
@@ -6398,6 +6398,9 @@ importers:
tempy:
specifier: 'catalog:'
version: 1.0.1
tinyglobby:
specifier: 'catalog:'
version: 0.2.12
validate-npm-package-name:
specifier: 'catalog:'
version: 5.0.0
@@ -14854,7 +14857,7 @@ snapshots:
'@babel/generator@7.23.0':
dependencies:
'@babel/types': 7.23.0
'@babel/types': 7.26.9
'@jridgewell/gen-mapping': 0.3.8
'@jridgewell/trace-mapping': 0.3.25
jsesc: 2.5.2
@@ -15753,7 +15756,7 @@ snapshots:
'@jest/console@29.7.0':
dependencies:
'@jest/types': 29.6.3
'@types/node': 18.19.34
'@types/node': 22.13.8
chalk: 4.1.2
jest-message-util: 29.7.0
jest-util: 29.7.0
@@ -15766,14 +15769,14 @@ snapshots:
'@jest/test-result': 29.7.0
'@jest/transform': 29.7.0(@babel/types@7.26.9)
'@jest/types': 29.6.3
'@types/node': 18.19.34
'@types/node': 22.13.8
ansi-escapes: 4.3.2
chalk: 4.1.2
ci-info: 3.9.0
exit: 0.1.2
graceful-fs: 4.2.11(patch_hash=68ebc232025360cb3dcd3081f4067f4e9fc022ab6b6f71a3230e86c7a5b337d1)
jest-changed-files: 29.7.0
jest-config: 29.7.0(@babel/types@7.26.9)(@types/node@18.19.34)(ts-node@10.9.2(@types/node@18.19.34)(typescript@5.5.4))
jest-config: 29.7.0(@babel/types@7.26.9)(@types/node@22.13.8)(ts-node@10.9.2(@types/node@18.19.34)(typescript@5.5.4))
jest-haste-map: 29.7.0
jest-message-util: 29.7.0
jest-regex-util: 29.6.3
@@ -15799,7 +15802,7 @@ snapshots:
dependencies:
'@jest/fake-timers': 29.7.0
'@jest/types': 29.6.3
'@types/node': 18.19.34
'@types/node': 22.13.8
jest-mock: 29.7.0
'@jest/expect-utils@29.7.0':
@@ -15817,7 +15820,7 @@ snapshots:
dependencies:
'@jest/types': 29.6.3
'@sinonjs/fake-timers': 10.3.0
'@types/node': 18.19.34
'@types/node': 22.13.8
jest-message-util: 29.7.0
jest-mock: 29.7.0
jest-util: 29.7.0
@@ -15839,7 +15842,7 @@ snapshots:
'@jest/transform': 29.7.0(@babel/types@7.26.9)
'@jest/types': 29.6.3
'@jridgewell/trace-mapping': 0.3.25
'@types/node': 18.19.34
'@types/node': 22.13.8
chalk: 4.1.2
collect-v8-coverage: 1.0.2
exit: 0.1.2
@@ -15911,7 +15914,7 @@ snapshots:
'@jest/schemas': 29.6.3
'@types/istanbul-lib-coverage': 2.0.6
'@types/istanbul-reports': 3.0.4
'@types/node': 18.19.34
'@types/node': 22.13.8
'@types/yargs': 17.0.33
chalk: 4.1.2
@@ -16131,7 +16134,7 @@ snapshots:
'@pnpm/read-project-manifest': 6.0.6
'@pnpm/types': 12.0.0
'@pnpm/util.lex-comparator': 3.0.0
fast-glob: 3.3.2
fast-glob: 3.3.3
p-filter: 2.1.0
'@pnpm/fs.packlist@2.0.0':
@@ -16604,7 +16607,7 @@ snapshots:
'@types/isexe@2.0.2':
dependencies:
'@types/node': 18.19.34
'@types/node': 22.13.8
'@types/istanbul-lib-coverage@2.0.6': {}
@@ -16725,7 +16728,7 @@ snapshots:
'@types/touch@3.1.5':
dependencies:
'@types/node': 18.19.34
'@types/node': 22.13.8
'@types/treeify@1.0.3': {}
@@ -16948,7 +16951,7 @@ snapshots:
'@yarnpkg/core@4.0.5(typanion@3.14.0)':
dependencies:
'@arcanis/slice-ansi': 1.1.1
'@types/semver': 7.5.3
'@types/semver': 7.5.8
'@types/treeify': 1.0.3
'@yarnpkg/fslib': 3.1.1
'@yarnpkg/libzip': 3.1.0(@yarnpkg/fslib@3.1.1)
@@ -19685,7 +19688,7 @@ snapshots:
'@jest/expect': 29.7.0
'@jest/test-result': 29.7.0
'@jest/types': 29.6.3
'@types/node': 18.19.34
'@types/node': 22.13.8
chalk: 4.1.2
co: 4.6.0
dedent: 1.5.3
@@ -19758,6 +19761,38 @@ snapshots:
- babel-plugin-macros
- supports-color
jest-config@29.7.0(@babel/types@7.26.9)(@types/node@22.13.8)(ts-node@10.9.2(@types/node@18.19.34)(typescript@5.5.4)):
dependencies:
'@babel/core': 7.26.9
'@jest/test-sequencer': 29.7.0
'@jest/types': 29.6.3
babel-jest: 29.7.0(@babel/core@7.26.9)(@babel/types@7.26.9)
chalk: 4.1.2
ci-info: 3.9.0
deepmerge: 4.3.1
glob: 7.2.3
graceful-fs: 4.2.11(patch_hash=68ebc232025360cb3dcd3081f4067f4e9fc022ab6b6f71a3230e86c7a5b337d1)
jest-circus: 29.7.0(@babel/types@7.26.9)
jest-environment-node: 29.7.0
jest-get-type: 29.6.3
jest-regex-util: 29.6.3
jest-resolve: 29.7.0
jest-runner: 29.7.0(@babel/types@7.26.9)
jest-util: 29.7.0
jest-validate: 29.7.0
micromatch: 4.0.8
parse-json: 5.2.0
pretty-format: 29.7.0
slash: 3.0.0
strip-json-comments: 3.1.1
optionalDependencies:
'@types/node': 22.13.8
ts-node: 10.9.2(@types/node@18.19.34)(typescript@5.5.4)
transitivePeerDependencies:
- '@babel/types'
- babel-plugin-macros
- supports-color
jest-diff@29.7.0:
dependencies:
chalk: 4.1.2
@@ -19782,7 +19817,7 @@ snapshots:
'@jest/environment': 29.7.0
'@jest/fake-timers': 29.7.0
'@jest/types': 29.6.3
'@types/node': 18.19.34
'@types/node': 22.13.8
jest-mock: 29.7.0
jest-util: 29.7.0
@@ -19792,7 +19827,7 @@ snapshots:
dependencies:
'@jest/types': 29.6.3
'@types/graceful-fs': 4.1.9
'@types/node': 18.19.34
'@types/node': 22.13.8
anymatch: 3.1.3
fb-watchman: 2.0.2
graceful-fs: 4.2.11(patch_hash=68ebc232025360cb3dcd3081f4067f4e9fc022ab6b6f71a3230e86c7a5b337d1)
@@ -19831,7 +19866,7 @@ snapshots:
jest-mock@29.7.0:
dependencies:
'@jest/types': 29.6.3
'@types/node': 18.19.34
'@types/node': 22.13.8
jest-util: 29.7.0
jest-pnp-resolver@1.2.3(jest-resolve@29.7.0):
@@ -19866,7 +19901,7 @@ snapshots:
'@jest/test-result': 29.7.0
'@jest/transform': 29.7.0(@babel/types@7.26.9)
'@jest/types': 29.6.3
'@types/node': 18.19.34
'@types/node': 22.13.8
chalk: 4.1.2
emittery: 0.13.1
graceful-fs: 4.2.11(patch_hash=68ebc232025360cb3dcd3081f4067f4e9fc022ab6b6f71a3230e86c7a5b337d1)
@@ -19895,7 +19930,7 @@ snapshots:
'@jest/test-result': 29.7.0
'@jest/transform': 29.7.0(@babel/types@7.26.9)
'@jest/types': 29.6.3
'@types/node': 18.19.34
'@types/node': 22.13.8
chalk: 4.1.2
cjs-module-lexer: 1.4.3
collect-v8-coverage: 1.0.2
@@ -19942,7 +19977,7 @@ snapshots:
jest-util@29.7.0:
dependencies:
'@jest/types': 29.6.3
'@types/node': 18.19.34
'@types/node': 22.13.8
chalk: 4.1.2
ci-info: 3.9.0
graceful-fs: 4.2.11(patch_hash=68ebc232025360cb3dcd3081f4067f4e9fc022ab6b6f71a3230e86c7a5b337d1)
@@ -19961,7 +19996,7 @@ snapshots:
dependencies:
'@jest/test-result': 29.7.0
'@jest/types': 29.6.3
'@types/node': 18.19.34
'@types/node': 22.13.8
ansi-escapes: 4.3.2
chalk: 4.1.2
emittery: 0.13.1
@@ -19970,7 +20005,7 @@ snapshots:
jest-worker@29.7.0:
dependencies:
'@types/node': 18.19.34
'@types/node': 22.13.8
jest-util: 29.7.0
merge-stream: 2.0.0
supports-color: 8.1.1
@@ -22546,7 +22581,7 @@ snapshots:
wide-align@1.1.5:
dependencies:
string-width: 1.0.2
string-width: 4.2.3
optional: true
widest-line@3.1.0:

View File

@@ -242,6 +242,7 @@ catalog:
tar: ^6.2.1
tempy: ^1.0.1
terminal-link: ^2.1.1
tinyglobby: ^0.2.12
touch: 3.1.0
tree-kill: ^1.2.2
uuid: ^9.0.1

View File

@@ -55,13 +55,13 @@
"chalk": "catalog:",
"enquirer": "catalog:",
"execa": "catalog:",
"fast-glob": "catalog:",
"p-filter": "catalog:",
"ramda": "catalog:",
"realpath-missing": "catalog:",
"render-help": "catalog:",
"tar-stream": "catalog:",
"tempy": "catalog:",
"tinyglobby": "catalog:",
"validate-npm-package-name": "catalog:",
"write-json-file": "catalog:"
},

View File

@@ -9,7 +9,7 @@ import { createExportableManifest } from '@pnpm/exportable-manifest'
import { packlist } from '@pnpm/fs.packlist'
import { getBinsFromPackageManifest } from '@pnpm/package-bins'
import { type ProjectManifest, type DependencyManifest } from '@pnpm/types'
import fg from 'fast-glob'
import { glob } from 'tinyglobby'
import pick from 'ramda/src/pick'
import realpathMissing from 'realpath-missing'
import renderHelp from 'render-help'
@@ -19,7 +19,6 @@ import chalk from 'chalk'
import validateNpmPackageName from 'validate-npm-package-name'
const LICENSE_GLOB = 'LICEN{S,C}E{,.*}' // cspell:disable-line
const findLicenses = fg.bind(fg, [LICENSE_GLOB]) as (opts: { cwd: string }) => Promise<string[]>
export function rcOptionsTypes (): Record<string, unknown> {
return {
@@ -162,7 +161,7 @@ export async function api (opts: PackOptions): Promise<PackResult> {
const filesMap = Object.fromEntries(files.map((file) => [`package/${file}`, path.join(dir, file)]))
// cspell:disable-next-line
if (opts.workspaceDir != null && dir !== opts.workspaceDir && !files.some((file) => /LICEN[CS]E(\..+)?/i.test(file))) {
const licenses = await findLicenses({ cwd: opts.workspaceDir })
const licenses = await glob([LICENSE_GLOB], { cwd: opts.workspaceDir, expandDirectories: false })
for (const license of licenses) {
filesMap[`package/${license}`] = path.join(opts.workspaceDir, license)
}