Skip to content

Commit 4913fc0

Browse files
committed
refactor(cmd): Don't initialise API unless needed
1 parent a8988f7 commit 4913fc0

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

builders/nodejs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,12 @@ func (builder *NodeJSBuilder) Analyze(m module.Module, allowUnresolved bool) ([]
148148
func (builder *NodeJSBuilder) IsBuilt(m module.Module, allowUnresolved bool) (bool, error) {
149149
log.Logger.Debugf("Checking Nodejs build: %#v %#v", m, allowUnresolved)
150150

151+
// bug: there are some package.json with no deps (no node_modules)
151152
// TODO: Check if the installed modules are consistent with what's in the
152153
// actual manifest.
153154
isBuilt, err := hasFile(m.Dir, "node_modules")
154155
if err != nil {
156+
// TODO: make this optional -- IsBuilt failures should just be warnings
155157
return false, fmt.Errorf("could not find Nodejs dependencies folder: %s", err.Error())
156158
}
157159

cmd/fossa/cliutil/init.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import (
88
"github.com/fossas/fossa-cli/log"
99
)
1010

11-
func Init(ctx *cli.Context) config.CLIConfig {
11+
func Initialize(ctx *cli.Context, useAPI bool) config.CLIConfig {
1212
c := config.MustNew(ctx)
1313
log.Initialize(c.Interactive, c.Debug)
14-
fossa.Initialize(c.Endpoint, c.APIKey)
14+
if useAPI {
15+
fossa.MustInitialize(c.Endpoint, c.APIKey)
16+
}
1517
return c
1618
}

cmd/fossa/cmd/upload/upload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func getInput(ctx *cli.Context, usingLocators bool) ([]fossa.SourceUnit, error)
9090
}
9191

9292
func Run(ctx *cli.Context) {
93-
c := cliutil.Init(ctx)
93+
c := cliutil.Initialize(ctx, true)
9494

9595
data, err := getInput(ctx, c.UploadCmd.UseLocators)
9696
if err != nil {

0 commit comments

Comments
 (0)