mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-10 18:18:56 -04:00
5
.changeset/popular-carrots-rescue.md
Normal file
5
.changeset/popular-carrots-rescue.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@pnpm/filter-workspace-packages": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
New function exported: `filterPackagesFromDir`.
|
||||||
@@ -51,18 +51,33 @@ export async function readProjects (
|
|||||||
return { allProjects, selectedProjectsGraph }
|
return { allProjects, selectedProjectsGraph }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FilterPackagesOptions {
|
||||||
|
linkWorkspacePackages?: boolean
|
||||||
|
prefix: string
|
||||||
|
workspaceDir: string
|
||||||
|
testPattern?: string[]
|
||||||
|
changedFilesIgnorePattern?: string[]
|
||||||
|
useGlobDirFiltering?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function filterPackagesFromDir (
|
||||||
|
workspaceDir: string,
|
||||||
|
filter: WorkspaceFilter[],
|
||||||
|
opts: FilterPackagesOptions & { engineStrict?: boolean, patterns: string[] }
|
||||||
|
) {
|
||||||
|
const allProjects = await findWorkspacePackages(workspaceDir, { engineStrict: opts?.engineStrict, patterns: opts.patterns })
|
||||||
|
return {
|
||||||
|
allProjects,
|
||||||
|
...(await filterPackages(allProjects, filter, opts)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function filterPackages<T> (
|
export async function filterPackages<T> (
|
||||||
pkgs: Array<Package & T>,
|
pkgs: Array<Package & T>,
|
||||||
filter: WorkspaceFilter[],
|
filter: WorkspaceFilter[],
|
||||||
opts: {
|
opts: FilterPackagesOptions
|
||||||
linkWorkspacePackages?: boolean
|
|
||||||
prefix: string
|
|
||||||
workspaceDir: string
|
|
||||||
testPattern?: string[]
|
|
||||||
changedFilesIgnorePattern?: string[]
|
|
||||||
useGlobDirFiltering?: boolean
|
|
||||||
}
|
|
||||||
): Promise<{
|
): Promise<{
|
||||||
|
allProjectsGraph: PackageGraph<T>
|
||||||
selectedProjectsGraph: PackageGraph<T>
|
selectedProjectsGraph: PackageGraph<T>
|
||||||
unmatchedFilters: string[]
|
unmatchedFilters: string[]
|
||||||
}> {
|
}> {
|
||||||
@@ -82,6 +97,7 @@ export async function filterPkgsBySelectorObjects<T> (
|
|||||||
useGlobDirFiltering?: boolean
|
useGlobDirFiltering?: boolean
|
||||||
}
|
}
|
||||||
): Promise<{
|
): Promise<{
|
||||||
|
allProjectsGraph: PackageGraph<T>
|
||||||
selectedProjectsGraph: PackageGraph<T>
|
selectedProjectsGraph: PackageGraph<T>
|
||||||
unmatchedFilters: string[]
|
unmatchedFilters: string[]
|
||||||
}> {
|
}> {
|
||||||
@@ -89,9 +105,9 @@ export async function filterPkgsBySelectorObjects<T> (
|
|||||||
|
|
||||||
if ((allPackageSelectors.length > 0) || (prodPackageSelectors.length > 0)) {
|
if ((allPackageSelectors.length > 0) || (prodPackageSelectors.length > 0)) {
|
||||||
let filteredGraph: FilteredGraph<T> | undefined
|
let filteredGraph: FilteredGraph<T> | undefined
|
||||||
|
const { graph } = createPkgGraph<T>(pkgs, { linkWorkspacePackages: opts.linkWorkspacePackages })
|
||||||
|
|
||||||
if (allPackageSelectors.length > 0) {
|
if (allPackageSelectors.length > 0) {
|
||||||
const { graph } = createPkgGraph<T>(pkgs, { linkWorkspacePackages: opts.linkWorkspacePackages })
|
|
||||||
filteredGraph = await filterGraph(graph, allPackageSelectors, {
|
filteredGraph = await filterGraph(graph, allPackageSelectors, {
|
||||||
workspaceDir: opts.workspaceDir,
|
workspaceDir: opts.workspaceDir,
|
||||||
testPattern: opts.testPattern,
|
testPattern: opts.testPattern,
|
||||||
@@ -112,7 +128,8 @@ export async function filterPkgsBySelectorObjects<T> (
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve({
|
return {
|
||||||
|
allProjectsGraph: graph,
|
||||||
selectedProjectsGraph: {
|
selectedProjectsGraph: {
|
||||||
...prodFilteredGraph?.selectedProjectsGraph,
|
...prodFilteredGraph?.selectedProjectsGraph,
|
||||||
...filteredGraph?.selectedProjectsGraph,
|
...filteredGraph?.selectedProjectsGraph,
|
||||||
@@ -121,10 +138,10 @@ export async function filterPkgsBySelectorObjects<T> (
|
|||||||
...(prodFilteredGraph !== undefined ? prodFilteredGraph.unmatchedFilters : []),
|
...(prodFilteredGraph !== undefined ? prodFilteredGraph.unmatchedFilters : []),
|
||||||
...(filteredGraph !== undefined ? filteredGraph.unmatchedFilters : []),
|
...(filteredGraph !== undefined ? filteredGraph.unmatchedFilters : []),
|
||||||
],
|
],
|
||||||
})
|
}
|
||||||
} else {
|
} else {
|
||||||
const { graph } = createPkgGraph<T>(pkgs, { linkWorkspacePackages: opts.linkWorkspacePackages })
|
const { graph } = createPkgGraph<T>(pkgs, { linkWorkspacePackages: opts.linkWorkspacePackages })
|
||||||
return Promise.resolve({ selectedProjectsGraph: graph, unmatchedFilters: [] })
|
return { allProjectsGraph: graph, selectedProjectsGraph: graph, unmatchedFilters: [] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import {
|
|||||||
Config,
|
Config,
|
||||||
} from '@pnpm/config'
|
} from '@pnpm/config'
|
||||||
import { scopeLogger } from '@pnpm/core-loggers'
|
import { scopeLogger } from '@pnpm/core-loggers'
|
||||||
import { filterPackages } from '@pnpm/filter-workspace-packages'
|
import { filterPackagesFromDir } from '@pnpm/filter-workspace-packages'
|
||||||
import findWorkspacePackages from '@pnpm/find-workspace-packages'
|
|
||||||
import logger from '@pnpm/logger'
|
import logger from '@pnpm/logger'
|
||||||
import { ParsedCliArgs } from '@pnpm/parse-cli-args'
|
import { ParsedCliArgs } from '@pnpm/parse-cli-args'
|
||||||
import { node } from '@pnpm/plugin-commands-env'
|
import { node } from '@pnpm/plugin-commands-env'
|
||||||
@@ -167,18 +166,6 @@ export default async function run (inputArgv: string[]) {
|
|||||||
|
|
||||||
if (cliOptions['recursive']) {
|
if (cliOptions['recursive']) {
|
||||||
const wsDir = workspaceDir ?? process.cwd()
|
const wsDir = workspaceDir ?? process.cwd()
|
||||||
const allProjects = await findWorkspacePackages(wsDir, {
|
|
||||||
engineStrict: config.engineStrict,
|
|
||||||
patterns: cliOptions['workspace-packages'],
|
|
||||||
})
|
|
||||||
|
|
||||||
if (allProjects.length === 0) {
|
|
||||||
if (printLogs) {
|
|
||||||
console.log(`No projects found in "${wsDir}"`)
|
|
||||||
}
|
|
||||||
process.exitCode = 0
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
config.filter = config.filter ?? []
|
config.filter = config.filter ?? []
|
||||||
config.filterProd = config.filterProd ?? []
|
config.filterProd = config.filterProd ?? []
|
||||||
@@ -194,7 +181,9 @@ export default async function run (inputArgv: string[]) {
|
|||||||
filters.push({ filter: `!{${relativeWSDirPath()}}`, followProdDepsOnly: false })
|
filters.push({ filter: `!{${relativeWSDirPath()}}`, followProdDepsOnly: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
const filterResults = await filterPackages(allProjects, filters, {
|
const filterResults = await filterPackagesFromDir(wsDir, filters, {
|
||||||
|
engineStrict: config.engineStrict,
|
||||||
|
patterns: cliOptions['workspace-packages'],
|
||||||
linkWorkspacePackages: !!config.linkWorkspacePackages,
|
linkWorkspacePackages: !!config.linkWorkspacePackages,
|
||||||
prefix: process.cwd(),
|
prefix: process.cwd(),
|
||||||
workspaceDir: wsDir,
|
workspaceDir: wsDir,
|
||||||
@@ -202,6 +191,14 @@ export default async function run (inputArgv: string[]) {
|
|||||||
changedFilesIgnorePattern: config.changedFilesIgnorePattern,
|
changedFilesIgnorePattern: config.changedFilesIgnorePattern,
|
||||||
useGlobDirFiltering: !config.legacyDirFiltering,
|
useGlobDirFiltering: !config.legacyDirFiltering,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (filterResults.allProjects.length === 0) {
|
||||||
|
if (printLogs) {
|
||||||
|
console.log(`No projects found in "${wsDir}"`)
|
||||||
|
}
|
||||||
|
process.exitCode = 0
|
||||||
|
return
|
||||||
|
}
|
||||||
config.selectedProjectsGraph = filterResults.selectedProjectsGraph
|
config.selectedProjectsGraph = filterResults.selectedProjectsGraph
|
||||||
if (isEmpty(config.selectedProjectsGraph)) {
|
if (isEmpty(config.selectedProjectsGraph)) {
|
||||||
if (printLogs) {
|
if (printLogs) {
|
||||||
@@ -213,7 +210,7 @@ export default async function run (inputArgv: string[]) {
|
|||||||
if (filterResults.unmatchedFilters.length !== 0 && printLogs) {
|
if (filterResults.unmatchedFilters.length !== 0 && printLogs) {
|
||||||
console.log(`No projects matched the filters "${filterResults.unmatchedFilters.join(', ')}" in "${wsDir}"`)
|
console.log(`No projects matched the filters "${filterResults.unmatchedFilters.join(', ')}" in "${wsDir}"`)
|
||||||
}
|
}
|
||||||
config.allProjects = allProjects
|
config.allProjects = filterResults.allProjects
|
||||||
config.workspaceDir = wsDir
|
config.workspaceDir = wsDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user