Skip to content

Commit

Permalink
v1.2.3: regex generation is a slippery slope
Browse files Browse the repository at this point in the history
  • Loading branch information
colthreepv committed Jan 8, 2025
1 parent 1197faf commit a7d8413
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "llm-context",
"type": "module",
"version": "1.2.2",
"version": "1.2.3",
"packageManager": "[email protected]+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c",
"description": "A CLI tool to build context files to attach to Large Language Models (LLMs).",
"author": {
Expand Down
6 changes: 3 additions & 3 deletions src/ignore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function matchesPattern(path: string, pattern: string): boolean {
const regexString = pattern
.replace(/\*/g, '.*')
.replace(/\?/g, '.')
const escaped = pattern.replace(/\./g, '\\.')
const regexString = escaped.replace(/\*/g, '.*')

const regex = new RegExp(regexString)
return regex.test(path)
}
20 changes: 20 additions & 0 deletions tests/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,23 @@ describe('readFilesInDirectory', () => {
expect(tokensMap.get('test.txt')).toBeGreaterThanOrEqual(1)
})
})

describe('login dir ignore check', () => {
const testDir = join(__dirname, 'test-login')

beforeAll(() => {
rmSync(testDir, { recursive: true, force: true })
mkdirSync(join(testDir, 'login'), { recursive: true })
// Some dummy file to ensure the dir has content
writeFileSync(join(testDir, 'login', 'stuff.ts'), 'console.log("Login stuff")')
})

afterAll(() => {
rmSync(testDir, { recursive: true, force: true })
})

it('should NOT ignore login folder by default', () => {
const { context } = readFilesInDirectory(testDir, testDir)
expect(context).toContain('<file name="login/stuff.ts">')
})
})
18 changes: 18 additions & 0 deletions tests/tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,22 @@ describe('tree.util', () => {
expect(result).not.toContain('foofile.md')
})
})

it('should NOT ignore "login" folder by default', () => {
// Make sure the folder exists and has some file
mkdirSync(join(testDir, 'login'), { recursive: true })
writeFileSync(join(testDir, 'login', 'stuff.ts'), 'console.log("Login stuff")')

// Run getTreeOutput without custom ignores
const result = getTreeOutput(
testDir,
[],
new Map<string, number>(),
testDir,
)

// Confirm that "login" is present in the tree
expect(result).toContain('login')
expect(result).toContain('stuff.ts')
})
})

0 comments on commit a7d8413

Please sign in to comment.