@typespec/ts-http-runtime 0.3.1-alpha.20250825.2 → 0.3.1-alpha.20250826.2
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/browser/logger/debug.js +98 -6
- package/dist/browser/logger/debug.js.map +1 -1
- package/dist/commonjs/logger/debug.js +98 -6
- package/dist/commonjs/logger/debug.js.map +1 -1
- package/dist/esm/logger/debug.js +98 -6
- package/dist/esm/logger/debug.js.map +1 -1
- package/dist/react-native/logger/debug.js +98 -6
- package/dist/react-native/logger/debug.js.map +1 -1
- package/package.json +1 -1
|
@@ -21,14 +21,13 @@ function enable(namespaces) {
|
|
|
21
21
|
enabledString = namespaces;
|
|
22
22
|
enabledNamespaces = [];
|
|
23
23
|
skippedNamespaces = [];
|
|
24
|
-
const
|
|
25
|
-
const namespaceList = namespaces.split(",").map((ns) => ns.trim().replace(wildcard, ".*?"));
|
|
24
|
+
const namespaceList = namespaces.split(",").map((ns) => ns.trim());
|
|
26
25
|
for (const ns of namespaceList) {
|
|
27
26
|
if (ns.startsWith("-")) {
|
|
28
|
-
skippedNamespaces.push(
|
|
27
|
+
skippedNamespaces.push(ns.substring(1));
|
|
29
28
|
}
|
|
30
29
|
else {
|
|
31
|
-
enabledNamespaces.push(
|
|
30
|
+
enabledNamespaces.push(ns);
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
for (const instance of debuggers) {
|
|
@@ -40,17 +39,110 @@ function enabled(namespace) {
|
|
|
40
39
|
return true;
|
|
41
40
|
}
|
|
42
41
|
for (const skipped of skippedNamespaces) {
|
|
43
|
-
if (
|
|
42
|
+
if (namespaceMatches(namespace, skipped)) {
|
|
44
43
|
return false;
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
for (const enabledNamespace of enabledNamespaces) {
|
|
48
|
-
if (
|
|
47
|
+
if (namespaceMatches(namespace, enabledNamespace)) {
|
|
49
48
|
return true;
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
return false;
|
|
53
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Given a namespace, check if it matches a pattern.
|
|
55
|
+
* Patterns only have a single wildcard character which is *.
|
|
56
|
+
* The behavior of * is that it matches zero or more other characters.
|
|
57
|
+
*/
|
|
58
|
+
function namespaceMatches(namespace, patternToMatch) {
|
|
59
|
+
// simple case, no pattern matching required
|
|
60
|
+
if (patternToMatch.indexOf("*") === -1) {
|
|
61
|
+
return namespace === patternToMatch;
|
|
62
|
+
}
|
|
63
|
+
let pattern = patternToMatch;
|
|
64
|
+
// normalize successive * if needed
|
|
65
|
+
if (patternToMatch.indexOf("**") !== -1) {
|
|
66
|
+
const patternParts = [];
|
|
67
|
+
let lastCharacter = "";
|
|
68
|
+
for (const character of patternToMatch) {
|
|
69
|
+
if (character === "*" && lastCharacter === "*") {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
lastCharacter = character;
|
|
74
|
+
patternParts.push(character);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
pattern = patternParts.join("");
|
|
78
|
+
}
|
|
79
|
+
let namespaceIndex = 0;
|
|
80
|
+
let patternIndex = 0;
|
|
81
|
+
const patternLength = pattern.length;
|
|
82
|
+
const namespaceLength = namespace.length;
|
|
83
|
+
let lastWildcard = -1;
|
|
84
|
+
let lastWildcardNamespace = -1;
|
|
85
|
+
while (namespaceIndex < namespaceLength && patternIndex < patternLength) {
|
|
86
|
+
if (pattern[patternIndex] === "*") {
|
|
87
|
+
lastWildcard = patternIndex;
|
|
88
|
+
patternIndex++;
|
|
89
|
+
if (patternIndex === patternLength) {
|
|
90
|
+
// if wildcard is the last character, it will match the remaining namespace string
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
// now we let the wildcard eat characters until we match the next literal in the pattern
|
|
94
|
+
while (namespace[namespaceIndex] !== pattern[patternIndex]) {
|
|
95
|
+
namespaceIndex++;
|
|
96
|
+
// reached the end of the namespace without a match
|
|
97
|
+
if (namespaceIndex === namespaceLength) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// now that we have a match, let's try to continue on
|
|
102
|
+
// however, it's possible we could find a later match
|
|
103
|
+
// so keep a reference in case we have to backtrack
|
|
104
|
+
lastWildcardNamespace = namespaceIndex;
|
|
105
|
+
namespaceIndex++;
|
|
106
|
+
patternIndex++;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
else if (pattern[patternIndex] === namespace[namespaceIndex]) {
|
|
110
|
+
// simple case: literal pattern matches so keep going
|
|
111
|
+
patternIndex++;
|
|
112
|
+
namespaceIndex++;
|
|
113
|
+
}
|
|
114
|
+
else if (lastWildcard >= 0) {
|
|
115
|
+
// special case: we don't have a literal match, but there is a previous wildcard
|
|
116
|
+
// which we can backtrack to and try having the wildcard eat the match instead
|
|
117
|
+
patternIndex = lastWildcard + 1;
|
|
118
|
+
namespaceIndex = lastWildcardNamespace + 1;
|
|
119
|
+
// we've reached the end of the namespace without a match
|
|
120
|
+
if (namespaceIndex === namespaceLength) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
// similar to the previous logic, let's keep going until we find the next literal match
|
|
124
|
+
while (namespace[namespaceIndex] !== pattern[patternIndex]) {
|
|
125
|
+
namespaceIndex++;
|
|
126
|
+
if (namespaceIndex === namespaceLength) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
lastWildcardNamespace = namespaceIndex;
|
|
131
|
+
namespaceIndex++;
|
|
132
|
+
patternIndex++;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const namespaceDone = namespaceIndex === namespace.length;
|
|
140
|
+
const patternDone = patternIndex === pattern.length;
|
|
141
|
+
// this is to detect the case of an unneeded final wildcard
|
|
142
|
+
// e.g. the pattern `ab*` should match the string `ab`
|
|
143
|
+
const trailingWildCard = patternIndex === pattern.length - 1 && pattern[patternIndex] === "*";
|
|
144
|
+
return namespaceDone && (patternDone || trailingWildCard);
|
|
145
|
+
}
|
|
54
146
|
function disable() {
|
|
55
147
|
const result = enabledString || "";
|
|
56
148
|
enable("");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../../src/logger/debug.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAgE/B,MAAM,gBAAgB,GACpB,CAAC,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC;AAEpF,IAAI,aAAiC,CAAC;AACtC,IAAI,iBAAiB,GAAa,EAAE,CAAC;AACrC,IAAI,iBAAiB,GAAa,EAAE,CAAC;AACrC,MAAM,SAAS,GAAe,EAAE,CAAC;AAEjC,IAAI,gBAAgB,EAAE,CAAC;IACrB,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,QAAQ,GAAU,MAAM,CAAC,MAAM,CACnC,CAAC,SAAiB,EAAY,EAAE;IAC9B,OAAO,cAAc,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC,EACD;IACE,MAAM;IACN,OAAO;IACP,OAAO;IACP,GAAG;CACJ,CACF,CAAC;AAEF,SAAS,MAAM,CAAC,UAAkB;IAChC,aAAa,GAAG,UAAU,CAAC;IAC3B,iBAAiB,GAAG,EAAE,CAAC;IACvB,iBAAiB,GAAG,EAAE,CAAC;IACvB,MAAM,QAAQ,GAAG,KAAK,CAAC;IACvB,MAAM,aAAa,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,QAAQ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AK,EAAE;QACjD,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC;QAC3B,OAAO;QACP,GAAG,EAAE,QAAQ,CAAC,GAAG;QACjB,SAAS;QACT,MAAM;KACP,CAAC,CAAC;IAEH,SAAS,KAAK,CAAC,GAAG,IAAW;QAC3B,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACtC,CAAC;QACD,WAAW,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAE5B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,SAAS,OAAO;IACd,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QACf,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,MAAM,CAAiB,SAAiB;IAC/C,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,SAAS,EAAE,CAAC,CAAC;IACrE,WAAW,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IAC3B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,eAAe,QAAQ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { log } from \"./log.js\";\n\n/**\n * A simple mechanism for enabling logging.\n * Intended to mimic the publicly available `debug` package.\n */\nexport interface Debug {\n /**\n * Creates a new logger with the given namespace.\n */\n (namespace: string): Debugger;\n /**\n * The default log method (defaults to console)\n */\n log: (...args: any[]) => void;\n /**\n * Enables a particular set of namespaces.\n * To enable multiple separate them with commas, e.g. \"info,debug\".\n * Supports wildcards, e.g. \"typeSpecRuntime:*\"\n * Supports skip syntax, e.g. \"typeSpecRuntime:*,-typeSpecRuntime:storage:*\" will enable\n * everything under typeSpecRuntime except for things under typeSpecRuntime:storage.\n */\n enable: (namespaces: string) => void;\n /**\n * Checks if a particular namespace is enabled.\n */\n enabled: (namespace: string) => boolean;\n /**\n * Disables all logging, returns what was previously enabled.\n */\n disable: () => string;\n}\n\n/**\n * A log function that can be dynamically enabled and redirected.\n */\nexport interface Debugger {\n /**\n * Logs the given arguments to the `log` method.\n */\n (...args: any[]): void;\n /**\n * True if this logger is active and logging.\n */\n enabled: boolean;\n /**\n * Used to cleanup/remove this logger.\n */\n destroy: () => boolean;\n /**\n * The current log method. Can be overridden to redirect output.\n */\n log: (...args: any[]) => void;\n /**\n * The namespace of this logger.\n */\n namespace: string;\n /**\n * Extends this logger with a child namespace.\n * Namespaces are separated with a ':' character.\n */\n extend: (namespace: string) => Debugger;\n}\n\nconst debugEnvVariable =\n (typeof process !== \"undefined\" && process.env && process.env.DEBUG) || undefined;\n\nlet enabledString: string | undefined;\nlet enabledNamespaces: RegExp[] = [];\nlet skippedNamespaces: RegExp[] = [];\nconst debuggers: Debugger[] = [];\n\nif (debugEnvVariable) {\n enable(debugEnvVariable);\n}\n\nconst debugObj: Debug = Object.assign(\n (namespace: string): Debugger => {\n return createDebugger(namespace);\n },\n {\n enable,\n enabled,\n disable,\n log,\n },\n);\n\nfunction enable(namespaces: string): void {\n enabledString = namespaces;\n enabledNamespaces = [];\n skippedNamespaces = [];\n const wildcard = /\\*/g;\n const namespaceList = namespaces.split(\",\").map((ns) => ns.trim().replace(wildcard, \".*?\"));\n for (const ns of namespaceList) {\n if (ns.startsWith(\"-\")) {\n skippedNamespaces.push(new RegExp(`^${ns.substr(1)}$`));\n } else {\n enabledNamespaces.push(new RegExp(`^${ns}$`));\n }\n }\n for (const instance of debuggers) {\n instance.enabled = enabled(instance.namespace);\n }\n}\n\nfunction enabled(namespace: string): boolean {\n if (namespace.endsWith(\"*\")) {\n return true;\n }\n\n for (const skipped of skippedNamespaces) {\n if (skipped.test(namespace)) {\n return false;\n }\n }\n for (const enabledNamespace of enabledNamespaces) {\n if (enabledNamespace.test(namespace)) {\n return true;\n }\n }\n return false;\n}\n\nfunction disable(): string {\n const result = enabledString || \"\";\n enable(\"\");\n return result;\n}\n\nfunction createDebugger(namespace: string): Debugger {\n const newDebugger: Debugger = Object.assign(debug, {\n enabled: enabled(namespace),\n destroy,\n log: debugObj.log,\n namespace,\n extend,\n });\n\n function debug(...args: any[]): void {\n if (!newDebugger.enabled) {\n return;\n }\n if (args.length > 0) {\n args[0] = `${namespace} ${args[0]}`;\n }\n newDebugger.log(...args);\n }\n\n debuggers.push(newDebugger);\n\n return newDebugger;\n}\n\nfunction destroy(this: Debugger): boolean {\n const index = debuggers.indexOf(this);\n if (index >= 0) {\n debuggers.splice(index, 1);\n return true;\n }\n return false;\n}\n\nfunction extend(this: Debugger, namespace: string): Debugger {\n const newDebugger = createDebugger(`${this.namespace}:${namespace}`);\n newDebugger.log = this.log;\n return newDebugger;\n}\n\nexport default debugObj;\n"]}
|
|
1
|
+
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../../src/logger/debug.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAgE/B,MAAM,gBAAgB,GACpB,CAAC,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC;AAEpF,IAAI,aAAiC,CAAC;AACtC,IAAI,iBAAiB,GAAa,EAAE,CAAC;AACrC,IAAI,iBAAiB,GAAa,EAAE,CAAC;AACrC,MAAM,SAAS,GAAe,EAAE,CAAC;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,WAAW,CAAC,CAAC;IAE5B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,SAAS,OAAO;IACd,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QACf,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,MAAM,CAAiB,SAAiB;IAC/C,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,SAAS,EAAE,CAAC,CAAC;IACrE,WAAW,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IAC3B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,eAAe,QAAQ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { log } from \"./log.js\";\n\n/**\n * A simple mechanism for enabling logging.\n * Intended to mimic the publicly available `debug` package.\n */\nexport interface Debug {\n /**\n * Creates a new logger with the given namespace.\n */\n (namespace: string): Debugger;\n /**\n * The default log method (defaults to console)\n */\n log: (...args: any[]) => void;\n /**\n * Enables a particular set of namespaces.\n * To enable multiple separate them with commas, e.g. \"info,debug\".\n * Supports wildcards, e.g. \"typeSpecRuntime:*\"\n * Supports skip syntax, e.g. \"typeSpecRuntime:*,-typeSpecRuntime:storage:*\" will enable\n * everything under typeSpecRuntime except for things under typeSpecRuntime:storage.\n */\n enable: (namespaces: string) => void;\n /**\n * Checks if a particular namespace is enabled.\n */\n enabled: (namespace: string) => boolean;\n /**\n * Disables all logging, returns what was previously enabled.\n */\n disable: () => string;\n}\n\n/**\n * A log function that can be dynamically enabled and redirected.\n */\nexport interface Debugger {\n /**\n * Logs the given arguments to the `log` method.\n */\n (...args: any[]): void;\n /**\n * True if this logger is active and logging.\n */\n enabled: boolean;\n /**\n * Used to cleanup/remove this logger.\n */\n destroy: () => boolean;\n /**\n * The current log method. Can be overridden to redirect output.\n */\n log: (...args: any[]) => void;\n /**\n * The namespace of this logger.\n */\n namespace: string;\n /**\n * Extends this logger with a child namespace.\n * Namespaces are separated with a ':' character.\n */\n extend: (namespace: string) => Debugger;\n}\n\nconst debugEnvVariable =\n (typeof process !== \"undefined\" && process.env && process.env.DEBUG) || undefined;\n\nlet enabledString: string | undefined;\nlet enabledNamespaces: string[] = [];\nlet skippedNamespaces: string[] = [];\nconst debuggers: Debugger[] = [];\n\nif (debugEnvVariable) {\n enable(debugEnvVariable);\n}\n\nconst debugObj: Debug = Object.assign(\n (namespace: string): Debugger => {\n return createDebugger(namespace);\n },\n {\n enable,\n enabled,\n disable,\n log,\n },\n);\n\nfunction enable(namespaces: string): void {\n enabledString = namespaces;\n enabledNamespaces = [];\n skippedNamespaces = [];\n const namespaceList = namespaces.split(\",\").map((ns) => ns.trim());\n for (const ns of namespaceList) {\n if (ns.startsWith(\"-\")) {\n skippedNamespaces.push(ns.substring(1));\n } else {\n enabledNamespaces.push(ns);\n }\n }\n for (const instance of debuggers) {\n instance.enabled = enabled(instance.namespace);\n }\n}\n\nfunction enabled(namespace: string): boolean {\n if (namespace.endsWith(\"*\")) {\n return true;\n }\n\n for (const skipped of skippedNamespaces) {\n if (namespaceMatches(namespace, skipped)) {\n return false;\n }\n }\n for (const enabledNamespace of enabledNamespaces) {\n if (namespaceMatches(namespace, enabledNamespace)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Given a namespace, check if it matches a pattern.\n * Patterns only have a single wildcard character which is *.\n * The behavior of * is that it matches zero or more other characters.\n */\nfunction namespaceMatches(namespace: string, patternToMatch: string): boolean {\n // simple case, no pattern matching required\n if (patternToMatch.indexOf(\"*\") === -1) {\n return namespace === patternToMatch;\n }\n\n let pattern = patternToMatch;\n\n // normalize successive * if needed\n if (patternToMatch.indexOf(\"**\") !== -1) {\n const patternParts = [];\n let lastCharacter = \"\";\n for (const character of patternToMatch) {\n if (character === \"*\" && lastCharacter === \"*\") {\n continue;\n } else {\n lastCharacter = character;\n patternParts.push(character);\n }\n }\n pattern = patternParts.join(\"\");\n }\n\n let namespaceIndex = 0;\n let patternIndex = 0;\n const patternLength = pattern.length;\n const namespaceLength = namespace.length;\n let lastWildcard = -1;\n let lastWildcardNamespace = -1;\n\n while (namespaceIndex < namespaceLength && patternIndex < patternLength) {\n if (pattern[patternIndex] === \"*\") {\n lastWildcard = patternIndex;\n patternIndex++;\n if (patternIndex === patternLength) {\n // if wildcard is the last character, it will match the remaining namespace string\n return true;\n }\n // now we let the wildcard eat characters until we match the next literal in the pattern\n while (namespace[namespaceIndex] !== pattern[patternIndex]) {\n namespaceIndex++;\n // reached the end of the namespace without a match\n if (namespaceIndex === namespaceLength) {\n return false;\n }\n }\n\n // now that we have a match, let's try to continue on\n // however, it's possible we could find a later match\n // so keep a reference in case we have to backtrack\n lastWildcardNamespace = namespaceIndex;\n namespaceIndex++;\n patternIndex++;\n continue;\n } else if (pattern[patternIndex] === namespace[namespaceIndex]) {\n // simple case: literal pattern matches so keep going\n patternIndex++;\n namespaceIndex++;\n } else if (lastWildcard >= 0) {\n // special case: we don't have a literal match, but there is a previous wildcard\n // which we can backtrack to and try having the wildcard eat the match instead\n patternIndex = lastWildcard + 1;\n namespaceIndex = lastWildcardNamespace + 1;\n // we've reached the end of the namespace without a match\n if (namespaceIndex === namespaceLength) {\n return false;\n }\n // similar to the previous logic, let's keep going until we find the next literal match\n while (namespace[namespaceIndex] !== pattern[patternIndex]) {\n namespaceIndex++;\n if (namespaceIndex === namespaceLength) {\n return false;\n }\n }\n lastWildcardNamespace = namespaceIndex;\n namespaceIndex++;\n patternIndex++;\n continue;\n } else {\n return false;\n }\n }\n\n const namespaceDone = namespaceIndex === namespace.length;\n const patternDone = patternIndex === pattern.length;\n // this is to detect the case of an unneeded final wildcard\n // e.g. the pattern `ab*` should match the string `ab`\n const trailingWildCard = patternIndex === pattern.length - 1 && pattern[patternIndex] === \"*\";\n return namespaceDone && (patternDone || trailingWildCard);\n}\n\nfunction disable(): string {\n const result = enabledString || \"\";\n enable(\"\");\n return result;\n}\n\nfunction createDebugger(namespace: string): Debugger {\n const newDebugger: Debugger = Object.assign(debug, {\n enabled: enabled(namespace),\n destroy,\n log: debugObj.log,\n namespace,\n extend,\n });\n\n function debug(...args: any[]): void {\n if (!newDebugger.enabled) {\n return;\n }\n if (args.length > 0) {\n args[0] = `${namespace} ${args[0]}`;\n }\n newDebugger.log(...args);\n }\n\n debuggers.push(newDebugger);\n\n return newDebugger;\n}\n\nfunction destroy(this: Debugger): boolean {\n const index = debuggers.indexOf(this);\n if (index >= 0) {\n debuggers.splice(index, 1);\n return true;\n }\n return false;\n}\n\nfunction extend(this: Debugger, namespace: string): Debugger {\n const newDebugger = createDebugger(`${this.namespace}:${namespace}`);\n newDebugger.log = this.log;\n return newDebugger;\n}\n\nexport default debugObj;\n"]}
|
|
@@ -23,14 +23,13 @@ function enable(namespaces) {
|
|
|
23
23
|
enabledString = namespaces;
|
|
24
24
|
enabledNamespaces = [];
|
|
25
25
|
skippedNamespaces = [];
|
|
26
|
-
const
|
|
27
|
-
const namespaceList = namespaces.split(",").map((ns) => ns.trim().replace(wildcard, ".*?"));
|
|
26
|
+
const namespaceList = namespaces.split(",").map((ns) => ns.trim());
|
|
28
27
|
for (const ns of namespaceList) {
|
|
29
28
|
if (ns.startsWith("-")) {
|
|
30
|
-
skippedNamespaces.push(
|
|
29
|
+
skippedNamespaces.push(ns.substring(1));
|
|
31
30
|
}
|
|
32
31
|
else {
|
|
33
|
-
enabledNamespaces.push(
|
|
32
|
+
enabledNamespaces.push(ns);
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
for (const instance of debuggers) {
|
|
@@ -42,17 +41,110 @@ function enabled(namespace) {
|
|
|
42
41
|
return true;
|
|
43
42
|
}
|
|
44
43
|
for (const skipped of skippedNamespaces) {
|
|
45
|
-
if (
|
|
44
|
+
if (namespaceMatches(namespace, skipped)) {
|
|
46
45
|
return false;
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
for (const enabledNamespace of enabledNamespaces) {
|
|
50
|
-
if (
|
|
49
|
+
if (namespaceMatches(namespace, enabledNamespace)) {
|
|
51
50
|
return true;
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
return false;
|
|
55
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Given a namespace, check if it matches a pattern.
|
|
57
|
+
* Patterns only have a single wildcard character which is *.
|
|
58
|
+
* The behavior of * is that it matches zero or more other characters.
|
|
59
|
+
*/
|
|
60
|
+
function namespaceMatches(namespace, patternToMatch) {
|
|
61
|
+
// simple case, no pattern matching required
|
|
62
|
+
if (patternToMatch.indexOf("*") === -1) {
|
|
63
|
+
return namespace === patternToMatch;
|
|
64
|
+
}
|
|
65
|
+
let pattern = patternToMatch;
|
|
66
|
+
// normalize successive * if needed
|
|
67
|
+
if (patternToMatch.indexOf("**") !== -1) {
|
|
68
|
+
const patternParts = [];
|
|
69
|
+
let lastCharacter = "";
|
|
70
|
+
for (const character of patternToMatch) {
|
|
71
|
+
if (character === "*" && lastCharacter === "*") {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
lastCharacter = character;
|
|
76
|
+
patternParts.push(character);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
pattern = patternParts.join("");
|
|
80
|
+
}
|
|
81
|
+
let namespaceIndex = 0;
|
|
82
|
+
let patternIndex = 0;
|
|
83
|
+
const patternLength = pattern.length;
|
|
84
|
+
const namespaceLength = namespace.length;
|
|
85
|
+
let lastWildcard = -1;
|
|
86
|
+
let lastWildcardNamespace = -1;
|
|
87
|
+
while (namespaceIndex < namespaceLength && patternIndex < patternLength) {
|
|
88
|
+
if (pattern[patternIndex] === "*") {
|
|
89
|
+
lastWildcard = patternIndex;
|
|
90
|
+
patternIndex++;
|
|
91
|
+
if (patternIndex === patternLength) {
|
|
92
|
+
// if wildcard is the last character, it will match the remaining namespace string
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
// now we let the wildcard eat characters until we match the next literal in the pattern
|
|
96
|
+
while (namespace[namespaceIndex] !== pattern[patternIndex]) {
|
|
97
|
+
namespaceIndex++;
|
|
98
|
+
// reached the end of the namespace without a match
|
|
99
|
+
if (namespaceIndex === namespaceLength) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// now that we have a match, let's try to continue on
|
|
104
|
+
// however, it's possible we could find a later match
|
|
105
|
+
// so keep a reference in case we have to backtrack
|
|
106
|
+
lastWildcardNamespace = namespaceIndex;
|
|
107
|
+
namespaceIndex++;
|
|
108
|
+
patternIndex++;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
else if (pattern[patternIndex] === namespace[namespaceIndex]) {
|
|
112
|
+
// simple case: literal pattern matches so keep going
|
|
113
|
+
patternIndex++;
|
|
114
|
+
namespaceIndex++;
|
|
115
|
+
}
|
|
116
|
+
else if (lastWildcard >= 0) {
|
|
117
|
+
// special case: we don't have a literal match, but there is a previous wildcard
|
|
118
|
+
// which we can backtrack to and try having the wildcard eat the match instead
|
|
119
|
+
patternIndex = lastWildcard + 1;
|
|
120
|
+
namespaceIndex = lastWildcardNamespace + 1;
|
|
121
|
+
// we've reached the end of the namespace without a match
|
|
122
|
+
if (namespaceIndex === namespaceLength) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
// similar to the previous logic, let's keep going until we find the next literal match
|
|
126
|
+
while (namespace[namespaceIndex] !== pattern[patternIndex]) {
|
|
127
|
+
namespaceIndex++;
|
|
128
|
+
if (namespaceIndex === namespaceLength) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
lastWildcardNamespace = namespaceIndex;
|
|
133
|
+
namespaceIndex++;
|
|
134
|
+
patternIndex++;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const namespaceDone = namespaceIndex === namespace.length;
|
|
142
|
+
const patternDone = patternIndex === pattern.length;
|
|
143
|
+
// this is to detect the case of an unneeded final wildcard
|
|
144
|
+
// e.g. the pattern `ab*` should match the string `ab`
|
|
145
|
+
const trailingWildCard = patternIndex === pattern.length - 1 && pattern[patternIndex] === "*";
|
|
146
|
+
return namespaceDone && (patternDone || trailingWildCard);
|
|
147
|
+
}
|
|
56
148
|
function disable() {
|
|
57
149
|
const result = enabledString || "";
|
|
58
150
|
enable("");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../../src/logger/debug.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,qCAA+B;AAgE/B,MAAM,gBAAgB,GACpB,CAAC,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC;AAEpF,IAAI,aAAiC,CAAC;AACtC,IAAI,iBAAiB,GAAa,EAAE,CAAC;AACrC,IAAI,iBAAiB,GAAa,EAAE,CAAC;AACrC,MAAM,SAAS,GAAe,EAAE,CAAC;AAEjC,IAAI,gBAAgB,EAAE,CAAC;IACrB,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,QAAQ,GAAU,MAAM,CAAC,MAAM,CACnC,CAAC,SAAiB,EAAY,EAAE;IAC9B,OAAO,cAAc,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC,EACD;IACE,MAAM;IACN,OAAO;IACP,OAAO;IACP,GAAG,EAAH,YAAG;CACJ,CACF,CAAC;AAEF,SAAS,MAAM,CAAC,UAAkB;IAChC,aAAa,GAAG,UAAU,CAAC;IAC3B,iBAAiB,GAAG,EAAE,CAAC;IACvB,iBAAiB,GAAG,EAAE,CAAC;IACvB,MAAM,Q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ent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { log } from \"./log.js\";\n\n/**\n * A simple mechanism for enabling logging.\n * Intended to mimic the publicly available `debug` package.\n */\nexport interface Debug {\n /**\n * Creates a new logger with the given namespace.\n */\n (namespace: string): Debugger;\n /**\n * The default log method (defaults to console)\n */\n log: (...args: any[]) => void;\n /**\n * Enables a particular set of namespaces.\n * To enable multiple separate them with commas, e.g. \"info,debug\".\n * Supports wildcards, e.g. \"typeSpecRuntime:*\"\n * Supports skip syntax, e.g. \"typeSpecRuntime:*,-typeSpecRuntime:storage:*\" will enable\n * everything under typeSpecRuntime except for things under typeSpecRuntime:storage.\n */\n enable: (namespaces: string) => void;\n /**\n * Checks if a particular namespace is enabled.\n */\n enabled: (namespace: string) => boolean;\n /**\n * Disables all logging, returns what was previously enabled.\n */\n disable: () => string;\n}\n\n/**\n * A log function that can be dynamically enabled and redirected.\n */\nexport interface Debugger {\n /**\n * Logs the given arguments to the `log` method.\n */\n (...args: any[]): void;\n /**\n * True if this logger is active and logging.\n */\n enabled: boolean;\n /**\n * Used to cleanup/remove this logger.\n */\n destroy: () => boolean;\n /**\n * The current log method. Can be overridden to redirect output.\n */\n log: (...args: any[]) => void;\n /**\n * The namespace of this logger.\n */\n namespace: string;\n /**\n * Extends this logger with a child namespace.\n * Namespaces are separated with a ':' character.\n */\n extend: (namespace: string) => Debugger;\n}\n\nconst debugEnvVariable =\n (typeof process !== \"undefined\" && process.env && process.env.DEBUG) || undefined;\n\nlet enabledString: string | undefined;\nlet enabledNamespaces: RegExp[] = [];\nlet skippedNamespaces: RegExp[] = [];\nconst debuggers: Debugger[] = [];\n\nif (debugEnvVariable) {\n enable(debugEnvVariable);\n}\n\nconst debugObj: Debug = Object.assign(\n (namespace: string): Debugger => {\n return createDebugger(namespace);\n },\n {\n enable,\n enabled,\n disable,\n log,\n },\n);\n\nfunction enable(namespaces: string): void {\n enabledString = namespaces;\n enabledNamespaces = [];\n skippedNamespaces = [];\n const wildcard = /\\*/g;\n const namespaceList = namespaces.split(\",\").map((ns) => ns.trim().replace(wildcard, \".*?\"));\n for (const ns of namespaceList) {\n if (ns.startsWith(\"-\")) {\n skippedNamespaces.push(new RegExp(`^${ns.substr(1)}$`));\n } else {\n enabledNamespaces.push(new RegExp(`^${ns}$`));\n }\n }\n for (const instance of debuggers) {\n instance.enabled = enabled(instance.namespace);\n }\n}\n\nfunction enabled(namespace: string): boolean {\n if (namespace.endsWith(\"*\")) {\n return true;\n }\n\n for (const skipped of skippedNamespaces) {\n if (skipped.test(namespace)) {\n return false;\n }\n }\n for (const enabledNamespace of enabledNamespaces) {\n if (enabledNamespace.test(namespace)) {\n return true;\n }\n }\n return false;\n}\n\nfunction disable(): string {\n const result = enabledString || \"\";\n enable(\"\");\n return result;\n}\n\nfunction createDebugger(namespace: string): Debugger {\n const newDebugger: Debugger = Object.assign(debug, {\n enabled: enabled(namespace),\n destroy,\n log: debugObj.log,\n namespace,\n extend,\n });\n\n function debug(...args: any[]): void {\n if (!newDebugger.enabled) {\n return;\n }\n if (args.length > 0) {\n args[0] = `${namespace} ${args[0]}`;\n }\n newDebugger.log(...args);\n }\n\n debuggers.push(newDebugger);\n\n return newDebugger;\n}\n\nfunction destroy(this: Debugger): boolean {\n const index = debuggers.indexOf(this);\n if (index >= 0) {\n debuggers.splice(index, 1);\n return true;\n }\n return false;\n}\n\nfunction extend(this: Debugger, namespace: string): Debugger {\n const newDebugger = createDebugger(`${this.namespace}:${namespace}`);\n newDebugger.log = this.log;\n return newDebugger;\n}\n\nexport default debugObj;\n"]}
|
|
1
|
+
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../../src/logger/debug.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,qCAA+B;AAgE/B,MAAM,gBAAgB,GACpB,CAAC,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,SAA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GAAG,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACtC,CAAC;QACD,WAAW,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAE5B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,SAAS,OAAO;IACd,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QACf,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,MAAM,CAAiB,SAAiB;IAC/C,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,SAAS,EAAE,CAAC,CAAC;IACrE,WAAW,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IAC3B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,kBAAe,QAAQ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { log } from \"./log.js\";\n\n/**\n * A simple mechanism for enabling logging.\n * Intended to mimic the publicly available `debug` package.\n */\nexport interface Debug {\n /**\n * Creates a new logger with the given namespace.\n */\n (namespace: string): Debugger;\n /**\n * The default log method (defaults to console)\n */\n log: (...args: any[]) => void;\n /**\n * Enables a particular set of namespaces.\n * To enable multiple separate them with commas, e.g. \"info,debug\".\n * Supports wildcards, e.g. \"typeSpecRuntime:*\"\n * Supports skip syntax, e.g. \"typeSpecRuntime:*,-typeSpecRuntime:storage:*\" will enable\n * everything under typeSpecRuntime except for things under typeSpecRuntime:storage.\n */\n enable: (namespaces: string) => void;\n /**\n * Checks if a particular namespace is enabled.\n */\n enabled: (namespace: string) => boolean;\n /**\n * Disables all logging, returns what was previously enabled.\n */\n disable: () => string;\n}\n\n/**\n * A log function that can be dynamically enabled and redirected.\n */\nexport interface Debugger {\n /**\n * Logs the given arguments to the `log` method.\n */\n (...args: any[]): void;\n /**\n * True if this logger is active and logging.\n */\n enabled: boolean;\n /**\n * Used to cleanup/remove this logger.\n */\n destroy: () => boolean;\n /**\n * The current log method. Can be overridden to redirect output.\n */\n log: (...args: any[]) => void;\n /**\n * The namespace of this logger.\n */\n namespace: string;\n /**\n * Extends this logger with a child namespace.\n * Namespaces are separated with a ':' character.\n */\n extend: (namespace: string) => Debugger;\n}\n\nconst debugEnvVariable =\n (typeof process !== \"undefined\" && process.env && process.env.DEBUG) || undefined;\n\nlet enabledString: string | undefined;\nlet enabledNamespaces: string[] = [];\nlet skippedNamespaces: string[] = [];\nconst debuggers: Debugger[] = [];\n\nif (debugEnvVariable) {\n enable(debugEnvVariable);\n}\n\nconst debugObj: Debug = Object.assign(\n (namespace: string): Debugger => {\n return createDebugger(namespace);\n },\n {\n enable,\n enabled,\n disable,\n log,\n },\n);\n\nfunction enable(namespaces: string): void {\n enabledString = namespaces;\n enabledNamespaces = [];\n skippedNamespaces = [];\n const namespaceList = namespaces.split(\",\").map((ns) => ns.trim());\n for (const ns of namespaceList) {\n if (ns.startsWith(\"-\")) {\n skippedNamespaces.push(ns.substring(1));\n } else {\n enabledNamespaces.push(ns);\n }\n }\n for (const instance of debuggers) {\n instance.enabled = enabled(instance.namespace);\n }\n}\n\nfunction enabled(namespace: string): boolean {\n if (namespace.endsWith(\"*\")) {\n return true;\n }\n\n for (const skipped of skippedNamespaces) {\n if (namespaceMatches(namespace, skipped)) {\n return false;\n }\n }\n for (const enabledNamespace of enabledNamespaces) {\n if (namespaceMatches(namespace, enabledNamespace)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Given a namespace, check if it matches a pattern.\n * Patterns only have a single wildcard character which is *.\n * The behavior of * is that it matches zero or more other characters.\n */\nfunction namespaceMatches(namespace: string, patternToMatch: string): boolean {\n // simple case, no pattern matching required\n if (patternToMatch.indexOf(\"*\") === -1) {\n return namespace === patternToMatch;\n }\n\n let pattern = patternToMatch;\n\n // normalize successive * if needed\n if (patternToMatch.indexOf(\"**\") !== -1) {\n const patternParts = [];\n let lastCharacter = \"\";\n for (const character of patternToMatch) {\n if (character === \"*\" && lastCharacter === \"*\") {\n continue;\n } else {\n lastCharacter = character;\n patternParts.push(character);\n }\n }\n pattern = patternParts.join(\"\");\n }\n\n let namespaceIndex = 0;\n let patternIndex = 0;\n const patternLength = pattern.length;\n const namespaceLength = namespace.length;\n let lastWildcard = -1;\n let lastWildcardNamespace = -1;\n\n while (namespaceIndex < namespaceLength && patternIndex < patternLength) {\n if (pattern[patternIndex] === \"*\") {\n lastWildcard = patternIndex;\n patternIndex++;\n if (patternIndex === patternLength) {\n // if wildcard is the last character, it will match the remaining namespace string\n return true;\n }\n // now we let the wildcard eat characters until we match the next literal in the pattern\n while (namespace[namespaceIndex] !== pattern[patternIndex]) {\n namespaceIndex++;\n // reached the end of the namespace without a match\n if (namespaceIndex === namespaceLength) {\n return false;\n }\n }\n\n // now that we have a match, let's try to continue on\n // however, it's possible we could find a later match\n // so keep a reference in case we have to backtrack\n lastWildcardNamespace = namespaceIndex;\n namespaceIndex++;\n patternIndex++;\n continue;\n } else if (pattern[patternIndex] === namespace[namespaceIndex]) {\n // simple case: literal pattern matches so keep going\n patternIndex++;\n namespaceIndex++;\n } else if (lastWildcard >= 0) {\n // special case: we don't have a literal match, but there is a previous wildcard\n // which we can backtrack to and try having the wildcard eat the match instead\n patternIndex = lastWildcard + 1;\n namespaceIndex = lastWildcardNamespace + 1;\n // we've reached the end of the namespace without a match\n if (namespaceIndex === namespaceLength) {\n return false;\n }\n // similar to the previous logic, let's keep going until we find the next literal match\n while (namespace[namespaceIndex] !== pattern[patternIndex]) {\n namespaceIndex++;\n if (namespaceIndex === namespaceLength) {\n return false;\n }\n }\n lastWildcardNamespace = namespaceIndex;\n namespaceIndex++;\n patternIndex++;\n continue;\n } else {\n return false;\n }\n }\n\n const namespaceDone = namespaceIndex === namespace.length;\n const patternDone = patternIndex === pattern.length;\n // this is to detect the case of an unneeded final wildcard\n // e.g. the pattern `ab*` should match the string `ab`\n const trailingWildCard = patternIndex === pattern.length - 1 && pattern[patternIndex] === \"*\";\n return namespaceDone && (patternDone || trailingWildCard);\n}\n\nfunction disable(): string {\n const result = enabledString || \"\";\n enable(\"\");\n return result;\n}\n\nfunction createDebugger(namespace: string): Debugger {\n const newDebugger: Debugger = Object.assign(debug, {\n enabled: enabled(namespace),\n destroy,\n log: debugObj.log,\n namespace,\n extend,\n });\n\n function debug(...args: any[]): void {\n if (!newDebugger.enabled) {\n return;\n }\n if (args.length > 0) {\n args[0] = `${namespace} ${args[0]}`;\n }\n newDebugger.log(...args);\n }\n\n debuggers.push(newDebugger);\n\n return newDebugger;\n}\n\nfunction destroy(this: Debugger): boolean {\n const index = debuggers.indexOf(this);\n if (index >= 0) {\n debuggers.splice(index, 1);\n return true;\n }\n return false;\n}\n\nfunction extend(this: Debugger, namespace: string): Debugger {\n const newDebugger = createDebugger(`${this.namespace}:${namespace}`);\n newDebugger.log = this.log;\n return newDebugger;\n}\n\nexport default debugObj;\n"]}
|
package/dist/esm/logger/debug.js
CHANGED
|
@@ -21,14 +21,13 @@ function enable(namespaces) {
|
|
|
21
21
|
enabledString = namespaces;
|
|
22
22
|
enabledNamespaces = [];
|
|
23
23
|
skippedNamespaces = [];
|
|
24
|
-
const
|
|
25
|
-
const namespaceList = namespaces.split(",").map((ns) => ns.trim().replace(wildcard, ".*?"));
|
|
24
|
+
const namespaceList = namespaces.split(",").map((ns) => ns.trim());
|
|
26
25
|
for (const ns of namespaceList) {
|
|
27
26
|
if (ns.startsWith("-")) {
|
|
28
|
-
skippedNamespaces.push(
|
|
27
|
+
skippedNamespaces.push(ns.substring(1));
|
|
29
28
|
}
|
|
30
29
|
else {
|
|
31
|
-
enabledNamespaces.push(
|
|
30
|
+
enabledNamespaces.push(ns);
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
for (const instance of debuggers) {
|
|
@@ -40,17 +39,110 @@ function enabled(namespace) {
|
|
|
40
39
|
return true;
|
|
41
40
|
}
|
|
42
41
|
for (const skipped of skippedNamespaces) {
|
|
43
|
-
if (
|
|
42
|
+
if (namespaceMatches(namespace, skipped)) {
|
|
44
43
|
return false;
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
for (const enabledNamespace of enabledNamespaces) {
|
|
48
|
-
if (
|
|
47
|
+
if (namespaceMatches(namespace, enabledNamespace)) {
|
|
49
48
|
return true;
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
return false;
|
|
53
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Given a namespace, check if it matches a pattern.
|
|
55
|
+
* Patterns only have a single wildcard character which is *.
|
|
56
|
+
* The behavior of * is that it matches zero or more other characters.
|
|
57
|
+
*/
|
|
58
|
+
function namespaceMatches(namespace, patternToMatch) {
|
|
59
|
+
// simple case, no pattern matching required
|
|
60
|
+
if (patternToMatch.indexOf("*") === -1) {
|
|
61
|
+
return namespace === patternToMatch;
|
|
62
|
+
}
|
|
63
|
+
let pattern = patternToMatch;
|
|
64
|
+
// normalize successive * if needed
|
|
65
|
+
if (patternToMatch.indexOf("**") !== -1) {
|
|
66
|
+
const patternParts = [];
|
|
67
|
+
let lastCharacter = "";
|
|
68
|
+
for (const character of patternToMatch) {
|
|
69
|
+
if (character === "*" && lastCharacter === "*") {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
lastCharacter = character;
|
|
74
|
+
patternParts.push(character);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
pattern = patternParts.join("");
|
|
78
|
+
}
|
|
79
|
+
let namespaceIndex = 0;
|
|
80
|
+
let patternIndex = 0;
|
|
81
|
+
const patternLength = pattern.length;
|
|
82
|
+
const namespaceLength = namespace.length;
|
|
83
|
+
let lastWildcard = -1;
|
|
84
|
+
let lastWildcardNamespace = -1;
|
|
85
|
+
while (namespaceIndex < namespaceLength && patternIndex < patternLength) {
|
|
86
|
+
if (pattern[patternIndex] === "*") {
|
|
87
|
+
lastWildcard = patternIndex;
|
|
88
|
+
patternIndex++;
|
|
89
|
+
if (patternIndex === patternLength) {
|
|
90
|
+
// if wildcard is the last character, it will match the remaining namespace string
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
// now we let the wildcard eat characters until we match the next literal in the pattern
|
|
94
|
+
while (namespace[namespaceIndex] !== pattern[patternIndex]) {
|
|
95
|
+
namespaceIndex++;
|
|
96
|
+
// reached the end of the namespace without a match
|
|
97
|
+
if (namespaceIndex === namespaceLength) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// now that we have a match, let's try to continue on
|
|
102
|
+
// however, it's possible we could find a later match
|
|
103
|
+
// so keep a reference in case we have to backtrack
|
|
104
|
+
lastWildcardNamespace = namespaceIndex;
|
|
105
|
+
namespaceIndex++;
|
|
106
|
+
patternIndex++;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
else if (pattern[patternIndex] === namespace[namespaceIndex]) {
|
|
110
|
+
// simple case: literal pattern matches so keep going
|
|
111
|
+
patternIndex++;
|
|
112
|
+
namespaceIndex++;
|
|
113
|
+
}
|
|
114
|
+
else if (lastWildcard >= 0) {
|
|
115
|
+
// special case: we don't have a literal match, but there is a previous wildcard
|
|
116
|
+
// which we can backtrack to and try having the wildcard eat the match instead
|
|
117
|
+
patternIndex = lastWildcard + 1;
|
|
118
|
+
namespaceIndex = lastWildcardNamespace + 1;
|
|
119
|
+
// we've reached the end of the namespace without a match
|
|
120
|
+
if (namespaceIndex === namespaceLength) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
// similar to the previous logic, let's keep going until we find the next literal match
|
|
124
|
+
while (namespace[namespaceIndex] !== pattern[patternIndex]) {
|
|
125
|
+
namespaceIndex++;
|
|
126
|
+
if (namespaceIndex === namespaceLength) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
lastWildcardNamespace = namespaceIndex;
|
|
131
|
+
namespaceIndex++;
|
|
132
|
+
patternIndex++;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const namespaceDone = namespaceIndex === namespace.length;
|
|
140
|
+
const patternDone = patternIndex === pattern.length;
|
|
141
|
+
// this is to detect the case of an unneeded final wildcard
|
|
142
|
+
// e.g. the pattern `ab*` should match the string `ab`
|
|
143
|
+
const trailingWildCard = patternIndex === pattern.length - 1 && pattern[patternIndex] === "*";
|
|
144
|
+
return namespaceDone && (patternDone || trailingWildCard);
|
|
145
|
+
}
|
|
54
146
|
function disable() {
|
|
55
147
|
const result = enabledString || "";
|
|
56
148
|
enable("");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../../src/logger/debug.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAgE/B,MAAM,gBAAgB,GACpB,CAAC,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC;AAEpF,IAAI,aAAiC,CAAC;AACtC,IAAI,iBAAiB,GAAa,EAAE,CAAC;AACrC,IAAI,iBAAiB,GAAa,EAAE,CAAC;AACrC,MAAM,SAAS,GAAe,EAAE,CAAC;AAEjC,IAAI,gBAAgB,EAAE,CAAC;IACrB,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,QAAQ,GAAU,MAAM,CAAC,MAAM,CACnC,CAAC,SAAiB,EAAY,EAAE;IAC9B,OAAO,cAAc,CAAC,SAAS,CAAC,CAAC;AACnC,CAA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,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,SAAS,EAAE,CAAC,CAAC;IACrE,WAAW,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IAC3B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,eAAe,QAAQ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { log } from \"./log.js\";\n\n/**\n * A simple mechanism for enabling logging.\n * Intended to mimic the publicly available `debug` package.\n */\nexport interface Debug {\n /**\n * Creates a new logger with the given namespace.\n */\n (namespace: string): Debugger;\n /**\n * The default log method (defaults to console)\n */\n log: (...args: any[]) => void;\n /**\n * Enables a particular set of namespaces.\n * To enable multiple separate them with commas, e.g. \"info,debug\".\n * Supports wildcards, e.g. \"typeSpecRuntime:*\"\n * Supports skip syntax, e.g. \"typeSpecRuntime:*,-typeSpecRuntime:storage:*\" will enable\n * everything under typeSpecRuntime except for things under typeSpecRuntime:storage.\n */\n enable: (namespaces: string) => void;\n /**\n * Checks if a particular namespace is enabled.\n */\n enabled: (namespace: string) => boolean;\n /**\n * Disables all logging, returns what was previously enabled.\n */\n disable: () => string;\n}\n\n/**\n * A log function that can be dynamically enabled and redirected.\n */\nexport interface Debugger {\n /**\n * Logs the given arguments to the `log` method.\n */\n (...args: any[]): void;\n /**\n * True if this logger is active and logging.\n */\n enabled: boolean;\n /**\n * Used to cleanup/remove this logger.\n */\n destroy: () => boolean;\n /**\n * The current log method. Can be overridden to redirect output.\n */\n log: (...args: any[]) => void;\n /**\n * The namespace of this logger.\n */\n namespace: string;\n /**\n * Extends this logger with a child namespace.\n * Namespaces are separated with a ':' character.\n */\n extend: (namespace: string) => Debugger;\n}\n\nconst debugEnvVariable =\n (typeof process !== \"undefined\" && process.env && process.env.DEBUG) || undefined;\n\nlet enabledString: string | undefined;\nlet enabledNamespaces: RegExp[] = [];\nlet skippedNamespaces: RegExp[] = [];\nconst debuggers: Debugger[] = [];\n\nif (debugEnvVariable) {\n enable(debugEnvVariable);\n}\n\nconst debugObj: Debug = Object.assign(\n (namespace: string): Debugger => {\n return createDebugger(namespace);\n },\n {\n enable,\n enabled,\n disable,\n log,\n },\n);\n\nfunction enable(namespaces: string): void {\n enabledString = namespaces;\n enabledNamespaces = [];\n skippedNamespaces = [];\n const wildcard = /\\*/g;\n const namespaceList = namespaces.split(\",\").map((ns) => ns.trim().replace(wildcard, \".*?\"));\n for (const ns of namespaceList) {\n if (ns.startsWith(\"-\")) {\n skippedNamespaces.push(new RegExp(`^${ns.substr(1)}$`));\n } else {\n enabledNamespaces.push(new RegExp(`^${ns}$`));\n }\n }\n for (const instance of debuggers) {\n instance.enabled = enabled(instance.namespace);\n }\n}\n\nfunction enabled(namespace: string): boolean {\n if (namespace.endsWith(\"*\")) {\n return true;\n }\n\n for (const skipped of skippedNamespaces) {\n if (skipped.test(namespace)) {\n return false;\n }\n }\n for (const enabledNamespace of enabledNamespaces) {\n if (enabledNamespace.test(namespace)) {\n return true;\n }\n }\n return false;\n}\n\nfunction disable(): string {\n const result = enabledString || \"\";\n enable(\"\");\n return result;\n}\n\nfunction createDebugger(namespace: string): Debugger {\n const newDebugger: Debugger = Object.assign(debug, {\n enabled: enabled(namespace),\n destroy,\n log: debugObj.log,\n namespace,\n extend,\n });\n\n function debug(...args: any[]): void {\n if (!newDebugger.enabled) {\n return;\n }\n if (args.length > 0) {\n args[0] = `${namespace} ${args[0]}`;\n }\n newDebugger.log(...args);\n }\n\n debuggers.push(newDebugger);\n\n return newDebugger;\n}\n\nfunction destroy(this: Debugger): boolean {\n const index = debuggers.indexOf(this);\n if (index >= 0) {\n debuggers.splice(index, 1);\n return true;\n }\n return false;\n}\n\nfunction extend(this: Debugger, namespace: string): Debugger {\n const newDebugger = createDebugger(`${this.namespace}:${namespace}`);\n newDebugger.log = this.log;\n return newDebugger;\n}\n\nexport default debugObj;\n"]}
|
|
1
|
+
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../../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S;QACT,MAAM;KACP,CAAC,CAAC;IAEH,SAAS,KAAK,CAAC,GAAG,IAAW;QAC3B,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACtC,CAAC;QACD,WAAW,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAE5B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,SAAS,OAAO;IACd,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QACf,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,MAAM,CAAiB,SAAiB;IAC/C,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,SAAS,EAAE,CAAC,CAAC;IACrE,WAAW,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IAC3B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,eAAe,QAAQ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { log } from \"./log.js\";\n\n/**\n * A simple mechanism for enabling logging.\n * Intended to mimic the publicly available `debug` package.\n */\nexport interface Debug {\n /**\n * Creates a new logger with the given namespace.\n */\n (namespace: string): Debugger;\n /**\n * The default log method (defaults to console)\n */\n log: (...args: any[]) => void;\n /**\n * Enables a particular set of namespaces.\n * To enable multiple separate them with commas, e.g. \"info,debug\".\n * Supports wildcards, e.g. \"typeSpecRuntime:*\"\n * Supports skip syntax, e.g. \"typeSpecRuntime:*,-typeSpecRuntime:storage:*\" will enable\n * everything under typeSpecRuntime except for things under typeSpecRuntime:storage.\n */\n enable: (namespaces: string) => void;\n /**\n * Checks if a particular namespace is enabled.\n */\n enabled: (namespace: string) => boolean;\n /**\n * Disables all logging, returns what was previously enabled.\n */\n disable: () => string;\n}\n\n/**\n * A log function that can be dynamically enabled and redirected.\n */\nexport interface Debugger {\n /**\n * Logs the given arguments to the `log` method.\n */\n (...args: any[]): void;\n /**\n * True if this logger is active and logging.\n */\n enabled: boolean;\n /**\n * Used to cleanup/remove this logger.\n */\n destroy: () => boolean;\n /**\n * The current log method. Can be overridden to redirect output.\n */\n log: (...args: any[]) => void;\n /**\n * The namespace of this logger.\n */\n namespace: string;\n /**\n * Extends this logger with a child namespace.\n * Namespaces are separated with a ':' character.\n */\n extend: (namespace: string) => Debugger;\n}\n\nconst debugEnvVariable =\n (typeof process !== \"undefined\" && process.env && process.env.DEBUG) || undefined;\n\nlet enabledString: string | undefined;\nlet enabledNamespaces: string[] = [];\nlet skippedNamespaces: string[] = [];\nconst debuggers: Debugger[] = [];\n\nif (debugEnvVariable) {\n enable(debugEnvVariable);\n}\n\nconst debugObj: Debug = Object.assign(\n (namespace: string): Debugger => {\n return createDebugger(namespace);\n },\n {\n enable,\n enabled,\n disable,\n log,\n },\n);\n\nfunction enable(namespaces: string): void {\n enabledString = namespaces;\n enabledNamespaces = [];\n skippedNamespaces = [];\n const namespaceList = namespaces.split(\",\").map((ns) => ns.trim());\n for (const ns of namespaceList) {\n if (ns.startsWith(\"-\")) {\n skippedNamespaces.push(ns.substring(1));\n } else {\n enabledNamespaces.push(ns);\n }\n }\n for (const instance of debuggers) {\n instance.enabled = enabled(instance.namespace);\n }\n}\n\nfunction enabled(namespace: string): boolean {\n if (namespace.endsWith(\"*\")) {\n return true;\n }\n\n for (const skipped of skippedNamespaces) {\n if (namespaceMatches(namespace, skipped)) {\n return false;\n }\n }\n for (const enabledNamespace of enabledNamespaces) {\n if (namespaceMatches(namespace, enabledNamespace)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Given a namespace, check if it matches a pattern.\n * Patterns only have a single wildcard character which is *.\n * The behavior of * is that it matches zero or more other characters.\n */\nfunction namespaceMatches(namespace: string, patternToMatch: string): boolean {\n // simple case, no pattern matching required\n if (patternToMatch.indexOf(\"*\") === -1) {\n return namespace === patternToMatch;\n }\n\n let pattern = patternToMatch;\n\n // normalize successive * if needed\n if (patternToMatch.indexOf(\"**\") !== -1) {\n const patternParts = [];\n let lastCharacter = \"\";\n for (const character of patternToMatch) {\n if (character === \"*\" && lastCharacter === \"*\") {\n continue;\n } else {\n lastCharacter = character;\n patternParts.push(character);\n }\n }\n pattern = patternParts.join(\"\");\n }\n\n let namespaceIndex = 0;\n let patternIndex = 0;\n const patternLength = pattern.length;\n const namespaceLength = namespace.length;\n let lastWildcard = -1;\n let lastWildcardNamespace = -1;\n\n while (namespaceIndex < namespaceLength && patternIndex < patternLength) {\n if (pattern[patternIndex] === \"*\") {\n lastWildcard = patternIndex;\n patternIndex++;\n if (patternIndex === patternLength) {\n // if wildcard is the last character, it will match the remaining namespace string\n return true;\n }\n // now we let the wildcard eat characters until we match the next literal in the pattern\n while (namespace[namespaceIndex] !== pattern[patternIndex]) {\n namespaceIndex++;\n // reached the end of the namespace without a match\n if (namespaceIndex === namespaceLength) {\n return false;\n }\n }\n\n // now that we have a match, let's try to continue on\n // however, it's possible we could find a later match\n // so keep a reference in case we have to backtrack\n lastWildcardNamespace = namespaceIndex;\n namespaceIndex++;\n patternIndex++;\n continue;\n } else if (pattern[patternIndex] === namespace[namespaceIndex]) {\n // simple case: literal pattern matches so keep going\n patternIndex++;\n namespaceIndex++;\n } else if (lastWildcard >= 0) {\n // special case: we don't have a literal match, but there is a previous wildcard\n // which we can backtrack to and try having the wildcard eat the match instead\n patternIndex = lastWildcard + 1;\n namespaceIndex = lastWildcardNamespace + 1;\n // we've reached the end of the namespace without a match\n if (namespaceIndex === namespaceLength) {\n return false;\n }\n // similar to the previous logic, let's keep going until we find the next literal match\n while (namespace[namespaceIndex] !== pattern[patternIndex]) {\n namespaceIndex++;\n if (namespaceIndex === namespaceLength) {\n return false;\n }\n }\n lastWildcardNamespace = namespaceIndex;\n namespaceIndex++;\n patternIndex++;\n continue;\n } else {\n return false;\n }\n }\n\n const namespaceDone = namespaceIndex === namespace.length;\n const patternDone = patternIndex === pattern.length;\n // this is to detect the case of an unneeded final wildcard\n // e.g. the pattern `ab*` should match the string `ab`\n const trailingWildCard = patternIndex === pattern.length - 1 && pattern[patternIndex] === \"*\";\n return namespaceDone && (patternDone || trailingWildCard);\n}\n\nfunction disable(): string {\n const result = enabledString || \"\";\n enable(\"\");\n return result;\n}\n\nfunction createDebugger(namespace: string): Debugger {\n const newDebugger: Debugger = Object.assign(debug, {\n enabled: enabled(namespace),\n destroy,\n log: debugObj.log,\n namespace,\n extend,\n });\n\n function debug(...args: any[]): void {\n if (!newDebugger.enabled) {\n return;\n }\n if (args.length > 0) {\n args[0] = `${namespace} ${args[0]}`;\n }\n newDebugger.log(...args);\n }\n\n debuggers.push(newDebugger);\n\n return newDebugger;\n}\n\nfunction destroy(this: Debugger): boolean {\n const index = debuggers.indexOf(this);\n if (index >= 0) {\n debuggers.splice(index, 1);\n return true;\n }\n return false;\n}\n\nfunction extend(this: Debugger, namespace: string): Debugger {\n const newDebugger = createDebugger(`${this.namespace}:${namespace}`);\n newDebugger.log = this.log;\n return newDebugger;\n}\n\nexport default debugObj;\n"]}
|
|
@@ -21,14 +21,13 @@ function enable(namespaces) {
|
|
|
21
21
|
enabledString = namespaces;
|
|
22
22
|
enabledNamespaces = [];
|
|
23
23
|
skippedNamespaces = [];
|
|
24
|
-
const
|
|
25
|
-
const namespaceList = namespaces.split(",").map((ns) => ns.trim().replace(wildcard, ".*?"));
|
|
24
|
+
const namespaceList = namespaces.split(",").map((ns) => ns.trim());
|
|
26
25
|
for (const ns of namespaceList) {
|
|
27
26
|
if (ns.startsWith("-")) {
|
|
28
|
-
skippedNamespaces.push(
|
|
27
|
+
skippedNamespaces.push(ns.substring(1));
|
|
29
28
|
}
|
|
30
29
|
else {
|
|
31
|
-
enabledNamespaces.push(
|
|
30
|
+
enabledNamespaces.push(ns);
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
for (const instance of debuggers) {
|
|
@@ -40,17 +39,110 @@ function enabled(namespace) {
|
|
|
40
39
|
return true;
|
|
41
40
|
}
|
|
42
41
|
for (const skipped of skippedNamespaces) {
|
|
43
|
-
if (
|
|
42
|
+
if (namespaceMatches(namespace, skipped)) {
|
|
44
43
|
return false;
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
for (const enabledNamespace of enabledNamespaces) {
|
|
48
|
-
if (
|
|
47
|
+
if (namespaceMatches(namespace, enabledNamespace)) {
|
|
49
48
|
return true;
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
return false;
|
|
53
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Given a namespace, check if it matches a pattern.
|
|
55
|
+
* Patterns only have a single wildcard character which is *.
|
|
56
|
+
* The behavior of * is that it matches zero or more other characters.
|
|
57
|
+
*/
|
|
58
|
+
function namespaceMatches(namespace, patternToMatch) {
|
|
59
|
+
// simple case, no pattern matching required
|
|
60
|
+
if (patternToMatch.indexOf("*") === -1) {
|
|
61
|
+
return namespace === patternToMatch;
|
|
62
|
+
}
|
|
63
|
+
let pattern = patternToMatch;
|
|
64
|
+
// normalize successive * if needed
|
|
65
|
+
if (patternToMatch.indexOf("**") !== -1) {
|
|
66
|
+
const patternParts = [];
|
|
67
|
+
let lastCharacter = "";
|
|
68
|
+
for (const character of patternToMatch) {
|
|
69
|
+
if (character === "*" && lastCharacter === "*") {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
lastCharacter = character;
|
|
74
|
+
patternParts.push(character);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
pattern = patternParts.join("");
|
|
78
|
+
}
|
|
79
|
+
let namespaceIndex = 0;
|
|
80
|
+
let patternIndex = 0;
|
|
81
|
+
const patternLength = pattern.length;
|
|
82
|
+
const namespaceLength = namespace.length;
|
|
83
|
+
let lastWildcard = -1;
|
|
84
|
+
let lastWildcardNamespace = -1;
|
|
85
|
+
while (namespaceIndex < namespaceLength && patternIndex < patternLength) {
|
|
86
|
+
if (pattern[patternIndex] === "*") {
|
|
87
|
+
lastWildcard = patternIndex;
|
|
88
|
+
patternIndex++;
|
|
89
|
+
if (patternIndex === patternLength) {
|
|
90
|
+
// if wildcard is the last character, it will match the remaining namespace string
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
// now we let the wildcard eat characters until we match the next literal in the pattern
|
|
94
|
+
while (namespace[namespaceIndex] !== pattern[patternIndex]) {
|
|
95
|
+
namespaceIndex++;
|
|
96
|
+
// reached the end of the namespace without a match
|
|
97
|
+
if (namespaceIndex === namespaceLength) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// now that we have a match, let's try to continue on
|
|
102
|
+
// however, it's possible we could find a later match
|
|
103
|
+
// so keep a reference in case we have to backtrack
|
|
104
|
+
lastWildcardNamespace = namespaceIndex;
|
|
105
|
+
namespaceIndex++;
|
|
106
|
+
patternIndex++;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
else if (pattern[patternIndex] === namespace[namespaceIndex]) {
|
|
110
|
+
// simple case: literal pattern matches so keep going
|
|
111
|
+
patternIndex++;
|
|
112
|
+
namespaceIndex++;
|
|
113
|
+
}
|
|
114
|
+
else if (lastWildcard >= 0) {
|
|
115
|
+
// special case: we don't have a literal match, but there is a previous wildcard
|
|
116
|
+
// which we can backtrack to and try having the wildcard eat the match instead
|
|
117
|
+
patternIndex = lastWildcard + 1;
|
|
118
|
+
namespaceIndex = lastWildcardNamespace + 1;
|
|
119
|
+
// we've reached the end of the namespace without a match
|
|
120
|
+
if (namespaceIndex === namespaceLength) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
// similar to the previous logic, let's keep going until we find the next literal match
|
|
124
|
+
while (namespace[namespaceIndex] !== pattern[patternIndex]) {
|
|
125
|
+
namespaceIndex++;
|
|
126
|
+
if (namespaceIndex === namespaceLength) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
lastWildcardNamespace = namespaceIndex;
|
|
131
|
+
namespaceIndex++;
|
|
132
|
+
patternIndex++;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const namespaceDone = namespaceIndex === namespace.length;
|
|
140
|
+
const patternDone = patternIndex === pattern.length;
|
|
141
|
+
// this is to detect the case of an unneeded final wildcard
|
|
142
|
+
// e.g. the pattern `ab*` should match the string `ab`
|
|
143
|
+
const trailingWildCard = patternIndex === pattern.length - 1 && pattern[patternIndex] === "*";
|
|
144
|
+
return namespaceDone && (patternDone || trailingWildCard);
|
|
145
|
+
}
|
|
54
146
|
function disable() {
|
|
55
147
|
const result = enabledString || "";
|
|
56
148
|
enable("");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../../src/logger/debug.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAgE/B,MAAM,gBAAgB,GACpB,CAAC,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC;AAEpF,IAAI,aAAiC,CAAC;AACtC,IAAI,iBAAiB,GAAa,EAAE,CAAC;AACrC,IAAI,iBAAiB,GAAa,EAAE,CAAC;AACrC,MAAM,SAAS,GAAe,EAAE,CAAC;AAEjC,IAAI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AI,KAAK,IAAI,CAAC,EAAE,CAAC;QACf,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,MAAM,CAAiB,SAAiB;IAC/C,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,SAAS,EAAE,CAAC,CAAC;IACrE,WAAW,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IAC3B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,eAAe,QAAQ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { log } from \"./log.js\";\n\n/**\n * A simple mechanism for enabling logging.\n * Intended to mimic the publicly available `debug` package.\n */\nexport interface Debug {\n /**\n * Creates a new logger with the given namespace.\n */\n (namespace: string): Debugger;\n /**\n * The default log method (defaults to console)\n */\n log: (...args: any[]) => void;\n /**\n * Enables a particular set of namespaces.\n * To enable multiple separate them with commas, e.g. \"info,debug\".\n * Supports wildcards, e.g. \"typeSpecRuntime:*\"\n * Supports skip syntax, e.g. \"typeSpecRuntime:*,-typeSpecRuntime:storage:*\" will enable\n * everything under typeSpecRuntime except for things under typeSpecRuntime:storage.\n */\n enable: (namespaces: string) => void;\n /**\n * Checks if a particular namespace is enabled.\n */\n enabled: (namespace: string) => boolean;\n /**\n * Disables all logging, returns what was previously enabled.\n */\n disable: () => string;\n}\n\n/**\n * A log function that can be dynamically enabled and redirected.\n */\nexport interface Debugger {\n /**\n * Logs the given arguments to the `log` method.\n */\n (...args: any[]): void;\n /**\n * True if this logger is active and logging.\n */\n enabled: boolean;\n /**\n * Used to cleanup/remove this logger.\n */\n destroy: () => boolean;\n /**\n * The current log method. Can be overridden to redirect output.\n */\n log: (...args: any[]) => void;\n /**\n * The namespace of this logger.\n */\n namespace: string;\n /**\n * Extends this logger with a child namespace.\n * Namespaces are separated with a ':' character.\n */\n extend: (namespace: string) => Debugger;\n}\n\nconst debugEnvVariable =\n (typeof process !== \"undefined\" && process.env && process.env.DEBUG) || undefined;\n\nlet enabledString: string | undefined;\nlet enabledNamespaces: RegExp[] = [];\nlet skippedNamespaces: RegExp[] = [];\nconst debuggers: Debugger[] = [];\n\nif (debugEnvVariable) {\n enable(debugEnvVariable);\n}\n\nconst debugObj: Debug = Object.assign(\n (namespace: string): Debugger => {\n return createDebugger(namespace);\n },\n {\n enable,\n enabled,\n disable,\n log,\n },\n);\n\nfunction enable(namespaces: string): void {\n enabledString = namespaces;\n enabledNamespaces = [];\n skippedNamespaces = [];\n const wildcard = /\\*/g;\n const namespaceList = namespaces.split(\",\").map((ns) => ns.trim().replace(wildcard, \".*?\"));\n for (const ns of namespaceList) {\n if (ns.startsWith(\"-\")) {\n skippedNamespaces.push(new RegExp(`^${ns.substr(1)}$`));\n } else {\n enabledNamespaces.push(new RegExp(`^${ns}$`));\n }\n }\n for (const instance of debuggers) {\n instance.enabled = enabled(instance.namespace);\n }\n}\n\nfunction enabled(namespace: string): boolean {\n if (namespace.endsWith(\"*\")) {\n return true;\n }\n\n for (const skipped of skippedNamespaces) {\n if (skipped.test(namespace)) {\n return false;\n }\n }\n for (const enabledNamespace of enabledNamespaces) {\n if (enabledNamespace.test(namespace)) {\n return true;\n }\n }\n return false;\n}\n\nfunction disable(): string {\n const result = enabledString || \"\";\n enable(\"\");\n return result;\n}\n\nfunction createDebugger(namespace: string): Debugger {\n const newDebugger: Debugger = Object.assign(debug, {\n enabled: enabled(namespace),\n destroy,\n log: debugObj.log,\n namespace,\n extend,\n });\n\n function debug(...args: any[]): void {\n if (!newDebugger.enabled) {\n return;\n }\n if (args.length > 0) {\n args[0] = `${namespace} ${args[0]}`;\n }\n newDebugger.log(...args);\n }\n\n debuggers.push(newDebugger);\n\n return newDebugger;\n}\n\nfunction destroy(this: Debugger): boolean {\n const index = debuggers.indexOf(this);\n if (index >= 0) {\n debuggers.splice(index, 1);\n return true;\n }\n return false;\n}\n\nfunction extend(this: Debugger, namespace: string): Debugger {\n const newDebugger = createDebugger(`${this.namespace}:${namespace}`);\n newDebugger.log = this.log;\n return newDebugger;\n}\n\nexport default debugObj;\n"]}
|
|
1
|
+
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../../src/logger/debug.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAgE/B,MAAM,gBAAgB,GACpB,CAAC,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC;AAEpF,IAAI,aAAiC,CAAC;AACtC,IAAI,iBAAiB,GAAa,EAAE,CAAC;AACrC,IAAI,iBAAiB,GAAa,EAAE,CAAC;AACrC,MAAM,SAAS,GAAe,EAAE,CAAC;AAEjC,IAAI,gBAAgB,EAAE,CAAC;IACrB,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,QAAQ,GAAU,MAAM,CAAC,MAAM,CACnC,CAAC,SAAiB,EAAY,EAAE;IAC9B,OAAO,cAAc,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC,EACD;IACE,MAAM;IACN,OAAO;IACP,OAAO;IACP,GAAG;CACJ,CACF,CAAC;AAEF,SAAS,MAAM,CAAC,UAAkB;IAChC,aAAa,GAAG,UAAU,CAAC;IAC3B,iBAAiB,GAAG,EAAE,CAAC;IACvB,iBAAiB,GAAG,EAAE,CAAC;IACvB,MAAM,aAAa,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;IACnE,KAAK,MAAM,EAAE,IAAI,aAAa,EAAE,CAAC;QAC/B,IAAI,EAAE,CAAC,UAAU,CAAC,GAAG,CA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B,CAAC;AAED,SAAS,cAAc,CAAC,SAAiB;IACvC,MAAM,WAAW,GAAa,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE;QACjD,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC;QAC3B,OAAO;QACP,GAAG,EAAE,QAAQ,CAAC,GAAG;QACjB,SAAS;QACT,MAAM;KACP,CAAC,CAAC;IAEH,SAAS,KAAK,CAAC,GAAG,IAAW;QAC3B,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACtC,CAAC;QACD,WAAW,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAE5B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,SAAS,OAAO;IACd,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QACf,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,MAAM,CAAiB,SAAiB;IAC/C,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,SAAS,EAAE,CAAC,CAAC;IACrE,WAAW,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IAC3B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,eAAe,QAAQ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { log } from \"./log.js\";\n\n/**\n * A simple mechanism for enabling logging.\n * Intended to mimic the publicly available `debug` package.\n */\nexport interface Debug {\n /**\n * Creates a new logger with the given namespace.\n */\n (namespace: string): Debugger;\n /**\n * The default log method (defaults to console)\n */\n log: (...args: any[]) => void;\n /**\n * Enables a particular set of namespaces.\n * To enable multiple separate them with commas, e.g. \"info,debug\".\n * Supports wildcards, e.g. \"typeSpecRuntime:*\"\n * Supports skip syntax, e.g. \"typeSpecRuntime:*,-typeSpecRuntime:storage:*\" will enable\n * everything under typeSpecRuntime except for things under typeSpecRuntime:storage.\n */\n enable: (namespaces: string) => void;\n /**\n * Checks if a particular namespace is enabled.\n */\n enabled: (namespace: string) => boolean;\n /**\n * Disables all logging, returns what was previously enabled.\n */\n disable: () => string;\n}\n\n/**\n * A log function that can be dynamically enabled and redirected.\n */\nexport interface Debugger {\n /**\n * Logs the given arguments to the `log` method.\n */\n (...args: any[]): void;\n /**\n * True if this logger is active and logging.\n */\n enabled: boolean;\n /**\n * Used to cleanup/remove this logger.\n */\n destroy: () => boolean;\n /**\n * The current log method. Can be overridden to redirect output.\n */\n log: (...args: any[]) => void;\n /**\n * The namespace of this logger.\n */\n namespace: string;\n /**\n * Extends this logger with a child namespace.\n * Namespaces are separated with a ':' character.\n */\n extend: (namespace: string) => Debugger;\n}\n\nconst debugEnvVariable =\n (typeof process !== \"undefined\" && process.env && process.env.DEBUG) || undefined;\n\nlet enabledString: string | undefined;\nlet enabledNamespaces: string[] = [];\nlet skippedNamespaces: string[] = [];\nconst debuggers: Debugger[] = [];\n\nif (debugEnvVariable) {\n enable(debugEnvVariable);\n}\n\nconst debugObj: Debug = Object.assign(\n (namespace: string): Debugger => {\n return createDebugger(namespace);\n },\n {\n enable,\n enabled,\n disable,\n log,\n },\n);\n\nfunction enable(namespaces: string): void {\n enabledString = namespaces;\n enabledNamespaces = [];\n skippedNamespaces = [];\n const namespaceList = namespaces.split(\",\").map((ns) => ns.trim());\n for (const ns of namespaceList) {\n if (ns.startsWith(\"-\")) {\n skippedNamespaces.push(ns.substring(1));\n } else {\n enabledNamespaces.push(ns);\n }\n }\n for (const instance of debuggers) {\n instance.enabled = enabled(instance.namespace);\n }\n}\n\nfunction enabled(namespace: string): boolean {\n if (namespace.endsWith(\"*\")) {\n return true;\n }\n\n for (const skipped of skippedNamespaces) {\n if (namespaceMatches(namespace, skipped)) {\n return false;\n }\n }\n for (const enabledNamespace of enabledNamespaces) {\n if (namespaceMatches(namespace, enabledNamespace)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Given a namespace, check if it matches a pattern.\n * Patterns only have a single wildcard character which is *.\n * The behavior of * is that it matches zero or more other characters.\n */\nfunction namespaceMatches(namespace: string, patternToMatch: string): boolean {\n // simple case, no pattern matching required\n if (patternToMatch.indexOf(\"*\") === -1) {\n return namespace === patternToMatch;\n }\n\n let pattern = patternToMatch;\n\n // normalize successive * if needed\n if (patternToMatch.indexOf(\"**\") !== -1) {\n const patternParts = [];\n let lastCharacter = \"\";\n for (const character of patternToMatch) {\n if (character === \"*\" && lastCharacter === \"*\") {\n continue;\n } else {\n lastCharacter = character;\n patternParts.push(character);\n }\n }\n pattern = patternParts.join(\"\");\n }\n\n let namespaceIndex = 0;\n let patternIndex = 0;\n const patternLength = pattern.length;\n const namespaceLength = namespace.length;\n let lastWildcard = -1;\n let lastWildcardNamespace = -1;\n\n while (namespaceIndex < namespaceLength && patternIndex < patternLength) {\n if (pattern[patternIndex] === \"*\") {\n lastWildcard = patternIndex;\n patternIndex++;\n if (patternIndex === patternLength) {\n // if wildcard is the last character, it will match the remaining namespace string\n return true;\n }\n // now we let the wildcard eat characters until we match the next literal in the pattern\n while (namespace[namespaceIndex] !== pattern[patternIndex]) {\n namespaceIndex++;\n // reached the end of the namespace without a match\n if (namespaceIndex === namespaceLength) {\n return false;\n }\n }\n\n // now that we have a match, let's try to continue on\n // however, it's possible we could find a later match\n // so keep a reference in case we have to backtrack\n lastWildcardNamespace = namespaceIndex;\n namespaceIndex++;\n patternIndex++;\n continue;\n } else if (pattern[patternIndex] === namespace[namespaceIndex]) {\n // simple case: literal pattern matches so keep going\n patternIndex++;\n namespaceIndex++;\n } else if (lastWildcard >= 0) {\n // special case: we don't have a literal match, but there is a previous wildcard\n // which we can backtrack to and try having the wildcard eat the match instead\n patternIndex = lastWildcard + 1;\n namespaceIndex = lastWildcardNamespace + 1;\n // we've reached the end of the namespace without a match\n if (namespaceIndex === namespaceLength) {\n return false;\n }\n // similar to the previous logic, let's keep going until we find the next literal match\n while (namespace[namespaceIndex] !== pattern[patternIndex]) {\n namespaceIndex++;\n if (namespaceIndex === namespaceLength) {\n return false;\n }\n }\n lastWildcardNamespace = namespaceIndex;\n namespaceIndex++;\n patternIndex++;\n continue;\n } else {\n return false;\n }\n }\n\n const namespaceDone = namespaceIndex === namespace.length;\n const patternDone = patternIndex === pattern.length;\n // this is to detect the case of an unneeded final wildcard\n // e.g. the pattern `ab*` should match the string `ab`\n const trailingWildCard = patternIndex === pattern.length - 1 && pattern[patternIndex] === \"*\";\n return namespaceDone && (patternDone || trailingWildCard);\n}\n\nfunction disable(): string {\n const result = enabledString || \"\";\n enable(\"\");\n return result;\n}\n\nfunction createDebugger(namespace: string): Debugger {\n const newDebugger: Debugger = Object.assign(debug, {\n enabled: enabled(namespace),\n destroy,\n log: debugObj.log,\n namespace,\n extend,\n });\n\n function debug(...args: any[]): void {\n if (!newDebugger.enabled) {\n return;\n }\n if (args.length > 0) {\n args[0] = `${namespace} ${args[0]}`;\n }\n newDebugger.log(...args);\n }\n\n debuggers.push(newDebugger);\n\n return newDebugger;\n}\n\nfunction destroy(this: Debugger): boolean {\n const index = debuggers.indexOf(this);\n if (index >= 0) {\n debuggers.splice(index, 1);\n return true;\n }\n return false;\n}\n\nfunction extend(this: Debugger, namespace: string): Debugger {\n const newDebugger = createDebugger(`${this.namespace}:${namespace}`);\n newDebugger.log = this.log;\n return newDebugger;\n}\n\nexport default debugObj;\n"]}
|
package/package.json
CHANGED