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

Bump ignore from 5.1.9 to 5.2.0 #5787

Merged
merged 1 commit into from Dec 20, 2021
Merged

Conversation

dependabot[bot]
Copy link
Contributor

@dependabot dependabot bot commented on behalf of github Dec 20, 2021

Bumps ignore from 5.1.9 to 5.2.0.

Release notes

Sourced from ignore's releases.

5.2.0

  • PATCH support readonly arrays of typescript. (#70)
  • MINOR bring backward compatibility with relative paths. (#75)

An upgrade is recommended for all dependents.


ignore().ignores('../foo/bar.js') // will throw

And the code below will not throw, however it is not recommended

ignore({
  allowRelativePaths: true
}).ignores('../foo/bar.js')

Recommend:

ignore().ignores('foo/bar.js')
Commits
  • 5768b70 5.2.0: #70, #75: ts: adds more test cases for typescript
  • 950d665 #75: README.md: improves explanation of options.allowRelativePaths
  • 052a722 #75: main, README.md, test, ts: new options.allowRelativePaths to bring backw...
  • 92e83e2 #70: test: improve ts cases
  • 7785ba8 Merge pull request #70 from nicojs/patch-1
  • 64e9992 fix(types): allow for readonly arrays
  • See full diff in compare view

Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

  • @dependabot rebase will rebase this PR
  • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
  • @dependabot merge will merge this PR after your CI passes on it
  • @dependabot squash and merge will squash and merge this PR after your CI passes on it
  • @dependabot cancel merge will cancel a previously requested merge and block automerging
  • @dependabot reopen will reopen this PR if it is closed
  • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
  • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

Bumps [ignore](https://github.com/kaelzhang/node-ignore) from 5.1.9 to 5.2.0.
- [Release notes](https://github.com/kaelzhang/node-ignore/releases)
- [Changelog](https://github.com/kaelzhang/node-ignore/blob/master/CHANGELOG.md)
- [Commits](kaelzhang/node-ignore@5.1.9...5.2.0)

---
updated-dependencies:
- dependency-name: ignore
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
@dependabot dependabot bot added the pr: dependencies relates to dependencies label Dec 20, 2021
@ybiquitous
Copy link
Member

Looks like no problems 👍🏼

$ npm diff --diff=ignore@5.1.9 --diff=ignore@5.2.0
diff --git a/index.js b/index.js
index v5.1.9..v5.2.0 100644
--- a/index.js
+++ b/index.js
@@ -30,6 +30,8 @@
 
 const REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g
 
+const RETURN_FALSE = () => false
+
 // Sanitize the range of a regular expression
 // The cases are complicated, see test cases for details
 const sanitizeRange = range => range.replace(
@@ -288,7 +290,7 @@
 const regexCache = Object.create(null)
 
 // @param {pattern}
-const makeRegex = (pattern, ignorecase) => {
+const makeRegex = (pattern, ignoreCase) => {
   let source = regexCache[pattern]
 
   if (!source) {
@@ -299,7 +301,7 @@
     regexCache[pattern] = source
   }
 
-  return ignorecase
+  return ignoreCase
     ? new RegExp(source, 'i')
     : new RegExp(source)
 }
@@ -330,7 +332,7 @@
   }
 }
 
-const createRule = (pattern, ignorecase) => {
+const createRule = (pattern, ignoreCase) => {
   const origin = pattern
   let negative = false
 
@@ -348,7 +350,7 @@
   // >   begin with a hash.
   .replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#')
 
-  const regex = makeRegex(pattern, ignorecase)
+  const regex = makeRegex(pattern, ignoreCase)
 
   return new IgnoreRule(
     origin,
@@ -394,12 +396,15 @@
 
 class Ignore {
   constructor ({
-    ignorecase = true
+    ignorecase = true,
+    ignoreCase = ignorecase,
+    allowRelativePaths = false
   } = {}) {
     define(this, KEY_IGNORE, true)
 
     this._rules = []
-    this._ignorecase = ignorecase
+    this._ignoreCase = ignoreCase
+    this._allowRelativePaths = allowRelativePaths
     this._initCache()
   }
 
@@ -417,7 +422,7 @@
     }
 
     if (checkPattern(pattern)) {
-      const rule = createRule(pattern, this._ignorecase)
+      const rule = createRule(pattern, this._ignoreCase)
       this._added = true
       this._rules.push(rule)
     }
@@ -496,7 +501,13 @@
       // Supports nullable path
       && checkPath.convert(originalPath)
 
-    checkPath(path, originalPath, throwError)
+    checkPath(
+      path,
+      originalPath,
+      this._allowRelativePaths
+        ? RETURN_FALSE
+        : throwError
+    )
 
     return this._t(path, cache, checkUnignored, slices)
   }
@@ -554,10 +565,8 @@
 
 const factory = options => new Ignore(options)
 
-const returnFalse = () => false
-
 const isPathValid = path =>
-  checkPath(path && checkPath.convert(path), path, returnFalse)
+  checkPath(path && checkPath.convert(path), path, RETURN_FALSE)
 
 factory.isPathValid = isPathValid
 
diff --git a/legacy.js b/legacy.js
index v5.1.9..v5.2.0 100644
--- a/legacy.js
+++ b/legacy.js
@@ -35,9 +35,14 @@
   });
 };
 
-var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g; // Sanitize the range of a regular expression
+var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g;
+
+var RETURN_FALSE = function RETURN_FALSE() {
+  return false;
+}; // Sanitize the range of a regular expression
 // The cases are complicated, see test cases for details
 
+
 var sanitizeRange = function sanitizeRange(range) {
   return range.replace(REGEX_REGEXP_RANGE, function (match, from, to) {
     return from.charCodeAt(0) <= to.charCodeAt(0) ? match // Invalid range (out of order) which is ok for gitignore rules but
@@ -205,7 +210,7 @@
 
 var regexCache = Object.create(null); // @param {pattern}
 
-var makeRegex = function makeRegex(pattern, ignorecase) {
+var makeRegex = function makeRegex(pattern, ignoreCase) {
   var source = regexCache[pattern];
 
   if (!source) {
@@ -215,7 +220,7 @@
     regexCache[pattern] = source;
   }
 
-  return ignorecase ? new RegExp(source, 'i') : new RegExp(source);
+  return ignoreCase ? new RegExp(source, 'i') : new RegExp(source);
 };
 
 var isString = function isString(subject) {
@@ -241,7 +246,7 @@
   this.regex = regex;
 };
 
-var createRule = function createRule(pattern, ignorecase) {
+var createRule = function createRule(pattern, ignoreCase) {
   var origin = pattern;
   var negative = false; // > An optional prefix "!" which negates the pattern;
 
@@ -255,7 +260,7 @@
   .replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that
   // >   begin with a hash.
   .replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#');
-  var regex = makeRegex(pattern, ignorecase);
+  var regex = makeRegex(pattern, ignoreCase);
   return new IgnoreRule(origin, pattern, negative, regex);
 };
 
@@ -296,13 +301,18 @@
   function Ignore() {
     var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
         _ref$ignorecase = _ref.ignorecase,
-        ignorecase = _ref$ignorecase === void 0 ? true : _ref$ignorecase;
+        ignorecase = _ref$ignorecase === void 0 ? true : _ref$ignorecase,
+        _ref$ignoreCase = _ref.ignoreCase,
+        ignoreCase = _ref$ignoreCase === void 0 ? ignorecase : _ref$ignoreCase,
+        _ref$allowRelativePat = _ref.allowRelativePaths,
+        allowRelativePaths = _ref$allowRelativePat === void 0 ? false : _ref$allowRelativePat;
 
     _classCallCheck(this, Ignore);
 
     define(this, KEY_IGNORE, true);
     this._rules = [];
-    this._ignorecase = ignorecase;
+    this._ignoreCase = ignoreCase;
+    this._allowRelativePaths = allowRelativePaths;
 
     this._initCache();
   }
@@ -324,7 +334,7 @@
       }
 
       if (checkPattern(pattern)) {
-        var rule = createRule(pattern, this._ignorecase);
+        var rule = createRule(pattern, this._ignoreCase);
         this._added = true;
 
         this._rules.push(rule);
@@ -395,7 +405,7 @@
     value: function _test(originalPath, cache, checkUnignored, slices) {
       var path = originalPath // Supports nullable path
       && checkPath.convert(originalPath);
-      checkPath(path, originalPath, throwError);
+      checkPath(path, originalPath, this._allowRelativePaths ? RETURN_FALSE : throwError);
       return this._t(path, cache, checkUnignored, slices);
     }
   }, {
@@ -458,12 +468,8 @@
   return new Ignore(options);
 };
 
-var returnFalse = function returnFalse() {
-  return false;
-};
-
 var isPathValid = function isPathValid(path) {
-  return checkPath(path && checkPath.convert(path), path, returnFalse);
+  return checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
 };
 
 factory.isPathValid = isPathValid; // Fixes typescript
diff --git a/package.json b/package.json
index v5.1.9..v5.2.0 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "ignore",
-  "version": "5.1.9",
+  "version": "5.2.0",
   "description": "Ignore is a manager and filter for .gitignore rules, the one used by eslint, gitbook and many others.",
   "files": [
     "legacy.js",
diff --git a/README.md b/README.md
index v5.1.9..v5.2.0 100644
--- a/README.md
+++ b/README.md
@@ -298,8 +298,20 @@
 - `{ignored: false, unignored: true}`: the `pathname` is unignored
 - `{ignored: false, unignored: false}`: the `pathname` is never matched by any ignore rules.
 
-## `options.ignorecase` since 4.0.0
+## static `ignore.isPathValid(pathname): boolean` since 5.0.0
 
+Check whether the `pathname` is an valid `path.relative()`d path according to the [convention](#1-pathname-should-be-a-pathrelatived-pathname).
+
+This method is **NOT** used to check if an ignore pattern is valid.
+
+```js
+ignore.isPathValid('./foo')  // false
+```
+
+## ignore(options)
+
+### `options.ignorecase` since 4.0.0
+
 Similar as the `core.ignorecase` option of [git-config](https://git-scm.com/docs/git-config), `node-ignore` will be case insensitive if `options.ignorecase` is set to `true` (the default value), otherwise case sensitive.
 
 ```js
@@ -312,14 +324,20 @@
 ig.ignores('*.PNG')  // false
 ```
 
-## static `ignore.isPathValid(pathname): boolean` since 5.0.0
+### `options.ignoreCase?: boolean` since 5.2.0
 
-Check whether the `pathname` is an valid `path.relative()`d path according to the [convention](#1-pathname-should-be-a-pathrelatived-pathname).
+Which is alternative to `options.ignoreCase`
 
-This method is **NOT** used to check if an ignore pattern is valid.
+### `options.allowRelativePaths?: boolean` since 5.2.0
 
+This option brings backward compatibility with projects which based on `ignore@4.x`. If `options.allowRelativePaths` is `true`, `ignore` will not check whether the given path to be tested is [`path.relative()`d](#pathname-conventions).
+
+However, passing a relative path, such as `'./foo'` or `'../foo'`, to test if it is ignored or not is not a good practise, which might lead to unexpected behavior
+
 ```js
-ignore.isPathValid('./foo')  // false
+ignore({
+  allowRelativePaths: true
+}).ignores('../foo/bar.js') // And it will not throw
 ```
 
 ****
@@ -328,8 +346,10 @@
 
 ## Upgrade 4.x -> 5.x
 
-Since `5.0.0`, if an invalid `Pathname` passed into `ig.ignores()`, an error will be thrown, while `ignore < 5.0.0` did not make sure what the return value was, as well as
+Since `5.0.0`, if an invalid `Pathname` passed into `ig.ignores()`, an error will be thrown, unless `options.allowRelative = true` is passed to the `Ignore` factory.
 
+While `ignore < 5.0.0` did not make sure what the return value was, as well as
+
 ```ts
 .ignores(pathname: Pathname): boolean
 
diff --git a/index.d.ts b/index.d.ts
index v5.1.9..v5.2.0 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -7,17 +7,11 @@
 
 export interface Ignore {
   /**
-   * Adds a rule rules to the current manager.
-   * @param  {string | Ignore} pattern
-   * @returns IgnoreBase
-   */
-  add(pattern: string | Ignore): this
-  /**
-   * Adds several rules to the current manager.
+   * Adds one or several rules to the current manager.
    * @param  {string[]} patterns
    * @returns IgnoreBase
    */
-  add(patterns: (string | Ignore)[]): this
+  add(patterns: string | Ignore | readonly (string | Ignore)[]): this
 
   /**
    * Filters the given array of pathnames, and returns the filtered array.
@@ -25,7 +19,8 @@
    * @param paths the array of paths to be filtered.
    * @returns The filtered array of paths
    */
-  filter(pathnames: Pathname[]): Pathname[]
+  filter(pathnames: readonly Pathname[]): Pathname[]
+
   /**
    * Creates a filter function which could filter
    * an array of paths with Array.prototype.filter.
@@ -49,6 +44,9 @@
 
 interface Options {
   ignorecase?: boolean
+  // For compatibility
+  ignoreCase?: boolean
+  allowRelativePaths?: boolean
 }
 
 /**

@jeddy3 jeddy3 merged commit 28978c2 into main Dec 20, 2021
@jeddy3 jeddy3 deleted the dependabot/npm_and_yarn/ignore-5.2.0 branch December 20, 2021 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: dependencies relates to dependencies
Development

Successfully merging this pull request may close these issues.

None yet

2 participants