diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/client.go | 18 | ||||
-rw-r--r-- | modules/client_test.go | 9 | ||||
-rw-r--r-- | modules/collect.go | 9 | ||||
-rw-r--r-- | modules/collect_test.go | 11 | ||||
-rw-r--r-- | modules/config.go | 9 | ||||
-rw-r--r-- | modules/config_test.go | 2 | ||||
-rw-r--r-- | modules/npm/package_builder.go | 3 |
7 files changed, 13 insertions, 48 deletions
diff --git a/modules/client.go b/modules/client.go index 7d2175c94..88c1e933e 100644 --- a/modules/client.go +++ b/modules/client.go @@ -25,6 +25,8 @@ import ( "os/exec" "path/filepath" "regexp" + "strings" + "time" hglob "github.com/gohugoio/hugo/hugofs/glob" @@ -36,9 +38,6 @@ import ( "github.com/gohugoio/hugo/common/loggers" - "strings" - "time" - "github.com/gohugoio/hugo/config" "github.com/rogpeppe/go-internal/module" @@ -49,9 +48,7 @@ import ( "github.com/spf13/afero" ) -var ( - fileSeparator = string(os.PathSeparator) -) +var fileSeparator = string(os.PathSeparator) const ( goBinaryStatusOK goBinaryStatus = iota @@ -93,7 +90,6 @@ func NewClient(cfg ClientConfig) *Client { if cfg.CacheDir != "" { // Module cache stored below $GOPATH/pkg config.SetEnvVars(&env, "GOPATH", cfg.CacheDir) - } logger := cfg.Logger @@ -113,7 +109,8 @@ func NewClient(cfg ClientConfig) *Client { noVendor: noVendor, moduleConfig: mcfg, environ: env, - GoModulesFilename: goModFilename} + GoModulesFilename: goModFilename, + } } // Client contains most of the API provided by this package. @@ -165,7 +162,6 @@ func (c *Client) Graph(w io.Writer) error { // Local dir. dep += " => " + replace.Dir() } - } fmt.Fprintln(w, prefix+dep) } @@ -357,7 +353,6 @@ var verifyErrorDirRe = regexp.MustCompile(`dir has been modified \((.*?)\)`) func (c *Client) Verify(clean bool) error { // TODO1 add path to mod clean err := c.runVerify() - if err != nil { if clean { m := verifyErrorDirRe.FindAllStringSubmatch(err.Error(), -1) @@ -450,7 +445,6 @@ func (c *Client) listGoMods() (goModules, error) { } return modules, err - } func (c *Client) rewriteGoMod(name string, isGoMod map[string]bool) error { @@ -515,7 +509,6 @@ func (c *Client) rewriteGoModRewrite(name string, isGoMod map[string]bool) ([]by } return b.Bytes(), nil - } func (c *Client) rmVendorDir(vendorDir string) error { @@ -539,7 +532,6 @@ func (c *Client) runGo( ctx context.Context, stdout io.Writer, args ...string) error { - if c.goBinaryStatus != 0 { return nil } diff --git a/modules/client_test.go b/modules/client_test.go index 7cc1058fc..c7a07fb87 100644 --- a/modules/client_test.go +++ b/modules/client_test.go @@ -30,7 +30,6 @@ import ( ) func TestClient(t *testing.T) { - modName := "hugo-modules-basic-test" modPath := "github.com/gohugoio/tests/" + modName expect := `github.com/gohugoio/tests/hugo-modules-basic-test github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0 @@ -41,7 +40,6 @@ github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0 github.com/gohugoio/h c := qt.New(t) newClient := func(c *qt.C, withConfig func(cfg *ClientConfig)) (*Client, func()) { - workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, modName) c.Assert(err, qt.IsNil) themesDir := filepath.Join(workingDir, "themes") @@ -55,7 +53,7 @@ github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0 github.com/gohugoio/h } withConfig(&ccfg) - ccfg.ModuleConfig.Imports = []Import{Import{Path: "github.com/gohugoio/hugoTestModules1_darwin/modh2_2"}} + ccfg.ModuleConfig.Imports = []Import{{Path: "github.com/gohugoio/hugoTestModules1_darwin/modh2_2"}} client := NewClient(ccfg) return client, clean @@ -98,7 +96,6 @@ project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor // Test Tidy c.Assert(client.Tidy(), qt.IsNil) - }) c.Run("IgnoreVendor", func(c *qt.C) { @@ -165,15 +162,12 @@ project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor dirname, err = client.createThemeDirname(absDir, false) fmt.Println(dirname) c.Assert(err, qt.Not(qt.IsNil)) - }) - } var globAll, _ = glob.GetGlob("**") func TestGetModlineSplitter(t *testing.T) { - c := qt.New(t) gomodSplitter := getModlineSplitter(true) @@ -184,5 +178,4 @@ func TestGetModlineSplitter(t *testing.T) { gosumSplitter := getModlineSplitter(false) c.Assert(gosumSplitter("github.com/BurntSushi/toml v0.3.1"), qt.DeepEquals, []string{"github.com/BurntSushi/toml", "v0.3.1"}) - } diff --git a/modules/collect.go b/modules/collect.go index e00fa540f..179b9d1fb 100644 --- a/modules/collect.go +++ b/modules/collect.go @@ -110,7 +110,6 @@ func (h *Client) collect(tidy bool) (ModulesConfig, *collector) { AllModules: c.modules, GoModulesFilename: c.GoModulesFilename, }, c - } type ModulesConfig struct { @@ -325,7 +324,6 @@ func (c *collector) add(owner *moduleAdapter, moduleImport Import, disabled bool c.modules = append(c.modules, ma) return ma, nil - } func (c *collector) addAndRecurse(owner *moduleAdapter, disabled bool) error { @@ -363,7 +361,6 @@ func (c *collector) applyMounts(moduleImport Import, mod *moduleAdapter) error { if len(mounts) == 0 { // Mounts not defined by the import. mounts = modConfig.Mounts - } if !mod.projectMod && len(mounts) == 0 { @@ -397,7 +394,6 @@ func (c *collector) applyMounts(moduleImport Import, mod *moduleAdapter) error { } func (c *collector) applyThemeConfig(tc *moduleAdapter) error { - var ( configFilename string cfg config.Provider @@ -477,7 +473,6 @@ func (c *collector) applyThemeConfig(tc *moduleAdapter) error { tc.config = config return nil - } func (c *collector) collect() { @@ -502,7 +497,6 @@ func (c *collector) collect() { // Add the project mod on top. c.modules = append(Modules{projectMod}, c.modules...) - } func (c *collector) isVendored(dir string) bool { @@ -515,7 +509,6 @@ func (c *collector) collectModulesTXT(owner Module) error { filename := filepath.Join(vendorDir, vendorModulesFilename) f, err := c.fs.Open(filename) - if err != nil { if os.IsNotExist(err) { return nil @@ -656,7 +649,6 @@ func (c *collector) wrapModuleNotFound(err error) error { } return err - } type vendoredModule struct { @@ -679,7 +671,6 @@ func createProjectModule(gomod *goModule, workingDir string, conf Config) *modul projectMod: true, config: conf, } - } // In the first iteration of Hugo Modules, we do not support multiple diff --git a/modules/collect_test.go b/modules/collect_test.go index 7f320f40a..9487c0a0e 100644 --- a/modules/collect_test.go +++ b/modules/collect_test.go @@ -34,21 +34,18 @@ func TestPathKey(t *testing.T) { } { c.Assert(pathKey(test.in), qt.Equals, test.expect) } - } func TestFilterUnwantedMounts(t *testing.T) { - mounts := []Mount{ - Mount{Source: "a", Target: "b", Lang: "en"}, - Mount{Source: "a", Target: "b", Lang: "en"}, - Mount{Source: "b", Target: "c", Lang: "en"}, + {Source: "a", Target: "b", Lang: "en"}, + {Source: "a", Target: "b", Lang: "en"}, + {Source: "b", Target: "c", Lang: "en"}, } filtered := filterUnwantedMounts(mounts) c := qt.New(t) c.Assert(len(filtered), qt.Equals, 2) - c.Assert(filtered, qt.DeepEquals, []Mount{Mount{Source: "a", Target: "b", Lang: "en"}, Mount{Source: "b", Target: "c", Lang: "en"}}) - + c.Assert(filtered, qt.DeepEquals, []Mount{{Source: "a", Target: "b", Lang: "en"}, {Source: "b", Target: "c", Lang: "en"}}) } diff --git a/modules/config.go b/modules/config.go index 1ce8c9f02..d56f38343 100644 --- a/modules/config.go +++ b/modules/config.go @@ -113,10 +113,11 @@ func ApplyProjectConfigDefaults(cfg config.Provider, mod Module) error { source := cfg.GetString(d.key) componentsConfigured[d.component] = true - return []Mount{Mount{ + return []Mount{{ // No lang set for layouts etc. Source: source, - Target: d.component}} + Target: d.component, + }} } return nil @@ -166,7 +167,6 @@ func ApplyProjectConfigDefaults(cfg config.Provider, mod Module) error { var mounts []Mount for _, dirKey := range dirKeys { if componentsConfigured[dirKey.component] { - continue } @@ -240,7 +240,6 @@ func decodeConfig(cfg config.Provider, pathReplacements map[string]string) (Conf c.Imports[i] = imp } } - } for i, mnt := range c.Mounts { @@ -393,11 +392,9 @@ func getStaticDirs(cfg config.Provider) []string { } func getStringOrStringSlice(cfg config.Provider, key string, id int) []string { - if id >= 0 { key = fmt.Sprintf("%s%d", key, id) } return config.GetStringSlicePreserveString(cfg, key) - } diff --git a/modules/config_test.go b/modules/config_test.go index dd9dbc22f..458240b60 100644 --- a/modules/config_test.go +++ b/modules/config_test.go @@ -120,7 +120,6 @@ path="github.com/bep/mycomponent" } }) - } func TestDecodeConfigBothOldAndNewProvided(t *testing.T) { @@ -141,7 +140,6 @@ path="a" c.Assert(err, qt.IsNil) c.Assert(len(modCfg.Imports), qt.Equals, 3) c.Assert(modCfg.Imports[0].Path, qt.Equals, "a") - } // Test old style theme import. diff --git a/modules/npm/package_builder.go b/modules/npm/package_builder.go index c0a5b0dad..f407a92bd 100644 --- a/modules/npm/package_builder.go +++ b/modules/npm/package_builder.go @@ -45,7 +45,6 @@ const ( ) func Pack(fs afero.Fs, fis []hugofs.FileMetaInfo) error { - var b *packageBuilder // Have a package.hugo.json? @@ -140,7 +139,6 @@ func Pack(fs afero.Fs, fis []hugofs.FileMetaInfo) error { } return nil - } func newPackageBuilder(source string, first io.Reader) *packageBuilder { @@ -220,7 +218,6 @@ func (b *packageBuilder) addm(source string, m map[string]interface{}) { } } } - } func (b *packageBuilder) unmarshal(r io.Reader) map[string]interface{} { |