Skip to content

Commit

Permalink
revert and fix 0865e8c
Browse files Browse the repository at this point in the history
  • Loading branch information
Aylur committed Nov 11, 2024
1 parent fe56428 commit 9f46c91
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
13 changes: 10 additions & 3 deletions cmd/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import (
"github.com/spf13/cobra"
)

var tsconfig string
var (
tsconfig string
workingDir string
)

var bundleCommand = &cobra.Command{
Use: "bundle [entryfile] [outfile]",
Expand All @@ -31,14 +34,18 @@ var bundleCommand = &cobra.Command{
}

if info.IsDir() {
lib.Bundle(getAppEntry(path), outfile, tsconfig)
lib.Bundle(getAppEntry(path), outfile, tsconfig, workingDir)
} else {
lib.Bundle(path, outfile, tsconfig)
lib.Bundle(path, outfile, tsconfig, workingDir)
}
},
}

func init() {
f := bundleCommand.Flags()
f.StringVar(&tsconfig, "tsconfig", "", "path to tsconfig.json")

f.StringVar(&workingDir, "cwd", "", `working directory of the bundle
leaving it empty is same as the root directory of the entryfile
this flag is useful when the entryfile is not in the root directory`)
}
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func getAppEntry(dir string) string {

func run(infile string) {
outfile := getOutfile()
lib.Bundle(infile, outfile, tsconfig)
lib.Bundle(infile, outfile, tsconfig, "")

if gtk4 {
os.Setenv("LD_PRELOAD", gtk4LayerShell)
Expand Down
33 changes: 22 additions & 11 deletions lib/esbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,19 @@ var blpPlugin api.Plugin = api.Plugin{
// svg loader
// other css preproceccors
// http plugin with caching
func Bundle(infile, outfile, tsconfig string) {
func Bundle(infile, outfile, tsconfig, cwd string) {
srcdir := filepath.Dir(infile)

if cwd == "" {
cwd = srcdir
} else {
var err error
cwd, err = filepath.Abs(cwd)
if err != nil {
Err(err)
}
}

if tsconfig != "" {
// if a tsconfig file is specified use that
path, err := filepath.Abs(tsconfig)
Expand All @@ -138,8 +148,8 @@ func Bundle(infile, outfile, tsconfig string) {
}

tsconfig = string(data)

} else if FileExists("tsconfig.json") {
// check cwd for tsconfig
cwd, err := os.Getwd()
if err != nil {
Err(err)
Expand All @@ -152,15 +162,16 @@ func Bundle(infile, outfile, tsconfig string) {
}

result := api.Build(api.BuildOptions{
Color: api.ColorAlways,
LogLevel: api.LogLevelWarning,
EntryPoints: []string{infile},
Bundle: true,
Outfile: outfile,
Format: api.FormatESModule,
Platform: api.PlatformNeutral,
TsconfigRaw: tsconfig,
Write: true,
Color: api.ColorAlways,
LogLevel: api.LogLevelWarning,
EntryPoints: []string{infile},
Bundle: true,
Outfile: outfile,
Format: api.FormatESModule,
Platform: api.PlatformNeutral,
AbsWorkingDir: cwd,
TsconfigRaw: tsconfig,
Write: true,
Define: map[string]string{
"SRC": fmt.Sprintf(`"%s"`, srcdir),
},
Expand Down

0 comments on commit 9f46c91

Please sign in to comment.