Skip to content

Commit e157302

Browse files
authored
fix(yarn): exclude root packages (#320)
1 parent f00b28f commit e157302

File tree

3 files changed

+51
-14
lines changed

3 files changed

+51
-14
lines changed

pkg/lockfile/parse-yarn-lock-v2_test.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,6 @@ func TestParseYarnLock_v2_WithPrerelease(t *testing.T) {
180180
Ecosystem: lockfile.YarnEcosystem,
181181
CompareAs: lockfile.YarnEcosystem,
182182
},
183-
{
184-
Name: "eslint-plugin-jest",
185-
Version: "0.0.0-use.local",
186-
Ecosystem: lockfile.YarnEcosystem,
187-
CompareAs: lockfile.YarnEcosystem,
188-
},
189183
})
190184
}
191185

@@ -212,12 +206,6 @@ func TestParseYarnLock_v2_WithBuildString(t *testing.T) {
212206
Ecosystem: lockfile.YarnEcosystem,
213207
CompareAs: lockfile.YarnEcosystem,
214208
},
215-
{
216-
Name: "zone.js",
217-
Version: "0.0.0-use.local",
218-
Ecosystem: lockfile.YarnEcosystem,
219-
CompareAs: lockfile.YarnEcosystem,
220-
},
221209
})
222210
}
223211

@@ -331,11 +319,30 @@ func TestParseYarnLock_v2_WithAliases(t *testing.T) {
331319
Ecosystem: lockfile.YarnEcosystem,
332320
CompareAs: lockfile.YarnEcosystem,
333321
},
322+
})
323+
}
324+
325+
func TestParseYarnLock_v2_ExcludeRoot(t *testing.T) {
326+
t.Parallel()
327+
328+
packages, err := lockfile.ParseYarnLock("testdata/yarn/exclude-root.v2.lock")
329+
330+
if err != nil {
331+
t.Errorf("Got unexpected error: %v", err)
332+
}
333+
334+
expectPackages(t, packages, []lockfile.PackageDetails{
334335
{
335-
Name: "mine",
336+
Name: "@ws/ansi-regex",
336337
Version: "0.0.0-use.local",
337338
Ecosystem: lockfile.YarnEcosystem,
338339
CompareAs: lockfile.YarnEcosystem,
339340
},
341+
{
342+
Name: "ansi-regex",
343+
Version: "6.1.0",
344+
Ecosystem: lockfile.YarnEcosystem,
345+
CompareAs: lockfile.YarnEcosystem,
346+
},
340347
})
341348
}

pkg/lockfile/parse-yarn-lock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func ParseYarnLock(pathToLockfile string) ([]PackageDetails, error) {
189189
packages := make([]PackageDetails, 0, len(packageGroups))
190190

191191
for _, group := range packageGroups {
192-
if group[0] == "__metadata:" {
192+
if group[0] == "__metadata:" || strings.HasSuffix(group[0], "@workspace:.\":") {
193193
continue
194194
}
195195

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file is generated by running "yarn install" inside your project.
2+
# Manual changes might be lost - proceed with caution!
3+
4+
__metadata:
5+
version: 8
6+
cacheKey: 10c0
7+
8+
"@ws/ansi-regex@workspace:^, @ws/ansi-regex@workspace:ansi-regex":
9+
version: 0.0.0-use.local
10+
resolution: "@ws/ansi-regex@workspace:ansi-regex"
11+
dependencies:
12+
ansi-regex: "npm:^6.1.0"
13+
languageName: unknown
14+
linkType: soft
15+
16+
"ansi-regex@npm:^6.1.0":
17+
version: 6.1.0
18+
resolution: "ansi-regex@npm:6.1.0"
19+
checksum: 10c0/a91daeddd54746338478eef88af3439a7edf30f8e23196e2d6ed182da9add559c601266dbef01c2efa46a958ad6f1f8b176799657616c702b5b02e799e7fd8dc
20+
languageName: node
21+
linkType: hard
22+
23+
"ansi-regex@workspace:.":
24+
version: 0.0.0-use.local
25+
resolution: "ansi-regex@workspace:."
26+
dependencies:
27+
"@ws/ansi-regex": "workspace:^"
28+
ansi-regex: "npm:^6.1.0"
29+
languageName: unknown
30+
linkType: soft

0 commit comments

Comments
 (0)