air-verse / air

☁️ Live reload for Go apps
GNU General Public License v3.0
17.47k stars 800 forks source link

only watch file in root folder #197

Open iqbaldp78 opened 2 years ago

iqbaldp78 commented 2 years ago

i have project directory like this :

cmd
----app
--------main.go
commands.go
.env

my .air.toml

# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root
root = "." 
tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o tmp/server ./cmd/app/."

# Binary file yields from `cmd`.
bin = "tmp"

# Customize binary.
# This is how you start to run your application. Since my application will works like CLI, so to run it, like to make a CLI call.
full_bin = "APP_ENV=dev APP_USER=air ./tmp/server"

# This log file places in your tmp_dir.
log = "air_errors.log"

# Watch these filename extensions.
include_ext = ["go","tpl", "tmpl", "html", "yml", "toml","env"]

# Ignore these filename extensions or directories.
exclude_dir = []

# Watch these directories if you specified.
include_dir = []

# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms

# Exclude specific regular expressions.
# exclude_regex = ["_test.go"]

# Stop running old binary when build errors occur.
stop_on_error = true

# Send Interrupt signal before killing process (windows does not support this feature)
send_interrupt = false

# Delay after sending Interrupt signal
kill_delay = 500 # ms

[log]
# Show log time
time = true

[misc]
# Delete tmp directory on exit
clean_on_exit = true

when try to save .env file its reload as well, but when i try to save main.go file under dir cmd/app/main.go . does not work ..

can someone help me ??

chihiros commented 2 years ago

When you start Docker, does cmd/* show the watching log in the terminal?

sample: watching *** image

iqbaldp78 commented 2 years ago

yes log

my terminal @SuzurikawaChihiro

cozzbie commented 2 years ago

Interesting. The reverse here is the case for me. Air does not track root changes but does quite fine once files are in a sub directory.

rochinworks commented 2 years ago

I have a similar problem and tried "*", "." but neither worked for root files.

Falldot commented 2 years ago

Hi, I have a similar problem

My project directory: image

my .air.toml:

# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

root = "."
tmp_dir = "tmp"

[build]
  # cmd = "make build-api"
  cmd = "go build -o ./tmp/main ./cmd/user_service/main.go"
  bin = "tmp/main"
  full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
  include_ext = ["go", "tpl", "tmpl", "html", "css", "js", "env", "yaml"]
  exclude_dir = ["tmp", "assets", "vendor", "bin", "build", "deploy"]
  include_dir = []
  exclude_regex = ["_test.go"]
  exclude_file = []
  exclude_unchanged = true
  log = "air.log"
  args_bin = []
  stop_on_error = true
  send_interrupt = false
  delay = 1000
  kill_delay = 500

[log]
  time = false

[color]
  main = "magenta"
  watcher = "cyan"
  build = "yellow"
  runner = "green"

[misc]
  clean_on_exit = false

When I save any file in the root, air rebuilds successfully, but ignores all subdirectories and files in them. Writing directories in the include_dir field does not solve this problem. Use WSL2 Ubuntu 22.04.

k-frankov commented 1 year ago

Same here, created simple Fiber app, it works if 'main.go' is in root directory, but after I moved it to 'src' directory - it says 'no Go files in {paht to root directory}'. Include_dir didn't help

dhritimanCognitive commented 1 year ago

@Falldot Did it work for you ? I am facing the same problem

PickledDev commented 1 year ago

This apparently is still a thing. I have a project where the go files are in ./cmd/web. Air refuses to find them. I eventually moved all the files into the root directory to get around this.

watching . watching cmd watching cmd/api watching cmd/web watching cmd/web/templates watching internal !exclude tmp building... no Go files in {/Users/[my-name]/Development/[project-name]} failed to build, error: exit status 1

infinite-sea commented 12 months ago

@PickledDev I have a similar setup, and it works for me. In your build section, are you using the following ?

  cmd = "go build -o ./tmp/main ./cmd/web/." (with period at the end, not main.go,etc)
PickledDev commented 11 months ago

If I run the build command as listed on the line in the terminal, it will compile. Only Air doesn't want to.

I have that but still no go (pun not intended).

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./tmp/main ./cmd/web/."
# Binary file yields from `cmd`.
bin = "/tmp/main"

My file structure is: Screenshot 2023-10-07 at 09 10 34

PickledDev commented 11 months ago

I also noticed it says it is watching my templates folder, but it does not see changes there when I make them. I have verified that the include line is watching the correct extensions

include_ext = ["go", "tpl", "tmpl", "html", "gohtml"]
PickledDev commented 11 months ago

I've made a little progress. As a test I decided that the wording "No Go files..." was a clue to the problem. I do not have any go files at the root of my project, they are all in ./cmd/web at the moment. So I created a dummy.go file with a function that just had a comment in it. Ran air, and it compiled and stopped complaining.

Now I have a new problem; the executable created in ./tmp does not have execute permissions. I should probably note I am an a Mac running Sonoma.

niraj-khatiwada commented 10 months ago

Make sure to add http server main.go file in cmd directory of air.toml

image

songlim327 commented 9 months ago

I have a similar issue, only changing main.go in root folder will trigger rebuild. Modifying files in subfolders will not trigger the rebuild.

I run air with default config, no custom config file pass in. When run, it shows that it is watching all the subdirectories. image

muhhae commented 8 months ago

Got similar problem. Air exclude cmd and internal folder and i dont know why. log:

!exclude cmd
!exclude internal
!exclude node_modules
!exclude tmp

config:

root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "tmp/main.exe"
cmd = "go build -o ./tmp/main.exe ./cmd/app/."
delay = 1000
exclude_dir = ["tmp", "node_modules"]
exclude_file = []
exclude_regex = ["_test.go", "_temp.go"]
exclude_unchanged = true
follow_symlink = true
full_bin = ""
include_dir = ["**"]
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = [
  "templ generate",
  "npx tailwindcss -i ./internal/style/style.css -o ./internal/static/style/output.css",
]
rerun = true
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false

[misc]
clean_on_exit = false

[screen]
clear_on_rebuild = false
keep_scroll = true
art3xias23 commented 5 months ago

As mentioned here

and here

setting poll=true in the build section works. This is at least true for me running WSL2 Debian on Windows 10

This is my working .air.toml config for reference


root = "."
tmp_dir = "tmp"

[build]
  bin = "./tmp/main"
  cmd = "templ generate && go build -o ./tmp/main ."
  delay = 1000
  exclude_regex = [".*_templ.go"]
  exclude_dir = ["assets", "tmp", "vendor", "node_modules"]
  include_dir = []
  exclude_file = []
  exclude_unchanged = false
  follow_symlink = false
  full_bin = ""
  poll=true

  include_ext = ["go", "tpl", "tmpl", "templ", "html"]
  kill_delay = "0s"
  log = "build-errors.log"
  send_interrupt = false
  stop_on_error = true

[color]
  app = ""
  build = "yellow"
  main = "magenta"
  runner = "green"
  watcher = "cyan"

[log]
  time = false

[misc]
  clean_on_exit = false 
konstantinoskolios commented 5 months ago

This is my file structure using Windows 11 WSL Ubuntu:

image

And this is my air.toml: root = "."

Running air at the root of the project:

image

Edit the air.toml: root = "./cmd"

Still the same error:

image

if i delete the air.toml and run the air command at ./cmd:

kkolios@kkolios-pc:/mnt/c/Users/kkolios/Desktop/my-beatiful-cv/cmd$ air


/ /\ | | | |) //--\ || || _ v1.51.0, built with Go go1.22.2

watching . watching docs watching internal watching internal/models watching internal/repositories watching internal/services watching internal/utils watching tests watching tests/models watching tests/repositories watching tests/services watching tests/utils !exclude tmp building... running...


/ /__/ / / _// / \/ \ //\////\/ v4.12.0 High performance, minimalist Go web framework https://echo.labstack.com ____O/___ O\ ⇨ http server started on [::]:9999

it's working but this not the expected behavior, i cannot find a way to configure the air.toml is like WSL ignore the configurations, any related problem ?

Gautamvaishnav-git commented 4 months ago

As mentioned here

and here

setting poll=true in the build section works. This is at least true for me running WSL2 Debian on Windows 10

This is my working .air.toml config for reference


root = "."
tmp_dir = "tmp"

[build]
  bin = "./tmp/main"
  cmd = "templ generate && go build -o ./tmp/main ."
  delay = 1000
  exclude_regex = [".*_templ.go"]
  exclude_dir = ["assets", "tmp", "vendor", "node_modules"]
  include_dir = []
  exclude_file = []
  exclude_unchanged = false
  follow_symlink = false
  full_bin = ""
  poll=true

  include_ext = ["go", "tpl", "tmpl", "templ", "html"]
  kill_delay = "0s"
  log = "build-errors.log"
  send_interrupt = false
  stop_on_error = true

[color]
  app = ""
  build = "yellow"
  main = "magenta"
  runner = "green"
  watcher = "cyan"

[log]
  time = false

[misc]
  clean_on_exit = false 

it worked for me

amanzeniq commented 4 months ago

Make sure to add http server main.go file in cmd directory of air.toml

image

this works for me, thanks