Skip to content

Commit 64ddd93

Browse files
authored
Merge pull request #127 from fossas/fix/support-bower-custom-folder
fix(builders): #125 add bower component dir resolution
2 parents da16a44 + e142a95 commit 64ddd93

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

builders/bower.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ type BowerComponent struct {
2121
Version string `json:"version"`
2222
}
2323

24+
type BowerConfiguration struct {
25+
Cwd string `json:"cwd"`
26+
Directory string `json:"directory"`
27+
Registry string `json:"registry"`
28+
}
29+
2430
// Fetcher always returns bower for BowerComponent
2531
func (m BowerComponent) Fetcher() string {
2632
return "bower" // TODO: support `git` and etc...
@@ -121,13 +127,30 @@ func (builder *BowerBuilder) Analyze(m module.Module, allowUnresolved bool) ([]m
121127
return deps, nil
122128
}
123129

130+
// resolveBowerComponentsDirectory resolves a component dir from a `.bowerrc` file, falling back to `bower_components`
131+
func resolveBowerComponentsDirectory(dir string) string {
132+
bowerConfigPath := filepath.Join(dir, ".bowerrc")
133+
bowerComponentsPath := filepath.Join(dir, "bower_components")
134+
135+
if bowerConfigExists, _ := hasFile(bowerConfigPath); bowerConfigExists {
136+
var bowerConfiguration BowerConfiguration
137+
parseLogged(bowerLogger, bowerConfigPath, &bowerConfiguration)
138+
139+
if bowerConfiguration.Directory != "" {
140+
bowerComponentsPath = bowerConfiguration.Directory
141+
}
142+
}
143+
144+
return bowerComponentsPath
145+
}
146+
124147
// IsBuilt checks for the existence of `$PROJECT/bower_components`
125148
func (builder *BowerBuilder) IsBuilt(m module.Module, allowUnresolved bool) (bool, error) {
126149
bowerLogger.Debug("Checking Bower build: %#v %#v", m, allowUnresolved)
127150

128151
// TODO: Check if the installed modules are consistent with what's in the
129152
// actual manifest.
130-
isBuilt, err := hasFile(m.Dir, "bower_components")
153+
isBuilt, err := hasFile(resolveBowerComponentsDirectory(m.Dir))
131154
if err != nil {
132155
return false, fmt.Errorf("could not find Bower dependencies folder: %s", err.Error())
133156
}

0 commit comments

Comments
 (0)