这是indexloc提供的服务,不要输入任何密码
Skip to content

switch over to use go-yarnlock for yarn.lock parsing #1893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ require (
github.com/hashicorp/go-gatedio v0.5.0
github.com/hashicorp/go-hclog v1.2.1
github.com/hashicorp/go-retryablehttp v0.6.8
github.com/iseki0/go-yarnlock v0.0.2-0.20220905015017-a2a90751cdfa
github.com/karrick/godirwalk v1.16.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/mattn/go-isatty v0.0.14
github.com/mitchellh/cli v1.1.2
github.com/mitchellh/go-homedir v1.1.0
Expand All @@ -33,7 +33,7 @@ require (
github.com/spf13/cobra v1.3.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.12.0
github.com/stretchr/testify v1.7.2
github.com/stretchr/testify v1.8.0
github.com/yookoala/realpath v1.0.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
google.golang.org/grpc v1.46.2
Expand All @@ -46,6 +46,7 @@ require (
require (
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
10 changes: 7 additions & 3 deletions cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f h1:NNJE6p4LchkmNfNskDUaSbrwxZzr7t2/lj2aS+q4oF0=
github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f/go.mod h1:k8feO4+kXDxro6ErPXBRTJ/ro2mf0SsFG8s7doP9kJE=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
Expand Down Expand Up @@ -289,6 +291,8 @@ github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/iseki0/go-yarnlock v0.0.2-0.20220905015017-a2a90751cdfa h1:0sf91Q+lIGU9ikSy16mNfFURM52O1RiB2fQCYEiRPBU=
github.com/iseki0/go-yarnlock v0.0.2-0.20220905015017-a2a90751cdfa/go.mod h1:wQ9AjysVf4yTrNMlPgNbVY8s/XZcdjpMLNyNwDIj47o=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand All @@ -301,8 +305,6 @@ github.com/karrick/godirwalk v1.16.1 h1:DynhcF+bztK8gooS0+NDJFrdNZjJ3gzVzC545UNA
github.com/karrick/godirwalk v1.16.1/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand Down Expand Up @@ -436,15 +438,17 @@ github.com/spf13/viper v1.12.0 h1:CZ7eSOd3kZoaYDLbXnmzgQI5RlciuXBMA+18HwHRfZQ=
github.com/spf13/viper v1.12.0/go.mod h1:b6COn30jlNxbm/V2IqWiNWkJ+vZNiMNksliPCiuKtSI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/subosito/gotenv v1.3.0 h1:mjC+YW8QpAdXibNi+vNWgzmgBH4+5l5dCXv8cNysBLI=
github.com/subosito/gotenv v1.3.0/go.mod h1:YzJjq/33h7nrwdY+iHMhEOEEbW0ovIz0tB6t6PwAXzs=
Expand Down
27 changes: 26 additions & 1 deletion cli/internal/lockfile/berry_lockfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ import (
"gopkg.in/yaml.v3"
)

// YarnLockfileEntry package information from yarn lockfile
type YarnLockfileEntry struct {
// resolved version for the particular entry based on the provided semver revision
Version string `yaml:"version"`
Resolved string `yaml:"resolved"`
Integrity string `yaml:"integrity"`
// the list of unresolved modules and revisions (e.g. type-detect : ^4.0.0)
Dependencies map[string]string `yaml:"dependencies,omitempty"`
// the list of unresolved modules and revisions (e.g. type-detect : ^4.0.0)
OptionalDependencies map[string]string `yaml:"optionalDependencies,omitempty"`
}

// BerryLockfile representation of berry lockfile
type BerryLockfile map[string]*YarnLockfileEntry

Expand Down Expand Up @@ -47,7 +59,7 @@ func (l *BerryLockfile) AllDependencies(key string) (map[string]string, bool) {

// Subgraph Given a list of lockfile keys returns a Lockfile based off the original one that only contains the packages given
func (l *BerryLockfile) Subgraph(packages []string) (Lockfile, error) {
lockfile := make(YarnLockfile, len(packages))
lockfile := make(BerryLockfile, len(packages))
for _, key := range packages {
entry, ok := (*l)[key]
if ok {
Expand Down Expand Up @@ -104,3 +116,16 @@ func DecodeBerryLockfile(contents []byte) (*BerryLockfile, error) {
prettyLockFile := BerryLockfile(yarnSplitOutEntries(lockfile))
return &prettyLockFile, nil
}

func yarnSplitOutEntries(lockfile map[string]*YarnLockfileEntry) map[string]*YarnLockfileEntry {
prettyLockfile := map[string]*YarnLockfileEntry{}
// This final step is important, it splits any deps with multiple-resolutions
// (e.g. "@babel/generator@^7.13.0, @babel/generator@^7.13.9":) into separate
// entries in our map
for key, val := range lockfile {
for _, v := range strings.Split(key, ", ") {
prettyLockfile[strings.TrimSpace(v)] = val
}
}
return prettyLockfile
}
2 changes: 1 addition & 1 deletion cli/internal/lockfile/pnpm_lockfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func getFixture(t *testing.T, name string) ([]byte, error) {
if err != nil {
t.Fatalf("cwd is not an absolute directory %v: %v", defaultCwd, err)
}
lockfilePath := cwd.Join("testdata", "pnpm-lockfiles", name)
lockfilePath := cwd.Join("testdata", name)
if !lockfilePath.FileExists() {
return nil, errors.Errorf("unable to find 'testdata/%s'", name)
}
Expand Down
Loading