mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
resources/js: Fix some import discrepancies between Hugo and ESBuild
This fixes the cases where ```js import 'imp2/index.js'; import 'imp3/foo.js'; ``` And these files lives in `assets` as: ``` imp2/index.ts imp3/foo.ts ``` Fixes #10527
This commit is contained in:
@@ -259,3 +259,47 @@ JS Content:{{ $js.Content }}:End:
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// See issue 10527.
|
||||
func TestImportHugoVsESBuild(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
for _, importSrcDir := range []string{"node_modules", "assets"} {
|
||||
c.Run(importSrcDir, func(c *qt.C) {
|
||||
files := `
|
||||
-- IMPORT_SRC_DIR/imp1/index.js --
|
||||
console.log("IMPORT_SRC_DIR:imp1/index.js");
|
||||
-- IMPORT_SRC_DIR/imp2/index.ts --
|
||||
console.log("IMPORT_SRC_DIR:imp2/index.ts");
|
||||
-- IMPORT_SRC_DIR/imp3/foo.ts --
|
||||
console.log("IMPORT_SRC_DIR:imp3/foo.ts");
|
||||
-- assets/js/main.js --
|
||||
import 'imp1/index.js';
|
||||
import 'imp2/index.js';
|
||||
import 'imp3/foo.js';
|
||||
-- layouts/index.html --
|
||||
{{ $js := resources.Get "js/main.js" | js.Build }}
|
||||
{{ $js.RelPermalink }}
|
||||
`
|
||||
|
||||
files = strings.ReplaceAll(files, "IMPORT_SRC_DIR", importSrcDir)
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: c,
|
||||
NeedsOsFS: true,
|
||||
TxtarString: files,
|
||||
}).Build()
|
||||
|
||||
expected := `
|
||||
IMPORT_SRC_DIR:imp1/index.js
|
||||
IMPORT_SRC_DIR:imp2/index.ts
|
||||
IMPORT_SRC_DIR:imp3/foo.ts
|
||||
`
|
||||
expected = strings.ReplaceAll(expected, "IMPORT_SRC_DIR", importSrcDir)
|
||||
|
||||
b.AssertFileContent("public/js/main.js", expected)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user