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

Restore ability to accept relative paths #75

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface Ignore {

interface Options {
ignorecase?: boolean
ignorerelative?: boolean
}

/**
Expand Down
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ const throwError = (message, Ctor) => {
throw new Ctor(message)
}

const checkPath = (path, originalPath, doThrow) => {
const checkPath = (path, originalPath, doThrow, ignoreRelative = false) => {
if (!isString(path)) {
return doThrow(
`path must be a string, but got \`${originalPath}\``,
Expand All @@ -376,7 +376,7 @@ const checkPath = (path, originalPath, doThrow) => {
}

// Check if it is a relative path
if (checkPath.isNotRelative(path)) {
if (checkPath.isNotRelative(path) && !ignoreRelative) {
const r = '`path.relative()`d'
return doThrow(
`path should be a ${r} string, but got "${originalPath}"`,
Expand All @@ -394,12 +394,14 @@ checkPath.convert = p => p

class Ignore {
constructor ({
ignorecase = true
ignorecase = true,
ignorerelative = false,
} = {}) {
define(this, KEY_IGNORE, true)

this._rules = []
this._ignorecase = ignorecase
this._ignorerelative = ignorerelative
this._initCache()
}

Expand Down Expand Up @@ -496,7 +498,7 @@ class Ignore {
// Supports nullable path
&& checkPath.convert(originalPath)

checkPath(path, originalPath, throwError)
checkPath(path, originalPath, throwError, this._ignorerelative)

return this._t(path, cache, checkUnignored, slices)
}
Expand Down Expand Up @@ -559,7 +561,7 @@ const returnFalse = () => false
const isPathValid = path =>
checkPath(path && checkPath.convert(path), path, returnFalse)

factory.isPathValid = isPathValid
factory.isPathValid = path => isPathValid(path)

// Fixes typescript
factory.default = factory
Expand Down