Skip to content

Commit 25539c2

Browse files
authored
Merge pull request #6335 from snyk/fix/pnpm-workspaces-respect-exclude
fix: pnpm workspaces respect exclude
2 parents 0e933a6 + 293d9b1 commit 25539c2

File tree

10 files changed

+221
-1114
lines changed

10 files changed

+221
-1114
lines changed

package-lock.json

Lines changed: 43 additions & 1107 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@
122122
"snyk-gradle-plugin": "5.1.1",
123123
"snyk-module": "3.1.0",
124124
"snyk-mvn-plugin": "4.3.3",
125-
"snyk-nodejs-lockfile-parser": "2.4.2",
126-
"snyk-nodejs-plugin": "1.4.4",
125+
"snyk-nodejs-lockfile-parser": "2.4.3",
126+
"snyk-nodejs-plugin": "1.4.5",
127127
"snyk-nuget-plugin": "2.12.0",
128128
"snyk-php-plugin": "1.12.1",
129129
"snyk-policy": "^4.1.6",

src/lib/plugins/get-multi-plugin-result.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ async function processWorkspacesProjects(
214214
{
215215
strictOutOfSync: options.strictOutOfSync,
216216
dev: options.dev,
217+
exclude: options.exclude,
217218
},
218219
targetFiles,
219220
);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "app1",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"lodash": "4.17.11"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "app2",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"axios": "0.21.0"
6+
}
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "pnpm-workspace-root",
3+
"version": "1.0.0",
4+
"private": true,
5+
"description": "Test fixture for pnpm workspace exclude bug"
6+
}

test/fixtures/pnpm-workspace-with-exclude-issue/workspace/pnpm-lock.yaml

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
packages:
2+
- 'app1'
3+
- 'app2'
4+
- 'shared'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "shared",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"moment": "2.29.1"
6+
}
7+
}

test/jest/acceptance/snyk-test/all-projects.spec.ts

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import { mkdir, rm, writeFile } from 'fs/promises';
2+
import { tmpdir } from 'os';
3+
import { join } from 'path';
4+
import { fakeServer } from '../../../acceptance/fake-server';
15
import {
26
createProjectFromFixture,
37
createProjectFromWorkspace,
48
} from '../../util/createProject';
5-
import { runSnykCLI } from '../../util/runSnykCLI';
6-
import { fakeServer } from '../../../acceptance/fake-server';
79
import { getServerPort } from '../../util/getServerPort';
8-
import { rm, writeFile, mkdir } from 'fs/promises';
9-
import { join } from 'path';
10-
import { tmpdir } from 'os';
10+
import { runSnykCLI } from '../../util/runSnykCLI';
1111

1212
jest.setTimeout(1000 * 60);
1313

@@ -403,4 +403,81 @@ describe('snyk test --all-projects (mocked server only)', () => {
403403
console.warn('teardown failed');
404404
}
405405
});
406+
407+
test('`test pnpm-workspace --all-projects --exclude=shared` excludes specified directory', async () => {
408+
server.setFeatureFlag('enablePnpmCli', true);
409+
410+
const project = await createProjectFromFixture(
411+
'pnpm-workspace-with-exclude-issue/workspace',
412+
);
413+
414+
const { code, stdout } = await runSnykCLI(
415+
'test --all-projects --exclude=shared',
416+
{
417+
cwd: project.path(),
418+
env,
419+
},
420+
);
421+
422+
const backendRequests = server.getRequests().filter((req: any) => {
423+
return req.url.includes('/api/v1/test');
424+
});
425+
426+
const sharedPath = join('shared', 'package.json');
427+
const app1Path = join('app1', 'package.json');
428+
const app2Path = join('app2', 'package.json');
429+
430+
expect(backendRequests.length).toBe(3);
431+
expect(stdout).not.toMatch(sharedPath);
432+
expect(stdout).toMatch(app1Path);
433+
expect(stdout).toMatch(app2Path);
434+
expect(code).toEqual(0);
435+
});
436+
437+
test('`test pnpm-workspace --all-projects --exclude=shared --detection-depth=2` excludes specified directory', async () => {
438+
server.setFeatureFlag('enablePnpmCli', true);
439+
440+
const project = await createProjectFromFixture(
441+
'pnpm-workspace-with-exclude-issue/workspace',
442+
);
443+
444+
const { code, stdout } = await runSnykCLI(
445+
'test --all-projects --exclude=shared --detection-depth=2',
446+
{
447+
cwd: project.path(),
448+
env,
449+
},
450+
);
451+
452+
const backendRequests = server.getRequests().filter((req: any) => {
453+
return req.url.includes('/api/v1/test');
454+
});
455+
456+
expect(backendRequests.length).toBe(3);
457+
expect(stdout).not.toMatch(join('shared', 'package.json'));
458+
expect(code).toEqual(0);
459+
});
460+
461+
test('`test pnpm-workspace --all-projects` scans all workspace projects', async () => {
462+
server.setFeatureFlag('enablePnpmCli', true);
463+
464+
const project = await createProjectFromFixture(
465+
'pnpm-workspace-with-exclude-issue/workspace',
466+
);
467+
468+
const { code, stdout } = await runSnykCLI('test --all-projects', {
469+
cwd: project.path(),
470+
env,
471+
});
472+
473+
const backendRequests = server.getRequests().filter((req: any) => {
474+
return req.url.includes('/api/v1/test');
475+
});
476+
477+
expect(backendRequests.length).toBe(4);
478+
expect(stdout).toMatch(join('app1', 'package.json'));
479+
expect(stdout).toMatch(join('app2', 'package.json'));
480+
expect(stdout).toMatch(join('shared', 'package.json'));
481+
expect(code).toEqual(0);
482+
});
406483
});

0 commit comments

Comments
 (0)