Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
// Package modules provides a client that can be used to manage Hugo Components,
|
2019-07-31 08:36:36 -04:00
|
|
|
// what's referred to as Hugo Modules. Hugo Modules is built on top of Go Modules,
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
// but also supports vendoring and components stored directly in the themes dir.
|
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
2021-06-27 12:00:20 -04:00
|
|
|
"time"
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
"github.com/gohugoio/hugo/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ Module = (*moduleAdapter)(nil)
|
|
|
|
|
|
|
|
type Module interface {
|
|
|
|
|
|
|
|
// Optional config read from the configFilename above.
|
|
|
|
Cfg() config.Provider
|
|
|
|
|
|
|
|
// The decoded module config and mounts.
|
|
|
|
Config() Config
|
|
|
|
|
2021-06-16 13:11:01 -04:00
|
|
|
// Optional configuration filenames (e.g. "/themes/mytheme/config.json").
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
// This will be added to the special configuration watch list when in
|
|
|
|
// server mode.
|
2021-06-16 13:11:01 -04:00
|
|
|
ConfigFilenames() []string
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
|
|
|
|
// Directory holding files for this module.
|
|
|
|
Dir() string
|
|
|
|
|
|
|
|
// This module is disabled.
|
|
|
|
Disabled() bool
|
|
|
|
|
|
|
|
// Returns whether this is a Go Module.
|
|
|
|
IsGoMod() bool
|
|
|
|
|
|
|
|
// Any directory remappings.
|
|
|
|
Mounts() []Mount
|
|
|
|
|
|
|
|
// In the dependency tree, this is the first module that defines this module
|
|
|
|
// as a dependency.
|
|
|
|
Owner() Module
|
|
|
|
|
|
|
|
// Returns the path to this module.
|
|
|
|
// This will either be the module path, e.g. "github.com/gohugoio/myshortcodes",
|
|
|
|
// or the path below your /theme folder, e.g. "mytheme".
|
|
|
|
Path() string
|
|
|
|
|
|
|
|
// Replaced by this module.
|
|
|
|
Replace() Module
|
|
|
|
|
|
|
|
// Returns whether Dir points below the _vendor dir.
|
|
|
|
Vendor() bool
|
|
|
|
|
|
|
|
// The module version.
|
|
|
|
Version() string
|
|
|
|
|
2021-06-27 12:00:20 -04:00
|
|
|
// Time version was created.
|
2021-06-27 12:06:52 -04:00
|
|
|
Time() time.Time
|
2021-06-27 12:00:20 -04:00
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
// Whether this module's dir is a watch candidate.
|
|
|
|
Watch() bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type Modules []Module
|
|
|
|
|
|
|
|
type moduleAdapter struct {
|
|
|
|
path string
|
|
|
|
dir string
|
|
|
|
version string
|
|
|
|
vendor bool
|
|
|
|
disabled bool
|
|
|
|
projectMod bool
|
|
|
|
owner Module
|
|
|
|
|
|
|
|
mounts []Mount
|
|
|
|
|
2021-06-16 13:11:01 -04:00
|
|
|
configFilenames []string
|
|
|
|
cfg config.Provider
|
|
|
|
config Config
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
|
|
|
|
// Set if a Go module.
|
|
|
|
gomod *goModule
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *moduleAdapter) Cfg() config.Provider {
|
|
|
|
return m.cfg
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *moduleAdapter) Config() Config {
|
|
|
|
return m.config
|
|
|
|
}
|
|
|
|
|
2021-06-16 13:11:01 -04:00
|
|
|
func (m *moduleAdapter) ConfigFilenames() []string {
|
|
|
|
return m.configFilenames
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *moduleAdapter) Dir() string {
|
|
|
|
// This may point to the _vendor dir.
|
|
|
|
if !m.IsGoMod() || m.dir != "" {
|
|
|
|
return m.dir
|
|
|
|
}
|
|
|
|
return m.gomod.Dir
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *moduleAdapter) Disabled() bool {
|
|
|
|
return m.disabled
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *moduleAdapter) IsGoMod() bool {
|
|
|
|
return m.gomod != nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *moduleAdapter) Mounts() []Mount {
|
|
|
|
return m.mounts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *moduleAdapter) Owner() Module {
|
|
|
|
return m.owner
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *moduleAdapter) Path() string {
|
|
|
|
if !m.IsGoMod() || m.path != "" {
|
|
|
|
return m.path
|
|
|
|
}
|
|
|
|
return m.gomod.Path
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *moduleAdapter) Replace() Module {
|
|
|
|
if m.IsGoMod() && !m.Vendor() && m.gomod.Replace != nil {
|
|
|
|
return &moduleAdapter{
|
|
|
|
gomod: m.gomod.Replace,
|
|
|
|
owner: m.owner,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *moduleAdapter) Vendor() bool {
|
|
|
|
return m.vendor
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *moduleAdapter) Version() string {
|
|
|
|
if !m.IsGoMod() || m.version != "" {
|
|
|
|
return m.version
|
|
|
|
}
|
|
|
|
return m.gomod.Version
|
|
|
|
}
|
|
|
|
|
2021-06-27 12:06:52 -04:00
|
|
|
func (m *moduleAdapter) Time() time.Time {
|
2021-06-27 12:00:20 -04:00
|
|
|
if !m.IsGoMod() || m.gomod.Time == nil {
|
2021-06-27 12:06:52 -04:00
|
|
|
return time.Time{}
|
2021-06-27 12:00:20 -04:00
|
|
|
}
|
|
|
|
|
2021-06-27 12:06:52 -04:00
|
|
|
return *m.gomod.Time
|
|
|
|
|
2021-06-27 12:00:20 -04:00
|
|
|
}
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
func (m *moduleAdapter) Watch() bool {
|
|
|
|
if m.Owner() == nil {
|
|
|
|
// Main project
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if !m.IsGoMod() {
|
|
|
|
// Module inside /themes
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.Replace() != nil {
|
|
|
|
// Version is not set when replaced by a local folder.
|
|
|
|
return m.Replace().Version() == ""
|
|
|
|
}
|
|
|
|
|
2022-12-19 11:49:45 -05:00
|
|
|
// Any module set up in a workspace file will have Indirect set to false.
|
|
|
|
// That leaves modules inside the read-only module cache.
|
|
|
|
return !m.gomod.Indirect
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
}
|