Skip to content

Commit 2dedbdc

Browse files
authored
Merge pull request #261 from snyk/fix/OSM-2329/pnpm-fix-check-out-of-sync-option
fix: [OSM-2329] pnpm check out of sync option for missing top level deps
2 parents e76c4af + 9aec600 commit 2dedbdc

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

lib/dep-graph-builders/pnpm/build-dep-graph-pnpm.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ export const buildDepGraphPnpm = async (
4747

4848
for (const name of Object.keys(topLevelDeps)) {
4949
if (!extractedTopLevelDeps[name]) {
50+
if (!strictOutOfSync) {
51+
continue;
52+
}
5053
const errMessage =
5154
`Dependency ${name} was not found in ` +
5255
`${LOCK_FILE_NAME[LockfileType.pnpm]}. Your package.json and ` +

test/jest/dep-graph-builders/pnpm-lock.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,56 @@ describe.each(['pnpm-lock-v5', 'pnpm-lock-v6', 'pnpm-lock-v9'])(
207207
),
208208
);
209209
});
210+
211+
it('project: simple-non-top-level-out-of-sync does not throws OutOfSyncError for strictOutOfSync=false', async () => {
212+
const fixtureName = 'missing-non-top-level-deps';
213+
const pkgJsonContent = readFileSync(
214+
join(
215+
__dirname,
216+
`./fixtures/${lockFileVersionPath}/${fixtureName}/package.json`,
217+
),
218+
'utf8',
219+
);
220+
const pnpmLockContent = readFileSync(
221+
join(
222+
__dirname,
223+
`./fixtures/${lockFileVersionPath}/${fixtureName}/pnpm-lock.yaml`,
224+
),
225+
'utf8',
226+
);
227+
const deGraph = parsePnpmProject(pkgJsonContent, pnpmLockContent, {
228+
includeDevDeps: false,
229+
includeOptionalDeps: true,
230+
pruneWithinTopLevelDeps: true,
231+
strictOutOfSync: false,
232+
});
233+
expect(deGraph).toBeDefined();
234+
});
235+
236+
it('project: simple-top-level-out-of-sync does not throws OutOfSyncError for strictOutOfSync=false', async () => {
237+
const fixtureName = 'missing-top-level-deps';
238+
const pkgJsonContent = readFileSync(
239+
join(
240+
__dirname,
241+
`./fixtures/${lockFileVersionPath}/${fixtureName}/package.json`,
242+
),
243+
'utf8',
244+
);
245+
const pnpmLockContent = readFileSync(
246+
join(
247+
__dirname,
248+
`./fixtures/${lockFileVersionPath}/${fixtureName}/pnpm-lock.yaml`,
249+
),
250+
'utf8',
251+
);
252+
const deGraph = parsePnpmProject(pkgJsonContent, pnpmLockContent, {
253+
includeDevDeps: false,
254+
includeOptionalDeps: true,
255+
pruneWithinTopLevelDeps: true,
256+
strictOutOfSync: false,
257+
});
258+
expect(deGraph).toBeDefined();
259+
});
210260
});
211261
},
212262
);

0 commit comments

Comments
 (0)