diff --git a/gitignore.js b/gitignore.js index 982834c..9ecbc05 100644 --- a/gitignore.js +++ b/gitignore.js @@ -44,8 +44,20 @@ const reduceIgnore = files => { }, gitIgnore()); }; +const ensureAbsolutePathForCwd = (cwd, p) => { + if (path.isAbsolute(p)) { + if (p.startsWith(cwd)) { + return p; + } + + throw new Error(`Path ${p} is not in cwd ${cwd}`); + } + + return path.join(cwd, p); +}; + const getIsIgnoredPredecate = (ignores, cwd) => { - return p => ignores.ignores(slash(path.relative(cwd, p))); + return p => ignores.ignores(slash(path.relative(cwd, ensureAbsolutePathForCwd(cwd, p)))); }; const getFile = (file, cwd) => { diff --git a/package.json b/package.json index b345ab4..570174f 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "dir-glob": "^2.2.2", "fast-glob": "^2.2.6", "glob": "^7.1.3", - "ignore": "^4.0.3", + "ignore": "^5.1.1", "pify": "^4.0.1", "slash": "^2.0.0" },