diff --git a/core/package.json b/core/package.json index 8db05a2..4153558 100644 --- a/core/package.json +++ b/core/package.json @@ -32,7 +32,6 @@ "@dqbd/tiktoken": "^1.0.7", "gitignore-parser": "^0.0.2", "gray-matter": "^4.0.3", - "mime-types": "^2.1.35", "mustache": "^4.2.0", "openai": "^4.11.1", "temporal-polyfill": "^0.2.4", @@ -40,7 +39,6 @@ "yaml": "^2.4.1" }, "devDependencies": { - "@types/mime-types": "^2.1.4", "@types/mustache": "^4.2.5", "vitest": "^1.5.0" } diff --git a/core/src/content/gitignore_fs.test.ts b/core/src/content/gitignore_fs.test.ts index 555ea06..21bbf1f 100644 --- a/core/src/content/gitignore_fs.test.ts +++ b/core/src/content/gitignore_fs.test.ts @@ -3,6 +3,16 @@ import { describe, expect, it } from "vitest"; import { GitignoreFs } from "./gitignore_fs.js"; describe("gitignore fs", () => { + it("skips files with no extension", async () => { + const fs = new GitignoreFs( + new ObjectFileSystemAdapter({ + "file.txt": "abc", + skip: "skip", + }) + ); + + expect(await fs.readdir("/")).toEqual(["file.txt"]); + }); it("reads while obeying .gitignores", async () => { const fs = new GitignoreFs( new ObjectFileSystemAdapter({ diff --git a/core/src/content/gitignore_fs.ts b/core/src/content/gitignore_fs.ts index e796c8d..317a8ed 100644 --- a/core/src/content/gitignore_fs.ts +++ b/core/src/content/gitignore_fs.ts @@ -1,6 +1,5 @@ import { FileSystem, SEP } from "@davidsouther/jiffies/lib/cjs/fs.js"; import { join, normalize } from "path"; -import { contentType } from "mime-types"; import * as gitignoreParser from "gitignore-parser"; export class GitignoreFs extends FileSystem { @@ -25,9 +24,10 @@ export class GitignoreFs extends FileSystem { }); } const paths = await this.adapter.scandir(path); + const ignoredNames = [".git", ".gitignore"]; const filtered = paths.filter( (p) => - p.name !== ".git" && + !ignoredNames.includes(p.name) && (p.isDirectory() || isTextExtension(p.name)) && gitignores.every((g) => p.isDirectory() ? g.accepts(p.name + "/") : g.accepts(p.name) @@ -38,10 +38,29 @@ export class GitignoreFs extends FileSystem { } function isTextExtension(name: string) { - const overrides = ["go", "ts"]; - if (overrides.includes(name.split(".").pop() || "")) { - return true; + // If theres no extension, err on the side + // of caution and don't include it in the context. + if (!name.includes(".")) { + return false; } - const contType = contentType(name) || ""; - return contType.startsWith("text") || contType.startsWith("application"); + + // From https://github.com/bevry/binaryextensions/blob/master/source/index.ts + const binaryExtensions = [ + "dds", + "eot", + "gif", + "ico", + "jar", + "jpeg", + "jpg", + "pdf", + "png", + "swf", + "tga", + "ttf", + "zip", + ]; + + const ext = name.split(".").pop() || ""; + return !binaryExtensions.includes(ext); } diff --git a/integ/package.json b/integ/package.json index 461a9e3..4e4ce05 100644 --- a/integ/package.json +++ b/integ/package.json @@ -1,12 +1,13 @@ { "name": "integ", "version": "1.0.0", - "description": "", "main": "index.js", + "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", - "license": "ISC" + "license": "ISC", + "description": "" } diff --git a/package-lock.json b/package-lock.json index a83900d..6a335a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,10 +14,10 @@ }, "cli": { "name": "@ailly/cli", - "version": "1.5.0", + "version": "1.5.1", "license": "ISC", "dependencies": { - "@ailly/core": "1.5.0", + "@ailly/core": "1.5.1", "@davidsouther/jiffies": "^2.2.4", "yaml": "^2.4.1" }, @@ -33,7 +33,7 @@ }, "core": { "name": "@ailly/core", - "version": "1.5.0", + "version": "1.5.1", "license": "ISC", "dependencies": { "@aws-sdk/client-bedrock-runtime": "^3.427.0", @@ -42,7 +42,6 @@ "@dqbd/tiktoken": "^1.0.7", "gitignore-parser": "^0.0.2", "gray-matter": "^4.0.3", - "mime-types": "^2.1.35", "mustache": "^4.2.0", "openai": "^4.11.1", "temporal-polyfill": "^0.2.4", @@ -50,7 +49,6 @@ "yaml": "^2.4.1" }, "devDependencies": { - "@types/mime-types": "^2.1.4", "@types/mustache": "^4.2.5", "vitest": "^1.5.0" }, @@ -60,9 +58,9 @@ }, "extension": { "name": "ailly", - "version": "1.5.0", + "version": "1.5.1", "dependencies": { - "@ailly/core": "1.5.0", + "@ailly/core": "1.5.1", "@davidsouther/jiffies": "^2.1.3" }, "devDependencies": { @@ -3704,12 +3702,6 @@ "@types/unist": "*" } }, - "node_modules/@types/mime-types": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.4.tgz", - "integrity": "sha512-lfU4b34HOri+kAY5UheuFMWPDOI+OPceBSHZKp69gEyTL/mmJ4cnU6Y/rlme3UL3GyOn6Y42hyIEw0/q8sWx5w==", - "dev": true - }, "node_modules/@types/mocha": { "version": "10.0.6", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.6.tgz", @@ -13291,9 +13283,9 @@ }, "web": { "name": "@ailly/web", - "version": "1.5.0", + "version": "1.5.1", "dependencies": { - "@ailly/core": "1.5.0", + "@ailly/core": "1.5.1", "@davidsouther/jiffies": "^2.2.4", "marked-react": "^2.0.0", "react": "^18",