@travisennis/acai 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +225 -6
- package/dist/api/exa/index.d.ts +177 -0
- package/dist/api/exa/index.d.ts.map +1 -0
- package/dist/api/exa/index.js +439 -0
- package/dist/cli.d.ts +3 -2
- package/dist/cli.d.ts.map +1 -0
- package/dist/commands/application-log-command.d.ts +1 -0
- package/dist/commands/application-log-command.d.ts.map +1 -0
- package/dist/commands/application-log-command.js +5 -3
- package/dist/commands/clear-command.d.ts +1 -0
- package/dist/commands/clear-command.d.ts.map +1 -0
- package/dist/commands/clear-command.js +2 -3
- package/dist/commands/compact-command.d.ts +1 -0
- package/dist/commands/compact-command.d.ts.map +1 -0
- package/dist/commands/compact-command.js +1 -1
- package/dist/commands/copy-command.d.ts +1 -0
- package/dist/commands/copy-command.d.ts.map +1 -0
- package/dist/commands/copy-command.js +3 -2
- package/dist/commands/edit-command.d.ts +1 -0
- package/dist/commands/edit-command.d.ts.map +1 -0
- package/dist/commands/edit-command.js +7 -5
- package/dist/commands/edit-prompt-command.d.ts +2 -1
- package/dist/commands/edit-prompt-command.d.ts.map +1 -0
- package/dist/commands/edit-prompt-command.js +15 -7
- package/dist/commands/exit-command.d.ts +13 -2
- package/dist/commands/exit-command.d.ts.map +1 -0
- package/dist/commands/exit-command.js +14 -2
- package/dist/commands/files-command.d.ts +1 -0
- package/dist/commands/files-command.d.ts.map +1 -0
- package/dist/commands/files-command.js +9 -8
- package/dist/commands/generate-rules-command.d.ts +1 -0
- package/dist/commands/generate-rules-command.d.ts.map +1 -0
- package/dist/commands/generate-rules-command.js +4 -3
- package/dist/commands/health-command.d.ts +3 -1
- package/dist/commands/health-command.d.ts.map +1 -0
- package/dist/commands/health-command.js +42 -5
- package/dist/commands/help-command.d.ts +1 -0
- package/dist/commands/help-command.d.ts.map +1 -0
- package/dist/commands/help-command.js +2 -3
- package/dist/commands/init-command.d.ts +1 -0
- package/dist/commands/init-command.d.ts.map +1 -0
- package/dist/commands/init-command.js +1 -2
- package/dist/commands/last-log-command.d.ts +1 -0
- package/dist/commands/last-log-command.d.ts.map +1 -0
- package/dist/commands/last-log-command.js +12 -17
- package/dist/commands/list-tools-command.d.ts +3 -0
- package/dist/commands/list-tools-command.d.ts.map +1 -0
- package/dist/commands/list-tools-command.js +61 -0
- package/dist/commands/manager.d.ts +7 -2
- package/dist/commands/manager.d.ts.map +1 -0
- package/dist/commands/manager.js +43 -6
- package/dist/commands/model-command.d.ts +1 -0
- package/dist/commands/model-command.d.ts.map +1 -0
- package/dist/commands/model-command.js +5 -5
- package/dist/commands/paste-command.d.ts +1 -0
- package/dist/commands/paste-command.d.ts.map +1 -0
- package/dist/commands/paste-command.js +6 -5
- package/dist/commands/prompt-command.d.ts +2 -1
- package/dist/commands/prompt-command.d.ts.map +1 -0
- package/dist/commands/prompt-command.js +62 -8
- package/dist/commands/reset-command.d.ts +1 -0
- package/dist/commands/reset-command.d.ts.map +1 -0
- package/dist/commands/reset-command.js +1 -1
- package/dist/commands/rules-command.d.ts +1 -0
- package/dist/commands/rules-command.d.ts.map +1 -0
- package/dist/commands/rules-command.js +5 -3
- package/dist/commands/save-command.d.ts +1 -0
- package/dist/commands/save-command.d.ts.map +1 -0
- package/dist/commands/save-command.js +1 -1
- package/dist/commands/shell-command.d.ts +3 -0
- package/dist/commands/shell-command.d.ts.map +1 -0
- package/dist/commands/shell-command.js +60 -0
- package/dist/commands/types.d.ts +9 -6
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/usage-command.d.ts +1 -0
- package/dist/commands/usage-command.d.ts.map +1 -0
- package/dist/commands/usage-command.js +2 -3
- package/dist/config.d.ts +22 -34
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +61 -15
- package/dist/conversation-analyzer.d.ts +2 -1
- package/dist/conversation-analyzer.d.ts.map +1 -0
- package/dist/dedent.d.ts +1 -0
- package/dist/dedent.d.ts.map +1 -0
- package/dist/execution/index.d.ts +112 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +432 -0
- package/dist/formatting.d.ts +2 -13
- package/dist/formatting.d.ts.map +1 -0
- package/dist/formatting.js +5 -64
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -4
- package/dist/logger.d.ts +1 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/mentions.d.ts +4 -0
- package/dist/mentions.d.ts.map +1 -0
- package/dist/mentions.js +42 -10
- package/dist/messages.d.ts +8 -20
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +33 -53
- package/dist/middleware/audit-message.d.ts +1 -0
- package/dist/middleware/audit-message.d.ts.map +1 -0
- package/dist/middleware/index.d.ts +1 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/rate-limit.d.ts +1 -0
- package/dist/middleware/rate-limit.d.ts.map +1 -0
- package/dist/models/ai-config.d.ts +1 -0
- package/dist/models/ai-config.d.ts.map +1 -0
- package/dist/models/anthropic-provider.d.ts +1 -0
- package/dist/models/anthropic-provider.d.ts.map +1 -0
- package/dist/models/deepseek-provider.d.ts +1 -0
- package/dist/models/deepseek-provider.d.ts.map +1 -0
- package/dist/models/google-provider.d.ts +1 -0
- package/dist/models/google-provider.d.ts.map +1 -0
- package/dist/models/groq-provider.d.ts +20 -0
- package/dist/models/groq-provider.d.ts.map +1 -0
- package/dist/models/groq-provider.js +31 -0
- package/dist/models/manager.d.ts +1 -0
- package/dist/models/manager.d.ts.map +1 -0
- package/dist/models/openai-provider.d.ts +2 -1
- package/dist/models/openai-provider.d.ts.map +1 -0
- package/dist/models/openrouter-provider.d.ts +31 -22
- package/dist/models/openrouter-provider.d.ts.map +1 -0
- package/dist/models/openrouter-provider.js +115 -1
- package/dist/models/providers.d.ts +4 -5
- package/dist/models/providers.d.ts.map +1 -0
- package/dist/models/providers.js +7 -3
- package/dist/models/xai-provider.d.ts +1 -0
- package/dist/models/xai-provider.d.ts.map +1 -0
- package/dist/parsing.d.ts +2 -1
- package/dist/parsing.d.ts.map +1 -0
- package/dist/prompts/manager.d.ts +14 -2
- package/dist/prompts/manager.d.ts.map +1 -0
- package/dist/prompts.d.ts +1 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +15 -11
- package/dist/repl/display-tool-messages.d.ts +4 -0
- package/dist/repl/display-tool-messages.d.ts.map +1 -0
- package/dist/repl/display-tool-messages.js +55 -0
- package/dist/repl/display-tool-use.d.ts +14 -0
- package/dist/repl/display-tool-use.d.ts.map +1 -0
- package/dist/repl/display-tool-use.js +63 -0
- package/dist/repl/get-prompt-header.d.ts +8 -0
- package/dist/repl/get-prompt-header.d.ts.map +1 -0
- package/dist/repl/get-prompt-header.js +38 -0
- package/dist/repl/tool-call-repair.d.ts +4 -0
- package/dist/repl/tool-call-repair.d.ts.map +1 -0
- package/dist/repl/tool-call-repair.js +50 -0
- package/dist/repl-prompt.d.ts +1 -0
- package/dist/repl-prompt.d.ts.map +1 -0
- package/dist/repl.d.ts +8 -4
- package/dist/repl.d.ts.map +1 -0
- package/dist/repl.js +108 -252
- package/dist/terminal/ansi-styles.d.ts +77 -0
- package/dist/terminal/ansi-styles.d.ts.map +1 -0
- package/dist/terminal/ansi-styles.js +215 -0
- package/dist/terminal/checkbox-prompt.d.ts +36 -0
- package/dist/terminal/checkbox-prompt.d.ts.map +1 -0
- package/dist/terminal/checkbox-prompt.js +362 -0
- package/dist/terminal/default-theme.d.ts +6 -0
- package/dist/terminal/default-theme.d.ts.map +1 -0
- package/dist/terminal/default-theme.js +182 -0
- package/dist/terminal/east-asian-width.d.ts +8 -0
- package/dist/terminal/east-asian-width.d.ts.map +1 -0
- package/dist/terminal/east-asian-width.js +409 -0
- package/dist/terminal/editor-prompt.d.ts +10 -0
- package/dist/terminal/editor-prompt.d.ts.map +1 -0
- package/dist/terminal/editor-prompt.js +61 -0
- package/dist/terminal/errors.d.ts +19 -0
- package/dist/terminal/errors.d.ts.map +1 -0
- package/dist/terminal/errors.js +37 -0
- package/dist/terminal/formatting.d.ts +1 -11
- package/dist/terminal/formatting.d.ts.map +1 -0
- package/dist/terminal/formatting.js +4 -20
- package/dist/terminal/highlight/index.d.ts +53 -0
- package/dist/terminal/highlight/index.d.ts.map +1 -0
- package/dist/terminal/highlight/index.js +90 -0
- package/dist/terminal/highlight/theme.d.ts +233 -0
- package/dist/terminal/highlight/theme.d.ts.map +1 -0
- package/dist/terminal/highlight/theme.js +83 -0
- package/dist/terminal/index.d.ts +16 -9
- package/dist/terminal/index.d.ts.map +1 -0
- package/dist/terminal/index.js +42 -126
- package/dist/terminal/input-prompt.d.ts +16 -0
- package/dist/terminal/input-prompt.d.ts.map +1 -0
- package/dist/terminal/input-prompt.js +181 -0
- package/dist/terminal/markdown-utils.d.ts +1 -0
- package/dist/terminal/markdown-utils.d.ts.map +1 -0
- package/dist/terminal/markdown.d.ts +1 -0
- package/dist/terminal/markdown.d.ts.map +1 -0
- package/dist/terminal/markdown.js +17 -12
- package/dist/terminal/search-prompt.d.ts +20 -0
- package/dist/terminal/search-prompt.d.ts.map +1 -0
- package/dist/terminal/search-prompt.js +279 -0
- package/dist/terminal/select-prompt.d.ts +26 -0
- package/dist/terminal/select-prompt.d.ts.map +1 -0
- package/dist/terminal/select-prompt.js +298 -0
- package/dist/terminal/string-width.d.ts +7 -0
- package/dist/terminal/string-width.d.ts.map +1 -0
- package/dist/terminal/string-width.js +61 -0
- package/dist/terminal/strip-ansi.d.ts +2 -0
- package/dist/terminal/strip-ansi.d.ts.map +1 -0
- package/dist/terminal/strip-ansi.js +20 -0
- package/dist/terminal/style.d.ts +191 -0
- package/dist/terminal/style.d.ts.map +1 -0
- package/dist/terminal/style.js +259 -0
- package/dist/terminal/supports-color.d.ts +1 -0
- package/dist/terminal/supports-color.d.ts.map +1 -0
- package/dist/terminal/supports-hyperlinks.d.ts +1 -3
- package/dist/terminal/supports-hyperlinks.d.ts.map +1 -0
- package/dist/terminal/supports-hyperlinks.js +1 -1
- package/dist/terminal/types.d.ts +1 -37
- package/dist/terminal/types.d.ts.map +1 -0
- package/dist/terminal/wrap-ansi.d.ts +8 -0
- package/dist/terminal/wrap-ansi.d.ts.map +1 -0
- package/dist/terminal/wrap-ansi.js +190 -0
- package/dist/{token-utils.d.ts → tokens/counter.d.ts} +1 -0
- package/dist/tokens/counter.d.ts.map +1 -0
- package/dist/{token-utils.js → tokens/counter.js} +1 -1
- package/dist/tokens/manage-output.d.ts +34 -0
- package/dist/tokens/manage-output.d.ts.map +1 -0
- package/dist/tokens/manage-output.js +44 -0
- package/dist/{token-tracker.d.ts → tokens/tracker.d.ts} +1 -0
- package/dist/tokens/tracker.d.ts.map +1 -0
- package/dist/tool-executor.d.ts +28 -0
- package/dist/tool-executor.d.ts.map +1 -0
- package/dist/tool-executor.js +74 -0
- package/dist/tools/agent.d.ts +3 -2
- package/dist/tools/agent.d.ts.map +1 -0
- package/dist/tools/agent.js +7 -4
- package/dist/tools/bash-utils.d.ts +7 -0
- package/dist/tools/bash-utils.d.ts.map +1 -0
- package/dist/tools/bash-utils.js +212 -0
- package/dist/tools/bash.d.ts +9 -7
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +95 -212
- package/dist/tools/code-interpreter.d.ts +1 -1
- package/dist/tools/code-interpreter.d.ts.map +1 -0
- package/dist/tools/code-interpreter.js +31 -96
- package/dist/tools/delete-file.d.ts +5 -3
- package/dist/tools/delete-file.d.ts.map +1 -0
- package/dist/tools/delete-file.js +47 -33
- package/dist/tools/directory-tree.d.ts +10 -1
- package/dist/tools/directory-tree.d.ts.map +1 -0
- package/dist/tools/directory-tree.js +91 -8
- package/dist/tools/dynamic-tool-loader.d.ts +12 -0
- package/dist/tools/dynamic-tool-loader.d.ts.map +1 -0
- package/dist/tools/dynamic-tool-loader.js +280 -0
- package/dist/tools/dynamic-tool-parser.d.ts +20 -0
- package/dist/tools/dynamic-tool-parser.d.ts.map +1 -0
- package/dist/tools/dynamic-tool-parser.js +21 -0
- package/dist/tools/edit-file.d.ts +10 -2
- package/dist/tools/edit-file.d.ts.map +1 -0
- package/dist/tools/edit-file.js +117 -40
- package/dist/tools/file-editing-utils.d.ts +2 -0
- package/dist/tools/file-editing-utils.d.ts.map +1 -0
- package/dist/tools/file-editing-utils.js +135 -0
- package/dist/tools/filesystem-utils.d.ts +6 -21
- package/dist/tools/filesystem-utils.d.ts.map +1 -0
- package/dist/tools/filesystem-utils.js +96 -148
- package/dist/tools/git-utils.d.ts +1 -0
- package/dist/tools/git-utils.d.ts.map +1 -0
- package/dist/tools/grep.d.ts +5 -3
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +67 -27
- package/dist/tools/index.d.ts +10 -16
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +33 -22
- package/dist/tools/move-file.d.ts +1 -0
- package/dist/tools/move-file.d.ts.map +1 -0
- package/dist/tools/move-file.js +12 -5
- package/dist/tools/read-file.d.ts +2 -1
- package/dist/tools/read-file.d.ts.map +1 -0
- package/dist/tools/read-file.js +13 -6
- package/dist/tools/read-multiple-files.d.ts +2 -1
- package/dist/tools/read-multiple-files.d.ts.map +1 -0
- package/dist/tools/read-multiple-files.js +90 -9
- package/dist/tools/save-file.d.ts +5 -3
- package/dist/tools/save-file.d.ts.map +1 -0
- package/dist/tools/save-file.js +64 -36
- package/dist/tools/think.d.ts +1 -0
- package/dist/tools/think.d.ts.map +1 -0
- package/dist/tools/think.js +5 -1
- package/dist/tools/types.d.ts +14 -1
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/web-fetch.d.ts +4 -2
- package/dist/tools/web-fetch.d.ts.map +1 -0
- package/dist/tools/web-fetch.js +2 -2
- package/dist/tools/web-search.d.ts +2 -1
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +46 -11
- package/dist/utils/filesystem.d.ts +23 -0
- package/dist/utils/filesystem.d.ts.map +1 -0
- package/dist/utils/filesystem.js +140 -0
- package/dist/utils/filetype-detection.d.ts +3 -0
- package/dist/utils/filetype-detection.d.ts.map +1 -0
- package/dist/utils/filetype-detection.js +112 -0
- package/dist/utils/glob.d.ts +52 -0
- package/dist/utils/glob.d.ts.map +1 -0
- package/dist/utils/glob.js +376 -0
- package/dist/utils/ignore.d.ts +104 -0
- package/dist/utils/ignore.d.ts.map +1 -0
- package/dist/utils/ignore.js +649 -0
- package/dist/utils/process.d.ts +3 -2
- package/dist/utils/process.d.ts.map +1 -0
- package/dist/utils/process.js +17 -2
- package/dist/utils/zod-utils.d.ts +4 -0
- package/dist/utils/zod-utils.d.ts.map +1 -0
- package/dist/utils/zod-utils.js +7 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +32 -30
- package/dist/tools/command-validation.d.ts +0 -11
- package/dist/tools/command-validation.js +0 -45
- /package/dist/{token-tracker.js → tokens/tracker.js} +0 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { basename, extname } from "node:path";
|
|
2
|
+
const extensionToLanguageMap = {
|
|
3
|
+
".ts": { name: "TypeScript", codeblock: "typescript" },
|
|
4
|
+
".js": { name: "JavaScript", codeblock: "javascript" },
|
|
5
|
+
".mjs": { name: "JavaScript", codeblock: "javascript" },
|
|
6
|
+
".cjs": { name: "JavaScript", codeblock: "javascript" },
|
|
7
|
+
".jsx": { name: "JavaScript", codeblock: "javascript" },
|
|
8
|
+
".tsx": { name: "TypeScript", codeblock: "typescript" },
|
|
9
|
+
".py": { name: "Python", codeblock: "python" },
|
|
10
|
+
".java": { name: "Java", codeblock: "java" },
|
|
11
|
+
".go": { name: "Go", codeblock: "go" },
|
|
12
|
+
".rb": { name: "Ruby", codeblock: "ruby" },
|
|
13
|
+
".php": { name: "PHP", codeblock: "php" },
|
|
14
|
+
".phtml": { name: "PHP", codeblock: "php" },
|
|
15
|
+
".cs": { name: "C#", codeblock: "csharp" },
|
|
16
|
+
".cpp": { name: "C++", codeblock: "cpp" },
|
|
17
|
+
".cxx": { name: "C++", codeblock: "cpp" },
|
|
18
|
+
".cc": { name: "C++", codeblock: "cpp" },
|
|
19
|
+
".c": { name: "C", codeblock: "c" },
|
|
20
|
+
".h": { name: "C/C++", codeblock: "cpp" },
|
|
21
|
+
".hpp": { name: "C++", codeblock: "cpp" },
|
|
22
|
+
".swift": { name: "Swift", codeblock: "swift" },
|
|
23
|
+
".kt": { name: "Kotlin", codeblock: "kotlin" },
|
|
24
|
+
".rs": { name: "Rust", codeblock: "rust" },
|
|
25
|
+
".m": { name: "Objective-C", codeblock: "objectivec" },
|
|
26
|
+
".mm": { name: "Objective-C", codeblock: "objectivec" },
|
|
27
|
+
".pl": { name: "Perl", codeblock: "perl" },
|
|
28
|
+
".pm": { name: "Perl", codeblock: "perl" },
|
|
29
|
+
".lua": { name: "Lua", codeblock: "lua" },
|
|
30
|
+
".r": { name: "R", codeblock: "r" },
|
|
31
|
+
".scala": { name: "Scala", codeblock: "scala" },
|
|
32
|
+
".sc": { name: "Scala", codeblock: "scala" },
|
|
33
|
+
".sh": { name: "Shell", codeblock: "bash" },
|
|
34
|
+
".ps1": { name: "PowerShell", codeblock: "powershell" },
|
|
35
|
+
".bat": { name: "Batch", codeblock: "batch" },
|
|
36
|
+
".cmd": { name: "Batch", codeblock: "batch" },
|
|
37
|
+
".sql": { name: "SQL", codeblock: "sql" },
|
|
38
|
+
".html": { name: "HTML", codeblock: "html" },
|
|
39
|
+
".htm": { name: "HTML", codeblock: "html" },
|
|
40
|
+
".css": { name: "CSS", codeblock: "css" },
|
|
41
|
+
".less": { name: "Less", codeblock: "less" },
|
|
42
|
+
".sass": { name: "Sass", codeblock: "sass" },
|
|
43
|
+
".scss": { name: "Sass", codeblock: "scss" },
|
|
44
|
+
".json": { name: "JSON", codeblock: "json" },
|
|
45
|
+
".xml": { name: "XML", codeblock: "xml" },
|
|
46
|
+
".yaml": { name: "YAML", codeblock: "yaml" },
|
|
47
|
+
".yml": { name: "YAML", codeblock: "yaml" },
|
|
48
|
+
".md": { name: "Markdown", codeblock: "markdown" },
|
|
49
|
+
".markdown": { name: "Markdown", codeblock: "markdown" },
|
|
50
|
+
".dockerfile": { name: "Dockerfile", codeblock: "dockerfile" },
|
|
51
|
+
".vim": { name: "Vim script", codeblock: "vim" },
|
|
52
|
+
".vb": { name: "Visual Basic", codeblock: "vb" },
|
|
53
|
+
".fs": { name: "F#", codeblock: "fsharp" },
|
|
54
|
+
".clj": { name: "Clojure", codeblock: "clojure" },
|
|
55
|
+
".cljs": { name: "Clojure", codeblock: "clojure" },
|
|
56
|
+
".dart": { name: "Dart", codeblock: "dart" },
|
|
57
|
+
".ex": { name: "Elixir", codeblock: "elixir" },
|
|
58
|
+
".erl": { name: "Erlang", codeblock: "erlang" },
|
|
59
|
+
".hs": { name: "Haskell", codeblock: "haskell" },
|
|
60
|
+
".lisp": { name: "Lisp", codeblock: "lisp" },
|
|
61
|
+
".rkt": { name: "Racket", codeblock: "racket" },
|
|
62
|
+
".groovy": { name: "Groovy", codeblock: "groovy" },
|
|
63
|
+
".jl": { name: "Julia", codeblock: "julia" },
|
|
64
|
+
".tex": { name: "LaTeX", codeblock: "latex" },
|
|
65
|
+
".ino": { name: "Arduino", codeblock: "arduino" },
|
|
66
|
+
".asm": { name: "Assembly", codeblock: "asm" },
|
|
67
|
+
".s": { name: "Assembly", codeblock: "asm" },
|
|
68
|
+
".toml": { name: "TOML", codeblock: "toml" },
|
|
69
|
+
".vue": { name: "Vue", codeblock: "vue" },
|
|
70
|
+
".svelte": { name: "Svelte", codeblock: "svelte" },
|
|
71
|
+
".gohtml": { name: "Go Template", codeblock: "go" },
|
|
72
|
+
".hbs": { name: "Handlebars", codeblock: "handlebars" },
|
|
73
|
+
".ejs": { name: "EJS", codeblock: "ejs" },
|
|
74
|
+
".erb": { name: "ERB", codeblock: "erb" },
|
|
75
|
+
".jsp": { name: "JSP", codeblock: "jsp" },
|
|
76
|
+
".dockerignore": { name: "Docker", codeblock: "dockerfile" },
|
|
77
|
+
".gitignore": { name: "Git", codeblock: "gitignore" },
|
|
78
|
+
".npmignore": { name: "npm", codeblock: "npmignore" },
|
|
79
|
+
".editorconfig": { name: "EditorConfig", codeblock: "editorconfig" },
|
|
80
|
+
".prettierrc": { name: "Prettier", codeblock: "json" },
|
|
81
|
+
".eslintrc": { name: "ESLint", codeblock: "json" },
|
|
82
|
+
".babelrc": { name: "Babel", codeblock: "json" },
|
|
83
|
+
".tsconfig": { name: "TypeScript", codeblock: "json" },
|
|
84
|
+
".flow": { name: "Flow", codeblock: "flow" },
|
|
85
|
+
".graphql": { name: "GraphQL", codeblock: "graphql" },
|
|
86
|
+
".proto": { name: "Protocol Buffers", codeblock: "protobuf" },
|
|
87
|
+
".txt": { name: "Text", codeblock: "text" },
|
|
88
|
+
};
|
|
89
|
+
export function getLanguageFromFilePath(filePath) {
|
|
90
|
+
const extension = extname(filePath).toLowerCase();
|
|
91
|
+
const languageInfo = extension
|
|
92
|
+
? extensionToLanguageMap[extension]
|
|
93
|
+
: undefined;
|
|
94
|
+
if (languageInfo) {
|
|
95
|
+
return languageInfo.name;
|
|
96
|
+
}
|
|
97
|
+
const filename = basename(filePath).toLowerCase();
|
|
98
|
+
const filenameLanguageInfo = extensionToLanguageMap[`.${filename}`];
|
|
99
|
+
return filenameLanguageInfo?.name;
|
|
100
|
+
}
|
|
101
|
+
export function getCodeblockFromFilePath(filePath) {
|
|
102
|
+
const extension = extname(filePath).toLowerCase();
|
|
103
|
+
const languageInfo = extension
|
|
104
|
+
? extensionToLanguageMap[extension]
|
|
105
|
+
: undefined;
|
|
106
|
+
if (languageInfo) {
|
|
107
|
+
return languageInfo.codeblock;
|
|
108
|
+
}
|
|
109
|
+
const filename = basename(filePath).toLowerCase();
|
|
110
|
+
const filenameLanguageInfo = extensionToLanguageMap[`.${filename}`];
|
|
111
|
+
return filenameLanguageInfo?.codeblock;
|
|
112
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type Options as FastGlobOptions } from "fast-glob";
|
|
2
|
+
type ExpandDirectoriesOption = boolean | readonly string[] | {
|
|
3
|
+
files?: readonly string[];
|
|
4
|
+
extensions?: readonly string[];
|
|
5
|
+
};
|
|
6
|
+
type FastGlobOptionsWithoutCwd = Omit<FastGlobOptions, "cwd">;
|
|
7
|
+
type Options = {
|
|
8
|
+
/**
|
|
9
|
+
* If set to `true`, `glob` will automatically glob directories for you. If you define an `Array` it will only glob files that matches the patterns inside the `Array`. You can also define an `Object` with `files` and `extensions` like in the example below.
|
|
10
|
+
*
|
|
11
|
+
* Note that if you set this option to `false`, you won't get back matched directories unless you set `onlyFiles: false`.
|
|
12
|
+
*
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
15
|
+
readonly expandDirectories?: ExpandDirectoriesOption;
|
|
16
|
+
/**
|
|
17
|
+
* Respect ignore patterns in `.gitignore` files that apply to the globbed files.
|
|
18
|
+
*
|
|
19
|
+
* Performance note: This option searches for all `.gitignore` files in the entire directory tree before globbing, which can be slow. For better performance, use `ignoreFiles: '.gitignore'` to only respect the root `.gitignore` file.
|
|
20
|
+
*
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
readonly gitignore?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Glob patterns to look for ignore files, which are then used to ignore globbed files.
|
|
26
|
+
*
|
|
27
|
+
* This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files.
|
|
28
|
+
*
|
|
29
|
+
* Performance tip: Using a specific path like `'.gitignore'` is much faster than recursive patterns.
|
|
30
|
+
*
|
|
31
|
+
* @default undefined
|
|
32
|
+
*/
|
|
33
|
+
readonly ignoreFiles?: string | readonly string[];
|
|
34
|
+
/**
|
|
35
|
+
* The current working directory in which to search.
|
|
36
|
+
*
|
|
37
|
+
* @default process.cwd()
|
|
38
|
+
*/
|
|
39
|
+
readonly cwd?: URL | string;
|
|
40
|
+
} & FastGlobOptionsWithoutCwd;
|
|
41
|
+
/**
|
|
42
|
+
* Find files and directories using glob patterns.
|
|
43
|
+
*
|
|
44
|
+
* Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use `path.posix.join()` instead of `path.join()`.
|
|
45
|
+
*
|
|
46
|
+
* @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
|
|
47
|
+
* @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
|
|
48
|
+
* @returns The matching paths.
|
|
49
|
+
*/
|
|
50
|
+
export declare const glob: (patterns: string | string[] | readonly string[], options?: Options) => Promise<string[]>;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=glob.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../source/utils/glob.ts"],"names":[],"mappings":"AAIA,OAAW,EAAc,KAAK,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC;AAgB5E,KAAK,uBAAuB,GACxB,OAAO,GACP,SAAS,MAAM,EAAE,GACjB;IAAE,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAElE,KAAK,yBAAyB,GAAG,IAAI,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;AAE9D,KAAK,OAAO,GAAG;IACb;;;;;;OAMG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;IAErD;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;;;;;OAQG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IAElD;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC;CAC7B,GAAG,yBAAyB,CAAC;AA6U9B;;;;;;;;GAQG;AACH,eAAO,MAAM,IAAI,8DAtLa,OAAO,sBAoMpC,CAAC"}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import path, * as nodePath from "node:path";
|
|
4
|
+
import * as process from "node:process";
|
|
5
|
+
import fg from "fast-glob";
|
|
6
|
+
import { isDirectory, slash, toPath } from "./filesystem.js";
|
|
7
|
+
import { Ignore } from "./ignore.js";
|
|
8
|
+
// Cache for ignore patterns to avoid repeated IO
|
|
9
|
+
const ignoreCache = new Map();
|
|
10
|
+
const CACHE_TTL = 60000; // 1 minute TTL
|
|
11
|
+
const assertPatternsInput = (patterns) => {
|
|
12
|
+
if (patterns.some((pattern) => typeof pattern !== "string")) {
|
|
13
|
+
throw new TypeError("Patterns must be a string or an array of strings");
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
// Pre-compiled regexes for performance
|
|
17
|
+
const GLOBSTAR_DIRECTORY_REGEX = /\*\*\/([^/]+)$/;
|
|
18
|
+
const WILDCARD_CHARS_REGEX = /[*?[\]{}]/;
|
|
19
|
+
const EXTENSION_PATTERN_REGEX = /\.[a-zA-Z0-9]{1,5}$/;
|
|
20
|
+
const normalizePathForDirectoryGlob = (filePath, cwd) => {
|
|
21
|
+
const path = isNegativePattern(filePath) ? filePath.slice(1) : filePath;
|
|
22
|
+
return nodePath.isAbsolute(path) ? path : nodePath.join(cwd, path);
|
|
23
|
+
};
|
|
24
|
+
const shouldExpandGlobstarDirectory = (pattern) => {
|
|
25
|
+
const match = pattern?.match(GLOBSTAR_DIRECTORY_REGEX);
|
|
26
|
+
if (!match) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const dirname = match[1];
|
|
30
|
+
const hasWildcards = WILDCARD_CHARS_REGEX.test(dirname);
|
|
31
|
+
// Only consider it an extension if it looks like a file extension pattern
|
|
32
|
+
// (e.g., contains common extension chars and doesn't look like a directory name)
|
|
33
|
+
const hasExtension = EXTENSION_PATTERN_REGEX.test(dirname) && !dirname.startsWith(".");
|
|
34
|
+
return !hasWildcards && !hasExtension;
|
|
35
|
+
};
|
|
36
|
+
const getDirectoryGlob = ({ directoryPath, files, extensions, }) => {
|
|
37
|
+
const extensionGlob = extensions && extensions.length > 0
|
|
38
|
+
? `.${extensions.length > 1 ? `{${extensions.join(",")}}` : extensions[0]}`
|
|
39
|
+
: "";
|
|
40
|
+
return files
|
|
41
|
+
? files.map((file) => {
|
|
42
|
+
// Don't append extension glob if file already has wildcards, extension, or looks like a pattern
|
|
43
|
+
const hasGlobChars = /[*?[\]{}]/.test(file);
|
|
44
|
+
const hasExtension = nodePath.extname(file);
|
|
45
|
+
const shouldAppendExtension = extensionGlob && !hasGlobChars && !hasExtension;
|
|
46
|
+
return nodePath.posix.join(directoryPath, `**/${shouldAppendExtension ? `${file}${extensionGlob}` : file}`);
|
|
47
|
+
})
|
|
48
|
+
: [
|
|
49
|
+
nodePath.posix.join(directoryPath, `**${extensionGlob ? `/*${extensionGlob}` : ""}`),
|
|
50
|
+
];
|
|
51
|
+
};
|
|
52
|
+
const directoryToGlob = async (directoryPaths, { cwd = process.cwd(), files, extensions, } = {}) => {
|
|
53
|
+
const globs = await Promise.all(directoryPaths.map(async (directoryPath) => {
|
|
54
|
+
// Check pattern without negative prefix
|
|
55
|
+
const checkPattern = isNegativePattern(directoryPath)
|
|
56
|
+
? directoryPath.slice(1)
|
|
57
|
+
: directoryPath;
|
|
58
|
+
// Expand globstar directory patterns like **/dirname to **/dirname/**
|
|
59
|
+
if (shouldExpandGlobstarDirectory(checkPattern)) {
|
|
60
|
+
return getDirectoryGlob({ directoryPath, files, extensions });
|
|
61
|
+
}
|
|
62
|
+
// If pattern contains any glob wildcard, do not stat; leave as-is
|
|
63
|
+
if (/[*?[\]{}]/.test(checkPattern)) {
|
|
64
|
+
return directoryPath;
|
|
65
|
+
}
|
|
66
|
+
// Original logic for checking actual directories
|
|
67
|
+
const pathToCheck = normalizePathForDirectoryGlob(directoryPath, cwd);
|
|
68
|
+
return (await isDirectory(pathToCheck))
|
|
69
|
+
? getDirectoryGlob({ directoryPath, files, extensions })
|
|
70
|
+
: directoryPath;
|
|
71
|
+
}));
|
|
72
|
+
return globs.flat();
|
|
73
|
+
};
|
|
74
|
+
const toPatternsArray = (patterns) => {
|
|
75
|
+
const flattenedPatterns = Array.from(new Set([patterns].flat()));
|
|
76
|
+
assertPatternsInput(flattenedPatterns);
|
|
77
|
+
return flattenedPatterns;
|
|
78
|
+
};
|
|
79
|
+
const checkCwdOption = (cwd) => {
|
|
80
|
+
if (!cwd) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
let stat;
|
|
84
|
+
try {
|
|
85
|
+
stat = fs.statSync(cwd);
|
|
86
|
+
}
|
|
87
|
+
catch (_error) {
|
|
88
|
+
throw new Error(`The \`cwd\` option must point to an existing directory: ${cwd}`);
|
|
89
|
+
}
|
|
90
|
+
if (!stat.isDirectory()) {
|
|
91
|
+
throw new Error("The `cwd` option must be a path to a directory");
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const normalizeOptions = (options = {}) => {
|
|
95
|
+
const resolvedCwd = options.cwd ? toPath(options.cwd) : undefined;
|
|
96
|
+
const normalizedOptions = {
|
|
97
|
+
...options,
|
|
98
|
+
ignore: options.ignore ?? [],
|
|
99
|
+
expandDirectories: options.expandDirectories ?? true,
|
|
100
|
+
cwd: resolvedCwd,
|
|
101
|
+
};
|
|
102
|
+
if (resolvedCwd) {
|
|
103
|
+
checkCwdOption(resolvedCwd);
|
|
104
|
+
}
|
|
105
|
+
return normalizedOptions;
|
|
106
|
+
};
|
|
107
|
+
const normalizeArguments = (fn) => (patterns, options) => fn(toPatternsArray(patterns), normalizeOptions(options || {}));
|
|
108
|
+
const getIgnoreFilesPatterns = (options) => {
|
|
109
|
+
const { ignoreFiles, gitignore } = options;
|
|
110
|
+
const patterns = ignoreFiles ? toPatternsArray(ignoreFiles) : [];
|
|
111
|
+
if (gitignore) {
|
|
112
|
+
patterns.push(GITIGNORE_FILES_PATTERN);
|
|
113
|
+
}
|
|
114
|
+
return patterns;
|
|
115
|
+
};
|
|
116
|
+
const getFilter = async (options) => {
|
|
117
|
+
const ignoreFilesPatterns = getIgnoreFilesPatterns(options);
|
|
118
|
+
const isIgnoredFn = ignoreFilesPatterns.length > 0
|
|
119
|
+
? await isIgnoredByIgnoreFiles(ignoreFilesPatterns, options)
|
|
120
|
+
: false;
|
|
121
|
+
return createFilterFunction(isIgnoredFn);
|
|
122
|
+
};
|
|
123
|
+
// No-op predicate for when no ignore filtering is needed
|
|
124
|
+
const noOpPredicate = () => false;
|
|
125
|
+
const createFilterFunction = (isIgnored) => {
|
|
126
|
+
const seen = new Set();
|
|
127
|
+
const ignorePredicate = isIgnored === false ? noOpPredicate : isIgnored;
|
|
128
|
+
return (fastGlobResult) => {
|
|
129
|
+
let pathKey;
|
|
130
|
+
if (typeof fastGlobResult === "string") {
|
|
131
|
+
pathKey = fastGlobResult;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
const entry = fastGlobResult;
|
|
135
|
+
if (!entry.path) {
|
|
136
|
+
// Entry without path is invalid - skip it
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
pathKey = entry.path;
|
|
140
|
+
}
|
|
141
|
+
// Normalize to POSIX for consistent cross-platform behavior
|
|
142
|
+
pathKey = slash(nodePath.normalize(pathKey));
|
|
143
|
+
if (seen.has(pathKey) || ignorePredicate(pathKey)) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
seen.add(pathKey);
|
|
147
|
+
return true;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
const unionFastGlobResults = (results, filter) => results.flat().filter((fastGlobResult) => filter(fastGlobResult));
|
|
151
|
+
const convertNegativePatterns = (patterns, options) => {
|
|
152
|
+
const tasks = [];
|
|
153
|
+
let localPatterns = patterns;
|
|
154
|
+
while (localPatterns.length > 0) {
|
|
155
|
+
const index = localPatterns.findIndex((pattern) => isNegativePattern(pattern));
|
|
156
|
+
if (index === -1) {
|
|
157
|
+
tasks.push({ patterns: localPatterns, options });
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
const ignorePattern = localPatterns[index].slice(1);
|
|
161
|
+
// Create immutable copies for all existing tasks
|
|
162
|
+
for (let i = 0; i < tasks.length; i++) {
|
|
163
|
+
tasks[i] = {
|
|
164
|
+
...tasks[i],
|
|
165
|
+
options: {
|
|
166
|
+
...tasks[i].options,
|
|
167
|
+
ignore: [...(tasks[i].options.ignore ?? []), ignorePattern],
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (index !== 0) {
|
|
172
|
+
tasks.push({
|
|
173
|
+
patterns: localPatterns.slice(0, index),
|
|
174
|
+
options: {
|
|
175
|
+
...options,
|
|
176
|
+
ignore: [...(options.ignore ?? []), ignorePattern],
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
localPatterns = localPatterns.slice(index + 1);
|
|
181
|
+
}
|
|
182
|
+
return tasks;
|
|
183
|
+
};
|
|
184
|
+
const normalizeExpandDirectoriesOption = (options, cwd) => {
|
|
185
|
+
const result = {};
|
|
186
|
+
if (cwd) {
|
|
187
|
+
result.cwd = cwd;
|
|
188
|
+
}
|
|
189
|
+
if (Array.isArray(options)) {
|
|
190
|
+
result.files = options;
|
|
191
|
+
}
|
|
192
|
+
else if (typeof options === "object" && options !== null) {
|
|
193
|
+
if ("files" in options)
|
|
194
|
+
result.files = options.files;
|
|
195
|
+
if ("extensions" in options)
|
|
196
|
+
result.extensions = options.extensions;
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
};
|
|
200
|
+
const generateTasks = async (patterns, options) => {
|
|
201
|
+
const globTasks = convertNegativePatterns(patterns, options);
|
|
202
|
+
const { cwd, expandDirectories } = options;
|
|
203
|
+
if (!expandDirectories) {
|
|
204
|
+
return globTasks;
|
|
205
|
+
}
|
|
206
|
+
const directoryToGlobOptions = normalizeExpandDirectoriesOption(expandDirectories, cwd ? toPath(cwd) : cwd);
|
|
207
|
+
return Promise.all(globTasks.map(async (task) => {
|
|
208
|
+
let { patterns, options } = task;
|
|
209
|
+
[patterns, options.ignore] = await Promise.all([
|
|
210
|
+
directoryToGlob(patterns, directoryToGlobOptions),
|
|
211
|
+
directoryToGlob(options.ignore, {
|
|
212
|
+
cwd: cwd ? toPath(cwd) : cwd,
|
|
213
|
+
}),
|
|
214
|
+
]);
|
|
215
|
+
return { patterns, options };
|
|
216
|
+
}));
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Find files and directories using glob patterns.
|
|
220
|
+
*
|
|
221
|
+
* Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use `path.posix.join()` instead of `path.join()`.
|
|
222
|
+
*
|
|
223
|
+
* @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
|
|
224
|
+
* @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
|
|
225
|
+
* @returns The matching paths.
|
|
226
|
+
*/
|
|
227
|
+
export const glob = normalizeArguments(async (patterns, options) => {
|
|
228
|
+
const [tasks, filter] = await Promise.all([
|
|
229
|
+
generateTasks(patterns, options),
|
|
230
|
+
getFilter(options),
|
|
231
|
+
]);
|
|
232
|
+
const results = await Promise.all(tasks.map((task) => fg(task.patterns, convertOptionsForFastGlob(task.options))));
|
|
233
|
+
return unionFastGlobResults(results, filter);
|
|
234
|
+
});
|
|
235
|
+
// Helper function to convert our Options to fast-glob compatible options
|
|
236
|
+
const convertOptionsForFastGlob = (options) => {
|
|
237
|
+
const { cwd, ...rest } = options;
|
|
238
|
+
return {
|
|
239
|
+
...rest,
|
|
240
|
+
cwd: cwd ? toPath(cwd) : undefined,
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
const defaultIgnoredDirectories = [
|
|
244
|
+
"**/node_modules",
|
|
245
|
+
"**/flow-typed",
|
|
246
|
+
"**/coverage",
|
|
247
|
+
"**/.git",
|
|
248
|
+
];
|
|
249
|
+
const ignoreFilesGlobOptions = {
|
|
250
|
+
absolute: true,
|
|
251
|
+
dot: true,
|
|
252
|
+
};
|
|
253
|
+
const GITIGNORE_FILES_PATTERN = "**/.gitignore";
|
|
254
|
+
// Apply base path to gitignore patterns based on .gitignore spec 2.22.1
|
|
255
|
+
// https://git-scm.com/docs/gitignore#_pattern_format
|
|
256
|
+
// See also https://github.com/sindresorhus/globby/issues/146
|
|
257
|
+
const applyBaseToPattern = (pattern, base) => {
|
|
258
|
+
if (!base) {
|
|
259
|
+
return pattern;
|
|
260
|
+
}
|
|
261
|
+
const isNegative = isNegativePattern(pattern);
|
|
262
|
+
const cleanPattern = isNegative ? pattern.slice(1) : pattern;
|
|
263
|
+
// Check if pattern has non-trailing slashes
|
|
264
|
+
const slashIndex = cleanPattern.indexOf("/");
|
|
265
|
+
const hasNonTrailingSlash = slashIndex !== -1 && slashIndex !== cleanPattern.length - 1;
|
|
266
|
+
let result;
|
|
267
|
+
if (!hasNonTrailingSlash) {
|
|
268
|
+
// "If there is no separator at the beginning or middle of the pattern,
|
|
269
|
+
// then the pattern may also match at any level below the .gitignore level."
|
|
270
|
+
// So patterns like '*.log' or 'temp' or 'build/' (trailing slash) match recursively.
|
|
271
|
+
result = path.posix.join(base, "**", cleanPattern);
|
|
272
|
+
}
|
|
273
|
+
else if (cleanPattern.startsWith("/")) {
|
|
274
|
+
// "If there is a separator at the beginning [...] of the pattern,
|
|
275
|
+
// then the pattern is relative to the directory level of the particular .gitignore file itself."
|
|
276
|
+
// Leading slash anchors the pattern to the .gitignore's directory.
|
|
277
|
+
result = path.posix.join(base, cleanPattern.slice(1));
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
// "If there is a separator [...] middle [...] of the pattern,
|
|
281
|
+
// then the pattern is relative to the directory level of the particular .gitignore file itself."
|
|
282
|
+
// Patterns like 'src/foo' are relative to the .gitignore's directory.
|
|
283
|
+
result = path.posix.join(base, cleanPattern);
|
|
284
|
+
}
|
|
285
|
+
return isNegative ? `!${result}` : result;
|
|
286
|
+
};
|
|
287
|
+
const parseIgnoreFile = (file, cwd) => {
|
|
288
|
+
const base = slash(path.relative(cwd, path.dirname(file.filePath)));
|
|
289
|
+
const patterns = [];
|
|
290
|
+
for (const raw of file.content.split(/\r?\n/)) {
|
|
291
|
+
if (raw === "")
|
|
292
|
+
continue; // blank line
|
|
293
|
+
if (raw.startsWith("#"))
|
|
294
|
+
continue; // comment line (only when not escaped)
|
|
295
|
+
const line = raw; // preserve escapes like \# and \ for Ignore engine
|
|
296
|
+
patterns.push(applyBaseToPattern(line, base));
|
|
297
|
+
}
|
|
298
|
+
return patterns;
|
|
299
|
+
};
|
|
300
|
+
const toRelativePath = (fileOrDirectory, cwd) => {
|
|
301
|
+
const abs = path.isAbsolute(fileOrDirectory)
|
|
302
|
+
? fileOrDirectory
|
|
303
|
+
: path.resolve(cwd, fileOrDirectory);
|
|
304
|
+
const rel = path.relative(cwd, abs);
|
|
305
|
+
if (rel.startsWith("..") || path.isAbsolute(rel))
|
|
306
|
+
return undefined;
|
|
307
|
+
return rel.startsWith("./") ? rel.slice(2) : rel;
|
|
308
|
+
};
|
|
309
|
+
const getIsIgnoredPredicate = (files, cwd) => {
|
|
310
|
+
// Sort files by path depth (ascending) so deeper .gitignore files override shallower ones
|
|
311
|
+
const sortedFiles = [...files].sort((a, b) => {
|
|
312
|
+
const depthA = a.filePath.split(nodePath.sep).length;
|
|
313
|
+
const depthB = b.filePath.split(nodePath.sep).length;
|
|
314
|
+
return depthA - depthB;
|
|
315
|
+
});
|
|
316
|
+
// Generate cache key using file paths + content hash
|
|
317
|
+
const hashString = (s) => {
|
|
318
|
+
// FNV-1a 32-bit
|
|
319
|
+
let h = 0x811c9dc5;
|
|
320
|
+
for (let i = 0; i < s.length; i++) {
|
|
321
|
+
h ^= s.charCodeAt(i);
|
|
322
|
+
h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24);
|
|
323
|
+
}
|
|
324
|
+
// force to uint32 and hex
|
|
325
|
+
return (h >>> 0).toString(16);
|
|
326
|
+
};
|
|
327
|
+
const cacheKey = `${cwd}|` +
|
|
328
|
+
sortedFiles.map((f) => `${f.filePath}:${hashString(f.content)}`).join("|");
|
|
329
|
+
const now = Date.now();
|
|
330
|
+
const cached = ignoreCache.get(cacheKey);
|
|
331
|
+
let patterns;
|
|
332
|
+
if (cached && now - cached.timestamp < CACHE_TTL) {
|
|
333
|
+
patterns = cached.patterns;
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
patterns = sortedFiles.flatMap((file) => parseIgnoreFile(file, cwd));
|
|
337
|
+
ignoreCache.set(cacheKey, { patterns, timestamp: now });
|
|
338
|
+
}
|
|
339
|
+
const ignoreInstance = new Ignore().add(patterns);
|
|
340
|
+
return (fileOrDirectory) => {
|
|
341
|
+
let fileOrDirectoryAsPath = toPath(fileOrDirectory);
|
|
342
|
+
fileOrDirectoryAsPath = toRelativePath(fileOrDirectoryAsPath, cwd);
|
|
343
|
+
// If path is outside cwd (undefined), it can't be ignored by patterns in cwd
|
|
344
|
+
if (fileOrDirectoryAsPath === undefined) {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
return fileOrDirectoryAsPath
|
|
348
|
+
? ignoreInstance.ignores(slash(fileOrDirectoryAsPath))
|
|
349
|
+
: false;
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
const normalizeIgnoreOptions = (options = {}) => ({
|
|
353
|
+
cwd: options.cwd ? toPath(options.cwd) : process.cwd(),
|
|
354
|
+
suppressErrors: Boolean(options.suppressErrors),
|
|
355
|
+
deep: typeof options.deep === "number" ? options.deep : Number.POSITIVE_INFINITY,
|
|
356
|
+
ignore: [...(options.ignore ?? []), ...defaultIgnoredDirectories],
|
|
357
|
+
});
|
|
358
|
+
const isIgnoredByIgnoreFiles = async (patterns, options) => {
|
|
359
|
+
const { cwd, suppressErrors, deep, ignore } = normalizeIgnoreOptions(options);
|
|
360
|
+
const paths = await fg(patterns, {
|
|
361
|
+
cwd,
|
|
362
|
+
suppressErrors,
|
|
363
|
+
deep,
|
|
364
|
+
ignore: ignore,
|
|
365
|
+
...ignoreFilesGlobOptions,
|
|
366
|
+
});
|
|
367
|
+
const files = await Promise.all(paths.map(async (filePath) => ({
|
|
368
|
+
filePath,
|
|
369
|
+
content: await readFile(filePath, "utf8"),
|
|
370
|
+
})));
|
|
371
|
+
return getIsIgnoredPredicate(files, cwd);
|
|
372
|
+
};
|
|
373
|
+
/**
|
|
374
|
+
* Check if a pattern is negative (starts with '!')
|
|
375
|
+
*/
|
|
376
|
+
const isNegativePattern = (pattern) => pattern[0] === "!";
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modern TypeScript implementation of node-ignore
|
|
3
|
+
* Based on https://github.com/kaelzhang/node-ignore
|
|
4
|
+
*/
|
|
5
|
+
interface TestResult {
|
|
6
|
+
ignored: boolean;
|
|
7
|
+
unignored: boolean;
|
|
8
|
+
rule?: IgnoreRule;
|
|
9
|
+
}
|
|
10
|
+
interface PatternObject {
|
|
11
|
+
pattern: string;
|
|
12
|
+
mark?: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare class IgnoreRule {
|
|
15
|
+
readonly pattern: string;
|
|
16
|
+
readonly mark?: boolean;
|
|
17
|
+
readonly negative: boolean;
|
|
18
|
+
private readonly ignoreCase;
|
|
19
|
+
private readonly regexPrefix;
|
|
20
|
+
private _regex?;
|
|
21
|
+
private _checkRegex?;
|
|
22
|
+
constructor(pattern: string, mark: boolean | undefined, _body: string, ignoreCase: boolean, negative: boolean, regexPrefix: string);
|
|
23
|
+
get regex(): RegExp;
|
|
24
|
+
get checkRegex(): RegExp;
|
|
25
|
+
private compileRegex;
|
|
26
|
+
}
|
|
27
|
+
interface IgnoreOptions {
|
|
28
|
+
ignorecase?: boolean;
|
|
29
|
+
ignoreCase?: boolean;
|
|
30
|
+
allowRelativePaths?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare class Ignore {
|
|
33
|
+
private readonly _rules;
|
|
34
|
+
private readonly _strictPathCheck;
|
|
35
|
+
private _ignoreCache;
|
|
36
|
+
private _testCache;
|
|
37
|
+
/**
|
|
38
|
+
* Create a new Ignore instance
|
|
39
|
+
* @param options - Configuration options
|
|
40
|
+
* @param options.ignorecase - Whether to use case-insensitive matching (default: true)
|
|
41
|
+
* @param options.ignoreCase - Alias for ignorecase
|
|
42
|
+
* @param options.allowRelativePaths - Allow relative paths like './' and '../' (default: false)
|
|
43
|
+
*/
|
|
44
|
+
constructor({ ignorecase, ignoreCase, allowRelativePaths, }?: IgnoreOptions);
|
|
45
|
+
private _initCache;
|
|
46
|
+
/**
|
|
47
|
+
* Clear all internal caches
|
|
48
|
+
*/
|
|
49
|
+
clearCache(): this;
|
|
50
|
+
/**
|
|
51
|
+
* Add ignore patterns
|
|
52
|
+
* @param pattern - Pattern(s) to add
|
|
53
|
+
* @returns This instance for chaining
|
|
54
|
+
*/
|
|
55
|
+
add(pattern: string | string[] | Ignore | PatternObject): this;
|
|
56
|
+
/**
|
|
57
|
+
* Legacy alias for add()
|
|
58
|
+
* @deprecated Use add() instead
|
|
59
|
+
*/
|
|
60
|
+
addPattern(pattern: string | string[] | Ignore | PatternObject): this;
|
|
61
|
+
private _test;
|
|
62
|
+
/**
|
|
63
|
+
* Check if a path is ignored (Git check-ignore compatible)
|
|
64
|
+
* @param path - The path to check
|
|
65
|
+
* @returns TestResult with ignored status and matched rule
|
|
66
|
+
*/
|
|
67
|
+
checkIgnore(path: string): TestResult;
|
|
68
|
+
private _t;
|
|
69
|
+
/**
|
|
70
|
+
* Check if a path is ignored
|
|
71
|
+
* @param path - The path to check
|
|
72
|
+
* @returns True if the path is ignored
|
|
73
|
+
*/
|
|
74
|
+
ignores(path: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Create a filter function that returns true for non-ignored paths
|
|
77
|
+
* @returns Filter function
|
|
78
|
+
*/
|
|
79
|
+
createFilter(): (path: string) => boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Filter an array of paths, returning only non-ignored paths
|
|
82
|
+
* @param paths - Paths to filter
|
|
83
|
+
* @returns Array of non-ignored paths
|
|
84
|
+
*/
|
|
85
|
+
filter(paths: string | string[]): string[];
|
|
86
|
+
/**
|
|
87
|
+
* Test if a path is ignored
|
|
88
|
+
* @param path - The path to test
|
|
89
|
+
* @returns TestResult with ignored status and matched rule
|
|
90
|
+
*/
|
|
91
|
+
test(path: string): TestResult;
|
|
92
|
+
/**
|
|
93
|
+
* Compile a pattern to a regular expression
|
|
94
|
+
* @param pattern - The pattern to compile
|
|
95
|
+
* @returns Compiled regular expression
|
|
96
|
+
*/
|
|
97
|
+
compile(pattern: string): RegExp;
|
|
98
|
+
}
|
|
99
|
+
declare const factory: {
|
|
100
|
+
(options?: IgnoreOptions): Ignore;
|
|
101
|
+
default: /*elided*/ any;
|
|
102
|
+
};
|
|
103
|
+
export default factory;
|
|
104
|
+
//# sourceMappingURL=ignore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ignore.d.ts","sourceRoot":"","sources":["../../source/utils/ignore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqWH,UAAU,UAAU;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,UAAU,aAAa;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,cAAM,UAAU;IACd,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,SAAgB,IAAI,CAAC,EAAE,OAAO,CAAC;IAC/B,SAAgB,QAAQ,EAAE,OAAO,CAAC;IAElC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAU;IACrC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IAGrC,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,WAAW,CAAC,CAAS;gBAG3B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,OAAO,GAAG,SAAS,EACzB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,OAAO,EACnB,QAAQ,EAAE,OAAO,EACjB,WAAW,EAAE,MAAM;IASrB,IAAI,KAAK,IAAI,MAAM,CAKlB;IAED,IAAI,UAAU,IAAI,MAAM,CAKvB;IAED,OAAO,CAAC,YAAY;CAWrB;AA0MD,UAAU,aAAa;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IACrC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAU;IAC3C,OAAO,CAAC,YAAY,CAAkC;IACtD,OAAO,CAAC,UAAU,CAAkC;IAEpD;;;;;;OAMG;gBACS,EACV,UAAiB,EACjB,UAAuB,EACvB,kBAA0B,GAC3B,GAAE,aAAkB;IASrB,OAAO,CAAC,UAAU;IAQlB;;OAEG;IACH,UAAU,IAAI,IAAI;IAKlB;;;;OAIG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,aAAa,GAAG,IAAI;IAW9D;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,aAAa,GAAG,IAAI;IAKrE,OAAO,CAAC,KAAK;IAuBb;;;;OAIG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU;IA0BrC,OAAO,CAAC,EAAE;IAgDV;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9B;;;OAGG;IACH,YAAY,IAAI,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO;IAIzC;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE;IAI1C;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU;IAI9B;;;;OAIG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CAKjC;AAED,QAAA,MAAM,OAAO;eAAc,aAAa,GAAG,MAAM;;CAAuB,CAAC;AA6BzE,eAAe,OAAO,CAAC"}
|