Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 17 additions & 26 deletions taskfile/node_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type FileNode struct {
}

func NewFileNode(entrypoint, dir string, opts ...NodeOption) (*FileNode, error) {
// Find the entrypoint file
// Find the entrypoint file.
resolvedEntrypoint, err := fsext.Search(entrypoint, dir, DefaultTaskfiles)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
Expand All @@ -27,7 +27,7 @@ func NewFileNode(entrypoint, dir string, opts ...NodeOption) (*FileNode, error)
return nil, err
}

// Resolve the directory
// Resolve the directory.
resolvedDir, err := fsext.ResolveDir(entrypoint, resolvedEntrypoint, dir)
if err != nil {
return nil, err
Expand All @@ -53,38 +53,29 @@ func (node *FileNode) Read() ([]byte, error) {
}

func (node *FileNode) ResolveEntrypoint(entrypoint string) (string, error) {
// If the file is remote, we don't need to resolve the path
// Resolve to entrypoint without adjustment.
if isRemoteEntrypoint(entrypoint) {
return entrypoint, nil
}

path, err := execext.ExpandLiteral(entrypoint)
// Resolve relative to this nodes Taskfile location, or absolute.
entrypoint, err := execext.ExpandLiteral(entrypoint)
if err != nil {
return "", err
}

if filepathext.IsAbs(path) {
return path, nil
}

// NOTE: Uses the directory of the entrypoint (Taskfile), not the current working directory
// This means that files are included relative to one another
entrypointDir := filepath.Dir(node.entrypoint)
return filepathext.SmartJoin(entrypointDir, path), nil
dir := filepath.Dir(node.Location())
return filepathext.SmartJoin(dir, entrypoint), nil
}

func (node *FileNode) ResolveDir(dir string) (string, error) {
path, err := execext.ExpandLiteral(dir)
if err != nil {
return "", err
}

if filepathext.IsAbs(path) {
return path, nil
if len(dir) == 0 {
// Resolve to the current node.Dir().
return node.Dir(), nil
} else {
// Resolve include.Dir, relative to this node.Dir(), or absolute.
dir, err := execext.ExpandLiteral(dir)
if err != nil {
return "", err
}
return filepathext.SmartJoin(node.Dir(), dir), nil
}

// NOTE: Uses the directory of the entrypoint (Taskfile), not the current working directory
// This means that files are included relative to one another
entrypointDir := filepath.Dir(node.entrypoint)
return filepathext.SmartJoin(entrypointDir, path), nil
}
22 changes: 10 additions & 12 deletions taskfile/node_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,17 @@ func (node *GitNode) ResolveEntrypoint(entrypoint string) (string, error) {
}

func (node *GitNode) ResolveDir(dir string) (string, error) {
path, err := execext.ExpandLiteral(dir)
if err != nil {
return "", err
}

if filepathext.IsAbs(path) {
return path, nil
if len(dir) == 0 {
// Resolve to the current node.Dir().
return node.Dir(), nil
} else {
// Resolve include.Dir, relative to this node.Dir(), or absolute.
dir, err := execext.ExpandLiteral(dir)
if err != nil {
return "", err
}
return filepathext.SmartJoin(node.Dir(), dir), nil
}

// NOTE: Uses the directory of the entrypoint (Taskfile), not the current working directory
// This means that files are included relative to one another
entrypointDir := filepath.Dir(node.Dir())
return filepathext.SmartJoin(entrypointDir, path), nil
}

func (node *GitNode) CacheKey() string {
Expand Down
26 changes: 10 additions & 16 deletions taskfile/node_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,17 @@ func (node *HTTPNode) ResolveEntrypoint(entrypoint string) (string, error) {
}

func (node *HTTPNode) ResolveDir(dir string) (string, error) {
path, err := execext.ExpandLiteral(dir)
if err != nil {
return "", err
}

if filepathext.IsAbs(path) {
return path, nil
}

// NOTE: Uses the directory of the entrypoint (Taskfile), not the current working directory
// This means that files are included relative to one another
parent := node.Dir()
if node.Parent() != nil {
parent = node.Parent().Dir()
if len(dir) == 0 {
// Resolve to the current node.Dir().
return node.Dir(), nil
} else {
// Resolve include.Dir, relative to this node.Dir(), or absolute.
dir, err := execext.ExpandLiteral(dir)
if err != nil {
return "", err
}
return filepathext.SmartJoin(node.Dir(), dir), nil
}

return filepathext.SmartJoin(parent, path), nil
}

func (node *HTTPNode) CacheKey() string {
Expand Down
32 changes: 14 additions & 18 deletions taskfile/node_stdin.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,28 @@ func (node *StdinNode) Read() ([]byte, error) {
}

func (node *StdinNode) ResolveEntrypoint(entrypoint string) (string, error) {
// If the file is remote, we don't need to resolve the path
// Resolve to entrypoint without adjustment.
if isRemoteEntrypoint(entrypoint) {
return entrypoint, nil
}

path, err := execext.ExpandLiteral(entrypoint)
// Resolve relative to this node.Dir() (i.e. the root node), or absolute.
entrypoint, err := execext.ExpandLiteral(entrypoint)
if err != nil {
return "", err
}

if filepathext.IsAbs(path) {
return path, nil
}

return filepathext.SmartJoin(node.Dir(), path), nil
return filepathext.SmartJoin(node.Dir(), entrypoint), nil
}

func (node *StdinNode) ResolveDir(dir string) (string, error) {
path, err := execext.ExpandLiteral(dir)
if err != nil {
return "", err
}

if filepathext.IsAbs(path) {
return path, nil
if len(dir) == 0 {
// Resolve to the current node.Dir().
return node.Dir(), nil
} else {
// Resolve include.Dir, relative to this node.Dir(), or absolute.
dir, err := execext.ExpandLiteral(dir)
if err != nil {
return "", err
}
return filepathext.SmartJoin(node.Dir(), dir), nil
}

return filepathext.SmartJoin(node.Dir(), path), nil
}
Loading