github.com/evanw/esbuild@v0.21.4/internal/helpers/path.go (about) 1 package helpers 2 3 import "strings" 4 5 func IsInsideNodeModules(path string) bool { 6 for { 7 // This is written in a platform-independent manner because it's run on 8 // user-specified paths which can be arbitrary non-file-system things. So 9 // for example Windows paths may end up being used on Unix or URLs may end 10 // up being used on Windows. Be consistently agnostic to which kind of 11 // slash is used on all platforms. 12 slash := strings.LastIndexAny(path, "/\\") 13 if slash == -1 { 14 return false 15 } 16 dir, base := path[:slash], path[slash+1:] 17 if base == "node_modules" { 18 return true 19 } 20 path = dir 21 } 22 }