Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative paths don't work with gitignore option #168

Open
NickHeiner opened this issue Feb 24, 2021 · 3 comments
Open

Relative paths don't work with gitignore option #168

NickHeiner opened this issue Feb 24, 2021 · 3 comments

Comments

@NickHeiner
Copy link

When I pass a relative path, and gitignore: true, I get an error.

Demo repo

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)
@cboden
Copy link

cboden commented Jun 3, 2021

+1

@pinuke
Copy link

pinuke commented Apr 16, 2022

+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.

@vdawg-git
Copy link

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants