mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-08 11:58:49 +03:00
Merge pull request #932 from pedronasser/fix-import
fix: import should always be relative to current file directory
This commit is contained in:
commit
d6110f8e9e
1 changed files with 28 additions and 2 deletions
|
@ -218,8 +218,13 @@ func (p *parser) doImport() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var matches []string
|
var matches []string
|
||||||
relImportPattern := filepath.Join(filepath.Dir(absFile), importPattern)
|
var globPattern string
|
||||||
matches, err = filepath.Glob(relImportPattern)
|
if !filepath.IsAbs(importPattern) {
|
||||||
|
globPattern = filepath.Join(filepath.Dir(absFile), importPattern)
|
||||||
|
} else {
|
||||||
|
globPattern = importPattern
|
||||||
|
}
|
||||||
|
matches, err = filepath.Glob(globPattern)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return p.Errf("Failed to use import pattern %s: %v", importPattern, err)
|
return p.Errf("Failed to use import pattern %s: %v", importPattern, err)
|
||||||
|
@ -239,6 +244,27 @@ func (p *parser) doImport() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
var importLine int
|
||||||
|
importDir := filepath.Dir(importFile)
|
||||||
|
for i, token := range newTokens {
|
||||||
|
if token.Text == "import" {
|
||||||
|
importLine = token.Line
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if token.Line == importLine {
|
||||||
|
var abs string
|
||||||
|
if !filepath.IsAbs(importFile) {
|
||||||
|
abs = filepath.Join(filepath.Dir(absFile), token.Text)
|
||||||
|
} else {
|
||||||
|
abs = filepath.Join(importDir, token.Text)
|
||||||
|
}
|
||||||
|
newTokens[i] = Token{
|
||||||
|
Text: abs,
|
||||||
|
Line: token.Line,
|
||||||
|
File: token.File,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
importedTokens = append(importedTokens, newTokens...)
|
importedTokens = append(importedTokens, newTokens...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue