@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,649 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modern TypeScript implementation of node-ignore
|
|
3
|
+
* Based on https://github.com/kaelzhang/node-ignore
|
|
4
|
+
*/
|
|
5
|
+
// A simple implementation of make-array
|
|
6
|
+
function makeArray(subject) {
|
|
7
|
+
return Array.isArray(subject) ? subject : [subject];
|
|
8
|
+
}
|
|
9
|
+
const SPACE = " ";
|
|
10
|
+
const ESCAPE = "\\";
|
|
11
|
+
const REGEX_TEST_BLANK_LINE = /^\s+$/;
|
|
12
|
+
const REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
|
|
13
|
+
const REGEX_REPLACE_LEADING_ESCAPED_EXCLAMATION = /^\\!/;
|
|
14
|
+
const REGEX_REPLACE_LEADING_ESCAPED_HASH = /^\\#/;
|
|
15
|
+
const REGEX_SPLITALL_CRLF = /\r?\n/g;
|
|
16
|
+
// Invalid:
|
|
17
|
+
// - /foo,
|
|
18
|
+
// - ./foo,
|
|
19
|
+
// - ../foo,
|
|
20
|
+
// - .
|
|
21
|
+
// - ..
|
|
22
|
+
// Valid:
|
|
23
|
+
// - .foo
|
|
24
|
+
const REGEX_TEST_INVALID_PATH = /^(?:\/|\.{1,2}(?:\/|$))/;
|
|
25
|
+
const REGEX_TEST_TRAILING_SLASH = /\/$/;
|
|
26
|
+
const SLASH = "/";
|
|
27
|
+
// Do not use ternary expression here
|
|
28
|
+
let TmpKeyIgnore = "node-ignore";
|
|
29
|
+
if (typeof Symbol !== "undefined") {
|
|
30
|
+
TmpKeyIgnore = Symbol.for("node-ignore");
|
|
31
|
+
}
|
|
32
|
+
const KEY_IGNORE = TmpKeyIgnore;
|
|
33
|
+
const REGEX_REGEXP_RANGE = /([A-Za-z0-9])-([A-Za-z0-9])/g;
|
|
34
|
+
const RETURN_FALSE = () => false;
|
|
35
|
+
// Sanitize the range of a regular expression
|
|
36
|
+
// The cases are complicated, see test cases for details
|
|
37
|
+
const sanitizeRange = (range) => range.replace(REGEX_REGEXP_RANGE, (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0)
|
|
38
|
+
? match
|
|
39
|
+
: // Invalid range (out of order) which is ok for gitignore rules but
|
|
40
|
+
// fatal for JavaScript regular expression, so eliminate it.
|
|
41
|
+
"");
|
|
42
|
+
// See fixtures #59
|
|
43
|
+
const cleanRangeBackSlash = (slashes) => {
|
|
44
|
+
const { length } = slashes;
|
|
45
|
+
return slashes.slice(0, length - (length % 2));
|
|
46
|
+
};
|
|
47
|
+
// > If the pattern ends with a slash,
|
|
48
|
+
// > it is removed for the purpose of the following description,
|
|
49
|
+
// > but it would only find a match with a directory.
|
|
50
|
+
// > In other words, foo/ will match a directory foo and paths underneath it,
|
|
51
|
+
// > but will not match a regular file or a symbolic link foo
|
|
52
|
+
// > (this is consistent with the way how pathspec works in general in Git).
|
|
53
|
+
// '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
|
|
54
|
+
// -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
|
|
55
|
+
// you could use option `mark: true` with `glob`
|
|
56
|
+
// '`foo/`' should not continue with the '`..`'
|
|
57
|
+
const REPLACERS = [
|
|
58
|
+
[
|
|
59
|
+
// Remove BOM
|
|
60
|
+
// TODO:
|
|
61
|
+
// Other similar zero-width characters?
|
|
62
|
+
/^\uFEFF/,
|
|
63
|
+
() => "",
|
|
64
|
+
],
|
|
65
|
+
// > Trailing spaces are ignored unless they are quoted with backslash ("\\")
|
|
66
|
+
[
|
|
67
|
+
// (a\ ) -> (a )
|
|
68
|
+
// (a ) -> (a)
|
|
69
|
+
// (a ) -> (a)
|
|
70
|
+
// (a \ ) -> (a )
|
|
71
|
+
/((?:\\\\)*?)(\\?\s+)$/,
|
|
72
|
+
(_, m1, m2) => m1 + (m2.indexOf("\\") === 0 ? SPACE : ""),
|
|
73
|
+
],
|
|
74
|
+
// Replace (\ ) with ' '
|
|
75
|
+
// (\ ) -> ' '
|
|
76
|
+
// (\\ ) -> '\\ '
|
|
77
|
+
// (\\\ ) -> '\\ '
|
|
78
|
+
[
|
|
79
|
+
/(\\+?)\s/g,
|
|
80
|
+
(_, m1) => {
|
|
81
|
+
const { length } = m1;
|
|
82
|
+
return m1.slice(0, length - (length % 2)) + SPACE;
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
// Escape metacharacters
|
|
86
|
+
// which is written down by users but means special for regular expressions.
|
|
87
|
+
// > There are 12 characters with special meanings:
|
|
88
|
+
// > - the backslash \,
|
|
89
|
+
// > - the caret ^,
|
|
90
|
+
// > - the dollar sign $,
|
|
91
|
+
// > - the period or dot .,
|
|
92
|
+
// > - the vertical bar or pipe symbol |,
|
|
93
|
+
// > - the question mark ?,
|
|
94
|
+
// > - the asterisk or star *,
|
|
95
|
+
// > - the plus sign +,
|
|
96
|
+
// > - the opening parenthesis (,
|
|
97
|
+
// > - the closing parenthesis ),
|
|
98
|
+
// > - and the opening square bracket [,
|
|
99
|
+
// > - the opening curly brace {,
|
|
100
|
+
// > These special characters are often called "metacharacters".
|
|
101
|
+
[/[\\$.|*+(){^]/g, (match) => `\\${match}`],
|
|
102
|
+
[
|
|
103
|
+
// > a question mark (?) matches a single character
|
|
104
|
+
/(?!\\)\?/g,
|
|
105
|
+
() => "[^/]",
|
|
106
|
+
],
|
|
107
|
+
// leading slash
|
|
108
|
+
[
|
|
109
|
+
// > A leading slash matches the beginning of the pathname.
|
|
110
|
+
// > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
|
|
111
|
+
// A leading slash matches the beginning of the pathname
|
|
112
|
+
/^\//,
|
|
113
|
+
() => "^",
|
|
114
|
+
],
|
|
115
|
+
// replace special metacharacter slash after the leading slash
|
|
116
|
+
[/\//g, () => "\\/"],
|
|
117
|
+
[
|
|
118
|
+
// > A leading "**" followed by a slash means match in all directories.
|
|
119
|
+
// > For example, "**/foo" matches file or directory "foo" anywhere,
|
|
120
|
+
// > the same as pattern "foo".
|
|
121
|
+
// > "**/foo/bar" matches file or directory "bar" anywhere that is directly
|
|
122
|
+
// > under directory "foo".
|
|
123
|
+
// Notice that the '*'s have been replaced as '\\*'
|
|
124
|
+
/^\^*\\\*\\\*\\\//,
|
|
125
|
+
// '**/foo' <-> 'foo'
|
|
126
|
+
() => "^(?:.*\\/)?",
|
|
127
|
+
],
|
|
128
|
+
// starting
|
|
129
|
+
[
|
|
130
|
+
// there will be no leading '/'
|
|
131
|
+
// (which has been replaced by section "leading slash")
|
|
132
|
+
// If starts with '**', adding a '^' to the regular expression also works
|
|
133
|
+
/^(?=[^^])/,
|
|
134
|
+
(pattern) => {
|
|
135
|
+
// If has a slash `/` at the beginning or middle
|
|
136
|
+
return !/\/(?!$)/.test(pattern)
|
|
137
|
+
? // > Prior to 2.22.1
|
|
138
|
+
// > If the pattern does not contain a slash /,
|
|
139
|
+
// > Git treats it as a shell glob pattern
|
|
140
|
+
// Actually, if there is only a trailing slash,
|
|
141
|
+
// git also treats it as a shell glob pattern
|
|
142
|
+
// After 2.22.1 (compatible but clearer)
|
|
143
|
+
// > If there is a separator at the beginning or middle (or both)
|
|
144
|
+
// > of the pattern, then the pattern is relative to the directory
|
|
145
|
+
// > level of the particular .gitignore file itself.
|
|
146
|
+
// > Otherwise the pattern may also match at any level below
|
|
147
|
+
// > the .gitignore level.
|
|
148
|
+
"(?:^|/)"
|
|
149
|
+
: // > Otherwise, Git treats the pattern as a shell glob suitable for
|
|
150
|
+
// > consumption by fnmatch(3)
|
|
151
|
+
"^";
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
// two globstars
|
|
155
|
+
[
|
|
156
|
+
// Use lookahead assertions so that we could match more than one `'/**'`
|
|
157
|
+
/\\\/\\\*\\\*(?=\\\/|$)/g,
|
|
158
|
+
// Zero, one or several directories
|
|
159
|
+
// should not use '*', or it will be replaced by the next replacer
|
|
160
|
+
// Check if it is not the last `'/**'`
|
|
161
|
+
(_, index, str) => Number(index) + 6 < str.length
|
|
162
|
+
? // case: /**/
|
|
163
|
+
// > A slash followed by two consecutive asterisks then a slash matches
|
|
164
|
+
// > zero or more directories.
|
|
165
|
+
// > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
|
|
166
|
+
// '/**/'
|
|
167
|
+
"(?:\\/[^\\/]+)*"
|
|
168
|
+
: // case: /**
|
|
169
|
+
// > A trailing `"/**"` matches everything inside.
|
|
170
|
+
// #21: everything inside but it should not include the current folder
|
|
171
|
+
"\\/.+",
|
|
172
|
+
],
|
|
173
|
+
// normal intermediate wildcards
|
|
174
|
+
[
|
|
175
|
+
// Never replace escaped '*'
|
|
176
|
+
// ignore rule '\*' will match the path '*'
|
|
177
|
+
// 'abc.*/' -> go
|
|
178
|
+
// 'abc.*' -> skip this rule,
|
|
179
|
+
// coz trailing single wildcard will be handed by [trailing wildcard]
|
|
180
|
+
/(^|[^\\]+)(\\\*)+(?=.+)/g,
|
|
181
|
+
// '*.js' matches '.js'
|
|
182
|
+
// '*.js' doesn't match 'abc'
|
|
183
|
+
(_, p1, p2) => {
|
|
184
|
+
// 1.
|
|
185
|
+
// > An asterisk "*" matches anything except a slash.
|
|
186
|
+
// 2.
|
|
187
|
+
// > Other consecutive asterisks are considered regular asterisks
|
|
188
|
+
// > and will match according to the previous rules.
|
|
189
|
+
const unescaped = p2.replace(/\\\*/g, "[^\\/]*");
|
|
190
|
+
return p1 + unescaped;
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
[
|
|
194
|
+
// unescape, revert step 3 except for back slash
|
|
195
|
+
// For example, if a user escape a '\\*',
|
|
196
|
+
// after step 3, the result will be '\\\\\\*'
|
|
197
|
+
/\\\\\\\\(?=[$.|*+(){^])/g,
|
|
198
|
+
() => ESCAPE,
|
|
199
|
+
],
|
|
200
|
+
[
|
|
201
|
+
// '\\\\' -> '\\'
|
|
202
|
+
/\\\\/g,
|
|
203
|
+
() => ESCAPE,
|
|
204
|
+
],
|
|
205
|
+
[
|
|
206
|
+
// > The range notation, e.g. [a-zA-Z],
|
|
207
|
+
// > can be used to match one of the characters in a range.
|
|
208
|
+
// `\` is escaped by step 3
|
|
209
|
+
/(\\)?\[([^\]/]*?)(\\*)($|\])/g,
|
|
210
|
+
(_, leadEscape, range, endEscape, close) => leadEscape === ESCAPE
|
|
211
|
+
? // '\\[bar]' -> '\\\\[bar\\]'
|
|
212
|
+
`\\[${range}${cleanRangeBackSlash(endEscape)}${close}`
|
|
213
|
+
: close === "]"
|
|
214
|
+
? endEscape.length % 2 === 0
|
|
215
|
+
? // A normal case, and it is a range notation
|
|
216
|
+
// '[bar]'
|
|
217
|
+
// '[bar\\\\]'
|
|
218
|
+
`[${sanitizeRange(range)}${endEscape}]`
|
|
219
|
+
: // Invalid range notaton
|
|
220
|
+
// '[bar\\]' -> '[bar\\\\]'
|
|
221
|
+
"[]"
|
|
222
|
+
: "[]",
|
|
223
|
+
],
|
|
224
|
+
// ending
|
|
225
|
+
[
|
|
226
|
+
// 'js' will not match 'js.'
|
|
227
|
+
// 'ab' will not match 'abc'
|
|
228
|
+
/(?:[^*])$/,
|
|
229
|
+
// WTF!
|
|
230
|
+
// https://git-scm.com/docs/gitignore
|
|
231
|
+
// changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
|
|
232
|
+
// which re-fixes #24, #38
|
|
233
|
+
// > If there is a separator at the end of the pattern then the pattern
|
|
234
|
+
// > will only match directories, otherwise the pattern can match both
|
|
235
|
+
// > files and directories.
|
|
236
|
+
// 'js*' will not match 'a.js'
|
|
237
|
+
// 'js/' will not match 'a.js'
|
|
238
|
+
// 'js' will match 'a.js' and 'a.js/'
|
|
239
|
+
(match) => /\/$/.test(match)
|
|
240
|
+
? // foo/ will not match 'foo'
|
|
241
|
+
`${match}$`
|
|
242
|
+
: // foo matches 'foo' and 'foo/'
|
|
243
|
+
`${match}(?=$|\\/$)`,
|
|
244
|
+
],
|
|
245
|
+
];
|
|
246
|
+
// Freeze REPLACERS to prevent accidental mutation and help VMs optimize constants
|
|
247
|
+
Object.freeze(REPLACERS);
|
|
248
|
+
const REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\\\*$/;
|
|
249
|
+
const MODE_IGNORE = "regex";
|
|
250
|
+
const MODE_CHECK_IGNORE = "checkRegex";
|
|
251
|
+
const TRAILING_WILD_CARD_REPLACERS = {
|
|
252
|
+
[MODE_IGNORE](_, p1) {
|
|
253
|
+
const prefix = p1
|
|
254
|
+
? // '\\^':
|
|
255
|
+
// '/*' does not match EMPTY
|
|
256
|
+
// '/*' does not match everything
|
|
257
|
+
// '\\\/':
|
|
258
|
+
// 'abc/*' does not match 'abc/'
|
|
259
|
+
`${p1}[^/]+`
|
|
260
|
+
: // 'a*' matches 'a'
|
|
261
|
+
// 'a*' matches 'aa'
|
|
262
|
+
"[^/]*";
|
|
263
|
+
return `${prefix}(?=$|\\/$)`;
|
|
264
|
+
},
|
|
265
|
+
[MODE_CHECK_IGNORE](_, p1) {
|
|
266
|
+
// When doing `git check-ignore`
|
|
267
|
+
const prefix = p1
|
|
268
|
+
? // '\\\/':
|
|
269
|
+
// 'abc/*' DOES match 'abc/' !
|
|
270
|
+
`${p1}[^/]*`
|
|
271
|
+
: // 'a*' matches 'a'
|
|
272
|
+
// 'a*' matches 'aa'
|
|
273
|
+
"[^/]*";
|
|
274
|
+
return `${prefix}(?=$|\\/$)`;
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
// @param {pattern}
|
|
278
|
+
const makeRegexPrefix = (pattern) => REPLACERS.reduce((prev, [matcher, replacer]) => prev.replace(matcher, (match, ...args) => replacer(match, ...args, pattern)), pattern);
|
|
279
|
+
const isString = (subject) => typeof subject === "string";
|
|
280
|
+
// > A blank line matches no files, so it can serve as a separator for readability.
|
|
281
|
+
const checkPattern = (pattern) => !!pattern &&
|
|
282
|
+
isString(pattern) &&
|
|
283
|
+
!REGEX_TEST_BLANK_LINE.test(pattern) &&
|
|
284
|
+
!REGEX_INVALID_TRAILING_BACKSLASH.test(pattern) &&
|
|
285
|
+
// > A line starting with # serves as a comment.
|
|
286
|
+
pattern.indexOf("#") !== 0;
|
|
287
|
+
const splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
|
|
288
|
+
class IgnoreRule {
|
|
289
|
+
pattern;
|
|
290
|
+
mark;
|
|
291
|
+
negative;
|
|
292
|
+
ignoreCase;
|
|
293
|
+
regexPrefix;
|
|
294
|
+
// Simple private cache properties
|
|
295
|
+
_regex;
|
|
296
|
+
_checkRegex;
|
|
297
|
+
constructor(pattern, mark, _body, ignoreCase, negative, regexPrefix) {
|
|
298
|
+
this.pattern = pattern;
|
|
299
|
+
this.mark = mark;
|
|
300
|
+
this.ignoreCase = ignoreCase;
|
|
301
|
+
this.negative = negative;
|
|
302
|
+
this.regexPrefix = regexPrefix;
|
|
303
|
+
}
|
|
304
|
+
get regex() {
|
|
305
|
+
if (!this._regex) {
|
|
306
|
+
this._regex = this.compileRegex("regex");
|
|
307
|
+
}
|
|
308
|
+
return this._regex;
|
|
309
|
+
}
|
|
310
|
+
get checkRegex() {
|
|
311
|
+
if (!this._checkRegex) {
|
|
312
|
+
this._checkRegex = this.compileRegex("checkRegex");
|
|
313
|
+
}
|
|
314
|
+
return this._checkRegex;
|
|
315
|
+
}
|
|
316
|
+
compileRegex(mode) {
|
|
317
|
+
const str = this.regexPrefix.replace(REGEX_REPLACE_TRAILING_WILDCARD,
|
|
318
|
+
// It does not need to bind pattern
|
|
319
|
+
TRAILING_WILD_CARD_REPLACERS[mode]);
|
|
320
|
+
return this.ignoreCase ? new RegExp(str, "i") : new RegExp(str);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const createRule = ({ pattern, mark }, ignoreCase) => {
|
|
324
|
+
let negative = false;
|
|
325
|
+
let body = pattern;
|
|
326
|
+
// > An optional prefix "!" which negates the pattern;
|
|
327
|
+
if (body.indexOf("!") === 0) {
|
|
328
|
+
negative = true;
|
|
329
|
+
body = body.substring(1);
|
|
330
|
+
}
|
|
331
|
+
body = body
|
|
332
|
+
// > Put a backslash ("\\") in front of the first "!" for patterns that
|
|
333
|
+
// > begin with a literal "!", for example, `"\\!important!.txt"`.
|
|
334
|
+
.replace(REGEX_REPLACE_LEADING_ESCAPED_EXCLAMATION, "!")
|
|
335
|
+
// > Put a backslash ("\\") in front of the first hash for patterns that
|
|
336
|
+
// > begin with a hash.
|
|
337
|
+
.replace(REGEX_REPLACE_LEADING_ESCAPED_HASH, "#");
|
|
338
|
+
const regexPrefix = makeRegexPrefix(body);
|
|
339
|
+
return new IgnoreRule(pattern, mark, body, ignoreCase, negative, regexPrefix);
|
|
340
|
+
};
|
|
341
|
+
class RuleManager {
|
|
342
|
+
_ignoreCase;
|
|
343
|
+
_rules = [];
|
|
344
|
+
_added = false;
|
|
345
|
+
constructor(ignoreCase) {
|
|
346
|
+
this._ignoreCase = ignoreCase;
|
|
347
|
+
}
|
|
348
|
+
get ignoreCase() {
|
|
349
|
+
return this._ignoreCase;
|
|
350
|
+
}
|
|
351
|
+
_add(pattern) {
|
|
352
|
+
// #32
|
|
353
|
+
if (pattern &&
|
|
354
|
+
pattern[KEY_IGNORE]) {
|
|
355
|
+
const otherRules = pattern._rules._rules;
|
|
356
|
+
this._rules.push(...otherRules);
|
|
357
|
+
this._added = true;
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
let patternObj;
|
|
361
|
+
if (isString(pattern)) {
|
|
362
|
+
patternObj = {
|
|
363
|
+
pattern,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
patternObj = pattern;
|
|
368
|
+
}
|
|
369
|
+
if (checkPattern(patternObj.pattern)) {
|
|
370
|
+
const rule = createRule(patternObj, this._ignoreCase);
|
|
371
|
+
this._added = true;
|
|
372
|
+
this._rules.push(rule);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
// @param {Array<string> | string | Ignore} pattern
|
|
376
|
+
add(pattern) {
|
|
377
|
+
this._added = false;
|
|
378
|
+
let patterns;
|
|
379
|
+
if (isString(pattern)) {
|
|
380
|
+
patterns = splitPattern(pattern);
|
|
381
|
+
}
|
|
382
|
+
else if (Array.isArray(pattern)) {
|
|
383
|
+
patterns = pattern;
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
patterns = [pattern];
|
|
387
|
+
}
|
|
388
|
+
for (const p of patterns) {
|
|
389
|
+
this._add(p);
|
|
390
|
+
}
|
|
391
|
+
return this._added;
|
|
392
|
+
}
|
|
393
|
+
// Test one single path without recursively checking parent directories
|
|
394
|
+
//
|
|
395
|
+
// - checkUnignored `boolean` whether should check if the path is unignored,
|
|
396
|
+
// setting `checkUnignored` to `false` could reduce additional
|
|
397
|
+
// path matching.
|
|
398
|
+
// - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
|
|
399
|
+
// @returns {TestResult} true if a file is ignored
|
|
400
|
+
test(path, checkUnignored, mode) {
|
|
401
|
+
let ignored = false;
|
|
402
|
+
let unignored = false;
|
|
403
|
+
let matchedRule;
|
|
404
|
+
for (const rule of this._rules) {
|
|
405
|
+
const { negative } = rule;
|
|
406
|
+
// | ignored : unignored
|
|
407
|
+
// -------- | ---------------------------------------
|
|
408
|
+
// negative | 0:0 | 0:1 | 1:0 | 1:1
|
|
409
|
+
// -------- | ------- | ------- | ------- | --------
|
|
410
|
+
// 0 | TEST | TEST | SKIP | X
|
|
411
|
+
// 1 | TESTIF | SKIP | TEST | X
|
|
412
|
+
// - SKIP: always skip
|
|
413
|
+
// - TEST: always test
|
|
414
|
+
// - TESTIF: only test if checkUnignored
|
|
415
|
+
// - X: that never happen
|
|
416
|
+
if ((unignored === negative && ignored !== unignored) ||
|
|
417
|
+
(negative && !ignored && !unignored && !checkUnignored)) {
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
const regex = mode === "regex" ? rule.regex : rule.checkRegex;
|
|
421
|
+
const matched = regex.test(path);
|
|
422
|
+
if (!matched) {
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
ignored = !negative;
|
|
426
|
+
unignored = negative;
|
|
427
|
+
matchedRule = negative ? undefined : rule;
|
|
428
|
+
}
|
|
429
|
+
const ret = {
|
|
430
|
+
ignored,
|
|
431
|
+
unignored,
|
|
432
|
+
};
|
|
433
|
+
if (matchedRule) {
|
|
434
|
+
ret.rule = matchedRule;
|
|
435
|
+
}
|
|
436
|
+
return ret;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
const throwError = (message, Ctor) => {
|
|
440
|
+
throw new Ctor(message);
|
|
441
|
+
};
|
|
442
|
+
const checkPath = (path, originalPath, doThrow) => {
|
|
443
|
+
if (!isString(path)) {
|
|
444
|
+
return doThrow(`path must be a string, but got \`${originalPath}\``, TypeError);
|
|
445
|
+
}
|
|
446
|
+
// We don't know if we should ignore EMPTY, so throw
|
|
447
|
+
if (!path) {
|
|
448
|
+
return doThrow("path must not be empty", TypeError);
|
|
449
|
+
}
|
|
450
|
+
// Check if it is a relative path
|
|
451
|
+
if (checkPath.isNotRelative?.(path)) {
|
|
452
|
+
const r = "`path.relative()`d";
|
|
453
|
+
return doThrow(`path should be a ${r} string, but got "${originalPath}". Use allowRelativePaths: true to permit absolute paths or './', '../'`, RangeError);
|
|
454
|
+
}
|
|
455
|
+
return true;
|
|
456
|
+
};
|
|
457
|
+
const isNotRelative = (path) => REGEX_TEST_INVALID_PATH.test(path);
|
|
458
|
+
checkPath.isNotRelative = isNotRelative;
|
|
459
|
+
// On windows, the following function will be replaced
|
|
460
|
+
checkPath.convert = (p) => p;
|
|
461
|
+
export class Ignore {
|
|
462
|
+
_rules;
|
|
463
|
+
_strictPathCheck;
|
|
464
|
+
_ignoreCache = {};
|
|
465
|
+
_testCache = {};
|
|
466
|
+
/**
|
|
467
|
+
* Create a new Ignore instance
|
|
468
|
+
* @param options - Configuration options
|
|
469
|
+
* @param options.ignorecase - Whether to use case-insensitive matching (default: true)
|
|
470
|
+
* @param options.ignoreCase - Alias for ignorecase
|
|
471
|
+
* @param options.allowRelativePaths - Allow relative paths like './' and '../' (default: false)
|
|
472
|
+
*/
|
|
473
|
+
constructor({ ignorecase = true, ignoreCase = ignorecase, allowRelativePaths = false, } = {}) {
|
|
474
|
+
// Simple instance identification instead of define()
|
|
475
|
+
this[KEY_IGNORE] = true;
|
|
476
|
+
this._rules = new RuleManager(ignoreCase);
|
|
477
|
+
this._strictPathCheck = !allowRelativePaths;
|
|
478
|
+
this._initCache();
|
|
479
|
+
}
|
|
480
|
+
_initCache() {
|
|
481
|
+
// A cache for the result of `.ignores()`
|
|
482
|
+
this._ignoreCache = Object.create(null);
|
|
483
|
+
// A cache for the result of `.test()`
|
|
484
|
+
this._testCache = Object.create(null);
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Clear all internal caches
|
|
488
|
+
*/
|
|
489
|
+
clearCache() {
|
|
490
|
+
this._initCache();
|
|
491
|
+
return this;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Add ignore patterns
|
|
495
|
+
* @param pattern - Pattern(s) to add
|
|
496
|
+
* @returns This instance for chaining
|
|
497
|
+
*/
|
|
498
|
+
add(pattern) {
|
|
499
|
+
if (this._rules.add(pattern)) {
|
|
500
|
+
// Some rules have just added to the ignore,
|
|
501
|
+
// making the behavior changed,
|
|
502
|
+
// so we need to re-initialize the result cache
|
|
503
|
+
this._initCache();
|
|
504
|
+
}
|
|
505
|
+
return this;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Legacy alias for add()
|
|
509
|
+
* @deprecated Use add() instead
|
|
510
|
+
*/
|
|
511
|
+
addPattern(pattern) {
|
|
512
|
+
return this.add(pattern);
|
|
513
|
+
}
|
|
514
|
+
// @returns {TestResult}
|
|
515
|
+
_test(originalPath, cache, checkUnignored, slices) {
|
|
516
|
+
const path = originalPath
|
|
517
|
+
? // Supports nullable path
|
|
518
|
+
(checkPath.convert?.(originalPath) ?? originalPath)
|
|
519
|
+
: null;
|
|
520
|
+
checkPath(path, originalPath, this._strictPathCheck ? throwError : RETURN_FALSE);
|
|
521
|
+
if (!path) {
|
|
522
|
+
throw new Error("Path cannot be null or undefined");
|
|
523
|
+
}
|
|
524
|
+
return this._t(path, cache, checkUnignored, slices);
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Check if a path is ignored (Git check-ignore compatible)
|
|
528
|
+
* @param path - The path to check
|
|
529
|
+
* @returns TestResult with ignored status and matched rule
|
|
530
|
+
*/
|
|
531
|
+
checkIgnore(path) {
|
|
532
|
+
// If the path doest not end with a slash, `.ignores()` is much equivalent
|
|
533
|
+
// to `git check-ignore`
|
|
534
|
+
if (!REGEX_TEST_TRAILING_SLASH.test(path)) {
|
|
535
|
+
return this.test(path);
|
|
536
|
+
}
|
|
537
|
+
const slices = path.split(SLASH).filter(Boolean);
|
|
538
|
+
slices.pop();
|
|
539
|
+
if (slices.length) {
|
|
540
|
+
const parent = this._t(slices.join(SLASH) + SLASH, this._testCache, true, slices);
|
|
541
|
+
if (parent.ignored) {
|
|
542
|
+
return parent;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return this._rules.test(path, false, MODE_CHECK_IGNORE);
|
|
546
|
+
}
|
|
547
|
+
_t(
|
|
548
|
+
// The path to be tested
|
|
549
|
+
path,
|
|
550
|
+
// The cache for the result of a certain checking
|
|
551
|
+
cache,
|
|
552
|
+
// Whether should check if the path is unignored
|
|
553
|
+
checkUnignored,
|
|
554
|
+
// The path slices
|
|
555
|
+
slices) {
|
|
556
|
+
if (path in cache) {
|
|
557
|
+
return cache[path];
|
|
558
|
+
}
|
|
559
|
+
let pathSlices = slices;
|
|
560
|
+
if (!pathSlices) {
|
|
561
|
+
// path/to/a.js
|
|
562
|
+
// ['path', 'to', 'a.js']
|
|
563
|
+
pathSlices = path.split(SLASH).filter(Boolean);
|
|
564
|
+
}
|
|
565
|
+
pathSlices.pop();
|
|
566
|
+
// If the path has no parent directory, just test it
|
|
567
|
+
if (!pathSlices.length) {
|
|
568
|
+
cache[path] = this._rules.test(path, checkUnignored, MODE_IGNORE);
|
|
569
|
+
return cache[path];
|
|
570
|
+
}
|
|
571
|
+
const parent = this._t(pathSlices.join(SLASH) + SLASH, cache, checkUnignored, pathSlices);
|
|
572
|
+
// If the path contains a parent directory, check the parent first
|
|
573
|
+
cache[path] = parent.ignored
|
|
574
|
+
? // > It is not possible to re-include a file if a parent directory of
|
|
575
|
+
// > that file is excluded.
|
|
576
|
+
parent
|
|
577
|
+
: this._rules.test(path, checkUnignored, MODE_IGNORE);
|
|
578
|
+
return cache[path];
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Check if a path is ignored
|
|
582
|
+
* @param path - The path to check
|
|
583
|
+
* @returns True if the path is ignored
|
|
584
|
+
*/
|
|
585
|
+
ignores(path) {
|
|
586
|
+
return this._test(path, this._ignoreCache, false).ignored;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Create a filter function that returns true for non-ignored paths
|
|
590
|
+
* @returns Filter function
|
|
591
|
+
*/
|
|
592
|
+
createFilter() {
|
|
593
|
+
return (path) => !this.ignores(path);
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Filter an array of paths, returning only non-ignored paths
|
|
597
|
+
* @param paths - Paths to filter
|
|
598
|
+
* @returns Array of non-ignored paths
|
|
599
|
+
*/
|
|
600
|
+
filter(paths) {
|
|
601
|
+
return makeArray(paths).filter(this.createFilter());
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Test if a path is ignored
|
|
605
|
+
* @param path - The path to test
|
|
606
|
+
* @returns TestResult with ignored status and matched rule
|
|
607
|
+
*/
|
|
608
|
+
test(path) {
|
|
609
|
+
return this._test(path, this._testCache, true);
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Compile a pattern to a regular expression
|
|
613
|
+
* @param pattern - The pattern to compile
|
|
614
|
+
* @returns Compiled regular expression
|
|
615
|
+
*/
|
|
616
|
+
compile(pattern) {
|
|
617
|
+
// Create a temporary rule to get the compiled regex
|
|
618
|
+
const tempRule = createRule({ pattern }, this._rules.ignoreCase);
|
|
619
|
+
return tempRule.regex;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
const factory = (options) => new Ignore(options);
|
|
623
|
+
const setupWindows = () => {
|
|
624
|
+
/* eslint no-control-regex: "off" */
|
|
625
|
+
const makePosix = (str) => /^\\\?\\/.test(str) || /["<>|]+/u.test(str)
|
|
626
|
+
? str
|
|
627
|
+
: str.replace(/\\+/g, "/"); // Collapse multiple backslashes
|
|
628
|
+
checkPath.convert = makePosix;
|
|
629
|
+
// 'C:\\foo' <- 'C:\\foo' has been converted to 'C:/'
|
|
630
|
+
// 'd:\\foo'
|
|
631
|
+
const RegexTestWindowsPathAbsolute = /^[a-z]:\//i;
|
|
632
|
+
checkPath.isNotRelative = (path) => RegexTestWindowsPathAbsolute.test(path) || isNotRelative(path);
|
|
633
|
+
};
|
|
634
|
+
// Windows
|
|
635
|
+
// --------------------------------------------------------------
|
|
636
|
+
if (
|
|
637
|
+
// Detect `process` so that it can run in browsers.
|
|
638
|
+
typeof process !== "undefined" &&
|
|
639
|
+
process.platform === "win32") {
|
|
640
|
+
setupWindows();
|
|
641
|
+
}
|
|
642
|
+
// Export the factory function as default
|
|
643
|
+
export default factory;
|
|
644
|
+
// Although it is an anti-pattern,
|
|
645
|
+
// it is still widely misused by a lot of libraries in github
|
|
646
|
+
// Ref: https://github.com/search?q=ignore.default%28%29&type=code
|
|
647
|
+
factory.default = factory;
|
|
648
|
+
// For testing purposes
|
|
649
|
+
factory[Symbol.for("setupWindows")] = setupWindows;
|
package/dist/utils/process.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ interface ExecuteOptions {
|
|
|
14
14
|
/** Maximum buffer size in bytes (defaults to 1MB) */
|
|
15
15
|
maxBuffer?: number;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
interface ExecuteResult {
|
|
18
18
|
/** Standard output from the command */
|
|
19
19
|
stdout: string;
|
|
20
20
|
/** Standard error from the command */
|
|
@@ -24,7 +24,7 @@ export interface ExecuteResult {
|
|
|
24
24
|
/** The signal that terminated the process, if any */
|
|
25
25
|
signal?: NodeJS.Signals;
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
type ParseResult = {
|
|
28
28
|
ok: true;
|
|
29
29
|
argv: [string, ...string[]];
|
|
30
30
|
} | {
|
|
@@ -42,3 +42,4 @@ export declare function parseArgv(input: string): ParseResult;
|
|
|
42
42
|
*/
|
|
43
43
|
export declare function executeCommand(command: string | [string, ...string[]], options?: ExecuteOptions): Promise<ExecuteResult>;
|
|
44
44
|
export {};
|
|
45
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../source/utils/process.ts"],"names":[],"mappings":"AAOA,UAAU,cAAc;IACtB,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0CAA0C;IAC1C,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,sDAAsD;IACtD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,mGAAmG;IACnG,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,aAAa;IACrB,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC;CACzB;AAED,KAAK,WAAW,GACZ;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;CAAE,GACzC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAGjC,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CA2EpD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,EACvC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,aAAa,CAAC,CAqGxB"}
|