@c4a/extract-ts 0.7.8 → 0.7.10-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +146 -130
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -11444,15 +11444,21 @@ function replaceWithCount(value, pattern, replacement, count) {
|
|
|
11444
11444
|
return replacement(...args.slice(0, -2));
|
|
11445
11445
|
});
|
|
11446
11446
|
}
|
|
11447
|
+
var SECRET_TEXT_KEY = "(?:[A-Za-z0-9_.-]*(?:password|passwd|pwd|secret|token|credential|cookie)[A-Za-z0-9_.-]*|api[-_]?key|access[-_]?(?:key|token)|private[-_]?key|client[-_]?secret|authorization)";
|
|
11448
|
+
var SECRET_TEXT_ASSIGNMENT = `(?:=\\s*|:\\s+(?=\\S)|:\\s*(?=["']))`;
|
|
11449
|
+
var AUTHORIZATION_TEXT_PATTERN = new RegExp(`(\\bauthorization\\s*:\\s*(?:bearer|basic)\\s+)` + `(?!${escapeRegExp(INDEXER_OUTPUT_REDACTION_MARKER)})[^\\s,;]+`, "giu");
|
|
11450
|
+
var QUERY_SECRET_TEXT_PATTERN = new RegExp(`([?&](?:access_token|refresh_token|api_key|password|secret)=)` + `(?!${escapeRegExp(INDEXER_OUTPUT_REDACTION_MARKER)})[^&#\\s]+`, "giu");
|
|
11451
|
+
var ASSIGNMENT_SECRET_TEXT_PATTERN = new RegExp(`((?:["']?${SECRET_TEXT_KEY}["']?)\\s*${SECRET_TEXT_ASSIGNMENT})` + `(?!["']?${escapeRegExp(INDEXER_OUTPUT_REDACTION_MARKER)})` + `(?:"(?:\\\\.|[^"])*"|'(?:\\\\.|[^'])*'|[^\\s,;}\\]]+)`, "giu");
|
|
11447
11452
|
function redactKnownText(value, count) {
|
|
11453
|
+
if (!value.includes(":") && !value.includes("=") && !value.includes("-----BEGIN ")) {
|
|
11454
|
+
return value;
|
|
11455
|
+
}
|
|
11448
11456
|
let output = value;
|
|
11449
11457
|
output = replaceWithCount(output, /-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/gu, INDEXER_OUTPUT_REDACTION_MARKER, count);
|
|
11450
|
-
output = replaceWithCount(output,
|
|
11458
|
+
output = replaceWithCount(output, AUTHORIZATION_TEXT_PATTERN, (_match, prefix) => `${prefix}${INDEXER_OUTPUT_REDACTION_MARKER}`, count);
|
|
11451
11459
|
output = replaceWithCount(output, /([a-z][a-z0-9+.-]*:\/\/)[^\s/@:]+:[^\s/@]+@/giu, (_match, prefix) => `${prefix}${INDEXER_OUTPUT_REDACTION_MARKER}@`, count);
|
|
11452
|
-
output = replaceWithCount(output,
|
|
11453
|
-
|
|
11454
|
-
const assignment = `(?:=\\s*|:\\s+(?=\\S)|:\\s*(?=["']))`;
|
|
11455
|
-
output = replaceWithCount(output, new RegExp(`((?:["']?${key}["']?)\\s*${assignment})` + `(?!["']?${escapeRegExp(INDEXER_OUTPUT_REDACTION_MARKER)})` + `(?:"(?:\\\\.|[^"])*"|'(?:\\\\.|[^'])*'|[^\\s,;}\\]]+)`, "giu"), (_match, prefix) => `${prefix}"${INDEXER_OUTPUT_REDACTION_MARKER}"`, count);
|
|
11460
|
+
output = replaceWithCount(output, QUERY_SECRET_TEXT_PATTERN, (_match, prefix) => `${prefix}${INDEXER_OUTPUT_REDACTION_MARKER}`, count);
|
|
11461
|
+
output = replaceWithCount(output, ASSIGNMENT_SECRET_TEXT_PATTERN, (_match, prefix) => `${prefix}"${INDEXER_OUTPUT_REDACTION_MARKER}"`, count);
|
|
11456
11462
|
return output;
|
|
11457
11463
|
}
|
|
11458
11464
|
function redactBlockedText(value, blocked, count) {
|
|
@@ -13163,9 +13169,11 @@ async function enrichPublicContracts(input) {
|
|
|
13163
13169
|
getNewLine: () => `
|
|
13164
13170
|
`
|
|
13165
13171
|
};
|
|
13166
|
-
const program = ts5.createProgram([...sources.keys()], options, host);
|
|
13167
13172
|
for (const source of sources.values())
|
|
13168
13173
|
input.symbols.push(...runtimeRegistrations(source), ...federationContracts(source));
|
|
13174
|
+
if (!input.symbols.some((symbol) => symbol.visibility === "exported" /* Exported */))
|
|
13175
|
+
return;
|
|
13176
|
+
const program = ts5.createProgram([...sources.keys()], options, host);
|
|
13169
13177
|
const checker = program.getTypeChecker();
|
|
13170
13178
|
const diagnosticsByFile = new Map;
|
|
13171
13179
|
for (const symbol of input.symbols) {
|
|
@@ -14485,6 +14493,8 @@ var scriptKind = (filePath) => {
|
|
|
14485
14493
|
};
|
|
14486
14494
|
var createEcmaScriptSourceFile = (source, filePath) => ts6.createSourceFile(filePath, source, ts6.ScriptTarget.Latest, true, scriptKind(filePath));
|
|
14487
14495
|
var treeSitterCompatibleJsxSource = (sourceFile, source) => {
|
|
14496
|
+
if (!source.includes("&"))
|
|
14497
|
+
return source;
|
|
14488
14498
|
const characters = source.split("");
|
|
14489
14499
|
let changed = false;
|
|
14490
14500
|
const visit2 = (node2) => {
|
|
@@ -14728,8 +14738,7 @@ var collectDynamicDiagnostics = (sourceFile) => {
|
|
|
14728
14738
|
visit2(sourceFile);
|
|
14729
14739
|
return diagnostics;
|
|
14730
14740
|
};
|
|
14731
|
-
var analyzeCommonJsModule = (source, filePath) => {
|
|
14732
|
-
const sourceFile = createEcmaScriptSourceFile(source, filePath);
|
|
14741
|
+
var analyzeCommonJsModule = (source, filePath, sourceFile = createEcmaScriptSourceFile(source, filePath)) => {
|
|
14733
14742
|
const bindings = collectBindings(sourceFile);
|
|
14734
14743
|
const bindingMap = new Map(bindings.map((binding) => [binding.localName, binding]));
|
|
14735
14744
|
const result = {
|
|
@@ -14967,101 +14976,105 @@ var traceFile = async (filePath, fs, state) => {
|
|
|
14967
14976
|
const tree = await parseFile(parserSource, jsxLike);
|
|
14968
14977
|
if (!tree)
|
|
14969
14978
|
return [];
|
|
14970
|
-
|
|
14971
|
-
|
|
14972
|
-
|
|
14973
|
-
|
|
14974
|
-
|
|
14975
|
-
|
|
14976
|
-
|
|
14977
|
-
|
|
14978
|
-
|
|
14979
|
-
|
|
14980
|
-
|
|
14981
|
-
|
|
14982
|
-
const exportsList = [];
|
|
14983
|
-
for (const node2 of root.namedChildren) {
|
|
14984
|
-
if (node2.type !== "export_statement")
|
|
14985
|
-
continue;
|
|
14986
|
-
const stringNode = node2.namedChildren.find((child) => child.type === "string");
|
|
14987
|
-
const exportClause = node2.namedChildren.find((child) => child.type === "export_clause");
|
|
14988
|
-
const declaration = node2.namedChildren.find((child) => DECLARATION_TYPES2.has(child.type));
|
|
14989
|
-
if (declaration) {
|
|
14990
|
-
for (const name of getDeclarationName(declaration)) {
|
|
14991
|
-
exportsList.push({ exportedName: name, localName: name, declarationFile: filePath });
|
|
14992
|
-
}
|
|
14993
|
-
continue;
|
|
14994
|
-
}
|
|
14995
|
-
if (node2.text.startsWith("export default ")) {
|
|
14996
|
-
const identifier = node2.namedChildren.find((child) => child.type === "identifier" || child.type === "type_identifier");
|
|
14997
|
-
if (identifier && localDeclarations.has(identifier.text)) {
|
|
14998
|
-
exportsList.push({
|
|
14999
|
-
exportedName: identifier.text,
|
|
15000
|
-
localName: identifier.text,
|
|
15001
|
-
declarationFile: filePath
|
|
15002
|
-
});
|
|
15003
|
-
}
|
|
15004
|
-
continue;
|
|
14979
|
+
try {
|
|
14980
|
+
const root = tree.rootNode;
|
|
14981
|
+
const localDeclarations = collectLocalDeclarations(root);
|
|
14982
|
+
const importBindings = collectImportBindings(root);
|
|
14983
|
+
for (const declaration of commonJs.syntheticDeclarations) {
|
|
14984
|
+
localDeclarations.set(declaration.name, declaration.name);
|
|
14985
|
+
}
|
|
14986
|
+
for (const binding of commonJs.bindings) {
|
|
14987
|
+
importBindings.set(binding.localName, {
|
|
14988
|
+
source: binding.source,
|
|
14989
|
+
importedName: binding.importedName
|
|
14990
|
+
});
|
|
15005
14991
|
}
|
|
15006
|
-
|
|
15007
|
-
|
|
15008
|
-
|
|
15009
|
-
|
|
15010
|
-
|
|
14992
|
+
const exportsList = [];
|
|
14993
|
+
for (const node2 of root.namedChildren) {
|
|
14994
|
+
if (node2.type !== "export_statement")
|
|
14995
|
+
continue;
|
|
14996
|
+
const stringNode = node2.namedChildren.find((child) => child.type === "string");
|
|
14997
|
+
const exportClause = node2.namedChildren.find((child) => child.type === "export_clause");
|
|
14998
|
+
const declaration = node2.namedChildren.find((child) => DECLARATION_TYPES2.has(child.type));
|
|
14999
|
+
if (declaration) {
|
|
15000
|
+
for (const name of getDeclarationName(declaration)) {
|
|
15001
|
+
exportsList.push({ exportedName: name, localName: name, declarationFile: filePath });
|
|
15011
15002
|
}
|
|
15003
|
+
continue;
|
|
15012
15004
|
}
|
|
15013
|
-
|
|
15014
|
-
|
|
15015
|
-
|
|
15016
|
-
for (const specifier of exportClause.namedChildren.filter((child) => child.type === "export_specifier")) {
|
|
15017
|
-
const parsed = parseExportSpecifier(specifier);
|
|
15018
|
-
if (!parsed)
|
|
15019
|
-
continue;
|
|
15020
|
-
if (localDeclarations.has(parsed.localName)) {
|
|
15005
|
+
if (node2.text.startsWith("export default ")) {
|
|
15006
|
+
const identifier = node2.namedChildren.find((child) => child.type === "identifier" || child.type === "type_identifier");
|
|
15007
|
+
if (identifier && localDeclarations.has(identifier.text)) {
|
|
15021
15008
|
exportsList.push({
|
|
15022
|
-
exportedName:
|
|
15023
|
-
localName:
|
|
15009
|
+
exportedName: identifier.text,
|
|
15010
|
+
localName: identifier.text,
|
|
15024
15011
|
declarationFile: filePath
|
|
15025
15012
|
});
|
|
15026
|
-
continue;
|
|
15027
15013
|
}
|
|
15028
|
-
|
|
15029
|
-
|
|
15030
|
-
|
|
15014
|
+
continue;
|
|
15015
|
+
}
|
|
15016
|
+
if (!exportClause) {
|
|
15017
|
+
if (stringNode && node2.text.startsWith("export *")) {
|
|
15018
|
+
const targetPath2 = await resolveImportSourcePath(filePath, stripQuotes(stringNode.text), fs, state.resolver);
|
|
15019
|
+
if (targetPath2) {
|
|
15020
|
+
exportsList.push(...await traceFile(targetPath2, fs, state));
|
|
15021
|
+
}
|
|
15031
15022
|
}
|
|
15023
|
+
continue;
|
|
15032
15024
|
}
|
|
15033
|
-
|
|
15034
|
-
|
|
15035
|
-
|
|
15036
|
-
|
|
15037
|
-
|
|
15038
|
-
|
|
15039
|
-
|
|
15040
|
-
|
|
15041
|
-
|
|
15025
|
+
if (!stringNode) {
|
|
15026
|
+
for (const specifier of exportClause.namedChildren.filter((child) => child.type === "export_specifier")) {
|
|
15027
|
+
const parsed = parseExportSpecifier(specifier);
|
|
15028
|
+
if (!parsed)
|
|
15029
|
+
continue;
|
|
15030
|
+
if (localDeclarations.has(parsed.localName)) {
|
|
15031
|
+
exportsList.push({
|
|
15032
|
+
exportedName: parsed.exportedName,
|
|
15033
|
+
localName: parsed.localName,
|
|
15034
|
+
declarationFile: filePath
|
|
15035
|
+
});
|
|
15036
|
+
continue;
|
|
15037
|
+
}
|
|
15038
|
+
const importBinding = importBindings.get(parsed.localName);
|
|
15039
|
+
if (importBinding) {
|
|
15040
|
+
exportsList.push(...await traceImportedBinding(filePath, importBinding, parsed.exportedName, fs, state));
|
|
15041
|
+
}
|
|
15042
|
+
}
|
|
15042
15043
|
continue;
|
|
15043
|
-
|
|
15044
|
-
|
|
15044
|
+
}
|
|
15045
|
+
const targetPath = await resolveImportSourcePath(filePath, stripQuotes(stringNode.text), fs, state.resolver);
|
|
15046
|
+
if (!targetPath)
|
|
15045
15047
|
continue;
|
|
15046
|
-
|
|
15047
|
-
|
|
15048
|
-
|
|
15049
|
-
|
|
15050
|
-
|
|
15048
|
+
const traced = await traceFile(targetPath, fs, state);
|
|
15049
|
+
for (const specifier of exportClause.namedChildren.filter((child) => child.type === "export_specifier")) {
|
|
15050
|
+
const parsed = parseExportSpecifier(specifier);
|
|
15051
|
+
if (!parsed)
|
|
15052
|
+
continue;
|
|
15053
|
+
const match = traced.find((item) => item.exportedName === parsed.localName);
|
|
15054
|
+
if (!match)
|
|
15055
|
+
continue;
|
|
15056
|
+
exportsList.push({
|
|
15057
|
+
exportedName: parsed.exportedName,
|
|
15058
|
+
localName: match.localName,
|
|
15059
|
+
declarationFile: match.declarationFile
|
|
15060
|
+
});
|
|
15061
|
+
}
|
|
15051
15062
|
}
|
|
15063
|
+
exportsList.push(...await traceCommonJsExports({
|
|
15064
|
+
analysis: commonJs,
|
|
15065
|
+
filePath,
|
|
15066
|
+
localDeclarations,
|
|
15067
|
+
traceImported: (source2, importedName, exportedName) => traceImportedBinding(filePath, { source: source2, importedName }, exportedName, fs, state),
|
|
15068
|
+
traceWildcard: async (source2) => {
|
|
15069
|
+
const targetPath = await resolveImportSourcePath(filePath, source2, fs, state.resolver);
|
|
15070
|
+
return targetPath ? traceFile(targetPath, fs, state) : [];
|
|
15071
|
+
}
|
|
15072
|
+
}));
|
|
15073
|
+
return uniqueExports(exportsList);
|
|
15074
|
+
} finally {
|
|
15075
|
+
tree.delete();
|
|
15076
|
+
state.inFlight.delete(filePath);
|
|
15052
15077
|
}
|
|
15053
|
-
exportsList.push(...await traceCommonJsExports({
|
|
15054
|
-
analysis: commonJs,
|
|
15055
|
-
filePath,
|
|
15056
|
-
localDeclarations,
|
|
15057
|
-
traceImported: (source2, importedName, exportedName) => traceImportedBinding(filePath, { source: source2, importedName }, exportedName, fs, state),
|
|
15058
|
-
traceWildcard: async (source2) => {
|
|
15059
|
-
const targetPath = await resolveImportSourcePath(filePath, source2, fs, state.resolver);
|
|
15060
|
-
return targetPath ? traceFile(targetPath, fs, state) : [];
|
|
15061
|
-
}
|
|
15062
|
-
}));
|
|
15063
|
-
state.inFlight.delete(filePath);
|
|
15064
|
-
return uniqueExports(exportsList);
|
|
15065
15078
|
})();
|
|
15066
15079
|
state.cache.set(filePath, promise);
|
|
15067
15080
|
return promise;
|
|
@@ -15115,8 +15128,7 @@ var declarationName = (node2, sourceFile) => {
|
|
|
15115
15128
|
}
|
|
15116
15129
|
return null;
|
|
15117
15130
|
};
|
|
15118
|
-
var collectStaticCallRelations = (source, filePath, importBindings) => {
|
|
15119
|
-
const sourceFile = createEcmaScriptSourceFile(source, filePath);
|
|
15131
|
+
var collectStaticCallRelations = (source, filePath, importBindings, sourceFile = createEcmaScriptSourceFile(source, filePath)) => {
|
|
15120
15132
|
const relations = [];
|
|
15121
15133
|
const visit2 = (node2, owner) => {
|
|
15122
15134
|
const namedOwner = declarationName(node2, sourceFile) ?? owner;
|
|
@@ -15432,7 +15444,7 @@ var appendCommonJsSyntheticDeclarations = (commonJs, filePath, declarations) =>
|
|
|
15432
15444
|
var analyzeFile = async (filePath, fs, resolver = { mappings: [] }) => {
|
|
15433
15445
|
const source = await fs.readFile(filePath);
|
|
15434
15446
|
const sourceFile = createEcmaScriptSourceFile(source, filePath);
|
|
15435
|
-
const commonJs = analyzeCommonJsModule(source, filePath);
|
|
15447
|
+
const commonJs = analyzeCommonJsModule(source, filePath, sourceFile);
|
|
15436
15448
|
const jsxLike = isJsxLikePath(filePath);
|
|
15437
15449
|
const parserSource = jsxLike ? treeSitterCompatibleJsxSource(sourceFile, source) : source;
|
|
15438
15450
|
const tree = await parseFile(parserSource, jsxLike);
|
|
@@ -15456,47 +15468,51 @@ var analyzeFile = async (filePath, fs, resolver = { mappings: [] }) => {
|
|
|
15456
15468
|
diagnostics
|
|
15457
15469
|
};
|
|
15458
15470
|
}
|
|
15459
|
-
|
|
15460
|
-
|
|
15461
|
-
|
|
15462
|
-
|
|
15463
|
-
|
|
15464
|
-
|
|
15465
|
-
|
|
15466
|
-
|
|
15467
|
-
|
|
15468
|
-
|
|
15469
|
-
const root = tree.rootNode;
|
|
15470
|
-
const relations = [];
|
|
15471
|
-
const importBindings = await collectImportBindings2(root, filePath, fs, resolver, relations, commonJs);
|
|
15472
|
-
const declarations = new Map;
|
|
15473
|
-
for (const relation of relations) {
|
|
15474
|
-
if (relation.from === "") {
|
|
15475
|
-
relation.from = filePath;
|
|
15471
|
+
try {
|
|
15472
|
+
if (commonJs.diagnostics.length > 0) {
|
|
15473
|
+
return {
|
|
15474
|
+
declarations: new Map,
|
|
15475
|
+
importBindings: new Map,
|
|
15476
|
+
relations: [],
|
|
15477
|
+
lines: countLines(source),
|
|
15478
|
+
disposition: "unsupported",
|
|
15479
|
+
diagnostics: commonJs.diagnostics
|
|
15480
|
+
};
|
|
15476
15481
|
}
|
|
15477
|
-
|
|
15478
|
-
|
|
15479
|
-
|
|
15480
|
-
|
|
15481
|
-
|
|
15482
|
+
const root = tree.rootNode;
|
|
15483
|
+
const relations = [];
|
|
15484
|
+
const importBindings = await collectImportBindings2(root, filePath, fs, resolver, relations, commonJs);
|
|
15485
|
+
const declarations = new Map;
|
|
15486
|
+
for (const relation of relations) {
|
|
15487
|
+
if (relation.from === "") {
|
|
15488
|
+
relation.from = filePath;
|
|
15489
|
+
}
|
|
15482
15490
|
}
|
|
15483
|
-
|
|
15484
|
-
|
|
15485
|
-
|
|
15486
|
-
|
|
15487
|
-
|
|
15491
|
+
for (const child of root.namedChildren) {
|
|
15492
|
+
if (DECLARATION_TYPES.has(child.type)) {
|
|
15493
|
+
analyzeDeclaration(child, filePath, declarations, importBindings, relations);
|
|
15494
|
+
continue;
|
|
15495
|
+
}
|
|
15496
|
+
if (child.type !== "export_statement")
|
|
15497
|
+
continue;
|
|
15498
|
+
const declaration = child.namedChildren.find((node2) => DECLARATION_TYPES.has(node2.type));
|
|
15499
|
+
if (declaration) {
|
|
15500
|
+
analyzeDeclaration(declaration, filePath, declarations, importBindings, relations);
|
|
15501
|
+
}
|
|
15488
15502
|
}
|
|
15503
|
+
appendCommonJsSyntheticDeclarations(commonJs, filePath, declarations);
|
|
15504
|
+
relations.push(...collectStaticCallRelations(source, filePath, importBindings, sourceFile));
|
|
15505
|
+
return {
|
|
15506
|
+
declarations,
|
|
15507
|
+
importBindings,
|
|
15508
|
+
relations: relations.map((relation) => ({ ...relation, file: filePath })),
|
|
15509
|
+
lines: countLines(source),
|
|
15510
|
+
disposition: "analyzed",
|
|
15511
|
+
diagnostics: []
|
|
15512
|
+
};
|
|
15513
|
+
} finally {
|
|
15514
|
+
tree.delete();
|
|
15489
15515
|
}
|
|
15490
|
-
appendCommonJsSyntheticDeclarations(commonJs, filePath, declarations);
|
|
15491
|
-
relations.push(...collectStaticCallRelations(source, filePath, importBindings));
|
|
15492
|
-
return {
|
|
15493
|
-
declarations,
|
|
15494
|
-
importBindings,
|
|
15495
|
-
relations: relations.map((relation) => ({ ...relation, file: filePath })),
|
|
15496
|
-
lines: countLines(source),
|
|
15497
|
-
disposition: "analyzed",
|
|
15498
|
-
diagnostics: []
|
|
15499
|
-
};
|
|
15500
15516
|
};
|
|
15501
15517
|
|
|
15502
15518
|
// src/symbolExtractor.ts
|