# go list should skip 'ignore' directives with respect to module boundaries.
# See golang.org/issue/42965

env ROOT=$WORK${/}gopath${/}src

# Lists all packages known to the Go toolchain.
# Since go list already does not traverse into other modules found in
# subdirectories, it should only ignore the root node_modules.
go list -x all
stdout 'example$'
stdout 'example/depA'
stderr 'ignoring directory '$ROOT''${/}'node_modules'
! stderr 'ignoring directory '$ROOT''${/}'depA'${/}'node_modules'

# Lists all packages within the current Go module.
# Since go list already does not traverse into other modules found in
# subdirectories, it should only ignore the root node_modules.
go list -x ./...
stdout 'example$'
stderr 'ignoring directory '$ROOT''${/}'node_modules'
! stderr 'ignoring directory '$ROOT''${/}'depA'${/}'node_modules'

# Lists all packages belonging to the module whose import path starts with
# example.
# In this case, go list will traverse into each module that starts with example.
# So it should ignore the root node_modules and the subdirectories' node_modules.
go list -x example/...
stdout 'example$'
stdout 'example/depA'
stderr 'ignoring directory '$ROOT''${/}'node_modules'
stderr 'ignoring directory '$ROOT''${/}'depA'${/}'node_modules'

# Entering the submodule should now cause go list to ignore depA/node_modules.
cd depA
go list -x all
stdout 'example/depA'
stderr 'ignoring directory '$ROOT''${/}'depA'${/}'node_modules'
! stderr 'ignoring directory '$ROOT''${/}'node_modules'

go list -x ./...
stdout 'example/depA'
stderr 'ignoring directory '$ROOT''${/}'depA'${/}'node_modules'
! stderr 'ignoring directory '$ROOT''${/}'node_modules'

-- depA/go.mod --
module example/depA

go 1.24
ignore ./node_modules
-- depA/depA.go --
package depA

const Foo = "This is Foo!"
-- depA/node_modules/some_pkg/index.js --
console.log("This should be ignored!");
-- node_modules/some_pkg/index.js --
console.log("This should be ignored!");
-- go.mod --
module example

go 1.24

ignore ./node_modules
require example/depA v1.0.0
replace example/depA => ./depA

-- main.go --
package main
import (
        "fmt"
        "example/depA"
)
func main() {
        fmt.Println("test")
        fmt.Println(depA.Foo)
}
