summaryrefslogtreecommitdiffstats
path: root/hugolib/hugo_modules_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-09-09 22:31:43 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-09-13 20:55:29 +0200
commit85ba9bfffba9bfd0b095cb766f72700d4c211e31 (patch)
tree43b66efaafe4cb804234ca7273873ab949305799 /hugolib/hugo_modules_test.go
parent9df60b62f9c4e36a269f0c6e9a69bee9dc691031 (diff)
Add "hugo mod npm pack"
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into: ``` assets/_jsconfig ´`` These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename. But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific. This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above. Fixes #7644 Fixes #7656 Fixes #7675
Diffstat (limited to 'hugolib/hugo_modules_test.go')
-rw-r--r--hugolib/hugo_modules_test.go159
1 files changed, 157 insertions, 2 deletions
diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go
index 0ed4fceb0..c3358a0c2 100644
--- a/hugolib/hugo_modules_test.go
+++ b/hugolib/hugo_modules_test.go
@@ -22,6 +22,8 @@ import (
"testing"
"time"
+ "github.com/gohugoio/hugo/modules/npm"
+
"github.com/gohugoio/hugo/common/loggers"
"github.com/spf13/afero"
@@ -38,7 +40,6 @@ import (
"github.com/spf13/viper"
)
-// https://github.com/gohugoio/hugo/issues/6730
func TestHugoModulesVariants(t *testing.T) {
if !isCI() {
t.Skip("skip (relative) long running modules test when running locally")
@@ -60,8 +61,10 @@ path="github.com/gohugoio/hugoTestModule2"
newTestBuilder := func(t testing.TB, moduleOpts string) (*sitesBuilder, func()) {
b := newTestSitesBuilder(t)
- workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-modules-variants")
+ tempDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-modules-variants")
b.Assert(err, qt.IsNil)
+ workingDir := filepath.Join(tempDir, "myhugosite")
+ b.Assert(os.MkdirAll(workingDir, 0777), qt.IsNil)
b.Fs = hugofs.NewDefault(viper.New())
b.WithWorkingDir(workingDir).WithConfigFile("toml", createConfig(workingDir, moduleOpts))
b.WithTemplates(
@@ -129,6 +132,158 @@ JS imported in module: |
`)
})
+ t.Run("Create package.json", func(t *testing.T) {
+
+ b, clean := newTestBuilder(t, "")
+ defer clean()
+
+ b.WithSourceFile("package.json", `{
+ "name": "mypack",
+ "version": "1.2.3",
+ "scripts": {},
+ "dependencies": {
+ "nonon": "error"
+ }
+}`)
+
+ b.WithSourceFile("package.hugo.json", `{
+ "name": "mypack",
+ "version": "1.2.3",
+ "scripts": {},
+ "dependencies": {
+ "foo": "1.2.3"
+ },
+ "devDependencies": {
+ "postcss-cli": "7.8.0",
+ "tailwindcss": "1.8.0"
+
+ }
+}`)
+
+ b.Build(BuildCfg{})
+ b.Assert(npm.Pack(b.H.BaseFs.SourceFs, b.H.BaseFs.Assets.Dirs), qt.IsNil)
+
+ b.AssertFileContentFn("package.json", func(s string) bool {
+ return s == `{
+ "comments": {
+ "dependencies": {
+ "foo": "project",
+ "react-dom": "github.com/gohugoio/hugoTestModule2"
+ },
+ "devDependencies": {
+ "@babel/cli": "github.com/gohugoio/hugoTestModule2",
+ "@babel/core": "github.com/gohugoio/hugoTestModule2",
+ "@babel/preset-env": "github.com/gohugoio/hugoTestModule2",
+ "postcss-cli": "project",
+ "tailwindcss": "project"
+ }
+ },
+ "dependencies": {
+ "foo": "1.2.3",
+ "react-dom": "^16.13.1"
+ },
+ "devDependencies": {
+ "@babel/cli": "7.8.4",
+ "@babel/core": "7.9.0",
+ "@babel/preset-env": "7.9.5",
+ "postcss-cli": "7.8.0",
+ "tailwindcss": "1.8.0"
+ },
+ "name": "mypack",
+ "scripts": {},
+ "version": "1.2.3"
+}`
+ })
+ })
+
+ t.Run("Create package.json, no default", func(t *testing.T) {
+
+ b, clean := newTestBuilder(t, "")
+ defer clean()
+
+ b.WithSourceFile("package.json", `{
+ "name": "mypack",
+ "version": "1.2.3",
+ "scripts": {},
+ "dependencies": {
+ "moo": "1.2.3"
+ }
+}`)
+
+ b.Build(BuildCfg{})
+ b.Assert(npm.Pack(b.H.BaseFs.SourceFs, b.H.BaseFs.Assets.Dirs), qt.IsNil)
+
+ b.AssertFileContentFn("package.json", func(s string) bool {
+ return s == `{
+ "comments": {
+ "dependencies": {
+ "moo": "project",
+ "react-dom": "github.com/gohugoio/hugoTestModule2"
+ },
+ "devDependencies": {
+ "@babel/cli": "github.com/gohugoio/hugoTestModule2",
+ "@babel/core": "github.com/gohugoio/hugoTestModule2",
+ "@babel/preset-env": "github.com/gohugoio/hugoTestModule2",
+ "postcss-cli": "github.com/gohugoio/hugoTestModule2",
+ "tailwindcss": "github.com/gohugoio/hugoTestModule2"
+ }
+ },
+ "dependencies": {
+ "moo": "1.2.3",
+ "react-dom": "^16.13.1"
+ },
+ "devDependencies": {
+ "@babel/cli": "7.8.4",
+ "@babel/core": "7.9.0",
+ "@babel/preset-env": "7.9.5",
+ "postcss-cli": "7.1.0",
+ "tailwindcss": "1.2.0"
+ },
+ "name": "mypack",
+ "scripts": {},
+ "version": "1.2.3"
+}`
+ })
+ })
+
+ t.Run("Create package.json, no default, no package.json", func(t *testing.T) {
+
+ b, clean := newTestBuilder(t, "")
+ defer clean()
+
+ b.Build(BuildCfg{})
+ b.Assert(npm.Pack(b.H.BaseFs.SourceFs, b.H.BaseFs.Assets.Dirs), qt.IsNil)
+
+ b.AssertFileContentFn("package.json", func(s string) bool {
+ return s == `{
+ "comments": {
+ "dependencies": {
+ "react-dom": "github.com/gohugoio/hugoTestModule2"
+ },
+ "devDependencies": {
+ "@babel/cli": "github.com/gohugoio/hugoTestModule2",
+ "@babel/core": "github.com/gohugoio/hugoTestModule2",
+ "@babel/preset-env": "github.com/gohugoio/hugoTestModule2",
+ "postcss-cli": "github.com/gohugoio/hugoTestModule2",
+ "tailwindcss": "github.com/gohugoio/hugoTestModule2"
+ }
+ },
+ "dependencies": {
+ "react-dom": "^16.13.1"
+ },
+ "devDependencies": {
+ "@babel/cli": "7.8.4",
+ "@babel/core": "7.9.0",
+ "@babel/preset-env": "7.9.5",
+ "postcss-cli": "7.1.0",
+ "tailwindcss": "1.2.0"
+ },
+ "name": "myhugosite",
+ "version": "0.1.0"
+}`
+ })
+ })
+
}
// TODO(bep) this fails when testmodBuilder is also building ...