@rasputin-ai/node 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +143 -16
  2. package/dist/auto-instrumentation/bun-plugin.d.ts +23 -0
  3. package/dist/auto-instrumentation/bun-plugin.d.ts.map +1 -0
  4. package/dist/auto-instrumentation/collect-instrumentation-delta.d.ts +64 -0
  5. package/dist/auto-instrumentation/collect-instrumentation-delta.d.ts.map +1 -0
  6. package/dist/auto-instrumentation/format-configuration-report.d.ts +14 -0
  7. package/dist/auto-instrumentation/format-configuration-report.d.ts.map +1 -0
  8. package/dist/auto-instrumentation/instrumentation-manifest-registry.d.ts +17 -0
  9. package/dist/auto-instrumentation/instrumentation-manifest-registry.d.ts.map +1 -0
  10. package/dist/auto-instrumentation/node-hooks.d.ts +6 -0
  11. package/dist/auto-instrumentation/node-hooks.d.ts.map +1 -0
  12. package/dist/auto-instrumentation/schedule-instrumentation-manifest-upload.d.ts +26 -0
  13. package/dist/auto-instrumentation/schedule-instrumentation-manifest-upload.d.ts.map +1 -0
  14. package/dist/auto-instrumentation/sdk-source-boundary.d.ts +7 -0
  15. package/dist/auto-instrumentation/sdk-source-boundary.d.ts.map +1 -0
  16. package/dist/auto-instrumentation/source-classification.d.ts +10 -0
  17. package/dist/auto-instrumentation/source-classification.d.ts.map +1 -0
  18. package/dist/auto-instrumentation/source-map-locations.d.ts +3 -0
  19. package/dist/auto-instrumentation/source-map-locations.d.ts.map +1 -0
  20. package/dist/auto-instrumentation/transform-source.d.ts +18 -0
  21. package/dist/auto-instrumentation/transform-source.d.ts.map +1 -0
  22. package/dist/execution-recorder/automatic-runtime.d.ts +21 -0
  23. package/dist/execution-recorder/automatic-runtime.d.ts.map +1 -0
  24. package/dist/execution-recorder/call-aware-event-buffer.d.ts +23 -0
  25. package/dist/execution-recorder/call-aware-event-buffer.d.ts.map +1 -0
  26. package/dist/execution-recorder/execution-recorder-types.d.ts +75 -0
  27. package/dist/execution-recorder/execution-recorder-types.d.ts.map +1 -0
  28. package/dist/execution-recorder/execution-recorder.d.ts +4 -0
  29. package/dist/execution-recorder/execution-recorder.d.ts.map +1 -0
  30. package/dist/execution-recorder/index.d.ts +3 -0
  31. package/dist/execution-recorder/index.d.ts.map +1 -0
  32. package/dist/execution-recorder/recorder-memory-budget.d.ts +37 -0
  33. package/dist/execution-recorder/recorder-memory-budget.d.ts.map +1 -0
  34. package/dist/execution-recorder/safe-serialize.d.ts +10 -0
  35. package/dist/execution-recorder/safe-serialize.d.ts.map +1 -0
  36. package/dist/execution-recorder/source-exclusions.d.ts +10 -0
  37. package/dist/execution-recorder/source-exclusions.d.ts.map +1 -0
  38. package/dist/index.d.ts +5 -0
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +1393 -5
  41. package/dist/instrument/bun.d.ts +2 -0
  42. package/dist/instrument/bun.d.ts.map +1 -0
  43. package/dist/instrument/bun.js +489 -0
  44. package/dist/instrument/node.d.ts +2 -0
  45. package/dist/instrument/node.d.ts.map +1 -0
  46. package/dist/instrument/node.js +544 -0
  47. package/dist/rasputin-init.d.ts +24 -4
  48. package/dist/rasputin-init.d.ts.map +1 -1
  49. package/dist/sdk-meta.d.ts +2 -2
  50. package/dist/sdk-meta.d.ts.map +1 -1
  51. package/package.json +15 -4
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=bun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bun.d.ts","sourceRoot":"","sources":["../../src/instrument/bun.ts"],"names":[],"mappings":""}
@@ -0,0 +1,489 @@
1
+ // src/instrument/bun.ts
2
+ import { plugin } from "bun";
3
+
4
+ // src/auto-instrumentation/bun-plugin.ts
5
+ import { readFile } from "node:fs/promises";
6
+ import { resolve as resolve4 } from "node:path";
7
+
8
+ // src/auto-instrumentation/instrumentation-manifest-registry.ts
9
+ import { resolve } from "node:path";
10
+ import {
11
+ INSTRUMENTATION_MANIFEST_SCHEMA_VERSION,
12
+ sourceLocatorFromFile as sourceLocatorFromFile2
13
+ } from "@rasputin-ai/core";
14
+
15
+ // src/execution-recorder/automatic-runtime.ts
16
+ import {
17
+ runtimeFunctionId,
18
+ sourceLocatorFromFile
19
+ } from "@rasputin-ai/core";
20
+ var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v2";
21
+ var AUTOMATIC_SOURCE_PREFIX = "rasputin-source-v2:";
22
+ var runtimeSymbol = Symbol.for(AUTOMATIC_RUNTIME_SYMBOL);
23
+ var encodeAutomaticFunctionSource = (source) => {
24
+ const locator = sourceLocatorFromFile(source.filePath);
25
+ const value = {
26
+ name: source.name,
27
+ ...locator ? { source: { ...locator, line: source.line, column: source.column } } : {}
28
+ };
29
+ return `${AUTOMATIC_SOURCE_PREFIX}${JSON.stringify(value)}`;
30
+ };
31
+
32
+ // src/auto-instrumentation/instrumentation-manifest-registry.ts
33
+ var INSTRUMENTATION_MANIFEST_SYMBOL = "rasputin.instrumentation.manifest.v2";
34
+ var registrySymbol = Symbol.for(INSTRUMENTATION_MANIFEST_SYMBOL);
35
+ var getRegistry = () => {
36
+ const existing = Reflect.get(globalThis, registrySymbol);
37
+ if (existing?.__rasputinManifestRegistry && existing.files instanceof Map && typeof existing.generation === "number" && typeof existing.uploadedGeneration === "number") {
38
+ return existing;
39
+ }
40
+ const registry = {
41
+ __rasputinManifestRegistry: true,
42
+ files: /* @__PURE__ */ new Map(),
43
+ generation: 0,
44
+ uploadedGeneration: 0
45
+ };
46
+ Reflect.set(globalThis, registrySymbol, registry);
47
+ return registry;
48
+ };
49
+ var recordInstrumentationManifestDelta = (filePath, delta) => {
50
+ const registry = getRegistry();
51
+ registry.files.set(resolve(filePath), delta);
52
+ registry.generation += 1;
53
+ registry.onDirty?.();
54
+ };
55
+
56
+ // src/auto-instrumentation/source-classification.ts
57
+ import { isAbsolute, relative, resolve as resolve2, sep } from "node:path";
58
+ var sourceExtension = /\.[cm]?[jt]sx?$/i;
59
+ var alwaysExcludedDirectory = /(^|[\\/])(node_modules|coverage|generated|\.git|\.next|\.svelte-kit|\.output|\.vercel|\.rasputin|\.turbo|\.yarn|\.pnpm|\.bun)([\\/]|$)/;
60
+ var buildOutputDirectory = /(^|[\\/])(dist|build|out)([\\/]|$)/;
61
+ var matches = (pattern, value) => {
62
+ pattern.lastIndex = 0;
63
+ const result = pattern.test(value);
64
+ pattern.lastIndex = 0;
65
+ return result;
66
+ };
67
+ var isWithinRoot = (filePath, root) => {
68
+ const fromRoot = relative(resolve2(root), filePath);
69
+ return fromRoot === "" || !fromRoot.startsWith(`..${sep}`) && fromRoot !== ".." && !isAbsolute(fromRoot);
70
+ };
71
+ var isApplicationSource = (filePath, options = {}) => {
72
+ const absolutePath = resolve2(filePath);
73
+ if (!sourceExtension.test(absolutePath) || alwaysExcludedDirectory.test(absolutePath))
74
+ return false;
75
+ if (options.includeBuildOutput !== true && buildOutputDirectory.test(absolutePath)) return false;
76
+ if (options.excludedRoots?.some((root) => isWithinRoot(absolutePath, root))) return false;
77
+ if (options.exclude && matches(options.exclude, absolutePath)) return false;
78
+ if (options.include && !matches(options.include, absolutePath)) return false;
79
+ if (options.rootDir) {
80
+ if (!isWithinRoot(absolutePath, options.rootDir)) return false;
81
+ }
82
+ return true;
83
+ };
84
+
85
+ // src/auto-instrumentation/transform-source.ts
86
+ import { resolve as resolve3 } from "node:path";
87
+ import ts2 from "typescript";
88
+
89
+ // src/auto-instrumentation/collect-instrumentation-delta.ts
90
+ import ts from "typescript";
91
+ var paramBindingFromName = (name, sourceFile) => {
92
+ if (ts.isIdentifier(name)) return { kind: "identifier", name: name.text };
93
+ if (ts.isArrayBindingPattern(name)) {
94
+ const elements = name.elements.map(
95
+ (element) => {
96
+ if (ts.isOmittedExpression(element)) return { kind: "omitted" };
97
+ const binding = paramBindingFromName(element.name, sourceFile);
98
+ if (element.dotDotDotToken) return { kind: "rest", binding };
99
+ return binding;
100
+ }
101
+ );
102
+ return { kind: "array", elements };
103
+ }
104
+ const properties = name.elements.map((element) => {
105
+ const binding = paramBindingFromName(element.name, sourceFile);
106
+ const key = element.propertyName ? element.propertyName.getText(sourceFile).replace(/^['"]|['"]$/g, "") : ts.isIdentifier(element.name) ? element.name.text : element.name.getText(sourceFile);
107
+ if (element.dotDotDotToken) {
108
+ const rest = { kind: "rest", binding };
109
+ return { key, binding: rest };
110
+ }
111
+ return { key, binding };
112
+ });
113
+ return { kind: "object", properties };
114
+ };
115
+ var collectFunctionParams = (node, sourceFile) => {
116
+ const params = [];
117
+ for (const parameter of node.parameters) {
118
+ if (ts.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
119
+ const binding = paramBindingFromName(parameter.name, sourceFile);
120
+ params.push(parameter.dotDotDotToken ? { kind: "rest", binding } : binding);
121
+ }
122
+ return { params, paramNames: identifierNames(params) };
123
+ };
124
+ var identifierNames = (bindings) => {
125
+ const names = /* @__PURE__ */ new Set();
126
+ const walk = (node) => {
127
+ if (node.kind === "identifier") {
128
+ names.add(node.name);
129
+ return;
130
+ }
131
+ if (node.kind === "rest") {
132
+ walk(node.binding);
133
+ return;
134
+ }
135
+ if (node.kind === "object") {
136
+ for (const property of node.properties) walk(property.binding);
137
+ return;
138
+ }
139
+ if (node.kind === "array") {
140
+ for (const element of node.elements) {
141
+ if (element.kind !== "omitted") walk(element);
142
+ }
143
+ }
144
+ };
145
+ for (const item of bindings) walk(item);
146
+ return names;
147
+ };
148
+ var mappedLocation = (sourceFile, position, absolutePath, mapLocation) => {
149
+ const generated = sourceFile.getLineAndCharacterOfPosition(position);
150
+ const raw = {
151
+ filePath: absolutePath,
152
+ line: generated.line + 1,
153
+ column: generated.character + 1
154
+ };
155
+ return mapLocation ? mapLocation(raw) : raw;
156
+ };
157
+ var unwrapExpression = (expression) => {
158
+ let current = expression;
159
+ while (ts.isParenthesizedExpression(current) || ts.isNonNullExpression(current)) {
160
+ current = current.expression;
161
+ }
162
+ if (ts.isAwaitExpression(current)) return unwrapExpression(current.expression);
163
+ return current;
164
+ };
165
+ var calleeFromExpression = (expression, sourceFile) => {
166
+ const current = unwrapExpression(expression);
167
+ if (ts.isIdentifier(current)) {
168
+ return { calleeName: current.text, calleeText: current.text };
169
+ }
170
+ if (ts.isPropertyAccessExpression(current) && ts.isIdentifier(current.name)) {
171
+ return {
172
+ calleeName: current.name.text,
173
+ calleeText: current.getText(sourceFile).replace(/\s+/g, "")
174
+ };
175
+ }
176
+ return null;
177
+ };
178
+ var resultBindingForCall = (call) => {
179
+ let node = call.parent;
180
+ if (ts.isAwaitExpression(node)) node = node.parent;
181
+ if (!ts.isVariableDeclaration(node)) return null;
182
+ if (!ts.isIdentifier(node.name)) return null;
183
+ const initializer = node.initializer;
184
+ if (!initializer) return null;
185
+ const inner = unwrapExpression(initializer);
186
+ if (inner !== call) return null;
187
+ return node.name.text;
188
+ };
189
+ var argIdentifiersForCall = (call) => {
190
+ const identifiers = [];
191
+ call.arguments?.forEach((argument, index) => {
192
+ if (ts.isIdentifier(argument)) {
193
+ identifiers.push({ index, kind: "identifier", name: argument.text });
194
+ return;
195
+ }
196
+ if (!ts.isObjectLiteralExpression(argument)) return;
197
+ const properties = [];
198
+ for (const property of argument.properties) {
199
+ if (ts.isShorthandPropertyAssignment(property)) {
200
+ properties.push({ key: property.name.text, name: property.name.text });
201
+ continue;
202
+ }
203
+ if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) && ts.isIdentifier(property.initializer)) {
204
+ properties.push({ key: property.name.text, name: property.initializer.text });
205
+ }
206
+ }
207
+ if (properties.length > 0) {
208
+ identifiers.push({ index, kind: "object", properties });
209
+ }
210
+ });
211
+ return identifiers;
212
+ };
213
+ var collectCallSite = (call, caller, context) => {
214
+ const callee = calleeFromExpression(call.expression, context.sourceFile);
215
+ if (!callee) return null;
216
+ const start = mappedLocation(
217
+ context.sourceFile,
218
+ call.getStart(context.sourceFile),
219
+ context.absolutePath,
220
+ context.mapLocation
221
+ );
222
+ const end = mappedLocation(
223
+ context.sourceFile,
224
+ call.end,
225
+ context.absolutePath,
226
+ context.mapLocation
227
+ );
228
+ if (!start || !end) return null;
229
+ return {
230
+ callerSourceToken: caller.sourceToken,
231
+ calleeName: callee.calleeName,
232
+ calleeText: callee.calleeText,
233
+ filePath: start.filePath,
234
+ line: start.line,
235
+ column: start.column,
236
+ endLine: end.line,
237
+ endColumn: end.column,
238
+ resultBinding: resultBindingForCall(call),
239
+ argIdentifiers: argIdentifiersForCall(call)
240
+ };
241
+ };
242
+ var collectParamDestructure = (declaration, caller, context) => {
243
+ if (!declaration.initializer || !ts.isIdentifier(declaration.initializer)) return null;
244
+ if (!ts.isObjectBindingPattern(declaration.name) && !ts.isArrayBindingPattern(declaration.name)) {
245
+ return null;
246
+ }
247
+ const sourceParam = declaration.initializer.text;
248
+ if (!caller.paramNames.has(sourceParam)) return null;
249
+ const start = mappedLocation(
250
+ context.sourceFile,
251
+ declaration.getStart(context.sourceFile),
252
+ context.absolutePath,
253
+ context.mapLocation
254
+ );
255
+ if (!start) return null;
256
+ return {
257
+ callerSourceToken: caller.sourceToken,
258
+ sourceParam,
259
+ filePath: start.filePath,
260
+ line: start.line,
261
+ column: start.column,
262
+ binding: paramBindingFromName(declaration.name, context.sourceFile)
263
+ };
264
+ };
265
+
266
+ // src/auto-instrumentation/transform-source.ts
267
+ var scriptKindFor = (filePath) => {
268
+ if (/\.tsx$/i.test(filePath)) return ts2.ScriptKind.TSX;
269
+ if (/\.jsx$/i.test(filePath)) return ts2.ScriptKind.JSX;
270
+ if (/\.[cm]?ts$/i.test(filePath)) return ts2.ScriptKind.TS;
271
+ return ts2.ScriptKind.JS;
272
+ };
273
+ var functionName = (node, sourceFile) => {
274
+ if (node.name) return node.name.getText(sourceFile).replace(/^['"]|['"]$/g, "");
275
+ const parent = node.parent;
276
+ if (ts2.isVariableDeclaration(parent) && ts2.isIdentifier(parent.name)) return parent.name.text;
277
+ if (ts2.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
278
+ if (ts2.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
279
+ const location = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
280
+ return `anonymous@${location.line + 1}:${location.character + 1}`;
281
+ };
282
+ var functionLocationPosition = (node, sourceFile) => {
283
+ if (node.name) return node.name.getStart(sourceFile);
284
+ const parent = node.parent;
285
+ if ((ts2.isVariableDeclaration(parent) || ts2.isPropertyAssignment(parent)) && parent.name) {
286
+ return parent.name.getStart(sourceFile);
287
+ }
288
+ return node.getStart(sourceFile);
289
+ };
290
+ var bindingValue = (name, sourceFile) => {
291
+ if (ts2.isIdentifier(name)) return name.text;
292
+ if (ts2.isArrayBindingPattern(name)) {
293
+ const values = name.elements.map((element) => {
294
+ if (ts2.isOmittedExpression(element)) return "";
295
+ const value = bindingValue(element.name, sourceFile);
296
+ return element.dotDotDotToken ? `...${value}` : value;
297
+ });
298
+ return `[${values.join(",")}]`;
299
+ }
300
+ const properties = name.elements.map((element) => {
301
+ const value = bindingValue(element.name, sourceFile);
302
+ if (element.dotDotDotToken) return `...${value}`;
303
+ if (element.propertyName) return `${element.propertyName.getText(sourceFile)}:${value}`;
304
+ return value;
305
+ });
306
+ return `{${properties.join(",")}}`;
307
+ };
308
+ var arrowArguments = (node) => {
309
+ const values = node.parameters.flatMap((parameter) => {
310
+ if (ts2.isIdentifier(parameter.name) && parameter.name.text === "this") return [];
311
+ const value = bindingValue(parameter.name, node.getSourceFile());
312
+ return [parameter.dotDotDotToken ? `...${value}` : value];
313
+ });
314
+ return `[${values.join(",")}]`;
315
+ };
316
+ var isSupportedFunction = (node) => {
317
+ if (!ts2.isFunctionDeclaration(node) && !ts2.isFunctionExpression(node) && !ts2.isArrowFunction(node) && !ts2.isMethodDeclaration(node) && !ts2.isGetAccessorDeclaration(node) && !ts2.isSetAccessorDeclaration(node)) {
318
+ return false;
319
+ }
320
+ if (!node.body || "asteriskToken" in node && node.asteriskToken) return false;
321
+ return true;
322
+ };
323
+ var helperDeclaration = (helperName) => `const ${helperName}=(functionId,args,callback)=>{const runtime=Reflect.get(globalThis,Symbol.for(${JSON.stringify(AUTOMATIC_RUNTIME_SYMBOL)}));return runtime?runtime.run(functionId,args,callback):callback()};`;
324
+ var collectWrappedFunction = (node, sourceFile, absolutePath, mapLocation) => {
325
+ const start = mappedLocation(
326
+ sourceFile,
327
+ functionLocationPosition(node, sourceFile),
328
+ absolutePath,
329
+ mapLocation
330
+ );
331
+ if (!start) return void 0;
332
+ const end = mappedLocation(sourceFile, node.end, absolutePath, mapLocation) ?? start;
333
+ const name = functionName(node, sourceFile).replace(/@\d+:\d+$/, "");
334
+ const { params, paramNames } = collectFunctionParams(node, sourceFile);
335
+ return {
336
+ sourceToken: encodeAutomaticFunctionSource({
337
+ filePath: start.filePath,
338
+ name,
339
+ line: start.line,
340
+ column: start.column
341
+ }),
342
+ filePath: start.filePath,
343
+ name,
344
+ startLine: start.line,
345
+ startColumn: start.column,
346
+ endLine: end.line,
347
+ endColumn: end.column,
348
+ params,
349
+ paramNames
350
+ };
351
+ };
352
+ var transformSource = (source, options) => {
353
+ if (source.includes("@rasputin-ignore-file")) return void 0;
354
+ const sourceFile = ts2.createSourceFile(
355
+ options.filePath,
356
+ source,
357
+ ts2.ScriptTarget.Latest,
358
+ true,
359
+ scriptKindFor(options.filePath)
360
+ );
361
+ let helperName = "__rasputinAutoRun__";
362
+ while (source.includes(helperName)) helperName += "_";
363
+ const absolutePath = resolve3(options.filePath);
364
+ const edits = [];
365
+ let order = 0;
366
+ const delta = {
367
+ functions: [],
368
+ callSites: [],
369
+ destructures: []
370
+ };
371
+ const collectContext = {
372
+ sourceFile,
373
+ mapLocation: options.mapLocation,
374
+ absolutePath
375
+ };
376
+ const visit = (node, caller) => {
377
+ if (isSupportedFunction(node)) {
378
+ const collected = collectWrappedFunction(node, sourceFile, absolutePath, options.mapLocation);
379
+ if (!collected) {
380
+ ts2.forEachChild(node, (child) => visit(child, caller));
381
+ return;
382
+ }
383
+ delta.functions.push(collected);
384
+ const args = ts2.isArrowFunction(node) ? arrowArguments(node) : "arguments";
385
+ const asyncCallback = node.modifiers?.some(
386
+ (modifier) => modifier.kind === ts2.SyntaxKind.AsyncKeyword
387
+ ) ? "async " : "";
388
+ if (ts2.isBlock(node.body)) {
389
+ edits.push({
390
+ position: node.body.getStart(sourceFile) + 1,
391
+ text: `return ${helperName}(${JSON.stringify(collected.sourceToken)},${args},${asyncCallback}()=>{`,
392
+ order: order++
393
+ });
394
+ edits.push({ position: node.body.end - 1, text: "});", order: order++ });
395
+ } else {
396
+ edits.push({
397
+ position: node.body.getStart(sourceFile),
398
+ text: `${helperName}(${JSON.stringify(collected.sourceToken)},${args},${asyncCallback}()=>(`,
399
+ order: order++
400
+ });
401
+ edits.push({ position: node.body.end, text: "))", order: order++ });
402
+ }
403
+ ts2.forEachChild(node, (child) => visit(child, collected));
404
+ return;
405
+ }
406
+ if (caller && (ts2.isCallExpression(node) || ts2.isNewExpression(node))) {
407
+ const site = collectCallSite(node, caller, collectContext);
408
+ if (site) delta.callSites.push(site);
409
+ }
410
+ if (caller && ts2.isVariableDeclaration(node)) {
411
+ const destructure = collectParamDestructure(node, caller, collectContext);
412
+ if (destructure) delta.destructures.push(destructure);
413
+ }
414
+ ts2.forEachChild(node, (child) => visit(child, caller));
415
+ };
416
+ visit(sourceFile);
417
+ if (edits.length === 0) return void 0;
418
+ const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
419
+ edits.push({ position: shebangEnd, text: helperDeclaration(helperName), order: -1 });
420
+ edits.sort((left, right) => right.position - left.position || right.order - left.order);
421
+ let transformed = source;
422
+ for (const edit of edits) {
423
+ transformed = `${transformed.slice(0, edit.position)}${edit.text}${transformed.slice(edit.position)}`;
424
+ }
425
+ return { code: transformed, delta };
426
+ };
427
+
428
+ // src/auto-instrumentation/bun-plugin.ts
429
+ var loaderFor = (filePath) => {
430
+ if (/\.tsx$/i.test(filePath)) return "tsx";
431
+ if (/\.jsx$/i.test(filePath)) return "jsx";
432
+ if (/\.[cm]?ts$/i.test(filePath)) return "ts";
433
+ return "js";
434
+ };
435
+ var loadedSourceFilter = /^(?!.*[\\/](?:node_modules|dist|build|out|coverage|generated|\.git|\.next|\.svelte-kit|\.output|\.vercel|\.rasputin|\.turbo|\.yarn|\.pnpm|\.bun)[\\/]).*\.[cm]?[jt]sx?$/i;
436
+ var isLoadedApplicationSource = (filePath, options = {}) => isApplicationSource(filePath, { ...options, includeBuildOutput: false });
437
+ var loadSourceForInstrumentation = async (filePath, options = {}) => {
438
+ const absolutePath = resolve4(filePath);
439
+ const source = await readFile(absolutePath, "utf8");
440
+ if (!isLoadedApplicationSource(absolutePath, options)) {
441
+ return { contents: source, loader: loaderFor(absolutePath), transformed: false };
442
+ }
443
+ try {
444
+ const transformed = transformSource(source, { filePath: absolutePath });
445
+ if (transformed) {
446
+ recordInstrumentationManifestDelta(absolutePath, transformed.delta);
447
+ }
448
+ return {
449
+ contents: transformed?.code ?? source,
450
+ loader: loaderFor(absolutePath),
451
+ transformed: transformed !== void 0
452
+ };
453
+ } catch {
454
+ return { contents: source, loader: loaderFor(absolutePath), transformed: false };
455
+ }
456
+ };
457
+ var createRasputinBunPlugin = (options = {}) => {
458
+ const debug = options.debug ?? process.env.RASPUTIN_DEBUG === "1";
459
+ return {
460
+ name: "rasputin-automatic-execution-instrumentation",
461
+ setup(build) {
462
+ if (debug) {
463
+ console.info(
464
+ options.rootDir ? `[rasputin] automatic instrumentation active (source root: ${resolve4(options.rootDir)})` : "[rasputin] automatic instrumentation active (loaded local source)"
465
+ );
466
+ }
467
+ build.onLoad({ filter: loadedSourceFilter }, async ({ path }) => {
468
+ const absolutePath = resolve4(path);
469
+ const result = await loadSourceForInstrumentation(absolutePath, options);
470
+ if (debug && result.transformed) {
471
+ console.info(`[rasputin] instrumented ${absolutePath}`);
472
+ }
473
+ return { contents: result.contents, loader: result.loader };
474
+ });
475
+ }
476
+ };
477
+ };
478
+
479
+ // src/auto-instrumentation/sdk-source-boundary.ts
480
+ import { dirname, resolve as resolve5 } from "node:path";
481
+ import { fileURLToPath } from "node:url";
482
+ var sdkPackageScopeRootFrom = (instrumentEntryUrl) => resolve5(dirname(fileURLToPath(instrumentEntryUrl)), "../../..");
483
+
484
+ // src/instrument/bun.ts
485
+ plugin(
486
+ createRasputinBunPlugin({
487
+ excludedRoots: [sdkPackageScopeRootFrom(import.meta.url)]
488
+ })
489
+ );
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/instrument/node.ts"],"names":[],"mappings":""}