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:
2
build.ts
2
build.ts
@@ -2,7 +2,7 @@ import isolatedDecl from 'bun-plugin-isolated-decl';
|
||||
|
||||
// handles building the library
|
||||
await Bun.build({
|
||||
entrypoints: ['./src/index.ts'],
|
||||
entrypoints: ['./src/*.ts'],
|
||||
outdir: './dist',
|
||||
target: 'node',
|
||||
plugins: [
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "code-tokenizer-md",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.6",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"module": "src/index.ts",
|
||||
@@ -13,15 +13,13 @@
|
||||
}
|
||||
},
|
||||
"bin": {
|
||||
"code-tokenizer-md": "./dist/code-tokenizer-md"
|
||||
"code-tokenizer-md": "./dist/cli.js"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"types": "",
|
||||
"scripts": {
|
||||
"build": "rm -rf dist && bun ./build.ts && bun build:cli",
|
||||
"build:cli": "bun build ./src/cli.ts --compile --outfile dist/code-tokenizer-md",
|
||||
"build": "rm -rf dist && bun build ./src/index.ts ./src/cli.ts --outdir dist --target node && bun ./build.ts",
|
||||
"test": "bun test",
|
||||
"prepublishOnly": "bun run build",
|
||||
"dev": "bun run .",
|
||||
@@ -32,6 +30,7 @@
|
||||
"fix": "bun format && bun lint:fix"
|
||||
},
|
||||
"dependencies": {
|
||||
"glob": "^11.0.0",
|
||||
"llama3-tokenizer-js": "^1.0.0",
|
||||
"micromatch": "^4.0.8"
|
||||
},
|
||||
|
@@ -1,5 +1,3 @@
|
||||
// MarkdownGenerator.ts
|
||||
|
||||
import path from 'path';
|
||||
import { execSync } from 'child_process';
|
||||
import { readFile, writeFile } from 'fs/promises';
|
||||
@@ -9,7 +7,7 @@ import * as micromatch from 'micromatch';
|
||||
import fileTypeExclusions from './fileTypeExclusions.js';
|
||||
import fileExclusions from './fileExclusions.js';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { Glob } from 'bun';
|
||||
import { glob } from 'glob';
|
||||
|
||||
|
||||
interface MarkdownGeneratorOptions {
|
||||
@@ -72,37 +70,19 @@ export class MarkdownGenerator {
|
||||
* @returns {Promise<void>}
|
||||
* @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> {
|
||||
try {
|
||||
if (this.verbose) {
|
||||
console.log('Loading ignore patterns...');
|
||||
}
|
||||
|
||||
const ignoreGlob = new Glob("**/.code-tokenizer-md-ignore");
|
||||
const ignoreFiles: string[] = [];
|
||||
|
||||
// Use Bun's native glob to find ignore files
|
||||
for await (const file of ignoreGlob.scan({
|
||||
const ignoreFiles = await glob('**/.code-tokenizer-md-ignore', {
|
||||
cwd: this.dir,
|
||||
dot: true,
|
||||
absolute: true,
|
||||
followSymlinks: false,
|
||||
onlyFiles: true
|
||||
})) {
|
||||
ignoreFiles.push(file);
|
||||
}
|
||||
follow: false,
|
||||
nodir: true
|
||||
});
|
||||
|
||||
if (this.verbose) {
|
||||
console.log(`Found ${ignoreFiles.length} ignore files`);
|
||||
@@ -147,6 +127,7 @@ export class MarkdownGenerator {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of files tracked by Git, excluding those specified in fileTypeExclusions and fileExclusions.
|
||||
* @async
|
||||
|
@@ -69,4 +69,4 @@ export default [
|
||||
'**/tmp/',
|
||||
'**/temp/',
|
||||
'**/*.log'
|
||||
]
|
||||
] as const;
|
@@ -1,4 +1,4 @@
|
||||
export default [
|
||||
const filetypeExclusions = [
|
||||
// Images
|
||||
'.jpg',
|
||||
'.jpeg',
|
||||
@@ -57,4 +57,6 @@ export default [
|
||||
'.db',
|
||||
'.sqlite',
|
||||
'.sqlite3'
|
||||
]
|
||||
] as const;
|
||||
|
||||
export default filetypeExclusions;
|
Reference in New Issue
Block a user