@rasputin-ai/node 0.12.1 → 0.13.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/dist/auto-instrumentation/bun-plugin.d.ts.map +1 -1
- package/dist/auto-instrumentation/instrument-compiled-esm.d.ts.map +1 -1
- package/dist/auto-instrumentation/instrumentation-manifest-registry.d.ts +2 -1
- package/dist/auto-instrumentation/instrumentation-manifest-registry.d.ts.map +1 -1
- package/dist/auto-instrumentation/node-hooks.d.ts.map +1 -1
- package/dist/auto-instrumentation/transform-disk-cache.d.ts.map +1 -1
- package/dist/execution-recorder/bind-adaptive-recorder.d.ts +4 -2
- package/dist/execution-recorder/bind-adaptive-recorder.d.ts.map +1 -1
- package/dist/execution-recorder/execution-recorder-hooks.d.ts +3 -0
- package/dist/execution-recorder/execution-recorder-hooks.d.ts.map +1 -1
- package/dist/execution-recorder/execution-recorder-types.d.ts +1 -2
- package/dist/execution-recorder/execution-recorder-types.d.ts.map +1 -1
- package/dist/execution-recorder/execution-recorder.d.ts.map +1 -1
- package/dist/execution-recorder/execution-recording-sync.d.ts +2 -2
- package/dist/execution-recorder/execution-recording-sync.d.ts.map +1 -1
- package/dist/execution-recorder/function-plan.d.ts +3 -1
- package/dist/execution-recorder/function-plan.d.ts.map +1 -1
- package/dist/function-metrics/bind-function-metrics.d.ts +19 -0
- package/dist/function-metrics/bind-function-metrics.d.ts.map +1 -0
- package/dist/function-metrics/create-metrics-only-runtime.d.ts +4 -0
- package/dist/function-metrics/create-metrics-only-runtime.d.ts.map +1 -0
- package/dist/function-metrics/encode-function-metrics-upload.d.ts +14 -0
- package/dist/function-metrics/encode-function-metrics-upload.d.ts.map +1 -0
- package/dist/function-metrics/function-metric-declaration-registry.d.ts +9 -0
- package/dist/function-metrics/function-metric-declaration-registry.d.ts.map +1 -0
- package/dist/function-metrics/function-metrics-batches.d.ts +35 -0
- package/dist/function-metrics/function-metrics-batches.d.ts.map +1 -0
- package/dist/function-metrics/function-metrics-collector.d.ts +45 -0
- package/dist/function-metrics/function-metrics-collector.d.ts.map +1 -0
- package/dist/function-metrics/function-metrics-exporter.d.ts +23 -0
- package/dist/function-metrics/function-metrics-exporter.d.ts.map +1 -0
- package/dist/function-metrics/install-function-metric-declaration-sink.d.ts +2 -0
- package/dist/function-metrics/install-function-metric-declaration-sink.d.ts.map +1 -0
- package/dist/function-metrics/intern-prepared-metrics.d.ts +4 -0
- package/dist/function-metrics/intern-prepared-metrics.d.ts.map +1 -0
- package/dist/function-metrics/send-function-metrics-batch.d.ts +25 -0
- package/dist/function-metrics/send-function-metrics-batch.d.ts.map +1 -0
- package/dist/function-metrics/settle-function-metrics.d.ts +5 -0
- package/dist/function-metrics/settle-function-metrics.d.ts.map +1 -0
- package/dist/index.js +1624 -147
- package/dist/instrument/build.js +458 -162
- package/dist/instrument/bun.js +454 -132
- package/dist/instrument/node.js +452 -132
- package/dist/internal.d.ts +2 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1600 -139
- package/dist/rasputin-init.d.ts +17 -4
- package/dist/rasputin-init.d.ts.map +1 -1
- package/dist/sdk-meta.d.ts +1 -1
- package/package.json +2 -2
package/dist/instrument/bun.js
CHANGED
|
@@ -5,6 +5,28 @@ import { plugin } from "bun";
|
|
|
5
5
|
import { readFile } from "node:fs/promises";
|
|
6
6
|
import { resolve as resolve5 } from "node:path";
|
|
7
7
|
|
|
8
|
+
// src/function-metrics/function-metric-declaration-registry.ts
|
|
9
|
+
var REGISTRY_SYMBOL = Symbol.for("rasputin.functionMetrics.declarations.v1");
|
|
10
|
+
var getRegistry = () => {
|
|
11
|
+
const existing = Reflect.get(globalThis, REGISTRY_SYMBOL);
|
|
12
|
+
if (typeof existing === "object" && existing !== null) {
|
|
13
|
+
const byRuntimeId = Reflect.get(existing, "byRuntimeId");
|
|
14
|
+
if (byRuntimeId instanceof Map) return { byRuntimeId };
|
|
15
|
+
}
|
|
16
|
+
const registry = {
|
|
17
|
+
byRuntimeId: /* @__PURE__ */ new Map()
|
|
18
|
+
};
|
|
19
|
+
Reflect.set(globalThis, REGISTRY_SYMBOL, registry);
|
|
20
|
+
return registry;
|
|
21
|
+
};
|
|
22
|
+
var registerFunctionMetricDeclarations = (declarations) => {
|
|
23
|
+
const { byRuntimeId } = getRegistry();
|
|
24
|
+
for (const declaration of declarations) {
|
|
25
|
+
if (byRuntimeId.has(declaration.runtime_id)) continue;
|
|
26
|
+
byRuntimeId.set(declaration.runtime_id, declaration);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
8
30
|
// src/auto-instrumentation/instrumentation-manifest-registry.ts
|
|
9
31
|
import { resolve } from "node:path";
|
|
10
32
|
import {
|
|
@@ -51,7 +73,7 @@ var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
|
|
|
51
73
|
// src/auto-instrumentation/instrumentation-manifest-registry.ts
|
|
52
74
|
var INSTRUMENTATION_MANIFEST_SYMBOL = "rasputin.instrumentation.manifest.v3";
|
|
53
75
|
var registrySymbol = Symbol.for(INSTRUMENTATION_MANIFEST_SYMBOL);
|
|
54
|
-
var
|
|
76
|
+
var getRegistry2 = () => {
|
|
55
77
|
const existing = Reflect.get(globalThis, registrySymbol);
|
|
56
78
|
if (existing?.__rasputinManifestRegistry && existing.files instanceof Map && typeof existing.generation === "number" && typeof existing.uploadedGeneration === "number") {
|
|
57
79
|
const registry2 = existing;
|
|
@@ -69,7 +91,7 @@ var getRegistry = () => {
|
|
|
69
91
|
return registry;
|
|
70
92
|
};
|
|
71
93
|
var recordInstrumentationManifestDelta = (filePath, delta) => {
|
|
72
|
-
const registry =
|
|
94
|
+
const registry = getRegistry2();
|
|
73
95
|
if (delta.alreadyInstrumented) {
|
|
74
96
|
registry.alreadyInstrumented += 1;
|
|
75
97
|
return;
|
|
@@ -122,6 +144,7 @@ import {
|
|
|
122
144
|
} from "node:fs";
|
|
123
145
|
import { homedir } from "node:os";
|
|
124
146
|
import { dirname as dirname2, join as join2 } from "node:path";
|
|
147
|
+
import { sourceLocatorFromFile as sourceLocatorFromFile4 } from "@rasputin-ai/core";
|
|
125
148
|
|
|
126
149
|
// ../instrumentation/src/classify-function.ts
|
|
127
150
|
import ts3 from "typescript";
|
|
@@ -730,7 +753,7 @@ var attachInlineSourceMap = (original, generated, filePath, edits, basenameOf) =
|
|
|
730
753
|
|
|
731
754
|
// ../instrumentation/src/browser-function-edits.ts
|
|
732
755
|
import { propertyNameIsSensitive } from "@rasputin-ai/core";
|
|
733
|
-
import
|
|
756
|
+
import ts10 from "typescript";
|
|
734
757
|
|
|
735
758
|
// ../instrumentation/src/suspension-whitelist.ts
|
|
736
759
|
import ts4 from "typescript";
|
|
@@ -861,34 +884,286 @@ var decideAsyncInstrumentation = (node, sourceFile) => {
|
|
|
861
884
|
|
|
862
885
|
// ../instrumentation/src/transform-source.ts
|
|
863
886
|
import { basename, resolve as resolve3 } from "node:path";
|
|
864
|
-
import
|
|
887
|
+
import ts9 from "typescript";
|
|
865
888
|
|
|
866
|
-
// ../instrumentation/src/
|
|
889
|
+
// ../instrumentation/src/function-metric-declarations.ts
|
|
890
|
+
import {
|
|
891
|
+
canonicalizeFunctionIdentityPath,
|
|
892
|
+
FUNCTION_IDENTITY_VERSION,
|
|
893
|
+
functionIdentityKey,
|
|
894
|
+
sha256Hex,
|
|
895
|
+
sourceLocatorFromFile as sourceLocatorFromFile3
|
|
896
|
+
} from "@rasputin-ai/core";
|
|
867
897
|
import ts5 from "typescript";
|
|
898
|
+
var printer = ts5.createPrinter({ removeComments: true, newLine: ts5.NewLineKind.LineFeed });
|
|
899
|
+
var propertyText = (name) => {
|
|
900
|
+
if (!name) return void 0;
|
|
901
|
+
if (ts5.isIdentifier(name) || ts5.isStringLiteral(name) || ts5.isNumericLiteral(name)) {
|
|
902
|
+
return name.text;
|
|
903
|
+
}
|
|
904
|
+
if (ts5.isNoSubstitutionTemplateLiteral(name)) return name.text;
|
|
905
|
+
return void 0;
|
|
906
|
+
};
|
|
907
|
+
var hasStaticModifier = (node) => {
|
|
908
|
+
if (!ts5.canHaveModifiers(node)) return false;
|
|
909
|
+
const modifiers = ts5.getModifiers(node);
|
|
910
|
+
if (!modifiers) return false;
|
|
911
|
+
return modifiers.some((modifier) => modifier.kind === ts5.SyntaxKind.StaticKeyword);
|
|
912
|
+
};
|
|
913
|
+
var memberIsStatic = (node) => {
|
|
914
|
+
if (hasStaticModifier(node)) return true;
|
|
915
|
+
const parent = node.parent;
|
|
916
|
+
const isPropertyValue = ts5.isArrowFunction(node) || ts5.isFunctionExpression(node);
|
|
917
|
+
if (!isPropertyValue || !ts5.isPropertyDeclaration(parent)) return false;
|
|
918
|
+
return hasStaticModifier(parent);
|
|
919
|
+
};
|
|
920
|
+
var kindOf = (node) => {
|
|
921
|
+
if (ts5.isConstructorDeclaration(node)) return "constructor";
|
|
922
|
+
if (ts5.isGetAccessor(node)) return "getter";
|
|
923
|
+
if (ts5.isSetAccessor(node)) return "setter";
|
|
924
|
+
if (ts5.isMethodDeclaration(node)) return "method";
|
|
925
|
+
if (ts5.isArrowFunction(node)) return "arrow";
|
|
926
|
+
return "function";
|
|
927
|
+
};
|
|
928
|
+
var bindingOf = (node) => {
|
|
929
|
+
if (ts5.isConstructorDeclaration(node)) return "constructor";
|
|
930
|
+
const ownName = propertyText(node.name);
|
|
931
|
+
if (ownName) return ownName;
|
|
932
|
+
const parent = node.parent;
|
|
933
|
+
if (ts5.isVariableDeclaration(parent) && ts5.isIdentifier(parent.name)) {
|
|
934
|
+
return parent.name.text;
|
|
935
|
+
}
|
|
936
|
+
if (ts5.isPropertyAssignment(parent) || ts5.isPropertyDeclaration(parent)) {
|
|
937
|
+
return propertyText(parent.name);
|
|
938
|
+
}
|
|
939
|
+
return void 0;
|
|
940
|
+
};
|
|
941
|
+
var calleeText = (expression) => {
|
|
942
|
+
if (ts5.isIdentifier(expression)) return expression.text;
|
|
943
|
+
if (!ts5.isPropertyAccessExpression(expression) || !ts5.isIdentifier(expression.name)) {
|
|
944
|
+
return void 0;
|
|
945
|
+
}
|
|
946
|
+
const object = calleeText(expression.expression);
|
|
947
|
+
if (!object) return void 0;
|
|
948
|
+
return `${object}.${expression.name.text}`;
|
|
949
|
+
};
|
|
950
|
+
var soleCallbackCallee = (node) => {
|
|
951
|
+
const parent = node.parent;
|
|
952
|
+
if (ts5.isCallExpression(parent)) {
|
|
953
|
+
if (parent.arguments.length !== 1 || parent.arguments[0] !== node) return void 0;
|
|
954
|
+
return parent.expression;
|
|
955
|
+
}
|
|
956
|
+
if (!ts5.isNewExpression(parent) || !parent.arguments) return void 0;
|
|
957
|
+
if (parent.arguments.length !== 1 || parent.arguments[0] !== node) return void 0;
|
|
958
|
+
return parent.expression;
|
|
959
|
+
};
|
|
960
|
+
var withScope = (scopes, kind, name) => {
|
|
961
|
+
if (!name) return scopes;
|
|
962
|
+
return [...scopes, { kind, name }];
|
|
963
|
+
};
|
|
964
|
+
var fingerprintOf = (node, sourceFile) => {
|
|
965
|
+
const printed = printer.printNode(ts5.EmitHint.Unspecified, node, sourceFile);
|
|
966
|
+
const normalized = printed.replace(/\s+/g, "");
|
|
967
|
+
return `fp1_${sha256Hex(normalized)}`;
|
|
968
|
+
};
|
|
969
|
+
var sourceRange = (node, sourceFile, filePath, mapLocation) => {
|
|
970
|
+
const start = mappedLocation(sourceFile, node.getStart(sourceFile), filePath, mapLocation);
|
|
971
|
+
const end = mappedLocation(sourceFile, node.end, filePath, mapLocation);
|
|
972
|
+
if (!start || !end) return null;
|
|
973
|
+
return {
|
|
974
|
+
start_line: start.line,
|
|
975
|
+
start_column: start.column,
|
|
976
|
+
end_line: end.line,
|
|
977
|
+
end_column: end.column
|
|
978
|
+
};
|
|
979
|
+
};
|
|
980
|
+
var isFunctionNode = (node) => {
|
|
981
|
+
const isFunction = ts5.isFunctionDeclaration(node) || ts5.isFunctionExpression(node) || ts5.isArrowFunction(node) || ts5.isMethodDeclaration(node) || ts5.isGetAccessor(node) || ts5.isSetAccessor(node) || ts5.isConstructorDeclaration(node);
|
|
982
|
+
return isFunction && Boolean(node.body);
|
|
983
|
+
};
|
|
984
|
+
var anchoredName = (candidate, anchorCount) => {
|
|
985
|
+
if (candidate.binding || !candidate.anchor) return void 0;
|
|
986
|
+
if (anchorCount.get(candidate.anchor) !== 1) return void 0;
|
|
987
|
+
const binding = candidate.anchor.split(".").at(-1) ?? candidate.anchor;
|
|
988
|
+
return {
|
|
989
|
+
binding,
|
|
990
|
+
scopes: withScope(candidate.scopes, "property", candidate.anchor)
|
|
991
|
+
};
|
|
992
|
+
};
|
|
993
|
+
var stableDescriptor = (candidate, packagePath, packageName, anchorCount) => {
|
|
994
|
+
const anchored = anchoredName(candidate, anchorCount);
|
|
995
|
+
const binding = candidate.binding ?? anchored?.binding;
|
|
996
|
+
const scopes = anchored?.scopes ?? candidate.scopes;
|
|
997
|
+
if (candidate.ancestorAmbiguous || !binding || !packagePath || !packageName) return void 0;
|
|
998
|
+
return {
|
|
999
|
+
identity_version: FUNCTION_IDENTITY_VERSION,
|
|
1000
|
+
identity_kind: "stable",
|
|
1001
|
+
source_basis: "package",
|
|
1002
|
+
package_name: packageName,
|
|
1003
|
+
path: packagePath,
|
|
1004
|
+
scopes,
|
|
1005
|
+
declaration_kind: candidate.kind,
|
|
1006
|
+
binding_name: binding,
|
|
1007
|
+
is_static: candidate.isStatic
|
|
1008
|
+
};
|
|
1009
|
+
};
|
|
1010
|
+
var walkCandidates = (sourceFile, runtimeIdByNode) => {
|
|
1011
|
+
const candidates = [];
|
|
1012
|
+
const visit = (node, scopes, ancestorAmbiguous, parent) => {
|
|
1013
|
+
if (isFunctionNode(node)) {
|
|
1014
|
+
const binding = bindingOf(node);
|
|
1015
|
+
const index = candidates.length;
|
|
1016
|
+
const callee = binding ? void 0 : soleCallbackCallee(node);
|
|
1017
|
+
candidates.push({
|
|
1018
|
+
node,
|
|
1019
|
+
scopes,
|
|
1020
|
+
ancestorAmbiguous,
|
|
1021
|
+
binding,
|
|
1022
|
+
kind: kindOf(node),
|
|
1023
|
+
isStatic: memberIsStatic(node),
|
|
1024
|
+
anchor: callee ? calleeText(callee) : void 0,
|
|
1025
|
+
parent,
|
|
1026
|
+
runtimeId: runtimeIdByNode.get(node)
|
|
1027
|
+
});
|
|
1028
|
+
const nextScopes = binding && !ancestorAmbiguous ? withScope(scopes, "function", binding) : scopes;
|
|
1029
|
+
const childAmbiguous = ancestorAmbiguous || !binding;
|
|
1030
|
+
ts5.forEachChild(node, (child) => visit(child, nextScopes, childAmbiguous, index));
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
if ((ts5.isClassDeclaration(node) || ts5.isClassExpression(node)) && node.name) {
|
|
1034
|
+
const next = withScope(scopes, "class", node.name.text);
|
|
1035
|
+
ts5.forEachChild(node, (child) => visit(child, next, ancestorAmbiguous, parent));
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
if (ts5.isModuleDeclaration(node) && ts5.isIdentifier(node.name)) {
|
|
1039
|
+
const next = withScope(scopes, "namespace", node.name.text);
|
|
1040
|
+
ts5.forEachChild(node, (child) => visit(child, next, ancestorAmbiguous, parent));
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
if (ts5.isVariableDeclaration(node) && ts5.isIdentifier(node.name) && node.initializer && ts5.isObjectLiteralExpression(node.initializer)) {
|
|
1044
|
+
visit(
|
|
1045
|
+
node.initializer,
|
|
1046
|
+
withScope(scopes, "object", node.name.text),
|
|
1047
|
+
ancestorAmbiguous,
|
|
1048
|
+
parent
|
|
1049
|
+
);
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
if (ts5.isPropertyAssignment(node) && node.initializer && ts5.isObjectLiteralExpression(node.initializer)) {
|
|
1053
|
+
const name = propertyText(node.name);
|
|
1054
|
+
visit(node.initializer, withScope(scopes, "property", name), ancestorAmbiguous, parent);
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
ts5.forEachChild(node, (child) => visit(child, scopes, ancestorAmbiguous, parent));
|
|
1058
|
+
};
|
|
1059
|
+
visit(sourceFile, [], false, void 0);
|
|
1060
|
+
return candidates;
|
|
1061
|
+
};
|
|
1062
|
+
var blockDescendants = (candidates, blocked, index) => {
|
|
1063
|
+
if (blocked.has(index)) return;
|
|
1064
|
+
blocked.add(index);
|
|
1065
|
+
for (let child = 0; child < candidates.length; child += 1) {
|
|
1066
|
+
const candidate = candidates[child];
|
|
1067
|
+
if (candidate?.parent === index) blockDescendants(candidates, blocked, child);
|
|
1068
|
+
}
|
|
1069
|
+
};
|
|
1070
|
+
var releaseScopedDescriptor = (runtimeId) => ({
|
|
1071
|
+
identity_version: FUNCTION_IDENTITY_VERSION,
|
|
1072
|
+
identity_kind: "release_scoped",
|
|
1073
|
+
declaration_id: runtimeId
|
|
1074
|
+
});
|
|
1075
|
+
var collectFunctionMetricDeclarations = (input) => {
|
|
1076
|
+
const runtimeIdByNode = new Map(input.functions.map((item) => [item.node, item.runtimeId]));
|
|
1077
|
+
const candidates = walkCandidates(input.sourceFile, runtimeIdByNode);
|
|
1078
|
+
const anchorCount = /* @__PURE__ */ new Map();
|
|
1079
|
+
for (const candidate of candidates) {
|
|
1080
|
+
if (!candidate.anchor) continue;
|
|
1081
|
+
anchorCount.set(candidate.anchor, (anchorCount.get(candidate.anchor) ?? 0) + 1);
|
|
1082
|
+
}
|
|
1083
|
+
const locator = input.originalAst ? sourceLocatorFromFile3(input.filePath) : void 0;
|
|
1084
|
+
const packageName = locator?.packageName;
|
|
1085
|
+
const packagePath = locator && packageName ? canonicalizeFunctionIdentityPath(locator.packageRelativePath) : void 0;
|
|
1086
|
+
const rows = candidates.map((candidate) => ({
|
|
1087
|
+
candidate,
|
|
1088
|
+
descriptor: stableDescriptor(candidate, packagePath, packageName, anchorCount)
|
|
1089
|
+
}));
|
|
1090
|
+
const keyCount = /* @__PURE__ */ new Map();
|
|
1091
|
+
for (const row of rows) {
|
|
1092
|
+
if (!row.descriptor) continue;
|
|
1093
|
+
const key = functionIdentityKey(row.descriptor);
|
|
1094
|
+
keyCount.set(key, (keyCount.get(key) ?? 0) + 1);
|
|
1095
|
+
}
|
|
1096
|
+
const blocked = /* @__PURE__ */ new Set();
|
|
1097
|
+
for (const [index, row] of rows.entries()) {
|
|
1098
|
+
if (!row.descriptor) {
|
|
1099
|
+
blockDescendants(candidates, blocked, index);
|
|
1100
|
+
continue;
|
|
1101
|
+
}
|
|
1102
|
+
const key = functionIdentityKey(row.descriptor);
|
|
1103
|
+
if ((keyCount.get(key) ?? 0) > 1) blockDescendants(candidates, blocked, index);
|
|
1104
|
+
}
|
|
1105
|
+
const declarations = [];
|
|
1106
|
+
for (const [index, row] of rows.entries()) {
|
|
1107
|
+
const runtimeId = row.candidate.runtimeId;
|
|
1108
|
+
if (!runtimeId) continue;
|
|
1109
|
+
const range = sourceRange(
|
|
1110
|
+
row.candidate.node,
|
|
1111
|
+
input.sourceFile,
|
|
1112
|
+
input.filePath,
|
|
1113
|
+
input.mapLocation
|
|
1114
|
+
);
|
|
1115
|
+
const fingerprint = input.originalAst ? fingerprintOf(row.candidate.node, input.sourceFile) : null;
|
|
1116
|
+
const stable = blocked.has(index) ? void 0 : row.descriptor;
|
|
1117
|
+
if (stable) {
|
|
1118
|
+
declarations.push({
|
|
1119
|
+
runtime_id: runtimeId,
|
|
1120
|
+
logical_key: functionIdentityKey(stable),
|
|
1121
|
+
identity_kind: "stable",
|
|
1122
|
+
descriptor: stable,
|
|
1123
|
+
source_range: range,
|
|
1124
|
+
implementation_fingerprint: fingerprint
|
|
1125
|
+
});
|
|
1126
|
+
continue;
|
|
1127
|
+
}
|
|
1128
|
+
const descriptor = releaseScopedDescriptor(runtimeId);
|
|
1129
|
+
declarations.push({
|
|
1130
|
+
runtime_id: runtimeId,
|
|
1131
|
+
logical_key: functionIdentityKey(descriptor),
|
|
1132
|
+
identity_kind: "release_scoped",
|
|
1133
|
+
descriptor,
|
|
1134
|
+
source_range: range,
|
|
1135
|
+
implementation_fingerprint: fingerprint
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
return declarations;
|
|
1139
|
+
};
|
|
1140
|
+
|
|
1141
|
+
// ../instrumentation/src/parameter-initializer-may-run-code.ts
|
|
1142
|
+
import ts6 from "typescript";
|
|
868
1143
|
var unwrap = (expression) => {
|
|
869
1144
|
let current = expression;
|
|
870
|
-
while (
|
|
1145
|
+
while (ts6.isParenthesizedExpression(current) || ts6.isNonNullExpression(current)) {
|
|
871
1146
|
current = current.expression;
|
|
872
1147
|
}
|
|
873
1148
|
return current;
|
|
874
1149
|
};
|
|
875
1150
|
var isSafeLiteralInitializer = (expression) => {
|
|
876
1151
|
const current = unwrap(expression);
|
|
877
|
-
if (
|
|
1152
|
+
if (ts6.isNumericLiteral(current) || ts6.isStringLiteral(current) || ts6.isNoSubstitutionTemplateLiteral(current) || ts6.isBigIntLiteral(current)) {
|
|
878
1153
|
return true;
|
|
879
1154
|
}
|
|
880
|
-
if (current.kind ===
|
|
1155
|
+
if (current.kind === ts6.SyntaxKind.TrueKeyword || current.kind === ts6.SyntaxKind.FalseKeyword || current.kind === ts6.SyntaxKind.NullKeyword) {
|
|
881
1156
|
return true;
|
|
882
1157
|
}
|
|
883
|
-
if (
|
|
884
|
-
if (
|
|
885
|
-
return
|
|
1158
|
+
if (ts6.isIdentifier(current) && current.text === "undefined") return true;
|
|
1159
|
+
if (ts6.isPrefixUnaryExpression(current) && (current.operator === ts6.SyntaxKind.PlusToken || current.operator === ts6.SyntaxKind.MinusToken)) {
|
|
1160
|
+
return ts6.isNumericLiteral(unwrap(current.operand));
|
|
886
1161
|
}
|
|
887
1162
|
return false;
|
|
888
1163
|
};
|
|
889
1164
|
var functionHasPreBodyParameterEvaluation = (node) => {
|
|
890
1165
|
for (const parameter of node.parameters) {
|
|
891
|
-
if (
|
|
1166
|
+
if (ts6.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
|
|
892
1167
|
if (!parameter.initializer) continue;
|
|
893
1168
|
if (!isSafeLiteralInitializer(parameter.initializer)) return true;
|
|
894
1169
|
}
|
|
@@ -896,24 +1171,24 @@ var functionHasPreBodyParameterEvaluation = (node) => {
|
|
|
896
1171
|
};
|
|
897
1172
|
|
|
898
1173
|
// ../instrumentation/src/verify-instrumentation-isomorphism.ts
|
|
899
|
-
import
|
|
1174
|
+
import ts7 from "typescript";
|
|
900
1175
|
var RASPUTIN_IDENT = /^__rasputin/;
|
|
901
1176
|
var scriptKindFor = (filePath) => {
|
|
902
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
903
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
904
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
905
|
-
return
|
|
1177
|
+
if (/\.tsx$/i.test(filePath)) return ts7.ScriptKind.TSX;
|
|
1178
|
+
if (/\.jsx$/i.test(filePath)) return ts7.ScriptKind.JSX;
|
|
1179
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts7.ScriptKind.TS;
|
|
1180
|
+
return ts7.ScriptKind.JS;
|
|
906
1181
|
};
|
|
907
|
-
var parse = (filePath, source) =>
|
|
1182
|
+
var parse = (filePath, source) => ts7.createSourceFile(filePath, source, ts7.ScriptTarget.Latest, true, scriptKindFor(filePath));
|
|
908
1183
|
var isRasputinName = (name) => RASPUTIN_IDENT.test(name);
|
|
909
1184
|
var identText = (node) => {
|
|
910
|
-
if (
|
|
911
|
-
if (
|
|
1185
|
+
if (ts7.isIdentifier(node)) return node.text;
|
|
1186
|
+
if (ts7.isPrivateIdentifier(node)) return node.text;
|
|
912
1187
|
return void 0;
|
|
913
1188
|
};
|
|
914
1189
|
var calleeName = (expression) => {
|
|
915
|
-
if (
|
|
916
|
-
if (
|
|
1190
|
+
if (ts7.isIdentifier(expression)) return expression.text;
|
|
1191
|
+
if (ts7.isPropertyAccessExpression(expression)) {
|
|
917
1192
|
const object = identText(expression.expression);
|
|
918
1193
|
const property = identText(expression.name);
|
|
919
1194
|
if (object && isRasputinName(object) && property) return `${object}.${property}`;
|
|
@@ -921,7 +1196,7 @@ var calleeName = (expression) => {
|
|
|
921
1196
|
return void 0;
|
|
922
1197
|
};
|
|
923
1198
|
var isRasputinCall = (node, methods) => {
|
|
924
|
-
if (!
|
|
1199
|
+
if (!ts7.isCallExpression(node)) return false;
|
|
925
1200
|
const name = calleeName(node.expression);
|
|
926
1201
|
if (!name) return false;
|
|
927
1202
|
if (isRasputinName(name)) return !methods || methods.has(name.split(".")[1] ?? "");
|
|
@@ -931,20 +1206,20 @@ var unwrapCall = (node) => {
|
|
|
931
1206
|
let current = node;
|
|
932
1207
|
while (isRasputinCall(current) && current.arguments.length === 1 && current.arguments[0]) {
|
|
933
1208
|
current = current.arguments[0];
|
|
934
|
-
if (
|
|
1209
|
+
if (ts7.isParenthesizedExpression(current)) current = current.expression;
|
|
935
1210
|
}
|
|
936
|
-
if (
|
|
1211
|
+
if (ts7.isParenthesizedExpression(current)) return current.expression;
|
|
937
1212
|
return current;
|
|
938
1213
|
};
|
|
939
1214
|
var isRasputinStatement = (node) => {
|
|
940
|
-
if (
|
|
941
|
-
if (
|
|
1215
|
+
if (ts7.isEmptyStatement(node)) return true;
|
|
1216
|
+
if (ts7.isVariableStatement(node)) {
|
|
942
1217
|
return node.declarationList.declarations.every((declaration) => {
|
|
943
1218
|
const name = identText(declaration.name);
|
|
944
1219
|
return Boolean(name && isRasputinName(name));
|
|
945
1220
|
});
|
|
946
1221
|
}
|
|
947
|
-
if (
|
|
1222
|
+
if (ts7.isExpressionStatement(node)) {
|
|
948
1223
|
if (!isRasputinCall(node.expression)) return false;
|
|
949
1224
|
const unwrapped = unwrapCall(node.expression);
|
|
950
1225
|
return unwrapped === node.expression;
|
|
@@ -958,7 +1233,7 @@ var isRasputinTryWrapper = (node) => {
|
|
|
958
1233
|
(statement) => !isRasputinStatement(statement)
|
|
959
1234
|
);
|
|
960
1235
|
const leftover = catchCalls[0];
|
|
961
|
-
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 &&
|
|
1236
|
+
const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts7.isThrowStatement(leftover) && ts7.isIdentifier(leftover.expression) && isRasputinName(leftover.expression.text);
|
|
962
1237
|
if (!leftoverThrow && catchCalls.length > 0) return false;
|
|
963
1238
|
return node.finallyBlock.statements.every((statement) => isRasputinStatement(statement));
|
|
964
1239
|
};
|
|
@@ -966,7 +1241,7 @@ var flattenStatements = (statements) => {
|
|
|
966
1241
|
const flattened = [];
|
|
967
1242
|
for (const statement of statements) {
|
|
968
1243
|
if (isRasputinStatement(statement)) continue;
|
|
969
|
-
if (
|
|
1244
|
+
if (ts7.isTryStatement(statement) && isRasputinTryWrapper(statement)) {
|
|
970
1245
|
flattened.push(...flattenStatements(statement.tryBlock.statements));
|
|
971
1246
|
continue;
|
|
972
1247
|
}
|
|
@@ -975,38 +1250,38 @@ var flattenStatements = (statements) => {
|
|
|
975
1250
|
return flattened;
|
|
976
1251
|
};
|
|
977
1252
|
var extra = (node) => {
|
|
978
|
-
if (
|
|
1253
|
+
if (ts7.isIdentifier(node) || ts7.isPrivateIdentifier(node)) {
|
|
979
1254
|
return isRasputinName(node.text) ? "" : node.text;
|
|
980
1255
|
}
|
|
981
|
-
if (
|
|
1256
|
+
if (ts7.isStringLiteral(node) || ts7.isNumericLiteral(node) || ts7.isNoSubstitutionTemplateLiteral(node)) {
|
|
982
1257
|
return node.text;
|
|
983
1258
|
}
|
|
984
|
-
if (
|
|
1259
|
+
if (ts7.isToken(node) && !ts7.isIdentifier(node)) return ts7.SyntaxKind[node.kind] ?? "";
|
|
985
1260
|
return "";
|
|
986
1261
|
};
|
|
987
1262
|
var signatureOf = (node) => {
|
|
988
1263
|
const unwrapped = unwrapCall(node);
|
|
989
1264
|
if (unwrapped !== node) return signatureOf(unwrapped);
|
|
990
|
-
if (
|
|
991
|
-
if (
|
|
1265
|
+
if (ts7.isEmptyStatement(unwrapped) || isRasputinStatement(unwrapped)) return "";
|
|
1266
|
+
if (ts7.isTryStatement(unwrapped) && isRasputinTryWrapper(unwrapped)) {
|
|
992
1267
|
return flattenStatements(unwrapped.tryBlock.statements).map(signatureOf).filter(Boolean).join("");
|
|
993
1268
|
}
|
|
994
|
-
if (
|
|
1269
|
+
if (ts7.isBlock(unwrapped)) {
|
|
995
1270
|
const statements = flattenStatements(unwrapped.statements);
|
|
996
1271
|
return `Block[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
|
|
997
1272
|
}
|
|
998
|
-
if (
|
|
1273
|
+
if (ts7.isCatchClause(unwrapped)) {
|
|
999
1274
|
const statements = flattenStatements(unwrapped.block.statements);
|
|
1000
1275
|
const variable = unwrapped.variableDeclaration ? signatureOf(unwrapped.variableDeclaration) : "";
|
|
1001
1276
|
return `Catch${variable}[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
|
|
1002
1277
|
}
|
|
1003
|
-
if (
|
|
1278
|
+
if (ts7.isArrowFunction(unwrapped) && ts7.isBlock(unwrapped.body)) {
|
|
1004
1279
|
const statements = flattenStatements(unwrapped.body.statements);
|
|
1005
1280
|
const only = statements[0];
|
|
1006
|
-
if (statements.length === 1 && only &&
|
|
1281
|
+
if (statements.length === 1 && only && ts7.isReturnStatement(only) && only.expression) {
|
|
1007
1282
|
const expression = only.expression;
|
|
1008
1283
|
const parts2 = [];
|
|
1009
|
-
|
|
1284
|
+
ts7.forEachChild(unwrapped, (child) => {
|
|
1010
1285
|
if (child === unwrapped.body) {
|
|
1011
1286
|
const part2 = signatureOf(expression);
|
|
1012
1287
|
if (part2) parts2.push(part2);
|
|
@@ -1019,11 +1294,11 @@ var signatureOf = (node) => {
|
|
|
1019
1294
|
}
|
|
1020
1295
|
}
|
|
1021
1296
|
const parts = [];
|
|
1022
|
-
|
|
1297
|
+
ts7.forEachChild(unwrapped, (child) => {
|
|
1023
1298
|
const part = signatureOf(child);
|
|
1024
1299
|
if (part) parts.push(part);
|
|
1025
1300
|
});
|
|
1026
|
-
const kind =
|
|
1301
|
+
const kind = ts7.SyntaxKind[unwrapped.kind] ?? "Node";
|
|
1027
1302
|
const label = extra(unwrapped);
|
|
1028
1303
|
return `${kind}${label}[${parts.join(",")}]`;
|
|
1029
1304
|
};
|
|
@@ -1032,14 +1307,14 @@ var instrumentationTreesAreIsomorphic = (filePath, original, transformed) => {
|
|
|
1032
1307
|
};
|
|
1033
1308
|
|
|
1034
1309
|
// ../instrumentation/src/verify-transformed-source.ts
|
|
1035
|
-
import
|
|
1036
|
-
var transpileForVerification = (filePath, code) =>
|
|
1310
|
+
import ts8 from "typescript";
|
|
1311
|
+
var transpileForVerification = (filePath, code) => ts8.transpileModule(code, {
|
|
1037
1312
|
compilerOptions: {
|
|
1038
1313
|
// ES2020 downlevel keeps native @decorators out of `new Function`.
|
|
1039
|
-
target:
|
|
1040
|
-
module:
|
|
1314
|
+
target: ts8.ScriptTarget.ES2020,
|
|
1315
|
+
module: ts8.ModuleKind.ESNext,
|
|
1041
1316
|
allowJs: true,
|
|
1042
|
-
jsx:
|
|
1317
|
+
jsx: ts8.JsxEmit.React,
|
|
1043
1318
|
experimentalDecorators: true
|
|
1044
1319
|
},
|
|
1045
1320
|
reportDiagnostics: true,
|
|
@@ -1047,7 +1322,7 @@ var transpileForVerification = (filePath, code) => ts7.transpileModule(code, {
|
|
|
1047
1322
|
});
|
|
1048
1323
|
var hasScanOrParseError = (diagnostics) => Boolean(
|
|
1049
1324
|
diagnostics?.some(
|
|
1050
|
-
(diagnostic) => diagnostic.category ===
|
|
1325
|
+
(diagnostic) => diagnostic.category === ts8.DiagnosticCategory.Error && diagnostic.code < 2e3
|
|
1051
1326
|
)
|
|
1052
1327
|
);
|
|
1053
1328
|
var scriptBodyForEngine = (emitted) => (
|
|
@@ -1056,39 +1331,39 @@ var scriptBodyForEngine = (emitted) => (
|
|
|
1056
1331
|
);
|
|
1057
1332
|
var looksTyped = (filePath) => /\.[cm]?tsx?$/i.test(filePath);
|
|
1058
1333
|
var scriptKindFor2 = (filePath) => {
|
|
1059
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
1060
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
1061
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
1062
|
-
return
|
|
1334
|
+
if (/\.tsx$/i.test(filePath)) return ts8.ScriptKind.TSX;
|
|
1335
|
+
if (/\.jsx$/i.test(filePath)) return ts8.ScriptKind.JSX;
|
|
1336
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts8.ScriptKind.TS;
|
|
1337
|
+
return ts8.ScriptKind.JS;
|
|
1063
1338
|
};
|
|
1064
|
-
var isIterationStatement = (node) =>
|
|
1339
|
+
var isIterationStatement = (node) => ts8.isForStatement(node) || ts8.isForOfStatement(node) || ts8.isForInStatement(node) || ts8.isWhileStatement(node) || ts8.isDoStatement(node);
|
|
1065
1340
|
var unwrapLabeled = (node) => {
|
|
1066
1341
|
let current = node;
|
|
1067
|
-
while (
|
|
1342
|
+
while (ts8.isLabeledStatement(current)) current = current.statement;
|
|
1068
1343
|
return current;
|
|
1069
1344
|
};
|
|
1070
1345
|
var hasInvalidLabelJump = (sourceFile) => {
|
|
1071
1346
|
const visit = (node, labels) => {
|
|
1072
|
-
if (
|
|
1347
|
+
if (ts8.isFunctionLike(node)) {
|
|
1073
1348
|
let nestedInvalid = false;
|
|
1074
|
-
|
|
1349
|
+
ts8.forEachChild(node, (child) => {
|
|
1075
1350
|
if (visit(child, /* @__PURE__ */ new Map())) nestedInvalid = true;
|
|
1076
1351
|
});
|
|
1077
1352
|
return nestedInvalid;
|
|
1078
1353
|
}
|
|
1079
|
-
if (
|
|
1354
|
+
if (ts8.isLabeledStatement(node)) {
|
|
1080
1355
|
const next = new Map(labels);
|
|
1081
1356
|
next.set(node.label.text, isIterationStatement(unwrapLabeled(node.statement)));
|
|
1082
1357
|
return visit(node.statement, next);
|
|
1083
1358
|
}
|
|
1084
|
-
if (
|
|
1359
|
+
if (ts8.isContinueStatement(node) && node.label) {
|
|
1085
1360
|
if (labels.get(node.label.text) !== true) return true;
|
|
1086
1361
|
}
|
|
1087
|
-
if (
|
|
1362
|
+
if (ts8.isBreakStatement(node) && node.label && !labels.has(node.label.text)) {
|
|
1088
1363
|
return true;
|
|
1089
1364
|
}
|
|
1090
1365
|
let invalid = false;
|
|
1091
|
-
|
|
1366
|
+
ts8.forEachChild(node, (child) => {
|
|
1092
1367
|
if (visit(child, labels)) invalid = true;
|
|
1093
1368
|
});
|
|
1094
1369
|
return invalid;
|
|
@@ -1131,10 +1406,10 @@ var UNTERMINATED_BARE_LEAVE = /\breturn\s+__rasputin\w*\.leave\(\)(?!\s*;|\()/;
|
|
|
1131
1406
|
var transformedSourceIsInvalid = (filePath, code) => {
|
|
1132
1407
|
if (GLUED_INSTRUMENTATION.test(code)) return true;
|
|
1133
1408
|
if (UNTERMINATED_BARE_LEAVE.test(code)) return true;
|
|
1134
|
-
const sourceFile =
|
|
1409
|
+
const sourceFile = ts8.createSourceFile(
|
|
1135
1410
|
filePath,
|
|
1136
1411
|
code,
|
|
1137
|
-
|
|
1412
|
+
ts8.ScriptTarget.Latest,
|
|
1138
1413
|
true,
|
|
1139
1414
|
scriptKindFor2(filePath)
|
|
1140
1415
|
);
|
|
@@ -1155,25 +1430,25 @@ var alreadyInstrumentedResult = (source) => ({
|
|
|
1155
1430
|
delta: { functions: [], callSites: [], destructures: [], alreadyInstrumented: true }
|
|
1156
1431
|
});
|
|
1157
1432
|
var scriptKindFor3 = (filePath) => {
|
|
1158
|
-
if (/\.tsx$/i.test(filePath)) return
|
|
1159
|
-
if (/\.jsx$/i.test(filePath)) return
|
|
1160
|
-
if (/\.[cm]?ts$/i.test(filePath)) return
|
|
1161
|
-
return
|
|
1433
|
+
if (/\.tsx$/i.test(filePath)) return ts9.ScriptKind.TSX;
|
|
1434
|
+
if (/\.jsx$/i.test(filePath)) return ts9.ScriptKind.JSX;
|
|
1435
|
+
if (/\.[cm]?ts$/i.test(filePath)) return ts9.ScriptKind.TS;
|
|
1436
|
+
return ts9.ScriptKind.JS;
|
|
1162
1437
|
};
|
|
1163
1438
|
var functionName = (node, sourceFile) => {
|
|
1164
|
-
if (
|
|
1439
|
+
if (ts9.isConstructorDeclaration(node)) return "constructor";
|
|
1165
1440
|
if (node.name) return node.name.getText(sourceFile).replace(/^['"]|['"]$/g, "");
|
|
1166
1441
|
const parent = node.parent;
|
|
1167
|
-
if (
|
|
1168
|
-
if (
|
|
1169
|
-
if (
|
|
1442
|
+
if (ts9.isVariableDeclaration(parent) && ts9.isIdentifier(parent.name)) return parent.name.text;
|
|
1443
|
+
if (ts9.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
|
|
1444
|
+
if (ts9.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
|
|
1170
1445
|
const location = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
1171
1446
|
return `anonymous@${location.line + 1}:${location.character + 1}`;
|
|
1172
1447
|
};
|
|
1173
1448
|
var functionLocationPosition = (node, sourceFile) => {
|
|
1174
1449
|
if (node.name) return node.name.getStart(sourceFile);
|
|
1175
1450
|
const parent = node.parent;
|
|
1176
|
-
if ((
|
|
1451
|
+
if ((ts9.isVariableDeclaration(parent) || ts9.isPropertyAssignment(parent)) && parent.name) {
|
|
1177
1452
|
return parent.name.getStart(sourceFile);
|
|
1178
1453
|
}
|
|
1179
1454
|
return node.getStart(sourceFile);
|
|
@@ -1186,12 +1461,12 @@ var functionBodyPrologueEnd = (body, sourceFile) => {
|
|
|
1186
1461
|
}
|
|
1187
1462
|
return end;
|
|
1188
1463
|
};
|
|
1189
|
-
var isStaticPropertyName = (name) =>
|
|
1464
|
+
var isStaticPropertyName = (name) => ts9.isIdentifier(name) || ts9.isStringLiteral(name) || ts9.isNoSubstitutionTemplateLiteral(name) || ts9.isNumericLiteral(name);
|
|
1190
1465
|
var canReconstructBinding = (name) => {
|
|
1191
|
-
if (
|
|
1192
|
-
if (
|
|
1466
|
+
if (ts9.isIdentifier(name)) return true;
|
|
1467
|
+
if (ts9.isArrayBindingPattern(name)) {
|
|
1193
1468
|
return name.elements.every(
|
|
1194
|
-
(element) =>
|
|
1469
|
+
(element) => ts9.isOmittedExpression(element) || canReconstructBinding(element.name)
|
|
1195
1470
|
);
|
|
1196
1471
|
}
|
|
1197
1472
|
return name.elements.every((element) => {
|
|
@@ -1200,10 +1475,10 @@ var canReconstructBinding = (name) => {
|
|
|
1200
1475
|
});
|
|
1201
1476
|
};
|
|
1202
1477
|
var bindingValue = (name, sourceFile) => {
|
|
1203
|
-
if (
|
|
1204
|
-
if (
|
|
1478
|
+
if (ts9.isIdentifier(name)) return name.text;
|
|
1479
|
+
if (ts9.isArrayBindingPattern(name)) {
|
|
1205
1480
|
const values = name.elements.map((element) => {
|
|
1206
|
-
if (
|
|
1481
|
+
if (ts9.isOmittedExpression(element)) return "";
|
|
1207
1482
|
const value = bindingValue(element.name, sourceFile);
|
|
1208
1483
|
return element.dotDotDotToken ? `...${value}` : value;
|
|
1209
1484
|
});
|
|
@@ -1213,7 +1488,7 @@ var bindingValue = (name, sourceFile) => {
|
|
|
1213
1488
|
const value = bindingValue(element.name, sourceFile);
|
|
1214
1489
|
if (element.dotDotDotToken) return `...${value}`;
|
|
1215
1490
|
if (!element.propertyName) return value;
|
|
1216
|
-
const key =
|
|
1491
|
+
const key = ts9.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
|
|
1217
1492
|
return `${key}:${value}`;
|
|
1218
1493
|
});
|
|
1219
1494
|
return `{${properties.join(",")}}`;
|
|
@@ -1221,7 +1496,7 @@ var bindingValue = (name, sourceFile) => {
|
|
|
1221
1496
|
var arrowArgsCapture = (node) => {
|
|
1222
1497
|
const sourceFile = node.getSourceFile();
|
|
1223
1498
|
const params = node.parameters.filter(
|
|
1224
|
-
(parameter) => !(
|
|
1499
|
+
(parameter) => !(ts9.isIdentifier(parameter.name) && parameter.name.text === "this")
|
|
1225
1500
|
);
|
|
1226
1501
|
if (!params.every((parameter) => canReconstructBinding(parameter.name))) {
|
|
1227
1502
|
return {
|
|
@@ -1236,13 +1511,13 @@ var arrowArgsCapture = (node) => {
|
|
|
1236
1511
|
return { args: `[${values.join(",")}]`, omitValues: false };
|
|
1237
1512
|
};
|
|
1238
1513
|
var isSupportedFunction = (node) => {
|
|
1239
|
-
if (!
|
|
1514
|
+
if (!ts9.isFunctionDeclaration(node) && !ts9.isFunctionExpression(node) && !ts9.isArrowFunction(node) && !ts9.isMethodDeclaration(node) && !ts9.isGetAccessorDeclaration(node) && !ts9.isSetAccessorDeclaration(node)) {
|
|
1240
1515
|
return false;
|
|
1241
1516
|
}
|
|
1242
1517
|
if (!node.body || "asteriskToken" in node && node.asteriskToken) return false;
|
|
1243
1518
|
return true;
|
|
1244
1519
|
};
|
|
1245
|
-
var isDirectivePrologue = (statement) =>
|
|
1520
|
+
var isDirectivePrologue = (statement) => ts9.isExpressionStatement(statement) && ts9.isStringLiteral(statement.expression);
|
|
1246
1521
|
var insertPositionAfterPrologue = (source, sourceFile) => {
|
|
1247
1522
|
const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
|
|
1248
1523
|
let end = shebangEnd;
|
|
@@ -1293,7 +1568,7 @@ var insertAfterSuperOrPrologue = (body, sourceFile) => {
|
|
|
1293
1568
|
const end = functionBodyPrologueEnd(body, sourceFile);
|
|
1294
1569
|
for (const statement of body.statements) {
|
|
1295
1570
|
if (isDirectivePrologue(statement)) continue;
|
|
1296
|
-
if (
|
|
1571
|
+
if (ts9.isExpressionStatement(statement) && ts9.isCallExpression(statement.expression) && statement.expression.expression.kind === ts9.SyntaxKind.SuperKeyword) {
|
|
1297
1572
|
return statement.end;
|
|
1298
1573
|
}
|
|
1299
1574
|
break;
|
|
@@ -1304,15 +1579,15 @@ var failEpilogue = (handleName, errorName, args, restoreOnCatch) => `}catch(${er
|
|
|
1304
1579
|
var walkOwnBody = (node, visitNode) => {
|
|
1305
1580
|
if (!node.body) return;
|
|
1306
1581
|
const visit = (candidate) => {
|
|
1307
|
-
if (candidate !== node &&
|
|
1582
|
+
if (candidate !== node && ts9.isFunctionLike(candidate)) return;
|
|
1308
1583
|
visitNode(candidate);
|
|
1309
|
-
|
|
1584
|
+
ts9.forEachChild(candidate, visit);
|
|
1310
1585
|
};
|
|
1311
1586
|
visit(node.body);
|
|
1312
1587
|
};
|
|
1313
1588
|
var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
1314
1589
|
walkOwnBody(node, (candidate) => {
|
|
1315
|
-
if (!
|
|
1590
|
+
if (!ts9.isAwaitExpression(candidate)) return;
|
|
1316
1591
|
wrap(
|
|
1317
1592
|
edits,
|
|
1318
1593
|
candidate.expression.getStart(sourceFile),
|
|
@@ -1333,7 +1608,7 @@ var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
|
1333
1608
|
};
|
|
1334
1609
|
var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) => {
|
|
1335
1610
|
walkOwnBody(node, (candidate) => {
|
|
1336
|
-
if (!
|
|
1611
|
+
if (!ts9.isTryStatement(candidate)) return;
|
|
1337
1612
|
const blocks = [candidate.catchClause?.block, candidate.finallyBlock];
|
|
1338
1613
|
for (const block of blocks) {
|
|
1339
1614
|
if (!block) continue;
|
|
@@ -1349,10 +1624,10 @@ var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) =>
|
|
|
1349
1624
|
});
|
|
1350
1625
|
};
|
|
1351
1626
|
var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
1352
|
-
if (!node.body || !
|
|
1627
|
+
if (!node.body || !ts9.isBlock(node.body)) return;
|
|
1353
1628
|
const visit = (candidate, at) => {
|
|
1354
|
-
if (candidate !== node &&
|
|
1355
|
-
if (
|
|
1629
|
+
if (candidate !== node && ts9.isFunctionLike(candidate)) return;
|
|
1630
|
+
if (ts9.isReturnStatement(candidate) && candidate.expression) {
|
|
1356
1631
|
const expression = candidate.expression;
|
|
1357
1632
|
wrap(
|
|
1358
1633
|
edits,
|
|
@@ -1364,17 +1639,17 @@ var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
|
|
|
1364
1639
|
);
|
|
1365
1640
|
return;
|
|
1366
1641
|
}
|
|
1367
|
-
|
|
1642
|
+
ts9.forEachChild(candidate, (child) => visit(child, at + 1));
|
|
1368
1643
|
};
|
|
1369
1644
|
visit(node.body, depth + 1);
|
|
1370
1645
|
};
|
|
1371
1646
|
var transformSource = (source, options) => {
|
|
1372
1647
|
if (source.includes("@rasputin-ignore-file")) return void 0;
|
|
1373
1648
|
if (sourceIsRasputinInstrumented(source)) return alreadyInstrumentedResult(source);
|
|
1374
|
-
const sourceFile =
|
|
1649
|
+
const sourceFile = ts9.createSourceFile(
|
|
1375
1650
|
options.filePath,
|
|
1376
1651
|
source,
|
|
1377
|
-
|
|
1652
|
+
ts9.ScriptTarget.Latest,
|
|
1378
1653
|
true,
|
|
1379
1654
|
scriptKindFor3(options.filePath)
|
|
1380
1655
|
);
|
|
@@ -1395,10 +1670,31 @@ var transformSource = (source, options) => {
|
|
|
1395
1670
|
absolutePath
|
|
1396
1671
|
};
|
|
1397
1672
|
const pending = [];
|
|
1398
|
-
const
|
|
1673
|
+
const identityNodes = [];
|
|
1674
|
+
const rememberIdentity = (node, collected) => {
|
|
1675
|
+
identityNodes.push({ node, runtimeId: collected.functionId });
|
|
1676
|
+
};
|
|
1677
|
+
const withDeclarations = (result) => {
|
|
1678
|
+
if (!options.functionMetrics) return result;
|
|
1679
|
+
if (identityNodes.length === 0) return { ...result, declarations: [] };
|
|
1680
|
+
const declarations = collectFunctionMetricDeclarations({
|
|
1681
|
+
sourceFile,
|
|
1682
|
+
filePath: options.filePath,
|
|
1683
|
+
functions: identityNodes,
|
|
1684
|
+
originalAst: !options.mapLocation,
|
|
1685
|
+
mapLocation: options.mapLocation
|
|
1686
|
+
});
|
|
1687
|
+
const byId = new Map(declarations.map((declaration) => [declaration.runtime_id, declaration]));
|
|
1688
|
+
for (const fn of result.delta.functions) {
|
|
1689
|
+
fn.metricsDeclaration = byId.get(fn.functionId);
|
|
1690
|
+
}
|
|
1691
|
+
return { ...result, declarations };
|
|
1692
|
+
};
|
|
1693
|
+
const skipFunction = (node, collected, reason) => {
|
|
1399
1694
|
collected.instrumented = false;
|
|
1400
1695
|
collected.skipReason = reason;
|
|
1401
1696
|
delta.functions.push(collected);
|
|
1697
|
+
rememberIdentity(node, collected);
|
|
1402
1698
|
if (process.env.RASPUTIN_DEBUG === "1") {
|
|
1403
1699
|
console.info(
|
|
1404
1700
|
`[rasputin] skipped instrumentation for ${collected.name} in ${options.filePath}: ${reason}`
|
|
@@ -1415,9 +1711,9 @@ var transformSource = (source, options) => {
|
|
|
1415
1711
|
);
|
|
1416
1712
|
if (collected) {
|
|
1417
1713
|
collected.asyncFunction = true;
|
|
1418
|
-
skipFunction(collected, "unsupported_async_generator");
|
|
1714
|
+
skipFunction(node, collected, "unsupported_async_generator");
|
|
1419
1715
|
}
|
|
1420
|
-
|
|
1716
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1421
1717
|
return;
|
|
1422
1718
|
}
|
|
1423
1719
|
if (isSyncGeneratorLike(node) && node.body) {
|
|
@@ -1427,25 +1723,27 @@ var transformSource = (source, options) => {
|
|
|
1427
1723
|
absolutePath,
|
|
1428
1724
|
options.mapLocation
|
|
1429
1725
|
);
|
|
1430
|
-
if (collected)
|
|
1431
|
-
|
|
1726
|
+
if (collected)
|
|
1727
|
+
skipFunction(node, collected, "unsupported_sync_generator");
|
|
1728
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1432
1729
|
return;
|
|
1433
1730
|
}
|
|
1434
|
-
if (
|
|
1731
|
+
if (ts9.isConstructorDeclaration(node) && node.body) {
|
|
1435
1732
|
const collected = collectWrappedFunction(
|
|
1436
1733
|
node,
|
|
1437
1734
|
sourceFile,
|
|
1438
1735
|
absolutePath,
|
|
1439
1736
|
options.mapLocation
|
|
1440
1737
|
);
|
|
1441
|
-
if (collected)
|
|
1442
|
-
|
|
1738
|
+
if (collected)
|
|
1739
|
+
skipFunction(node, collected, "unsupported_constructor");
|
|
1740
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1443
1741
|
return;
|
|
1444
1742
|
}
|
|
1445
1743
|
if (isSupportedFunction(node)) {
|
|
1446
1744
|
const collected = collectWrappedFunction(node, sourceFile, absolutePath, options.mapLocation);
|
|
1447
1745
|
if (!collected) {
|
|
1448
|
-
|
|
1746
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1449
1747
|
return;
|
|
1450
1748
|
}
|
|
1451
1749
|
if (options.decideFunction?.({
|
|
@@ -1454,15 +1752,15 @@ var transformSource = (source, options) => {
|
|
|
1454
1752
|
filePath: options.filePath,
|
|
1455
1753
|
name: collected.name
|
|
1456
1754
|
}) === "skip") {
|
|
1457
|
-
|
|
1755
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1458
1756
|
return;
|
|
1459
1757
|
}
|
|
1460
1758
|
const asyncFunction = isAsyncFunctionLike(node);
|
|
1461
1759
|
collected.asyncFunction = asyncFunction;
|
|
1462
1760
|
const decision = asyncFunction ? decideAsyncInstrumentation(node, sourceFile) : { action: "inline" };
|
|
1463
1761
|
if (decision.action === "skip") {
|
|
1464
|
-
skipFunction(collected, decision.reason);
|
|
1465
|
-
|
|
1762
|
+
skipFunction(node, collected, decision.reason);
|
|
1763
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1466
1764
|
return;
|
|
1467
1765
|
}
|
|
1468
1766
|
if (functionHasPreBodyParameterEvaluation(node)) {
|
|
@@ -1475,29 +1773,30 @@ var transformSource = (source, options) => {
|
|
|
1475
1773
|
suspendResume: decision.action === "suspend_resume"
|
|
1476
1774
|
});
|
|
1477
1775
|
delta.functions.push(collected);
|
|
1478
|
-
|
|
1776
|
+
rememberIdentity(node, collected);
|
|
1777
|
+
ts9.forEachChild(node, (child) => visit(child, collected, depth + 1));
|
|
1479
1778
|
return;
|
|
1480
1779
|
}
|
|
1481
|
-
if (caller && (
|
|
1780
|
+
if (caller && (ts9.isCallExpression(node) || ts9.isNewExpression(node))) {
|
|
1482
1781
|
const site = collectCallSite(node, caller, collectContext);
|
|
1483
1782
|
if (site) delta.callSites.push(site);
|
|
1484
1783
|
}
|
|
1485
|
-
if (caller &&
|
|
1784
|
+
if (caller && ts9.isVariableDeclaration(node)) {
|
|
1486
1785
|
const destructure = collectParamDestructure(node, caller, collectContext);
|
|
1487
1786
|
if (destructure) delta.destructures.push(destructure);
|
|
1488
1787
|
}
|
|
1489
|
-
|
|
1788
|
+
ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
|
|
1490
1789
|
};
|
|
1491
1790
|
visit(sourceFile, void 0, 0);
|
|
1492
1791
|
if (pending.length === 0) {
|
|
1493
|
-
return delta.functions.length > 0 ? { code: source, delta } : void 0;
|
|
1792
|
+
return delta.functions.length > 0 ? withDeclarations({ code: source, delta }) : void 0;
|
|
1494
1793
|
}
|
|
1495
1794
|
for (const [planIndex, entry] of pending.entries()) {
|
|
1496
|
-
const captured =
|
|
1795
|
+
const captured = ts9.isArrowFunction(entry.node) ? arrowArgsCapture(entry.node) : { args: "arguments", omitValues: false };
|
|
1497
1796
|
const omitArg = captured.omitValues ? ",true" : "";
|
|
1498
1797
|
const enterCall = `${runName}.enter(${planIndex},${captured.args}${omitArg})`;
|
|
1499
1798
|
const epilogue = failEpilogue(handleName, errorName, captured.args, entry.suspendResume);
|
|
1500
|
-
if (
|
|
1799
|
+
if (ts9.isBlock(entry.node.body)) {
|
|
1501
1800
|
const prologueAt = insertAfterSuperOrPrologue(entry.node.body, sourceFile);
|
|
1502
1801
|
const closeAt = entry.node.body.end - 1;
|
|
1503
1802
|
wrap(
|
|
@@ -1563,7 +1862,7 @@ var transformSource = (source, options) => {
|
|
|
1563
1862
|
`[rasputin] skipped instrumentation for ${options.filePath}: verification_failed`
|
|
1564
1863
|
);
|
|
1565
1864
|
}
|
|
1566
|
-
return { code: source, delta };
|
|
1865
|
+
return withDeclarations({ code: source, delta });
|
|
1567
1866
|
};
|
|
1568
1867
|
if (verify && transformedSourceIsInvalid(options.filePath, transformed)) {
|
|
1569
1868
|
if (transformedSourceIsInvalid(options.filePath, source)) {
|
|
@@ -1579,34 +1878,34 @@ var transformSource = (source, options) => {
|
|
|
1579
1878
|
if (verify && !instrumentationTreesAreIsomorphic(options.filePath, source, transformed)) {
|
|
1580
1879
|
return refuseTransformed();
|
|
1581
1880
|
}
|
|
1582
|
-
return {
|
|
1881
|
+
return withDeclarations({
|
|
1583
1882
|
code: attachInlineSourceMap(source, transformed, options.filePath, edits, basename),
|
|
1584
1883
|
delta,
|
|
1585
1884
|
map: exactTransformMap(source, transformed, basename(options.filePath), edits)
|
|
1586
|
-
};
|
|
1885
|
+
});
|
|
1587
1886
|
};
|
|
1588
1887
|
|
|
1589
1888
|
// ../instrumentation/src/json-producer-sites.ts
|
|
1590
|
-
import
|
|
1889
|
+
import ts11 from "typescript";
|
|
1591
1890
|
|
|
1592
1891
|
// ../instrumentation/src/literal-sites.ts
|
|
1593
|
-
import
|
|
1892
|
+
import ts12 from "typescript";
|
|
1594
1893
|
|
|
1595
1894
|
// ../instrumentation/src/observe-sites.ts
|
|
1596
1895
|
import { propertyNameIsSensitive as propertyNameIsSensitive2 } from "@rasputin-ai/core";
|
|
1597
|
-
import
|
|
1896
|
+
import ts13 from "typescript";
|
|
1598
1897
|
|
|
1599
1898
|
// ../instrumentation/src/verify-browser-source.ts
|
|
1600
|
-
import
|
|
1899
|
+
import ts14 from "typescript";
|
|
1601
1900
|
|
|
1602
1901
|
// ../instrumentation/src/provenance-function-edits.ts
|
|
1603
|
-
import
|
|
1902
|
+
import ts15 from "typescript";
|
|
1604
1903
|
|
|
1605
1904
|
// ../instrumentation/src/source-map-location.ts
|
|
1606
1905
|
import { originalPositionFor as originalPositionFor2, TraceMap as TraceMap3 } from "@jridgewell/trace-mapping";
|
|
1607
1906
|
|
|
1608
1907
|
// src/sdk-meta.ts
|
|
1609
|
-
var SDK_VERSION = "0.
|
|
1908
|
+
var SDK_VERSION = "0.13.1";
|
|
1610
1909
|
|
|
1611
1910
|
// src/auto-instrumentation/source-map-locations.ts
|
|
1612
1911
|
import { readFileSync } from "node:fs";
|
|
@@ -1699,7 +1998,12 @@ var ensureTrustedCacheDir = (directory, explicit) => {
|
|
|
1699
1998
|
return false;
|
|
1700
1999
|
}
|
|
1701
2000
|
};
|
|
1702
|
-
var
|
|
2001
|
+
var identityCacheToken = (filePath, metricsRequested) => {
|
|
2002
|
+
if (!metricsRequested) return "no-metrics";
|
|
2003
|
+
const locator = sourceLocatorFromFile4(filePath);
|
|
2004
|
+
return `metrics-manifest-v1\0${locator?.packageName ?? ""}\0${locator?.packageRelativePath ?? ""}`;
|
|
2005
|
+
};
|
|
2006
|
+
var cacheKey = (source, filePath, verifyTransform, metricsRequested) => createHash("sha256").update(SDK_VERSION).update("\0").update(filePath).update("\0").update(source).update("\0").update(sourceMapPayloadForCache(filePath, source)).update("\0").update(verifyTransform ? "1" : "0").update("\0").update(identityCacheToken(filePath, metricsRequested)).digest("hex");
|
|
1703
2007
|
var revive = (cached) => ({
|
|
1704
2008
|
code: cached.code,
|
|
1705
2009
|
delta: {
|
|
@@ -1710,9 +2014,10 @@ var revive = (cached) => ({
|
|
|
1710
2014
|
})),
|
|
1711
2015
|
callSites: cached.delta.callSites,
|
|
1712
2016
|
destructures: cached.delta.destructures
|
|
1713
|
-
}
|
|
2017
|
+
},
|
|
2018
|
+
...cached.declarations ? { declarations: cached.declarations } : {}
|
|
1714
2019
|
});
|
|
1715
|
-
var persistable = (result) => ({
|
|
2020
|
+
var persistable = (result, metricsRequested) => ({
|
|
1716
2021
|
code: result.code,
|
|
1717
2022
|
delta: {
|
|
1718
2023
|
functions: result.delta.functions.map((fn) => ({
|
|
@@ -1721,7 +2026,8 @@ var persistable = (result) => ({
|
|
|
1721
2026
|
})),
|
|
1722
2027
|
callSites: result.delta.callSites,
|
|
1723
2028
|
destructures: result.delta.destructures
|
|
1724
|
-
}
|
|
2029
|
+
},
|
|
2030
|
+
...metricsRequested || result.declarations ? { declarations: result.declarations ?? [] } : {}
|
|
1725
2031
|
});
|
|
1726
2032
|
var evictOldest = (directory, keep) => {
|
|
1727
2033
|
const entries = readdirSync(directory).map((name) => {
|
|
@@ -1752,10 +2058,10 @@ var readCache = (directory, key) => {
|
|
|
1752
2058
|
return void 0;
|
|
1753
2059
|
}
|
|
1754
2060
|
};
|
|
1755
|
-
var writeCache = (directory, key, result, limit) => {
|
|
2061
|
+
var writeCache = (directory, key, result, limit, metricsRequested) => {
|
|
1756
2062
|
try {
|
|
1757
2063
|
const path = join2(directory, `${key}.json`);
|
|
1758
|
-
writeFileSync(path, JSON.stringify(persistable(result)), { mode: 384 });
|
|
2064
|
+
writeFileSync(path, JSON.stringify(persistable(result, metricsRequested)), { mode: 384 });
|
|
1759
2065
|
try {
|
|
1760
2066
|
chmodSync(path, 384);
|
|
1761
2067
|
} catch {
|
|
@@ -1772,12 +2078,22 @@ var transformSourceCached = (source, options, cache = {}) => {
|
|
|
1772
2078
|
if (!cacheEnabled()) return transformSource(source, transformOptions);
|
|
1773
2079
|
const explicit = cache.directory !== void 0;
|
|
1774
2080
|
const directory = cache.directory ?? resolveTransformCacheDir();
|
|
1775
|
-
if (!ensureTrustedCacheDir(directory, explicit))
|
|
1776
|
-
|
|
2081
|
+
if (!ensureTrustedCacheDir(directory, explicit)) {
|
|
2082
|
+
return transformSource(source, transformOptions);
|
|
2083
|
+
}
|
|
2084
|
+
const metricsRequested = transformOptions.functionMetrics === true;
|
|
2085
|
+
const key = cacheKey(
|
|
2086
|
+
source,
|
|
2087
|
+
options.filePath,
|
|
2088
|
+
transformOptions.verifyTransform === true,
|
|
2089
|
+
metricsRequested
|
|
2090
|
+
);
|
|
1777
2091
|
const hit = readCache(directory, key);
|
|
1778
|
-
if (hit) return hit;
|
|
2092
|
+
if (hit && !(metricsRequested && hit.declarations === void 0)) return hit;
|
|
1779
2093
|
const result = transformSource(source, transformOptions);
|
|
1780
|
-
if (result)
|
|
2094
|
+
if (result) {
|
|
2095
|
+
writeCache(directory, key, result, cache.limit ?? defaultCacheLimit(), metricsRequested);
|
|
2096
|
+
}
|
|
1781
2097
|
return result;
|
|
1782
2098
|
};
|
|
1783
2099
|
|
|
@@ -1797,8 +2113,14 @@ var loadSourceForInstrumentation = async (filePath, options = {}) => {
|
|
|
1797
2113
|
return { contents: source, loader: loaderFor(absolutePath), transformed: false };
|
|
1798
2114
|
}
|
|
1799
2115
|
try {
|
|
1800
|
-
const transformed = transformSourceCached(source, {
|
|
2116
|
+
const transformed = transformSourceCached(source, {
|
|
2117
|
+
filePath: absolutePath,
|
|
2118
|
+
functionMetrics: true
|
|
2119
|
+
});
|
|
1801
2120
|
if (transformed) {
|
|
2121
|
+
if (transformed.declarations) {
|
|
2122
|
+
registerFunctionMetricDeclarations(transformed.declarations);
|
|
2123
|
+
}
|
|
1802
2124
|
recordInstrumentationManifestDelta(absolutePath, transformed.delta);
|
|
1803
2125
|
}
|
|
1804
2126
|
return {
|