mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 06:00:25 +03:00
postCSS: Improve validation of option 'config'
This commit is contained in:
parent
e08d9af21e
commit
2c36796025
4 changed files with 25 additions and 13 deletions
|
@ -209,19 +209,19 @@ func (b *BaseFs) AbsProjectContentDir(filename string) (string, string, error) {
|
|||
|
||||
// ResolveJSConfigFile resolves the JS-related config file to a absolute
|
||||
// filename. One example of such would be postcss.config.js.
|
||||
func (b *BaseFs) ResolveJSConfigFile(name string) string {
|
||||
func (b *BaseFs) ResolveJSConfigFile(name string) (string, bool) {
|
||||
// First look in assets/_jsconfig
|
||||
fi, err := b.Assets.Fs.Stat(filepath.Join(files.FolderJSConfig, name))
|
||||
if err == nil {
|
||||
return fi.(hugofs.FileMetaInfo).Meta().Filename
|
||||
return fi.(hugofs.FileMetaInfo).Meta().Filename, fi.IsDir()
|
||||
}
|
||||
// Fall back to the work dir.
|
||||
fi, err = b.Work.Stat(name)
|
||||
if err == nil {
|
||||
return fi.(hugofs.FileMetaInfo).Meta().Filename
|
||||
return fi.(hugofs.FileMetaInfo).Meta().Filename, fi.IsDir()
|
||||
}
|
||||
|
||||
return ""
|
||||
return "", false
|
||||
}
|
||||
|
||||
// SourceFilesystems contains the different source file systems. These can be
|
||||
|
|
|
@ -55,7 +55,7 @@ func (c *BuildClient) Build(opts Options) (api.BuildResult, error) {
|
|||
opts.OutDir = c.rs.AbsPublishDir
|
||||
opts.ResolveDir = c.rs.Cfg.BaseConfig().WorkingDir // where node_modules gets resolved
|
||||
opts.AbsWorkingDir = opts.ResolveDir
|
||||
opts.TsConfig = c.rs.ResolveJSConfigFile("tsconfig.json")
|
||||
opts.TsConfig, _ = c.rs.ResolveJSConfigFile("tsconfig.json")
|
||||
assetsResolver := newFSResolver(c.rs.Assets.Fs)
|
||||
|
||||
if err := opts.validate(); err != nil {
|
||||
|
|
|
@ -134,13 +134,19 @@ func (t *babelTransformation) Transform(ctx *resources.ResourceTransformationCtx
|
|||
}
|
||||
|
||||
configFile = filepath.Clean(configFile)
|
||||
isConfigFileDir := false
|
||||
|
||||
// We need an absolute filename to the config file.
|
||||
if !filepath.IsAbs(configFile) {
|
||||
configFile = t.rs.BaseFs.ResolveJSConfigFile(configFile)
|
||||
if configFile == "" && t.options.Config != "" {
|
||||
// Only fail if the user specified config file is not found.
|
||||
return fmt.Errorf("babel config %q not found", configFile)
|
||||
configFile, isConfigFileDir = t.rs.BaseFs.ResolveJSConfigFile(configFile)
|
||||
if t.options.Config != "" {
|
||||
if configFile == "" {
|
||||
// Only fail if the user specified config file is not found.
|
||||
return fmt.Errorf("babel config file %q not found", configFile)
|
||||
}
|
||||
if isConfigFileDir {
|
||||
loggers.Log().Warnf("babel config %q must be a file, not a directory", configFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -157,13 +157,19 @@ func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationC
|
|||
}
|
||||
|
||||
configFile = filepath.Clean(configFile)
|
||||
isConfigFileDir := false
|
||||
|
||||
// We need an absolute filename to the config file.
|
||||
if !filepath.IsAbs(configFile) {
|
||||
configFile = t.rs.BaseFs.ResolveJSConfigFile(configFile)
|
||||
if configFile == "" && options.Config != "" {
|
||||
// Only fail if the user specified config file is not found.
|
||||
return fmt.Errorf("postcss config %q not found", options.Config)
|
||||
configFile, isConfigFileDir = t.rs.BaseFs.ResolveJSConfigFile(configFile)
|
||||
if options.Config != "" {
|
||||
if configFile == "" {
|
||||
// Only fail if the user specified config file is not found.
|
||||
return fmt.Errorf("postcss config directory %q not found", options.Config)
|
||||
}
|
||||
if !isConfigFileDir {
|
||||
loggers.Log().Warnf("postcss config %q must be a directory", options.Config)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue