spur-board 0.163.0 → 0.164.0
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/dist/daemon.mjs +3782 -404
- package/package.json +1 -1
package/dist/daemon.mjs
CHANGED
|
@@ -603,6 +603,218 @@ function authorize(grants, actor, state) {
|
|
|
603
603
|
hint
|
|
604
604
|
};
|
|
605
605
|
}
|
|
606
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/helper/keyword-guard.js
|
|
607
|
+
/**
|
|
608
|
+
* The guard of a keyword: a condition on the characters that follow the keyword.
|
|
609
|
+
*
|
|
610
|
+
* A pattern declares a guarded keyword as `{ keyword: "00", after: "[A-Za-z0-9_-]{40,}" }`.
|
|
611
|
+
* `after` is one set of ASCII characters and one least count, in a small subset of the syntax of regular expressions:
|
|
612
|
+
*
|
|
613
|
+
* - The set is `[` and `]` around characters and ranges such as `a-z`.
|
|
614
|
+
* `\` is written only before `\` and `]`. A `-` as a character is the last item.
|
|
615
|
+
* - The count is `{n,}`, and `n` is from 1 to 255.
|
|
616
|
+
*
|
|
617
|
+
* The syntax is strict: a guard has one way to write it, apart from the order of the items of the set.
|
|
618
|
+
* Anything else is an error, so that a form of a newer secretlint is never read in another way.
|
|
619
|
+
* The set is compared with the content as it is written: `[a-f]` does not have `A`.
|
|
620
|
+
*
|
|
621
|
+
* This module has no dependency, because the core also runs in browsers.
|
|
622
|
+
*/
|
|
623
|
+
const ASCII_SIZE$1 = 128;
|
|
624
|
+
const isAscii = (text) => {
|
|
625
|
+
for (let i = 0; i < text.length; i++) if (text.charCodeAt(i) >= ASCII_SIZE$1) return false;
|
|
626
|
+
return true;
|
|
627
|
+
};
|
|
628
|
+
const SHORT_CLASSES = {
|
|
629
|
+
d: "0-9",
|
|
630
|
+
w: "A-Za-z0-9_"
|
|
631
|
+
};
|
|
632
|
+
/**
|
|
633
|
+
* Parse the set at the start of `after`.
|
|
634
|
+
* Return the characters of the set and the index after `]`.
|
|
635
|
+
*/
|
|
636
|
+
const parseSet = (after) => {
|
|
637
|
+
if (after[0] !== "[") throw new Error("It should start with a set of characters, such as `[A-Za-z0-9]`.");
|
|
638
|
+
if (after[1] === "^") throw new Error("A set with `^` is not supported. Write the characters that follow the keyword.");
|
|
639
|
+
const items = [];
|
|
640
|
+
let index = 1;
|
|
641
|
+
for (;; index++) {
|
|
642
|
+
const char = after[index];
|
|
643
|
+
if (char === void 0) throw new Error("The set has no `]`.");
|
|
644
|
+
if (char === "]") break;
|
|
645
|
+
if (char === "\\") {
|
|
646
|
+
const escaped = after[index + 1];
|
|
647
|
+
if (escaped === "\\" || escaped === "]") {
|
|
648
|
+
items.push(`\\${escaped}`);
|
|
649
|
+
index++;
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
const shortClass = escaped === void 0 ? void 0 : SHORT_CLASSES[escaped];
|
|
653
|
+
if (shortClass !== void 0) throw new Error(`\`\\${escaped}\` is not supported. Write \`${shortClass}\`.`);
|
|
654
|
+
if (escaped === "-") throw new Error("`\\-` is not supported. Write `-` as the last item of the set.");
|
|
655
|
+
throw new Error(`\`\\${escaped ?? ""}\` is not supported. In a set, \`\\\` is written only before \`\\\` and \`]\`.`);
|
|
656
|
+
}
|
|
657
|
+
items.push(char);
|
|
658
|
+
}
|
|
659
|
+
const end = index + 1;
|
|
660
|
+
const codes = [];
|
|
661
|
+
const add = (code) => {
|
|
662
|
+
if (codes.includes(code)) throw new Error(`The set has ${JSON.stringify(String.fromCharCode(code))} twice.`);
|
|
663
|
+
codes.push(code);
|
|
664
|
+
};
|
|
665
|
+
const codeOf = (item) => item.charCodeAt(item.length - 1);
|
|
666
|
+
for (let i = 0; i < items.length; i++) {
|
|
667
|
+
const item = items[i];
|
|
668
|
+
if (item === "-") {
|
|
669
|
+
if (i !== items.length - 1) throw new Error("A `-` that is a character of the set should be the last item, such as `[A-Za-z0-9_-]`.");
|
|
670
|
+
add(codeOf(item));
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
const next = items[i + 1];
|
|
674
|
+
const last = items[i + 2];
|
|
675
|
+
if (next === "-" && last !== void 0) {
|
|
676
|
+
if (last === "-") throw new Error("A range can not end with `-`.");
|
|
677
|
+
const from = codeOf(item);
|
|
678
|
+
const to = codeOf(last);
|
|
679
|
+
if (from >= to) throw new Error(`The range \`${item}-${last}\` is not in order.`);
|
|
680
|
+
for (let code = from; code <= to; code++) add(code);
|
|
681
|
+
i += 2;
|
|
682
|
+
continue;
|
|
683
|
+
}
|
|
684
|
+
add(codeOf(item));
|
|
685
|
+
}
|
|
686
|
+
if (codes.length === 0) throw new Error("The set is empty.");
|
|
687
|
+
codes.sort((a, b) => a - b);
|
|
688
|
+
return {
|
|
689
|
+
chars: String.fromCharCode(...codes),
|
|
690
|
+
end
|
|
691
|
+
};
|
|
692
|
+
};
|
|
693
|
+
/**
|
|
694
|
+
* Parse the count after the set. It is `{n,}`.
|
|
695
|
+
*/
|
|
696
|
+
const parseCount = (count) => {
|
|
697
|
+
const setExample = "[...]";
|
|
698
|
+
if (count === "+") throw new Error(`\`+\` is not supported. Write \`${setExample}{1,}\`.`);
|
|
699
|
+
const alwaysTrue = () => {
|
|
700
|
+
throw new Error(`\`${count}\` makes the guard always true. The count should be \`{n,}\`, and n is 1 or more.`);
|
|
701
|
+
};
|
|
702
|
+
if (count === "*" || count === "?") return alwaysTrue();
|
|
703
|
+
const matched = /^\{(\d+)(,(\d*))?\}$/.exec(count);
|
|
704
|
+
if (!matched) {
|
|
705
|
+
if (count === "") throw new Error("The set should be followed by a count, such as `{40,}`.");
|
|
706
|
+
throw new Error(`\`${count}\` is not supported. After the set, only a count such as \`{40,}\` is supported.`);
|
|
707
|
+
}
|
|
708
|
+
const least = matched[1];
|
|
709
|
+
if (Number(least) === 0) return alwaysTrue();
|
|
710
|
+
if (matched[2] === void 0) throw new Error(`\`${count}\` is not supported, because the guard does not check where the characters end. Write \`{${least},}\`.`);
|
|
711
|
+
if (matched[3] !== "") throw new Error(`\`${count}\` is not supported, because the guard does not check the most count. Write \`{${least},}\`.`);
|
|
712
|
+
if (least.startsWith("0")) throw new Error(`\`${count}\` is not supported. Write the count without \`0\` at its start.`);
|
|
713
|
+
const min = Number(least);
|
|
714
|
+
if (min > 255) throw new Error(`The count should be 255 or less.`);
|
|
715
|
+
return min;
|
|
716
|
+
};
|
|
717
|
+
/**
|
|
718
|
+
* Parse `after` of a keyword object.
|
|
719
|
+
* It throws an error that tells what is not supported, and the supported form if there is one.
|
|
720
|
+
*/
|
|
721
|
+
const parseKeywordGuard = (after) => {
|
|
722
|
+
if (!isAscii(after)) throw new Error("It should have only ASCII characters.");
|
|
723
|
+
const { chars, end } = parseSet(after);
|
|
724
|
+
return {
|
|
725
|
+
chars,
|
|
726
|
+
min: parseCount(after.slice(end))
|
|
727
|
+
};
|
|
728
|
+
};
|
|
729
|
+
const KEYWORD_OBJECT_PROPERTIES = /* @__PURE__ */ new Set(["keyword", "after"]);
|
|
730
|
+
/**
|
|
731
|
+
* Read a keyword object `{ keyword, after }` of `keywords` of a pattern.
|
|
732
|
+
* It throws if the object is not a guarded keyword that this version of secretlint supports.
|
|
733
|
+
* The message of the error does not have the rule: the caller adds it.
|
|
734
|
+
*/
|
|
735
|
+
const parseKeywordObject = (item) => {
|
|
736
|
+
const describe = () => {
|
|
737
|
+
try {
|
|
738
|
+
return JSON.stringify(item) ?? String(item);
|
|
739
|
+
} catch {
|
|
740
|
+
return String(item);
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
const fail = (reason, cause) => {
|
|
744
|
+
throw new Error(`The keyword ${describe()} is not supported. ${reason}
|
|
745
|
+
A keyword with a guard is written as { keyword: "00", after: "[A-Za-z0-9_-]{40,}" }.`, cause === void 0 ? void 0 : { cause });
|
|
746
|
+
};
|
|
747
|
+
const unknownProperties = Object.keys(item).filter((property) => !KEYWORD_OBJECT_PROPERTIES.has(property));
|
|
748
|
+
if (unknownProperties.length > 0) return fail(`It has unknown properties: ${unknownProperties.join(", ")}. If they are properties of a newer secretlint, please update secretlint.`);
|
|
749
|
+
const { keyword, after } = item;
|
|
750
|
+
if (typeof keyword !== "string" || keyword.length === 0 || !isAscii(keyword)) return fail("`keyword` should be a non-empty ASCII string.");
|
|
751
|
+
if (after === void 0) return fail(`\`after\` is required. A keyword without a guard is written as the string ${JSON.stringify(keyword)}.`);
|
|
752
|
+
if (typeof after !== "string") return fail("`after` should be a string.");
|
|
753
|
+
try {
|
|
754
|
+
return {
|
|
755
|
+
keyword,
|
|
756
|
+
after,
|
|
757
|
+
guard: parseKeywordGuard(after)
|
|
758
|
+
};
|
|
759
|
+
} catch (error) {
|
|
760
|
+
return fail(`\`after\`: ${error instanceof Error ? error.message : String(error)}`, error);
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
/**
|
|
764
|
+
* Create the table of the set: `table[code] === 1` if the character is in the set.
|
|
765
|
+
* It has 256 entries, so a byte that is not ASCII is never in the set.
|
|
766
|
+
*/
|
|
767
|
+
const createGuardTable = (guard) => {
|
|
768
|
+
const table = /* @__PURE__ */ new Uint8Array(256);
|
|
769
|
+
for (let i = 0; i < guard.chars.length; i++) table[guard.chars.charCodeAt(i)] = 1;
|
|
770
|
+
return table;
|
|
771
|
+
};
|
|
772
|
+
/**
|
|
773
|
+
* Return true if the `min` bytes from `start` are all in the set.
|
|
774
|
+
* It reads at most `min` bytes, and it fails at the end of the bytes.
|
|
775
|
+
*/
|
|
776
|
+
const isGuardMetInBytes = (bytes, start, table, min) => {
|
|
777
|
+
const end = start + min;
|
|
778
|
+
if (end > bytes.length) return false;
|
|
779
|
+
for (let i = start; i < end; i++) if (table[bytes[i]] !== 1) return false;
|
|
780
|
+
return true;
|
|
781
|
+
};
|
|
782
|
+
/**
|
|
783
|
+
* Return true if the `min` characters from `start` are all in the set.
|
|
784
|
+
* A character that is not ASCII is never in the set, so the result is the same as for the UTF-8 bytes of the text.
|
|
785
|
+
*/
|
|
786
|
+
const isGuardMetInText = (text, start, table, min) => {
|
|
787
|
+
const end = start + min;
|
|
788
|
+
if (end > text.length) return false;
|
|
789
|
+
for (let i = start; i < end; i++) if (table[text.charCodeAt(i)] !== 1) return false;
|
|
790
|
+
return true;
|
|
791
|
+
};
|
|
792
|
+
/**
|
|
793
|
+
* Write the guard in the syntax of `after`, with the keyword before it: `00 [0-9A-Za-z_-]{40,}`.
|
|
794
|
+
* It is the name of a guarded keyword in the profile.
|
|
795
|
+
*/
|
|
796
|
+
const formatGuardedKeyword = (keyword, guard) => {
|
|
797
|
+
const codes = Array.from(guard.chars, (char) => char.charCodeAt(0)).filter((code) => code !== 45);
|
|
798
|
+
const write = (code) => {
|
|
799
|
+
const char = String.fromCharCode(code);
|
|
800
|
+
return char === "\\" || char === "]" ? `\\${char}` : char;
|
|
801
|
+
};
|
|
802
|
+
let set = "";
|
|
803
|
+
for (let i = 0; i < codes.length;) {
|
|
804
|
+
let end = i;
|
|
805
|
+
while (end + 1 < codes.length && codes[end + 1] === codes[end] + 1) end++;
|
|
806
|
+
if (end - i >= 2) set += `${write(codes[i])}-${write(codes[end])}`;
|
|
807
|
+
else for (let j = i; j <= end; j++) set += write(codes[j]);
|
|
808
|
+
i = end + 1;
|
|
809
|
+
}
|
|
810
|
+
return `${keyword} [${set}${guard.chars.includes("-") ? "-" : ""}]{${guard.min},}`;
|
|
811
|
+
};
|
|
812
|
+
/**
|
|
813
|
+
* The key of a guard: two guards with the same key check the same thing
|
|
814
|
+
*/
|
|
815
|
+
const keywordGuardKey = (guard) => {
|
|
816
|
+
return guard === void 0 ? "" : `${guard.min}:${guard.chars}`;
|
|
817
|
+
};
|
|
606
818
|
// ../../node_modules/.pnpm/boundary@2.0.0/node_modules/boundary/lib/index.js
|
|
607
819
|
var require_lib = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
608
820
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -646,7 +858,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
646
858
|
}
|
|
647
859
|
exports.binarySearch = binarySearch;
|
|
648
860
|
}));
|
|
649
|
-
// ../../node_modules/.pnpm/@secretlint+core@
|
|
861
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/helper/invariant.js
|
|
650
862
|
var import_structured_source = (/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
651
863
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
652
864
|
exports.StructuredSource = void 0;
|
|
@@ -726,27 +938,51 @@ var import_structured_source = (/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
726
938
|
function invariant(condition, message) {
|
|
727
939
|
if (!condition) throw new Error(message);
|
|
728
940
|
}
|
|
729
|
-
// ../../node_modules/.pnpm/@secretlint+core@
|
|
941
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/SecretLintSourceCodeImpl.js
|
|
730
942
|
/**
|
|
731
943
|
* This class represent of source code.
|
|
732
944
|
*/
|
|
733
945
|
var SecretLintSourceCodeImpl = class {
|
|
734
|
-
hasBOM;
|
|
735
|
-
content;
|
|
736
946
|
filePath;
|
|
737
947
|
physicalFilePath;
|
|
738
948
|
contentType;
|
|
739
949
|
ext;
|
|
740
|
-
|
|
741
|
-
|
|
950
|
+
contentBytes;
|
|
951
|
+
_getRawContent;
|
|
952
|
+
_rawContent;
|
|
953
|
+
_content;
|
|
954
|
+
_structuredSource;
|
|
955
|
+
constructor({ content = "", ext, filePath, physicalFilePath, contentType, contentBytes }) {
|
|
742
956
|
invariant(ext || filePath, "should be set either of fileExt or filePath.");
|
|
743
|
-
this.
|
|
744
|
-
this.
|
|
745
|
-
this.structuredSource = new import_structured_source.StructuredSource(this.content);
|
|
957
|
+
if (typeof content === "function") this._getRawContent = content;
|
|
958
|
+
else this._rawContent = content;
|
|
746
959
|
this.filePath = filePath;
|
|
747
960
|
this.physicalFilePath = physicalFilePath;
|
|
748
961
|
this.contentType = contentType;
|
|
749
962
|
this.ext = ext;
|
|
963
|
+
this.contentBytes = contentBytes;
|
|
964
|
+
}
|
|
965
|
+
get rawContent() {
|
|
966
|
+
if (this._rawContent === void 0) {
|
|
967
|
+
this._rawContent = this._getRawContent?.() ?? "";
|
|
968
|
+
this._getRawContent = void 0;
|
|
969
|
+
}
|
|
970
|
+
return this._rawContent;
|
|
971
|
+
}
|
|
972
|
+
get hasBOM() {
|
|
973
|
+
return this.rawContent.charCodeAt(0) === 65279;
|
|
974
|
+
}
|
|
975
|
+
get content() {
|
|
976
|
+
if (this._content === void 0) this._content = this.hasBOM ? this.rawContent.slice(1) : this.rawContent;
|
|
977
|
+
return this._content;
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* StructuredSource builds the line index of the content.
|
|
981
|
+
* It is created lazily because most files do not have any report and do not need location info.
|
|
982
|
+
*/
|
|
983
|
+
get structuredSource() {
|
|
984
|
+
if (this._structuredSource === void 0) this._structuredSource = new import_structured_source.StructuredSource(this.content);
|
|
985
|
+
return this._structuredSource;
|
|
750
986
|
}
|
|
751
987
|
/**
|
|
752
988
|
* get file path
|
|
@@ -813,54 +1049,7 @@ var SecretLintSourceCodeImpl = class {
|
|
|
813
1049
|
};
|
|
814
1050
|
}
|
|
815
1051
|
};
|
|
816
|
-
// ../../node_modules/.pnpm/@secretlint+core@
|
|
817
|
-
var EventEmitter = class {
|
|
818
|
-
#listeners = /* @__PURE__ */ new Map();
|
|
819
|
-
on(type, listener) {
|
|
820
|
-
const listenerSet = this.#listeners.get(type) ?? /* @__PURE__ */ new Set();
|
|
821
|
-
listenerSet?.add(listener);
|
|
822
|
-
this.#listeners.set(type, listenerSet);
|
|
823
|
-
}
|
|
824
|
-
emit(type, ...args) {
|
|
825
|
-
const listenerSet = this.#listeners.get(type);
|
|
826
|
-
if (!listenerSet) return;
|
|
827
|
-
for (const listenerSetElement of listenerSet) listenerSetElement(...args);
|
|
828
|
-
}
|
|
829
|
-
off(type, listener) {
|
|
830
|
-
const listenerSet = this.#listeners.get(type);
|
|
831
|
-
if (!listenerSet) return;
|
|
832
|
-
for (const listenerSetElement of listenerSet) if (listenerSetElement === listener) listenerSet.delete(listener);
|
|
833
|
-
}
|
|
834
|
-
removeAllListeners() {
|
|
835
|
-
this.#listeners.clear();
|
|
836
|
-
}
|
|
837
|
-
listenerCount(type) {
|
|
838
|
-
return this.#listeners.get(type)?.size ?? 0;
|
|
839
|
-
}
|
|
840
|
-
listeners(type) {
|
|
841
|
-
return Array.from(this.#listeners.get(type) ?? []);
|
|
842
|
-
}
|
|
843
|
-
};
|
|
844
|
-
var PromiseEventEmitter = class {
|
|
845
|
-
events;
|
|
846
|
-
constructor() {
|
|
847
|
-
this.events = new EventEmitter();
|
|
848
|
-
}
|
|
849
|
-
listenerCount(type) {
|
|
850
|
-
return this.events.listenerCount(type);
|
|
851
|
-
}
|
|
852
|
-
on(event, listener) {
|
|
853
|
-
return this.events.on(event, listener);
|
|
854
|
-
}
|
|
855
|
-
emit(event, ...args) {
|
|
856
|
-
const promises = [];
|
|
857
|
-
this.events.listeners(event).forEach((listener) => {
|
|
858
|
-
promises.push(listener(...args));
|
|
859
|
-
});
|
|
860
|
-
return Promise.all(promises);
|
|
861
|
-
}
|
|
862
|
-
};
|
|
863
|
-
// ../../node_modules/.pnpm/@secretlint+core@13.1.0_supports-color@7.2.0/node_modules/@secretlint/core/module/helper/SecretLintRuleMessageTranslator.js
|
|
1052
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/helper/SecretLintRuleMessageTranslator.js
|
|
864
1053
|
/**
|
|
865
1054
|
* Default locale that is also fallback locale.
|
|
866
1055
|
*/
|
|
@@ -910,38 +1099,7 @@ const createTranslator = (messages, options) => {
|
|
|
910
1099
|
};
|
|
911
1100
|
};
|
|
912
1101
|
};
|
|
913
|
-
// ../../node_modules/.pnpm/@secretlint+core@
|
|
914
|
-
const createContextEvents = () => {
|
|
915
|
-
const contextEvents = new EventEmitter();
|
|
916
|
-
const REPORT_SYMBOL = Symbol("report");
|
|
917
|
-
const IGNORE_SYMBOL = Symbol("ignore");
|
|
918
|
-
return {
|
|
919
|
-
report(descriptor) {
|
|
920
|
-
contextEvents.emit(REPORT_SYMBOL, descriptor);
|
|
921
|
-
},
|
|
922
|
-
onReport(handler) {
|
|
923
|
-
const listener = (descriptor) => {
|
|
924
|
-
handler(descriptor);
|
|
925
|
-
};
|
|
926
|
-
contextEvents.on(REPORT_SYMBOL, listener);
|
|
927
|
-
return () => {
|
|
928
|
-
contextEvents.off(REPORT_SYMBOL, listener);
|
|
929
|
-
};
|
|
930
|
-
},
|
|
931
|
-
ignore(descriptor) {
|
|
932
|
-
contextEvents.emit(IGNORE_SYMBOL, descriptor);
|
|
933
|
-
},
|
|
934
|
-
onIgnore(handler) {
|
|
935
|
-
const listener = (descriptor) => {
|
|
936
|
-
handler(descriptor);
|
|
937
|
-
};
|
|
938
|
-
contextEvents.on(IGNORE_SYMBOL, listener);
|
|
939
|
-
return () => {
|
|
940
|
-
contextEvents.off(IGNORE_SYMBOL, listener);
|
|
941
|
-
};
|
|
942
|
-
}
|
|
943
|
-
};
|
|
944
|
-
};
|
|
1102
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/RuleContext.js
|
|
945
1103
|
const createRuleContext = ({ ruleId, ruleParentId, meta, severity, sourceCode, contextEvents, sharedOptions, locale }) => {
|
|
946
1104
|
return {
|
|
947
1105
|
sharedOptions,
|
|
@@ -989,236 +1147,138 @@ const createRuleContext = ({ ruleId, ruleParentId, meta, severity, sourceCode, c
|
|
|
989
1147
|
}
|
|
990
1148
|
};
|
|
991
1149
|
};
|
|
992
|
-
// ../../node_modules/.pnpm/@secretlint+
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
this.ruleCreator = descriptorRule.rule;
|
|
1000
|
-
const ruleCreatorOptions = descriptorRule.options || {};
|
|
1001
|
-
this.ruleReportHandle = this.ruleCreator.create(context, ruleCreatorOptions);
|
|
1002
|
-
}
|
|
1003
|
-
allowMessageIds() {
|
|
1004
|
-
if (!this.descriptorRule.allowMessageIds) return [];
|
|
1005
|
-
const ruleId = this.ruleCreator.meta.id;
|
|
1006
|
-
return this.descriptorRule.allowMessageIds.map((allowMessageId) => {
|
|
1007
|
-
return {
|
|
1008
|
-
messageId: allowMessageId,
|
|
1009
|
-
ruleId
|
|
1010
|
-
};
|
|
1011
|
-
});
|
|
1012
|
-
}
|
|
1013
|
-
supportSourceCode(sourceCode) {
|
|
1014
|
-
const contentType = sourceCode.contentType;
|
|
1015
|
-
if (contentType === "unknown") return true;
|
|
1016
|
-
if (this.ruleCreator.meta.supportedContentTypes.includes("all")) return true;
|
|
1017
|
-
return this.ruleCreator.meta.supportedContentTypes.includes(contentType);
|
|
1018
|
-
}
|
|
1019
|
-
async file(source) {
|
|
1020
|
-
const file = this.ruleReportHandle.file;
|
|
1021
|
-
if (!file) return;
|
|
1022
|
-
return file(source);
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
// ../../node_modules/.pnpm/@secretlint+profiler@13.1.0/node_modules/@secretlint/profiler/module/index.js
|
|
1150
|
+
// ../../node_modules/.pnpm/@secretlint+profiler@14.0.0/node_modules/@secretlint/profiler/module/index.js
|
|
1151
|
+
const NO_ID = "";
|
|
1152
|
+
/**
|
|
1153
|
+
* The profiler keeps only the totals for each type and id: the count and the time.
|
|
1154
|
+
* It does not keep each record, because the core records for each file and each pattern.
|
|
1155
|
+
* https://github.com/secretlint/secretlint/issues/1633
|
|
1156
|
+
*/
|
|
1026
1157
|
var SecretLintProfiler = class {
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
observer;
|
|
1158
|
+
nowFn;
|
|
1159
|
+
enabled;
|
|
1030
1160
|
/**
|
|
1031
|
-
*
|
|
1032
|
-
* `performance.mark()` and `PerformanceObserver` callback are called for each rule and each file.
|
|
1033
|
-
* So, the profiler should be disabled if the user does not need the profiling result.
|
|
1034
|
-
* https://github.com/secretlint/secretlint/issues/1633
|
|
1161
|
+
* type -> id -> total. The id of a type without a target is ""
|
|
1035
1162
|
*/
|
|
1036
|
-
|
|
1037
|
-
entries = [];
|
|
1038
|
-
measures = [];
|
|
1163
|
+
stats = /* @__PURE__ */ new Map();
|
|
1039
1164
|
/**
|
|
1040
|
-
*
|
|
1165
|
+
* The start time of the spans that are started by `mark()` and not ended yet
|
|
1041
1166
|
*/
|
|
1042
|
-
|
|
1043
|
-
executionPromises = [];
|
|
1167
|
+
startTimes = /* @__PURE__ */ new Map();
|
|
1044
1168
|
constructor(options) {
|
|
1045
|
-
this.
|
|
1046
|
-
this.
|
|
1047
|
-
this.enabled = options.enabled ?? true;
|
|
1169
|
+
this.nowFn = options.now;
|
|
1170
|
+
this.enabled = options.enabled ?? false;
|
|
1048
1171
|
}
|
|
1049
1172
|
get isEnabled() {
|
|
1050
1173
|
return this.enabled;
|
|
1051
1174
|
}
|
|
1052
1175
|
/**
|
|
1053
1176
|
* Enable or Disable the profiler.
|
|
1054
|
-
* If the profiler is disabled,
|
|
1177
|
+
* If the profiler is disabled, it records nothing and the collected totals are cleared.
|
|
1055
1178
|
* @param enabled
|
|
1056
1179
|
*/
|
|
1057
1180
|
setEnabled(enabled) {
|
|
1058
1181
|
if (this.enabled === enabled) return;
|
|
1059
1182
|
this.enabled = enabled;
|
|
1060
|
-
if (!enabled)
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
this.observer = observer;
|
|
1083
|
-
}
|
|
1084
|
-
stopObserving() {
|
|
1085
|
-
this.observer?.disconnect();
|
|
1086
|
-
this.observer = void 0;
|
|
1087
|
-
this.entries.length = 0;
|
|
1088
|
-
this.measures.length = 0;
|
|
1089
|
-
this.executionPromises.length = 0;
|
|
1090
|
-
this.startMarkNames.clear();
|
|
1183
|
+
if (!enabled) {
|
|
1184
|
+
this.stats.clear();
|
|
1185
|
+
this.startTimes.clear();
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
statOf(type, id) {
|
|
1189
|
+
let statsOfType = this.stats.get(type);
|
|
1190
|
+
if (!statsOfType) {
|
|
1191
|
+
statsOfType = /* @__PURE__ */ new Map();
|
|
1192
|
+
this.stats.set(type, statsOfType);
|
|
1193
|
+
}
|
|
1194
|
+
const key = id ?? NO_ID;
|
|
1195
|
+
let stat = statsOfType.get(key);
|
|
1196
|
+
if (!stat) {
|
|
1197
|
+
stat = {
|
|
1198
|
+
count: 0,
|
|
1199
|
+
duration: 0,
|
|
1200
|
+
maxDuration: 0
|
|
1201
|
+
};
|
|
1202
|
+
statsOfType.set(key, stat);
|
|
1203
|
+
}
|
|
1204
|
+
return stat;
|
|
1091
1205
|
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Mark the start or the end of a span: `{span}::start` and `{span}::end`.
|
|
1208
|
+
* The time between the start and the end is recorded for the span and the id.
|
|
1209
|
+
* `::end` without `::start` is ignored.
|
|
1210
|
+
* A span is found by its type and id, so the spans of the same type and id should not overlap.
|
|
1211
|
+
* Use `now()` and `record()` for the code that can run again before it ends.
|
|
1212
|
+
*/
|
|
1092
1213
|
mark(marker) {
|
|
1093
1214
|
if (!this.enabled) return;
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1215
|
+
const now = this.nowFn();
|
|
1216
|
+
const id = "id" in marker ? marker.id : void 0;
|
|
1217
|
+
const isStart = marker.type.endsWith("::start");
|
|
1218
|
+
const span = marker.type.slice(0, isStart ? -7 : -5);
|
|
1219
|
+
const name = id === void 0 ? span : `${span}||${id}`;
|
|
1220
|
+
if (isStart) {
|
|
1221
|
+
this.startTimes.set(name, now);
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
const startTime = this.startTimes.get(name);
|
|
1225
|
+
if (startTime === void 0) return;
|
|
1226
|
+
this.startTimes.delete(name);
|
|
1227
|
+
this.add(span, id, now - startTime);
|
|
1097
1228
|
}
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
async getEntries() {
|
|
1104
|
-
await this.waifForExecutionPromises();
|
|
1105
|
-
return this.entries;
|
|
1229
|
+
/**
|
|
1230
|
+
* Return the current time for `record()`. It is 0 if the profiler is disabled.
|
|
1231
|
+
*/
|
|
1232
|
+
now() {
|
|
1233
|
+
return this.enabled ? this.nowFn() : 0;
|
|
1106
1234
|
}
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1235
|
+
/**
|
|
1236
|
+
* Record the time from `startTime` to now. `startTime` is the result of `now()`.
|
|
1237
|
+
* It is for code that runs many times: check `isEnabled` first, and call `now()` and `record()` only if it is true.
|
|
1238
|
+
*/
|
|
1239
|
+
record(type, id, startTime) {
|
|
1240
|
+
if (!this.enabled) return;
|
|
1241
|
+
this.add(type, id, this.nowFn() - startTime);
|
|
1110
1242
|
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
Duplicated rule.id is something wrong in .secretlintrc.
|
|
1146
|
-
`);
|
|
1147
|
-
registerSet.add(descriptorRule.id);
|
|
1148
|
-
const rule = new SecretLintRule({
|
|
1149
|
-
descriptorRule,
|
|
1150
|
-
context
|
|
1151
|
-
});
|
|
1152
|
-
rules.push(rule);
|
|
1153
|
-
contextEvents.on(LINT_HANDLE, async ({ sourceCode }) => {
|
|
1154
|
-
secretLintProfiler.mark({
|
|
1155
|
-
type: "@core>rule-handler::start",
|
|
1156
|
-
id: descriptorRule.rule.meta.id
|
|
1157
|
-
});
|
|
1158
|
-
if (rule.supportSourceCode(sourceCode)) await rule.file(sourceCode);
|
|
1159
|
-
secretLintProfiler.mark({
|
|
1160
|
-
type: "@core>rule-handler::end",
|
|
1161
|
-
id: descriptorRule.rule.meta.id
|
|
1162
|
-
});
|
|
1163
|
-
});
|
|
1164
|
-
},
|
|
1165
|
-
registerRulePreset({ descriptorRulePreset, context }) {
|
|
1166
|
-
const rulePresetCreatorOptions = descriptorRulePreset.options || [];
|
|
1167
|
-
descriptorRulePreset.rule.create(context, rulePresetCreatorOptions);
|
|
1168
|
-
},
|
|
1169
|
-
isRegistered(ruleId) {
|
|
1170
|
-
return registerSet.has(ruleId);
|
|
1171
|
-
}
|
|
1172
|
-
};
|
|
1173
|
-
};
|
|
1174
|
-
// ../../node_modules/.pnpm/@secretlint+core@13.1.0_supports-color@7.2.0/node_modules/@secretlint/core/module/RulePresetContext.js
|
|
1175
|
-
/**
|
|
1176
|
-
* Create a context for Rule Preset
|
|
1177
|
-
*/
|
|
1178
|
-
const createRulePresetContext = ({ configRulePreset, sourceCode, runningEvents, contextEvents, sharedOptions, locale }) => {
|
|
1179
|
-
const presetRules = configRulePreset.rules || [];
|
|
1180
|
-
if (!Array.isArray(presetRules)) {
|
|
1181
|
-
console.error(`${configRulePreset.id}:PresetRules is invalid format`, presetRules);
|
|
1182
|
-
throw new Error("preset's rules should be an array of rule definitions");
|
|
1243
|
+
/**
|
|
1244
|
+
* Add a total that was measured somewhere else, such as in a worker thread
|
|
1245
|
+
*/
|
|
1246
|
+
addTotal(type, id, total) {
|
|
1247
|
+
if (!this.enabled) return;
|
|
1248
|
+
const stat = this.statOf(type, id);
|
|
1249
|
+
stat.count += total.count;
|
|
1250
|
+
stat.duration += total.duration;
|
|
1251
|
+
if (total.duration > stat.maxDuration) stat.maxDuration = total.duration;
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* Count something that has no duration
|
|
1255
|
+
*/
|
|
1256
|
+
count(type, id, count = 1) {
|
|
1257
|
+
if (!this.enabled) return;
|
|
1258
|
+
this.statOf(type, id).count += count;
|
|
1259
|
+
}
|
|
1260
|
+
add(type, id, duration) {
|
|
1261
|
+
const stat = this.statOf(type, id);
|
|
1262
|
+
stat.count++;
|
|
1263
|
+
stat.duration += duration;
|
|
1264
|
+
if (duration > stat.maxDuration) stat.maxDuration = duration;
|
|
1265
|
+
}
|
|
1266
|
+
/**
|
|
1267
|
+
* Return the totals for each type and id, in the order of the first record
|
|
1268
|
+
*/
|
|
1269
|
+
getStats() {
|
|
1270
|
+
const results = [];
|
|
1271
|
+
for (const [type, statsOfType] of this.stats) for (const [id, stat] of statsOfType) results.push({
|
|
1272
|
+
type,
|
|
1273
|
+
id: id === NO_ID ? void 0 : id,
|
|
1274
|
+
...stat
|
|
1275
|
+
});
|
|
1276
|
+
return results;
|
|
1183
1277
|
}
|
|
1184
|
-
return {
|
|
1185
|
-
sharedOptions,
|
|
1186
|
-
registerRule(rule, defaultValue) {
|
|
1187
|
-
const descriptorRule = presetRules.find((descriptorRule) => {
|
|
1188
|
-
return descriptorRule.id === rule.meta.id;
|
|
1189
|
-
});
|
|
1190
|
-
const descriptorRuleOptions = descriptorRule ? descriptorRule.options : void 0;
|
|
1191
|
-
const descriptorRuleDisabled = descriptorRule ? descriptorRule.disabled : void 0;
|
|
1192
|
-
const descriptorRuleSeverity = descriptorRule ? descriptorRule.severity : void 0;
|
|
1193
|
-
const descriptorAllowMessageIds = descriptorRule ? descriptorRule.allowMessageIds : void 0;
|
|
1194
|
-
const context = createRuleContext({
|
|
1195
|
-
ruleId: rule.meta.id,
|
|
1196
|
-
ruleParentId: configRulePreset.id,
|
|
1197
|
-
meta: rule.meta,
|
|
1198
|
-
severity: descriptorRuleSeverity,
|
|
1199
|
-
sourceCode,
|
|
1200
|
-
contextEvents,
|
|
1201
|
-
sharedOptions,
|
|
1202
|
-
locale
|
|
1203
|
-
});
|
|
1204
|
-
const defaultValueOfPreset = defaultValue ? defaultValue : {};
|
|
1205
|
-
runningEvents.registerRule({
|
|
1206
|
-
descriptorRule: {
|
|
1207
|
-
...defaultValueOfPreset,
|
|
1208
|
-
...descriptorRule,
|
|
1209
|
-
id: rule.meta.id,
|
|
1210
|
-
options: descriptorRuleOptions,
|
|
1211
|
-
rule,
|
|
1212
|
-
disabled: descriptorRuleDisabled,
|
|
1213
|
-
allowMessageIds: descriptorAllowMessageIds,
|
|
1214
|
-
severity: descriptorRuleSeverity
|
|
1215
|
-
},
|
|
1216
|
-
context
|
|
1217
|
-
});
|
|
1218
|
-
}
|
|
1219
|
-
};
|
|
1220
1278
|
};
|
|
1221
|
-
// ../../node_modules/.pnpm/@secretlint+
|
|
1279
|
+
// ../../node_modules/.pnpm/@secretlint+profiler@14.0.0/node_modules/@secretlint/profiler/module/node.js
|
|
1280
|
+
const secretLintProfiler = new SecretLintProfiler({ now: () => perf_hooks.performance.now() });
|
|
1281
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/messages/filter-ignored-process.js
|
|
1222
1282
|
/**
|
|
1223
1283
|
* the `index` is in the `range` and return true.
|
|
1224
1284
|
* @param {Number} index
|
|
@@ -1246,7 +1306,7 @@ function filterIgnoredMessages(options) {
|
|
|
1246
1306
|
});
|
|
1247
1307
|
});
|
|
1248
1308
|
}
|
|
1249
|
-
// ../../node_modules/.pnpm/@secretlint+core@
|
|
1309
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/messages/MessageProcessManager.js
|
|
1250
1310
|
const createMessageProcessor = (processors) => {
|
|
1251
1311
|
return {
|
|
1252
1312
|
/**
|
|
@@ -1260,7 +1320,7 @@ process(messages) {
|
|
|
1260
1320
|
}, originalMessages);
|
|
1261
1321
|
} };
|
|
1262
1322
|
};
|
|
1263
|
-
// ../../node_modules/.pnpm/@secretlint+core@
|
|
1323
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/messages/filter-duplicated-process.js
|
|
1264
1324
|
/**
|
|
1265
1325
|
* equal message
|
|
1266
1326
|
*/
|
|
@@ -1277,7 +1337,7 @@ function filterDuplicatedMessages(messages = []) {
|
|
|
1277
1337
|
});
|
|
1278
1338
|
});
|
|
1279
1339
|
}
|
|
1280
|
-
// ../../node_modules/.pnpm/@secretlint+core@
|
|
1340
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/messages/sort-messages-process.js
|
|
1281
1341
|
/**
|
|
1282
1342
|
* sort messages by line and column
|
|
1283
1343
|
*/
|
|
@@ -1288,7 +1348,7 @@ function sortMessagesByLocation(messages) {
|
|
|
1288
1348
|
else return startIndexDiff;
|
|
1289
1349
|
});
|
|
1290
1350
|
}
|
|
1291
|
-
// ../../node_modules/.pnpm/@secretlint+core@
|
|
1351
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/messages/filter-message-id.js
|
|
1292
1352
|
const filterByAllowMessageIds = (messages, allowMessageIds) => {
|
|
1293
1353
|
const disabledSet = new Set(allowMessageIds.map((allowMessage) => {
|
|
1294
1354
|
return `${allowMessage.ruleId}--${allowMessage.messageId}`;
|
|
@@ -1297,7 +1357,7 @@ const filterByAllowMessageIds = (messages, allowMessageIds) => {
|
|
|
1297
1357
|
return !disabledSet.has(`${message.ruleId}--${message.messageId}`);
|
|
1298
1358
|
});
|
|
1299
1359
|
};
|
|
1300
|
-
// ../../node_modules/.pnpm/@secretlint+core@
|
|
1360
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/messages/filter-mask-secrets.js
|
|
1301
1361
|
const deepMask = (object, handler) => {
|
|
1302
1362
|
for (const key of Object.keys(object)) if (typeof object[key] === "object" && object[key] !== null) object[key] = deepMask(object[key], handler);
|
|
1303
1363
|
else if (typeof object[key] === "string") object[key] = handler(object[key]);
|
|
@@ -1345,7 +1405,7 @@ const filterMaskSecretsData = (messages = []) => {
|
|
|
1345
1405
|
};
|
|
1346
1406
|
});
|
|
1347
1407
|
};
|
|
1348
|
-
// ../../node_modules/.pnpm/@secretlint+core@
|
|
1408
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/messages/index.js
|
|
1349
1409
|
/**
|
|
1350
1410
|
* Post cleanup messages
|
|
1351
1411
|
* - filter ignored range
|
|
@@ -2159,128 +2219,3446 @@ var require_node = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2159
2219
|
return util.inspect(v, this.inspectOpts);
|
|
2160
2220
|
};
|
|
2161
2221
|
}));
|
|
2162
|
-
|
|
2222
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/helper/keyword-matcher.js
|
|
2223
|
+
var import_src = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2163
2224
|
/**
|
|
2164
2225
|
* Detect Electron renderer / nwjs process, which is node, but we should
|
|
2165
2226
|
* treat as a browser.
|
|
2166
2227
|
*/
|
|
2167
2228
|
if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) module.exports = require_browser();
|
|
2168
2229
|
else module.exports = require_node();
|
|
2169
|
-
})))(), 1)
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2230
|
+
})))(), 1);
|
|
2231
|
+
/**
|
|
2232
|
+
* Find where keywords appear in a text or in UTF-8 bytes, in a single pass.
|
|
2233
|
+
*
|
|
2234
|
+
* This is the Aho-Corasick algorithm.
|
|
2235
|
+
* Keywords are always matched ASCII case-insensitively: "a-z" and "A-Z" are the same character.
|
|
2236
|
+
* A keyword can have a guard: a set of ASCII characters and a least count of them after the keyword.
|
|
2237
|
+
* The guard is checked in the scan loop, and a place whose guard is not met is not recorded.
|
|
2238
|
+
* Non-ASCII characters never match a keyword character.
|
|
2239
|
+
* Keywords are ASCII only, so scanning the UTF-8 bytes finds the same keywords as scanning the decoded text.
|
|
2240
|
+
*
|
|
2241
|
+
* Rules declare keywords, and the core scans the content once for all keywords of all rules
|
|
2242
|
+
* instead of running each rule's regular expressions over the whole content.
|
|
2243
|
+
* Secret scanners such as gitleaks and TruffleHog use the same keyword pre-filter.
|
|
2244
|
+
*/
|
|
2245
|
+
const ASCII_SIZE = 128;
|
|
2246
|
+
const BYTE_SIZE = 256;
|
|
2247
|
+
const INITIAL_POSITIONS_SIZE = 64;
|
|
2248
|
+
/**
|
|
2249
|
+
* Normalize a keyword for matching.
|
|
2250
|
+
* Return `undefined` if the keyword can not be matched by {@link KeywordMatcher}.
|
|
2251
|
+
*/
|
|
2252
|
+
const normalizeKeyword = (keyword) => {
|
|
2253
|
+
if (typeof keyword !== "string" || keyword.length === 0) return;
|
|
2254
|
+
for (let i = 0; i < keyword.length; i++) if (keyword.charCodeAt(i) >= ASCII_SIZE) return;
|
|
2255
|
+
return keyword.toLowerCase();
|
|
2256
|
+
};
|
|
2257
|
+
/**
|
|
2258
|
+
* Create a matcher for the keywords.
|
|
2259
|
+
* Keywords should be lower-cased by {@link normalizeKeyword}.
|
|
2260
|
+
* If `guards[i]` is defined, `keywords[i]` is found only where the guard is met.
|
|
2261
|
+
*/
|
|
2262
|
+
const createKeywordMatcher = (keywords, guards = [], options = {}) => {
|
|
2263
|
+
const trieKeywords = keywords.map((keyword) => keyword.toLowerCase());
|
|
2264
|
+
const charClass = new Uint8Array(BYTE_SIZE);
|
|
2265
|
+
let classCount = 1;
|
|
2266
|
+
for (const keyword of trieKeywords) for (let i = 0; i < keyword.length; i++) {
|
|
2267
|
+
const code = keyword.charCodeAt(i);
|
|
2268
|
+
if (charClass[code] === 0) charClass[code] = classCount++;
|
|
2269
|
+
}
|
|
2270
|
+
for (let code = 65; code <= 90; code++) charClass[code] = charClass[code + 32] ?? 0;
|
|
2271
|
+
const children = [new Int32Array(classCount).fill(-1)];
|
|
2272
|
+
const trieOutputs = [[]];
|
|
2273
|
+
trieKeywords.forEach((keyword, keywordIndex) => {
|
|
2274
|
+
let state = 0;
|
|
2275
|
+
for (let i = 0; i < keyword.length; i++) {
|
|
2276
|
+
const cls = charClass[keyword.charCodeAt(i)] ?? 0;
|
|
2277
|
+
const stateChildren = children[state];
|
|
2278
|
+
let next = stateChildren[cls] ?? -1;
|
|
2279
|
+
if (next < 0) {
|
|
2280
|
+
next = children.length;
|
|
2281
|
+
stateChildren[cls] = next;
|
|
2282
|
+
children.push(new Int32Array(classCount).fill(-1));
|
|
2283
|
+
trieOutputs.push([]);
|
|
2284
|
+
}
|
|
2285
|
+
state = next;
|
|
2286
|
+
}
|
|
2287
|
+
trieOutputs[state].push(keywordIndex);
|
|
2174
2288
|
});
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
const
|
|
2178
|
-
const
|
|
2179
|
-
const
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2289
|
+
const stateCount = children.length;
|
|
2290
|
+
const trieTransitions = new Int32Array(stateCount * classCount);
|
|
2291
|
+
const failure = new Int32Array(stateCount);
|
|
2292
|
+
const queue = [];
|
|
2293
|
+
const rootChildren = children[0];
|
|
2294
|
+
for (let cls = 0; cls < classCount; cls++) {
|
|
2295
|
+
const next = rootChildren[cls] ?? -1;
|
|
2296
|
+
if (next > 0) {
|
|
2297
|
+
trieTransitions[cls] = next;
|
|
2298
|
+
queue.push(next);
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
for (let head = 0; head < queue.length; head++) {
|
|
2302
|
+
const state = queue[head];
|
|
2303
|
+
const fail = failure[state] ?? 0;
|
|
2304
|
+
trieOutputs[state] = trieOutputs[state].concat(trieOutputs[fail]);
|
|
2305
|
+
const stateChildren = children[state];
|
|
2306
|
+
for (let cls = 0; cls < classCount; cls++) {
|
|
2307
|
+
const next = stateChildren[cls] ?? -1;
|
|
2308
|
+
const failTransition = trieTransitions[fail * classCount + cls] ?? 0;
|
|
2309
|
+
if (next >= 0) {
|
|
2310
|
+
failure[next] = failTransition;
|
|
2311
|
+
trieTransitions[state * classCount + cls] = next;
|
|
2312
|
+
queue.push(next);
|
|
2313
|
+
} else trieTransitions[state * classCount + cls] = failTransition;
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
const order = [];
|
|
2317
|
+
for (let state = 0; state < stateCount; state++) if (trieOutputs[state].length === 0) order.push(state);
|
|
2318
|
+
const firstOutputState = order.length;
|
|
2319
|
+
for (let state = 0; state < stateCount; state++) if (trieOutputs[state].length > 0) order.push(state);
|
|
2320
|
+
const newState = new Int32Array(stateCount);
|
|
2321
|
+
order.forEach((oldState, state) => {
|
|
2322
|
+
newState[oldState] = state;
|
|
2186
2323
|
});
|
|
2187
|
-
|
|
2188
|
-
|
|
2324
|
+
const tableSize = stateCount * classCount;
|
|
2325
|
+
const transitions = tableSize <= 65535 ? new Uint16Array(tableSize) : new Int32Array(tableSize);
|
|
2326
|
+
const outputs = [];
|
|
2327
|
+
order.forEach((oldState, state) => {
|
|
2328
|
+
for (let cls = 0; cls < classCount; cls++) transitions[state * classCount + cls] = newState[trieTransitions[oldState * classCount + cls]] * classCount;
|
|
2329
|
+
outputs.push(trieOutputs[oldState]);
|
|
2189
2330
|
});
|
|
2190
|
-
const
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
ext: source.ext || "",
|
|
2195
|
-
contentType: source.contentType
|
|
2331
|
+
const firstOutputOffset = firstOutputState * classCount;
|
|
2332
|
+
const guardTables = keywords.map((_, index) => {
|
|
2333
|
+
const guard = guards[index];
|
|
2334
|
+
return guard === void 0 ? void 0 : createGuardTable(guard);
|
|
2196
2335
|
});
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
});
|
|
2203
|
-
registerRule({
|
|
2204
|
-
sourceCode,
|
|
2205
|
-
config: options.config,
|
|
2206
|
-
descriptorRule: rule,
|
|
2207
|
-
contextEvents,
|
|
2208
|
-
runningEvents,
|
|
2209
|
-
locale
|
|
2210
|
-
});
|
|
2211
|
-
secretLintProfiler.mark({
|
|
2212
|
-
type: "@core>setup-rule::end",
|
|
2213
|
-
id: rule.rule.meta.id
|
|
2214
|
-
});
|
|
2336
|
+
const guardMins = keywords.map((_, index) => guards[index]?.min ?? 0);
|
|
2337
|
+
const hasGuards = guardTables.some((table) => table !== void 0);
|
|
2338
|
+
const needsCheck = new Uint8Array(stateCount);
|
|
2339
|
+
outputs.forEach((output, state) => {
|
|
2340
|
+
if (output.some((keywordIndex) => guardTables[keywordIndex] !== void 0)) needsCheck[state] = 1;
|
|
2215
2341
|
});
|
|
2216
|
-
|
|
2217
|
-
|
|
2342
|
+
let guardCounts = options.countGuards ? new Float64Array(keywords.length * 2) : void 0;
|
|
2343
|
+
const subsetIds = /* @__PURE__ */ new Map();
|
|
2344
|
+
/**
|
|
2345
|
+
* Return the id of the keywords of the state that are found at the place, or -1 if none is found.
|
|
2346
|
+
* `lastIndex` is the index of the last character of the keywords.
|
|
2347
|
+
* It reads at most 255 characters after the place for each guard, and it does not change the state of the scan.
|
|
2348
|
+
*/
|
|
2349
|
+
const checkGuards = (input, state, lastIndex) => {
|
|
2350
|
+
const output = outputs[state];
|
|
2351
|
+
const isText = typeof input === "string";
|
|
2352
|
+
let metCount = 0;
|
|
2353
|
+
for (let i = 0; i < output.length; i++) {
|
|
2354
|
+
const keywordIndex = output[i];
|
|
2355
|
+
const table = guardTables[keywordIndex];
|
|
2356
|
+
if (table === void 0) {
|
|
2357
|
+
metCount++;
|
|
2358
|
+
continue;
|
|
2359
|
+
}
|
|
2360
|
+
const min = guardMins[keywordIndex];
|
|
2361
|
+
const met = isText ? isGuardMetInText(input, lastIndex + 1, table, min) : isGuardMetInBytes(input, lastIndex + 1, table, min);
|
|
2362
|
+
if (guardCounts) {
|
|
2363
|
+
guardCounts[keywordIndex * 2]++;
|
|
2364
|
+
if (met) guardCounts[keywordIndex * 2 + 1]++;
|
|
2365
|
+
}
|
|
2366
|
+
if (met) metCount++;
|
|
2367
|
+
}
|
|
2368
|
+
if (metCount === output.length) return state;
|
|
2369
|
+
if (metCount === 0) return -1;
|
|
2370
|
+
const matched = output.filter((keywordIndex) => {
|
|
2371
|
+
const table = guardTables[keywordIndex];
|
|
2372
|
+
if (table === void 0) return true;
|
|
2373
|
+
const min = guardMins[keywordIndex];
|
|
2374
|
+
return isText ? isGuardMetInText(input, lastIndex + 1, table, min) : isGuardMetInBytes(input, lastIndex + 1, table, min);
|
|
2375
|
+
});
|
|
2376
|
+
const key = `${state}:${matched.join(",")}`;
|
|
2377
|
+
const knownId = subsetIds.get(key);
|
|
2378
|
+
if (knownId !== void 0) return knownId;
|
|
2379
|
+
const id = outputs.length;
|
|
2380
|
+
outputs.push(matched);
|
|
2381
|
+
subsetIds.set(key, id);
|
|
2382
|
+
return id;
|
|
2383
|
+
};
|
|
2384
|
+
let buffer = new Int32Array(INITIAL_POSITIONS_SIZE);
|
|
2385
|
+
const growBuffer = () => {
|
|
2386
|
+
const grown = new Int32Array(buffer.length * 2);
|
|
2387
|
+
grown.set(buffer);
|
|
2388
|
+
buffer = grown;
|
|
2389
|
+
};
|
|
2390
|
+
/**
|
|
2391
|
+
* Write [state, index] of the hits to the buffer, and return the length of the written part
|
|
2392
|
+
*/
|
|
2393
|
+
const scanBytes = (bytes, start) => {
|
|
2394
|
+
let offset = 0;
|
|
2395
|
+
let written = 0;
|
|
2396
|
+
for (let i = start, length = bytes.length; i < length; i++) {
|
|
2397
|
+
offset = transitions[offset + charClass[bytes[i]]];
|
|
2398
|
+
if (offset >= firstOutputOffset) {
|
|
2399
|
+
let id = offset / classCount;
|
|
2400
|
+
if (hasGuards && needsCheck[id] === 1) {
|
|
2401
|
+
id = checkGuards(bytes, id, i);
|
|
2402
|
+
if (id < 0) continue;
|
|
2403
|
+
}
|
|
2404
|
+
if (written >= buffer.length) growBuffer();
|
|
2405
|
+
buffer[written] = id;
|
|
2406
|
+
buffer[written + 1] = i;
|
|
2407
|
+
written += 2;
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
return written;
|
|
2411
|
+
};
|
|
2412
|
+
const scanText = (text, start) => {
|
|
2413
|
+
let offset = 0;
|
|
2414
|
+
let written = 0;
|
|
2415
|
+
for (let i = start, length = text.length; i < length; i++) {
|
|
2416
|
+
const code = text.charCodeAt(i);
|
|
2417
|
+
offset = transitions[offset + (code < ASCII_SIZE ? charClass[code] : 0)];
|
|
2418
|
+
if (offset >= firstOutputOffset) {
|
|
2419
|
+
let id = offset / classCount;
|
|
2420
|
+
if (hasGuards && needsCheck[id] === 1) {
|
|
2421
|
+
id = checkGuards(text, id, i);
|
|
2422
|
+
if (id < 0) continue;
|
|
2423
|
+
}
|
|
2424
|
+
if (written >= buffer.length) growBuffer();
|
|
2425
|
+
buffer[written] = id;
|
|
2426
|
+
buffer[written + 1] = i;
|
|
2427
|
+
written += 2;
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
return written;
|
|
2431
|
+
};
|
|
2432
|
+
const noHits = {
|
|
2433
|
+
found: new Uint8Array(keywords.length),
|
|
2434
|
+
positions: /* @__PURE__ */ new Int32Array(0),
|
|
2435
|
+
count: 0
|
|
2436
|
+
};
|
|
2437
|
+
const scan = (input, start = 0) => {
|
|
2438
|
+
if (keywords.length === 0) return noHits;
|
|
2439
|
+
const length = typeof input === "string" ? scanText(input, start) : scanBytes(input, start);
|
|
2440
|
+
if (length === 0) return noHits;
|
|
2441
|
+
const positions = buffer.slice(0, length);
|
|
2442
|
+
const found = new Uint8Array(keywords.length);
|
|
2443
|
+
for (let i = 0; i < length; i += 2) {
|
|
2444
|
+
const output = outputs[positions[i]];
|
|
2445
|
+
for (let j = 0; j < output.length; j++) found[output[j]] = 1;
|
|
2446
|
+
}
|
|
2218
2447
|
return {
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
messages: cleanupMessages({
|
|
2223
|
-
reportedMessages,
|
|
2224
|
-
ignoredMessages,
|
|
2225
|
-
allowMessageIds: runningEvents.collectAllowMessageIds(),
|
|
2226
|
-
maskSecrets
|
|
2227
|
-
})
|
|
2448
|
+
found,
|
|
2449
|
+
positions,
|
|
2450
|
+
count: length / 2
|
|
2228
2451
|
};
|
|
2229
|
-
}
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2452
|
+
};
|
|
2453
|
+
return {
|
|
2454
|
+
keywords,
|
|
2455
|
+
guards: keywords.map((_, index) => guards[index]),
|
|
2456
|
+
setGuardCounting(enabled) {
|
|
2457
|
+
if (enabled === (guardCounts !== void 0)) return;
|
|
2458
|
+
guardCounts = enabled && hasGuards ? new Float64Array(keywords.length * 2) : void 0;
|
|
2459
|
+
},
|
|
2460
|
+
takeGuardCounts() {
|
|
2461
|
+
if (!guardCounts) return [];
|
|
2462
|
+
const counts = [];
|
|
2463
|
+
for (let keywordIndex = 0; keywordIndex < keywords.length; keywordIndex++) {
|
|
2464
|
+
const found = guardCounts[keywordIndex * 2];
|
|
2465
|
+
if (found > 0) counts.push({
|
|
2466
|
+
keywordIndex,
|
|
2467
|
+
found,
|
|
2468
|
+
met: guardCounts[keywordIndex * 2 + 1]
|
|
2469
|
+
});
|
|
2470
|
+
}
|
|
2471
|
+
guardCounts.fill(0);
|
|
2472
|
+
return counts;
|
|
2473
|
+
},
|
|
2474
|
+
match(text) {
|
|
2475
|
+
return scan(text).found;
|
|
2476
|
+
},
|
|
2477
|
+
scan,
|
|
2478
|
+
keywordsOfState(state) {
|
|
2479
|
+
return outputs[state] ?? [];
|
|
2480
|
+
}
|
|
2481
|
+
};
|
|
2235
2482
|
};
|
|
2236
|
-
const
|
|
2237
|
-
|
|
2483
|
+
const MAX_CACHE_SIZE = 32;
|
|
2484
|
+
const matcherCache = /* @__PURE__ */ new Map();
|
|
2485
|
+
/**
|
|
2486
|
+
* Return a cached matcher for the keywords.
|
|
2487
|
+
*/
|
|
2488
|
+
const getKeywordMatcher = (keywords, guards = []) => {
|
|
2489
|
+
const key = JSON.stringify([keywords, keywords.map((_, index) => keywordGuardKey(guards[index]))]);
|
|
2490
|
+
const cached = matcherCache.get(key);
|
|
2491
|
+
if (cached) return cached;
|
|
2492
|
+
if (matcherCache.size >= MAX_CACHE_SIZE) matcherCache.clear();
|
|
2493
|
+
const matcher = createKeywordMatcher(keywords, guards);
|
|
2494
|
+
matcherCache.set(key, matcher);
|
|
2495
|
+
return matcher;
|
|
2238
2496
|
};
|
|
2239
|
-
|
|
2240
|
-
|
|
2497
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/helper/line-check.js
|
|
2498
|
+
const LINE_FEED = 10;
|
|
2499
|
+
const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
2500
|
+
/**
|
|
2501
|
+
* Decode a part of UTF-8 bytes.
|
|
2502
|
+
* The part is a line: it starts after a line feed and ends with a line feed,
|
|
2503
|
+
* so the result is the same as the part of the decoded whole content.
|
|
2504
|
+
*/
|
|
2505
|
+
const decodeBytes = (bytes, start, end) => {
|
|
2506
|
+
const utf8Slice = bytes.utf8Slice;
|
|
2507
|
+
if (typeof utf8Slice === "function") return utf8Slice.call(bytes, start, end);
|
|
2508
|
+
return textDecoder.decode(bytes.subarray(start, end));
|
|
2509
|
+
};
|
|
2510
|
+
const isKeywordFound = (keywordIndexes, found) => {
|
|
2511
|
+
return keywordIndexes.some((keywordIndex) => found[keywordIndex] === 1);
|
|
2241
2512
|
};
|
|
2242
2513
|
/**
|
|
2243
|
-
*
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
const
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
locale
|
|
2276
|
-
});
|
|
2277
|
-
runningEvents.registerRule({
|
|
2278
|
-
descriptorRule,
|
|
2279
|
-
context
|
|
2280
|
-
});
|
|
2281
|
-
return;
|
|
2514
|
+
* Call `visit` for each line that has a keyword of a "line" scope pattern, with the patterns of the keywords.
|
|
2515
|
+
* A line is [start, end), and it includes its line feed.
|
|
2516
|
+
* Stop and return true if `visit` returns true.
|
|
2517
|
+
*/
|
|
2518
|
+
const someKeywordLine = (view, hits, lineStartOf, lineEndOf, visit) => {
|
|
2519
|
+
const { matcher, linePatternsOfKeyword } = view;
|
|
2520
|
+
if (!matcher) return false;
|
|
2521
|
+
const positions = hits.positions;
|
|
2522
|
+
const end = hits.count * 2;
|
|
2523
|
+
const addLinePatterns = (patterns, state) => {
|
|
2524
|
+
const keywordIndexes = matcher.keywordsOfState(state);
|
|
2525
|
+
for (let i = 0; i < keywordIndexes.length; i++) {
|
|
2526
|
+
const linePatterns = linePatternsOfKeyword[keywordIndexes[i]];
|
|
2527
|
+
for (let j = 0; j < linePatterns.length; j++) {
|
|
2528
|
+
const pattern = linePatterns[j];
|
|
2529
|
+
if (!patterns.includes(pattern)) patterns.push(pattern);
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
};
|
|
2533
|
+
for (let cursor = 0; cursor < end;) {
|
|
2534
|
+
const patterns = [];
|
|
2535
|
+
addLinePatterns(patterns, positions[cursor]);
|
|
2536
|
+
if (patterns.length === 0) {
|
|
2537
|
+
cursor += 2;
|
|
2538
|
+
continue;
|
|
2539
|
+
}
|
|
2540
|
+
const index = positions[cursor + 1];
|
|
2541
|
+
const lineStart = lineStartOf(index);
|
|
2542
|
+
const lineEnd = lineEndOf(index);
|
|
2543
|
+
cursor += 2;
|
|
2544
|
+
for (; cursor < end && positions[cursor + 1] < lineEnd; cursor += 2) addLinePatterns(patterns, positions[cursor]);
|
|
2545
|
+
if (visit(lineStart, lineEnd, patterns)) return true;
|
|
2282
2546
|
}
|
|
2283
|
-
|
|
2547
|
+
return false;
|
|
2548
|
+
};
|
|
2549
|
+
/**
|
|
2550
|
+
* Return true if a "line" scope pattern matches a line that has its keyword.
|
|
2551
|
+
* It decodes only the lines that have a keyword, so the whole content is not decoded for the files without secrets.
|
|
2552
|
+
* `hits` is the result of scanning the bytes.
|
|
2553
|
+
*/
|
|
2554
|
+
const hasLineMatchInBytes = (view, hits, bytes, contentStart, test = (pattern, line) => pattern.tester.test(line)) => {
|
|
2555
|
+
return someKeywordLine(view, hits, (index) => Math.max((index === 0 ? -1 : bytes.lastIndexOf(LINE_FEED, index - 1)) + 1, contentStart), (index) => {
|
|
2556
|
+
const nextLineFeed = bytes.indexOf(LINE_FEED, index);
|
|
2557
|
+
return nextLineFeed < 0 ? bytes.length : nextLineFeed + 1;
|
|
2558
|
+
}, (lineStart, lineEnd, patterns) => {
|
|
2559
|
+
const line = decodeBytes(bytes, lineStart, lineEnd);
|
|
2560
|
+
return patterns.some((pattern) => test(pattern, line));
|
|
2561
|
+
});
|
|
2562
|
+
};
|
|
2563
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/keyword-scan.js
|
|
2564
|
+
const createKeywordScanPlan = ({ keywords, guards, requiresKeyword, ruleCheck }) => {
|
|
2565
|
+
const planGuards = keywords.map((_, index) => {
|
|
2566
|
+
const guard = guards[index];
|
|
2567
|
+
return guard ? {
|
|
2568
|
+
chars: guard.chars,
|
|
2569
|
+
min: guard.min
|
|
2570
|
+
} : void 0;
|
|
2571
|
+
});
|
|
2572
|
+
return {
|
|
2573
|
+
id: JSON.stringify([
|
|
2574
|
+
keywords,
|
|
2575
|
+
planGuards,
|
|
2576
|
+
ruleCheck
|
|
2577
|
+
]),
|
|
2578
|
+
keywords: [...keywords],
|
|
2579
|
+
guards: planGuards,
|
|
2580
|
+
requiresKeyword,
|
|
2581
|
+
ruleCheck
|
|
2582
|
+
};
|
|
2583
|
+
};
|
|
2584
|
+
const hasUtf8BOM = (bytes) => {
|
|
2585
|
+
return bytes.length >= 3 && bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191;
|
|
2586
|
+
};
|
|
2587
|
+
// ../../node_modules/.pnpm/@textlint+regexp-string-matcher@2.0.3/node_modules/@textlint/regexp-string-matcher/lib/regexp-parse.js
|
|
2588
|
+
var require_regexp_parse = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2589
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2590
|
+
exports.isRegExpString = exports.parseRegExpString = void 0;
|
|
2591
|
+
var REGEXP_LITERAL_PATTERN = /^\/(.+)\/([guimysd]*)$/;
|
|
2592
|
+
var parseRegExpString = function(str) {
|
|
2593
|
+
var result = str.match(REGEXP_LITERAL_PATTERN);
|
|
2594
|
+
if (!result) return null;
|
|
2595
|
+
return {
|
|
2596
|
+
source: result[1],
|
|
2597
|
+
flagString: result[2]
|
|
2598
|
+
};
|
|
2599
|
+
};
|
|
2600
|
+
exports.parseRegExpString = parseRegExpString;
|
|
2601
|
+
var isRegExpString = function(str) {
|
|
2602
|
+
return REGEXP_LITERAL_PATTERN.test(str);
|
|
2603
|
+
};
|
|
2604
|
+
exports.isRegExpString = isRegExpString;
|
|
2605
|
+
}));
|
|
2606
|
+
// ../../node_modules/.pnpm/@textlint+regexp-string-matcher@2.0.3/node_modules/@textlint/regexp-string-matcher/lib/regexp-string-matcher.js
|
|
2607
|
+
var require_regexp_string_matcher = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2608
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2609
|
+
exports.matchPatterns = exports.createRegExp = void 0;
|
|
2610
|
+
var regexp_parse_1 = require_regexp_parse();
|
|
2611
|
+
var DEFAULT_FLAGS = "ug";
|
|
2612
|
+
/**
|
|
2613
|
+
* Escape RegExp special characters.
|
|
2614
|
+
* Same as escape-string-regexp@4
|
|
2615
|
+
* https://github.com/sindresorhus/escape-string-regexp/blob/v4.0.0/index.js
|
|
2616
|
+
* TODO: Replace with RegExp.escape when supported Node.js versions are >= 24
|
|
2617
|
+
*/
|
|
2618
|
+
var escapeStringRegexp = function(string) {
|
|
2619
|
+
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
2620
|
+
};
|
|
2621
|
+
var defaultFlags = function(flagsString) {
|
|
2622
|
+
if (flagsString.length === 0) return DEFAULT_FLAGS;
|
|
2623
|
+
return Array.from(new Set((flagsString + DEFAULT_FLAGS).split(""))).join("");
|
|
2624
|
+
};
|
|
2625
|
+
var createRegExp = function(patternString, defaultFlag) {
|
|
2626
|
+
if (defaultFlag === void 0) defaultFlag = DEFAULT_FLAGS;
|
|
2627
|
+
if (patternString.length === 0) throw new Error("Empty string can not handled");
|
|
2628
|
+
if ((0, regexp_parse_1.isRegExpString)(patternString)) {
|
|
2629
|
+
var regExpStructure = (0, regexp_parse_1.parseRegExpString)(patternString);
|
|
2630
|
+
if (regExpStructure) return new RegExp(regExpStructure.source, defaultFlags(regExpStructure.flagString));
|
|
2631
|
+
throw new Error("\"".concat(patternString, "\" can not parse as RegExp."));
|
|
2632
|
+
} else return new RegExp(escapeStringRegexp(patternString), defaultFlag);
|
|
2633
|
+
};
|
|
2634
|
+
exports.createRegExp = createRegExp;
|
|
2635
|
+
var isEqualMatchPatternResult = function(a, b) {
|
|
2636
|
+
return a.startIndex === b.startIndex && a.endIndex === b.endIndex && a.match === b.match;
|
|
2637
|
+
};
|
|
2638
|
+
/**
|
|
2639
|
+
* Match regExpLikeStrings and return matchPatternResults
|
|
2640
|
+
* @param text target text
|
|
2641
|
+
* @param regExpLikeStrings an array of pattern string
|
|
2642
|
+
*/
|
|
2643
|
+
var matchPatterns = function(text, regExpLikeStrings) {
|
|
2644
|
+
var matchPatternResults = [];
|
|
2645
|
+
regExpLikeStrings.map(function(patternString) {
|
|
2646
|
+
return (0, exports.createRegExp)(patternString);
|
|
2647
|
+
}).forEach(function(regExp) {
|
|
2648
|
+
var results = text.matchAll(regExp);
|
|
2649
|
+
Array.from(results).forEach(function(result) {
|
|
2650
|
+
if (result.index === void 0) return;
|
|
2651
|
+
var match = result[0];
|
|
2652
|
+
var index = result.index;
|
|
2653
|
+
matchPatternResults.push({
|
|
2654
|
+
match,
|
|
2655
|
+
captures: result.slice(1),
|
|
2656
|
+
startIndex: index,
|
|
2657
|
+
endIndex: index + match.length
|
|
2658
|
+
});
|
|
2659
|
+
});
|
|
2660
|
+
});
|
|
2661
|
+
return matchPatternResults.filter(function(result, index) {
|
|
2662
|
+
return matchPatternResults.findIndex(function(other) {
|
|
2663
|
+
return isEqualMatchPatternResult(result, other);
|
|
2664
|
+
}) === index;
|
|
2665
|
+
}).sort(function(a, b) {
|
|
2666
|
+
if (a.startIndex !== b.startIndex) return a.startIndex - b.startIndex;
|
|
2667
|
+
return a.endIndex - b.endIndex;
|
|
2668
|
+
});
|
|
2669
|
+
};
|
|
2670
|
+
exports.matchPatterns = matchPatterns;
|
|
2671
|
+
}));
|
|
2672
|
+
// ../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/constants.js
|
|
2673
|
+
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2674
|
+
const WIN_SLASH = "\\\\/";
|
|
2675
|
+
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
2676
|
+
const DEFAULT_MAX_EXTGLOB_RECURSION = 0;
|
|
2677
|
+
/**
|
|
2678
|
+
* Posix glob regex
|
|
2679
|
+
*/
|
|
2680
|
+
const DOT_LITERAL = "\\.";
|
|
2681
|
+
const PLUS_LITERAL = "\\+";
|
|
2682
|
+
const QMARK_LITERAL = "\\?";
|
|
2683
|
+
const SLASH_LITERAL = "\\/";
|
|
2684
|
+
const ONE_CHAR = "(?=.)";
|
|
2685
|
+
const QMARK = "[^/]";
|
|
2686
|
+
const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
|
2687
|
+
const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
|
2688
|
+
const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
|
2689
|
+
const POSIX_CHARS = {
|
|
2690
|
+
DOT_LITERAL,
|
|
2691
|
+
PLUS_LITERAL,
|
|
2692
|
+
QMARK_LITERAL,
|
|
2693
|
+
SLASH_LITERAL,
|
|
2694
|
+
ONE_CHAR,
|
|
2695
|
+
QMARK,
|
|
2696
|
+
END_ANCHOR,
|
|
2697
|
+
DOTS_SLASH,
|
|
2698
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
2699
|
+
NO_DOTS: `(?!${START_ANCHOR}${DOTS_SLASH})`,
|
|
2700
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`,
|
|
2701
|
+
NO_DOTS_SLASH: `(?!${DOTS_SLASH})`,
|
|
2702
|
+
QMARK_NO_DOT: `[^.${SLASH_LITERAL}]`,
|
|
2703
|
+
STAR: `${QMARK}*?`,
|
|
2704
|
+
START_ANCHOR,
|
|
2705
|
+
SEP: "/"
|
|
2706
|
+
};
|
|
2707
|
+
/**
|
|
2708
|
+
* Windows glob regex
|
|
2709
|
+
*/
|
|
2710
|
+
const WINDOWS_CHARS = {
|
|
2711
|
+
...POSIX_CHARS,
|
|
2712
|
+
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
|
2713
|
+
QMARK: WIN_NO_SLASH,
|
|
2714
|
+
STAR: `${WIN_NO_SLASH}*?`,
|
|
2715
|
+
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
|
2716
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
2717
|
+
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
2718
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
|
2719
|
+
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
2720
|
+
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
2721
|
+
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
2722
|
+
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
|
|
2723
|
+
SEP: "\\"
|
|
2724
|
+
};
|
|
2725
|
+
module.exports = {
|
|
2726
|
+
DEFAULT_MAX_EXTGLOB_RECURSION,
|
|
2727
|
+
MAX_LENGTH: 65536,
|
|
2728
|
+
POSIX_REGEX_SOURCE: {
|
|
2729
|
+
__proto__: null,
|
|
2730
|
+
alnum: "a-zA-Z0-9",
|
|
2731
|
+
alpha: "a-zA-Z",
|
|
2732
|
+
ascii: "\\x00-\\x7F",
|
|
2733
|
+
blank: " \\t",
|
|
2734
|
+
cntrl: "\\x00-\\x1F\\x7F",
|
|
2735
|
+
digit: "0-9",
|
|
2736
|
+
graph: "\\x21-\\x7E",
|
|
2737
|
+
lower: "a-z",
|
|
2738
|
+
print: "\\x20-\\x7E ",
|
|
2739
|
+
punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
|
|
2740
|
+
space: " \\t\\r\\n\\v\\f",
|
|
2741
|
+
upper: "A-Z",
|
|
2742
|
+
word: "A-Za-z0-9_",
|
|
2743
|
+
xdigit: "A-Fa-f0-9"
|
|
2744
|
+
},
|
|
2745
|
+
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
2746
|
+
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
2747
|
+
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
2748
|
+
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
2749
|
+
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
2750
|
+
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
2751
|
+
REPLACEMENTS: {
|
|
2752
|
+
__proto__: null,
|
|
2753
|
+
"***": "*",
|
|
2754
|
+
"**/**": "**",
|
|
2755
|
+
"**/**/**": "**"
|
|
2756
|
+
},
|
|
2757
|
+
CHAR_0: 48,
|
|
2758
|
+
CHAR_9: 57,
|
|
2759
|
+
CHAR_UPPERCASE_A: 65,
|
|
2760
|
+
CHAR_LOWERCASE_A: 97,
|
|
2761
|
+
CHAR_UPPERCASE_Z: 90,
|
|
2762
|
+
CHAR_LOWERCASE_Z: 122,
|
|
2763
|
+
CHAR_LEFT_PARENTHESES: 40,
|
|
2764
|
+
CHAR_RIGHT_PARENTHESES: 41,
|
|
2765
|
+
CHAR_ASTERISK: 42,
|
|
2766
|
+
CHAR_AMPERSAND: 38,
|
|
2767
|
+
CHAR_AT: 64,
|
|
2768
|
+
CHAR_BACKWARD_SLASH: 92,
|
|
2769
|
+
CHAR_CARRIAGE_RETURN: 13,
|
|
2770
|
+
CHAR_CIRCUMFLEX_ACCENT: 94,
|
|
2771
|
+
CHAR_COLON: 58,
|
|
2772
|
+
CHAR_COMMA: 44,
|
|
2773
|
+
CHAR_DOT: 46,
|
|
2774
|
+
CHAR_DOUBLE_QUOTE: 34,
|
|
2775
|
+
CHAR_EQUAL: 61,
|
|
2776
|
+
CHAR_EXCLAMATION_MARK: 33,
|
|
2777
|
+
CHAR_FORM_FEED: 12,
|
|
2778
|
+
CHAR_FORWARD_SLASH: 47,
|
|
2779
|
+
CHAR_GRAVE_ACCENT: 96,
|
|
2780
|
+
CHAR_HASH: 35,
|
|
2781
|
+
CHAR_HYPHEN_MINUS: 45,
|
|
2782
|
+
CHAR_LEFT_ANGLE_BRACKET: 60,
|
|
2783
|
+
CHAR_LEFT_CURLY_BRACE: 123,
|
|
2784
|
+
CHAR_LEFT_SQUARE_BRACKET: 91,
|
|
2785
|
+
CHAR_LINE_FEED: 10,
|
|
2786
|
+
CHAR_NO_BREAK_SPACE: 160,
|
|
2787
|
+
CHAR_PERCENT: 37,
|
|
2788
|
+
CHAR_PLUS: 43,
|
|
2789
|
+
CHAR_QUESTION_MARK: 63,
|
|
2790
|
+
CHAR_RIGHT_ANGLE_BRACKET: 62,
|
|
2791
|
+
CHAR_RIGHT_CURLY_BRACE: 125,
|
|
2792
|
+
CHAR_RIGHT_SQUARE_BRACKET: 93,
|
|
2793
|
+
CHAR_SEMICOLON: 59,
|
|
2794
|
+
CHAR_SINGLE_QUOTE: 39,
|
|
2795
|
+
CHAR_SPACE: 32,
|
|
2796
|
+
CHAR_TAB: 9,
|
|
2797
|
+
CHAR_UNDERSCORE: 95,
|
|
2798
|
+
CHAR_VERTICAL_LINE: 124,
|
|
2799
|
+
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
2800
|
+
/**
|
|
2801
|
+
* Create EXTGLOB_CHARS
|
|
2802
|
+
*/
|
|
2803
|
+
extglobChars(chars) {
|
|
2804
|
+
return {
|
|
2805
|
+
"!": {
|
|
2806
|
+
type: "negate",
|
|
2807
|
+
open: "(?:(?!(?:",
|
|
2808
|
+
close: `))${chars.STAR})`
|
|
2809
|
+
},
|
|
2810
|
+
"?": {
|
|
2811
|
+
type: "qmark",
|
|
2812
|
+
open: "(?:",
|
|
2813
|
+
close: ")?"
|
|
2814
|
+
},
|
|
2815
|
+
"+": {
|
|
2816
|
+
type: "plus",
|
|
2817
|
+
open: "(?:",
|
|
2818
|
+
close: ")+"
|
|
2819
|
+
},
|
|
2820
|
+
"*": {
|
|
2821
|
+
type: "star",
|
|
2822
|
+
open: "(?:",
|
|
2823
|
+
close: ")*"
|
|
2824
|
+
},
|
|
2825
|
+
"@": {
|
|
2826
|
+
type: "at",
|
|
2827
|
+
open: "(?:",
|
|
2828
|
+
close: ")"
|
|
2829
|
+
}
|
|
2830
|
+
};
|
|
2831
|
+
},
|
|
2832
|
+
/**
|
|
2833
|
+
* Create GLOB_CHARS
|
|
2834
|
+
*/
|
|
2835
|
+
globChars(win32) {
|
|
2836
|
+
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
|
2837
|
+
}
|
|
2838
|
+
};
|
|
2839
|
+
}));
|
|
2840
|
+
// ../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/utils.js
|
|
2841
|
+
var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2842
|
+
const { REGEX_BACKSLASH, REGEX_REMOVE_BACKSLASH, REGEX_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_GLOBAL } = require_constants();
|
|
2843
|
+
exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
2844
|
+
exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
|
|
2845
|
+
exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
|
|
2846
|
+
exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
|
|
2847
|
+
exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
|
|
2848
|
+
exports.isWindows = () => {
|
|
2849
|
+
if (typeof navigator !== "undefined" && navigator.platform) {
|
|
2850
|
+
const platform = navigator.platform.toLowerCase();
|
|
2851
|
+
return platform === "win32" || platform === "windows";
|
|
2852
|
+
}
|
|
2853
|
+
if (typeof process !== "undefined" && process.platform) return process.platform === "win32";
|
|
2854
|
+
return false;
|
|
2855
|
+
};
|
|
2856
|
+
exports.removeBackslashes = (str) => {
|
|
2857
|
+
return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
|
|
2858
|
+
return match === "\\" ? "" : match;
|
|
2859
|
+
});
|
|
2860
|
+
};
|
|
2861
|
+
exports.escapeLast = (input, char, lastIdx) => {
|
|
2862
|
+
const idx = input.lastIndexOf(char, lastIdx);
|
|
2863
|
+
if (idx === -1) return input;
|
|
2864
|
+
if (input[idx - 1] === "\\") return exports.escapeLast(input, char, idx - 1);
|
|
2865
|
+
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
|
2866
|
+
};
|
|
2867
|
+
exports.removePrefix = (input, state = {}) => {
|
|
2868
|
+
let output = input;
|
|
2869
|
+
if (output.startsWith("./")) {
|
|
2870
|
+
output = output.slice(2);
|
|
2871
|
+
state.prefix = "./";
|
|
2872
|
+
}
|
|
2873
|
+
return output;
|
|
2874
|
+
};
|
|
2875
|
+
exports.wrapOutput = (input, state = {}, options = {}) => {
|
|
2876
|
+
let output = `${options.contains ? "" : "^"}(?:${input})${options.contains ? "" : "$"}`;
|
|
2877
|
+
if (state.negated === true) output = `(?:^(?!${output}).*$)`;
|
|
2878
|
+
return output;
|
|
2879
|
+
};
|
|
2880
|
+
exports.basename = (path, { windows } = {}) => {
|
|
2881
|
+
const segs = path.split(windows ? /[\\/]/ : "/");
|
|
2882
|
+
const last = segs[segs.length - 1];
|
|
2883
|
+
if (last === "") return segs[segs.length - 2];
|
|
2884
|
+
return last;
|
|
2885
|
+
};
|
|
2886
|
+
}));
|
|
2887
|
+
// ../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/scan.js
|
|
2888
|
+
var require_scan = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2889
|
+
const utils = require_utils();
|
|
2890
|
+
const { CHAR_ASTERISK, CHAR_AT, CHAR_BACKWARD_SLASH, CHAR_COMMA, CHAR_DOT, CHAR_EXCLAMATION_MARK, CHAR_FORWARD_SLASH, CHAR_LEFT_CURLY_BRACE, CHAR_LEFT_PARENTHESES, CHAR_LEFT_SQUARE_BRACKET, CHAR_PLUS, CHAR_QUESTION_MARK, CHAR_RIGHT_CURLY_BRACE, CHAR_RIGHT_PARENTHESES, CHAR_RIGHT_SQUARE_BRACKET } = require_constants();
|
|
2891
|
+
const isPathSeparator = (code) => {
|
|
2892
|
+
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
2893
|
+
};
|
|
2894
|
+
const depth = (token) => {
|
|
2895
|
+
if (token.isPrefix !== true) token.depth = token.isGlobstar ? Infinity : 1;
|
|
2896
|
+
};
|
|
2897
|
+
/**
|
|
2898
|
+
* Quickly scans a glob pattern and returns an object with a handful of
|
|
2899
|
+
* useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
|
|
2900
|
+
* `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
|
|
2901
|
+
* with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
|
|
2902
|
+
*
|
|
2903
|
+
* ```js
|
|
2904
|
+
* const pm = require('picomatch');
|
|
2905
|
+
* console.log(pm.scan('foo/bar/*.js'));
|
|
2906
|
+
* { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
|
|
2907
|
+
* ```
|
|
2908
|
+
* @param {String} `str`
|
|
2909
|
+
* @param {Object} `options`
|
|
2910
|
+
* @return {Object} Returns an object with tokens and regex source string.
|
|
2911
|
+
* @api public
|
|
2912
|
+
*/
|
|
2913
|
+
const scan = (input, options) => {
|
|
2914
|
+
const opts = options || {};
|
|
2915
|
+
const length = input.length - 1;
|
|
2916
|
+
const scanToEnd = opts.parts === true || opts.tokens === true || opts.scanToEnd === true;
|
|
2917
|
+
const slashes = [];
|
|
2918
|
+
const tokens = [];
|
|
2919
|
+
const parts = [];
|
|
2920
|
+
let str = input;
|
|
2921
|
+
let index = -1;
|
|
2922
|
+
let start = 0;
|
|
2923
|
+
let lastIndex = 0;
|
|
2924
|
+
let isBrace = false;
|
|
2925
|
+
let isBracket = false;
|
|
2926
|
+
let isGlob = false;
|
|
2927
|
+
let isExtglob = false;
|
|
2928
|
+
let isGlobstar = false;
|
|
2929
|
+
let braceEscaped = false;
|
|
2930
|
+
let backslashes = false;
|
|
2931
|
+
let negated = false;
|
|
2932
|
+
let negatedExtglob = false;
|
|
2933
|
+
let finished = false;
|
|
2934
|
+
let braces = 0;
|
|
2935
|
+
let prev;
|
|
2936
|
+
let code;
|
|
2937
|
+
let token = {
|
|
2938
|
+
value: "",
|
|
2939
|
+
depth: 0,
|
|
2940
|
+
isGlob: false
|
|
2941
|
+
};
|
|
2942
|
+
const eos = () => index >= length;
|
|
2943
|
+
const peek = () => str.charCodeAt(index + 1);
|
|
2944
|
+
const advance = () => {
|
|
2945
|
+
prev = code;
|
|
2946
|
+
return str.charCodeAt(++index);
|
|
2947
|
+
};
|
|
2948
|
+
while (index < length) {
|
|
2949
|
+
code = advance();
|
|
2950
|
+
let next;
|
|
2951
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
2952
|
+
backslashes = token.backslashes = true;
|
|
2953
|
+
code = advance();
|
|
2954
|
+
if (code === CHAR_LEFT_CURLY_BRACE) braceEscaped = true;
|
|
2955
|
+
continue;
|
|
2956
|
+
}
|
|
2957
|
+
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
2958
|
+
braces++;
|
|
2959
|
+
while (eos() !== true && (code = advance())) {
|
|
2960
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
2961
|
+
backslashes = token.backslashes = true;
|
|
2962
|
+
advance();
|
|
2963
|
+
continue;
|
|
2964
|
+
}
|
|
2965
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
2966
|
+
braces++;
|
|
2967
|
+
continue;
|
|
2968
|
+
}
|
|
2969
|
+
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
|
2970
|
+
isBrace = token.isBrace = true;
|
|
2971
|
+
isGlob = token.isGlob = true;
|
|
2972
|
+
finished = true;
|
|
2973
|
+
if (scanToEnd === true) continue;
|
|
2974
|
+
break;
|
|
2975
|
+
}
|
|
2976
|
+
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
2977
|
+
isBrace = token.isBrace = true;
|
|
2978
|
+
isGlob = token.isGlob = true;
|
|
2979
|
+
finished = true;
|
|
2980
|
+
if (scanToEnd === true) continue;
|
|
2981
|
+
break;
|
|
2982
|
+
}
|
|
2983
|
+
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
2984
|
+
braces--;
|
|
2985
|
+
if (braces === 0) {
|
|
2986
|
+
braceEscaped = false;
|
|
2987
|
+
isBrace = token.isBrace = true;
|
|
2988
|
+
finished = true;
|
|
2989
|
+
break;
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
if (scanToEnd === true) continue;
|
|
2994
|
+
break;
|
|
2995
|
+
}
|
|
2996
|
+
if (code === CHAR_FORWARD_SLASH) {
|
|
2997
|
+
slashes.push(index);
|
|
2998
|
+
tokens.push(token);
|
|
2999
|
+
token = {
|
|
3000
|
+
value: "",
|
|
3001
|
+
depth: 0,
|
|
3002
|
+
isGlob: false
|
|
3003
|
+
};
|
|
3004
|
+
if (finished === true) continue;
|
|
3005
|
+
if (prev === CHAR_DOT && index === start + 1) {
|
|
3006
|
+
start += 2;
|
|
3007
|
+
continue;
|
|
3008
|
+
}
|
|
3009
|
+
lastIndex = index + 1;
|
|
3010
|
+
continue;
|
|
3011
|
+
}
|
|
3012
|
+
if (opts.noext !== true) {
|
|
3013
|
+
if ((code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK) === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
3014
|
+
isGlob = token.isGlob = true;
|
|
3015
|
+
isExtglob = token.isExtglob = true;
|
|
3016
|
+
finished = true;
|
|
3017
|
+
if (code === CHAR_EXCLAMATION_MARK && index === start) negatedExtglob = true;
|
|
3018
|
+
if (scanToEnd === true) {
|
|
3019
|
+
let parens = 0;
|
|
3020
|
+
while (eos() !== true && (code = advance())) {
|
|
3021
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
3022
|
+
backslashes = token.backslashes = true;
|
|
3023
|
+
advance();
|
|
3024
|
+
continue;
|
|
3025
|
+
}
|
|
3026
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
3027
|
+
parens++;
|
|
3028
|
+
continue;
|
|
3029
|
+
}
|
|
3030
|
+
if (code === CHAR_RIGHT_PARENTHESES && --parens === 0) {
|
|
3031
|
+
finished = true;
|
|
3032
|
+
break;
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
continue;
|
|
3036
|
+
}
|
|
3037
|
+
break;
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
if (code === CHAR_ASTERISK) {
|
|
3041
|
+
if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
|
|
3042
|
+
isGlob = token.isGlob = true;
|
|
3043
|
+
finished = true;
|
|
3044
|
+
if (scanToEnd === true) continue;
|
|
3045
|
+
break;
|
|
3046
|
+
}
|
|
3047
|
+
if (code === CHAR_QUESTION_MARK) {
|
|
3048
|
+
isGlob = token.isGlob = true;
|
|
3049
|
+
finished = true;
|
|
3050
|
+
if (scanToEnd === true) continue;
|
|
3051
|
+
break;
|
|
3052
|
+
}
|
|
3053
|
+
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
3054
|
+
while (eos() !== true && (next = advance())) {
|
|
3055
|
+
if (next === CHAR_BACKWARD_SLASH) {
|
|
3056
|
+
backslashes = token.backslashes = true;
|
|
3057
|
+
advance();
|
|
3058
|
+
continue;
|
|
3059
|
+
}
|
|
3060
|
+
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
3061
|
+
isBracket = token.isBracket = true;
|
|
3062
|
+
isGlob = token.isGlob = true;
|
|
3063
|
+
finished = true;
|
|
3064
|
+
break;
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
if (scanToEnd === true) continue;
|
|
3068
|
+
break;
|
|
3069
|
+
}
|
|
3070
|
+
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
3071
|
+
negated = token.negated = true;
|
|
3072
|
+
start++;
|
|
3073
|
+
continue;
|
|
3074
|
+
}
|
|
3075
|
+
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
3076
|
+
isGlob = token.isGlob = true;
|
|
3077
|
+
if (scanToEnd === true) {
|
|
3078
|
+
let parens = 1;
|
|
3079
|
+
while (eos() !== true && (code = advance())) {
|
|
3080
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
3081
|
+
backslashes = token.backslashes = true;
|
|
3082
|
+
advance();
|
|
3083
|
+
continue;
|
|
3084
|
+
}
|
|
3085
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
3086
|
+
parens++;
|
|
3087
|
+
continue;
|
|
3088
|
+
}
|
|
3089
|
+
if (code === CHAR_RIGHT_PARENTHESES && --parens === 0) {
|
|
3090
|
+
finished = true;
|
|
3091
|
+
break;
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
continue;
|
|
3095
|
+
}
|
|
3096
|
+
break;
|
|
3097
|
+
}
|
|
3098
|
+
if (isGlob === true) {
|
|
3099
|
+
finished = true;
|
|
3100
|
+
if (scanToEnd === true) continue;
|
|
3101
|
+
break;
|
|
3102
|
+
}
|
|
3103
|
+
}
|
|
3104
|
+
if (opts.noext === true) {
|
|
3105
|
+
isExtglob = false;
|
|
3106
|
+
isGlob = false;
|
|
3107
|
+
}
|
|
3108
|
+
let base = str;
|
|
3109
|
+
let prefix = "";
|
|
3110
|
+
let glob = "";
|
|
3111
|
+
if (start > 0) {
|
|
3112
|
+
prefix = str.slice(0, start);
|
|
3113
|
+
str = str.slice(start);
|
|
3114
|
+
lastIndex -= start;
|
|
3115
|
+
}
|
|
3116
|
+
if (base && isGlob === true && lastIndex > 0) {
|
|
3117
|
+
base = str.slice(0, lastIndex);
|
|
3118
|
+
glob = str.slice(lastIndex);
|
|
3119
|
+
} else if (isGlob === true) {
|
|
3120
|
+
base = "";
|
|
3121
|
+
glob = str;
|
|
3122
|
+
} else base = str;
|
|
3123
|
+
if (base && base !== "" && base !== "/" && base !== str) {
|
|
3124
|
+
if (isPathSeparator(base.charCodeAt(base.length - 1))) base = base.slice(0, -1);
|
|
3125
|
+
}
|
|
3126
|
+
if (opts.unescape === true) {
|
|
3127
|
+
if (glob) glob = utils.removeBackslashes(glob);
|
|
3128
|
+
if (base && backslashes === true) base = utils.removeBackslashes(base);
|
|
3129
|
+
}
|
|
3130
|
+
const state = {
|
|
3131
|
+
prefix,
|
|
3132
|
+
input,
|
|
3133
|
+
start,
|
|
3134
|
+
base,
|
|
3135
|
+
glob,
|
|
3136
|
+
isBrace,
|
|
3137
|
+
isBracket,
|
|
3138
|
+
isGlob,
|
|
3139
|
+
isExtglob,
|
|
3140
|
+
isGlobstar,
|
|
3141
|
+
negated,
|
|
3142
|
+
negatedExtglob
|
|
3143
|
+
};
|
|
3144
|
+
if (opts.tokens === true) {
|
|
3145
|
+
state.maxDepth = 0;
|
|
3146
|
+
if (!isPathSeparator(code)) tokens.push(token);
|
|
3147
|
+
state.tokens = tokens;
|
|
3148
|
+
}
|
|
3149
|
+
if (opts.parts === true || opts.tokens === true) {
|
|
3150
|
+
let prevIndex;
|
|
3151
|
+
for (let idx = 0; idx < slashes.length; idx++) {
|
|
3152
|
+
const n = prevIndex !== void 0 ? prevIndex + 1 : start;
|
|
3153
|
+
const i = slashes[idx];
|
|
3154
|
+
const value = input.slice(n, i);
|
|
3155
|
+
if (opts.tokens) {
|
|
3156
|
+
if (idx === 0 && start !== 0) {
|
|
3157
|
+
tokens[idx].isPrefix = true;
|
|
3158
|
+
tokens[idx].value = prefix;
|
|
3159
|
+
} else tokens[idx].value = value;
|
|
3160
|
+
depth(tokens[idx]);
|
|
3161
|
+
state.maxDepth += tokens[idx].depth;
|
|
3162
|
+
}
|
|
3163
|
+
if (i >= start) {
|
|
3164
|
+
parts.push(value);
|
|
3165
|
+
prevIndex = i;
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
const n = prevIndex !== void 0 ? prevIndex + 1 : start;
|
|
3169
|
+
const value = input.slice(n);
|
|
3170
|
+
parts.push(value);
|
|
3171
|
+
if (opts.tokens && prevIndex && prevIndex + 1 < input.length) {
|
|
3172
|
+
tokens[tokens.length - 1].value = value;
|
|
3173
|
+
depth(tokens[tokens.length - 1]);
|
|
3174
|
+
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
3175
|
+
}
|
|
3176
|
+
state.slashes = slashes;
|
|
3177
|
+
state.parts = parts;
|
|
3178
|
+
}
|
|
3179
|
+
return state;
|
|
3180
|
+
};
|
|
3181
|
+
module.exports = scan;
|
|
3182
|
+
}));
|
|
3183
|
+
// ../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/parse.js
|
|
3184
|
+
var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3185
|
+
const constants = require_constants();
|
|
3186
|
+
const utils = require_utils();
|
|
3187
|
+
/**
|
|
3188
|
+
* Constants
|
|
3189
|
+
*/
|
|
3190
|
+
const { MAX_LENGTH, POSIX_REGEX_SOURCE, REGEX_NON_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_BACKREF, REPLACEMENTS } = constants;
|
|
3191
|
+
/**
|
|
3192
|
+
* Helpers
|
|
3193
|
+
*/
|
|
3194
|
+
const expandRange = (args, options) => {
|
|
3195
|
+
if (typeof options.expandRange === "function") return options.expandRange(...args, options);
|
|
3196
|
+
args.sort();
|
|
3197
|
+
const value = `[${args.join("-")}]`;
|
|
3198
|
+
try {
|
|
3199
|
+
new RegExp(value);
|
|
3200
|
+
} catch (ex) {
|
|
3201
|
+
return args.map((v) => utils.escapeRegex(v)).join("..");
|
|
3202
|
+
}
|
|
3203
|
+
return value;
|
|
3204
|
+
};
|
|
3205
|
+
/**
|
|
3206
|
+
* Create the message for a syntax error
|
|
3207
|
+
*/
|
|
3208
|
+
const syntaxError = (type, char) => {
|
|
3209
|
+
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
3210
|
+
};
|
|
3211
|
+
const splitTopLevel = (input) => {
|
|
3212
|
+
const parts = [];
|
|
3213
|
+
let bracket = 0;
|
|
3214
|
+
let paren = 0;
|
|
3215
|
+
let quote = 0;
|
|
3216
|
+
let value = "";
|
|
3217
|
+
let escaped = false;
|
|
3218
|
+
for (const ch of input) {
|
|
3219
|
+
if (escaped === true) {
|
|
3220
|
+
value += ch;
|
|
3221
|
+
escaped = false;
|
|
3222
|
+
continue;
|
|
3223
|
+
}
|
|
3224
|
+
if (ch === "\\") {
|
|
3225
|
+
value += ch;
|
|
3226
|
+
escaped = true;
|
|
3227
|
+
continue;
|
|
3228
|
+
}
|
|
3229
|
+
if (ch === "\"") {
|
|
3230
|
+
quote = quote === 1 ? 0 : 1;
|
|
3231
|
+
value += ch;
|
|
3232
|
+
continue;
|
|
3233
|
+
}
|
|
3234
|
+
if (quote === 0) {
|
|
3235
|
+
if (ch === "[") bracket++;
|
|
3236
|
+
else if (ch === "]" && bracket > 0) bracket--;
|
|
3237
|
+
else if (bracket === 0) {
|
|
3238
|
+
if (ch === "(") paren++;
|
|
3239
|
+
else if (ch === ")" && paren > 0) paren--;
|
|
3240
|
+
else if (ch === "|" && paren === 0) {
|
|
3241
|
+
parts.push(value);
|
|
3242
|
+
value = "";
|
|
3243
|
+
continue;
|
|
3244
|
+
}
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
value += ch;
|
|
3248
|
+
}
|
|
3249
|
+
parts.push(value);
|
|
3250
|
+
return parts;
|
|
3251
|
+
};
|
|
3252
|
+
const isPlainBranch = (branch) => {
|
|
3253
|
+
let escaped = false;
|
|
3254
|
+
for (const ch of branch) {
|
|
3255
|
+
if (escaped === true) {
|
|
3256
|
+
escaped = false;
|
|
3257
|
+
continue;
|
|
3258
|
+
}
|
|
3259
|
+
if (ch === "\\") {
|
|
3260
|
+
escaped = true;
|
|
3261
|
+
continue;
|
|
3262
|
+
}
|
|
3263
|
+
if (/[?*+@!()[\]{}]/.test(ch)) return false;
|
|
3264
|
+
}
|
|
3265
|
+
return true;
|
|
3266
|
+
};
|
|
3267
|
+
const normalizeSimpleBranch = (branch) => {
|
|
3268
|
+
let value = branch.trim();
|
|
3269
|
+
let changed = true;
|
|
3270
|
+
while (changed === true) {
|
|
3271
|
+
changed = false;
|
|
3272
|
+
if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
|
|
3273
|
+
value = value.slice(2, -1);
|
|
3274
|
+
changed = true;
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
if (!isPlainBranch(value)) return;
|
|
3278
|
+
return value.replace(/\\(.)/g, "$1");
|
|
3279
|
+
};
|
|
3280
|
+
const hasRepeatedCharPrefixOverlap = (branches) => {
|
|
3281
|
+
const values = branches.map(normalizeSimpleBranch).filter(Boolean);
|
|
3282
|
+
for (let i = 0; i < values.length; i++) for (let j = i + 1; j < values.length; j++) {
|
|
3283
|
+
const a = values[i];
|
|
3284
|
+
const b = values[j];
|
|
3285
|
+
const char = a[0];
|
|
3286
|
+
if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) continue;
|
|
3287
|
+
if (a === b || a.startsWith(b) || b.startsWith(a)) return true;
|
|
3288
|
+
}
|
|
3289
|
+
return false;
|
|
3290
|
+
};
|
|
3291
|
+
const parseRepeatedExtglob = (pattern, requireEnd = true) => {
|
|
3292
|
+
if (pattern[0] !== "+" && pattern[0] !== "*" || pattern[1] !== "(") return;
|
|
3293
|
+
let bracket = 0;
|
|
3294
|
+
let paren = 0;
|
|
3295
|
+
let quote = 0;
|
|
3296
|
+
let escaped = false;
|
|
3297
|
+
for (let i = 1; i < pattern.length; i++) {
|
|
3298
|
+
const ch = pattern[i];
|
|
3299
|
+
if (escaped === true) {
|
|
3300
|
+
escaped = false;
|
|
3301
|
+
continue;
|
|
3302
|
+
}
|
|
3303
|
+
if (ch === "\\") {
|
|
3304
|
+
escaped = true;
|
|
3305
|
+
continue;
|
|
3306
|
+
}
|
|
3307
|
+
if (ch === "\"") {
|
|
3308
|
+
quote = quote === 1 ? 0 : 1;
|
|
3309
|
+
continue;
|
|
3310
|
+
}
|
|
3311
|
+
if (quote === 1) continue;
|
|
3312
|
+
if (ch === "[") {
|
|
3313
|
+
bracket++;
|
|
3314
|
+
continue;
|
|
3315
|
+
}
|
|
3316
|
+
if (ch === "]" && bracket > 0) {
|
|
3317
|
+
bracket--;
|
|
3318
|
+
continue;
|
|
3319
|
+
}
|
|
3320
|
+
if (bracket > 0) continue;
|
|
3321
|
+
if (ch === "(") {
|
|
3322
|
+
paren++;
|
|
3323
|
+
continue;
|
|
3324
|
+
}
|
|
3325
|
+
if (ch === ")") {
|
|
3326
|
+
paren--;
|
|
3327
|
+
if (paren === 0) {
|
|
3328
|
+
if (requireEnd === true && i !== pattern.length - 1) return;
|
|
3329
|
+
return {
|
|
3330
|
+
type: pattern[0],
|
|
3331
|
+
body: pattern.slice(2, i),
|
|
3332
|
+
end: i
|
|
3333
|
+
};
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
};
|
|
3338
|
+
const buildCharClassStar = (chars) => {
|
|
3339
|
+
return `${chars.length === 1 ? utils.escapeRegex(chars[0]) : `[${chars.map((ch) => utils.escapeRegex(ch)).join("")}]`}*`;
|
|
3340
|
+
};
|
|
3341
|
+
const getStarExtglobSequenceChars = (pattern) => {
|
|
3342
|
+
let index = 0;
|
|
3343
|
+
const chars = [];
|
|
3344
|
+
while (index < pattern.length) {
|
|
3345
|
+
const match = parseRepeatedExtglob(pattern.slice(index), false);
|
|
3346
|
+
if (!match || match.type !== "*") return;
|
|
3347
|
+
const branches = splitTopLevel(match.body).map((branch) => branch.trim());
|
|
3348
|
+
if (branches.length !== 1) return;
|
|
3349
|
+
const branch = normalizeSimpleBranch(branches[0]);
|
|
3350
|
+
if (!branch || branch.length !== 1) return;
|
|
3351
|
+
chars.push(branch);
|
|
3352
|
+
index += match.end + 1;
|
|
3353
|
+
}
|
|
3354
|
+
if (chars.length < 1) return;
|
|
3355
|
+
return chars;
|
|
3356
|
+
};
|
|
3357
|
+
const repeatedExtglobRecursion = (pattern) => {
|
|
3358
|
+
let depth = 0;
|
|
3359
|
+
let value = pattern.trim();
|
|
3360
|
+
let match = parseRepeatedExtglob(value);
|
|
3361
|
+
while (match) {
|
|
3362
|
+
depth++;
|
|
3363
|
+
value = match.body.trim();
|
|
3364
|
+
match = parseRepeatedExtglob(value);
|
|
3365
|
+
}
|
|
3366
|
+
return depth;
|
|
3367
|
+
};
|
|
3368
|
+
const analyzeRepeatedExtglob = (body, options) => {
|
|
3369
|
+
if (options.maxExtglobRecursion === false) return { risky: false };
|
|
3370
|
+
const max = typeof options.maxExtglobRecursion === "number" ? options.maxExtglobRecursion : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
|
|
3371
|
+
const branches = splitTopLevel(body).map((branch) => branch.trim());
|
|
3372
|
+
if (branches.length > 1) {
|
|
3373
|
+
if (branches.some((branch) => branch === "") || branches.some((branch) => /^[*?]+$/.test(branch)) || hasRepeatedCharPrefixOverlap(branches)) return { risky: true };
|
|
3374
|
+
}
|
|
3375
|
+
const safeChars = [];
|
|
3376
|
+
let sawStarSequence = false;
|
|
3377
|
+
let combinable = true;
|
|
3378
|
+
for (const branch of branches) {
|
|
3379
|
+
const chars = getStarExtglobSequenceChars(branch);
|
|
3380
|
+
if (chars) {
|
|
3381
|
+
sawStarSequence = true;
|
|
3382
|
+
safeChars.push(...chars);
|
|
3383
|
+
continue;
|
|
3384
|
+
}
|
|
3385
|
+
const literal = normalizeSimpleBranch(branch);
|
|
3386
|
+
if (literal && literal.length === 1) {
|
|
3387
|
+
safeChars.push(literal);
|
|
3388
|
+
continue;
|
|
3389
|
+
}
|
|
3390
|
+
combinable = false;
|
|
3391
|
+
if (repeatedExtglobRecursion(branch) > max) return { risky: true };
|
|
3392
|
+
}
|
|
3393
|
+
if (sawStarSequence) return combinable ? {
|
|
3394
|
+
risky: true,
|
|
3395
|
+
safeOutput: buildCharClassStar([...new Set(safeChars)])
|
|
3396
|
+
} : { risky: true };
|
|
3397
|
+
return { risky: false };
|
|
3398
|
+
};
|
|
3399
|
+
/**
|
|
3400
|
+
* Parse the given input string.
|
|
3401
|
+
* @param {String} input
|
|
3402
|
+
* @param {Object} options
|
|
3403
|
+
* @return {Object}
|
|
3404
|
+
*/
|
|
3405
|
+
const parse = (input, options) => {
|
|
3406
|
+
if (typeof input !== "string") throw new TypeError("Expected a string");
|
|
3407
|
+
input = REPLACEMENTS[input] || input;
|
|
3408
|
+
const opts = { ...options };
|
|
3409
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
3410
|
+
let len = input.length;
|
|
3411
|
+
if (len > max) throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
3412
|
+
const bos = {
|
|
3413
|
+
type: "bos",
|
|
3414
|
+
value: "",
|
|
3415
|
+
output: opts.prepend || ""
|
|
3416
|
+
};
|
|
3417
|
+
const tokens = [bos];
|
|
3418
|
+
const capture = opts.capture ? "" : "?:";
|
|
3419
|
+
const PLATFORM_CHARS = constants.globChars(opts.windows);
|
|
3420
|
+
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
|
|
3421
|
+
const { DOT_LITERAL, PLUS_LITERAL, SLASH_LITERAL, ONE_CHAR, DOTS_SLASH, NO_DOT, NO_DOT_SLASH, NO_DOTS_SLASH, QMARK, QMARK_NO_DOT, STAR, START_ANCHOR } = PLATFORM_CHARS;
|
|
3422
|
+
const globstar = (opts) => {
|
|
3423
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
3424
|
+
};
|
|
3425
|
+
const nodot = opts.dot ? "" : NO_DOT;
|
|
3426
|
+
const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
|
|
3427
|
+
let star = opts.bash === true ? globstar(opts) : STAR;
|
|
3428
|
+
if (opts.capture) star = `(${star})`;
|
|
3429
|
+
if (typeof opts.noext === "boolean") opts.noextglob = opts.noext;
|
|
3430
|
+
const state = {
|
|
3431
|
+
input,
|
|
3432
|
+
index: -1,
|
|
3433
|
+
start: 0,
|
|
3434
|
+
dot: opts.dot === true,
|
|
3435
|
+
consumed: "",
|
|
3436
|
+
output: "",
|
|
3437
|
+
prefix: "",
|
|
3438
|
+
backtrack: false,
|
|
3439
|
+
negated: false,
|
|
3440
|
+
brackets: 0,
|
|
3441
|
+
braces: 0,
|
|
3442
|
+
parens: 0,
|
|
3443
|
+
quotes: 0,
|
|
3444
|
+
globstar: false,
|
|
3445
|
+
tokens
|
|
3446
|
+
};
|
|
3447
|
+
input = utils.removePrefix(input, state);
|
|
3448
|
+
len = input.length;
|
|
3449
|
+
const extglobs = [];
|
|
3450
|
+
const braces = [];
|
|
3451
|
+
const stack = [];
|
|
3452
|
+
let prev = bos;
|
|
3453
|
+
let value;
|
|
3454
|
+
/**
|
|
3455
|
+
* Tokenizing helpers
|
|
3456
|
+
*/
|
|
3457
|
+
const eos = () => state.index === len - 1;
|
|
3458
|
+
const peek = state.peek = (n = 1) => input[state.index + n];
|
|
3459
|
+
const advance = state.advance = () => input[++state.index] || "";
|
|
3460
|
+
const remaining = () => input.slice(state.index + 1);
|
|
3461
|
+
const consume = (value = "", num = 0) => {
|
|
3462
|
+
state.consumed += value;
|
|
3463
|
+
state.index += num;
|
|
3464
|
+
};
|
|
3465
|
+
const append = (token) => {
|
|
3466
|
+
state.output += token.output != null ? token.output : token.value;
|
|
3467
|
+
consume(token.value);
|
|
3468
|
+
};
|
|
3469
|
+
const negate = () => {
|
|
3470
|
+
let count = 1;
|
|
3471
|
+
while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
|
|
3472
|
+
advance();
|
|
3473
|
+
state.start++;
|
|
3474
|
+
count++;
|
|
3475
|
+
}
|
|
3476
|
+
if (count % 2 === 0) return false;
|
|
3477
|
+
state.negated = true;
|
|
3478
|
+
state.start++;
|
|
3479
|
+
return true;
|
|
3480
|
+
};
|
|
3481
|
+
const increment = (type) => {
|
|
3482
|
+
state[type]++;
|
|
3483
|
+
stack.push(type);
|
|
3484
|
+
};
|
|
3485
|
+
const decrement = (type) => {
|
|
3486
|
+
state[type]--;
|
|
3487
|
+
stack.pop();
|
|
3488
|
+
};
|
|
3489
|
+
/**
|
|
3490
|
+
* Push tokens onto the tokens array. This helper speeds up
|
|
3491
|
+
* tokenizing by 1) helping us avoid backtracking as much as possible,
|
|
3492
|
+
* and 2) helping us avoid creating extra tokens when consecutive
|
|
3493
|
+
* characters are plain text. This improves performance and simplifies
|
|
3494
|
+
* lookbehinds.
|
|
3495
|
+
*/
|
|
3496
|
+
const push = (tok) => {
|
|
3497
|
+
if (prev.type === "globstar") {
|
|
3498
|
+
const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
|
|
3499
|
+
const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
|
|
3500
|
+
if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
|
|
3501
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
3502
|
+
prev.type = "star";
|
|
3503
|
+
prev.value = "*";
|
|
3504
|
+
prev.output = star;
|
|
3505
|
+
state.output += prev.output;
|
|
3506
|
+
}
|
|
3507
|
+
}
|
|
3508
|
+
if (extglobs.length && tok.type !== "paren") extglobs[extglobs.length - 1].inner += tok.value;
|
|
3509
|
+
if (tok.value || tok.output) append(tok);
|
|
3510
|
+
if (prev && prev.type === "text" && tok.type === "text") {
|
|
3511
|
+
prev.output = (prev.output || prev.value) + tok.value;
|
|
3512
|
+
prev.value += tok.value;
|
|
3513
|
+
return;
|
|
3514
|
+
}
|
|
3515
|
+
tok.prev = prev;
|
|
3516
|
+
tokens.push(tok);
|
|
3517
|
+
prev = tok;
|
|
3518
|
+
};
|
|
3519
|
+
const extglobOpen = (type, value) => {
|
|
3520
|
+
const token = {
|
|
3521
|
+
...EXTGLOB_CHARS[value],
|
|
3522
|
+
conditions: 1,
|
|
3523
|
+
inner: ""
|
|
3524
|
+
};
|
|
3525
|
+
token.prev = prev;
|
|
3526
|
+
token.parens = state.parens;
|
|
3527
|
+
token.output = state.output;
|
|
3528
|
+
token.startIndex = state.index;
|
|
3529
|
+
token.tokensIndex = tokens.length;
|
|
3530
|
+
const output = (opts.capture ? "(" : "") + token.open;
|
|
3531
|
+
increment("parens");
|
|
3532
|
+
push({
|
|
3533
|
+
type,
|
|
3534
|
+
value,
|
|
3535
|
+
output: state.output ? "" : ONE_CHAR
|
|
3536
|
+
});
|
|
3537
|
+
push({
|
|
3538
|
+
type: "paren",
|
|
3539
|
+
extglob: true,
|
|
3540
|
+
value: advance(),
|
|
3541
|
+
output
|
|
3542
|
+
});
|
|
3543
|
+
extglobs.push(token);
|
|
3544
|
+
};
|
|
3545
|
+
const extglobClose = (token) => {
|
|
3546
|
+
const literal = input.slice(token.startIndex, state.index + 1);
|
|
3547
|
+
const body = input.slice(token.startIndex + 2, state.index);
|
|
3548
|
+
const analysis = analyzeRepeatedExtglob(body, opts);
|
|
3549
|
+
if ((token.type === "plus" || token.type === "star") && analysis.risky) {
|
|
3550
|
+
const safeOutput = analysis.safeOutput ? (token.output ? "" : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput) : void 0;
|
|
3551
|
+
const open = tokens[token.tokensIndex];
|
|
3552
|
+
open.type = "text";
|
|
3553
|
+
open.value = literal;
|
|
3554
|
+
open.output = safeOutput || utils.escapeRegex(literal);
|
|
3555
|
+
for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
|
|
3556
|
+
tokens[i].value = "";
|
|
3557
|
+
tokens[i].output = "";
|
|
3558
|
+
delete tokens[i].suffix;
|
|
3559
|
+
}
|
|
3560
|
+
state.output = token.output + open.output;
|
|
3561
|
+
state.backtrack = true;
|
|
3562
|
+
push({
|
|
3563
|
+
type: "paren",
|
|
3564
|
+
extglob: true,
|
|
3565
|
+
value,
|
|
3566
|
+
output: ""
|
|
3567
|
+
});
|
|
3568
|
+
decrement("parens");
|
|
3569
|
+
return;
|
|
3570
|
+
}
|
|
3571
|
+
let output = token.close + (opts.capture ? ")" : "");
|
|
3572
|
+
let rest;
|
|
3573
|
+
if (token.type === "negate") {
|
|
3574
|
+
let extglobStar = star;
|
|
3575
|
+
if (token.inner && token.inner.length > 1 && token.inner.includes("/")) extglobStar = globstar(opts);
|
|
3576
|
+
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) output = token.close = `)$))${extglobStar}`;
|
|
3577
|
+
if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) output = token.close = `)${parse(rest, {
|
|
3578
|
+
...options,
|
|
3579
|
+
fastpaths: false
|
|
3580
|
+
}).output})${extglobStar})`;
|
|
3581
|
+
if (token.prev.type === "bos") state.negatedExtglob = true;
|
|
3582
|
+
}
|
|
3583
|
+
push({
|
|
3584
|
+
type: "paren",
|
|
3585
|
+
extglob: true,
|
|
3586
|
+
value,
|
|
3587
|
+
output
|
|
3588
|
+
});
|
|
3589
|
+
decrement("parens");
|
|
3590
|
+
};
|
|
3591
|
+
/**
|
|
3592
|
+
* Fast paths
|
|
3593
|
+
*/
|
|
3594
|
+
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
3595
|
+
let backslashes = false;
|
|
3596
|
+
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
|
3597
|
+
if (first === "\\") {
|
|
3598
|
+
backslashes = true;
|
|
3599
|
+
return m;
|
|
3600
|
+
}
|
|
3601
|
+
if (first === "?") {
|
|
3602
|
+
if (esc) return esc + first + (rest ? QMARK.repeat(rest.length) : "");
|
|
3603
|
+
if (index === 0) return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
|
|
3604
|
+
return QMARK.repeat(chars.length);
|
|
3605
|
+
}
|
|
3606
|
+
if (first === ".") return DOT_LITERAL.repeat(chars.length);
|
|
3607
|
+
if (first === "*") {
|
|
3608
|
+
if (esc) return esc + first + (rest ? star : "");
|
|
3609
|
+
return star;
|
|
3610
|
+
}
|
|
3611
|
+
return esc ? m : `\\${m}`;
|
|
3612
|
+
});
|
|
3613
|
+
if (backslashes === true) {
|
|
3614
|
+
if (opts.unescape === true) output = output.replace(/\\/g, "");
|
|
3615
|
+
else output = output.replace(/\\+/g, (m) => {
|
|
3616
|
+
return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
|
|
3617
|
+
});
|
|
3618
|
+
}
|
|
3619
|
+
if (output === input && opts.contains === true) {
|
|
3620
|
+
state.output = input;
|
|
3621
|
+
return state;
|
|
3622
|
+
}
|
|
3623
|
+
state.output = utils.wrapOutput(output, state, options);
|
|
3624
|
+
return state;
|
|
3625
|
+
}
|
|
3626
|
+
/**
|
|
3627
|
+
* Tokenize input until we reach end-of-string
|
|
3628
|
+
*/
|
|
3629
|
+
while (!eos()) {
|
|
3630
|
+
value = advance();
|
|
3631
|
+
if (value === "\0") continue;
|
|
3632
|
+
/**
|
|
3633
|
+
* Escaped characters
|
|
3634
|
+
*/
|
|
3635
|
+
if (value === "\\") {
|
|
3636
|
+
const next = peek();
|
|
3637
|
+
if (next === "/" && opts.bash !== true) continue;
|
|
3638
|
+
if (next === "." || next === ";") continue;
|
|
3639
|
+
if (!next) {
|
|
3640
|
+
value += "\\";
|
|
3641
|
+
push({
|
|
3642
|
+
type: "text",
|
|
3643
|
+
value
|
|
3644
|
+
});
|
|
3645
|
+
continue;
|
|
3646
|
+
}
|
|
3647
|
+
const match = /^\\+/.exec(remaining());
|
|
3648
|
+
let slashes = 0;
|
|
3649
|
+
if (match && match[0].length > 2) {
|
|
3650
|
+
slashes = match[0].length;
|
|
3651
|
+
state.index += slashes;
|
|
3652
|
+
if (slashes % 2 !== 0) value += "\\";
|
|
3653
|
+
}
|
|
3654
|
+
if (opts.unescape === true) value = advance();
|
|
3655
|
+
else value += advance();
|
|
3656
|
+
if (state.brackets === 0) {
|
|
3657
|
+
push({
|
|
3658
|
+
type: "text",
|
|
3659
|
+
value
|
|
3660
|
+
});
|
|
3661
|
+
continue;
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
/**
|
|
3665
|
+
* If we're inside a regex character class, continue
|
|
3666
|
+
* until we reach the closing bracket.
|
|
3667
|
+
*/
|
|
3668
|
+
if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
|
|
3669
|
+
if (opts.posix !== false && value === ":") {
|
|
3670
|
+
const inner = prev.value.slice(1);
|
|
3671
|
+
if (inner.includes("[")) {
|
|
3672
|
+
prev.posix = true;
|
|
3673
|
+
if (inner.includes(":")) {
|
|
3674
|
+
const idx = prev.value.lastIndexOf("[");
|
|
3675
|
+
const pre = prev.value.slice(0, idx);
|
|
3676
|
+
const rest = prev.value.slice(idx + 2);
|
|
3677
|
+
const posix = POSIX_REGEX_SOURCE[rest];
|
|
3678
|
+
if (posix) {
|
|
3679
|
+
prev.value = pre + posix;
|
|
3680
|
+
state.backtrack = true;
|
|
3681
|
+
advance();
|
|
3682
|
+
if (!bos.output && tokens.indexOf(prev) === 1) bos.output = ONE_CHAR;
|
|
3683
|
+
continue;
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
}
|
|
3687
|
+
}
|
|
3688
|
+
if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") value = `\\${value}`;
|
|
3689
|
+
if (value === "]" && (prev.value === "[" || prev.value === "[^")) value = `\\${value}`;
|
|
3690
|
+
if (opts.posix === true && value === "!" && prev.value === "[") value = "^";
|
|
3691
|
+
prev.value += value;
|
|
3692
|
+
append({ value });
|
|
3693
|
+
continue;
|
|
3694
|
+
}
|
|
3695
|
+
/**
|
|
3696
|
+
* If we're inside a quoted string, continue
|
|
3697
|
+
* until we reach the closing double quote.
|
|
3698
|
+
*/
|
|
3699
|
+
if (state.quotes === 1 && value !== "\"") {
|
|
3700
|
+
value = utils.escapeRegex(value);
|
|
3701
|
+
prev.value += value;
|
|
3702
|
+
append({ value });
|
|
3703
|
+
continue;
|
|
3704
|
+
}
|
|
3705
|
+
/**
|
|
3706
|
+
* Double quotes
|
|
3707
|
+
*/
|
|
3708
|
+
if (value === "\"") {
|
|
3709
|
+
state.quotes = state.quotes === 1 ? 0 : 1;
|
|
3710
|
+
if (opts.keepQuotes === true) push({
|
|
3711
|
+
type: "text",
|
|
3712
|
+
value
|
|
3713
|
+
});
|
|
3714
|
+
continue;
|
|
3715
|
+
}
|
|
3716
|
+
/**
|
|
3717
|
+
* Parentheses
|
|
3718
|
+
*/
|
|
3719
|
+
if (value === "(") {
|
|
3720
|
+
increment("parens");
|
|
3721
|
+
push({
|
|
3722
|
+
type: "paren",
|
|
3723
|
+
value
|
|
3724
|
+
});
|
|
3725
|
+
continue;
|
|
3726
|
+
}
|
|
3727
|
+
if (value === ")") {
|
|
3728
|
+
if (state.parens === 0 && opts.strictBrackets === true) throw new SyntaxError(syntaxError("opening", "("));
|
|
3729
|
+
const extglob = extglobs[extglobs.length - 1];
|
|
3730
|
+
if (extglob && state.parens === extglob.parens + 1) {
|
|
3731
|
+
extglobClose(extglobs.pop());
|
|
3732
|
+
continue;
|
|
3733
|
+
}
|
|
3734
|
+
push({
|
|
3735
|
+
type: "paren",
|
|
3736
|
+
value,
|
|
3737
|
+
output: state.parens ? ")" : "\\)"
|
|
3738
|
+
});
|
|
3739
|
+
decrement("parens");
|
|
3740
|
+
continue;
|
|
3741
|
+
}
|
|
3742
|
+
/**
|
|
3743
|
+
* Square brackets
|
|
3744
|
+
*/
|
|
3745
|
+
if (value === "[") {
|
|
3746
|
+
if (opts.nobracket === true || !remaining().includes("]")) {
|
|
3747
|
+
if (opts.nobracket !== true && opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
3748
|
+
value = `\\${value}`;
|
|
3749
|
+
} else increment("brackets");
|
|
3750
|
+
push({
|
|
3751
|
+
type: "bracket",
|
|
3752
|
+
value
|
|
3753
|
+
});
|
|
3754
|
+
continue;
|
|
3755
|
+
}
|
|
3756
|
+
if (value === "]") {
|
|
3757
|
+
if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
|
|
3758
|
+
push({
|
|
3759
|
+
type: "text",
|
|
3760
|
+
value,
|
|
3761
|
+
output: `\\${value}`
|
|
3762
|
+
});
|
|
3763
|
+
continue;
|
|
3764
|
+
}
|
|
3765
|
+
if (state.brackets === 0) {
|
|
3766
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("opening", "["));
|
|
3767
|
+
push({
|
|
3768
|
+
type: "text",
|
|
3769
|
+
value,
|
|
3770
|
+
output: `\\${value}`
|
|
3771
|
+
});
|
|
3772
|
+
continue;
|
|
3773
|
+
}
|
|
3774
|
+
decrement("brackets");
|
|
3775
|
+
const prevValue = prev.value.slice(1);
|
|
3776
|
+
if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) value = `/${value}`;
|
|
3777
|
+
prev.value += value;
|
|
3778
|
+
append({ value });
|
|
3779
|
+
if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) continue;
|
|
3780
|
+
const escaped = utils.escapeRegex(prev.value);
|
|
3781
|
+
state.output = state.output.slice(0, -prev.value.length);
|
|
3782
|
+
if (opts.literalBrackets === true) {
|
|
3783
|
+
state.output += escaped;
|
|
3784
|
+
prev.value = escaped;
|
|
3785
|
+
continue;
|
|
3786
|
+
}
|
|
3787
|
+
prev.value = `(${capture}${escaped}|${prev.value})`;
|
|
3788
|
+
state.output += prev.value;
|
|
3789
|
+
continue;
|
|
3790
|
+
}
|
|
3791
|
+
/**
|
|
3792
|
+
* Braces
|
|
3793
|
+
*/
|
|
3794
|
+
if (value === "{" && opts.nobrace !== true) {
|
|
3795
|
+
increment("braces");
|
|
3796
|
+
const open = {
|
|
3797
|
+
type: "brace",
|
|
3798
|
+
value,
|
|
3799
|
+
output: "(",
|
|
3800
|
+
outputIndex: state.output.length,
|
|
3801
|
+
tokensIndex: state.tokens.length
|
|
3802
|
+
};
|
|
3803
|
+
braces.push(open);
|
|
3804
|
+
push(open);
|
|
3805
|
+
continue;
|
|
3806
|
+
}
|
|
3807
|
+
if (value === "}") {
|
|
3808
|
+
const brace = braces[braces.length - 1];
|
|
3809
|
+
if (opts.nobrace === true || !brace) {
|
|
3810
|
+
push({
|
|
3811
|
+
type: "text",
|
|
3812
|
+
value,
|
|
3813
|
+
output: value
|
|
3814
|
+
});
|
|
3815
|
+
continue;
|
|
3816
|
+
}
|
|
3817
|
+
let output = ")";
|
|
3818
|
+
if (brace.dots === true) {
|
|
3819
|
+
const arr = tokens.slice();
|
|
3820
|
+
const range = [];
|
|
3821
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
3822
|
+
tokens.pop();
|
|
3823
|
+
if (arr[i].type === "brace") break;
|
|
3824
|
+
if (arr[i].type !== "dots") range.unshift(arr[i].value);
|
|
3825
|
+
}
|
|
3826
|
+
output = expandRange(range, opts);
|
|
3827
|
+
state.backtrack = true;
|
|
3828
|
+
}
|
|
3829
|
+
if (brace.comma !== true && brace.dots !== true) {
|
|
3830
|
+
const out = state.output.slice(0, brace.outputIndex);
|
|
3831
|
+
const toks = state.tokens.slice(brace.tokensIndex);
|
|
3832
|
+
brace.value = brace.output = "\\{";
|
|
3833
|
+
value = output = "\\}";
|
|
3834
|
+
state.output = out;
|
|
3835
|
+
for (const t of toks) state.output += t.output || t.value;
|
|
3836
|
+
}
|
|
3837
|
+
push({
|
|
3838
|
+
type: "brace",
|
|
3839
|
+
value,
|
|
3840
|
+
output
|
|
3841
|
+
});
|
|
3842
|
+
decrement("braces");
|
|
3843
|
+
braces.pop();
|
|
3844
|
+
continue;
|
|
3845
|
+
}
|
|
3846
|
+
/**
|
|
3847
|
+
* Pipes
|
|
3848
|
+
*/
|
|
3849
|
+
if (value === "|") {
|
|
3850
|
+
if (extglobs.length > 0) extglobs[extglobs.length - 1].conditions++;
|
|
3851
|
+
push({
|
|
3852
|
+
type: "text",
|
|
3853
|
+
value
|
|
3854
|
+
});
|
|
3855
|
+
continue;
|
|
3856
|
+
}
|
|
3857
|
+
/**
|
|
3858
|
+
* Commas
|
|
3859
|
+
*/
|
|
3860
|
+
if (value === ",") {
|
|
3861
|
+
let output = value;
|
|
3862
|
+
const brace = braces[braces.length - 1];
|
|
3863
|
+
if (brace && stack[stack.length - 1] === "braces") {
|
|
3864
|
+
brace.comma = true;
|
|
3865
|
+
output = "|";
|
|
3866
|
+
}
|
|
3867
|
+
push({
|
|
3868
|
+
type: "comma",
|
|
3869
|
+
value,
|
|
3870
|
+
output
|
|
3871
|
+
});
|
|
3872
|
+
continue;
|
|
3873
|
+
}
|
|
3874
|
+
/**
|
|
3875
|
+
* Slashes
|
|
3876
|
+
*/
|
|
3877
|
+
if (value === "/") {
|
|
3878
|
+
if (prev.type === "dot" && state.index === state.start + 1) {
|
|
3879
|
+
state.start = state.index + 1;
|
|
3880
|
+
state.consumed = "";
|
|
3881
|
+
state.output = "";
|
|
3882
|
+
tokens.pop();
|
|
3883
|
+
prev = bos;
|
|
3884
|
+
continue;
|
|
3885
|
+
}
|
|
3886
|
+
push({
|
|
3887
|
+
type: "slash",
|
|
3888
|
+
value,
|
|
3889
|
+
output: SLASH_LITERAL
|
|
3890
|
+
});
|
|
3891
|
+
continue;
|
|
3892
|
+
}
|
|
3893
|
+
/**
|
|
3894
|
+
* Dots
|
|
3895
|
+
*/
|
|
3896
|
+
if (value === ".") {
|
|
3897
|
+
if (state.braces > 0 && prev.type === "dot") {
|
|
3898
|
+
if (prev.value === ".") prev.output = DOT_LITERAL;
|
|
3899
|
+
const brace = braces[braces.length - 1];
|
|
3900
|
+
prev.type = "dots";
|
|
3901
|
+
prev.output += value;
|
|
3902
|
+
prev.value += value;
|
|
3903
|
+
brace.dots = true;
|
|
3904
|
+
continue;
|
|
3905
|
+
}
|
|
3906
|
+
if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
|
|
3907
|
+
push({
|
|
3908
|
+
type: "text",
|
|
3909
|
+
value,
|
|
3910
|
+
output: DOT_LITERAL
|
|
3911
|
+
});
|
|
3912
|
+
continue;
|
|
3913
|
+
}
|
|
3914
|
+
push({
|
|
3915
|
+
type: "dot",
|
|
3916
|
+
value,
|
|
3917
|
+
output: DOT_LITERAL
|
|
3918
|
+
});
|
|
3919
|
+
continue;
|
|
3920
|
+
}
|
|
3921
|
+
/**
|
|
3922
|
+
* Question marks
|
|
3923
|
+
*/
|
|
3924
|
+
if (value === "?") {
|
|
3925
|
+
if (!(prev && prev.value === "(") && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
3926
|
+
extglobOpen("qmark", value);
|
|
3927
|
+
continue;
|
|
3928
|
+
}
|
|
3929
|
+
if (prev && prev.type === "paren") {
|
|
3930
|
+
const next = peek();
|
|
3931
|
+
let output = value;
|
|
3932
|
+
if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) output = `\\${value}`;
|
|
3933
|
+
push({
|
|
3934
|
+
type: "text",
|
|
3935
|
+
value,
|
|
3936
|
+
output
|
|
3937
|
+
});
|
|
3938
|
+
continue;
|
|
3939
|
+
}
|
|
3940
|
+
if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
|
|
3941
|
+
push({
|
|
3942
|
+
type: "qmark",
|
|
3943
|
+
value,
|
|
3944
|
+
output: QMARK_NO_DOT
|
|
3945
|
+
});
|
|
3946
|
+
continue;
|
|
3947
|
+
}
|
|
3948
|
+
push({
|
|
3949
|
+
type: "qmark",
|
|
3950
|
+
value,
|
|
3951
|
+
output: QMARK
|
|
3952
|
+
});
|
|
3953
|
+
continue;
|
|
3954
|
+
}
|
|
3955
|
+
/**
|
|
3956
|
+
* Exclamation
|
|
3957
|
+
*/
|
|
3958
|
+
if (value === "!") {
|
|
3959
|
+
if (opts.noextglob !== true && peek() === "(") {
|
|
3960
|
+
if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
|
|
3961
|
+
extglobOpen("negate", value);
|
|
3962
|
+
continue;
|
|
3963
|
+
}
|
|
3964
|
+
}
|
|
3965
|
+
if (opts.nonegate !== true && state.index === 0) {
|
|
3966
|
+
negate();
|
|
3967
|
+
continue;
|
|
3968
|
+
}
|
|
3969
|
+
}
|
|
3970
|
+
/**
|
|
3971
|
+
* Plus
|
|
3972
|
+
*/
|
|
3973
|
+
if (value === "+") {
|
|
3974
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
3975
|
+
extglobOpen("plus", value);
|
|
3976
|
+
continue;
|
|
3977
|
+
}
|
|
3978
|
+
if (prev && prev.value === "(" || opts.regex === false) {
|
|
3979
|
+
push({
|
|
3980
|
+
type: "plus",
|
|
3981
|
+
value,
|
|
3982
|
+
output: PLUS_LITERAL
|
|
3983
|
+
});
|
|
3984
|
+
continue;
|
|
3985
|
+
}
|
|
3986
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
|
|
3987
|
+
push({
|
|
3988
|
+
type: "plus",
|
|
3989
|
+
value
|
|
3990
|
+
});
|
|
3991
|
+
continue;
|
|
3992
|
+
}
|
|
3993
|
+
push({
|
|
3994
|
+
type: "plus",
|
|
3995
|
+
value: PLUS_LITERAL
|
|
3996
|
+
});
|
|
3997
|
+
continue;
|
|
3998
|
+
}
|
|
3999
|
+
/**
|
|
4000
|
+
* Plain text
|
|
4001
|
+
*/
|
|
4002
|
+
if (value === "@") {
|
|
4003
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
4004
|
+
push({
|
|
4005
|
+
type: "at",
|
|
4006
|
+
extglob: true,
|
|
4007
|
+
value,
|
|
4008
|
+
output: ""
|
|
4009
|
+
});
|
|
4010
|
+
continue;
|
|
4011
|
+
}
|
|
4012
|
+
push({
|
|
4013
|
+
type: "text",
|
|
4014
|
+
value
|
|
4015
|
+
});
|
|
4016
|
+
continue;
|
|
4017
|
+
}
|
|
4018
|
+
/**
|
|
4019
|
+
* Plain text
|
|
4020
|
+
*/
|
|
4021
|
+
if (value !== "*") {
|
|
4022
|
+
if (value === "$" || value === "^") value = `\\${value}`;
|
|
4023
|
+
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
|
4024
|
+
if (match) {
|
|
4025
|
+
value += match[0];
|
|
4026
|
+
state.index += match[0].length;
|
|
4027
|
+
}
|
|
4028
|
+
push({
|
|
4029
|
+
type: "text",
|
|
4030
|
+
value
|
|
4031
|
+
});
|
|
4032
|
+
continue;
|
|
4033
|
+
}
|
|
4034
|
+
/**
|
|
4035
|
+
* Stars
|
|
4036
|
+
*/
|
|
4037
|
+
if (prev && (prev.type === "globstar" || prev.star === true)) {
|
|
4038
|
+
prev.type = "star";
|
|
4039
|
+
prev.star = true;
|
|
4040
|
+
prev.value += value;
|
|
4041
|
+
prev.output = star;
|
|
4042
|
+
state.backtrack = true;
|
|
4043
|
+
state.globstar = true;
|
|
4044
|
+
consume(value);
|
|
4045
|
+
continue;
|
|
4046
|
+
}
|
|
4047
|
+
let rest = remaining();
|
|
4048
|
+
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
4049
|
+
extglobOpen("star", value);
|
|
4050
|
+
continue;
|
|
4051
|
+
}
|
|
4052
|
+
if (prev.type === "star") {
|
|
4053
|
+
if (opts.noglobstar === true) {
|
|
4054
|
+
consume(value);
|
|
4055
|
+
continue;
|
|
4056
|
+
}
|
|
4057
|
+
const prior = prev.prev;
|
|
4058
|
+
const before = prior.prev;
|
|
4059
|
+
const isStart = prior.type === "slash" || prior.type === "bos";
|
|
4060
|
+
const afterStar = before && (before.type === "star" || before.type === "globstar");
|
|
4061
|
+
if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
|
|
4062
|
+
push({
|
|
4063
|
+
type: "star",
|
|
4064
|
+
value,
|
|
4065
|
+
output: ""
|
|
4066
|
+
});
|
|
4067
|
+
continue;
|
|
4068
|
+
}
|
|
4069
|
+
const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
|
|
4070
|
+
const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
|
|
4071
|
+
if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
|
|
4072
|
+
push({
|
|
4073
|
+
type: "star",
|
|
4074
|
+
value,
|
|
4075
|
+
output: ""
|
|
4076
|
+
});
|
|
4077
|
+
continue;
|
|
4078
|
+
}
|
|
4079
|
+
while (rest.slice(0, 3) === "/**") {
|
|
4080
|
+
const after = input[state.index + 4];
|
|
4081
|
+
if (after && after !== "/") break;
|
|
4082
|
+
rest = rest.slice(3);
|
|
4083
|
+
consume("/**", 3);
|
|
4084
|
+
}
|
|
4085
|
+
const isEnd = eos() || state.parens > 0 && rest === ")".repeat(state.parens) && !extglobs.some((extglob) => extglob.type === "negate");
|
|
4086
|
+
if (prior.type === "bos" && eos()) {
|
|
4087
|
+
prev.type = "globstar";
|
|
4088
|
+
prev.value += value;
|
|
4089
|
+
prev.output = globstar(opts);
|
|
4090
|
+
state.output = prev.output;
|
|
4091
|
+
state.globstar = true;
|
|
4092
|
+
consume(value);
|
|
4093
|
+
continue;
|
|
4094
|
+
}
|
|
4095
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && isEnd) {
|
|
4096
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
4097
|
+
prior.output = `(?:${prior.output}`;
|
|
4098
|
+
prev.type = "globstar";
|
|
4099
|
+
prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
|
|
4100
|
+
prev.value += value;
|
|
4101
|
+
state.globstar = true;
|
|
4102
|
+
state.output += prior.output + prev.output;
|
|
4103
|
+
consume(value);
|
|
4104
|
+
continue;
|
|
4105
|
+
}
|
|
4106
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
|
|
4107
|
+
const end = rest[1] !== void 0 ? "|$" : "";
|
|
4108
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
4109
|
+
prior.output = `(?:${prior.output}`;
|
|
4110
|
+
prev.type = "globstar";
|
|
4111
|
+
prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
|
|
4112
|
+
prev.value += value;
|
|
4113
|
+
state.output += prior.output + prev.output;
|
|
4114
|
+
state.globstar = true;
|
|
4115
|
+
consume(value + advance());
|
|
4116
|
+
push({
|
|
4117
|
+
type: "slash",
|
|
4118
|
+
value: "/",
|
|
4119
|
+
output: ""
|
|
4120
|
+
});
|
|
4121
|
+
continue;
|
|
4122
|
+
}
|
|
4123
|
+
if (prior.type === "bos" && rest[0] === "/") {
|
|
4124
|
+
prev.type = "globstar";
|
|
4125
|
+
prev.value += value;
|
|
4126
|
+
prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
|
|
4127
|
+
state.output = prev.output;
|
|
4128
|
+
state.globstar = true;
|
|
4129
|
+
consume(value + advance());
|
|
4130
|
+
push({
|
|
4131
|
+
type: "slash",
|
|
4132
|
+
value: "/",
|
|
4133
|
+
output: ""
|
|
4134
|
+
});
|
|
4135
|
+
continue;
|
|
4136
|
+
}
|
|
4137
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
4138
|
+
prev.type = "globstar";
|
|
4139
|
+
prev.output = globstar(opts);
|
|
4140
|
+
prev.value += value;
|
|
4141
|
+
state.output += prev.output;
|
|
4142
|
+
state.globstar = true;
|
|
4143
|
+
consume(value);
|
|
4144
|
+
continue;
|
|
4145
|
+
}
|
|
4146
|
+
const token = {
|
|
4147
|
+
type: "star",
|
|
4148
|
+
value,
|
|
4149
|
+
output: star
|
|
4150
|
+
};
|
|
4151
|
+
if (opts.bash === true) {
|
|
4152
|
+
token.output = ".*?";
|
|
4153
|
+
if (prev.type === "bos" || prev.type === "slash") token.output = nodot + token.output;
|
|
4154
|
+
push(token);
|
|
4155
|
+
continue;
|
|
4156
|
+
}
|
|
4157
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
|
|
4158
|
+
token.output = value;
|
|
4159
|
+
push(token);
|
|
4160
|
+
continue;
|
|
4161
|
+
}
|
|
4162
|
+
if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
|
|
4163
|
+
if (prev.type === "dot") {
|
|
4164
|
+
state.output += NO_DOT_SLASH;
|
|
4165
|
+
prev.output += NO_DOT_SLASH;
|
|
4166
|
+
} else if (opts.dot === true) {
|
|
4167
|
+
state.output += NO_DOTS_SLASH;
|
|
4168
|
+
prev.output += NO_DOTS_SLASH;
|
|
4169
|
+
} else {
|
|
4170
|
+
state.output += nodot;
|
|
4171
|
+
prev.output += nodot;
|
|
4172
|
+
}
|
|
4173
|
+
if (peek() !== "*") {
|
|
4174
|
+
state.output += ONE_CHAR;
|
|
4175
|
+
prev.output += ONE_CHAR;
|
|
4176
|
+
}
|
|
4177
|
+
}
|
|
4178
|
+
push(token);
|
|
4179
|
+
}
|
|
4180
|
+
while (state.brackets > 0) {
|
|
4181
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
4182
|
+
state.output = utils.escapeLast(state.output, "[");
|
|
4183
|
+
decrement("brackets");
|
|
4184
|
+
}
|
|
4185
|
+
while (state.parens > 0) {
|
|
4186
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
|
|
4187
|
+
state.output = utils.escapeLast(state.output, "(");
|
|
4188
|
+
decrement("parens");
|
|
4189
|
+
}
|
|
4190
|
+
while (state.braces > 0) {
|
|
4191
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
|
|
4192
|
+
state.output = utils.escapeLast(state.output, "{");
|
|
4193
|
+
decrement("braces");
|
|
4194
|
+
}
|
|
4195
|
+
if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) push({
|
|
4196
|
+
type: "maybe_slash",
|
|
4197
|
+
value: "",
|
|
4198
|
+
output: `${SLASH_LITERAL}?`
|
|
4199
|
+
});
|
|
4200
|
+
if (state.backtrack === true) {
|
|
4201
|
+
state.output = "";
|
|
4202
|
+
for (const token of state.tokens) {
|
|
4203
|
+
state.output += token.output != null ? token.output : token.value;
|
|
4204
|
+
if (token.suffix) state.output += token.suffix;
|
|
4205
|
+
}
|
|
4206
|
+
}
|
|
4207
|
+
return state;
|
|
4208
|
+
};
|
|
4209
|
+
/**
|
|
4210
|
+
* Fast paths for creating regular expressions for common glob patterns.
|
|
4211
|
+
* This can significantly speed up processing and has very little downside
|
|
4212
|
+
* impact when none of the fast paths match.
|
|
4213
|
+
*/
|
|
4214
|
+
parse.fastpaths = (input, options) => {
|
|
4215
|
+
const opts = { ...options };
|
|
4216
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
4217
|
+
const len = input.length;
|
|
4218
|
+
if (len > max) throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
4219
|
+
input = REPLACEMENTS[input] || input;
|
|
4220
|
+
const { DOT_LITERAL, SLASH_LITERAL, ONE_CHAR, DOTS_SLASH, NO_DOT, NO_DOTS, NO_DOTS_SLASH, STAR, START_ANCHOR } = constants.globChars(opts.windows);
|
|
4221
|
+
const nodot = opts.dot ? NO_DOTS : NO_DOT;
|
|
4222
|
+
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
|
4223
|
+
const capture = opts.capture ? "" : "?:";
|
|
4224
|
+
const state = {
|
|
4225
|
+
negated: false,
|
|
4226
|
+
prefix: ""
|
|
4227
|
+
};
|
|
4228
|
+
let star = opts.bash === true ? ".*?" : STAR;
|
|
4229
|
+
if (opts.capture) star = `(${star})`;
|
|
4230
|
+
const globstar = (opts) => {
|
|
4231
|
+
if (opts.noglobstar === true) return star;
|
|
4232
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
4233
|
+
};
|
|
4234
|
+
const create = (str) => {
|
|
4235
|
+
switch (str) {
|
|
4236
|
+
case "*": return `${nodot}${ONE_CHAR}${star}`;
|
|
4237
|
+
case ".*": return `${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
4238
|
+
case "*.*": return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
4239
|
+
case "*/*": return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
|
|
4240
|
+
case "**": return nodot + globstar(opts);
|
|
4241
|
+
case "**/*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
|
|
4242
|
+
case "**/*.*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
4243
|
+
case "**/.*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
4244
|
+
default: {
|
|
4245
|
+
const match = /^(.*?)\.(\w+)$/.exec(str);
|
|
4246
|
+
if (!match) return;
|
|
4247
|
+
const source = create(match[1]);
|
|
4248
|
+
if (!source) return;
|
|
4249
|
+
return source + DOT_LITERAL + match[2];
|
|
4250
|
+
}
|
|
4251
|
+
}
|
|
4252
|
+
};
|
|
4253
|
+
let source = create(utils.removePrefix(input, state));
|
|
4254
|
+
if (source && opts.strictSlashes !== true) source += `${SLASH_LITERAL}?`;
|
|
4255
|
+
return source;
|
|
4256
|
+
};
|
|
4257
|
+
module.exports = parse;
|
|
4258
|
+
}));
|
|
4259
|
+
// ../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/picomatch.js
|
|
4260
|
+
var require_picomatch$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4261
|
+
const scan = require_scan();
|
|
4262
|
+
const parse = require_parse();
|
|
4263
|
+
const utils = require_utils();
|
|
4264
|
+
const constants = require_constants();
|
|
4265
|
+
const isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
|
|
4266
|
+
/**
|
|
4267
|
+
* Creates a matcher function from one or more glob patterns. The
|
|
4268
|
+
* returned function takes a string to match as its first argument,
|
|
4269
|
+
* and returns true if the string is a match. The returned matcher
|
|
4270
|
+
* function also takes a boolean as the second argument that, when true,
|
|
4271
|
+
* returns an object with additional information.
|
|
4272
|
+
*
|
|
4273
|
+
* ```js
|
|
4274
|
+
* const picomatch = require('picomatch');
|
|
4275
|
+
* // picomatch(glob[, options]);
|
|
4276
|
+
*
|
|
4277
|
+
* const isMatch = picomatch('*.!(*a)');
|
|
4278
|
+
* console.log(isMatch('a.a')); //=> false
|
|
4279
|
+
* console.log(isMatch('a.b')); //=> true
|
|
4280
|
+
*
|
|
4281
|
+
* // For environments without `node.js`, `picomatch/posix` provides you a dependency-free matcher, without automatic OS detection.
|
|
4282
|
+
* const picomatch = require('picomatch/posix');
|
|
4283
|
+
* // the same API, defaulting to posix paths
|
|
4284
|
+
* const isMatch = picomatch('a/*');
|
|
4285
|
+
* console.log(isMatch('a\\b')); //=> false
|
|
4286
|
+
* console.log(isMatch('a/b')); //=> true
|
|
4287
|
+
*
|
|
4288
|
+
* // you can still configure the matcher function to accept windows paths
|
|
4289
|
+
* const isMatch = picomatch('a/*', { options: windows });
|
|
4290
|
+
* console.log(isMatch('a\\b')); //=> true
|
|
4291
|
+
* console.log(isMatch('a/b')); //=> true
|
|
4292
|
+
* ```
|
|
4293
|
+
* @name picomatch
|
|
4294
|
+
* @param {String|Array} `globs` One or more glob patterns.
|
|
4295
|
+
* @param {Object=} `options`
|
|
4296
|
+
* @return {Function=} Returns a matcher function.
|
|
4297
|
+
* @api public
|
|
4298
|
+
*/
|
|
4299
|
+
const picomatch = (glob, options, returnState = false) => {
|
|
4300
|
+
if (Array.isArray(glob)) {
|
|
4301
|
+
const fns = glob.map((input) => picomatch(input, options, returnState));
|
|
4302
|
+
const arrayMatcher = (str) => {
|
|
4303
|
+
for (const isMatch of fns) {
|
|
4304
|
+
const state = isMatch(str);
|
|
4305
|
+
if (state) return state;
|
|
4306
|
+
}
|
|
4307
|
+
return false;
|
|
4308
|
+
};
|
|
4309
|
+
return arrayMatcher;
|
|
4310
|
+
}
|
|
4311
|
+
const isState = isObject(glob) && glob.tokens && glob.input;
|
|
4312
|
+
if (glob === "" || typeof glob !== "string" && !isState) throw new TypeError("Expected pattern to be a non-empty string");
|
|
4313
|
+
const opts = options || {};
|
|
4314
|
+
const posix = opts.windows;
|
|
4315
|
+
const regex = isState ? picomatch.compileRe(glob, options) : picomatch.makeRe(glob, options, false, true);
|
|
4316
|
+
const state = regex.state;
|
|
4317
|
+
delete regex.state;
|
|
4318
|
+
let isIgnored = () => false;
|
|
4319
|
+
if (opts.ignore) {
|
|
4320
|
+
const ignoreOpts = {
|
|
4321
|
+
...options,
|
|
4322
|
+
ignore: null,
|
|
4323
|
+
onMatch: null,
|
|
4324
|
+
onResult: null
|
|
4325
|
+
};
|
|
4326
|
+
isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
|
|
4327
|
+
}
|
|
4328
|
+
const matcher = (input, returnObject = false) => {
|
|
4329
|
+
const { isMatch, match, output } = picomatch.test(input, regex, options, {
|
|
4330
|
+
glob,
|
|
4331
|
+
posix
|
|
4332
|
+
});
|
|
4333
|
+
const result = {
|
|
4334
|
+
glob,
|
|
4335
|
+
state,
|
|
4336
|
+
regex,
|
|
4337
|
+
posix,
|
|
4338
|
+
input,
|
|
4339
|
+
output,
|
|
4340
|
+
match,
|
|
4341
|
+
isMatch
|
|
4342
|
+
};
|
|
4343
|
+
if (typeof opts.onResult === "function") opts.onResult(result);
|
|
4344
|
+
if (isMatch === false) {
|
|
4345
|
+
result.isMatch = false;
|
|
4346
|
+
return returnObject ? result : false;
|
|
4347
|
+
}
|
|
4348
|
+
if (isIgnored(input)) {
|
|
4349
|
+
if (typeof opts.onIgnore === "function") opts.onIgnore(result);
|
|
4350
|
+
result.isMatch = false;
|
|
4351
|
+
return returnObject ? result : false;
|
|
4352
|
+
}
|
|
4353
|
+
if (typeof opts.onMatch === "function") opts.onMatch(result);
|
|
4354
|
+
return returnObject ? result : true;
|
|
4355
|
+
};
|
|
4356
|
+
if (returnState) matcher.state = state;
|
|
4357
|
+
return matcher;
|
|
4358
|
+
};
|
|
4359
|
+
/**
|
|
4360
|
+
* Test `input` with the given `regex`. This is used by the main
|
|
4361
|
+
* `picomatch()` function to test the input string.
|
|
4362
|
+
*
|
|
4363
|
+
* ```js
|
|
4364
|
+
* const picomatch = require('picomatch');
|
|
4365
|
+
* // picomatch.test(input, regex[, options]);
|
|
4366
|
+
*
|
|
4367
|
+
* console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
|
|
4368
|
+
* // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
|
|
4369
|
+
* ```
|
|
4370
|
+
* @param {String} `input` String to test.
|
|
4371
|
+
* @param {RegExp} `regex`
|
|
4372
|
+
* @return {Object} Returns an object with matching info.
|
|
4373
|
+
* @api public
|
|
4374
|
+
*/
|
|
4375
|
+
picomatch.test = (input, regex, options, { glob, posix } = {}) => {
|
|
4376
|
+
if (typeof input !== "string") throw new TypeError("Expected input to be a string");
|
|
4377
|
+
if (input === "") return {
|
|
4378
|
+
isMatch: false,
|
|
4379
|
+
output: ""
|
|
4380
|
+
};
|
|
4381
|
+
const opts = options || {};
|
|
4382
|
+
const format = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
4383
|
+
let match = input === glob;
|
|
4384
|
+
let output = match && format ? format(input) : input;
|
|
4385
|
+
if (match === false) {
|
|
4386
|
+
output = format ? format(input) : input;
|
|
4387
|
+
match = output === glob;
|
|
4388
|
+
}
|
|
4389
|
+
if (match === false || opts.capture === true) {
|
|
4390
|
+
if (opts.matchBase === true || opts.basename === true) match = picomatch.matchBase(input, regex, options, posix);
|
|
4391
|
+
else match = regex.exec(output);
|
|
4392
|
+
}
|
|
4393
|
+
return {
|
|
4394
|
+
isMatch: Boolean(match),
|
|
4395
|
+
match,
|
|
4396
|
+
output
|
|
4397
|
+
};
|
|
4398
|
+
};
|
|
4399
|
+
/**
|
|
4400
|
+
* Match the basename of a filepath.
|
|
4401
|
+
*
|
|
4402
|
+
* ```js
|
|
4403
|
+
* const picomatch = require('picomatch');
|
|
4404
|
+
* // picomatch.matchBase(input, glob[, options]);
|
|
4405
|
+
* console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
|
|
4406
|
+
* ```
|
|
4407
|
+
* @param {String} `input` String to test.
|
|
4408
|
+
* @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
|
|
4409
|
+
* @return {Boolean}
|
|
4410
|
+
* @api public
|
|
4411
|
+
*/
|
|
4412
|
+
picomatch.matchBase = (input, glob, options, posix = options && options.windows) => {
|
|
4413
|
+
return (glob instanceof RegExp ? glob : picomatch.makeRe(glob, options)).test(utils.basename(input, { windows: posix }));
|
|
4414
|
+
};
|
|
4415
|
+
/**
|
|
4416
|
+
* Returns true if **any** of the given glob `patterns` match the specified `string`.
|
|
4417
|
+
*
|
|
4418
|
+
* ```js
|
|
4419
|
+
* const picomatch = require('picomatch');
|
|
4420
|
+
* // picomatch.isMatch(string, patterns[, options]);
|
|
4421
|
+
*
|
|
4422
|
+
* console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
|
|
4423
|
+
* console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
|
|
4424
|
+
* ```
|
|
4425
|
+
* @param {String|Array} str The string to test.
|
|
4426
|
+
* @param {String|Array} patterns One or more glob patterns to use for matching.
|
|
4427
|
+
* @param {Object} [options] See available [options](#options).
|
|
4428
|
+
* @return {Boolean} Returns true if any patterns match `str`
|
|
4429
|
+
* @api public
|
|
4430
|
+
*/
|
|
4431
|
+
picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
|
|
4432
|
+
/**
|
|
4433
|
+
* Parse a glob pattern to create the source string for a regular
|
|
4434
|
+
* expression.
|
|
4435
|
+
*
|
|
4436
|
+
* ```js
|
|
4437
|
+
* const picomatch = require('picomatch');
|
|
4438
|
+
* const result = picomatch.parse(pattern[, options]);
|
|
4439
|
+
* ```
|
|
4440
|
+
* @param {String} `pattern`
|
|
4441
|
+
* @param {Object} `options`
|
|
4442
|
+
* @return {Object} Returns an object with useful properties and output to be used as a regex source string.
|
|
4443
|
+
* @api public
|
|
4444
|
+
*/
|
|
4445
|
+
picomatch.parse = (pattern, options) => {
|
|
4446
|
+
if (Array.isArray(pattern)) return pattern.map((p) => picomatch.parse(p, options));
|
|
4447
|
+
return parse(pattern, {
|
|
4448
|
+
...options,
|
|
4449
|
+
fastpaths: false
|
|
4450
|
+
});
|
|
4451
|
+
};
|
|
4452
|
+
/**
|
|
4453
|
+
* Scan a glob pattern to separate the pattern into segments.
|
|
4454
|
+
*
|
|
4455
|
+
* ```js
|
|
4456
|
+
* const picomatch = require('picomatch');
|
|
4457
|
+
* // picomatch.scan(input[, options]);
|
|
4458
|
+
*
|
|
4459
|
+
* const result = picomatch.scan('!./foo/*.js');
|
|
4460
|
+
* console.log(result);
|
|
4461
|
+
* { prefix: '!./',
|
|
4462
|
+
* input: '!./foo/*.js',
|
|
4463
|
+
* start: 3,
|
|
4464
|
+
* base: 'foo',
|
|
4465
|
+
* glob: '*.js',
|
|
4466
|
+
* isBrace: false,
|
|
4467
|
+
* isBracket: false,
|
|
4468
|
+
* isGlob: true,
|
|
4469
|
+
* isExtglob: false,
|
|
4470
|
+
* isGlobstar: false,
|
|
4471
|
+
* negated: true }
|
|
4472
|
+
* ```
|
|
4473
|
+
* @param {String} `input` Glob pattern to scan.
|
|
4474
|
+
* @param {Object} `options`
|
|
4475
|
+
* @return {Object} Returns an object with
|
|
4476
|
+
* @api public
|
|
4477
|
+
*/
|
|
4478
|
+
picomatch.scan = (input, options) => scan(input, options);
|
|
4479
|
+
/**
|
|
4480
|
+
* Compile a regular expression from the `state` object returned by the
|
|
4481
|
+
* [parse()](#parse) method.
|
|
4482
|
+
*
|
|
4483
|
+
* ```js
|
|
4484
|
+
* const picomatch = require('picomatch');
|
|
4485
|
+
* const state = picomatch.parse('*.js');
|
|
4486
|
+
* // picomatch.compileRe(state[, options]);
|
|
4487
|
+
*
|
|
4488
|
+
* console.log(picomatch.compileRe(state));
|
|
4489
|
+
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
4490
|
+
* ```
|
|
4491
|
+
* @param {Object} `state`
|
|
4492
|
+
* @param {Object} `options`
|
|
4493
|
+
* @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
|
|
4494
|
+
* @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
|
|
4495
|
+
* @return {RegExp}
|
|
4496
|
+
* @api public
|
|
4497
|
+
*/
|
|
4498
|
+
picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
4499
|
+
if (returnOutput === true) return state.output;
|
|
4500
|
+
const opts = options || {};
|
|
4501
|
+
const prepend = opts.contains ? "" : "^";
|
|
4502
|
+
const append = opts.contains ? "" : "$";
|
|
4503
|
+
let source = `${prepend}(?:${state.output})${append}`;
|
|
4504
|
+
if (state && state.negated === true) source = `^(?!${source}).*$`;
|
|
4505
|
+
const regex = picomatch.toRegex(source, options);
|
|
4506
|
+
if (returnState === true) regex.state = state;
|
|
4507
|
+
return regex;
|
|
4508
|
+
};
|
|
4509
|
+
/**
|
|
4510
|
+
* Create a regular expression from a parsed glob pattern.
|
|
4511
|
+
*
|
|
4512
|
+
* ```js
|
|
4513
|
+
* const picomatch = require('picomatch');
|
|
4514
|
+
* // picomatch.makeRe(state[, options]);
|
|
4515
|
+
*
|
|
4516
|
+
* const result = picomatch.makeRe('*.js');
|
|
4517
|
+
* console.log(result);
|
|
4518
|
+
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
4519
|
+
* ```
|
|
4520
|
+
* @param {String} `state` The object returned from the `.parse` method.
|
|
4521
|
+
* @param {Object} `options`
|
|
4522
|
+
* @param {Boolean} `returnOutput` Implementors may use this argument to return the compiled output, instead of a regular expression. This is not exposed on the options to prevent end-users from mutating the result.
|
|
4523
|
+
* @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
|
|
4524
|
+
* @return {RegExp} Returns a regex created from the given pattern.
|
|
4525
|
+
* @api public
|
|
4526
|
+
*/
|
|
4527
|
+
picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
4528
|
+
if (!input || typeof input !== "string") throw new TypeError("Expected a non-empty string");
|
|
4529
|
+
let parsed = {
|
|
4530
|
+
negated: false,
|
|
4531
|
+
fastpaths: true
|
|
4532
|
+
};
|
|
4533
|
+
if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) parsed.output = parse.fastpaths(input, options);
|
|
4534
|
+
if (!parsed.output) parsed = parse(input, options);
|
|
4535
|
+
return picomatch.compileRe(parsed, options, returnOutput, returnState);
|
|
4536
|
+
};
|
|
4537
|
+
/**
|
|
4538
|
+
* Create a regular expression from the given regex source string.
|
|
4539
|
+
*
|
|
4540
|
+
* ```js
|
|
4541
|
+
* const picomatch = require('picomatch');
|
|
4542
|
+
* // picomatch.toRegex(source[, options]);
|
|
4543
|
+
*
|
|
4544
|
+
* const { output } = picomatch.parse('*.js');
|
|
4545
|
+
* console.log(picomatch.toRegex(output));
|
|
4546
|
+
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
4547
|
+
* ```
|
|
4548
|
+
* @param {String} `source` Regular expression source string.
|
|
4549
|
+
* @param {Object} `options`
|
|
4550
|
+
* @return {RegExp}
|
|
4551
|
+
* @api public
|
|
4552
|
+
*/
|
|
4553
|
+
picomatch.toRegex = (source, options) => {
|
|
4554
|
+
try {
|
|
4555
|
+
const opts = options || {};
|
|
4556
|
+
return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
|
|
4557
|
+
} catch (err) {
|
|
4558
|
+
if (options && options.debug === true) throw err;
|
|
4559
|
+
return /$^/;
|
|
4560
|
+
}
|
|
4561
|
+
};
|
|
4562
|
+
/**
|
|
4563
|
+
* Picomatch constants.
|
|
4564
|
+
* @return {Object}
|
|
4565
|
+
*/
|
|
4566
|
+
picomatch.constants = constants;
|
|
4567
|
+
/**
|
|
4568
|
+
* Expose "picomatch"
|
|
4569
|
+
*/
|
|
4570
|
+
module.exports = picomatch;
|
|
4571
|
+
}));
|
|
4572
|
+
// ../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/index.js
|
|
4573
|
+
var require_picomatch = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4574
|
+
const pico = require_picomatch$1();
|
|
4575
|
+
const utils = require_utils();
|
|
4576
|
+
function picomatch(glob, options, returnState = false) {
|
|
4577
|
+
if (options && (options.windows === null || options.windows === void 0)) options = {
|
|
4578
|
+
...options,
|
|
4579
|
+
windows: utils.isWindows()
|
|
4580
|
+
};
|
|
4581
|
+
return pico(glob, options, returnState);
|
|
4582
|
+
}
|
|
4583
|
+
Object.assign(picomatch, pico);
|
|
4584
|
+
module.exports = picomatch;
|
|
4585
|
+
}));
|
|
4586
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/builtin/path-util.js
|
|
4587
|
+
var import_regexp_string_matcher = require_regexp_string_matcher();
|
|
4588
|
+
var import_picomatch = /* @__PURE__ */ __toESM(require_picomatch(), 1);
|
|
4589
|
+
/**
|
|
4590
|
+
* Return the last portion of a path, like `path.basename()` of Node.js.
|
|
4591
|
+
* Both `/` and `\` are treated as separators, so it works for POSIX and Windows paths
|
|
4592
|
+
* without importing `node:path` (core must work in browsers).
|
|
4593
|
+
*/
|
|
4594
|
+
const basename$1 = (filePath) => {
|
|
4595
|
+
let end = filePath.length;
|
|
4596
|
+
while (end > 0 && (filePath[end - 1] === "/" || filePath[end - 1] === "\\")) end--;
|
|
4597
|
+
const trimmed = filePath.slice(0, end);
|
|
4598
|
+
const index = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
|
|
4599
|
+
return index === -1 ? trimmed : trimmed.slice(index + 1);
|
|
4600
|
+
};
|
|
4601
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/helper/extract-keywords.js
|
|
4602
|
+
/**
|
|
4603
|
+
* Find keywords in a regular expression: strings that every match of the regular expression contains.
|
|
4604
|
+
*
|
|
4605
|
+
* The keywords are used by the keyword pre-filter, so a wrong keyword makes a pattern miss a match.
|
|
4606
|
+
* This reads the pattern conservatively: it keeps only the characters that every match consumes one after another,
|
|
4607
|
+
* and it returns `undefined` for any syntax that it does not know.
|
|
4608
|
+
* Search tools use the same idea to find the literals that a match requires, such as the trigram index of
|
|
4609
|
+
* Google Code Search (https://swtch.com/~rsc/regexp/regexp4.html) and `regex_syntax::hir::literal` of Rust.
|
|
4610
|
+
*/
|
|
4611
|
+
/**
|
|
4612
|
+
* A keyword shorter than this is not used, because it is found in most files and makes the scan report many positions.
|
|
4613
|
+
*/
|
|
4614
|
+
const MIN_KEYWORD_LENGTH = 3;
|
|
4615
|
+
var UnsupportedSyntax = class extends Error {};
|
|
4616
|
+
const scoreOf = (set) => {
|
|
4617
|
+
let min = Infinity;
|
|
4618
|
+
for (const keyword of set) min = Math.min(min, keyword.length);
|
|
4619
|
+
return min;
|
|
4620
|
+
};
|
|
4621
|
+
/**
|
|
4622
|
+
* Return the set whose shortest keyword is the longest, or undefined if no set is long enough.
|
|
4623
|
+
*/
|
|
4624
|
+
const bestSet = (sets) => {
|
|
4625
|
+
let best;
|
|
4626
|
+
for (const set of sets) {
|
|
4627
|
+
if (scoreOf(set) < MIN_KEYWORD_LENGTH) continue;
|
|
4628
|
+
if (best === void 0 || scoreOf(set) > scoreOf(best)) best = set;
|
|
4629
|
+
}
|
|
4630
|
+
return best;
|
|
4631
|
+
};
|
|
4632
|
+
/**
|
|
4633
|
+
* A match takes one of the alternatives, so the keywords are the union of the best set of each alternative.
|
|
4634
|
+
* Return undefined if an alternative has no keyword.
|
|
4635
|
+
*/
|
|
4636
|
+
const unionOfAlternatives = (alternatives) => {
|
|
4637
|
+
const union = /* @__PURE__ */ new Set();
|
|
4638
|
+
for (const sets of alternatives) {
|
|
4639
|
+
const best = bestSet(sets);
|
|
4640
|
+
if (best === void 0) return;
|
|
4641
|
+
best.forEach((keyword) => union.add(keyword));
|
|
4642
|
+
}
|
|
4643
|
+
return [...union];
|
|
4644
|
+
};
|
|
4645
|
+
/**
|
|
4646
|
+
* Parse alternatives until ")" or the end, and return the keyword sets of each alternative
|
|
4647
|
+
*/
|
|
4648
|
+
const parseAlternatives = (parser) => {
|
|
4649
|
+
const alternatives = [parseSequence(parser)];
|
|
4650
|
+
while (parser.source[parser.index] === "|") {
|
|
4651
|
+
parser.index++;
|
|
4652
|
+
alternatives.push(parseSequence(parser));
|
|
4653
|
+
}
|
|
4654
|
+
return alternatives;
|
|
4655
|
+
};
|
|
4656
|
+
const indexAfter = (parser, char, from) => {
|
|
4657
|
+
const index = parser.source.indexOf(char, from);
|
|
4658
|
+
if (index < 0) throw new UnsupportedSyntax();
|
|
4659
|
+
return index + 1;
|
|
4660
|
+
};
|
|
4661
|
+
const parseEscape = (parser) => {
|
|
4662
|
+
const { source } = parser;
|
|
4663
|
+
const start = parser.index;
|
|
4664
|
+
const escaped = source[start + 1];
|
|
4665
|
+
if (escaped === void 0) throw new UnsupportedSyntax();
|
|
4666
|
+
if (!/[0-9A-Za-z]/.test(escaped)) {
|
|
4667
|
+
parser.index = start + 2;
|
|
4668
|
+
return {
|
|
4669
|
+
kind: "char",
|
|
4670
|
+
char: escaped
|
|
4671
|
+
};
|
|
4672
|
+
}
|
|
4673
|
+
switch (escaped) {
|
|
4674
|
+
case "x":
|
|
4675
|
+
parser.index = start + 4;
|
|
4676
|
+
break;
|
|
4677
|
+
case "u":
|
|
4678
|
+
parser.index = source[start + 2] === "{" ? indexAfter(parser, "}", start) : start + 6;
|
|
4679
|
+
break;
|
|
4680
|
+
case "c":
|
|
4681
|
+
parser.index = start + 3;
|
|
4682
|
+
break;
|
|
4683
|
+
case "p":
|
|
4684
|
+
case "P":
|
|
4685
|
+
parser.index = indexAfter(parser, "}", start);
|
|
4686
|
+
break;
|
|
4687
|
+
case "k":
|
|
4688
|
+
parser.index = indexAfter(parser, ">", start);
|
|
4689
|
+
break;
|
|
4690
|
+
default: {
|
|
4691
|
+
let next = start + 2;
|
|
4692
|
+
if (/[0-9]/.test(escaped)) while (/[0-9]/.test(source[next] ?? "")) next++;
|
|
4693
|
+
parser.index = next;
|
|
4694
|
+
}
|
|
4695
|
+
}
|
|
4696
|
+
return { kind: "other" };
|
|
4697
|
+
};
|
|
4698
|
+
const skipClass = (parser) => {
|
|
4699
|
+
const { source } = parser;
|
|
4700
|
+
let index = parser.index + 1;
|
|
4701
|
+
while (index < source.length && source[index] !== "]") index += source[index] === "\\" ? 2 : 1;
|
|
4702
|
+
if (index >= source.length) throw new UnsupportedSyntax();
|
|
4703
|
+
parser.index = index + 1;
|
|
4704
|
+
return { kind: "other" };
|
|
4705
|
+
};
|
|
4706
|
+
const parseGroup = (parser) => {
|
|
4707
|
+
const { source } = parser;
|
|
4708
|
+
let index = parser.index + 1;
|
|
4709
|
+
let negative = false;
|
|
4710
|
+
if (source[index] === "?") {
|
|
4711
|
+
const next = source[index + 1];
|
|
4712
|
+
const afterNext = source[index + 2];
|
|
4713
|
+
if (next === ":" || next === "=") index += 2;
|
|
4714
|
+
else if (next === "!") {
|
|
4715
|
+
negative = true;
|
|
4716
|
+
index += 2;
|
|
4717
|
+
} else if (next === "<" && afterNext === "=") index += 3;
|
|
4718
|
+
else if (next === "<" && afterNext === "!") {
|
|
4719
|
+
negative = true;
|
|
4720
|
+
index += 3;
|
|
4721
|
+
} else if (next === "<") index = indexAfter(parser, ">", index);
|
|
4722
|
+
else throw new UnsupportedSyntax();
|
|
4723
|
+
}
|
|
4724
|
+
parser.index = index;
|
|
4725
|
+
const alternatives = parseAlternatives(parser);
|
|
4726
|
+
if (source[parser.index] !== ")") throw new UnsupportedSyntax();
|
|
4727
|
+
parser.index++;
|
|
4728
|
+
return negative ? { kind: "other" } : {
|
|
4729
|
+
kind: "group",
|
|
4730
|
+
alternatives
|
|
4731
|
+
};
|
|
4732
|
+
};
|
|
4733
|
+
/**
|
|
4734
|
+
* Parse a quantifier after an atom, and return the minimum number of repetitions, or undefined if there is no quantifier
|
|
4735
|
+
*/
|
|
4736
|
+
const parseQuantifier = (parser) => {
|
|
4737
|
+
const { source } = parser;
|
|
4738
|
+
const char = source[parser.index];
|
|
4739
|
+
let min;
|
|
4740
|
+
if (char === "?" || char === "*") {
|
|
4741
|
+
min = 0;
|
|
4742
|
+
parser.index++;
|
|
4743
|
+
} else if (char === "+") {
|
|
4744
|
+
min = 1;
|
|
4745
|
+
parser.index++;
|
|
4746
|
+
} else if (char === "{") {
|
|
4747
|
+
const matched = /^\{(\d+)(?:,\d*)?\}/.exec(source.slice(parser.index));
|
|
4748
|
+
if (!matched) throw new UnsupportedSyntax();
|
|
4749
|
+
min = Number(matched[1]);
|
|
4750
|
+
parser.index += matched[0].length;
|
|
4751
|
+
}
|
|
4752
|
+
if (min !== void 0 && source[parser.index] === "?") parser.index++;
|
|
4753
|
+
return min;
|
|
4754
|
+
};
|
|
4755
|
+
/**
|
|
4756
|
+
* Parse a sequence until "|", ")", or the end, and return its keyword sets.
|
|
4757
|
+
* Every match of the sequence contains at least one keyword of each set.
|
|
4758
|
+
*/
|
|
4759
|
+
const parseSequence = (parser) => {
|
|
4760
|
+
const { source, ignoreCase } = parser;
|
|
4761
|
+
const sets = [];
|
|
4762
|
+
let run = "";
|
|
4763
|
+
const endRun = () => {
|
|
4764
|
+
if (run.length > 0) sets.push([run]);
|
|
4765
|
+
run = "";
|
|
4766
|
+
};
|
|
4767
|
+
while (parser.index < source.length && source[parser.index] !== "|" && source[parser.index] !== ")") {
|
|
4768
|
+
const char = source[parser.index];
|
|
4769
|
+
let atom;
|
|
4770
|
+
if (char === "\\") atom = parseEscape(parser);
|
|
4771
|
+
else if (char === "[") atom = skipClass(parser);
|
|
4772
|
+
else if (char === "(") atom = parseGroup(parser);
|
|
4773
|
+
else if (char === "." || char === "^" || char === "$") {
|
|
4774
|
+
parser.index++;
|
|
4775
|
+
atom = { kind: "other" };
|
|
4776
|
+
} else if (char === "?" || char === "*" || char === "+" || char === "{" || char === "}" || char === "]") throw new UnsupportedSyntax();
|
|
4777
|
+
else {
|
|
4778
|
+
parser.index++;
|
|
4779
|
+
atom = {
|
|
4780
|
+
kind: "char",
|
|
4781
|
+
char
|
|
4782
|
+
};
|
|
4783
|
+
}
|
|
4784
|
+
const min = parseQuantifier(parser);
|
|
4785
|
+
if (atom.kind === "char") {
|
|
4786
|
+
if (atom.char.charCodeAt(0) >= 128 || min === 0) endRun();
|
|
4787
|
+
else {
|
|
4788
|
+
run += ignoreCase ? atom.char.toLowerCase() : atom.char;
|
|
4789
|
+
if (min !== void 0) endRun();
|
|
4790
|
+
}
|
|
4791
|
+
} else if (atom.kind === "group") {
|
|
4792
|
+
endRun();
|
|
4793
|
+
if (min === void 0 || min >= 1) {
|
|
4794
|
+
const union = unionOfAlternatives(atom.alternatives);
|
|
4795
|
+
if (union !== void 0) sets.push(union);
|
|
4796
|
+
}
|
|
4797
|
+
} else endRun();
|
|
4798
|
+
}
|
|
4799
|
+
endRun();
|
|
4800
|
+
return sets;
|
|
4801
|
+
};
|
|
4802
|
+
/**
|
|
4803
|
+
* Return keywords that every match of the regular expression contains, or `undefined` if no keyword is found.
|
|
4804
|
+
* The keywords are ASCII, and lower-cased if the regular expression has the "i" flag.
|
|
4805
|
+
* At least one of the keywords is in the content when the regular expression matches it,
|
|
4806
|
+
* except for a match of the "i" flag with a non-ASCII character that folds to an ASCII letter, such as "K" for "k".
|
|
4807
|
+
*/
|
|
4808
|
+
const extractKeywords = (regex) => {
|
|
4809
|
+
if (regex.flags.includes("v")) return;
|
|
4810
|
+
const parser = {
|
|
4811
|
+
source: regex.source,
|
|
4812
|
+
ignoreCase: regex.flags.includes("i"),
|
|
4813
|
+
index: 0
|
|
4814
|
+
};
|
|
4815
|
+
try {
|
|
4816
|
+
const alternatives = parseAlternatives(parser);
|
|
4817
|
+
if (parser.index !== regex.source.length) return;
|
|
4818
|
+
return unionOfAlternatives(alternatives);
|
|
4819
|
+
} catch (error) {
|
|
4820
|
+
if (error instanceof UnsupportedSyntax) return;
|
|
4821
|
+
throw error;
|
|
4822
|
+
}
|
|
4823
|
+
};
|
|
4824
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/builtin/rules/pattern/user-patterns.js
|
|
4825
|
+
/**
|
|
4826
|
+
* Return true if the file path matches the globs, in the same way as `micromatch([filePath], globs).length > 0`.
|
|
4827
|
+
* A negated glob (starting with "!") excludes the path, and a later positive glob includes it again.
|
|
4828
|
+
* If all globs are negated, any path that none of them excludes matches.
|
|
4829
|
+
* This is the algorithm of micromatch() with picomatch, so that the rule does not need micromatch.
|
|
4830
|
+
*/
|
|
4831
|
+
const matchFilePathGlobs = (filePath, globs) => {
|
|
4832
|
+
let kept = false;
|
|
4833
|
+
let omitted = false;
|
|
4834
|
+
let negatives = 0;
|
|
4835
|
+
for (const glob of globs) {
|
|
4836
|
+
const isMatch = (0, import_picomatch.default)(glob, { dot: true }, true);
|
|
4837
|
+
const negated = Boolean(isMatch.state?.negated || isMatch.state?.negatedExtglob);
|
|
4838
|
+
if (negated) negatives++;
|
|
4839
|
+
const matched = isMatch(filePath);
|
|
4840
|
+
if (!(negated ? !matched : matched)) continue;
|
|
4841
|
+
if (negated) omitted = true;
|
|
4842
|
+
else {
|
|
4843
|
+
omitted = false;
|
|
4844
|
+
kept = true;
|
|
4845
|
+
}
|
|
4846
|
+
}
|
|
4847
|
+
return (negatives === globs.length || kept) && !omitted;
|
|
4848
|
+
};
|
|
4849
|
+
const messages$10 = { PATTERN: {
|
|
4850
|
+
en: (props) => `found matching ${props.PATTERN_NAME}: ${props.CREDENTIAL}`,
|
|
4851
|
+
ja: (props) => `${props.PATTERN_NAME}にマッチするパターンが見つかりました: ${props.CREDENTIAL}`
|
|
4852
|
+
} };
|
|
4853
|
+
const collectPatternStrings = (entry) => {
|
|
4854
|
+
if (entry.patterns && entry.patterns.length > 0) return entry.patterns;
|
|
4855
|
+
if (entry.pattern) return [entry.pattern];
|
|
4856
|
+
return [];
|
|
4857
|
+
};
|
|
4858
|
+
/**
|
|
4859
|
+
* Return the keywords of the entry, or undefined if the entry has no `keywords`.
|
|
4860
|
+
* `[]` means that the patterns have no keywords.
|
|
4861
|
+
*/
|
|
4862
|
+
const keywordsOfEntry = (entry) => {
|
|
4863
|
+
const keywords = entry.keywords;
|
|
4864
|
+
if (keywords === void 0) return;
|
|
4865
|
+
if (!Array.isArray(keywords)) throw new Error(`Pattern "${entry.name}" has "keywords" that is not an array.`);
|
|
4866
|
+
return keywords.map((keyword) => {
|
|
4867
|
+
if (typeof keyword === "object" && keyword !== null) try {
|
|
4868
|
+
const guarded = parseKeywordObject(keyword);
|
|
4869
|
+
return {
|
|
4870
|
+
keyword: guarded.keyword,
|
|
4871
|
+
after: guarded.after
|
|
4872
|
+
};
|
|
4873
|
+
} catch (error) {
|
|
4874
|
+
throw new Error(`Pattern "${entry.name}" has a keyword that is not supported.
|
|
4875
|
+
${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
4876
|
+
}
|
|
4877
|
+
if (normalizeKeyword(keyword) === void 0) throw new Error(`Pattern "${entry.name}" has a keyword that is not a non-empty ASCII string or a keyword with a guard: ${JSON.stringify(keyword)}`);
|
|
4878
|
+
return keyword;
|
|
4879
|
+
});
|
|
4880
|
+
};
|
|
4881
|
+
const assertEntry = (entry) => {
|
|
4882
|
+
if (entry.patterns && entry.patterns.length > 0 && entry.pattern) throw new Error(`Pattern "${entry.name}" cannot have both "patterns" and "pattern" specified. Use "patterns" array instead.`);
|
|
4883
|
+
const hasPatterns = entry.patterns && entry.patterns.length > 0 || entry.pattern;
|
|
4884
|
+
const hasFilePathGlobs = entry.filePathGlobs && entry.filePathGlobs.length > 0;
|
|
4885
|
+
if (!hasPatterns && !hasFilePathGlobs) throw new Error(`Pattern "${entry.name}" must have either "patterns", "pattern" (deprecated), or "filePathGlobs" specified`);
|
|
4886
|
+
};
|
|
4887
|
+
/**
|
|
4888
|
+
* Convert the options of `@secretlint/secretlint-rule-pattern` to patterns.
|
|
4889
|
+
* It throws if an entry is not valid, so that no file is linted with a wrong configuration.
|
|
4890
|
+
*/
|
|
4891
|
+
const compileUserPatterns = (options) => {
|
|
4892
|
+
const globalAllows = options.allows ?? [];
|
|
4893
|
+
return (options.patterns ?? []).flatMap((entry) => {
|
|
4894
|
+
assertEntry(entry);
|
|
4895
|
+
const entryKeywords = keywordsOfEntry(entry);
|
|
4896
|
+
const filePathGlobs = entry.filePathGlobs && entry.filePathGlobs.length > 0 ? entry.filePathGlobs : void 0;
|
|
4897
|
+
const filePathFilter = filePathGlobs ? (filePath) => !filePath || matchFilePathGlobs(filePath, filePathGlobs) : void 0;
|
|
4898
|
+
const patternStrings = collectPatternStrings(entry);
|
|
4899
|
+
if (patternStrings.length === 0) return [{
|
|
4900
|
+
name: entry.name,
|
|
4901
|
+
filePathFilter,
|
|
4902
|
+
pathOnly: true,
|
|
4903
|
+
pattern: {
|
|
4904
|
+
pattern: /(?:)/,
|
|
4905
|
+
report(_match, context) {
|
|
4906
|
+
const t = context.createTranslator(messages$10);
|
|
4907
|
+
context.report({
|
|
4908
|
+
message: t("PATTERN", {
|
|
4909
|
+
PATTERN_NAME: entry.name,
|
|
4910
|
+
CREDENTIAL: basename$1(context.source.filePath || "")
|
|
4911
|
+
}),
|
|
4912
|
+
range: [0, context.source.content.length]
|
|
4913
|
+
});
|
|
4914
|
+
}
|
|
4915
|
+
}
|
|
4916
|
+
}];
|
|
4917
|
+
const allows = [...globalAllows, ...entry.allows ?? []];
|
|
4918
|
+
return patternStrings.map((patternString) => {
|
|
4919
|
+
const regex = (0, import_regexp_string_matcher.createRegExp)(patternString);
|
|
4920
|
+
const keywords = entryKeywords ?? extractKeywords(regex);
|
|
4921
|
+
return {
|
|
4922
|
+
name: entry.name,
|
|
4923
|
+
filePathFilter,
|
|
4924
|
+
pathOnly: false,
|
|
4925
|
+
pattern: {
|
|
4926
|
+
pattern: regex,
|
|
4927
|
+
...keywords && keywords.length > 0 ? { keywords } : {},
|
|
4928
|
+
scope: "file",
|
|
4929
|
+
report(match, context) {
|
|
4930
|
+
if (allows.length > 0 && (0, import_regexp_string_matcher.matchPatterns)(match.text, allows).length > 0) return;
|
|
4931
|
+
const t = context.createTranslator(messages$10);
|
|
4932
|
+
context.report({
|
|
4933
|
+
message: t("PATTERN", {
|
|
4934
|
+
PATTERN_NAME: entry.name,
|
|
4935
|
+
CREDENTIAL: match.text
|
|
4936
|
+
}),
|
|
4937
|
+
range: match.range
|
|
4938
|
+
});
|
|
4939
|
+
}
|
|
4940
|
+
}
|
|
4941
|
+
};
|
|
4942
|
+
});
|
|
4943
|
+
});
|
|
4944
|
+
};
|
|
4945
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/builtin/rules/pattern/index.js
|
|
4946
|
+
/**
|
|
4947
|
+
* Without `options.patterns`, the rule adds nothing to the lint.
|
|
4948
|
+
*/
|
|
4949
|
+
const creator$1 = {
|
|
4950
|
+
messages: messages$10,
|
|
4951
|
+
meta: {
|
|
4952
|
+
id: "@secretlint/secretlint-rule-pattern",
|
|
4953
|
+
recommended: false,
|
|
4954
|
+
type: "scanner",
|
|
4955
|
+
supportedContentTypes: ["text"]
|
|
4956
|
+
},
|
|
4957
|
+
patterns: []
|
|
4958
|
+
};
|
|
4959
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/LintPlan.js
|
|
4960
|
+
const debug$1 = (0, import_src.default)("@secretlint/core");
|
|
4961
|
+
const isRulePreset = (ruleDescriptor) => {
|
|
4962
|
+
return ruleDescriptor.rule.meta.type === "preset";
|
|
4963
|
+
};
|
|
4964
|
+
const isRule = (ruleDescriptor) => {
|
|
4965
|
+
return ruleDescriptor.rule.meta.type === "scanner";
|
|
4966
|
+
};
|
|
4967
|
+
/**
|
|
4968
|
+
* Normalize keywords.
|
|
4969
|
+
* Return undefined if the pre-filter can not be used: no keywords, empty keywords, or an invalid keyword.
|
|
4970
|
+
*/
|
|
4971
|
+
const normalizeKeywords = (keywords) => {
|
|
4972
|
+
if (!Array.isArray(keywords) || keywords.length === 0) return;
|
|
4973
|
+
const normalized = [];
|
|
4974
|
+
for (const keyword of keywords) {
|
|
4975
|
+
const normalizedKeyword = normalizeKeyword(keyword);
|
|
4976
|
+
if (normalizedKeyword === void 0) return;
|
|
4977
|
+
normalized.push(normalizedKeyword);
|
|
4978
|
+
}
|
|
4979
|
+
return normalized;
|
|
4980
|
+
};
|
|
4981
|
+
/**
|
|
4982
|
+
* Normalize `keywords` of a pattern. An item is a string, or a keyword object `{ keyword, after }`.
|
|
4983
|
+
* Return undefined if the pre-filter can not be used: no keywords, empty keywords, or an invalid string.
|
|
4984
|
+
* It throws if a keyword object is not supported: running the pattern without the guard would hide the mistake
|
|
4985
|
+
* as a slow lint, and a guard of a newer secretlint must not be read in another way.
|
|
4986
|
+
*/
|
|
4987
|
+
const normalizePatternKeywords = (ruleId, keywords) => {
|
|
4988
|
+
if (!Array.isArray(keywords) || keywords.length === 0) return;
|
|
4989
|
+
const normalized = keywords.map((item) => {
|
|
4990
|
+
if (typeof item === "object" && item !== null) try {
|
|
4991
|
+
const guarded = parseKeywordObject(item);
|
|
4992
|
+
return {
|
|
4993
|
+
keyword: guarded.keyword.toLowerCase(),
|
|
4994
|
+
guard: guarded.guard,
|
|
4995
|
+
after: guarded.after
|
|
4996
|
+
};
|
|
4997
|
+
} catch (error) {
|
|
4998
|
+
throw new Error(`The rule "${ruleId}" has a pattern with a keyword that is not supported.
|
|
4999
|
+
${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
5000
|
+
}
|
|
5001
|
+
const keyword = normalizeKeyword(item);
|
|
5002
|
+
return keyword === void 0 ? void 0 : {
|
|
5003
|
+
keyword,
|
|
5004
|
+
guard: void 0,
|
|
5005
|
+
after: void 0
|
|
5006
|
+
};
|
|
5007
|
+
});
|
|
5008
|
+
if (normalized.includes(void 0)) return;
|
|
5009
|
+
return normalized;
|
|
5010
|
+
};
|
|
5011
|
+
/**
|
|
5012
|
+
* Return a copy of the regular expression with the "g" flag.
|
|
5013
|
+
* The copy does not share `lastIndex` with the regular expression of the rule.
|
|
5014
|
+
*/
|
|
5015
|
+
const toGlobalRegExp = (pattern) => {
|
|
5016
|
+
return new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`);
|
|
5017
|
+
};
|
|
5018
|
+
/**
|
|
5019
|
+
* Return a copy of the regular expression without the "g" and "y" flags.
|
|
5020
|
+
* `test()` of the copy does not read or write `lastIndex`, so it has no state.
|
|
5021
|
+
*/
|
|
5022
|
+
const toStatelessRegExp = (pattern) => {
|
|
5023
|
+
return new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ""));
|
|
5024
|
+
};
|
|
5025
|
+
/**
|
|
5026
|
+
* The properties of a pattern that this version of secretlint knows.
|
|
5027
|
+
*/
|
|
5028
|
+
const KNOWN_PATTERN_PROPERTIES = /* @__PURE__ */ new Set([
|
|
5029
|
+
"pattern",
|
|
5030
|
+
"keywords",
|
|
5031
|
+
"scope",
|
|
5032
|
+
"when",
|
|
5033
|
+
"report"
|
|
5034
|
+
]);
|
|
5035
|
+
/**
|
|
5036
|
+
* Throw if the pattern has a property that this version of secretlint does not know.
|
|
5037
|
+
* A rule is data, and a newer rule may use a property that changes what the pattern matches.
|
|
5038
|
+
* Ignoring the property would change the result silently, so it is an error.
|
|
5039
|
+
* A new property must have a new name: the meaning of a known property is never changed.
|
|
5040
|
+
*/
|
|
5041
|
+
const assertKnownPatternProperties = (rule, pattern) => {
|
|
5042
|
+
const unknownProperties = Object.keys(pattern).filter((property) => !KNOWN_PATTERN_PROPERTIES.has(property));
|
|
5043
|
+
if (unknownProperties.length > 0) throw new Error(`The rule "${rule.meta.id}" has a pattern with unknown properties: ${unknownProperties.join(", ")}
|
|
5044
|
+
This version of secretlint does not support the properties. Please update secretlint.`);
|
|
5045
|
+
const scope = pattern.scope;
|
|
5046
|
+
if (scope !== void 0 && scope !== "line" && scope !== "file") throw new Error(`The rule "${rule.meta.id}" has a pattern with unknown scope: ${JSON.stringify(scope)}
|
|
5047
|
+
The scope should be "line" or "file". If it is a scope of a newer secretlint, please update secretlint.`);
|
|
5048
|
+
};
|
|
5049
|
+
/**
|
|
5050
|
+
* `when` of a pattern refers to a boolean option of the rule as `options.<name>`, with or without "!" before it.
|
|
5051
|
+
* Other strings are an error, so that a `when` of a newer secretlint, such as an expression with another operator
|
|
5052
|
+
* or a value other than the options, never runs on this secretlint with a different result.
|
|
5053
|
+
*/
|
|
5054
|
+
const WHEN_PATTERN = /^(!?)options\.([A-Za-z_$][A-Za-z0-9_$]*)$/;
|
|
5055
|
+
/**
|
|
5056
|
+
* Return true if the pattern is enabled for the options of the rule.
|
|
5057
|
+
* - `when: "options.name"`: enabled only if the option is true
|
|
5058
|
+
* - `when: "!options.name"`: enabled unless the option is true
|
|
5059
|
+
* An option that is not set is false.
|
|
5060
|
+
*/
|
|
5061
|
+
const isEnabledPattern = (rule, pattern, options) => {
|
|
5062
|
+
const when = pattern.when;
|
|
5063
|
+
if (when === void 0) return true;
|
|
5064
|
+
const matched = typeof when === "string" ? WHEN_PATTERN.exec(when) : null;
|
|
5065
|
+
if (!matched) throw new Error(`The rule "${rule.meta.id}" has a pattern whose \`when\` is not supported: ${JSON.stringify(when) ?? typeof when}
|
|
5066
|
+
\`when\` should be "options.<name>" or "!options.<name>", where <name> is a boolean option of the rule.
|
|
5067
|
+
If it is a \`when\` of a newer secretlint, please update secretlint.`);
|
|
5068
|
+
const isNegated = matched[1] === "!";
|
|
5069
|
+
const optionName = matched[2];
|
|
5070
|
+
const value = Object.hasOwn(options, optionName) ? options[optionName] : void 0;
|
|
5071
|
+
if (value !== void 0 && typeof value !== "boolean") throw new Error(`The option "${optionName}" of the rule "${rule.meta.id}" should be a boolean, but it is ${value === null ? "null" : typeof value}.`);
|
|
5072
|
+
const optionValue = value === true;
|
|
5073
|
+
return isNegated ? !optionValue : optionValue;
|
|
5074
|
+
};
|
|
5075
|
+
const compilePattern = (ruleId, pattern) => {
|
|
5076
|
+
const keywords = normalizePatternKeywords(ruleId, pattern.keywords);
|
|
5077
|
+
const canUseLineScope = pattern.scope === "line" && keywords !== void 0 && keywords.every((keyword) => !keyword.keyword.includes("\n"));
|
|
5078
|
+
return {
|
|
5079
|
+
source: pattern,
|
|
5080
|
+
regex: toGlobalRegExp(pattern.pattern),
|
|
5081
|
+
tester: toStatelessRegExp(pattern.pattern),
|
|
5082
|
+
scope: canUseLineScope ? "line" : "file",
|
|
5083
|
+
keywords,
|
|
5084
|
+
name: void 0,
|
|
5085
|
+
filePathFilter: void 0,
|
|
5086
|
+
pathOnly: false
|
|
5087
|
+
};
|
|
5088
|
+
};
|
|
5089
|
+
/**
|
|
5090
|
+
* Compile the patterns of the rule that are enabled for the options.
|
|
5091
|
+
* A disabled pattern is not in the plan, so its keywords are not searched and it never runs.
|
|
5092
|
+
*/
|
|
5093
|
+
const compilePatterns = (rule, options) => {
|
|
5094
|
+
if (rule === creator$1) return compileUserPatterns(options).map((userPattern) => {
|
|
5095
|
+
return {
|
|
5096
|
+
...compilePattern(rule.meta.id, userPattern.pattern),
|
|
5097
|
+
name: userPattern.name,
|
|
5098
|
+
filePathFilter: userPattern.filePathFilter,
|
|
5099
|
+
pathOnly: userPattern.pathOnly
|
|
5100
|
+
};
|
|
5101
|
+
});
|
|
5102
|
+
const patterns = rule.patterns;
|
|
5103
|
+
if (!Array.isArray(patterns)) return;
|
|
5104
|
+
patterns.forEach((pattern) => assertKnownPatternProperties(rule, pattern));
|
|
5105
|
+
return patterns.filter((pattern) => isEnabledPattern(rule, pattern, options)).map((pattern) => compilePattern(rule.meta.id, pattern));
|
|
5106
|
+
};
|
|
5107
|
+
/**
|
|
5108
|
+
* Values of the config that the plan depends on.
|
|
5109
|
+
* A config is a plain object, and it can be changed between `lintSource()` calls.
|
|
5110
|
+
*/
|
|
5111
|
+
const createConfigSnapshot = (config) => {
|
|
5112
|
+
const snapshot = [
|
|
5113
|
+
config.sharedOptions,
|
|
5114
|
+
config.rules,
|
|
5115
|
+
config.rules.length
|
|
5116
|
+
];
|
|
5117
|
+
for (const descriptor of config.rules) {
|
|
5118
|
+
snapshot.push(descriptor, descriptor.id, descriptor.rule, descriptor.options, descriptor.disabled);
|
|
5119
|
+
if (isRulePreset(descriptor)) {
|
|
5120
|
+
const presetRules = descriptor.rules;
|
|
5121
|
+
snapshot.push(presetRules);
|
|
5122
|
+
if (Array.isArray(presetRules)) {
|
|
5123
|
+
snapshot.push(presetRules.length);
|
|
5124
|
+
for (const presetRule of presetRules) snapshot.push(presetRule, presetRule.id, presetRule.options, presetRule.disabled, presetRule.severity, presetRule.allowMessageIds);
|
|
5125
|
+
}
|
|
5126
|
+
} else {
|
|
5127
|
+
const rule = descriptor;
|
|
5128
|
+
snapshot.push(rule.severity, rule.allowMessageIds);
|
|
5129
|
+
}
|
|
5130
|
+
}
|
|
5131
|
+
return snapshot;
|
|
5132
|
+
};
|
|
5133
|
+
/**
|
|
5134
|
+
* Return true if nothing that the plan depends on is changed.
|
|
5135
|
+
* This runs for each `lintSource()` call, so it compares references only:
|
|
5136
|
+
* the config, the rule descriptors, `meta.keywords` and `patterns` of the rules.
|
|
5137
|
+
* Replace these arrays and objects to change them. A change inside them is not found.
|
|
5138
|
+
*/
|
|
5139
|
+
const isFreshPlan = (plan, config) => {
|
|
5140
|
+
const rules = plan.rules;
|
|
5141
|
+
for (let i = 0; i < rules.length; i++) {
|
|
5142
|
+
const planRule = rules[i];
|
|
5143
|
+
const creator = planRule.descriptorRule.rule;
|
|
5144
|
+
if (creator.meta.keywords !== planRule.metaKeywords || creator.patterns !== planRule.metaPatterns) return false;
|
|
5145
|
+
}
|
|
5146
|
+
const snapshot = plan.snapshot;
|
|
5147
|
+
const current = createConfigSnapshot(config);
|
|
5148
|
+
if (snapshot.length !== current.length) return false;
|
|
5149
|
+
for (let i = 0; i < snapshot.length; i++) if (snapshot[i] !== current[i]) return false;
|
|
5150
|
+
return true;
|
|
5151
|
+
};
|
|
5152
|
+
const createLintPlan = (config, locale) => {
|
|
5153
|
+
const registered = /* @__PURE__ */ new Set();
|
|
5154
|
+
const rules = [];
|
|
5155
|
+
const sharedOptions = config.sharedOptions ?? {};
|
|
5156
|
+
const registerRule = (descriptorRule, ruleParentId) => {
|
|
5157
|
+
if (registered.has(descriptorRule.id)) throw new Error(`rule.id:${descriptorRule.id} is already registered.
|
|
5158
|
+
|
|
5159
|
+
Duplicated rule.id is something wrong in .secretlintrc.
|
|
5160
|
+
`);
|
|
5161
|
+
registered.add(descriptorRule.id);
|
|
5162
|
+
rules.push({
|
|
5163
|
+
descriptorRule,
|
|
5164
|
+
ruleParentId,
|
|
5165
|
+
keywords: normalizeKeywords(descriptorRule.rule.meta.keywords),
|
|
5166
|
+
patterns: compilePatterns(descriptorRule.rule, descriptorRule.options || {}),
|
|
5167
|
+
metaKeywords: descriptorRule.rule.meta.keywords,
|
|
5168
|
+
metaPatterns: descriptorRule.rule.patterns
|
|
5169
|
+
});
|
|
5170
|
+
};
|
|
5171
|
+
secretLintProfiler.mark({ type: "@core>setup-rules::start" });
|
|
5172
|
+
for (const descriptor of config.rules) {
|
|
5173
|
+
const ruleId = descriptor.id;
|
|
5174
|
+
if (descriptor.disabled) {
|
|
5175
|
+
debug$1("Skip registerRule %s, because it is disabled", ruleId);
|
|
5176
|
+
continue;
|
|
5177
|
+
}
|
|
5178
|
+
debug$1("registerRule %s", ruleId);
|
|
5179
|
+
secretLintProfiler.mark({
|
|
5180
|
+
type: "@core>setup-rule::start",
|
|
5181
|
+
id: descriptor.rule.meta.id
|
|
5182
|
+
});
|
|
5183
|
+
if (isRulePreset(descriptor)) {
|
|
5184
|
+
const presetRules = descriptor.rules || [];
|
|
5185
|
+
if (!Array.isArray(presetRules)) {
|
|
5186
|
+
console.error(`${descriptor.id}:PresetRules is invalid format`, presetRules);
|
|
5187
|
+
throw new Error("preset's rules should be an array of rule definitions");
|
|
5188
|
+
}
|
|
5189
|
+
const context = {
|
|
5190
|
+
sharedOptions,
|
|
5191
|
+
registerRule(rule, defaultValue) {
|
|
5192
|
+
const descriptorRule = presetRules.find((descriptorRule) => {
|
|
5193
|
+
return descriptorRule.id === rule.meta.id;
|
|
5194
|
+
});
|
|
5195
|
+
if (descriptorRule?.disabled) {
|
|
5196
|
+
debug$1("Skip registerRule %s in %s, because it is disabled", rule.meta.id, descriptor.id);
|
|
5197
|
+
return;
|
|
5198
|
+
}
|
|
5199
|
+
registerRule({
|
|
5200
|
+
...defaultValue ?? {},
|
|
5201
|
+
...descriptorRule,
|
|
5202
|
+
id: rule.meta.id,
|
|
5203
|
+
options: descriptorRule ? descriptorRule.options : void 0,
|
|
5204
|
+
rule,
|
|
5205
|
+
disabled: descriptorRule ? descriptorRule.disabled : void 0,
|
|
5206
|
+
allowMessageIds: descriptorRule ? descriptorRule.allowMessageIds : void 0,
|
|
5207
|
+
severity: descriptorRule ? descriptorRule.severity : void 0
|
|
5208
|
+
}, descriptor.id);
|
|
5209
|
+
}
|
|
5210
|
+
};
|
|
5211
|
+
descriptor.rule.create(context, descriptor.options || []);
|
|
5212
|
+
} else if (isRule(descriptor)) registerRule(descriptor, void 0);
|
|
5213
|
+
else throw new Error(`Unknown descriptor type: ${descriptor}`);
|
|
5214
|
+
secretLintProfiler.mark({
|
|
5215
|
+
type: "@core>setup-rule::end",
|
|
5216
|
+
id: descriptor.rule.meta.id
|
|
5217
|
+
});
|
|
5218
|
+
}
|
|
5219
|
+
secretLintProfiler.mark({ type: "@core>setup-rules::end" });
|
|
5220
|
+
const allowMessageIds = [];
|
|
5221
|
+
for (const { descriptorRule } of rules) {
|
|
5222
|
+
const ruleId = descriptorRule.rule.meta.id;
|
|
5223
|
+
descriptorRule.allowMessageIds?.forEach((messageId) => {
|
|
5224
|
+
allowMessageIds.push({
|
|
5225
|
+
messageId,
|
|
5226
|
+
ruleId
|
|
5227
|
+
});
|
|
5228
|
+
});
|
|
5229
|
+
}
|
|
5230
|
+
return {
|
|
5231
|
+
config,
|
|
5232
|
+
locale,
|
|
5233
|
+
rules,
|
|
5234
|
+
allowMessageIds,
|
|
5235
|
+
views: /* @__PURE__ */ new Map(),
|
|
5236
|
+
snapshot: createConfigSnapshot(config)
|
|
5237
|
+
};
|
|
5238
|
+
};
|
|
5239
|
+
const supportContentType = (rule, contentType) => {
|
|
5240
|
+
if (contentType === "unknown") return true;
|
|
5241
|
+
const supportedContentTypes = rule.descriptorRule.rule.meta.supportedContentTypes;
|
|
5242
|
+
return supportedContentTypes.includes("all") || supportedContentTypes.includes(contentType);
|
|
5243
|
+
};
|
|
5244
|
+
const createView = (plan, contentType) => {
|
|
5245
|
+
const targets = plan.rules.filter((rule) => supportContentType(rule, contentType));
|
|
5246
|
+
const keywordsOfRule = (rule) => {
|
|
5247
|
+
return contentType === "text" ? rule.keywords : void 0;
|
|
5248
|
+
};
|
|
5249
|
+
const keywordKey = (keyword) => JSON.stringify([keyword.keyword, keywordGuardKey(keyword.guard)]);
|
|
5250
|
+
const withoutGuard = (keywords) => {
|
|
5251
|
+
return keywords?.map((keyword) => ({
|
|
5252
|
+
keyword,
|
|
5253
|
+
guard: void 0,
|
|
5254
|
+
after: void 0
|
|
5255
|
+
}));
|
|
5256
|
+
};
|
|
5257
|
+
const allKeywords = /* @__PURE__ */ new Map();
|
|
5258
|
+
const addKeywords = (keywords) => {
|
|
5259
|
+
keywords?.forEach((keyword) => {
|
|
5260
|
+
allKeywords.set(keywordKey(keyword), keyword);
|
|
5261
|
+
});
|
|
5262
|
+
};
|
|
5263
|
+
for (const rule of targets) if (rule.patterns) rule.patterns.forEach((pattern) => addKeywords(pattern.keywords));
|
|
5264
|
+
else addKeywords(withoutGuard(keywordsOfRule(rule)));
|
|
5265
|
+
const sortedKeys = [...allKeywords.keys()].sort();
|
|
5266
|
+
const matcherKeywords = sortedKeys.map((key) => allKeywords.get(key).keyword);
|
|
5267
|
+
const matcherGuards = sortedKeys.map((key) => allKeywords.get(key).guard);
|
|
5268
|
+
const matcher = sortedKeys.length > 0 ? getKeywordMatcher(matcherKeywords, matcherGuards) : void 0;
|
|
5269
|
+
const indexOf = new Map(sortedKeys.map((key, index) => [key, index]));
|
|
5270
|
+
const toIndexes = (keywords) => {
|
|
5271
|
+
return keywords?.map((keyword) => indexOf.get(keywordKey(keyword)));
|
|
5272
|
+
};
|
|
5273
|
+
const patternIndexes = new Map(targets.flatMap((rule) => rule.patterns ?? []).filter((pattern) => pattern.keywords !== void 0).map((pattern, index) => [pattern, index]));
|
|
5274
|
+
const rules = targets.map((rule) => {
|
|
5275
|
+
if (!rule.patterns) return {
|
|
5276
|
+
rule,
|
|
5277
|
+
keywordIndexes: toIndexes(withoutGuard(keywordsOfRule(rule))),
|
|
5278
|
+
patterns: void 0
|
|
5279
|
+
};
|
|
5280
|
+
return {
|
|
5281
|
+
rule,
|
|
5282
|
+
keywordIndexes: void 0,
|
|
5283
|
+
patterns: rule.patterns.map((pattern, patternNumber) => {
|
|
5284
|
+
const patternLabel = pattern.name === void 0 ? String(pattern.source.pattern) : `${pattern.name}${pattern.keywords === void 0 && !pattern.pathOnly ? " (no keywords)" : ""}`;
|
|
5285
|
+
return {
|
|
5286
|
+
profileId: `${rule.descriptorRule.rule.meta.id}#${patternNumber} ${patternLabel}`,
|
|
5287
|
+
index: patternIndexes.get(pattern) ?? -1,
|
|
5288
|
+
regex: pattern.regex,
|
|
5289
|
+
tester: pattern.tester,
|
|
5290
|
+
scope: pattern.scope,
|
|
5291
|
+
keywordIndexes: toIndexes(pattern.keywords),
|
|
5292
|
+
report: pattern.source.report,
|
|
5293
|
+
filePathFilter: pattern.filePathFilter,
|
|
5294
|
+
pathOnly: pattern.pathOnly
|
|
5295
|
+
};
|
|
5296
|
+
})
|
|
5297
|
+
};
|
|
5298
|
+
});
|
|
5299
|
+
const allPatterns = rules.flatMap((rule) => rule.patterns ?? []).filter((pattern) => !pattern.pathOnly);
|
|
5300
|
+
const keywordPatterns = allPatterns.filter((pattern) => pattern.keywordIndexes !== void 0);
|
|
5301
|
+
const linePatternsOfKeyword = (matcher?.keywords ?? []).map((_, keywordIndex) => {
|
|
5302
|
+
return keywordPatterns.filter((pattern) => {
|
|
5303
|
+
return pattern.scope === "line" && pattern.keywordIndexes.includes(keywordIndex);
|
|
5304
|
+
});
|
|
5305
|
+
});
|
|
5306
|
+
const hasAlwaysPattern = allPatterns.some((pattern) => pattern.keywordIndexes === void 0);
|
|
5307
|
+
const hasAlwaysRule = rules.some((rule) => rule.patterns === void 0 && rule.keywordIndexes === void 0);
|
|
5308
|
+
const pathPatterns = rules.flatMap((rule) => rule.patterns ?? []).filter((pattern) => pattern.pathOnly);
|
|
5309
|
+
return {
|
|
5310
|
+
rules,
|
|
5311
|
+
matcher,
|
|
5312
|
+
keywordScanPlan: matcher !== void 0 ? createKeywordScanPlan({
|
|
5313
|
+
keywords: matcherKeywords,
|
|
5314
|
+
guards: matcherGuards,
|
|
5315
|
+
requiresKeyword: !hasAlwaysPattern && !hasAlwaysRule && pathPatterns.length === 0,
|
|
5316
|
+
ruleCheck: {
|
|
5317
|
+
contentKeywordIndexes: [...rules.flatMap((rule) => rule.patterns === void 0 ? rule.keywordIndexes ?? [] : []), ...keywordPatterns.flatMap((pattern) => {
|
|
5318
|
+
return pattern.scope === "file" ? pattern.keywordIndexes : [];
|
|
5319
|
+
})],
|
|
5320
|
+
linePatterns: keywordPatterns.filter((pattern) => pattern.scope === "line").map((pattern) => ({
|
|
5321
|
+
source: pattern.tester.source,
|
|
5322
|
+
flags: pattern.tester.flags,
|
|
5323
|
+
keywordIndexes: pattern.keywordIndexes,
|
|
5324
|
+
profileId: pattern.profileId
|
|
5325
|
+
}))
|
|
5326
|
+
}
|
|
5327
|
+
}) : void 0,
|
|
5328
|
+
keywordPatterns,
|
|
5329
|
+
linePatternsOfKeyword,
|
|
5330
|
+
hasAlwaysPattern,
|
|
5331
|
+
hasAlwaysRule,
|
|
5332
|
+
hasFilePattern: keywordPatterns.some((pattern) => pattern.scope === "file"),
|
|
5333
|
+
pathPatterns
|
|
5334
|
+
};
|
|
5335
|
+
};
|
|
5336
|
+
const getPlanView = (plan, contentType) => {
|
|
5337
|
+
const cached = plan.views.get(contentType);
|
|
5338
|
+
if (cached) return cached;
|
|
5339
|
+
const view = createView(plan, contentType);
|
|
5340
|
+
plan.views.set(contentType, view);
|
|
5341
|
+
return view;
|
|
5342
|
+
};
|
|
5343
|
+
const planCache = /* @__PURE__ */ new WeakMap();
|
|
5344
|
+
/**
|
|
5345
|
+
* Return the plan for the config.
|
|
5346
|
+
* The plan is cached by the config object, and it is created again if the config or a rule is changed.
|
|
5347
|
+
*/
|
|
5348
|
+
const getLintPlan = (config, locale) => {
|
|
5349
|
+
const plans = planCache.get(config);
|
|
5350
|
+
const cached = plans?.get(locale);
|
|
5351
|
+
if (cached && isFreshPlan(cached, config)) return cached;
|
|
5352
|
+
const plan = createLintPlan(config, locale);
|
|
5353
|
+
if (plans) plans.set(locale, plan);
|
|
5354
|
+
else planCache.set(config, /* @__PURE__ */ new Map([[locale, plan]]));
|
|
5355
|
+
return plan;
|
|
5356
|
+
};
|
|
5357
|
+
// ../../node_modules/.pnpm/@secretlint+core@14.0.0_supports-color@7.2.0/node_modules/@secretlint/core/module/index.js
|
|
5358
|
+
const debug = (0, import_src.default)("@secretlint/core");
|
|
5359
|
+
const NO_KEYWORD_LINES = [];
|
|
5360
|
+
/**
|
|
5361
|
+
* Return the lines that have a keyword of each "line" scope pattern.
|
|
5362
|
+
* `hits` is the result of scanning the text.
|
|
5363
|
+
*/
|
|
5364
|
+
const collectKeywordLines = (view, hits, text) => {
|
|
5365
|
+
const lines = view.keywordPatterns.map(() => []);
|
|
5366
|
+
someKeywordLine(view, hits, (index) => index === 0 ? 0 : text.lastIndexOf("\n", index - 1) + 1, (index) => {
|
|
5367
|
+
const nextLineFeed = text.indexOf("\n", index);
|
|
5368
|
+
return nextLineFeed < 0 ? text.length : nextLineFeed + 1;
|
|
5369
|
+
}, (lineStart, lineEnd, patterns) => {
|
|
5370
|
+
patterns.forEach((pattern) => lines[pattern.index].push(lineStart, lineEnd));
|
|
5371
|
+
return false;
|
|
5372
|
+
});
|
|
5373
|
+
return lines;
|
|
5374
|
+
};
|
|
5375
|
+
/**
|
|
5376
|
+
* Call `report()` of the pattern for each match in the text.
|
|
5377
|
+
* `offset` is the index of the text in the source content.
|
|
5378
|
+
*/
|
|
5379
|
+
const runPattern = (pattern, text, offset, context) => {
|
|
5380
|
+
const profiling = secretLintProfiler.isEnabled;
|
|
5381
|
+
const startTime = profiling ? secretLintProfiler.now() : 0;
|
|
5382
|
+
let matchCount = 0;
|
|
5383
|
+
for (const match of text.matchAll(pattern.regex)) {
|
|
5384
|
+
matchCount++;
|
|
5385
|
+
const matchedText = match[0];
|
|
5386
|
+
const startIndex = offset + match.index;
|
|
5387
|
+
pattern.report({
|
|
5388
|
+
text: matchedText,
|
|
5389
|
+
range: [startIndex, startIndex + matchedText.length],
|
|
5390
|
+
captures: match,
|
|
5391
|
+
groups: match.groups
|
|
5392
|
+
}, context);
|
|
5393
|
+
}
|
|
5394
|
+
if (profiling) {
|
|
5395
|
+
secretLintProfiler.record("@core>pattern", pattern.profileId, startTime);
|
|
5396
|
+
if (matchCount > 0) secretLintProfiler.count("@core>pattern-match", pattern.profileId, matchCount);
|
|
5397
|
+
}
|
|
5398
|
+
};
|
|
5399
|
+
/**
|
|
5400
|
+
* Call `report()` of a path pattern once for the file, with the whole content as the match
|
|
5401
|
+
*/
|
|
5402
|
+
const reportPath = (pattern, content, context) => {
|
|
5403
|
+
const startTime = secretLintProfiler.isEnabled ? secretLintProfiler.now() : 0;
|
|
5404
|
+
pattern.report({
|
|
5405
|
+
text: content,
|
|
5406
|
+
range: [0, content.length],
|
|
5407
|
+
captures: [content],
|
|
5408
|
+
groups: void 0
|
|
5409
|
+
}, context);
|
|
5410
|
+
secretLintProfiler.record("@core>pattern", pattern.profileId, startTime);
|
|
5411
|
+
};
|
|
5412
|
+
/**
|
|
5413
|
+
* Add the places of the keywords with a guard to the profile.
|
|
5414
|
+
* The matcher counts them while the profiler is enabled.
|
|
5415
|
+
*/
|
|
5416
|
+
const recordGuardCounts = (matcher) => {
|
|
5417
|
+
for (const { keywordIndex, found, met } of matcher.takeGuardCounts()) {
|
|
5418
|
+
const id = formatGuardedKeyword(matcher.keywords[keywordIndex], matcher.guards[keywordIndex]);
|
|
5419
|
+
secretLintProfiler.count("@core>keyword-guard", id, found);
|
|
5420
|
+
secretLintProfiler.count("@core>keyword-guard-met", id, met);
|
|
5421
|
+
}
|
|
5422
|
+
};
|
|
5423
|
+
/**
|
|
5424
|
+
* 1. Scan the bytes once for the keywords of all rules.
|
|
5425
|
+
* 2. Check the patterns on the lines that have a keyword, without decoding the whole content.
|
|
5426
|
+
*/
|
|
5427
|
+
const checkBytes = (view, bytes, keywordScanResult) => {
|
|
5428
|
+
const matcher = view.matcher;
|
|
5429
|
+
if (!matcher) return;
|
|
5430
|
+
const profiling = secretLintProfiler.isEnabled;
|
|
5431
|
+
const found = (keywordIndexes) => {
|
|
5432
|
+
return () => {
|
|
5433
|
+
return view.keywordPatterns.some((pattern) => {
|
|
5434
|
+
return pattern.scope === "file" && isKeywordFound(pattern.keywordIndexes, keywordIndexes);
|
|
5435
|
+
});
|
|
5436
|
+
};
|
|
5437
|
+
};
|
|
5438
|
+
if (keywordScanResult !== void 0 && keywordScanResult.planId === view.keywordScanPlan?.id) {
|
|
5439
|
+
const hasFilePatternKeyword = found(keywordScanResult.found);
|
|
5440
|
+
return {
|
|
5441
|
+
found: keywordScanResult.found,
|
|
5442
|
+
hasKeyword: keywordScanResult.hasKeyword,
|
|
5443
|
+
runsPatterns: view.hasAlwaysPattern || keywordScanResult.hasKeyword && (view.hasFilePattern && hasFilePatternKeyword() || keywordScanResult.lineMatched)
|
|
5444
|
+
};
|
|
5445
|
+
}
|
|
5446
|
+
const contentStart = hasUtf8BOM(bytes) ? 3 : 0;
|
|
5447
|
+
const scanStartTime = profiling ? secretLintProfiler.now() : 0;
|
|
5448
|
+
matcher.setGuardCounting(profiling);
|
|
5449
|
+
const hits = matcher.scan(bytes, contentStart);
|
|
5450
|
+
if (profiling) {
|
|
5451
|
+
secretLintProfiler.record("@core>keyword-scan", void 0, scanStartTime);
|
|
5452
|
+
recordGuardCounts(matcher);
|
|
5453
|
+
}
|
|
5454
|
+
const hasKeyword = hits.count > 0;
|
|
5455
|
+
const hasFilePatternKeyword = found(hits.found);
|
|
5456
|
+
const hasLineMatch = () => {
|
|
5457
|
+
if (!profiling) return hasLineMatchInBytes(view, hits, bytes, contentStart);
|
|
5458
|
+
const startTime = secretLintProfiler.now();
|
|
5459
|
+
const matched = hasLineMatchInBytes(view, hits, bytes, contentStart, (pattern, line) => {
|
|
5460
|
+
const testStartTime = secretLintProfiler.now();
|
|
5461
|
+
const lineMatched = pattern.tester.test(line);
|
|
5462
|
+
secretLintProfiler.record("@core>pattern-line-test", pattern.profileId, testStartTime);
|
|
5463
|
+
return lineMatched;
|
|
5464
|
+
});
|
|
5465
|
+
secretLintProfiler.record("@core>line-check", void 0, startTime);
|
|
5466
|
+
return matched;
|
|
5467
|
+
};
|
|
5468
|
+
const runsPatterns = view.hasAlwaysPattern || hasKeyword && (view.hasFilePattern && hasFilePatternKeyword() || hasLineMatch());
|
|
5469
|
+
return {
|
|
5470
|
+
found: hits.found,
|
|
5471
|
+
hasKeyword,
|
|
5472
|
+
runsPatterns
|
|
5473
|
+
};
|
|
5474
|
+
};
|
|
5475
|
+
/**
|
|
5476
|
+
* Create the result of the lint.
|
|
5477
|
+
*
|
|
5478
|
+
* The result does not have the content of the source.
|
|
5479
|
+
* Most files have no message, and their bytes are never decoded: decoding them only for the result
|
|
5480
|
+
* would cost more than the lint. The caller has the source, and it can pass the content to a formatter.
|
|
5481
|
+
*/
|
|
5482
|
+
const createResult = (source, messages) => {
|
|
5483
|
+
return {
|
|
5484
|
+
filePath: source.filePath,
|
|
5485
|
+
sourceContentType: source.contentType,
|
|
5486
|
+
messages
|
|
5487
|
+
};
|
|
5488
|
+
};
|
|
5489
|
+
/**
|
|
5490
|
+
* Call `create()` of the rule that has no patterns.
|
|
5491
|
+
*/
|
|
5492
|
+
const createHandler = (descriptorRule, context) => {
|
|
5493
|
+
const create = descriptorRule.rule.create;
|
|
5494
|
+
if (typeof create !== "function") throw new Error(`The rule should have \`create\` function or \`patterns\`: ${descriptorRule.id}`);
|
|
5495
|
+
return create.call(descriptorRule.rule, context, descriptorRule.options || {});
|
|
5496
|
+
};
|
|
5497
|
+
const lintWithPlan = (plan, source, options, keywordScanResult) => {
|
|
5498
|
+
const contentType = source.contentType;
|
|
5499
|
+
const view = getPlanView(plan, contentType);
|
|
5500
|
+
const matcher = view.matcher;
|
|
5501
|
+
const bytes = source.contentBytes;
|
|
5502
|
+
const bytesCheck = bytes === void 0 ? void 0 : checkBytes(view, bytes, keywordScanResult);
|
|
5503
|
+
const isPathPatternTarget = (pattern) => {
|
|
5504
|
+
return pattern.filePathFilter === void 0 || pattern.filePathFilter(source.filePath);
|
|
5505
|
+
};
|
|
5506
|
+
const hasPathMatch = view.pathPatterns.some(isPathPatternTarget);
|
|
5507
|
+
if (bytes !== void 0 && !bytesCheck?.hasKeyword && !view.hasAlwaysPattern && !view.hasAlwaysRule && !hasPathMatch) return Promise.resolve(createResult(source, []));
|
|
5508
|
+
const sourceCode = new SecretLintSourceCodeImpl({
|
|
5509
|
+
content: () => source.content,
|
|
5510
|
+
filePath: source.filePath,
|
|
5511
|
+
physicalFilePath: options.noPhysicFilePath ? void 0 : source.filePath,
|
|
5512
|
+
ext: source.ext || "",
|
|
5513
|
+
contentType,
|
|
5514
|
+
contentBytes: bytes
|
|
5515
|
+
});
|
|
5516
|
+
const needsTextHits = bytes === void 0 || bytesCheck?.runsPatterns === true || view.hasAlwaysPattern;
|
|
5517
|
+
const scanText = () => {
|
|
5518
|
+
if (matcher === void 0 || !needsTextHits) return;
|
|
5519
|
+
matcher.setGuardCounting(secretLintProfiler.isEnabled);
|
|
5520
|
+
if (!secretLintProfiler.isEnabled) return matcher.scan(sourceCode.content);
|
|
5521
|
+
const content = sourceCode.content;
|
|
5522
|
+
const startTime = secretLintProfiler.now();
|
|
5523
|
+
const hits = matcher.scan(content);
|
|
5524
|
+
secretLintProfiler.record("@core>keyword-scan", void 0, startTime);
|
|
5525
|
+
if (bytes === void 0) recordGuardCounts(matcher);
|
|
5526
|
+
else matcher.takeGuardCounts();
|
|
5527
|
+
return hits;
|
|
5528
|
+
};
|
|
5529
|
+
const textHits = scanText();
|
|
5530
|
+
const found = textHits?.found ?? bytesCheck?.found;
|
|
5531
|
+
const runsContentPatterns = view.hasAlwaysPattern || (bytes === void 0 ? textHits !== void 0 && textHits.count > 0 : bytesCheck?.runsPatterns === true);
|
|
5532
|
+
const runsPatterns = runsContentPatterns || hasPathMatch;
|
|
5533
|
+
const keywordLines = runsContentPatterns && textHits !== void 0 ? collectKeywordLines(view, textHits, sourceCode.content) : NO_KEYWORD_LINES;
|
|
5534
|
+
const reportedMessages = [];
|
|
5535
|
+
const ignoredMessages = [];
|
|
5536
|
+
const contextEvents = {
|
|
5537
|
+
report(message) {
|
|
5538
|
+
reportedMessages.push(message);
|
|
5539
|
+
},
|
|
5540
|
+
ignore(message) {
|
|
5541
|
+
ignoredMessages.push(message);
|
|
5542
|
+
}
|
|
5543
|
+
};
|
|
5544
|
+
const sharedOptions = plan.config.sharedOptions ?? {};
|
|
5545
|
+
const createContext = (viewRule) => {
|
|
5546
|
+
const { descriptorRule, ruleParentId } = viewRule.rule;
|
|
5547
|
+
return createRuleContext({
|
|
5548
|
+
ruleId: descriptorRule.id,
|
|
5549
|
+
ruleParentId,
|
|
5550
|
+
severity: descriptorRule.severity,
|
|
5551
|
+
meta: descriptorRule.rule.meta,
|
|
5552
|
+
sourceCode,
|
|
5553
|
+
contextEvents,
|
|
5554
|
+
sharedOptions,
|
|
5555
|
+
locale: plan.locale
|
|
5556
|
+
});
|
|
5557
|
+
};
|
|
5558
|
+
const isKeywordInContent = (keywordIndexes) => {
|
|
5559
|
+
return found !== void 0 && isKeywordFound(keywordIndexes, found);
|
|
5560
|
+
};
|
|
5561
|
+
const rulesToRun = view.rules.filter((viewRule) => {
|
|
5562
|
+
if (viewRule.patterns) return runsPatterns;
|
|
5563
|
+
return viewRule.keywordIndexes === void 0 || isKeywordInContent(viewRule.keywordIndexes);
|
|
5564
|
+
}).map((viewRule) => {
|
|
5565
|
+
if (viewRule.patterns) return {
|
|
5566
|
+
type: "patterns",
|
|
5567
|
+
viewRule,
|
|
5568
|
+
patterns: viewRule.patterns
|
|
5569
|
+
};
|
|
5570
|
+
const descriptorRule = viewRule.rule.descriptorRule;
|
|
5571
|
+
return {
|
|
5572
|
+
type: "handler",
|
|
5573
|
+
viewRule,
|
|
5574
|
+
handler: createHandler(descriptorRule, createContext(viewRule))
|
|
5575
|
+
};
|
|
5576
|
+
});
|
|
5577
|
+
if (rulesToRun.length === 0) return Promise.resolve(createResult(source, []));
|
|
5578
|
+
/**
|
|
5579
|
+
* Return where the pattern runs: the whole content, some lines, or nowhere
|
|
5580
|
+
*/
|
|
5581
|
+
const targetsOfPattern = (pattern) => {
|
|
5582
|
+
if (pattern.filePathFilter !== void 0 && !pattern.filePathFilter(source.filePath)) return [];
|
|
5583
|
+
if (pattern.pathOnly) return "path";
|
|
5584
|
+
if (!runsContentPatterns) return [];
|
|
5585
|
+
if (pattern.keywordIndexes === void 0) return "content";
|
|
5586
|
+
if (pattern.scope === "file") return isKeywordInContent(pattern.keywordIndexes) ? "content" : [];
|
|
5587
|
+
return keywordLines[pattern.index] ?? [];
|
|
5588
|
+
};
|
|
5589
|
+
const promises = [];
|
|
5590
|
+
try {
|
|
5591
|
+
for (const ruleToRun of rulesToRun) {
|
|
5592
|
+
const viewRule = ruleToRun.viewRule;
|
|
5593
|
+
const ruleId = viewRule.rule.descriptorRule.rule.meta.id;
|
|
5594
|
+
const ruleStartTime = secretLintProfiler.isEnabled ? secretLintProfiler.now() : 0;
|
|
5595
|
+
if (ruleToRun.type === "patterns") {
|
|
5596
|
+
const targets = ruleToRun.patterns.map((pattern) => ({
|
|
5597
|
+
pattern,
|
|
5598
|
+
target: targetsOfPattern(pattern)
|
|
5599
|
+
})).filter(({ target }) => target.length > 0);
|
|
5600
|
+
if (targets.length > 0) {
|
|
5601
|
+
const content = sourceCode.content;
|
|
5602
|
+
const context = {
|
|
5603
|
+
...createContext(viewRule),
|
|
5604
|
+
options: viewRule.rule.descriptorRule.options || {},
|
|
5605
|
+
source: sourceCode
|
|
5606
|
+
};
|
|
5607
|
+
for (const { pattern, target } of targets) {
|
|
5608
|
+
if (target === "path") {
|
|
5609
|
+
reportPath(pattern, content, context);
|
|
5610
|
+
continue;
|
|
5611
|
+
}
|
|
5612
|
+
if (target === "content") {
|
|
5613
|
+
runPattern(pattern, content, 0, context);
|
|
5614
|
+
continue;
|
|
5615
|
+
}
|
|
5616
|
+
for (let i = 0; i < target.length; i += 2) {
|
|
5617
|
+
const lineStart = target[i];
|
|
5618
|
+
runPattern(pattern, content.slice(lineStart, target[i + 1]), lineStart, context);
|
|
5619
|
+
}
|
|
5620
|
+
}
|
|
5621
|
+
}
|
|
5622
|
+
secretLintProfiler.record("@core>rule-handler", ruleId, ruleStartTime);
|
|
5623
|
+
} else {
|
|
5624
|
+
const file = ruleToRun.handler.file;
|
|
5625
|
+
const returned = file ? file(sourceCode) : void 0;
|
|
5626
|
+
if (returned !== void 0 && typeof returned.then === "function") promises.push(Promise.resolve(returned).then(() => {
|
|
5627
|
+
secretLintProfiler.record("@core>rule-handler", ruleId, ruleStartTime);
|
|
5628
|
+
}));
|
|
5629
|
+
else secretLintProfiler.record("@core>rule-handler", ruleId, ruleStartTime);
|
|
5630
|
+
}
|
|
5631
|
+
}
|
|
5632
|
+
} catch (error) {
|
|
5633
|
+
return Promise.allSettled(promises).then(() => {
|
|
5634
|
+
throw error;
|
|
5635
|
+
});
|
|
5636
|
+
}
|
|
5637
|
+
const finish = () => {
|
|
5638
|
+
if (reportedMessages.length === 0) return createResult(source, []);
|
|
5639
|
+
return createResult(source, cleanupMessages({
|
|
5640
|
+
reportedMessages,
|
|
5641
|
+
ignoredMessages,
|
|
5642
|
+
allowMessageIds: plan.allowMessageIds,
|
|
5643
|
+
maskSecrets: options.maskSecrets
|
|
5644
|
+
}));
|
|
5645
|
+
};
|
|
5646
|
+
if (promises.length === 0) return Promise.resolve(finish());
|
|
5647
|
+
return Promise.all(promises).then(finish);
|
|
5648
|
+
};
|
|
5649
|
+
const lintSource = ({ source, options, keywordScanResult }) => {
|
|
5650
|
+
const startTime = secretLintProfiler.isEnabled ? secretLintProfiler.now() : 0;
|
|
5651
|
+
debug(`source filePath: %O`, source.filePath);
|
|
5652
|
+
debug(`options: %O`, options);
|
|
5653
|
+
const plan = getLintPlan(options.config, options.locale ?? "en");
|
|
5654
|
+
const promise = lintWithPlan(plan, source, {
|
|
5655
|
+
maskSecrets: options.maskSecrets ?? false,
|
|
5656
|
+
noPhysicFilePath: options.noPhysicFilePath ?? false
|
|
5657
|
+
}, keywordScanResult);
|
|
5658
|
+
if (!secretLintProfiler.isEnabled) return promise;
|
|
5659
|
+
return promise.finally(() => {
|
|
5660
|
+
secretLintProfiler.record("@core>lint", source.filePath, startTime);
|
|
5661
|
+
});
|
|
2284
5662
|
};
|
|
2285
5663
|
// ../../node_modules/.pnpm/@secretlint+secretlint-rule-preset-recommend@13.1.0/node_modules/@secretlint/secretlint-rule-preset-recommend/module/index.js
|
|
2286
5664
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|