diff options
author | Joe Mooring <[email protected]> | 2023-07-11 13:01:52 -0700 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-07-13 15:19:04 +0200 |
commit | f1886f8c379851c45f947efd2a10424cddd338c5 (patch) | |
tree | 4a86c899c86e2765164a1b85f4991a021aae25d9 | |
parent | 5bec50838c9d5ce097a82d91b7924f22453de1a9 (diff) | |
download | hugo-f1886f8c379851c45f947efd2a10424cddd338c5.tar.gz hugo-f1886f8c379851c45f947efd2a10424cddd338c5.zip |
js: Pass tsconfig.json to esBuild
Note that esBuild only inspects/honors certain fields.
See https://esbuild.github.io/content-types/#tsconfig-json.
Fixes #11232
-rw-r--r-- | resources/resource_transformers/js/build.go | 1 | ||||
-rw-r--r-- | resources/resource_transformers/js/integration_test.go | 49 |
2 files changed, 40 insertions, 10 deletions
diff --git a/resources/resource_transformers/js/build.go b/resources/resource_transformers/js/build.go index 949cd4fcb..aa802d81e 100644 --- a/resources/resource_transformers/js/build.go +++ b/resources/resource_transformers/js/build.go @@ -86,6 +86,7 @@ func (t *buildTransformation) Transform(ctx *resources.ResourceTransformationCtx opts.resolveDir = t.c.rs.Cfg.BaseConfig().WorkingDir // where node_modules gets resolved opts.contents = string(src) opts.mediaType = ctx.InMediaType + opts.tsConfig = t.c.rs.ResolveJSConfigFile("tsconfig.json") buildOptions, err := toBuildOptions(opts) if err != nil { diff --git a/resources/resource_transformers/js/integration_test.go b/resources/resource_transformers/js/integration_test.go index 023569b8d..0e311107b 100644 --- a/resources/resource_transformers/js/integration_test.go +++ b/resources/resource_transformers/js/integration_test.go @@ -48,7 +48,7 @@ export function hello3() { -- layouts/index.html -- {{ $js := resources.Get "js/main.js" | js.Build }} JS Content:{{ $js.Content }}:End: - + ` c.Run("Basic", func(c *qt.C) { @@ -90,9 +90,9 @@ disableKinds=["page", "section", "taxonomy", "term", "sitemap", "robotsTXT"] path="github.com/gohugoio/hugoTestProjectJSModImports" -- go.mod -- module github.com/gohugoio/tests/testHugoModules - + go 1.16 - + require github.com/gohugoio/hugoTestProjectJSModImports v0.10.0 // indirect -- package.json -- { @@ -100,7 +100,7 @@ require github.com/gohugoio/hugoTestProjectJSModImports v0.10.0 // indirect "date-fns": "^2.16.1" } } - + ` b := hugolib.NewIntegrationTestBuilder( hugolib.IntegrationTestConfig{ @@ -142,7 +142,7 @@ console.log("included"); -- assets/js/main.js -- import "./included"; import { toCamelCase } from "to-camel-case"; - + console.log("main"); console.log("To camel:", toCamelCase("space case")); -- assets/js/myjsx.jsx -- @@ -222,7 +222,7 @@ import { hello1, hello2 } from './util1'; hello1(); hello2(); -- assets/js/util1.js -- -/* Some +/* Some comments. */ import { hello3 } from './util2'; @@ -239,7 +239,7 @@ export function hello3() { -- layouts/index.html -- {{ $js := resources.Get "js/main.js" | js.Build }} JS Content:{{ $js.Content }}:End: - + ` c.Run("Import from main not found", func(c *qt.C) { @@ -292,9 +292,9 @@ import 'imp3/foo.js'; }).Build() expected := ` -IMPORT_SRC_DIR:imp1/index.js +IMPORT_SRC_DIR:imp1/index.js IMPORT_SRC_DIR:imp2/index.ts -IMPORT_SRC_DIR:imp3/foo.ts +IMPORT_SRC_DIR:imp3/foo.ts ` expected = strings.ReplaceAll(expected, "IMPORT_SRC_DIR", importSrcDir) @@ -340,7 +340,36 @@ console.log("Hello 2"); License util1 License util2 Main license - + `) } + +// Issue #11232 +func TestTypeScriptExperimentalDecorators(t *testing.T) { + t.Parallel() + files := ` +-- hugo.toml -- +disableKinds = ['RSS','sitemap','taxonomy','term'] +-- tsconfig.json -- +{ + "compilerOptions": { + "experimentalDecorators": true, + } +} +-- assets/ts/main.ts -- +function addFoo(target: any) {target.prototype.foo = 'bar'} +@addFoo +class A {} +-- layouts/index.html -- +{{ $opts := dict "target" "es2020" "targetPath" "js/main.js" }} +{{ (resources.Get "ts/main.ts" | js.Build $opts).Publish }} +` + b := hugolib.NewIntegrationTestBuilder( + hugolib.IntegrationTestConfig{ + T: t, + NeedsOsFS: true, + TxtarString: files, + }).Build() + b.AssertFileContent("public/js/main.js", "__decorateClass") +} |