Skip to content

Commit f19a790

Browse files
authored
Merge pull request #74 from forking-repos/tap-cache-fixes
Tap + Internal Caching Fixes
2 parents 7cc95d2 + f2f67cb commit f19a790

4 files changed

Lines changed: 38 additions & 20 deletions

File tree

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99

1010
strategy:
1111
matrix:
12-
node-version: [12.x, 14.x]
12+
node-version: [12.x, 14.x, 16.x]
1313

1414
steps:
1515
- uses: actions/checkout@v1

index.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -288,22 +288,17 @@ const REPLACERS = [
288288
const regexCache = Object.create(null)
289289

290290
// @param {pattern}
291-
const makeRegex = (pattern, negative, ignorecase) => {
292-
const r = regexCache[pattern]
293-
if (r) {
294-
return r
295-
}
296-
297-
// const replacers = negative
298-
// ? NEGATIVE_REPLACERS
299-
// : POSITIVE_REPLACERS
291+
const makeRegex = (pattern, ignorecase) => {
292+
let source = regexCache[pattern]
300293

301-
const source = REPLACERS.reduce(
302-
(prev, current) => prev.replace(current[0], current[1].bind(pattern)),
303-
pattern
304-
)
294+
if (!source) {
295+
regexCache[pattern] = source = REPLACERS.reduce(
296+
(prev, current) => prev.replace(current[0], current[1].bind(pattern)),
297+
pattern
298+
)
299+
}
305300

306-
return regexCache[pattern] = ignorecase
301+
return ignorecase
307302
? new RegExp(source, 'i')
308303
: new RegExp(source)
309304
}
@@ -352,7 +347,7 @@ const createRule = (pattern, ignorecase) => {
352347
// > begin with a hash.
353348
.replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#')
354349

355-
const regex = makeRegex(pattern, negative, ignorecase)
350+
const regex = makeRegex(pattern, ignorecase)
356351

357352
return new IgnoreRule(
358353
origin,

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
"test:lint": "eslint .",
1515
"test:tsc": "tsc ./test/ts/simple.ts --lib ES6",
1616
"test:ts": "node ./test/ts/simple.js",
17-
"test:git": "tap test/git-check-ignore.js",
18-
"test:ignore": "tap test/ignore.js",
19-
"test:others": "tap test/others.js",
20-
"test:cases": "tap test/*.js --coverage",
17+
"tap": "tap --reporter classic",
18+
"test:git": "npm run tap test/git-check-ignore.js",
19+
"test:ignore": "npm run tap test/ignore.js",
20+
"test:others": "npm run tap test/others.js",
21+
"test:cases": "npm run tap test/*.js -- --coverage",
2122
"test:only": "npm run test:lint && npm run test:tsc && npm run test:ts && npm run test:cases",
2223
"test": "npm run test:only",
2324
"test:win32": "IGNORE_TEST_WIN32=1 npm run test",

test/others.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,28 @@ _test('options.ignorecase', t => {
8585
t.end()
8686
})
8787

88+
_test('special case: internal cache respects ignorecase', t => {
89+
const rule = '*.[jJ][pP]g'
90+
91+
const ig = ignore({
92+
ignorecase: false
93+
})
94+
95+
ig.add(rule)
96+
97+
t.is(ig.ignores('a.JPG'), false)
98+
99+
const ig2 = ignore({
100+
ignorecase: true
101+
})
102+
103+
ig2.add(rule)
104+
105+
t.is(ig2.ignores('a.JPG'), true)
106+
107+
t.end()
108+
})
109+
88110
_test('special case: invalid paths, throw', t => {
89111
const ig = ignore()
90112

0 commit comments

Comments
 (0)