Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ type Config struct {
Targets map[string]*Target `json:"targets" yaml:"targets"`
// Map of go module names to TypeScript mapping settings
Mappings TypeScriptMappings `json:"mappings" yaml:"mappings"`
// Optional file extension to append to relative TypeScript import paths (e.g. ".js")
TSImportExtension string `json:"tsImportExtension" yaml:"tsImportExtension"`
}

func LoadConfigFile(file string) (conf *Config, err error) {
Expand Down
3 changes: 3 additions & 0 deletions gotsrpc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
},
"mappings": {
"$ref": "#/$defs/TypeScriptMappings"
},
"tsImportExtension": {
"type": "string"
}
},
"additionalProperties": false,
Expand Down
6 changes: 3 additions & 3 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ func deriveCommonJSMapping(conf *config.Config) {
}
}

func relativeFilePath(a, b string) (r string, e error) {
func relativeFilePath(a, b, ext string) (r string, e error) {
r, e = filepath.Rel(path.Dir(a), b)
if e != nil {
return
}

r = strings.TrimSuffix(r, ".ts")
r = strings.TrimSuffix(r, ".ts") + ext

return
}
Expand All @@ -304,7 +304,7 @@ func commonJSImports(conf *config.Config, c *codegen.Code, tsFilename string, co
continue
}

relativePath, relativeErr := relativeFilePath(tsFilename, importMapping.Out)
relativePath, relativeErr := relativeFilePath(tsFilename, importMapping.Out, conf.TSImportExtension)
if relativeErr != nil {
fmt.Println("can not derive a relative path between", tsFilename, "and", importMapping.Out, relativeErr)
os.Exit(1)
Expand Down
Loading