diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-09-19 10:53:39 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-09-19 12:26:04 +0200 |
commit | e363964f2fcbeabe4264eaa9d7f803c9989ad096 (patch) | |
tree | 1218d3e5f33015b5d671482fdd3a27c9c76c92fa /config | |
parent | c260cb28a9fe3d391530ecd9011ce6ed927f57f8 (diff) | |
download | hugo-e363964f2fcbeabe4264eaa9d7f803c9989ad096.tar.gz hugo-e363964f2fcbeabe4264eaa9d7f803c9989ad096.zip |
commands: Ignore "module does not exist" errors in hugo mod init
Closes #11458
Diffstat (limited to 'config')
-rw-r--r-- | config/allconfig/allconfig.go | 2 | ||||
-rw-r--r-- | config/allconfig/load.go | 30 |
2 files changed, 18 insertions, 14 deletions
diff --git a/config/allconfig/allconfig.go b/config/allconfig/allconfig.go index f6dfa7260..35517ece2 100644 --- a/config/allconfig/allconfig.go +++ b/config/allconfig/allconfig.go @@ -809,7 +809,7 @@ func (c *Configs) Init() error { } if len(c.Modules) == 0 { - return errors.New("no modules loaded (ned at least the main module)") + return errors.New("no modules loaded (need at least the main module)") } // Apply default project mounts. diff --git a/config/allconfig/load.go b/config/allconfig/load.go index 84419cb2e..16e2019cf 100644 --- a/config/allconfig/load.go +++ b/config/allconfig/load.go @@ -64,7 +64,7 @@ func LoadConfig(d ConfigSourceDescriptor) (*Configs, error) { return nil, fmt.Errorf("failed to create config from result: %w", err) } - moduleConfig, modulesClient, err := l.loadModules(configs) + moduleConfig, modulesClient, err := l.loadModules(configs, d.IgnoreModuleDoesNotExist) if err != nil { return nil, fmt.Errorf("failed to load modules: %w", err) } @@ -116,6 +116,9 @@ type ConfigSourceDescriptor struct { // Defaults to os.Environ if not set. Environ []string + + // If set, this will be used to ignore the module does not exist error. + IgnoreModuleDoesNotExist bool } func (d ConfigSourceDescriptor) configFilenames() []string { @@ -453,7 +456,7 @@ func (l *configLoader) loadConfigMain(d ConfigSourceDescriptor) (config.LoadConf return res, l.ModulesConfig, err } -func (l *configLoader) loadModules(configs *Configs) (modules.ModulesConfig, *modules.Client, error) { +func (l *configLoader) loadModules(configs *Configs, ignoreModuleDoesNotExist bool) (modules.ModulesConfig, *modules.Client, error) { bcfg := configs.LoadingInfo.BaseConfig conf := configs.Base workingDir := bcfg.WorkingDir @@ -487,17 +490,18 @@ func (l *configLoader) loadModules(configs *Configs) (modules.ModulesConfig, *mo } modulesClient := modules.NewClient(modules.ClientConfig{ - Fs: l.Fs, - Logger: l.Logger, - Exec: ex, - HookBeforeFinalize: hook, - WorkingDir: workingDir, - ThemesDir: themesDir, - PublishDir: publishDir, - Environment: l.Environment, - CacheDir: conf.Caches.CacheDirModules(), - ModuleConfig: conf.Module, - IgnoreVendor: ignoreVendor, + Fs: l.Fs, + Logger: l.Logger, + Exec: ex, + HookBeforeFinalize: hook, + WorkingDir: workingDir, + ThemesDir: themesDir, + PublishDir: publishDir, + Environment: l.Environment, + CacheDir: conf.Caches.CacheDirModules(), + ModuleConfig: conf.Module, + IgnoreVendor: ignoreVendor, + IgnoreModuleDoesNotExist: ignoreModuleDoesNotExist, }) moduleConfig, err := modulesClient.Collect() |