Skip to content

Commit 8debd73

Browse files
committed
Evaluate the root path only once
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
1 parent b9d7318 commit 8debd73

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

pkg/compile/compile.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ func Recursive(ctx context.Context, fss []fs.FS) (*yarax.Rules, error) {
205205
return nil, fmt.Errorf("yarax compiler: %w", err)
206206
}
207207

208+
// use the current working directory to determine the root path
209+
// this only needs to be done once
210+
cwd, err := os.Getwd()
211+
if err != nil {
212+
return nil, nil
213+
}
214+
abs, err := filepath.Abs(cwd)
215+
if err != nil {
216+
return nil, err
217+
}
218+
rootPath := findRoot(abs)
219+
208220
rulesToRemove := getRulesToRemove()
209221

210222
for _, root := range fss {
@@ -223,14 +235,9 @@ func Recursive(ctx context.Context, fss []fs.FS) (*yarax.Rules, error) {
223235
return fmt.Errorf("readfile: %w", err)
224236
}
225237

226-
abs, err := filepath.Abs(path)
227-
if err != nil {
228-
return err
229-
}
230-
root := findRoot(abs)
231-
globalAbs := filepath.Join(root, globalPath)
232-
233238
bs = removeRules(bs, rulesToRemove)
239+
240+
globalAbs := filepath.Join(rootPath, globalPath)
234241
bs = replaceGlobal(bs, globalAbs)
235242

236243
yxc.NewNamespace(path)

0 commit comments

Comments
 (0)