Skip to content

Commit 079fa6f

Browse files
authored
fix: optional deps default true and handle undefined version (#10)
1 parent f9989d5 commit 079fa6f

12 files changed

Lines changed: 190 additions & 11 deletions

File tree

lib/lock-parser/build-dep-graph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function buildDepGraph(
4141
lockFileContents,
4242
{
4343
includeDevDeps: options.includeDevDeps,
44-
includeOptionalDeps: options.includeOptionalDeps,
44+
includeOptionalDeps: options.includeOptionalDeps || true,
4545
pruneWithinTopLevelDeps: true,
4646
strictOutOfSync: options.strictOutOfSync,
4747
},

lib/workspaces/pnpm-workspaces-parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function computeProjectVersionMaps(root: string, targetFiles) {
3636
const projectVersion = parsedPkgJson.version;
3737
projectsVersionMap[
3838
normalizeFilePath(pathUtil.relative(root, directory))
39-
] = projectVersion;
39+
] = projectVersion || 'undefined';
4040
} catch (err: any) {
4141
debug(
4242
`Error getting version for project: ${packageJsonFileName}. ERROR: ${err}`,
@@ -132,7 +132,7 @@ export async function processPnpmWorkspaces(
132132
pnpmLock.content,
133133
{
134134
includeDevDeps: settings.dev || false,
135-
includeOptionalDeps: settings.optional || false,
135+
includeOptionalDeps: settings.optional || true,
136136
pruneWithinTopLevelDeps: true,
137137
strictOutOfSync:
138138
settings.strictOutOfSync === undefined

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"lodash.isempty": "^4.4.0",
4343
"lodash.sortby": "^4.7.0",
4444
"micromatch": "4.0.2",
45-
"snyk-nodejs-lockfile-parser": "^1.53.1",
45+
"snyk-nodejs-lockfile-parser": "^1.53.2",
4646
"snyk-resolve-deps": "4.8.0"
4747
},
4848
"devDependencies": {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "pnpm-shallow-goof",
3+
"version": "0.0.1",
4+
"description": "A vulnerable demo application",
5+
"homepage": "https://snyk.io/",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/snyk-fixtures/pnpm-shallow-goof"
9+
},
10+
"dependencies": {
11+
"a": "workspace:*"
12+
}
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "a",
3+
"description": "",
4+
"main": "index.js",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1"
7+
},
8+
"keywords": [],
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"node-uuid": "1.4.0",
13+
"qs": "0.0.6"
14+
}
15+
}
16+

test/fixtures/pnpm/lock-v5/undefined-package-version/pnpm-lock.yaml

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

test/fixtures/pnpm/lock-v5/undefined-package-version/pnpm-workspace.yaml

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "pnpm-shallow-goof",
3+
"version": "0.0.1",
4+
"description": "A vulnerable demo application",
5+
"homepage": "https://snyk.io/",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/snyk-fixtures/pnpm-shallow-goof"
9+
},
10+
"dependencies": {
11+
"a": "workspace:*"
12+
}
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "a",
3+
"description": "",
4+
"main": "index.js",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1"
7+
},
8+
"keywords": [],
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"node-uuid": "1.4.0",
13+
"qs": "0.0.6"
14+
}
15+
}
16+

test/fixtures/pnpm/lock-v6/undefined-package-version/pnpm-lock.yaml

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

0 commit comments

Comments
 (0)