Switch from Bun's Glob to glob package for file operations

Replaced Bun's `Glob` usage with the `glob` package in `MarkdownGenerator.ts` for better compatibility and functionality. Updated build entrypoints to include all TypeScript files and adjusted dependencies in `package.json` and `pnpm-lock.yaml` to accommodate this change. Also added type annotations to `fileExclusions` and `fileTypeExclusions` for improved type checking.
This commit is contained in:
2024-12-01 11:41:24 -05:00
parent bf16ed5253
commit 337e882767
6 changed files with 16 additions and 34 deletions

View File

@@ -2,7 +2,7 @@ import isolatedDecl from 'bun-plugin-isolated-decl';
// handles building the library // handles building the library
await Bun.build({ await Bun.build({
entrypoints: ['./src/index.ts'], entrypoints: ['./src/*.ts'],
outdir: './dist', outdir: './dist',
target: 'node', target: 'node',
plugins: [ plugins: [

BIN
bun.lockb

Binary file not shown.

View File

@@ -1,6 +1,6 @@
{ {
"name": "code-tokenizer-md", "name": "code-tokenizer-md",
"version": "1.1.2", "version": "1.1.6",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"module": "src/index.ts", "module": "src/index.ts",
@@ -13,15 +13,13 @@
} }
}, },
"bin": { "bin": {
"code-tokenizer-md": "./dist/code-tokenizer-md" "code-tokenizer-md": "./dist/cli.js"
}, },
"files": [ "files": [
"dist" "dist"
], ],
"types": "",
"scripts": { "scripts": {
"build": "rm -rf dist && bun ./build.ts && bun build:cli", "build": "rm -rf dist && bun build ./src/index.ts ./src/cli.ts --outdir dist --target node && bun ./build.ts",
"build:cli": "bun build ./src/cli.ts --compile --outfile dist/code-tokenizer-md",
"test": "bun test", "test": "bun test",
"prepublishOnly": "bun run build", "prepublishOnly": "bun run build",
"dev": "bun run .", "dev": "bun run .",
@@ -32,6 +30,7 @@
"fix": "bun format && bun lint:fix" "fix": "bun format && bun lint:fix"
}, },
"dependencies": { "dependencies": {
"glob": "^11.0.0",
"llama3-tokenizer-js": "^1.0.0", "llama3-tokenizer-js": "^1.0.0",
"micromatch": "^4.0.8" "micromatch": "^4.0.8"
}, },

View File

@@ -1,5 +1,3 @@
// MarkdownGenerator.ts
import path from 'path'; import path from 'path';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
import { readFile, writeFile } from 'fs/promises'; import { readFile, writeFile } from 'fs/promises';
@@ -9,7 +7,7 @@ import * as micromatch from 'micromatch';
import fileTypeExclusions from './fileTypeExclusions.js'; import fileTypeExclusions from './fileTypeExclusions.js';
import fileExclusions from './fileExclusions.js'; import fileExclusions from './fileExclusions.js';
import { readFileSync } from 'node:fs'; import { readFileSync } from 'node:fs';
import { Glob } from 'bun'; import { glob } from 'glob';
interface MarkdownGeneratorOptions { interface MarkdownGeneratorOptions {
@@ -72,37 +70,19 @@ export class MarkdownGenerator {
* @returns {Promise<void>} * @returns {Promise<void>}
* @throws {Error} When unable to read ignore files * @throws {Error} When unable to read ignore files
*/ */
/**
* Loads and processes .code-tokenizer-md-ignore files using ignore-walk.
* These files contain patterns for files to exclude from processing.
* @async
* @returns {Promise<void>}
* @throws {Error} When unable to read ignore files
*/
/**
* Quickly loads patterns from .code-tokenizer-md-ignore files using Bun's native Glob.
* @async
* @returns {Promise<void>}
*/
async loadNestedIgnoreFiles(): Promise<void> { async loadNestedIgnoreFiles(): Promise<void> {
try { try {
if (this.verbose) { if (this.verbose) {
console.log('Loading ignore patterns...'); console.log('Loading ignore patterns...');
} }
const ignoreGlob = new Glob("**/.code-tokenizer-md-ignore"); const ignoreFiles = await glob('**/.code-tokenizer-md-ignore', {
const ignoreFiles: string[] = [];
// Use Bun's native glob to find ignore files
for await (const file of ignoreGlob.scan({
cwd: this.dir, cwd: this.dir,
dot: true, dot: true,
absolute: true, absolute: true,
followSymlinks: false, follow: false,
onlyFiles: true nodir: true
})) { });
ignoreFiles.push(file);
}
if (this.verbose) { if (this.verbose) {
console.log(`Found ${ignoreFiles.length} ignore files`); console.log(`Found ${ignoreFiles.length} ignore files`);
@@ -147,6 +127,7 @@ export class MarkdownGenerator {
throw error; throw error;
} }
} }
/** /**
* Retrieves a list of files tracked by Git, excluding those specified in fileTypeExclusions and fileExclusions. * Retrieves a list of files tracked by Git, excluding those specified in fileTypeExclusions and fileExclusions.
* @async * @async

View File

@@ -69,4 +69,4 @@ export default [
'**/tmp/', '**/tmp/',
'**/temp/', '**/temp/',
'**/*.log' '**/*.log'
] ] as const;

View File

@@ -1,4 +1,4 @@
export default [ const filetypeExclusions = [
// Images // Images
'.jpg', '.jpg',
'.jpeg', '.jpeg',
@@ -57,4 +57,6 @@ export default [
'.db', '.db',
'.sqlite', '.sqlite',
'.sqlite3' '.sqlite3'
] ] as const;
export default filetypeExclusions;