Skip to content

Commit 8eded03

Browse files
committed
fix: root directory resolution
1 parent bb963ed commit 8eded03

File tree

5 files changed

+39
-25
lines changed

5 files changed

+39
-25
lines changed

cmd/bundle.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var (
1212
defines []string
1313
usePackage bool
1414
gtkVersion int
15+
workingDir string
1516
)
1617

1718
var bundleCommand = &cobra.Command{
@@ -36,10 +37,11 @@ var bundleCommand = &cobra.Command{
3637
}
3738

3839
opts := lib.BundleOpts{
39-
Outfile: outfile,
40-
UsePackage: usePackage,
41-
Defines: defines,
42-
GtkVersion: gtkVersion,
40+
Outfile: outfile,
41+
UsePackage: usePackage,
42+
Defines: defines,
43+
GtkVersion: gtkVersion,
44+
WorkingDirectory: workingDir,
4345
}
4446

4547
if info.IsDir() {
@@ -54,12 +56,9 @@ var bundleCommand = &cobra.Command{
5456

5557
func init() {
5658
f := bundleCommand.Flags()
59+
f.StringVarP(&workingDir, "root", "r", "", "root directory of the project")
5760
f.StringArrayVarP(&defines, "define", "d", []string{}, "replace global identifiers with constant expressions")
5861
f.BoolVarP(&usePackage, "package", "p", false, "use astal package as defined in package.json")
5962
f.IntVar(&gtkVersion, "gtk", 3, "gtk version")
6063
f.MarkHidden("gtk")
61-
62-
f.String("src", "", "source directory of the bundle")
63-
f.MarkHidden("src")
64-
f.MarkDeprecated("src", `use cd /path/to/src && bundle --define="SRC='/path/to/src'"`)
6564
}

cmd/run.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ var runCommand = &cobra.Command{
3535
}
3636

3737
if info.IsDir() {
38-
run(getAppEntry(path))
38+
run(getAppEntry(path), "")
3939
} else {
40-
run(path)
40+
run(path, "")
4141
}
4242

4343
} else {
44-
run(getAppEntry(targetDir))
44+
run(getAppEntry(targetDir), targetDir)
4545
}
4646
},
4747
}
@@ -107,19 +107,20 @@ func logging() (io.Writer, io.Writer, *os.File) {
107107
return io.MultiWriter(os.Stdout, file), io.MultiWriter(os.Stderr, file), file
108108
}
109109

110-
func run(infile string) {
110+
func run(infile string, rootdir string) {
111111
gtk := 3
112112
if gtk4 {
113113
gtk = 4
114114
}
115115

116116
outfile := getOutfile()
117117
lib.Bundle(lib.BundleOpts{
118-
Infile: infile,
119-
Outfile: outfile,
120-
Defines: defines,
121-
UsePackage: usePackage,
122-
GtkVersion: gtk,
118+
Infile: infile,
119+
Outfile: outfile,
120+
Defines: defines,
121+
UsePackage: usePackage,
122+
GtkVersion: gtk,
123+
WorkingDirectory: rootdir,
123124
})
124125

125126
if gtk4 {

docs/guide/bundling.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Flags:
2121
-d, --define stringArray replace global identifiers with constant expressions
2222
-h, --help help for bundle
2323
-p, --package use astal package as defined in package.json
24+
-r, --root string root directory of the project
2425
```
2526

2627
Currently there are 3 builtin plugins.
@@ -209,6 +210,7 @@ a good practice would be to:
209210
find_program('ags'),
210211
'bundle',
211212
'--define', 'DATADIR="' + pkgdatadir + '"',
213+
'--root', meson.project_source_root(),
212214
meson.project_source_root() / 'app.ts',
213215
meson.project_name(),
214216
],
@@ -255,6 +257,7 @@ custom_target(
255257
command: [
256258
find_program('ags'),
257259
'bundle',
260+
'--root', meson.project_source_root(),
258261
meson.project_source_root() / 'app.ts',
259262
main,
260263
],

lib/esbuild.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,19 @@ func sliceToKV(keyValuePairs []string) map[string]string {
131131
}
132132

133133
type BundleOpts struct {
134-
Infile string
135-
Outfile string
136-
UsePackage bool // use astal from package.json
137-
Defines []string
138-
GtkVersion int
134+
Infile string
135+
Outfile string
136+
UsePackage bool // use astal from package.json
137+
Defines []string
138+
GtkVersion int
139+
WorkingDirectory string
139140
}
140141

141142
// TODO: bundle plugins
142143
// svg loader
143144
// other css preproceccors
144145
// http plugin with caching
145146
func Bundle(opts BundleOpts) {
146-
tsconfig := GetTsconfig(Cwd(), opts.GtkVersion)
147147
defines := sliceToKV(opts.Defines)
148148

149149
if _, ok := defines["SRC"]; !ok {
@@ -159,7 +159,6 @@ func Bundle(opts BundleOpts) {
159159
Outfile: opts.Outfile,
160160
Format: api.FormatESModule,
161161
Platform: api.PlatformNeutral,
162-
TsconfigRaw: tsconfig,
163162
Define: defines,
164163
Target: api.ES2022,
165164
Sourcemap: api.SourceMapInline,
@@ -186,6 +185,18 @@ func Bundle(opts BundleOpts) {
186185
},
187186
}
188187

188+
if opts.WorkingDirectory != "" {
189+
dir, err := filepath.Abs(opts.WorkingDirectory)
190+
if err != nil {
191+
Err(err)
192+
}
193+
194+
buildOpts.AbsWorkingDir = dir
195+
buildOpts.TsconfigRaw = GetTsconfig(dir, opts.GtkVersion)
196+
} else {
197+
buildOpts.TsconfigRaw = GetTsconfig(Cwd(), opts.GtkVersion)
198+
}
199+
189200
if !opts.UsePackage {
190201
buildOpts.Alias = map[string]string{
191202
"astal": astalGjs,

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.0
1+
2.2.1

0 commit comments

Comments
 (0)