mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-30 04:52:04 -04:00
* refactor: merge @pnpm/fs.find-packages into @pnpm/workspace.projects-reader The find-packages package had only one production consumer (projects-reader). Inlining it removes a separate published package with minimal value as a standalone utility. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: sort devDependencies and add tsconfig reference for meta-updater Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: remove circular tsconfig reference Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: exclude circular tsconfig reference in meta-updater Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * refactor: move getConfig from cli/utils to pnpm CLI package getConfig and installConfigDepsAndLoadHooks were the only functions in cli/utils that pulled in heavy deps (env-installer, store.connection-manager, hooks.pnpmfile, default-reporter). Moving them to the pnpm CLI package (their only consumer) dramatically reduces the dependency weight of cli/utils, breaking the circular tsconfig reference chain that previously required fs.find-packages to be a separate package. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: sort imports Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
89 lines
3.3 KiB
TypeScript
89 lines
3.3 KiB
TypeScript
/// <reference path="../../../__typings__/index.d.ts"/>
|
|
import path from 'node:path'
|
|
|
|
import { findPackages } from '@pnpm/workspace.projects-reader'
|
|
|
|
function compare (a: string | undefined, b: string | undefined) {
|
|
if (a == null) return 1
|
|
if (b == null) return -1
|
|
return a.localeCompare(b)
|
|
}
|
|
|
|
const fixtures = path.join(import.meta.dirname, 'findPackages-fixtures')
|
|
|
|
test('finds package', async () => {
|
|
const root = path.join(fixtures, 'one-pkg')
|
|
const pkgs = await findPackages(root)
|
|
|
|
expect(pkgs).toHaveLength(1)
|
|
expect(pkgs[0].rootDir).toBeDefined()
|
|
expect(pkgs[0].manifest).toBeDefined()
|
|
})
|
|
|
|
test('finds packages by patterns', async () => {
|
|
const root = path.join(fixtures, 'many-pkgs')
|
|
const pkgs = await findPackages(root, { patterns: ['components/**'] })
|
|
|
|
expect(pkgs).toHaveLength(2)
|
|
expect(pkgs[0].rootDir).toBeDefined()
|
|
expect(pkgs[0].manifest).toBeDefined()
|
|
expect(pkgs[1].rootDir).toBeDefined()
|
|
expect(pkgs[1].manifest).toBeDefined()
|
|
expect([pkgs[0].manifest.name, pkgs[1].manifest.name].sort(compare)).toStrictEqual(['component-1', 'component-2'])
|
|
})
|
|
|
|
test('finds packages by * pattern', async () => {
|
|
const root = path.join(fixtures, 'many-pkgs-2')
|
|
const pkgs = await findPackages(root, { patterns: ['.', 'components/*'] })
|
|
|
|
expect(pkgs).toHaveLength(3)
|
|
expect([pkgs[0].manifest.name, pkgs[1].manifest.name, pkgs[2].manifest.name].sort(compare)).toStrictEqual(['component-1', 'component-2', 'many-pkgs-2'])
|
|
})
|
|
|
|
test('finds packages by default pattern', async () => {
|
|
const root = path.join(fixtures, 'many-pkgs-2')
|
|
const pkgs = await findPackages(root)
|
|
|
|
expect(pkgs).toHaveLength(4)
|
|
expect(pkgs.map(({ manifest }) => manifest.name).sort(compare)).toStrictEqual(['component-1', 'component-2', 'foo', 'many-pkgs-2'])
|
|
})
|
|
|
|
test('ignore packages by patterns', async () => {
|
|
const root = path.join(fixtures, 'many-pkgs')
|
|
const pkgs = await findPackages(root, { patterns: ['**', '!libs/**'] })
|
|
|
|
expect(pkgs).toHaveLength(2)
|
|
expect(pkgs[0].rootDir).toBeDefined()
|
|
expect(pkgs[0].manifest).toBeDefined()
|
|
expect(pkgs[1].rootDir).toBeDefined()
|
|
expect(pkgs[1].manifest).toBeDefined()
|
|
expect([pkgs[0].manifest.name, pkgs[1].manifest.name].sort(compare)).toStrictEqual(['component-1', 'component-2'])
|
|
})
|
|
|
|
test('ignore packages by patterns with starts with !/', async () => {
|
|
const root = path.join(fixtures, 'many-pkgs')
|
|
const pkgs = await findPackages(root, { patterns: ['**', '!/libs/**'] })
|
|
|
|
expect(pkgs).toHaveLength(3)
|
|
expect(pkgs[0].rootDir).toBeDefined()
|
|
expect(pkgs[0].manifest).toBeDefined()
|
|
expect(pkgs[1].rootDir).toBeDefined()
|
|
expect(pkgs[1].manifest).toBeDefined()
|
|
expect(pkgs[2].rootDir).toBeDefined()
|
|
expect(pkgs[2].manifest).toBeDefined()
|
|
expect([pkgs[0].manifest.name, pkgs[1].manifest.name, pkgs[2].manifest.name].sort(compare)).toStrictEqual(['component-1', 'component-2', 'foo'])
|
|
})
|
|
|
|
test('json and yaml manifests are also found', async () => {
|
|
const root = path.join(fixtures, 'many-pkgs-with-different-manifest-types')
|
|
const pkgs = await findPackages(root)
|
|
|
|
expect(pkgs).toHaveLength(3)
|
|
expect(pkgs[0].rootDir).toBeDefined()
|
|
expect(pkgs[0].manifest.name).toBe('component-1')
|
|
expect(pkgs[1].rootDir).toBeDefined()
|
|
expect(pkgs[1].manifest.name).toBe('component-2')
|
|
expect(pkgs[2].rootDir).toBeDefined()
|
|
expect(pkgs[2].manifest.name).toBe('foo')
|
|
})
|