From e363964f2fcbeabe4264eaa9d7f803c9989ad096 Mon Sep 17 00:00:00 2001 From: Bjørn Erik Pedersen Date: Thu, 19 Sep 2024 10:53:39 +0200 Subject: commands: Ignore "module does not exist" errors in hugo mod init Closes #11458 --- config/allconfig/allconfig.go | 2 +- config/allconfig/load.go | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'config/allconfig') 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() -- cgit v1.2.3