feat: add legacy-dir-filtering (#4610)

close #4606
This commit is contained in:
Zoltan Kochan
2022-04-23 16:23:04 +03:00
committed by GitHub
parent c38feff08f
commit e05dcc48a0
6 changed files with 71 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/config": minor
---
New setting added to turn back v6 directory filtering that doesn't require globs: `legacy-dir-filtering`.

View File

@@ -141,6 +141,7 @@ export interface Config {
modulesCacheMaxAge: number
embedReadme?: boolean
gitShallowHosts?: string[]
legacyDirFiltering?: boolean
registries: Registries
ignoreWorkspaceRootCheck: boolean

View File

@@ -58,6 +58,7 @@ export const types = Object.assign({
'ignore-pnpmfile': Boolean,
'ignore-workspace': Boolean,
'ignore-workspace-root-check': Boolean,
'legacy-dir-filtering': Boolean,
'link-workspace-packages': [Boolean, 'deep'],
lockfile: Boolean,
'lockfile-dir': String,

View File

@@ -13,6 +13,8 @@
In pnpm v7, a glob should be used: `--filter=./apps/**`
For easier upgrade, we have also added a setting to turn back filtering as it was in v6. Just set `legacy-dir-filtering=true` in `.npmrc`.
- The `NODE_PATH` env variable is not set in the command shims (the files in `node_modules/.bin`). This env variable was really long and frequently caused errors on Windows.
Also, the `extend-node-path` setting is removed.

View File

@@ -200,7 +200,7 @@ export default async function run (inputArgv: string[]) {
workspaceDir: wsDir,
testPattern: config.testPattern,
changedFilesIgnorePattern: config.changedFilesIgnorePattern,
useGlobDirFiltering: true,
useGlobDirFiltering: !config.legacyDirFiltering,
})
config.selectedProjectsGraph = filterResults.selectedProjectsGraph
if (isEmpty(config.selectedProjectsGraph)) {

View File

@@ -1498,3 +1498,64 @@ test('pnpm run should include the workspace root when --workspace-root option is
expect(await exists('test')).toBeTruthy()
expect(await exists('project/test')).toBeTruthy()
})
test('legacy directory filtering', async () => {
preparePackages([
{
location: 'packages/project-1',
package: {
name: 'project-1',
version: '1.0.0',
},
},
{
location: 'packages/project-2',
package: {
name: 'project-2',
version: '1.0.0',
},
},
])
process.chdir('..')
await writeYamlFile('pnpm-workspace.yaml', { packages: ['**', '!store/**'] })
await fs.writeFile('.npmrc', 'legacy-dir-filtering=true', 'utf8')
const { stdout } = execPnpmSync(['list', '--filter=./packages', '--parseable', '--depth=-1'])
const output = stdout.toString()
expect(output).toContain('project-1')
expect(output).toContain('project-2')
})
test('directory filtering', async () => {
preparePackages([
{
location: 'packages/project-1',
package: {
name: 'project-1',
version: '1.0.0',
},
},
{
location: 'packages/project-2',
package: {
name: 'project-2',
version: '1.0.0',
},
},
])
process.chdir('..')
await writeYamlFile('pnpm-workspace.yaml', { packages: ['**', '!store/**'] })
{
const { stdout } = execPnpmSync(['list', '--filter=./packages', '--parseable', '--depth=-1'])
expect(stdout.toString()).toEqual('')
}
{
const { stdout } = execPnpmSync(['list', '--filter=./packages/**', '--parseable', '--depth=-1'])
const output = stdout.toString()
expect(output).toContain('project-1')
expect(output).toContain('project-2')
}
})