encoding-converter-ai 0.1.0 → 0.2.1
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 +30 -4
- package/dist/converter.js +1879 -59
- package/dist/index.js +2201 -122
- package/dist/plugin.js +1879 -60
- package/package.json +36 -28
package/dist/index.js
CHANGED
|
@@ -3686,6 +3686,1772 @@ var require_lib = __commonJS({
|
|
|
3686
3686
|
}
|
|
3687
3687
|
});
|
|
3688
3688
|
|
|
3689
|
+
// node_modules/picomatch/lib/constants.js
|
|
3690
|
+
var require_constants = __commonJS({
|
|
3691
|
+
"node_modules/picomatch/lib/constants.js"(exports2, module2) {
|
|
3692
|
+
"use strict";
|
|
3693
|
+
var WIN_SLASH = "\\\\/";
|
|
3694
|
+
var WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
3695
|
+
var DEFAULT_MAX_EXTGLOB_RECURSION = 0;
|
|
3696
|
+
var DOT_LITERAL = "\\.";
|
|
3697
|
+
var PLUS_LITERAL = "\\+";
|
|
3698
|
+
var QMARK_LITERAL = "\\?";
|
|
3699
|
+
var SLASH_LITERAL = "\\/";
|
|
3700
|
+
var ONE_CHAR = "(?=.)";
|
|
3701
|
+
var QMARK = "[^/]";
|
|
3702
|
+
var END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
|
3703
|
+
var START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
|
3704
|
+
var DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
|
3705
|
+
var NO_DOT = `(?!${DOT_LITERAL})`;
|
|
3706
|
+
var NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
|
|
3707
|
+
var NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
|
|
3708
|
+
var NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
|
|
3709
|
+
var QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
|
|
3710
|
+
var STAR = `${QMARK}*?`;
|
|
3711
|
+
var SEP = "/";
|
|
3712
|
+
var POSIX_CHARS = {
|
|
3713
|
+
DOT_LITERAL,
|
|
3714
|
+
PLUS_LITERAL,
|
|
3715
|
+
QMARK_LITERAL,
|
|
3716
|
+
SLASH_LITERAL,
|
|
3717
|
+
ONE_CHAR,
|
|
3718
|
+
QMARK,
|
|
3719
|
+
END_ANCHOR,
|
|
3720
|
+
DOTS_SLASH,
|
|
3721
|
+
NO_DOT,
|
|
3722
|
+
NO_DOTS,
|
|
3723
|
+
NO_DOT_SLASH,
|
|
3724
|
+
NO_DOTS_SLASH,
|
|
3725
|
+
QMARK_NO_DOT,
|
|
3726
|
+
STAR,
|
|
3727
|
+
START_ANCHOR,
|
|
3728
|
+
SEP
|
|
3729
|
+
};
|
|
3730
|
+
var WINDOWS_CHARS = {
|
|
3731
|
+
...POSIX_CHARS,
|
|
3732
|
+
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
|
3733
|
+
QMARK: WIN_NO_SLASH,
|
|
3734
|
+
STAR: `${WIN_NO_SLASH}*?`,
|
|
3735
|
+
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
|
3736
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
3737
|
+
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
3738
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
|
3739
|
+
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
3740
|
+
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
3741
|
+
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
3742
|
+
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
|
|
3743
|
+
SEP: "\\"
|
|
3744
|
+
};
|
|
3745
|
+
var POSIX_REGEX_SOURCE = {
|
|
3746
|
+
__proto__: null,
|
|
3747
|
+
alnum: "a-zA-Z0-9",
|
|
3748
|
+
alpha: "a-zA-Z",
|
|
3749
|
+
ascii: "\\x00-\\x7F",
|
|
3750
|
+
blank: " \\t",
|
|
3751
|
+
cntrl: "\\x00-\\x1F\\x7F",
|
|
3752
|
+
digit: "0-9",
|
|
3753
|
+
graph: "\\x21-\\x7E",
|
|
3754
|
+
lower: "a-z",
|
|
3755
|
+
print: "\\x20-\\x7E ",
|
|
3756
|
+
punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
|
|
3757
|
+
space: " \\t\\r\\n\\v\\f",
|
|
3758
|
+
upper: "A-Z",
|
|
3759
|
+
word: "A-Za-z0-9_",
|
|
3760
|
+
xdigit: "A-Fa-f0-9"
|
|
3761
|
+
};
|
|
3762
|
+
module2.exports = {
|
|
3763
|
+
DEFAULT_MAX_EXTGLOB_RECURSION,
|
|
3764
|
+
MAX_LENGTH: 1024 * 64,
|
|
3765
|
+
POSIX_REGEX_SOURCE,
|
|
3766
|
+
// regular expressions
|
|
3767
|
+
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
3768
|
+
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
3769
|
+
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
3770
|
+
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
3771
|
+
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
3772
|
+
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
3773
|
+
// Replace globs with equivalent patterns to reduce parsing time.
|
|
3774
|
+
REPLACEMENTS: {
|
|
3775
|
+
__proto__: null,
|
|
3776
|
+
"***": "*",
|
|
3777
|
+
"**/**": "**",
|
|
3778
|
+
"**/**/**": "**"
|
|
3779
|
+
},
|
|
3780
|
+
// Digits
|
|
3781
|
+
CHAR_0: 48,
|
|
3782
|
+
/* 0 */
|
|
3783
|
+
CHAR_9: 57,
|
|
3784
|
+
/* 9 */
|
|
3785
|
+
// Alphabet chars.
|
|
3786
|
+
CHAR_UPPERCASE_A: 65,
|
|
3787
|
+
/* A */
|
|
3788
|
+
CHAR_LOWERCASE_A: 97,
|
|
3789
|
+
/* a */
|
|
3790
|
+
CHAR_UPPERCASE_Z: 90,
|
|
3791
|
+
/* Z */
|
|
3792
|
+
CHAR_LOWERCASE_Z: 122,
|
|
3793
|
+
/* z */
|
|
3794
|
+
CHAR_LEFT_PARENTHESES: 40,
|
|
3795
|
+
/* ( */
|
|
3796
|
+
CHAR_RIGHT_PARENTHESES: 41,
|
|
3797
|
+
/* ) */
|
|
3798
|
+
CHAR_ASTERISK: 42,
|
|
3799
|
+
/* * */
|
|
3800
|
+
// Non-alphabetic chars.
|
|
3801
|
+
CHAR_AMPERSAND: 38,
|
|
3802
|
+
/* & */
|
|
3803
|
+
CHAR_AT: 64,
|
|
3804
|
+
/* @ */
|
|
3805
|
+
CHAR_BACKWARD_SLASH: 92,
|
|
3806
|
+
/* \ */
|
|
3807
|
+
CHAR_CARRIAGE_RETURN: 13,
|
|
3808
|
+
/* \r */
|
|
3809
|
+
CHAR_CIRCUMFLEX_ACCENT: 94,
|
|
3810
|
+
/* ^ */
|
|
3811
|
+
CHAR_COLON: 58,
|
|
3812
|
+
/* : */
|
|
3813
|
+
CHAR_COMMA: 44,
|
|
3814
|
+
/* , */
|
|
3815
|
+
CHAR_DOT: 46,
|
|
3816
|
+
/* . */
|
|
3817
|
+
CHAR_DOUBLE_QUOTE: 34,
|
|
3818
|
+
/* " */
|
|
3819
|
+
CHAR_EQUAL: 61,
|
|
3820
|
+
/* = */
|
|
3821
|
+
CHAR_EXCLAMATION_MARK: 33,
|
|
3822
|
+
/* ! */
|
|
3823
|
+
CHAR_FORM_FEED: 12,
|
|
3824
|
+
/* \f */
|
|
3825
|
+
CHAR_FORWARD_SLASH: 47,
|
|
3826
|
+
/* / */
|
|
3827
|
+
CHAR_GRAVE_ACCENT: 96,
|
|
3828
|
+
/* ` */
|
|
3829
|
+
CHAR_HASH: 35,
|
|
3830
|
+
/* # */
|
|
3831
|
+
CHAR_HYPHEN_MINUS: 45,
|
|
3832
|
+
/* - */
|
|
3833
|
+
CHAR_LEFT_ANGLE_BRACKET: 60,
|
|
3834
|
+
/* < */
|
|
3835
|
+
CHAR_LEFT_CURLY_BRACE: 123,
|
|
3836
|
+
/* { */
|
|
3837
|
+
CHAR_LEFT_SQUARE_BRACKET: 91,
|
|
3838
|
+
/* [ */
|
|
3839
|
+
CHAR_LINE_FEED: 10,
|
|
3840
|
+
/* \n */
|
|
3841
|
+
CHAR_NO_BREAK_SPACE: 160,
|
|
3842
|
+
/* \u00A0 */
|
|
3843
|
+
CHAR_PERCENT: 37,
|
|
3844
|
+
/* % */
|
|
3845
|
+
CHAR_PLUS: 43,
|
|
3846
|
+
/* + */
|
|
3847
|
+
CHAR_QUESTION_MARK: 63,
|
|
3848
|
+
/* ? */
|
|
3849
|
+
CHAR_RIGHT_ANGLE_BRACKET: 62,
|
|
3850
|
+
/* > */
|
|
3851
|
+
CHAR_RIGHT_CURLY_BRACE: 125,
|
|
3852
|
+
/* } */
|
|
3853
|
+
CHAR_RIGHT_SQUARE_BRACKET: 93,
|
|
3854
|
+
/* ] */
|
|
3855
|
+
CHAR_SEMICOLON: 59,
|
|
3856
|
+
/* ; */
|
|
3857
|
+
CHAR_SINGLE_QUOTE: 39,
|
|
3858
|
+
/* ' */
|
|
3859
|
+
CHAR_SPACE: 32,
|
|
3860
|
+
/* */
|
|
3861
|
+
CHAR_TAB: 9,
|
|
3862
|
+
/* \t */
|
|
3863
|
+
CHAR_UNDERSCORE: 95,
|
|
3864
|
+
/* _ */
|
|
3865
|
+
CHAR_VERTICAL_LINE: 124,
|
|
3866
|
+
/* | */
|
|
3867
|
+
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
3868
|
+
/* \uFEFF */
|
|
3869
|
+
/**
|
|
3870
|
+
* Create EXTGLOB_CHARS
|
|
3871
|
+
*/
|
|
3872
|
+
extglobChars(chars) {
|
|
3873
|
+
return {
|
|
3874
|
+
"!": { type: "negate", open: "(?:(?!(?:", close: `))${chars.STAR})` },
|
|
3875
|
+
"?": { type: "qmark", open: "(?:", close: ")?" },
|
|
3876
|
+
"+": { type: "plus", open: "(?:", close: ")+" },
|
|
3877
|
+
"*": { type: "star", open: "(?:", close: ")*" },
|
|
3878
|
+
"@": { type: "at", open: "(?:", close: ")" }
|
|
3879
|
+
};
|
|
3880
|
+
},
|
|
3881
|
+
/**
|
|
3882
|
+
* Create GLOB_CHARS
|
|
3883
|
+
*/
|
|
3884
|
+
globChars(win32) {
|
|
3885
|
+
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
|
3886
|
+
}
|
|
3887
|
+
};
|
|
3888
|
+
}
|
|
3889
|
+
});
|
|
3890
|
+
|
|
3891
|
+
// node_modules/picomatch/lib/utils.js
|
|
3892
|
+
var require_utils = __commonJS({
|
|
3893
|
+
"node_modules/picomatch/lib/utils.js"(exports2) {
|
|
3894
|
+
"use strict";
|
|
3895
|
+
var {
|
|
3896
|
+
REGEX_BACKSLASH,
|
|
3897
|
+
REGEX_REMOVE_BACKSLASH,
|
|
3898
|
+
REGEX_SPECIAL_CHARS,
|
|
3899
|
+
REGEX_SPECIAL_CHARS_GLOBAL
|
|
3900
|
+
} = require_constants();
|
|
3901
|
+
exports2.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
3902
|
+
exports2.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
|
|
3903
|
+
exports2.isRegexChar = (str) => str.length === 1 && exports2.hasRegexChars(str);
|
|
3904
|
+
exports2.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
|
|
3905
|
+
exports2.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
|
|
3906
|
+
exports2.isWindows = () => {
|
|
3907
|
+
if (typeof navigator !== "undefined" && navigator.platform) {
|
|
3908
|
+
const platform = navigator.platform.toLowerCase();
|
|
3909
|
+
return platform === "win32" || platform === "windows";
|
|
3910
|
+
}
|
|
3911
|
+
if (typeof process !== "undefined" && process.platform) {
|
|
3912
|
+
return process.platform === "win32";
|
|
3913
|
+
}
|
|
3914
|
+
return false;
|
|
3915
|
+
};
|
|
3916
|
+
exports2.removeBackslashes = (str) => {
|
|
3917
|
+
return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
|
|
3918
|
+
return match === "\\" ? "" : match;
|
|
3919
|
+
});
|
|
3920
|
+
};
|
|
3921
|
+
exports2.escapeLast = (input, char, lastIdx) => {
|
|
3922
|
+
const idx = input.lastIndexOf(char, lastIdx);
|
|
3923
|
+
if (idx === -1)
|
|
3924
|
+
return input;
|
|
3925
|
+
if (input[idx - 1] === "\\")
|
|
3926
|
+
return exports2.escapeLast(input, char, idx - 1);
|
|
3927
|
+
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
|
3928
|
+
};
|
|
3929
|
+
exports2.removePrefix = (input, state = {}) => {
|
|
3930
|
+
let output = input;
|
|
3931
|
+
if (output.startsWith("./")) {
|
|
3932
|
+
output = output.slice(2);
|
|
3933
|
+
state.prefix = "./";
|
|
3934
|
+
}
|
|
3935
|
+
return output;
|
|
3936
|
+
};
|
|
3937
|
+
exports2.wrapOutput = (input, state = {}, options = {}) => {
|
|
3938
|
+
const prepend = options.contains ? "" : "^";
|
|
3939
|
+
const append = options.contains ? "" : "$";
|
|
3940
|
+
let output = `${prepend}(?:${input})${append}`;
|
|
3941
|
+
if (state.negated === true) {
|
|
3942
|
+
output = `(?:^(?!${output}).*$)`;
|
|
3943
|
+
}
|
|
3944
|
+
return output;
|
|
3945
|
+
};
|
|
3946
|
+
exports2.basename = (path5, { windows } = {}) => {
|
|
3947
|
+
const segs = path5.split(windows ? /[\\/]/ : "/");
|
|
3948
|
+
const last = segs[segs.length - 1];
|
|
3949
|
+
if (last === "") {
|
|
3950
|
+
return segs[segs.length - 2];
|
|
3951
|
+
}
|
|
3952
|
+
return last;
|
|
3953
|
+
};
|
|
3954
|
+
}
|
|
3955
|
+
});
|
|
3956
|
+
|
|
3957
|
+
// node_modules/picomatch/lib/scan.js
|
|
3958
|
+
var require_scan = __commonJS({
|
|
3959
|
+
"node_modules/picomatch/lib/scan.js"(exports2, module2) {
|
|
3960
|
+
"use strict";
|
|
3961
|
+
var utils = require_utils();
|
|
3962
|
+
var {
|
|
3963
|
+
CHAR_ASTERISK,
|
|
3964
|
+
/* * */
|
|
3965
|
+
CHAR_AT,
|
|
3966
|
+
/* @ */
|
|
3967
|
+
CHAR_BACKWARD_SLASH,
|
|
3968
|
+
/* \ */
|
|
3969
|
+
CHAR_COMMA,
|
|
3970
|
+
/* , */
|
|
3971
|
+
CHAR_DOT,
|
|
3972
|
+
/* . */
|
|
3973
|
+
CHAR_EXCLAMATION_MARK,
|
|
3974
|
+
/* ! */
|
|
3975
|
+
CHAR_FORWARD_SLASH,
|
|
3976
|
+
/* / */
|
|
3977
|
+
CHAR_LEFT_CURLY_BRACE,
|
|
3978
|
+
/* { */
|
|
3979
|
+
CHAR_LEFT_PARENTHESES,
|
|
3980
|
+
/* ( */
|
|
3981
|
+
CHAR_LEFT_SQUARE_BRACKET,
|
|
3982
|
+
/* [ */
|
|
3983
|
+
CHAR_PLUS,
|
|
3984
|
+
/* + */
|
|
3985
|
+
CHAR_QUESTION_MARK,
|
|
3986
|
+
/* ? */
|
|
3987
|
+
CHAR_RIGHT_CURLY_BRACE,
|
|
3988
|
+
/* } */
|
|
3989
|
+
CHAR_RIGHT_PARENTHESES,
|
|
3990
|
+
/* ) */
|
|
3991
|
+
CHAR_RIGHT_SQUARE_BRACKET
|
|
3992
|
+
/* ] */
|
|
3993
|
+
} = require_constants();
|
|
3994
|
+
var isPathSeparator = (code) => {
|
|
3995
|
+
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
3996
|
+
};
|
|
3997
|
+
var depth = (token) => {
|
|
3998
|
+
if (token.isPrefix !== true) {
|
|
3999
|
+
token.depth = token.isGlobstar ? Infinity : 1;
|
|
4000
|
+
}
|
|
4001
|
+
};
|
|
4002
|
+
var scan = (input, options) => {
|
|
4003
|
+
const opts = options || {};
|
|
4004
|
+
const length = input.length - 1;
|
|
4005
|
+
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
|
4006
|
+
const slashes = [];
|
|
4007
|
+
const tokens = [];
|
|
4008
|
+
const parts = [];
|
|
4009
|
+
let str = input;
|
|
4010
|
+
let index = -1;
|
|
4011
|
+
let start = 0;
|
|
4012
|
+
let lastIndex = 0;
|
|
4013
|
+
let isBrace = false;
|
|
4014
|
+
let isBracket = false;
|
|
4015
|
+
let isGlob = false;
|
|
4016
|
+
let isExtglob = false;
|
|
4017
|
+
let isGlobstar = false;
|
|
4018
|
+
let braceEscaped = false;
|
|
4019
|
+
let backslashes = false;
|
|
4020
|
+
let negated = false;
|
|
4021
|
+
let negatedExtglob = false;
|
|
4022
|
+
let finished = false;
|
|
4023
|
+
let braces = 0;
|
|
4024
|
+
let prev;
|
|
4025
|
+
let code;
|
|
4026
|
+
let token = { value: "", depth: 0, isGlob: false };
|
|
4027
|
+
const eos = () => index >= length;
|
|
4028
|
+
const peek = () => str.charCodeAt(index + 1);
|
|
4029
|
+
const advance = () => {
|
|
4030
|
+
prev = code;
|
|
4031
|
+
return str.charCodeAt(++index);
|
|
4032
|
+
};
|
|
4033
|
+
while (index < length) {
|
|
4034
|
+
code = advance();
|
|
4035
|
+
let next;
|
|
4036
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
4037
|
+
backslashes = token.backslashes = true;
|
|
4038
|
+
code = advance();
|
|
4039
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
4040
|
+
braceEscaped = true;
|
|
4041
|
+
}
|
|
4042
|
+
continue;
|
|
4043
|
+
}
|
|
4044
|
+
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
4045
|
+
braces++;
|
|
4046
|
+
while (eos() !== true && (code = advance())) {
|
|
4047
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
4048
|
+
backslashes = token.backslashes = true;
|
|
4049
|
+
advance();
|
|
4050
|
+
continue;
|
|
4051
|
+
}
|
|
4052
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
4053
|
+
braces++;
|
|
4054
|
+
continue;
|
|
4055
|
+
}
|
|
4056
|
+
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
|
4057
|
+
isBrace = token.isBrace = true;
|
|
4058
|
+
isGlob = token.isGlob = true;
|
|
4059
|
+
finished = true;
|
|
4060
|
+
if (scanToEnd === true) {
|
|
4061
|
+
continue;
|
|
4062
|
+
}
|
|
4063
|
+
break;
|
|
4064
|
+
}
|
|
4065
|
+
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
4066
|
+
isBrace = token.isBrace = true;
|
|
4067
|
+
isGlob = token.isGlob = true;
|
|
4068
|
+
finished = true;
|
|
4069
|
+
if (scanToEnd === true) {
|
|
4070
|
+
continue;
|
|
4071
|
+
}
|
|
4072
|
+
break;
|
|
4073
|
+
}
|
|
4074
|
+
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
4075
|
+
braces--;
|
|
4076
|
+
if (braces === 0) {
|
|
4077
|
+
braceEscaped = false;
|
|
4078
|
+
isBrace = token.isBrace = true;
|
|
4079
|
+
finished = true;
|
|
4080
|
+
break;
|
|
4081
|
+
}
|
|
4082
|
+
}
|
|
4083
|
+
}
|
|
4084
|
+
if (scanToEnd === true) {
|
|
4085
|
+
continue;
|
|
4086
|
+
}
|
|
4087
|
+
break;
|
|
4088
|
+
}
|
|
4089
|
+
if (code === CHAR_FORWARD_SLASH) {
|
|
4090
|
+
slashes.push(index);
|
|
4091
|
+
tokens.push(token);
|
|
4092
|
+
token = { value: "", depth: 0, isGlob: false };
|
|
4093
|
+
if (finished === true)
|
|
4094
|
+
continue;
|
|
4095
|
+
if (prev === CHAR_DOT && index === start + 1) {
|
|
4096
|
+
start += 2;
|
|
4097
|
+
continue;
|
|
4098
|
+
}
|
|
4099
|
+
lastIndex = index + 1;
|
|
4100
|
+
continue;
|
|
4101
|
+
}
|
|
4102
|
+
if (opts.noext !== true) {
|
|
4103
|
+
const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
|
|
4104
|
+
if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
4105
|
+
isGlob = token.isGlob = true;
|
|
4106
|
+
isExtglob = token.isExtglob = true;
|
|
4107
|
+
finished = true;
|
|
4108
|
+
if (code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
4109
|
+
negatedExtglob = true;
|
|
4110
|
+
}
|
|
4111
|
+
if (scanToEnd === true) {
|
|
4112
|
+
while (eos() !== true && (code = advance())) {
|
|
4113
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
4114
|
+
backslashes = token.backslashes = true;
|
|
4115
|
+
code = advance();
|
|
4116
|
+
continue;
|
|
4117
|
+
}
|
|
4118
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
4119
|
+
isGlob = token.isGlob = true;
|
|
4120
|
+
finished = true;
|
|
4121
|
+
break;
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4124
|
+
continue;
|
|
4125
|
+
}
|
|
4126
|
+
break;
|
|
4127
|
+
}
|
|
4128
|
+
}
|
|
4129
|
+
if (code === CHAR_ASTERISK) {
|
|
4130
|
+
if (prev === CHAR_ASTERISK)
|
|
4131
|
+
isGlobstar = token.isGlobstar = true;
|
|
4132
|
+
isGlob = token.isGlob = true;
|
|
4133
|
+
finished = true;
|
|
4134
|
+
if (scanToEnd === true) {
|
|
4135
|
+
continue;
|
|
4136
|
+
}
|
|
4137
|
+
break;
|
|
4138
|
+
}
|
|
4139
|
+
if (code === CHAR_QUESTION_MARK) {
|
|
4140
|
+
isGlob = token.isGlob = true;
|
|
4141
|
+
finished = true;
|
|
4142
|
+
if (scanToEnd === true) {
|
|
4143
|
+
continue;
|
|
4144
|
+
}
|
|
4145
|
+
break;
|
|
4146
|
+
}
|
|
4147
|
+
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
4148
|
+
while (eos() !== true && (next = advance())) {
|
|
4149
|
+
if (next === CHAR_BACKWARD_SLASH) {
|
|
4150
|
+
backslashes = token.backslashes = true;
|
|
4151
|
+
advance();
|
|
4152
|
+
continue;
|
|
4153
|
+
}
|
|
4154
|
+
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
4155
|
+
isBracket = token.isBracket = true;
|
|
4156
|
+
isGlob = token.isGlob = true;
|
|
4157
|
+
finished = true;
|
|
4158
|
+
break;
|
|
4159
|
+
}
|
|
4160
|
+
}
|
|
4161
|
+
if (scanToEnd === true) {
|
|
4162
|
+
continue;
|
|
4163
|
+
}
|
|
4164
|
+
break;
|
|
4165
|
+
}
|
|
4166
|
+
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
4167
|
+
negated = token.negated = true;
|
|
4168
|
+
start++;
|
|
4169
|
+
continue;
|
|
4170
|
+
}
|
|
4171
|
+
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
4172
|
+
isGlob = token.isGlob = true;
|
|
4173
|
+
if (scanToEnd === true) {
|
|
4174
|
+
while (eos() !== true && (code = advance())) {
|
|
4175
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
4176
|
+
backslashes = token.backslashes = true;
|
|
4177
|
+
code = advance();
|
|
4178
|
+
continue;
|
|
4179
|
+
}
|
|
4180
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
4181
|
+
finished = true;
|
|
4182
|
+
break;
|
|
4183
|
+
}
|
|
4184
|
+
}
|
|
4185
|
+
continue;
|
|
4186
|
+
}
|
|
4187
|
+
break;
|
|
4188
|
+
}
|
|
4189
|
+
if (isGlob === true) {
|
|
4190
|
+
finished = true;
|
|
4191
|
+
if (scanToEnd === true) {
|
|
4192
|
+
continue;
|
|
4193
|
+
}
|
|
4194
|
+
break;
|
|
4195
|
+
}
|
|
4196
|
+
}
|
|
4197
|
+
if (opts.noext === true) {
|
|
4198
|
+
isExtglob = false;
|
|
4199
|
+
isGlob = false;
|
|
4200
|
+
}
|
|
4201
|
+
let base = str;
|
|
4202
|
+
let prefix = "";
|
|
4203
|
+
let glob = "";
|
|
4204
|
+
if (start > 0) {
|
|
4205
|
+
prefix = str.slice(0, start);
|
|
4206
|
+
str = str.slice(start);
|
|
4207
|
+
lastIndex -= start;
|
|
4208
|
+
}
|
|
4209
|
+
if (base && isGlob === true && lastIndex > 0) {
|
|
4210
|
+
base = str.slice(0, lastIndex);
|
|
4211
|
+
glob = str.slice(lastIndex);
|
|
4212
|
+
} else if (isGlob === true) {
|
|
4213
|
+
base = "";
|
|
4214
|
+
glob = str;
|
|
4215
|
+
} else {
|
|
4216
|
+
base = str;
|
|
4217
|
+
}
|
|
4218
|
+
if (base && base !== "" && base !== "/" && base !== str) {
|
|
4219
|
+
if (isPathSeparator(base.charCodeAt(base.length - 1))) {
|
|
4220
|
+
base = base.slice(0, -1);
|
|
4221
|
+
}
|
|
4222
|
+
}
|
|
4223
|
+
if (opts.unescape === true) {
|
|
4224
|
+
if (glob)
|
|
4225
|
+
glob = utils.removeBackslashes(glob);
|
|
4226
|
+
if (base && backslashes === true) {
|
|
4227
|
+
base = utils.removeBackslashes(base);
|
|
4228
|
+
}
|
|
4229
|
+
}
|
|
4230
|
+
const state = {
|
|
4231
|
+
prefix,
|
|
4232
|
+
input,
|
|
4233
|
+
start,
|
|
4234
|
+
base,
|
|
4235
|
+
glob,
|
|
4236
|
+
isBrace,
|
|
4237
|
+
isBracket,
|
|
4238
|
+
isGlob,
|
|
4239
|
+
isExtglob,
|
|
4240
|
+
isGlobstar,
|
|
4241
|
+
negated,
|
|
4242
|
+
negatedExtglob
|
|
4243
|
+
};
|
|
4244
|
+
if (opts.tokens === true) {
|
|
4245
|
+
state.maxDepth = 0;
|
|
4246
|
+
if (!isPathSeparator(code)) {
|
|
4247
|
+
tokens.push(token);
|
|
4248
|
+
}
|
|
4249
|
+
state.tokens = tokens;
|
|
4250
|
+
}
|
|
4251
|
+
if (opts.parts === true || opts.tokens === true) {
|
|
4252
|
+
let prevIndex;
|
|
4253
|
+
for (let idx = 0; idx < slashes.length; idx++) {
|
|
4254
|
+
const n = prevIndex ? prevIndex + 1 : start;
|
|
4255
|
+
const i = slashes[idx];
|
|
4256
|
+
const value = input.slice(n, i);
|
|
4257
|
+
if (opts.tokens) {
|
|
4258
|
+
if (idx === 0 && start !== 0) {
|
|
4259
|
+
tokens[idx].isPrefix = true;
|
|
4260
|
+
tokens[idx].value = prefix;
|
|
4261
|
+
} else {
|
|
4262
|
+
tokens[idx].value = value;
|
|
4263
|
+
}
|
|
4264
|
+
depth(tokens[idx]);
|
|
4265
|
+
state.maxDepth += tokens[idx].depth;
|
|
4266
|
+
}
|
|
4267
|
+
if (idx !== 0 || value !== "") {
|
|
4268
|
+
parts.push(value);
|
|
4269
|
+
}
|
|
4270
|
+
prevIndex = i;
|
|
4271
|
+
}
|
|
4272
|
+
if (prevIndex && prevIndex + 1 < input.length) {
|
|
4273
|
+
const value = input.slice(prevIndex + 1);
|
|
4274
|
+
parts.push(value);
|
|
4275
|
+
if (opts.tokens) {
|
|
4276
|
+
tokens[tokens.length - 1].value = value;
|
|
4277
|
+
depth(tokens[tokens.length - 1]);
|
|
4278
|
+
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
4279
|
+
}
|
|
4280
|
+
}
|
|
4281
|
+
state.slashes = slashes;
|
|
4282
|
+
state.parts = parts;
|
|
4283
|
+
}
|
|
4284
|
+
return state;
|
|
4285
|
+
};
|
|
4286
|
+
module2.exports = scan;
|
|
4287
|
+
}
|
|
4288
|
+
});
|
|
4289
|
+
|
|
4290
|
+
// node_modules/picomatch/lib/parse.js
|
|
4291
|
+
var require_parse = __commonJS({
|
|
4292
|
+
"node_modules/picomatch/lib/parse.js"(exports2, module2) {
|
|
4293
|
+
"use strict";
|
|
4294
|
+
var constants = require_constants();
|
|
4295
|
+
var utils = require_utils();
|
|
4296
|
+
var {
|
|
4297
|
+
MAX_LENGTH,
|
|
4298
|
+
POSIX_REGEX_SOURCE,
|
|
4299
|
+
REGEX_NON_SPECIAL_CHARS,
|
|
4300
|
+
REGEX_SPECIAL_CHARS_BACKREF,
|
|
4301
|
+
REPLACEMENTS
|
|
4302
|
+
} = constants;
|
|
4303
|
+
var expandRange = (args, options) => {
|
|
4304
|
+
if (typeof options.expandRange === "function") {
|
|
4305
|
+
return options.expandRange(...args, options);
|
|
4306
|
+
}
|
|
4307
|
+
args.sort();
|
|
4308
|
+
const value = `[${args.join("-")}]`;
|
|
4309
|
+
try {
|
|
4310
|
+
new RegExp(value);
|
|
4311
|
+
} catch (ex) {
|
|
4312
|
+
return args.map((v) => utils.escapeRegex(v)).join("..");
|
|
4313
|
+
}
|
|
4314
|
+
return value;
|
|
4315
|
+
};
|
|
4316
|
+
var syntaxError = (type, char) => {
|
|
4317
|
+
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
4318
|
+
};
|
|
4319
|
+
var splitTopLevel = (input) => {
|
|
4320
|
+
const parts = [];
|
|
4321
|
+
let bracket = 0;
|
|
4322
|
+
let paren = 0;
|
|
4323
|
+
let quote = 0;
|
|
4324
|
+
let value = "";
|
|
4325
|
+
let escaped = false;
|
|
4326
|
+
for (const ch of input) {
|
|
4327
|
+
if (escaped === true) {
|
|
4328
|
+
value += ch;
|
|
4329
|
+
escaped = false;
|
|
4330
|
+
continue;
|
|
4331
|
+
}
|
|
4332
|
+
if (ch === "\\") {
|
|
4333
|
+
value += ch;
|
|
4334
|
+
escaped = true;
|
|
4335
|
+
continue;
|
|
4336
|
+
}
|
|
4337
|
+
if (ch === '"') {
|
|
4338
|
+
quote = quote === 1 ? 0 : 1;
|
|
4339
|
+
value += ch;
|
|
4340
|
+
continue;
|
|
4341
|
+
}
|
|
4342
|
+
if (quote === 0) {
|
|
4343
|
+
if (ch === "[") {
|
|
4344
|
+
bracket++;
|
|
4345
|
+
} else if (ch === "]" && bracket > 0) {
|
|
4346
|
+
bracket--;
|
|
4347
|
+
} else if (bracket === 0) {
|
|
4348
|
+
if (ch === "(") {
|
|
4349
|
+
paren++;
|
|
4350
|
+
} else if (ch === ")" && paren > 0) {
|
|
4351
|
+
paren--;
|
|
4352
|
+
} else if (ch === "|" && paren === 0) {
|
|
4353
|
+
parts.push(value);
|
|
4354
|
+
value = "";
|
|
4355
|
+
continue;
|
|
4356
|
+
}
|
|
4357
|
+
}
|
|
4358
|
+
}
|
|
4359
|
+
value += ch;
|
|
4360
|
+
}
|
|
4361
|
+
parts.push(value);
|
|
4362
|
+
return parts;
|
|
4363
|
+
};
|
|
4364
|
+
var isPlainBranch = (branch) => {
|
|
4365
|
+
let escaped = false;
|
|
4366
|
+
for (const ch of branch) {
|
|
4367
|
+
if (escaped === true) {
|
|
4368
|
+
escaped = false;
|
|
4369
|
+
continue;
|
|
4370
|
+
}
|
|
4371
|
+
if (ch === "\\") {
|
|
4372
|
+
escaped = true;
|
|
4373
|
+
continue;
|
|
4374
|
+
}
|
|
4375
|
+
if (/[?*+@!()[\]{}]/.test(ch)) {
|
|
4376
|
+
return false;
|
|
4377
|
+
}
|
|
4378
|
+
}
|
|
4379
|
+
return true;
|
|
4380
|
+
};
|
|
4381
|
+
var normalizeSimpleBranch = (branch) => {
|
|
4382
|
+
let value = branch.trim();
|
|
4383
|
+
let changed = true;
|
|
4384
|
+
while (changed === true) {
|
|
4385
|
+
changed = false;
|
|
4386
|
+
if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
|
|
4387
|
+
value = value.slice(2, -1);
|
|
4388
|
+
changed = true;
|
|
4389
|
+
}
|
|
4390
|
+
}
|
|
4391
|
+
if (!isPlainBranch(value)) {
|
|
4392
|
+
return;
|
|
4393
|
+
}
|
|
4394
|
+
return value.replace(/\\(.)/g, "$1");
|
|
4395
|
+
};
|
|
4396
|
+
var hasRepeatedCharPrefixOverlap = (branches) => {
|
|
4397
|
+
const values = branches.map(normalizeSimpleBranch).filter(Boolean);
|
|
4398
|
+
for (let i = 0; i < values.length; i++) {
|
|
4399
|
+
for (let j = i + 1; j < values.length; j++) {
|
|
4400
|
+
const a = values[i];
|
|
4401
|
+
const b = values[j];
|
|
4402
|
+
const char = a[0];
|
|
4403
|
+
if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) {
|
|
4404
|
+
continue;
|
|
4405
|
+
}
|
|
4406
|
+
if (a === b || a.startsWith(b) || b.startsWith(a)) {
|
|
4407
|
+
return true;
|
|
4408
|
+
}
|
|
4409
|
+
}
|
|
4410
|
+
}
|
|
4411
|
+
return false;
|
|
4412
|
+
};
|
|
4413
|
+
var parseRepeatedExtglob = (pattern, requireEnd = true) => {
|
|
4414
|
+
if (pattern[0] !== "+" && pattern[0] !== "*" || pattern[1] !== "(") {
|
|
4415
|
+
return;
|
|
4416
|
+
}
|
|
4417
|
+
let bracket = 0;
|
|
4418
|
+
let paren = 0;
|
|
4419
|
+
let quote = 0;
|
|
4420
|
+
let escaped = false;
|
|
4421
|
+
for (let i = 1; i < pattern.length; i++) {
|
|
4422
|
+
const ch = pattern[i];
|
|
4423
|
+
if (escaped === true) {
|
|
4424
|
+
escaped = false;
|
|
4425
|
+
continue;
|
|
4426
|
+
}
|
|
4427
|
+
if (ch === "\\") {
|
|
4428
|
+
escaped = true;
|
|
4429
|
+
continue;
|
|
4430
|
+
}
|
|
4431
|
+
if (ch === '"') {
|
|
4432
|
+
quote = quote === 1 ? 0 : 1;
|
|
4433
|
+
continue;
|
|
4434
|
+
}
|
|
4435
|
+
if (quote === 1) {
|
|
4436
|
+
continue;
|
|
4437
|
+
}
|
|
4438
|
+
if (ch === "[") {
|
|
4439
|
+
bracket++;
|
|
4440
|
+
continue;
|
|
4441
|
+
}
|
|
4442
|
+
if (ch === "]" && bracket > 0) {
|
|
4443
|
+
bracket--;
|
|
4444
|
+
continue;
|
|
4445
|
+
}
|
|
4446
|
+
if (bracket > 0) {
|
|
4447
|
+
continue;
|
|
4448
|
+
}
|
|
4449
|
+
if (ch === "(") {
|
|
4450
|
+
paren++;
|
|
4451
|
+
continue;
|
|
4452
|
+
}
|
|
4453
|
+
if (ch === ")") {
|
|
4454
|
+
paren--;
|
|
4455
|
+
if (paren === 0) {
|
|
4456
|
+
if (requireEnd === true && i !== pattern.length - 1) {
|
|
4457
|
+
return;
|
|
4458
|
+
}
|
|
4459
|
+
return {
|
|
4460
|
+
type: pattern[0],
|
|
4461
|
+
body: pattern.slice(2, i),
|
|
4462
|
+
end: i
|
|
4463
|
+
};
|
|
4464
|
+
}
|
|
4465
|
+
}
|
|
4466
|
+
}
|
|
4467
|
+
};
|
|
4468
|
+
var getStarExtglobSequenceOutput = (pattern) => {
|
|
4469
|
+
let index = 0;
|
|
4470
|
+
const chars = [];
|
|
4471
|
+
while (index < pattern.length) {
|
|
4472
|
+
const match = parseRepeatedExtglob(pattern.slice(index), false);
|
|
4473
|
+
if (!match || match.type !== "*") {
|
|
4474
|
+
return;
|
|
4475
|
+
}
|
|
4476
|
+
const branches = splitTopLevel(match.body).map((branch2) => branch2.trim());
|
|
4477
|
+
if (branches.length !== 1) {
|
|
4478
|
+
return;
|
|
4479
|
+
}
|
|
4480
|
+
const branch = normalizeSimpleBranch(branches[0]);
|
|
4481
|
+
if (!branch || branch.length !== 1) {
|
|
4482
|
+
return;
|
|
4483
|
+
}
|
|
4484
|
+
chars.push(branch);
|
|
4485
|
+
index += match.end + 1;
|
|
4486
|
+
}
|
|
4487
|
+
if (chars.length < 1) {
|
|
4488
|
+
return;
|
|
4489
|
+
}
|
|
4490
|
+
const source = chars.length === 1 ? utils.escapeRegex(chars[0]) : `[${chars.map((ch) => utils.escapeRegex(ch)).join("")}]`;
|
|
4491
|
+
return `${source}*`;
|
|
4492
|
+
};
|
|
4493
|
+
var repeatedExtglobRecursion = (pattern) => {
|
|
4494
|
+
let depth = 0;
|
|
4495
|
+
let value = pattern.trim();
|
|
4496
|
+
let match = parseRepeatedExtglob(value);
|
|
4497
|
+
while (match) {
|
|
4498
|
+
depth++;
|
|
4499
|
+
value = match.body.trim();
|
|
4500
|
+
match = parseRepeatedExtglob(value);
|
|
4501
|
+
}
|
|
4502
|
+
return depth;
|
|
4503
|
+
};
|
|
4504
|
+
var analyzeRepeatedExtglob = (body, options) => {
|
|
4505
|
+
if (options.maxExtglobRecursion === false) {
|
|
4506
|
+
return { risky: false };
|
|
4507
|
+
}
|
|
4508
|
+
const max = typeof options.maxExtglobRecursion === "number" ? options.maxExtglobRecursion : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
|
|
4509
|
+
const branches = splitTopLevel(body).map((branch) => branch.trim());
|
|
4510
|
+
if (branches.length > 1) {
|
|
4511
|
+
if (branches.some((branch) => branch === "") || branches.some((branch) => /^[*?]+$/.test(branch)) || hasRepeatedCharPrefixOverlap(branches)) {
|
|
4512
|
+
return { risky: true };
|
|
4513
|
+
}
|
|
4514
|
+
}
|
|
4515
|
+
for (const branch of branches) {
|
|
4516
|
+
const safeOutput = getStarExtglobSequenceOutput(branch);
|
|
4517
|
+
if (safeOutput) {
|
|
4518
|
+
return { risky: true, safeOutput };
|
|
4519
|
+
}
|
|
4520
|
+
if (repeatedExtglobRecursion(branch) > max) {
|
|
4521
|
+
return { risky: true };
|
|
4522
|
+
}
|
|
4523
|
+
}
|
|
4524
|
+
return { risky: false };
|
|
4525
|
+
};
|
|
4526
|
+
var parse = (input, options) => {
|
|
4527
|
+
if (typeof input !== "string") {
|
|
4528
|
+
throw new TypeError("Expected a string");
|
|
4529
|
+
}
|
|
4530
|
+
input = REPLACEMENTS[input] || input;
|
|
4531
|
+
const opts = { ...options };
|
|
4532
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
4533
|
+
let len = input.length;
|
|
4534
|
+
if (len > max) {
|
|
4535
|
+
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
4536
|
+
}
|
|
4537
|
+
const bos = { type: "bos", value: "", output: opts.prepend || "" };
|
|
4538
|
+
const tokens = [bos];
|
|
4539
|
+
const capture = opts.capture ? "" : "?:";
|
|
4540
|
+
const PLATFORM_CHARS = constants.globChars(opts.windows);
|
|
4541
|
+
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
|
|
4542
|
+
const {
|
|
4543
|
+
DOT_LITERAL,
|
|
4544
|
+
PLUS_LITERAL,
|
|
4545
|
+
SLASH_LITERAL,
|
|
4546
|
+
ONE_CHAR,
|
|
4547
|
+
DOTS_SLASH,
|
|
4548
|
+
NO_DOT,
|
|
4549
|
+
NO_DOT_SLASH,
|
|
4550
|
+
NO_DOTS_SLASH,
|
|
4551
|
+
QMARK,
|
|
4552
|
+
QMARK_NO_DOT,
|
|
4553
|
+
STAR,
|
|
4554
|
+
START_ANCHOR
|
|
4555
|
+
} = PLATFORM_CHARS;
|
|
4556
|
+
const globstar = (opts2) => {
|
|
4557
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
4558
|
+
};
|
|
4559
|
+
const nodot = opts.dot ? "" : NO_DOT;
|
|
4560
|
+
const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
|
|
4561
|
+
let star = opts.bash === true ? globstar(opts) : STAR;
|
|
4562
|
+
if (opts.capture) {
|
|
4563
|
+
star = `(${star})`;
|
|
4564
|
+
}
|
|
4565
|
+
if (typeof opts.noext === "boolean") {
|
|
4566
|
+
opts.noextglob = opts.noext;
|
|
4567
|
+
}
|
|
4568
|
+
const state = {
|
|
4569
|
+
input,
|
|
4570
|
+
index: -1,
|
|
4571
|
+
start: 0,
|
|
4572
|
+
dot: opts.dot === true,
|
|
4573
|
+
consumed: "",
|
|
4574
|
+
output: "",
|
|
4575
|
+
prefix: "",
|
|
4576
|
+
backtrack: false,
|
|
4577
|
+
negated: false,
|
|
4578
|
+
brackets: 0,
|
|
4579
|
+
braces: 0,
|
|
4580
|
+
parens: 0,
|
|
4581
|
+
quotes: 0,
|
|
4582
|
+
globstar: false,
|
|
4583
|
+
tokens
|
|
4584
|
+
};
|
|
4585
|
+
input = utils.removePrefix(input, state);
|
|
4586
|
+
len = input.length;
|
|
4587
|
+
const extglobs = [];
|
|
4588
|
+
const braces = [];
|
|
4589
|
+
const stack = [];
|
|
4590
|
+
let prev = bos;
|
|
4591
|
+
let value;
|
|
4592
|
+
const eos = () => state.index === len - 1;
|
|
4593
|
+
const peek = state.peek = (n = 1) => input[state.index + n];
|
|
4594
|
+
const advance = state.advance = () => input[++state.index] || "";
|
|
4595
|
+
const remaining = () => input.slice(state.index + 1);
|
|
4596
|
+
const consume = (value2 = "", num = 0) => {
|
|
4597
|
+
state.consumed += value2;
|
|
4598
|
+
state.index += num;
|
|
4599
|
+
};
|
|
4600
|
+
const append = (token) => {
|
|
4601
|
+
state.output += token.output != null ? token.output : token.value;
|
|
4602
|
+
consume(token.value);
|
|
4603
|
+
};
|
|
4604
|
+
const negate = () => {
|
|
4605
|
+
let count = 1;
|
|
4606
|
+
while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
|
|
4607
|
+
advance();
|
|
4608
|
+
state.start++;
|
|
4609
|
+
count++;
|
|
4610
|
+
}
|
|
4611
|
+
if (count % 2 === 0) {
|
|
4612
|
+
return false;
|
|
4613
|
+
}
|
|
4614
|
+
state.negated = true;
|
|
4615
|
+
state.start++;
|
|
4616
|
+
return true;
|
|
4617
|
+
};
|
|
4618
|
+
const increment = (type) => {
|
|
4619
|
+
state[type]++;
|
|
4620
|
+
stack.push(type);
|
|
4621
|
+
};
|
|
4622
|
+
const decrement = (type) => {
|
|
4623
|
+
state[type]--;
|
|
4624
|
+
stack.pop();
|
|
4625
|
+
};
|
|
4626
|
+
const push = (tok) => {
|
|
4627
|
+
if (prev.type === "globstar") {
|
|
4628
|
+
const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
|
|
4629
|
+
const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
|
|
4630
|
+
if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
|
|
4631
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
4632
|
+
prev.type = "star";
|
|
4633
|
+
prev.value = "*";
|
|
4634
|
+
prev.output = star;
|
|
4635
|
+
state.output += prev.output;
|
|
4636
|
+
}
|
|
4637
|
+
}
|
|
4638
|
+
if (extglobs.length && tok.type !== "paren") {
|
|
4639
|
+
extglobs[extglobs.length - 1].inner += tok.value;
|
|
4640
|
+
}
|
|
4641
|
+
if (tok.value || tok.output)
|
|
4642
|
+
append(tok);
|
|
4643
|
+
if (prev && prev.type === "text" && tok.type === "text") {
|
|
4644
|
+
prev.output = (prev.output || prev.value) + tok.value;
|
|
4645
|
+
prev.value += tok.value;
|
|
4646
|
+
return;
|
|
4647
|
+
}
|
|
4648
|
+
tok.prev = prev;
|
|
4649
|
+
tokens.push(tok);
|
|
4650
|
+
prev = tok;
|
|
4651
|
+
};
|
|
4652
|
+
const extglobOpen = (type, value2) => {
|
|
4653
|
+
const token = { ...EXTGLOB_CHARS[value2], conditions: 1, inner: "" };
|
|
4654
|
+
token.prev = prev;
|
|
4655
|
+
token.parens = state.parens;
|
|
4656
|
+
token.output = state.output;
|
|
4657
|
+
token.startIndex = state.index;
|
|
4658
|
+
token.tokensIndex = tokens.length;
|
|
4659
|
+
const output = (opts.capture ? "(" : "") + token.open;
|
|
4660
|
+
increment("parens");
|
|
4661
|
+
push({ type, value: value2, output: state.output ? "" : ONE_CHAR });
|
|
4662
|
+
push({ type: "paren", extglob: true, value: advance(), output });
|
|
4663
|
+
extglobs.push(token);
|
|
4664
|
+
};
|
|
4665
|
+
const extglobClose = (token) => {
|
|
4666
|
+
const literal = input.slice(token.startIndex, state.index + 1);
|
|
4667
|
+
const body = input.slice(token.startIndex + 2, state.index);
|
|
4668
|
+
const analysis = analyzeRepeatedExtglob(body, opts);
|
|
4669
|
+
if ((token.type === "plus" || token.type === "star") && analysis.risky) {
|
|
4670
|
+
const safeOutput = analysis.safeOutput ? (token.output ? "" : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput) : void 0;
|
|
4671
|
+
const open = tokens[token.tokensIndex];
|
|
4672
|
+
open.type = "text";
|
|
4673
|
+
open.value = literal;
|
|
4674
|
+
open.output = safeOutput || utils.escapeRegex(literal);
|
|
4675
|
+
for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
|
|
4676
|
+
tokens[i].value = "";
|
|
4677
|
+
tokens[i].output = "";
|
|
4678
|
+
delete tokens[i].suffix;
|
|
4679
|
+
}
|
|
4680
|
+
state.output = token.output + open.output;
|
|
4681
|
+
state.backtrack = true;
|
|
4682
|
+
push({ type: "paren", extglob: true, value, output: "" });
|
|
4683
|
+
decrement("parens");
|
|
4684
|
+
return;
|
|
4685
|
+
}
|
|
4686
|
+
let output = token.close + (opts.capture ? ")" : "");
|
|
4687
|
+
let rest;
|
|
4688
|
+
if (token.type === "negate") {
|
|
4689
|
+
let extglobStar = star;
|
|
4690
|
+
if (token.inner && token.inner.length > 1 && token.inner.includes("/")) {
|
|
4691
|
+
extglobStar = globstar(opts);
|
|
4692
|
+
}
|
|
4693
|
+
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
|
|
4694
|
+
output = token.close = `)$))${extglobStar}`;
|
|
4695
|
+
}
|
|
4696
|
+
if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
|
|
4697
|
+
const expression = parse(rest, { ...options, fastpaths: false }).output;
|
|
4698
|
+
output = token.close = `)${expression})${extglobStar})`;
|
|
4699
|
+
}
|
|
4700
|
+
if (token.prev.type === "bos") {
|
|
4701
|
+
state.negatedExtglob = true;
|
|
4702
|
+
}
|
|
4703
|
+
}
|
|
4704
|
+
push({ type: "paren", extglob: true, value, output });
|
|
4705
|
+
decrement("parens");
|
|
4706
|
+
};
|
|
4707
|
+
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
4708
|
+
let backslashes = false;
|
|
4709
|
+
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
|
4710
|
+
if (first === "\\") {
|
|
4711
|
+
backslashes = true;
|
|
4712
|
+
return m;
|
|
4713
|
+
}
|
|
4714
|
+
if (first === "?") {
|
|
4715
|
+
if (esc) {
|
|
4716
|
+
return esc + first + (rest ? QMARK.repeat(rest.length) : "");
|
|
4717
|
+
}
|
|
4718
|
+
if (index === 0) {
|
|
4719
|
+
return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
|
|
4720
|
+
}
|
|
4721
|
+
return QMARK.repeat(chars.length);
|
|
4722
|
+
}
|
|
4723
|
+
if (first === ".") {
|
|
4724
|
+
return DOT_LITERAL.repeat(chars.length);
|
|
4725
|
+
}
|
|
4726
|
+
if (first === "*") {
|
|
4727
|
+
if (esc) {
|
|
4728
|
+
return esc + first + (rest ? star : "");
|
|
4729
|
+
}
|
|
4730
|
+
return star;
|
|
4731
|
+
}
|
|
4732
|
+
return esc ? m : `\\${m}`;
|
|
4733
|
+
});
|
|
4734
|
+
if (backslashes === true) {
|
|
4735
|
+
if (opts.unescape === true) {
|
|
4736
|
+
output = output.replace(/\\/g, "");
|
|
4737
|
+
} else {
|
|
4738
|
+
output = output.replace(/\\+/g, (m) => {
|
|
4739
|
+
return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
|
|
4740
|
+
});
|
|
4741
|
+
}
|
|
4742
|
+
}
|
|
4743
|
+
if (output === input && opts.contains === true) {
|
|
4744
|
+
state.output = input;
|
|
4745
|
+
return state;
|
|
4746
|
+
}
|
|
4747
|
+
state.output = utils.wrapOutput(output, state, options);
|
|
4748
|
+
return state;
|
|
4749
|
+
}
|
|
4750
|
+
while (!eos()) {
|
|
4751
|
+
value = advance();
|
|
4752
|
+
if (value === "\0") {
|
|
4753
|
+
continue;
|
|
4754
|
+
}
|
|
4755
|
+
if (value === "\\") {
|
|
4756
|
+
const next = peek();
|
|
4757
|
+
if (next === "/" && opts.bash !== true) {
|
|
4758
|
+
continue;
|
|
4759
|
+
}
|
|
4760
|
+
if (next === "." || next === ";") {
|
|
4761
|
+
continue;
|
|
4762
|
+
}
|
|
4763
|
+
if (!next) {
|
|
4764
|
+
value += "\\";
|
|
4765
|
+
push({ type: "text", value });
|
|
4766
|
+
continue;
|
|
4767
|
+
}
|
|
4768
|
+
const match = /^\\+/.exec(remaining());
|
|
4769
|
+
let slashes = 0;
|
|
4770
|
+
if (match && match[0].length > 2) {
|
|
4771
|
+
slashes = match[0].length;
|
|
4772
|
+
state.index += slashes;
|
|
4773
|
+
if (slashes % 2 !== 0) {
|
|
4774
|
+
value += "\\";
|
|
4775
|
+
}
|
|
4776
|
+
}
|
|
4777
|
+
if (opts.unescape === true) {
|
|
4778
|
+
value = advance();
|
|
4779
|
+
} else {
|
|
4780
|
+
value += advance();
|
|
4781
|
+
}
|
|
4782
|
+
if (state.brackets === 0) {
|
|
4783
|
+
push({ type: "text", value });
|
|
4784
|
+
continue;
|
|
4785
|
+
}
|
|
4786
|
+
}
|
|
4787
|
+
if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
|
|
4788
|
+
if (opts.posix !== false && value === ":") {
|
|
4789
|
+
const inner = prev.value.slice(1);
|
|
4790
|
+
if (inner.includes("[")) {
|
|
4791
|
+
prev.posix = true;
|
|
4792
|
+
if (inner.includes(":")) {
|
|
4793
|
+
const idx = prev.value.lastIndexOf("[");
|
|
4794
|
+
const pre = prev.value.slice(0, idx);
|
|
4795
|
+
const rest2 = prev.value.slice(idx + 2);
|
|
4796
|
+
const posix = POSIX_REGEX_SOURCE[rest2];
|
|
4797
|
+
if (posix) {
|
|
4798
|
+
prev.value = pre + posix;
|
|
4799
|
+
state.backtrack = true;
|
|
4800
|
+
advance();
|
|
4801
|
+
if (!bos.output && tokens.indexOf(prev) === 1) {
|
|
4802
|
+
bos.output = ONE_CHAR;
|
|
4803
|
+
}
|
|
4804
|
+
continue;
|
|
4805
|
+
}
|
|
4806
|
+
}
|
|
4807
|
+
}
|
|
4808
|
+
}
|
|
4809
|
+
if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") {
|
|
4810
|
+
value = `\\${value}`;
|
|
4811
|
+
}
|
|
4812
|
+
if (value === "]" && (prev.value === "[" || prev.value === "[^")) {
|
|
4813
|
+
value = `\\${value}`;
|
|
4814
|
+
}
|
|
4815
|
+
if (opts.posix === true && value === "!" && prev.value === "[") {
|
|
4816
|
+
value = "^";
|
|
4817
|
+
}
|
|
4818
|
+
prev.value += value;
|
|
4819
|
+
append({ value });
|
|
4820
|
+
continue;
|
|
4821
|
+
}
|
|
4822
|
+
if (state.quotes === 1 && value !== '"') {
|
|
4823
|
+
value = utils.escapeRegex(value);
|
|
4824
|
+
prev.value += value;
|
|
4825
|
+
append({ value });
|
|
4826
|
+
continue;
|
|
4827
|
+
}
|
|
4828
|
+
if (value === '"') {
|
|
4829
|
+
state.quotes = state.quotes === 1 ? 0 : 1;
|
|
4830
|
+
if (opts.keepQuotes === true) {
|
|
4831
|
+
push({ type: "text", value });
|
|
4832
|
+
}
|
|
4833
|
+
continue;
|
|
4834
|
+
}
|
|
4835
|
+
if (value === "(") {
|
|
4836
|
+
increment("parens");
|
|
4837
|
+
push({ type: "paren", value });
|
|
4838
|
+
continue;
|
|
4839
|
+
}
|
|
4840
|
+
if (value === ")") {
|
|
4841
|
+
if (state.parens === 0 && opts.strictBrackets === true) {
|
|
4842
|
+
throw new SyntaxError(syntaxError("opening", "("));
|
|
4843
|
+
}
|
|
4844
|
+
const extglob = extglobs[extglobs.length - 1];
|
|
4845
|
+
if (extglob && state.parens === extglob.parens + 1) {
|
|
4846
|
+
extglobClose(extglobs.pop());
|
|
4847
|
+
continue;
|
|
4848
|
+
}
|
|
4849
|
+
push({ type: "paren", value, output: state.parens ? ")" : "\\)" });
|
|
4850
|
+
decrement("parens");
|
|
4851
|
+
continue;
|
|
4852
|
+
}
|
|
4853
|
+
if (value === "[") {
|
|
4854
|
+
if (opts.nobracket === true || !remaining().includes("]")) {
|
|
4855
|
+
if (opts.nobracket !== true && opts.strictBrackets === true) {
|
|
4856
|
+
throw new SyntaxError(syntaxError("closing", "]"));
|
|
4857
|
+
}
|
|
4858
|
+
value = `\\${value}`;
|
|
4859
|
+
} else {
|
|
4860
|
+
increment("brackets");
|
|
4861
|
+
}
|
|
4862
|
+
push({ type: "bracket", value });
|
|
4863
|
+
continue;
|
|
4864
|
+
}
|
|
4865
|
+
if (value === "]") {
|
|
4866
|
+
if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
|
|
4867
|
+
push({ type: "text", value, output: `\\${value}` });
|
|
4868
|
+
continue;
|
|
4869
|
+
}
|
|
4870
|
+
if (state.brackets === 0) {
|
|
4871
|
+
if (opts.strictBrackets === true) {
|
|
4872
|
+
throw new SyntaxError(syntaxError("opening", "["));
|
|
4873
|
+
}
|
|
4874
|
+
push({ type: "text", value, output: `\\${value}` });
|
|
4875
|
+
continue;
|
|
4876
|
+
}
|
|
4877
|
+
decrement("brackets");
|
|
4878
|
+
const prevValue = prev.value.slice(1);
|
|
4879
|
+
if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) {
|
|
4880
|
+
value = `/${value}`;
|
|
4881
|
+
}
|
|
4882
|
+
prev.value += value;
|
|
4883
|
+
append({ value });
|
|
4884
|
+
if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
|
|
4885
|
+
continue;
|
|
4886
|
+
}
|
|
4887
|
+
const escaped = utils.escapeRegex(prev.value);
|
|
4888
|
+
state.output = state.output.slice(0, -prev.value.length);
|
|
4889
|
+
if (opts.literalBrackets === true) {
|
|
4890
|
+
state.output += escaped;
|
|
4891
|
+
prev.value = escaped;
|
|
4892
|
+
continue;
|
|
4893
|
+
}
|
|
4894
|
+
prev.value = `(${capture}${escaped}|${prev.value})`;
|
|
4895
|
+
state.output += prev.value;
|
|
4896
|
+
continue;
|
|
4897
|
+
}
|
|
4898
|
+
if (value === "{" && opts.nobrace !== true) {
|
|
4899
|
+
increment("braces");
|
|
4900
|
+
const open = {
|
|
4901
|
+
type: "brace",
|
|
4902
|
+
value,
|
|
4903
|
+
output: "(",
|
|
4904
|
+
outputIndex: state.output.length,
|
|
4905
|
+
tokensIndex: state.tokens.length
|
|
4906
|
+
};
|
|
4907
|
+
braces.push(open);
|
|
4908
|
+
push(open);
|
|
4909
|
+
continue;
|
|
4910
|
+
}
|
|
4911
|
+
if (value === "}") {
|
|
4912
|
+
const brace = braces[braces.length - 1];
|
|
4913
|
+
if (opts.nobrace === true || !brace) {
|
|
4914
|
+
push({ type: "text", value, output: value });
|
|
4915
|
+
continue;
|
|
4916
|
+
}
|
|
4917
|
+
let output = ")";
|
|
4918
|
+
if (brace.dots === true) {
|
|
4919
|
+
const arr = tokens.slice();
|
|
4920
|
+
const range = [];
|
|
4921
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
4922
|
+
tokens.pop();
|
|
4923
|
+
if (arr[i].type === "brace") {
|
|
4924
|
+
break;
|
|
4925
|
+
}
|
|
4926
|
+
if (arr[i].type !== "dots") {
|
|
4927
|
+
range.unshift(arr[i].value);
|
|
4928
|
+
}
|
|
4929
|
+
}
|
|
4930
|
+
output = expandRange(range, opts);
|
|
4931
|
+
state.backtrack = true;
|
|
4932
|
+
}
|
|
4933
|
+
if (brace.comma !== true && brace.dots !== true) {
|
|
4934
|
+
const out = state.output.slice(0, brace.outputIndex);
|
|
4935
|
+
const toks = state.tokens.slice(brace.tokensIndex);
|
|
4936
|
+
brace.value = brace.output = "\\{";
|
|
4937
|
+
value = output = "\\}";
|
|
4938
|
+
state.output = out;
|
|
4939
|
+
for (const t of toks) {
|
|
4940
|
+
state.output += t.output || t.value;
|
|
4941
|
+
}
|
|
4942
|
+
}
|
|
4943
|
+
push({ type: "brace", value, output });
|
|
4944
|
+
decrement("braces");
|
|
4945
|
+
braces.pop();
|
|
4946
|
+
continue;
|
|
4947
|
+
}
|
|
4948
|
+
if (value === "|") {
|
|
4949
|
+
if (extglobs.length > 0) {
|
|
4950
|
+
extglobs[extglobs.length - 1].conditions++;
|
|
4951
|
+
}
|
|
4952
|
+
push({ type: "text", value });
|
|
4953
|
+
continue;
|
|
4954
|
+
}
|
|
4955
|
+
if (value === ",") {
|
|
4956
|
+
let output = value;
|
|
4957
|
+
const brace = braces[braces.length - 1];
|
|
4958
|
+
if (brace && stack[stack.length - 1] === "braces") {
|
|
4959
|
+
brace.comma = true;
|
|
4960
|
+
output = "|";
|
|
4961
|
+
}
|
|
4962
|
+
push({ type: "comma", value, output });
|
|
4963
|
+
continue;
|
|
4964
|
+
}
|
|
4965
|
+
if (value === "/") {
|
|
4966
|
+
if (prev.type === "dot" && state.index === state.start + 1) {
|
|
4967
|
+
state.start = state.index + 1;
|
|
4968
|
+
state.consumed = "";
|
|
4969
|
+
state.output = "";
|
|
4970
|
+
tokens.pop();
|
|
4971
|
+
prev = bos;
|
|
4972
|
+
continue;
|
|
4973
|
+
}
|
|
4974
|
+
push({ type: "slash", value, output: SLASH_LITERAL });
|
|
4975
|
+
continue;
|
|
4976
|
+
}
|
|
4977
|
+
if (value === ".") {
|
|
4978
|
+
if (state.braces > 0 && prev.type === "dot") {
|
|
4979
|
+
if (prev.value === ".")
|
|
4980
|
+
prev.output = DOT_LITERAL;
|
|
4981
|
+
const brace = braces[braces.length - 1];
|
|
4982
|
+
prev.type = "dots";
|
|
4983
|
+
prev.output += value;
|
|
4984
|
+
prev.value += value;
|
|
4985
|
+
brace.dots = true;
|
|
4986
|
+
continue;
|
|
4987
|
+
}
|
|
4988
|
+
if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
|
|
4989
|
+
push({ type: "text", value, output: DOT_LITERAL });
|
|
4990
|
+
continue;
|
|
4991
|
+
}
|
|
4992
|
+
push({ type: "dot", value, output: DOT_LITERAL });
|
|
4993
|
+
continue;
|
|
4994
|
+
}
|
|
4995
|
+
if (value === "?") {
|
|
4996
|
+
const isGroup = prev && prev.value === "(";
|
|
4997
|
+
if (!isGroup && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
4998
|
+
extglobOpen("qmark", value);
|
|
4999
|
+
continue;
|
|
5000
|
+
}
|
|
5001
|
+
if (prev && prev.type === "paren") {
|
|
5002
|
+
const next = peek();
|
|
5003
|
+
let output = value;
|
|
5004
|
+
if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) {
|
|
5005
|
+
output = `\\${value}`;
|
|
5006
|
+
}
|
|
5007
|
+
push({ type: "text", value, output });
|
|
5008
|
+
continue;
|
|
5009
|
+
}
|
|
5010
|
+
if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
|
|
5011
|
+
push({ type: "qmark", value, output: QMARK_NO_DOT });
|
|
5012
|
+
continue;
|
|
5013
|
+
}
|
|
5014
|
+
push({ type: "qmark", value, output: QMARK });
|
|
5015
|
+
continue;
|
|
5016
|
+
}
|
|
5017
|
+
if (value === "!") {
|
|
5018
|
+
if (opts.noextglob !== true && peek() === "(") {
|
|
5019
|
+
if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
|
|
5020
|
+
extglobOpen("negate", value);
|
|
5021
|
+
continue;
|
|
5022
|
+
}
|
|
5023
|
+
}
|
|
5024
|
+
if (opts.nonegate !== true && state.index === 0) {
|
|
5025
|
+
negate();
|
|
5026
|
+
continue;
|
|
5027
|
+
}
|
|
5028
|
+
}
|
|
5029
|
+
if (value === "+") {
|
|
5030
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
5031
|
+
extglobOpen("plus", value);
|
|
5032
|
+
continue;
|
|
5033
|
+
}
|
|
5034
|
+
if (prev && prev.value === "(" || opts.regex === false) {
|
|
5035
|
+
push({ type: "plus", value, output: PLUS_LITERAL });
|
|
5036
|
+
continue;
|
|
5037
|
+
}
|
|
5038
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
|
|
5039
|
+
push({ type: "plus", value });
|
|
5040
|
+
continue;
|
|
5041
|
+
}
|
|
5042
|
+
push({ type: "plus", value: PLUS_LITERAL });
|
|
5043
|
+
continue;
|
|
5044
|
+
}
|
|
5045
|
+
if (value === "@") {
|
|
5046
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
5047
|
+
push({ type: "at", extglob: true, value, output: "" });
|
|
5048
|
+
continue;
|
|
5049
|
+
}
|
|
5050
|
+
push({ type: "text", value });
|
|
5051
|
+
continue;
|
|
5052
|
+
}
|
|
5053
|
+
if (value !== "*") {
|
|
5054
|
+
if (value === "$" || value === "^") {
|
|
5055
|
+
value = `\\${value}`;
|
|
5056
|
+
}
|
|
5057
|
+
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
|
5058
|
+
if (match) {
|
|
5059
|
+
value += match[0];
|
|
5060
|
+
state.index += match[0].length;
|
|
5061
|
+
}
|
|
5062
|
+
push({ type: "text", value });
|
|
5063
|
+
continue;
|
|
5064
|
+
}
|
|
5065
|
+
if (prev && (prev.type === "globstar" || prev.star === true)) {
|
|
5066
|
+
prev.type = "star";
|
|
5067
|
+
prev.star = true;
|
|
5068
|
+
prev.value += value;
|
|
5069
|
+
prev.output = star;
|
|
5070
|
+
state.backtrack = true;
|
|
5071
|
+
state.globstar = true;
|
|
5072
|
+
consume(value);
|
|
5073
|
+
continue;
|
|
5074
|
+
}
|
|
5075
|
+
let rest = remaining();
|
|
5076
|
+
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
5077
|
+
extglobOpen("star", value);
|
|
5078
|
+
continue;
|
|
5079
|
+
}
|
|
5080
|
+
if (prev.type === "star") {
|
|
5081
|
+
if (opts.noglobstar === true) {
|
|
5082
|
+
consume(value);
|
|
5083
|
+
continue;
|
|
5084
|
+
}
|
|
5085
|
+
const prior = prev.prev;
|
|
5086
|
+
const before = prior.prev;
|
|
5087
|
+
const isStart = prior.type === "slash" || prior.type === "bos";
|
|
5088
|
+
const afterStar = before && (before.type === "star" || before.type === "globstar");
|
|
5089
|
+
if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
|
|
5090
|
+
push({ type: "star", value, output: "" });
|
|
5091
|
+
continue;
|
|
5092
|
+
}
|
|
5093
|
+
const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
|
|
5094
|
+
const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
|
|
5095
|
+
if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
|
|
5096
|
+
push({ type: "star", value, output: "" });
|
|
5097
|
+
continue;
|
|
5098
|
+
}
|
|
5099
|
+
while (rest.slice(0, 3) === "/**") {
|
|
5100
|
+
const after = input[state.index + 4];
|
|
5101
|
+
if (after && after !== "/") {
|
|
5102
|
+
break;
|
|
5103
|
+
}
|
|
5104
|
+
rest = rest.slice(3);
|
|
5105
|
+
consume("/**", 3);
|
|
5106
|
+
}
|
|
5107
|
+
if (prior.type === "bos" && eos()) {
|
|
5108
|
+
prev.type = "globstar";
|
|
5109
|
+
prev.value += value;
|
|
5110
|
+
prev.output = globstar(opts);
|
|
5111
|
+
state.output = prev.output;
|
|
5112
|
+
state.globstar = true;
|
|
5113
|
+
consume(value);
|
|
5114
|
+
continue;
|
|
5115
|
+
}
|
|
5116
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
|
|
5117
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
5118
|
+
prior.output = `(?:${prior.output}`;
|
|
5119
|
+
prev.type = "globstar";
|
|
5120
|
+
prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
|
|
5121
|
+
prev.value += value;
|
|
5122
|
+
state.globstar = true;
|
|
5123
|
+
state.output += prior.output + prev.output;
|
|
5124
|
+
consume(value);
|
|
5125
|
+
continue;
|
|
5126
|
+
}
|
|
5127
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
|
|
5128
|
+
const end = rest[1] !== void 0 ? "|$" : "";
|
|
5129
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
5130
|
+
prior.output = `(?:${prior.output}`;
|
|
5131
|
+
prev.type = "globstar";
|
|
5132
|
+
prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
|
|
5133
|
+
prev.value += value;
|
|
5134
|
+
state.output += prior.output + prev.output;
|
|
5135
|
+
state.globstar = true;
|
|
5136
|
+
consume(value + advance());
|
|
5137
|
+
push({ type: "slash", value: "/", output: "" });
|
|
5138
|
+
continue;
|
|
5139
|
+
}
|
|
5140
|
+
if (prior.type === "bos" && rest[0] === "/") {
|
|
5141
|
+
prev.type = "globstar";
|
|
5142
|
+
prev.value += value;
|
|
5143
|
+
prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
|
|
5144
|
+
state.output = prev.output;
|
|
5145
|
+
state.globstar = true;
|
|
5146
|
+
consume(value + advance());
|
|
5147
|
+
push({ type: "slash", value: "/", output: "" });
|
|
5148
|
+
continue;
|
|
5149
|
+
}
|
|
5150
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
5151
|
+
prev.type = "globstar";
|
|
5152
|
+
prev.output = globstar(opts);
|
|
5153
|
+
prev.value += value;
|
|
5154
|
+
state.output += prev.output;
|
|
5155
|
+
state.globstar = true;
|
|
5156
|
+
consume(value);
|
|
5157
|
+
continue;
|
|
5158
|
+
}
|
|
5159
|
+
const token = { type: "star", value, output: star };
|
|
5160
|
+
if (opts.bash === true) {
|
|
5161
|
+
token.output = ".*?";
|
|
5162
|
+
if (prev.type === "bos" || prev.type === "slash") {
|
|
5163
|
+
token.output = nodot + token.output;
|
|
5164
|
+
}
|
|
5165
|
+
push(token);
|
|
5166
|
+
continue;
|
|
5167
|
+
}
|
|
5168
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
|
|
5169
|
+
token.output = value;
|
|
5170
|
+
push(token);
|
|
5171
|
+
continue;
|
|
5172
|
+
}
|
|
5173
|
+
if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
|
|
5174
|
+
if (prev.type === "dot") {
|
|
5175
|
+
state.output += NO_DOT_SLASH;
|
|
5176
|
+
prev.output += NO_DOT_SLASH;
|
|
5177
|
+
} else if (opts.dot === true) {
|
|
5178
|
+
state.output += NO_DOTS_SLASH;
|
|
5179
|
+
prev.output += NO_DOTS_SLASH;
|
|
5180
|
+
} else {
|
|
5181
|
+
state.output += nodot;
|
|
5182
|
+
prev.output += nodot;
|
|
5183
|
+
}
|
|
5184
|
+
if (peek() !== "*") {
|
|
5185
|
+
state.output += ONE_CHAR;
|
|
5186
|
+
prev.output += ONE_CHAR;
|
|
5187
|
+
}
|
|
5188
|
+
}
|
|
5189
|
+
push(token);
|
|
5190
|
+
}
|
|
5191
|
+
while (state.brackets > 0) {
|
|
5192
|
+
if (opts.strictBrackets === true)
|
|
5193
|
+
throw new SyntaxError(syntaxError("closing", "]"));
|
|
5194
|
+
state.output = utils.escapeLast(state.output, "[");
|
|
5195
|
+
decrement("brackets");
|
|
5196
|
+
}
|
|
5197
|
+
while (state.parens > 0) {
|
|
5198
|
+
if (opts.strictBrackets === true)
|
|
5199
|
+
throw new SyntaxError(syntaxError("closing", ")"));
|
|
5200
|
+
state.output = utils.escapeLast(state.output, "(");
|
|
5201
|
+
decrement("parens");
|
|
5202
|
+
}
|
|
5203
|
+
while (state.braces > 0) {
|
|
5204
|
+
if (opts.strictBrackets === true)
|
|
5205
|
+
throw new SyntaxError(syntaxError("closing", "}"));
|
|
5206
|
+
state.output = utils.escapeLast(state.output, "{");
|
|
5207
|
+
decrement("braces");
|
|
5208
|
+
}
|
|
5209
|
+
if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) {
|
|
5210
|
+
push({ type: "maybe_slash", value: "", output: `${SLASH_LITERAL}?` });
|
|
5211
|
+
}
|
|
5212
|
+
if (state.backtrack === true) {
|
|
5213
|
+
state.output = "";
|
|
5214
|
+
for (const token of state.tokens) {
|
|
5215
|
+
state.output += token.output != null ? token.output : token.value;
|
|
5216
|
+
if (token.suffix) {
|
|
5217
|
+
state.output += token.suffix;
|
|
5218
|
+
}
|
|
5219
|
+
}
|
|
5220
|
+
}
|
|
5221
|
+
return state;
|
|
5222
|
+
};
|
|
5223
|
+
parse.fastpaths = (input, options) => {
|
|
5224
|
+
const opts = { ...options };
|
|
5225
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
5226
|
+
const len = input.length;
|
|
5227
|
+
if (len > max) {
|
|
5228
|
+
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
5229
|
+
}
|
|
5230
|
+
input = REPLACEMENTS[input] || input;
|
|
5231
|
+
const {
|
|
5232
|
+
DOT_LITERAL,
|
|
5233
|
+
SLASH_LITERAL,
|
|
5234
|
+
ONE_CHAR,
|
|
5235
|
+
DOTS_SLASH,
|
|
5236
|
+
NO_DOT,
|
|
5237
|
+
NO_DOTS,
|
|
5238
|
+
NO_DOTS_SLASH,
|
|
5239
|
+
STAR,
|
|
5240
|
+
START_ANCHOR
|
|
5241
|
+
} = constants.globChars(opts.windows);
|
|
5242
|
+
const nodot = opts.dot ? NO_DOTS : NO_DOT;
|
|
5243
|
+
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
|
5244
|
+
const capture = opts.capture ? "" : "?:";
|
|
5245
|
+
const state = { negated: false, prefix: "" };
|
|
5246
|
+
let star = opts.bash === true ? ".*?" : STAR;
|
|
5247
|
+
if (opts.capture) {
|
|
5248
|
+
star = `(${star})`;
|
|
5249
|
+
}
|
|
5250
|
+
const globstar = (opts2) => {
|
|
5251
|
+
if (opts2.noglobstar === true)
|
|
5252
|
+
return star;
|
|
5253
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
5254
|
+
};
|
|
5255
|
+
const create = (str) => {
|
|
5256
|
+
switch (str) {
|
|
5257
|
+
case "*":
|
|
5258
|
+
return `${nodot}${ONE_CHAR}${star}`;
|
|
5259
|
+
case ".*":
|
|
5260
|
+
return `${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
5261
|
+
case "*.*":
|
|
5262
|
+
return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
5263
|
+
case "*/*":
|
|
5264
|
+
return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
|
|
5265
|
+
case "**":
|
|
5266
|
+
return nodot + globstar(opts);
|
|
5267
|
+
case "**/*":
|
|
5268
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
|
|
5269
|
+
case "**/*.*":
|
|
5270
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
5271
|
+
case "**/.*":
|
|
5272
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
5273
|
+
default: {
|
|
5274
|
+
const match = /^(.*?)\.(\w+)$/.exec(str);
|
|
5275
|
+
if (!match)
|
|
5276
|
+
return;
|
|
5277
|
+
const source2 = create(match[1]);
|
|
5278
|
+
if (!source2)
|
|
5279
|
+
return;
|
|
5280
|
+
return source2 + DOT_LITERAL + match[2];
|
|
5281
|
+
}
|
|
5282
|
+
}
|
|
5283
|
+
};
|
|
5284
|
+
const output = utils.removePrefix(input, state);
|
|
5285
|
+
let source = create(output);
|
|
5286
|
+
if (source && opts.strictSlashes !== true) {
|
|
5287
|
+
source += `${SLASH_LITERAL}?`;
|
|
5288
|
+
}
|
|
5289
|
+
return source;
|
|
5290
|
+
};
|
|
5291
|
+
module2.exports = parse;
|
|
5292
|
+
}
|
|
5293
|
+
});
|
|
5294
|
+
|
|
5295
|
+
// node_modules/picomatch/lib/picomatch.js
|
|
5296
|
+
var require_picomatch = __commonJS({
|
|
5297
|
+
"node_modules/picomatch/lib/picomatch.js"(exports2, module2) {
|
|
5298
|
+
"use strict";
|
|
5299
|
+
var scan = require_scan();
|
|
5300
|
+
var parse = require_parse();
|
|
5301
|
+
var utils = require_utils();
|
|
5302
|
+
var constants = require_constants();
|
|
5303
|
+
var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
|
|
5304
|
+
var picomatch2 = (glob, options, returnState = false) => {
|
|
5305
|
+
if (Array.isArray(glob)) {
|
|
5306
|
+
const fns = glob.map((input) => picomatch2(input, options, returnState));
|
|
5307
|
+
const arrayMatcher = (str) => {
|
|
5308
|
+
for (const isMatch of fns) {
|
|
5309
|
+
const state2 = isMatch(str);
|
|
5310
|
+
if (state2)
|
|
5311
|
+
return state2;
|
|
5312
|
+
}
|
|
5313
|
+
return false;
|
|
5314
|
+
};
|
|
5315
|
+
return arrayMatcher;
|
|
5316
|
+
}
|
|
5317
|
+
const isState = isObject(glob) && glob.tokens && glob.input;
|
|
5318
|
+
if (glob === "" || typeof glob !== "string" && !isState) {
|
|
5319
|
+
throw new TypeError("Expected pattern to be a non-empty string");
|
|
5320
|
+
}
|
|
5321
|
+
const opts = options || {};
|
|
5322
|
+
const posix = opts.windows;
|
|
5323
|
+
const regex = isState ? picomatch2.compileRe(glob, options) : picomatch2.makeRe(glob, options, false, true);
|
|
5324
|
+
const state = regex.state;
|
|
5325
|
+
delete regex.state;
|
|
5326
|
+
let isIgnored = () => false;
|
|
5327
|
+
if (opts.ignore) {
|
|
5328
|
+
const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
|
|
5329
|
+
isIgnored = picomatch2(opts.ignore, ignoreOpts, returnState);
|
|
5330
|
+
}
|
|
5331
|
+
const matcher = (input, returnObject = false) => {
|
|
5332
|
+
const { isMatch, match, output } = picomatch2.test(input, regex, options, { glob, posix });
|
|
5333
|
+
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
|
5334
|
+
if (typeof opts.onResult === "function") {
|
|
5335
|
+
opts.onResult(result);
|
|
5336
|
+
}
|
|
5337
|
+
if (isMatch === false) {
|
|
5338
|
+
result.isMatch = false;
|
|
5339
|
+
return returnObject ? result : false;
|
|
5340
|
+
}
|
|
5341
|
+
if (isIgnored(input)) {
|
|
5342
|
+
if (typeof opts.onIgnore === "function") {
|
|
5343
|
+
opts.onIgnore(result);
|
|
5344
|
+
}
|
|
5345
|
+
result.isMatch = false;
|
|
5346
|
+
return returnObject ? result : false;
|
|
5347
|
+
}
|
|
5348
|
+
if (typeof opts.onMatch === "function") {
|
|
5349
|
+
opts.onMatch(result);
|
|
5350
|
+
}
|
|
5351
|
+
return returnObject ? result : true;
|
|
5352
|
+
};
|
|
5353
|
+
if (returnState) {
|
|
5354
|
+
matcher.state = state;
|
|
5355
|
+
}
|
|
5356
|
+
return matcher;
|
|
5357
|
+
};
|
|
5358
|
+
picomatch2.test = (input, regex, options, { glob, posix } = {}) => {
|
|
5359
|
+
if (typeof input !== "string") {
|
|
5360
|
+
throw new TypeError("Expected input to be a string");
|
|
5361
|
+
}
|
|
5362
|
+
if (input === "") {
|
|
5363
|
+
return { isMatch: false, output: "" };
|
|
5364
|
+
}
|
|
5365
|
+
const opts = options || {};
|
|
5366
|
+
const format = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
5367
|
+
let match = input === glob;
|
|
5368
|
+
let output = match && format ? format(input) : input;
|
|
5369
|
+
if (match === false) {
|
|
5370
|
+
output = format ? format(input) : input;
|
|
5371
|
+
match = output === glob;
|
|
5372
|
+
}
|
|
5373
|
+
if (match === false || opts.capture === true) {
|
|
5374
|
+
if (opts.matchBase === true || opts.basename === true) {
|
|
5375
|
+
match = picomatch2.matchBase(input, regex, options, posix);
|
|
5376
|
+
} else {
|
|
5377
|
+
match = regex.exec(output);
|
|
5378
|
+
}
|
|
5379
|
+
}
|
|
5380
|
+
return { isMatch: Boolean(match), match, output };
|
|
5381
|
+
};
|
|
5382
|
+
picomatch2.matchBase = (input, glob, options) => {
|
|
5383
|
+
const regex = glob instanceof RegExp ? glob : picomatch2.makeRe(glob, options);
|
|
5384
|
+
return regex.test(utils.basename(input));
|
|
5385
|
+
};
|
|
5386
|
+
picomatch2.isMatch = (str, patterns, options) => picomatch2(patterns, options)(str);
|
|
5387
|
+
picomatch2.parse = (pattern, options) => {
|
|
5388
|
+
if (Array.isArray(pattern))
|
|
5389
|
+
return pattern.map((p2) => picomatch2.parse(p2, options));
|
|
5390
|
+
return parse(pattern, { ...options, fastpaths: false });
|
|
5391
|
+
};
|
|
5392
|
+
picomatch2.scan = (input, options) => scan(input, options);
|
|
5393
|
+
picomatch2.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
5394
|
+
if (returnOutput === true) {
|
|
5395
|
+
return state.output;
|
|
5396
|
+
}
|
|
5397
|
+
const opts = options || {};
|
|
5398
|
+
const prepend = opts.contains ? "" : "^";
|
|
5399
|
+
const append = opts.contains ? "" : "$";
|
|
5400
|
+
let source = `${prepend}(?:${state.output})${append}`;
|
|
5401
|
+
if (state && state.negated === true) {
|
|
5402
|
+
source = `^(?!${source}).*$`;
|
|
5403
|
+
}
|
|
5404
|
+
const regex = picomatch2.toRegex(source, options);
|
|
5405
|
+
if (returnState === true) {
|
|
5406
|
+
regex.state = state;
|
|
5407
|
+
}
|
|
5408
|
+
return regex;
|
|
5409
|
+
};
|
|
5410
|
+
picomatch2.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
5411
|
+
if (!input || typeof input !== "string") {
|
|
5412
|
+
throw new TypeError("Expected a non-empty string");
|
|
5413
|
+
}
|
|
5414
|
+
let parsed = { negated: false, fastpaths: true };
|
|
5415
|
+
if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) {
|
|
5416
|
+
parsed.output = parse.fastpaths(input, options);
|
|
5417
|
+
}
|
|
5418
|
+
if (!parsed.output) {
|
|
5419
|
+
parsed = parse(input, options);
|
|
5420
|
+
}
|
|
5421
|
+
return picomatch2.compileRe(parsed, options, returnOutput, returnState);
|
|
5422
|
+
};
|
|
5423
|
+
picomatch2.toRegex = (source, options) => {
|
|
5424
|
+
try {
|
|
5425
|
+
const opts = options || {};
|
|
5426
|
+
return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
|
|
5427
|
+
} catch (err) {
|
|
5428
|
+
if (options && options.debug === true)
|
|
5429
|
+
throw err;
|
|
5430
|
+
return /$^/;
|
|
5431
|
+
}
|
|
5432
|
+
};
|
|
5433
|
+
picomatch2.constants = constants;
|
|
5434
|
+
module2.exports = picomatch2;
|
|
5435
|
+
}
|
|
5436
|
+
});
|
|
5437
|
+
|
|
5438
|
+
// node_modules/picomatch/index.js
|
|
5439
|
+
var require_picomatch2 = __commonJS({
|
|
5440
|
+
"node_modules/picomatch/index.js"(exports2, module2) {
|
|
5441
|
+
"use strict";
|
|
5442
|
+
var pico = require_picomatch();
|
|
5443
|
+
var utils = require_utils();
|
|
5444
|
+
function picomatch2(glob, options, returnState = false) {
|
|
5445
|
+
if (options && (options.windows === null || options.windows === void 0)) {
|
|
5446
|
+
options = { ...options, windows: utils.isWindows() };
|
|
5447
|
+
}
|
|
5448
|
+
return pico(glob, options, returnState);
|
|
5449
|
+
}
|
|
5450
|
+
Object.assign(picomatch2, pico);
|
|
5451
|
+
module2.exports = picomatch2;
|
|
5452
|
+
}
|
|
5453
|
+
});
|
|
5454
|
+
|
|
3689
5455
|
// src/cleanup.ts
|
|
3690
5456
|
var fs3 = __toESM(require("fs/promises"));
|
|
3691
5457
|
var crypto2 = __toESM(require("crypto"));
|
|
@@ -3838,9 +5604,10 @@ async function performCleanup(cwd, all) {
|
|
|
3838
5604
|
|
|
3839
5605
|
// src/installer.ts
|
|
3840
5606
|
var import_child_process2 = require("child_process");
|
|
3841
|
-
var
|
|
3842
|
-
var
|
|
5607
|
+
var fs5 = __toESM(require("fs/promises"));
|
|
5608
|
+
var path4 = __toESM(require("path"));
|
|
3843
5609
|
var os3 = __toESM(require("os"));
|
|
5610
|
+
var p = __toESM(require("@clack/prompts"));
|
|
3844
5611
|
|
|
3845
5612
|
// src/detector.ts
|
|
3846
5613
|
var import_child_process = require("child_process");
|
|
@@ -3860,7 +5627,358 @@ async function findPython() {
|
|
|
3860
5627
|
throw new Error("Python not found. Please install Python 3.x and ensure it is in PATH.");
|
|
3861
5628
|
}
|
|
3862
5629
|
|
|
5630
|
+
// src/config.ts
|
|
5631
|
+
var fs4 = __toESM(require("fs/promises"));
|
|
5632
|
+
var path3 = __toESM(require("path"));
|
|
5633
|
+
var DEFAULT_CONFIG = {
|
|
5634
|
+
targetEncoding: "UTF-8",
|
|
5635
|
+
confidenceThreshold: 0.8,
|
|
5636
|
+
defaultEncoding: "GB18030"
|
|
5637
|
+
};
|
|
5638
|
+
function migrateLegacyConfig(parsed) {
|
|
5639
|
+
if (parsed.sourceEncoding && !parsed.defaultEncoding) {
|
|
5640
|
+
parsed.defaultEncoding = parsed.sourceEncoding;
|
|
5641
|
+
delete parsed.sourceEncoding;
|
|
5642
|
+
}
|
|
5643
|
+
}
|
|
5644
|
+
async function loadProjectConfig(cwd) {
|
|
5645
|
+
const configPath = path3.join(cwd, ".encoding-converter.json");
|
|
5646
|
+
try {
|
|
5647
|
+
const content = await fs4.readFile(configPath, "utf-8");
|
|
5648
|
+
const parsed = JSON.parse(content);
|
|
5649
|
+
migrateLegacyConfig(parsed);
|
|
5650
|
+
return { ...DEFAULT_CONFIG, ...parsed };
|
|
5651
|
+
} catch (err) {
|
|
5652
|
+
if (err.code !== "ENOENT") {
|
|
5653
|
+
log("error", "Failed to parse config file", { path: configPath, error: err.message });
|
|
5654
|
+
}
|
|
5655
|
+
return { ...DEFAULT_CONFIG };
|
|
5656
|
+
}
|
|
5657
|
+
}
|
|
5658
|
+
|
|
3863
5659
|
// src/installer.ts
|
|
5660
|
+
var import_picomatch = __toESM(require_picomatch2());
|
|
5661
|
+
var CANCEL_SYMBOL = Symbol.for("clack:cancel");
|
|
5662
|
+
function cancelable(promise) {
|
|
5663
|
+
return promise.then((result) => {
|
|
5664
|
+
if (p.isCancel(result)) {
|
|
5665
|
+
p.cancel("\u64CD\u4F5C\u5DF2\u53D6\u6D88");
|
|
5666
|
+
process.exit(0);
|
|
5667
|
+
}
|
|
5668
|
+
return result;
|
|
5669
|
+
});
|
|
5670
|
+
}
|
|
5671
|
+
var ENCODING_PRESETS = [
|
|
5672
|
+
{ label: "GB18030", value: "GB18030" },
|
|
5673
|
+
{ label: "UTF-8", value: "UTF-8" },
|
|
5674
|
+
{ label: "GBK", value: "GBK" },
|
|
5675
|
+
{ label: "GB2312", value: "GB2312" }
|
|
5676
|
+
];
|
|
5677
|
+
function renderConfigInfo(config) {
|
|
5678
|
+
const lines = [];
|
|
5679
|
+
lines.push("\u5F53\u524D\u914D\u7F6E\uFF1A");
|
|
5680
|
+
lines.push(` \u7F6E\u4FE1\u5EA6\u9608\u503C\uFF1A${config.confidenceThreshold}`);
|
|
5681
|
+
lines.push(` \u9ED8\u8BA4\u7F16\u7801\uFF1A${config.defaultEncoding || "\u672A\u8BBE\u7F6E"}`);
|
|
5682
|
+
if (config.directoryRules && Object.keys(config.directoryRules).length > 0) {
|
|
5683
|
+
lines.push(" \u76EE\u5F55\u89C4\u5219\uFF1A");
|
|
5684
|
+
for (const [pattern, rule] of Object.entries(config.directoryRules)) {
|
|
5685
|
+
lines.push(` ${pattern} \u2192 ${rule.defaultEncoding || "\u7EE7\u627F\u9ED8\u8BA4"}`);
|
|
5686
|
+
}
|
|
5687
|
+
}
|
|
5688
|
+
p.log.info(lines.join("\n"));
|
|
5689
|
+
}
|
|
5690
|
+
async function selectEncodingWithCustom(message, defaultValue) {
|
|
5691
|
+
if (!process.stdin.isTTY) {
|
|
5692
|
+
const options = ENCODING_PRESETS.map((opt) => ({
|
|
5693
|
+
...opt,
|
|
5694
|
+
label: opt.value === defaultValue ? `${opt.label} (\u5F53\u524D)` : opt.label
|
|
5695
|
+
}));
|
|
5696
|
+
options.push({ label: "\u5176\u4ED6\uFF08\u624B\u52A8\u8F93\u5165\uFF09", value: "__custom__" });
|
|
5697
|
+
const choice = await p.select({ message, options });
|
|
5698
|
+
if (p.isCancel(choice))
|
|
5699
|
+
return CANCEL_SYMBOL;
|
|
5700
|
+
if (choice === "__custom__") {
|
|
5701
|
+
const custom = await p.text({
|
|
5702
|
+
message: "\u8F93\u5165\u7F16\u7801\u540D\u79F0",
|
|
5703
|
+
validate: (v) => v.trim().length > 0 ? void 0 : "\u8BF7\u8F93\u5165\u6709\u6548\u7F16\u7801"
|
|
5704
|
+
});
|
|
5705
|
+
if (p.isCancel(custom))
|
|
5706
|
+
return CANCEL_SYMBOL;
|
|
5707
|
+
return custom;
|
|
5708
|
+
}
|
|
5709
|
+
return choice;
|
|
5710
|
+
}
|
|
5711
|
+
return await new Promise((resolve) => {
|
|
5712
|
+
const stdin = process.stdin;
|
|
5713
|
+
const stdout = process.stdout;
|
|
5714
|
+
const presets = ENCODING_PRESETS.map((opt) => ({
|
|
5715
|
+
label: opt.value === defaultValue ? `${opt.label} (\u5F53\u524D)` : opt.label,
|
|
5716
|
+
value: opt.value
|
|
5717
|
+
}));
|
|
5718
|
+
const customIndex = presets.length;
|
|
5719
|
+
let cursor = defaultValue ? Math.max(0, presets.findIndex((pp) => pp.value === defaultValue)) : 0;
|
|
5720
|
+
let customBuffer = "";
|
|
5721
|
+
let showError = false;
|
|
5722
|
+
stdin.setRawMode(true);
|
|
5723
|
+
stdin.resume();
|
|
5724
|
+
stdin.setEncoding("utf-8");
|
|
5725
|
+
const cleanup = () => {
|
|
5726
|
+
stdin.setRawMode(false);
|
|
5727
|
+
stdin.removeListener("data", onData);
|
|
5728
|
+
stdin.pause();
|
|
5729
|
+
};
|
|
5730
|
+
function render() {
|
|
5731
|
+
const totalLines = presets.length + 2 + (showError ? 1 : 0);
|
|
5732
|
+
stdout.write(`\x1B[${totalLines}A`);
|
|
5733
|
+
for (let i = 0; i < totalLines; i++) {
|
|
5734
|
+
stdout.write("\x1B[2K\r");
|
|
5735
|
+
}
|
|
5736
|
+
stdout.write(`\x1B[1m${message}\x1B[22m
|
|
5737
|
+
`);
|
|
5738
|
+
for (let i = 0; i < presets.length; i++) {
|
|
5739
|
+
const isActive = cursor === i;
|
|
5740
|
+
const bullet = isActive ? "\u25CF" : "\u25CB";
|
|
5741
|
+
stdout.write(` ${bullet} ${presets[i].label}
|
|
5742
|
+
`);
|
|
5743
|
+
}
|
|
5744
|
+
const isCustomActive = cursor === customIndex;
|
|
5745
|
+
const customBullet = isCustomActive ? "\u25CF" : "\u25CB";
|
|
5746
|
+
if (isCustomActive && customBuffer.length > 0) {
|
|
5747
|
+
stdout.write(` ${customBullet} ${customBuffer}
|
|
5748
|
+
`);
|
|
5749
|
+
} else if (isCustomActive) {
|
|
5750
|
+
stdout.write(` ${customBullet} \u2502
|
|
5751
|
+
`);
|
|
5752
|
+
} else {
|
|
5753
|
+
stdout.write(` ${customBullet} \u5176\u4ED6\uFF08\u624B\u52A8\u8F93\u5165\uFF09
|
|
5754
|
+
`);
|
|
5755
|
+
}
|
|
5756
|
+
if (showError) {
|
|
5757
|
+
stdout.write(` \x1B[31m\u8BF7\u8F93\u5165\u6709\u6548\u7F16\u7801\x1B[0m
|
|
5758
|
+
`);
|
|
5759
|
+
}
|
|
5760
|
+
}
|
|
5761
|
+
function clearWidget() {
|
|
5762
|
+
const totalLines = presets.length + 2 + (showError ? 1 : 0);
|
|
5763
|
+
stdout.write(`\x1B[${totalLines}A`);
|
|
5764
|
+
for (let i = 0; i < totalLines; i++) {
|
|
5765
|
+
stdout.write("\x1B[2K\r");
|
|
5766
|
+
}
|
|
5767
|
+
}
|
|
5768
|
+
function onData(data) {
|
|
5769
|
+
const key = data;
|
|
5770
|
+
if (key === "") {
|
|
5771
|
+
cleanup();
|
|
5772
|
+
clearWidget();
|
|
5773
|
+
resolve(CANCEL_SYMBOL);
|
|
5774
|
+
return;
|
|
5775
|
+
}
|
|
5776
|
+
if (key === "\x1B" && data.length === 1) {
|
|
5777
|
+
cleanup();
|
|
5778
|
+
clearWidget();
|
|
5779
|
+
resolve(CANCEL_SYMBOL);
|
|
5780
|
+
return;
|
|
5781
|
+
}
|
|
5782
|
+
if (key === "\x1B[A") {
|
|
5783
|
+
showError = false;
|
|
5784
|
+
cursor = cursor > 0 ? cursor - 1 : customIndex;
|
|
5785
|
+
render();
|
|
5786
|
+
return;
|
|
5787
|
+
}
|
|
5788
|
+
if (key === "\x1B[B") {
|
|
5789
|
+
showError = false;
|
|
5790
|
+
cursor = cursor < customIndex ? cursor + 1 : 0;
|
|
5791
|
+
render();
|
|
5792
|
+
return;
|
|
5793
|
+
}
|
|
5794
|
+
if (key === "\r" || key === "\n") {
|
|
5795
|
+
if (cursor === customIndex) {
|
|
5796
|
+
if (customBuffer.trim().length === 0) {
|
|
5797
|
+
showError = true;
|
|
5798
|
+
render();
|
|
5799
|
+
return;
|
|
5800
|
+
}
|
|
5801
|
+
cleanup();
|
|
5802
|
+
clearWidget();
|
|
5803
|
+
resolve(customBuffer.trim());
|
|
5804
|
+
return;
|
|
5805
|
+
}
|
|
5806
|
+
cleanup();
|
|
5807
|
+
clearWidget();
|
|
5808
|
+
resolve(presets[cursor].value);
|
|
5809
|
+
return;
|
|
5810
|
+
}
|
|
5811
|
+
if (key === "\x7F" || key === "\b") {
|
|
5812
|
+
if (cursor === customIndex && customBuffer.length > 0) {
|
|
5813
|
+
customBuffer = customBuffer.slice(0, -1);
|
|
5814
|
+
showError = false;
|
|
5815
|
+
render();
|
|
5816
|
+
}
|
|
5817
|
+
return;
|
|
5818
|
+
}
|
|
5819
|
+
if (cursor === customIndex && key.length >= 1 && key.charCodeAt(0) >= 32) {
|
|
5820
|
+
customBuffer += key;
|
|
5821
|
+
showError = false;
|
|
5822
|
+
render();
|
|
5823
|
+
return;
|
|
5824
|
+
}
|
|
5825
|
+
}
|
|
5826
|
+
stdin.on("data", onData);
|
|
5827
|
+
const totalInitialLines = presets.length + 2;
|
|
5828
|
+
for (let i = 0; i < totalInitialLines; i++) {
|
|
5829
|
+
stdout.write("\n");
|
|
5830
|
+
}
|
|
5831
|
+
stdout.write(`\x1B[${totalInitialLines}A`);
|
|
5832
|
+
render();
|
|
5833
|
+
});
|
|
5834
|
+
}
|
|
5835
|
+
async function addDirectoryRule(state) {
|
|
5836
|
+
const pattern = await cancelable(p.text({
|
|
5837
|
+
message: "\u8F93\u5165\u76EE\u5F55\u8DEF\u5F84\uFF08\u652F\u6301 glob \u6A21\u5F0F\uFF09",
|
|
5838
|
+
validate: (value) => {
|
|
5839
|
+
const trimmed = value.trim();
|
|
5840
|
+
if (trimmed.length === 0)
|
|
5841
|
+
return "\u8BF7\u8F93\u5165\u6709\u6548\u8DEF\u5F84";
|
|
5842
|
+
if (trimmed.startsWith("/") || /^[A-Za-z]:/.test(trimmed))
|
|
5843
|
+
return "\u8BF7\u4F7F\u7528\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u5982 openspec/**";
|
|
5844
|
+
if (state.directoryRules.some((r) => r.pattern === trimmed))
|
|
5845
|
+
return "\u8BE5\u6A21\u5F0F\u5DF2\u5B58\u5728";
|
|
5846
|
+
try {
|
|
5847
|
+
(0, import_picomatch.default)(trimmed);
|
|
5848
|
+
return void 0;
|
|
5849
|
+
} catch {
|
|
5850
|
+
return "\u65E0\u6548\u7684 glob \u6A21\u5F0F";
|
|
5851
|
+
}
|
|
5852
|
+
}
|
|
5853
|
+
}));
|
|
5854
|
+
const encoding = await selectEncodingWithCustom("\u9009\u62E9\u8BE5\u76EE\u5F55\u7684\u9ED8\u8BA4\u7F16\u7801");
|
|
5855
|
+
if (p.isCancel(encoding)) {
|
|
5856
|
+
p.cancel("\u64CD\u4F5C\u5DF2\u53D6\u6D88");
|
|
5857
|
+
process.exit(0);
|
|
5858
|
+
}
|
|
5859
|
+
state.directoryRules.push({
|
|
5860
|
+
pattern: pattern.trim(),
|
|
5861
|
+
rule: { defaultEncoding: encoding }
|
|
5862
|
+
});
|
|
5863
|
+
}
|
|
5864
|
+
async function deleteDirectoryRule(state) {
|
|
5865
|
+
const options = state.directoryRules.map(({ pattern, rule }) => ({
|
|
5866
|
+
label: `${pattern} \u2192 ${rule.defaultEncoding || "\u7EE7\u627F\u9ED8\u8BA4"}`,
|
|
5867
|
+
value: pattern
|
|
5868
|
+
}));
|
|
5869
|
+
const toDelete = await cancelable(p.select({
|
|
5870
|
+
message: "\u9009\u62E9\u8981\u5220\u9664\u7684\u89C4\u5219",
|
|
5871
|
+
options
|
|
5872
|
+
}));
|
|
5873
|
+
state.directoryRules = state.directoryRules.filter((r) => r.pattern !== toDelete);
|
|
5874
|
+
}
|
|
5875
|
+
async function executeInstall(state, isUpdate) {
|
|
5876
|
+
const spinner2 = p.spinner();
|
|
5877
|
+
spinner2.start(isUpdate ? "\u66F4\u65B0\u914D\u7F6E..." : "\u5B89\u88C5\u4E2D...");
|
|
5878
|
+
spinner2.message("\u751F\u6210 .encoding-converter.json");
|
|
5879
|
+
await generateConfigFile(state, process.cwd());
|
|
5880
|
+
if (state.platforms.includes("claude-code")) {
|
|
5881
|
+
spinner2.message("\u914D\u7F6E Claude Code hooks");
|
|
5882
|
+
await installClaudeCode();
|
|
5883
|
+
}
|
|
5884
|
+
if (state.platforms.includes("opencode")) {
|
|
5885
|
+
spinner2.message("\u5B89\u88C5 OpenCode \u63D2\u4EF6");
|
|
5886
|
+
await installOpenCode();
|
|
5887
|
+
}
|
|
5888
|
+
spinner2.stop(isUpdate ? "\u914D\u7F6E\u66F4\u65B0\u5B8C\u6210\uFF01" : "\u5B89\u88C5\u5B8C\u6210\uFF01");
|
|
5889
|
+
p.log.info("\u8BF7\u91CD\u542F AI \u5DE5\u5177\u4EE5\u751F\u6548\u3002");
|
|
5890
|
+
}
|
|
5891
|
+
async function runInstaller() {
|
|
5892
|
+
const existingConfig = await loadProjectConfig(process.cwd());
|
|
5893
|
+
const hasExistingConfig = !!(existingConfig.confidenceThreshold !== 0.8 || existingConfig.defaultEncoding || existingConfig.directoryRules);
|
|
5894
|
+
const state = {
|
|
5895
|
+
platforms: [],
|
|
5896
|
+
confidenceThreshold: existingConfig.confidenceThreshold,
|
|
5897
|
+
defaultEncoding: existingConfig.defaultEncoding,
|
|
5898
|
+
directoryRules: existingConfig.directoryRules ? Object.entries(existingConfig.directoryRules).map(([pattern, rule]) => ({ pattern, rule })) : []
|
|
5899
|
+
};
|
|
5900
|
+
console.clear();
|
|
5901
|
+
p.intro("encoding-converter-ai \xB7 cli ai\u5DE5\u5177\u81EA\u52A8\u611F\u77E5\u7F16\u7801");
|
|
5902
|
+
const deps = await checkDependencies();
|
|
5903
|
+
if (!deps.python) {
|
|
5904
|
+
p.log.error("Python 3.x \u672A\u5B89\u88C5");
|
|
5905
|
+
process.exit(1);
|
|
5906
|
+
}
|
|
5907
|
+
if (!deps.chardet) {
|
|
5908
|
+
p.log.error("chardet \u5E93\u672A\u5B89\u88C5\uFF0C\u8BF7\u8FD0\u884C: pip install chardet");
|
|
5909
|
+
process.exit(1);
|
|
5910
|
+
}
|
|
5911
|
+
state.platforms = await cancelable(p.multiselect({
|
|
5912
|
+
message: "\u9009\u62E9\u8981\u5B89\u88C5\u7684\u5E73\u53F0",
|
|
5913
|
+
options: [
|
|
5914
|
+
{ label: "Claude Code", value: "claude-code" },
|
|
5915
|
+
{ label: "OpenCode", value: "opencode" }
|
|
5916
|
+
],
|
|
5917
|
+
initialValues: ["claude-code", "opencode"],
|
|
5918
|
+
required: true
|
|
5919
|
+
}));
|
|
5920
|
+
if (hasExistingConfig) {
|
|
5921
|
+
p.log.info("\u68C0\u6D4B\u5230\u73B0\u6709\u914D\u7F6E\u6587\u4EF6\uFF0C\u5C06\u52A0\u8F7D\u4E3A\u9ED8\u8BA4\u503C");
|
|
5922
|
+
renderConfigInfo(existingConfig);
|
|
5923
|
+
}
|
|
5924
|
+
const thresholdInput = await cancelable(p.text({
|
|
5925
|
+
message: "\u8BBE\u7F6E\u7F16\u7801\u68C0\u6D4B\u7F6E\u4FE1\u5EA6\u9608\u503C (0-1)",
|
|
5926
|
+
placeholder: String(state.confidenceThreshold),
|
|
5927
|
+
validate: (value) => {
|
|
5928
|
+
const num = parseFloat(value);
|
|
5929
|
+
if (isNaN(num) || num < 0 || num > 1)
|
|
5930
|
+
return "\u8BF7\u8F93\u5165 0 \u5230 1 \u4E4B\u95F4\u7684\u6570\u503C";
|
|
5931
|
+
return void 0;
|
|
5932
|
+
}
|
|
5933
|
+
}));
|
|
5934
|
+
state.confidenceThreshold = parseFloat(thresholdInput);
|
|
5935
|
+
const encoding = await selectEncodingWithCustom(
|
|
5936
|
+
"\u9009\u62E9\u9ED8\u8BA4\u7F16\u7801\uFF08\u7528\u4E8E\u68C0\u6D4B\u56DE\u843D\u548C\u65B0\u6587\u4EF6\uFF09",
|
|
5937
|
+
state.defaultEncoding
|
|
5938
|
+
);
|
|
5939
|
+
if (p.isCancel(encoding)) {
|
|
5940
|
+
p.cancel("\u64CD\u4F5C\u5DF2\u53D6\u6D88");
|
|
5941
|
+
process.exit(0);
|
|
5942
|
+
}
|
|
5943
|
+
state.defaultEncoding = encoding;
|
|
5944
|
+
while (true) {
|
|
5945
|
+
const options = [{ label: "\u6DFB\u52A0\u76EE\u5F55\u7EA7\u7F16\u7801\u89C4\u5219", value: "add" }];
|
|
5946
|
+
if (state.directoryRules.length > 0) {
|
|
5947
|
+
options.push({ label: "\u5220\u9664\u76EE\u5F55\u89C4\u5219", value: "delete" });
|
|
5948
|
+
}
|
|
5949
|
+
options.push({ label: "\u5B89\u88C5\u5B8C\u6210", value: "done" });
|
|
5950
|
+
const action = await cancelable(p.select({
|
|
5951
|
+
message: "\u4E0B\u4E00\u6B65\u64CD\u4F5C",
|
|
5952
|
+
options
|
|
5953
|
+
}));
|
|
5954
|
+
if (action === "done")
|
|
5955
|
+
break;
|
|
5956
|
+
if (action === "delete") {
|
|
5957
|
+
await deleteDirectoryRule(state);
|
|
5958
|
+
} else {
|
|
5959
|
+
await addDirectoryRule(state);
|
|
5960
|
+
}
|
|
5961
|
+
}
|
|
5962
|
+
await executeInstall(state, hasExistingConfig);
|
|
5963
|
+
p.outro("\u5B89\u88C5\u5B8C\u6210\uFF01");
|
|
5964
|
+
}
|
|
5965
|
+
async function generateConfigFile(state, projectRoot) {
|
|
5966
|
+
const configPath = path4.join(projectRoot, ".encoding-converter.json");
|
|
5967
|
+
const config = {
|
|
5968
|
+
targetEncoding: "UTF-8",
|
|
5969
|
+
confidenceThreshold: state.confidenceThreshold
|
|
5970
|
+
};
|
|
5971
|
+
if (state.defaultEncoding) {
|
|
5972
|
+
config.defaultEncoding = state.defaultEncoding;
|
|
5973
|
+
}
|
|
5974
|
+
if (state.directoryRules.length > 0) {
|
|
5975
|
+
config.directoryRules = {};
|
|
5976
|
+
for (const { pattern, rule } of state.directoryRules) {
|
|
5977
|
+
config.directoryRules[pattern] = rule;
|
|
5978
|
+
}
|
|
5979
|
+
}
|
|
5980
|
+
await fs5.writeFile(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
5981
|
+
}
|
|
3864
5982
|
async function checkDependencies() {
|
|
3865
5983
|
const status = { python: false, chardet: false };
|
|
3866
5984
|
try {
|
|
@@ -3878,20 +5996,30 @@ async function checkDependencies() {
|
|
|
3878
5996
|
return status;
|
|
3879
5997
|
}
|
|
3880
5998
|
async function installClaudeCode() {
|
|
3881
|
-
const hookDir =
|
|
3882
|
-
await
|
|
3883
|
-
const srcPath =
|
|
3884
|
-
const destPath =
|
|
5999
|
+
const hookDir = path4.join(os3.homedir(), ".claude", "hooks", "encoding_converter");
|
|
6000
|
+
await fs5.mkdir(hookDir, { recursive: true });
|
|
6001
|
+
const srcPath = path4.join(__dirname, "converter.js");
|
|
6002
|
+
const destPath = path4.join(hookDir, "converter.js");
|
|
3885
6003
|
try {
|
|
3886
|
-
|
|
6004
|
+
try {
|
|
6005
|
+
await fs5.access(srcPath);
|
|
6006
|
+
} catch {
|
|
6007
|
+
throw new Error(`Source file not found: ${srcPath}`);
|
|
6008
|
+
}
|
|
6009
|
+
await fs5.copyFile(srcPath, destPath);
|
|
6010
|
+
try {
|
|
6011
|
+
await fs5.access(destPath);
|
|
6012
|
+
} catch {
|
|
6013
|
+
throw new Error(`Copy appeared to succeed but destination not found: ${destPath}`);
|
|
6014
|
+
}
|
|
3887
6015
|
} catch (err) {
|
|
3888
6016
|
log("error", "Failed to copy converter.js", { error: err.message });
|
|
3889
|
-
throw new Error(`Could not
|
|
6017
|
+
throw new Error(`Could not install converter.js: ${err.message}`);
|
|
3890
6018
|
}
|
|
3891
|
-
const settingsPath =
|
|
6019
|
+
const settingsPath = path4.join(os3.homedir(), ".claude", "settings.json");
|
|
3892
6020
|
let settings = {};
|
|
3893
6021
|
try {
|
|
3894
|
-
const content = await
|
|
6022
|
+
const content = await fs5.readFile(settingsPath, "utf-8");
|
|
3895
6023
|
settings = JSON.parse(content);
|
|
3896
6024
|
} catch {
|
|
3897
6025
|
}
|
|
@@ -3917,13 +6045,13 @@ async function installClaudeCode() {
|
|
|
3917
6045
|
settings.hooks[event].push(hookConfig(phase));
|
|
3918
6046
|
}
|
|
3919
6047
|
}
|
|
3920
|
-
await
|
|
6048
|
+
await fs5.writeFile(settingsPath, JSON.stringify(settings, null, 2), "utf-8");
|
|
3921
6049
|
log("info", "Claude Code hooks configured", { settingsPath });
|
|
3922
6050
|
}
|
|
3923
6051
|
async function uninstallClaudeCode() {
|
|
3924
|
-
const settingsPath =
|
|
6052
|
+
const settingsPath = path4.join(os3.homedir(), ".claude", "settings.json");
|
|
3925
6053
|
try {
|
|
3926
|
-
const content = await
|
|
6054
|
+
const content = await fs5.readFile(settingsPath, "utf-8");
|
|
3927
6055
|
const settings = JSON.parse(content);
|
|
3928
6056
|
if (settings.hooks) {
|
|
3929
6057
|
for (const event of ["PreToolUse", "PostToolUse", "PostToolUseFailure"]) {
|
|
@@ -3940,23 +6068,23 @@ async function uninstallClaudeCode() {
|
|
|
3940
6068
|
delete settings.hooks;
|
|
3941
6069
|
}
|
|
3942
6070
|
}
|
|
3943
|
-
await
|
|
6071
|
+
await fs5.writeFile(settingsPath, JSON.stringify(settings, null, 2), "utf-8");
|
|
3944
6072
|
} catch (err) {
|
|
3945
6073
|
if (err.code !== "ENOENT") {
|
|
3946
6074
|
throw err;
|
|
3947
6075
|
}
|
|
3948
6076
|
}
|
|
3949
|
-
const hookDir =
|
|
6077
|
+
const hookDir = path4.join(os3.homedir(), ".claude", "hooks", "encoding_converter");
|
|
3950
6078
|
try {
|
|
3951
|
-
await
|
|
6079
|
+
await fs5.rm(hookDir, { recursive: true, force: true });
|
|
3952
6080
|
} catch {
|
|
3953
6081
|
}
|
|
3954
6082
|
log("info", "Claude Code hooks uninstalled");
|
|
3955
6083
|
}
|
|
3956
6084
|
async function uninstallOpenCode() {
|
|
3957
|
-
const pluginPath =
|
|
6085
|
+
const pluginPath = path4.join(os3.homedir(), ".config", "opencode", "plugins", "encoding-converter.js");
|
|
3958
6086
|
try {
|
|
3959
|
-
await
|
|
6087
|
+
await fs5.unlink(pluginPath);
|
|
3960
6088
|
} catch (err) {
|
|
3961
6089
|
if (err.code !== "ENOENT") {
|
|
3962
6090
|
throw err;
|
|
@@ -3965,24 +6093,29 @@ async function uninstallOpenCode() {
|
|
|
3965
6093
|
log("info", "OpenCode plugin uninstalled");
|
|
3966
6094
|
}
|
|
3967
6095
|
async function cleanupDataDir() {
|
|
3968
|
-
const dataDir =
|
|
6096
|
+
const dataDir = path4.join(os3.homedir(), ".encoding-converter");
|
|
3969
6097
|
try {
|
|
3970
|
-
await
|
|
6098
|
+
await fs5.rm(dataDir, { recursive: true, force: true });
|
|
3971
6099
|
} catch {
|
|
3972
6100
|
}
|
|
3973
6101
|
log("info", "Data directory cleaned up");
|
|
3974
6102
|
}
|
|
3975
6103
|
async function installOpenCode() {
|
|
3976
|
-
const pluginDir =
|
|
3977
|
-
await
|
|
3978
|
-
const srcPath =
|
|
3979
|
-
const destPath =
|
|
6104
|
+
const pluginDir = path4.join(os3.homedir(), ".config", "opencode", "plugins");
|
|
6105
|
+
await fs5.mkdir(pluginDir, { recursive: true });
|
|
6106
|
+
const srcPath = path4.join(__dirname, "plugin.js");
|
|
6107
|
+
const destPath = path4.join(pluginDir, "encoding-converter.js");
|
|
3980
6108
|
try {
|
|
3981
|
-
|
|
6109
|
+
try {
|
|
6110
|
+
await fs5.access(srcPath);
|
|
6111
|
+
} catch {
|
|
6112
|
+
throw new Error(`Source file not found: ${srcPath}`);
|
|
6113
|
+
}
|
|
6114
|
+
await fs5.copyFile(srcPath, destPath);
|
|
3982
6115
|
log("info", "OpenCode plugin installed", { destPath });
|
|
3983
6116
|
} catch (err) {
|
|
3984
6117
|
log("error", "Failed to copy plugin.js", { error: err.message });
|
|
3985
|
-
throw new Error(`Could not
|
|
6118
|
+
throw new Error(`Could not install plugin.js: ${err.message}`);
|
|
3986
6119
|
}
|
|
3987
6120
|
}
|
|
3988
6121
|
|
|
@@ -3999,106 +6132,52 @@ async function runCleanup(all) {
|
|
|
3999
6132
|
console.log("\n No residual states found. All clean!");
|
|
4000
6133
|
}
|
|
4001
6134
|
}
|
|
4002
|
-
async function
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
if (deps.python) {
|
|
4013
|
-
console.log(" \u2713 Python 3.x installed");
|
|
4014
|
-
} else {
|
|
4015
|
-
console.log(" \u2717 Python 3.x NOT found. Please install Python 3.x and add to PATH.");
|
|
4016
|
-
process.exit(1);
|
|
6135
|
+
async function runUninstaller() {
|
|
6136
|
+
const p2 = await import("@clack/prompts");
|
|
6137
|
+
function cancelable2(promise) {
|
|
6138
|
+
return promise.then((result) => {
|
|
6139
|
+
if (p2.isCancel(result)) {
|
|
6140
|
+
p2.cancel("\u64CD\u4F5C\u5DF2\u53D6\u6D88");
|
|
6141
|
+
process.exit(0);
|
|
6142
|
+
}
|
|
6143
|
+
return result;
|
|
6144
|
+
});
|
|
4017
6145
|
}
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
6146
|
+
console.clear();
|
|
6147
|
+
p2.intro("encoding-converter-ai \xB7 \u5378\u8F7D");
|
|
6148
|
+
const targets = await cancelable2(p2.multiselect({
|
|
6149
|
+
message: "\u9009\u62E9\u8981\u5378\u8F7D\u7684\u7EC4\u4EF6",
|
|
6150
|
+
options: [
|
|
6151
|
+
{ label: "Claude Code hooks", value: "claude-code" },
|
|
6152
|
+
{ label: "OpenCode plugin", value: "opencode" },
|
|
6153
|
+
{ label: "Data directory (~/.encoding-converter)", value: "data" }
|
|
6154
|
+
],
|
|
6155
|
+
initialValues: ["claude-code", "opencode"],
|
|
6156
|
+
required: true
|
|
6157
|
+
}));
|
|
6158
|
+
const confirmed = await cancelable2(p2.confirm({
|
|
6159
|
+
message: "\u786E\u8BA4\u5378\u8F7D\uFF1F"
|
|
6160
|
+
}));
|
|
6161
|
+
if (!confirmed) {
|
|
6162
|
+
p2.cancel("\u5DF2\u53D6\u6D88");
|
|
6163
|
+
process.exit(0);
|
|
4023
6164
|
}
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
choices: [
|
|
4030
|
-
{ name: "Claude Code", value: "claude-code", checked: true },
|
|
4031
|
-
{ name: "OpenCode", value: "opencode", checked: true }
|
|
4032
|
-
]
|
|
4033
|
-
});
|
|
4034
|
-
if (platforms.length === 0) {
|
|
4035
|
-
console.log("No platforms selected. Exiting.");
|
|
4036
|
-
return;
|
|
4037
|
-
}
|
|
4038
|
-
const confirmed = await confirm({ message: "Confirm installation?" });
|
|
4039
|
-
if (!confirmed) {
|
|
4040
|
-
console.log("Installation cancelled.");
|
|
4041
|
-
return;
|
|
4042
|
-
}
|
|
4043
|
-
console.log("\nInstalling...");
|
|
4044
|
-
if (platforms.includes("claude-code")) {
|
|
4045
|
-
await installClaudeCode();
|
|
4046
|
-
console.log(" \u2713 Claude Code: hooks configured");
|
|
4047
|
-
}
|
|
4048
|
-
if (platforms.includes("opencode")) {
|
|
4049
|
-
await installOpenCode();
|
|
4050
|
-
console.log(" \u2713 OpenCode: plugin installed");
|
|
4051
|
-
}
|
|
4052
|
-
console.log("\n\u2713 Installation complete! Please restart your AI tool for changes to take effect.");
|
|
4053
|
-
} catch (err) {
|
|
4054
|
-
log("error", "Installer failed", { error: err.message });
|
|
4055
|
-
console.error("Installation failed:", err.message);
|
|
4056
|
-
process.exit(1);
|
|
6165
|
+
const spinner2 = p2.spinner();
|
|
6166
|
+
spinner2.start("\u5378\u8F7D\u4E2D...");
|
|
6167
|
+
if (targets.includes("claude-code")) {
|
|
6168
|
+
await uninstallClaudeCode();
|
|
6169
|
+
spinner2.message("\u79FB\u9664 Claude Code hooks");
|
|
4057
6170
|
}
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
const { checkbox, confirm } = await import("@inquirer/prompts");
|
|
4066
|
-
const targets = await checkbox({
|
|
4067
|
-
message: "Select what to uninstall:",
|
|
4068
|
-
choices: [
|
|
4069
|
-
{ name: "Claude Code hooks", value: "claude-code", checked: true },
|
|
4070
|
-
{ name: "OpenCode plugin", value: "opencode", checked: true },
|
|
4071
|
-
{ name: "Data directory (~/.encoding-converter)", value: "data", checked: false }
|
|
4072
|
-
]
|
|
4073
|
-
});
|
|
4074
|
-
if (targets.length === 0) {
|
|
4075
|
-
console.log("Nothing selected. Exiting.");
|
|
4076
|
-
return;
|
|
4077
|
-
}
|
|
4078
|
-
const confirmed = await confirm({ message: "Confirm uninstallation?" });
|
|
4079
|
-
if (!confirmed) {
|
|
4080
|
-
console.log("Uninstallation cancelled.");
|
|
4081
|
-
return;
|
|
4082
|
-
}
|
|
4083
|
-
console.log("\nUninstalling...");
|
|
4084
|
-
if (targets.includes("claude-code")) {
|
|
4085
|
-
await uninstallClaudeCode();
|
|
4086
|
-
console.log(" \u2713 Claude Code: hooks removed");
|
|
4087
|
-
}
|
|
4088
|
-
if (targets.includes("opencode")) {
|
|
4089
|
-
await uninstallOpenCode();
|
|
4090
|
-
console.log(" \u2713 OpenCode: plugin removed");
|
|
4091
|
-
}
|
|
4092
|
-
if (targets.includes("data")) {
|
|
4093
|
-
await cleanupDataDir();
|
|
4094
|
-
console.log(" \u2713 Data directory: removed");
|
|
4095
|
-
}
|
|
4096
|
-
console.log("\n\u2713 Uninstallation complete! Please restart your AI tool for changes to take effect.");
|
|
4097
|
-
} catch (err) {
|
|
4098
|
-
log("error", "Uninstaller failed", { error: err.message });
|
|
4099
|
-
console.error("Uninstallation failed:", err.message);
|
|
4100
|
-
process.exit(1);
|
|
6171
|
+
if (targets.includes("opencode")) {
|
|
6172
|
+
await uninstallOpenCode();
|
|
6173
|
+
spinner2.message("\u79FB\u9664 OpenCode \u63D2\u4EF6");
|
|
6174
|
+
}
|
|
6175
|
+
if (targets.includes("data")) {
|
|
6176
|
+
await cleanupDataDir();
|
|
6177
|
+
spinner2.message("\u6E05\u7406\u6570\u636E\u76EE\u5F55");
|
|
4101
6178
|
}
|
|
6179
|
+
spinner2.stop("\u5378\u8F7D\u5B8C\u6210\uFF01");
|
|
6180
|
+
p2.outro("\u8BF7\u91CD\u542F AI \u5DE5\u5177\u4EE5\u751F\u6548\u3002");
|
|
4102
6181
|
}
|
|
4103
6182
|
async function main() {
|
|
4104
6183
|
const args = process.argv.slice(2);
|