globby
globby copied to clipboard
Relative paths don't work with `gitignore` option
When I pass a relative path, and gitignore: true, I get an error.
const path = require('path');
const globby = require('globby');
console.log(globby.sync(
['..'],
{cwd: path.join(__dirname, 'node_modules'), gitignore: true}
))
When I run this, I get:
/Users/nheiner/code/globby-relative-path-demo/node_modules/ignore/index.js:366
throw new Ctor(message)
^
RangeError: path should be a `path.relative()`d string, but got "../index.js"
at throwError (/Users/nheiner/code/globby-relative-path-demo/node_modules/ignore/index.js:366:9)
at checkPath (/Users/nheiner/code/globby-relative-path-demo/node_modules/ignore/index.js:385:12)
at Ignore._test (/Users/nheiner/code/globby-relative-path-demo/node_modules/ignore/index.js:502:5)
at Ignore.ignores (/Users/nheiner/code/globby-relative-path-demo/node_modules/ignore/index.js:541:17)
at /Users/nheiner/code/globby-relative-path-demo/node_modules/globby/gitignore.js:62:22
at /Users/nheiner/code/globby-relative-path-demo/node_modules/globby/index.js:154:34
at Array.filter (<anonymous>)
at AsyncFunction.module.exports.sync (/Users/nheiner/code/globby-relative-path-demo/node_modules/globby/index.js:154:17)
at Object.<anonymous> (/Users/nheiner/code/globby-relative-path-demo/index.js:4:20)
at Module._compile (internal/modules/cjs/loader.js:959:30)
+1
+1
A simpler way to demonstrate the bug:
globbySync([ "file.ext" ], { gitignore:true }) //works
globbySync([ "./file.ext" ], { gitignore:false }) //works
globbySync([ "./file.ext" ], { gitignore:true }) //throws an error
globby needs to get the relative path to the .gitignore file before passing it to ignore.js.
globby should also detect if a file with no relative path to the gitignore file was accidentally passed.
Any updates on this?