Skip to content

Commit 9ff8fc9

Browse files
authored
Merge pull request #259 from snyk/fix/pnpm-undefined-versions
fix: return same format for undefined versions pnpm
2 parents 49c359c + 780939b commit 9ff8fc9

File tree

25 files changed

+91
-66
lines changed

25 files changed

+91
-66
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '../../errors/out-of-sync-error';
1414
import { LockfileType } from '../..';
1515
import * as debugModule from 'debug';
16+
import { UNDEFINED_VERSION } from './constants';
1617

1718
const debug = debugModule('snyk-pnpm-workspaces');
1819

@@ -31,7 +32,7 @@ export const buildDepGraphPnpm = async (
3132

3233
const depGraphBuilder = new DepGraphBuilder(
3334
{ name: 'pnpm' },
34-
{ name: pkgJson.name, version: pkgJson.version },
35+
{ name: pkgJson.name, version: pkgJson.version || UNDEFINED_VERSION },
3536
);
3637

3738
lockFileParser.extractedPackages = lockFileParser.extractPackages();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const UNDEFINED_VERSION = 'undefined';

lib/dep-graph-builders/pnpm/lockfile-parser/lockfile-parser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { valid } from 'semver';
1212
import * as pathUtil from 'path';
1313
import { isEmpty } from 'lodash';
1414
import * as debugModule from 'debug';
15+
import { UNDEFINED_VERSION } from '../constants';
1516

1617
const debug = debugModule('snyk-pnpm-workspaces');
1718

@@ -218,12 +219,12 @@ export abstract class PnpmLockfileParser {
218219
debug(
219220
`Importer ${resolvedPathDep} discovered as a dependency of ${importerName} was not found in the lockfile`,
220221
);
221-
version = 'undefined';
222+
version = UNDEFINED_VERSION;
222223
} else {
223224
version = mappedProjInfo.version;
224225
}
225226
if (!version) {
226-
version = 'undefined';
227+
version = UNDEFINED_VERSION;
227228
}
228229

229230
// Stop recursion here if this package was already normalized and stored in extractedPackages

lib/dep-graph-builders/pnpm/parse-workspace.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { getPnpmLockfileParser } from './lockfile-parser/index';
1212
import { PnpmLockfileParser } from './lockfile-parser/lockfile-parser';
1313
import { getPnpmLockfileVersion } from '../../utils';
1414
import { getFileContents } from './utils';
15+
import { UNDEFINED_VERSION } from './constants';
1516

1617
const debug = debugModule('snyk-pnpm-workspaces');
1718

@@ -29,7 +30,7 @@ function computeProjectVersionMaps(root: string, targets: string[]) {
2930
try {
3031
const parsedPkgJson = parsePkgJson(packageJson.content);
3132
projectsVersionMap[target] = {
32-
version: parsedPkgJson.version,
33+
version: parsedPkgJson.version || UNDEFINED_VERSION,
3334
name: parsedPkgJson.name,
3435
};
3536
} catch (err: any) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
LOCK_FILE_NAME,
1212
} from '../../errors/out-of-sync-error';
1313
import * as debugModule from 'debug';
14+
import { UNDEFINED_VERSION } from './constants';
1415

1516
const debug = debugModule('snyk-pnpm-workspaces');
1617
export const getPnpmChildNode = (
@@ -50,7 +51,7 @@ export const getPnpmChildNode = (
5051
return {
5152
id: childNodeKey,
5253
name: name,
53-
version: resolvedVersion,
54+
version: resolvedVersion || UNDEFINED_VERSION,
5455
dependencies: {},
5556
isDev: depInfo.isDev,
5657
missingLockFileEntry: true,
@@ -71,7 +72,7 @@ export const getPnpmChildNode = (
7172
return {
7273
id: `${name}@${depData.version}`,
7374
name: name,
74-
version: resolvedVersion,
75+
version: depData.version || UNDEFINED_VERSION,
7576
dependencies: {
7677
...dependencies,
7778
...optionalDependencies,

test/jest/dep-graph-builders/fixtures/pnpm-lock-v5/alias-sub-dependency/expected.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
},
66
"pkgs": [
77
{
8-
"id": "pnpm-alias@",
8+
"id": "pnpm-alias@undefined",
99
"info": {
10-
"name": "pnpm-alias"
10+
"name": "pnpm-alias",
11+
"version": "undefined"
1112
}
1213
},
1314
{
@@ -149,7 +150,7 @@
149150
"nodes": [
150151
{
151152
"nodeId": "root-node",
152-
"pkgId": "pnpm-alias@",
153+
"pkgId": "pnpm-alias@undefined",
153154
"deps": [
154155
{
155156
"nodeId": "@isaacs/[email protected]"

test/jest/dep-graph-builders/fixtures/pnpm-lock-v5/cyclic-dep/expected.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
},
66
"pkgs": [
77
{
8-
"id": "cyclic@",
8+
"id": "cyclic@undefined",
99
"info": {
10-
"name": "cyclic"
10+
"name": "cyclic",
11+
"version": "undefined"
1112
}
1213
},
1314
{
@@ -254,7 +255,7 @@
254255
"nodes": [
255256
{
256257
"nodeId": "root-node",
257-
"pkgId": "cyclic@",
258+
"pkgId": "cyclic@undefined",
258259
"deps": [
259260
{
260261
"nodeId": "@blitzjs/[email protected]"

test/jest/dep-graph-builders/fixtures/pnpm-lock-v5/external-tarball/expected.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
},
66
"pkgs": [
77
{
8-
"id": "external-tarball@",
8+
"id": "external-tarball@undefined",
99
"info": {
10-
"name": "external-tarball"
10+
"name": "external-tarball",
11+
"version": "undefined"
1112
}
1213
},
1314
{
@@ -100,7 +101,7 @@
100101
"nodes": [
101102
{
102103
"nodeId": "root-node",
103-
"pkgId": "external-tarball@",
104+
"pkgId": "external-tarball@undefined",
104105
"deps": [
105106
{
106107
"nodeId": "[email protected]"

test/jest/dep-graph-builders/fixtures/pnpm-lock-v5/git-ssh-url-deps/expected.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
},
66
"pkgs": [
77
{
8-
"id": "git-ssh-url-deps@",
8+
"id": "git-ssh-url-deps@undefined",
99
"info": {
10-
"name": "git-ssh-url-deps"
10+
"name": "git-ssh-url-deps",
11+
"version": "undefined"
1112
}
1213
},
1314
{
@@ -100,7 +101,7 @@
100101
"nodes": [
101102
{
102103
"nodeId": "root-node",
103-
"pkgId": "git-ssh-url-deps@",
104+
"pkgId": "git-ssh-url-deps@undefined",
104105
"deps": [
105106
{
106107
"nodeId": "[email protected]"

test/jest/dep-graph-builders/fixtures/pnpm-lock-v5/npm-protocol/expected.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
},
66
"pkgs": [
77
{
8-
"id": "test3@",
8+
"id": "test3@undefined",
99
"info": {
10-
"name": "test3"
10+
"name": "test3",
11+
"version": "undefined"
1112
}
1213
},
1314
{
@@ -23,7 +24,7 @@
2324
"nodes": [
2425
{
2526
"nodeId": "root-node",
26-
"pkgId": "test3@",
27+
"pkgId": "test3@undefined",
2728
"deps": [
2829
{
2930
"nodeId": "[email protected]"

0 commit comments

Comments
 (0)