Skip to content

Commit e35a80c

Browse files
authored
fix(guided remediation): remove --relock-cmd flag (#1517)
`--relock-cmd` let you override the `npm install` command with an arbitrary command to regenerate the `package-lock.json` after doing a relax. We probably don't want to have that option in osv-scalibr when we migrate this there, so I've removed it now before the v2 release of osv-scanner. If someone actually needs this, they can run the command themselves outside of osv-scanner.
1 parent 33c8a7a commit e35a80c

File tree

5 files changed

+6
-23
lines changed

5 files changed

+6
-23
lines changed

cmd/osv-scanner/fix/main.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ type osvFixOptions struct {
5353
ManifestRW manifest.ReadWriter
5454
Lockfile string
5555
LockfileRW lockfile.ReadWriter
56-
RelockCmd string
5756
NoIntroduce bool
5857
}
5958

@@ -91,10 +90,6 @@ func Command(stdout, stderr io.Writer, r *reporter.Reporter) *cli.Command {
9190
Name: "maven-registry",
9291
Usage: "URL of the default Maven registry to fetch metadata",
9392
},
94-
&cli.StringFlag{
95-
Name: "relock-cmd",
96-
Usage: "command to run to regenerate lockfile on disk after changing the manifest",
97-
},
9893

9994
&cli.BoolFlag{
10095
Name: "non-interactive",
@@ -319,7 +314,6 @@ func action(ctx *cli.Context, stdout, stderr io.Writer) (reporter.Reporter, erro
319314
},
320315
Manifest: ctx.String("manifest"),
321316
Lockfile: ctx.String("lockfile"),
322-
RelockCmd: ctx.String("relock-cmd"),
323317
NoIntroduce: ctx.Bool("no-introduce"),
324318
}
325319

cmd/osv-scanner/fix/noninteractive.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func autoRelax(ctx context.Context, r *outputReporter, opts osvFixOptions, maxUp
182182
return err
183183
}
184184

185-
if opts.Lockfile != "" || opts.RelockCmd != "" {
185+
if opts.Lockfile != "" {
186186
// We only recreate the lockfile if we know a lockfile already exists
187187
// or we've been given a command to run.
188188
r.Infof("Shelling out to regenerate lockfile...\n")
@@ -198,9 +198,7 @@ func autoRelax(ctx context.Context, r *outputReporter, opts osvFixOptions, maxUp
198198
if err == nil {
199199
return nil
200200
}
201-
if opts.RelockCmd != "" {
202-
return err
203-
}
201+
204202
r.Warnf("Install failed. Trying again with `--legacy-peer-deps`...\n")
205203
cmd, err = regenerateLockfileCmd(opts)
206204
if err != nil {

cmd/osv-scanner/fix/regen_lockfile.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"os"
55
"os/exec"
66
"path/filepath"
7-
"strings"
87
)
98

109
func regenerateLockfileCmd(opts osvFixOptions) (*exec.Cmd, error) {
@@ -19,12 +18,7 @@ func regenerateLockfileCmd(opts osvFixOptions) (*exec.Cmd, error) {
1918
}
2019
// TODO: need to also remove node_modules/ in workspace packages
2120

22-
cmd := opts.RelockCmd
23-
if cmd == "" {
24-
cmd = "npm install --package-lock-only"
25-
}
26-
cmdParts := strings.Split(cmd, " ")
27-
c := exec.Command(cmdParts[0], cmdParts[1:]...) //nolint:gosec
21+
c := exec.Command("npm", "install", "--package-lock-only")
2822
c.Dir = dir
2923

3024
return c, nil

cmd/osv-scanner/fix/state-relock-result.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ func (st *stateRelockResult) write(m model) tea.Msg {
514514
return writeMsg{err}
515515
}
516516

517-
if m.options.Lockfile == "" && m.options.RelockCmd == "" {
517+
if m.options.Lockfile == "" {
518518
// TODO: there's no user feedback to show this was successful
519519
return writeMsg{nil}
520520
}
@@ -525,7 +525,7 @@ func (st *stateRelockResult) write(m model) tea.Msg {
525525
}
526526

527527
return tea.ExecProcess(c, func(err error) tea.Msg {
528-
if err != nil && m.options.RelockCmd == "" {
528+
if err != nil {
529529
// try again with "--legacy-peer-deps"
530530
c, err := regenerateLockfileCmd(m.options)
531531
if err != nil {

docs/guided-remediation.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,10 +683,7 @@ The relaxation patches are presented in order of effectiveness, with patches tha
683683
If you wish to apply your current relock & relaxation changes, select the "Write" option to update your manifest file with the new requirements and regenerate your lockfile (if provided).
684684

685685
{: .note }
686-
687-
> The `package-lock.json` file is regenerated by first deleting the existing `package-lock.json` and `node_modules/` directory, then running `npm install --package-lock-only`. This recreates the lockfile but does not install the `node_modules/` dependencies. Run `npm ci` separately to install the dependencies.
688-
>
689-
> The `--relock-cmd` flag can be used to change the executed install command.
686+
The `package-lock.json` file is regenerated by first deleting the existing `package-lock.json` and `node_modules/` directory, then running `npm install --package-lock-only`. This recreates the lockfile but does not install the `node_modules/` dependencies. Run `npm ci` separately to install the dependencies.
690687

691688
### Override dependency versions
692689

0 commit comments

Comments
 (0)