Skip to content

Commit

Permalink
fix(npm): Allow empty node_modules folders when no dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
elldritch committed May 30, 2018
1 parent 3453eb5 commit eb2d07d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion builders/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,27 @@ func (builder *NodeJSBuilder) Analyze(m module.Module, allowUnresolved bool) ([]
return deps, nil
}

type npmManifest struct {
Dependencies map[string]string
}

// IsBuilt checks for the existence of `$PROJECT/node_modules`
func (builder *NodeJSBuilder) IsBuilt(m module.Module, allowUnresolved bool) (bool, error) {
log.Logger.Debugf("Checking Nodejs build: %#v %#v", m, allowUnresolved)

// bug: there are some package.json with no deps (no node_modules)
// test: there are some package.json with no deps (no node_modules)
// TODO: Check if the installed modules are consistent with what's in the
// actual manifest.
var manifest npmManifest
err := parseLogged(filepath.Join(m.Dir, "package.json"), &manifest)
if err != nil {
return false, err
}
if len(manifest.Dependencies) == 0 {
return true, nil
}
isBuilt, err := hasFile(m.Dir, "node_modules")

if err != nil {
// TODO: make this optional -- IsBuilt failures should just be warnings
return false, fmt.Errorf("could not find Nodejs dependencies folder: %s", err.Error())
Expand Down

0 comments on commit eb2d07d

Please sign in to comment.