@sailfish-ai/sf-veritas 0.1.35 → 0.2.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/funcSpanTransformer-CTddGtUV.cjs +1 -0
- package/dist/funcSpanTransformer-coYDqcrs.js +136 -0
- package/dist/plugins/funcspanEsbuildPlugin.cjs +1 -0
- package/dist/plugins/funcspanEsbuildPlugin.mjs +21 -0
- package/dist/plugins/funcspanRollupPlugin.cjs +1 -0
- package/dist/plugins/funcspanRollupPlugin.mjs +18 -0
- package/dist/plugins/funcspanTscPlugin.cjs +1 -0
- package/dist/plugins/funcspanTscPlugin.mjs +39 -0
- package/dist/plugins/funcspanVitePlugin.cjs +1 -0
- package/dist/plugins/funcspanVitePlugin.mjs +17 -0
- package/dist/plugins/funcspanWebpackLoader.cjs +1 -0
- package/dist/plugins/funcspanWebpackLoader.mjs +15 -0
- package/dist/plugins/funcspanWebpackPlugin.cjs +1 -0
- package/dist/plugins/funcspanWebpackPlugin.mjs +28 -0
- package/dist/sf-veritas.cjs +38 -20
- package/dist/sf-veritas.mjs +850 -1239
- package/dist/source-map-Cr6YkjTd.js +631 -0
- package/dist/source-map-rHHEdpre.cjs +1 -0
- package/dist/types/baseTransmitter.d.ts +2 -1
- package/dist/types/contextManager.d.ts +23 -0
- package/dist/types/exceptionTransmitter.d.ts +1 -1
- package/dist/types/funcSpanCapture.d.ts +24 -0
- package/dist/types/funcSpanConfig.d.ts +80 -0
- package/dist/types/funcSpanConfigLoader.d.ts +70 -0
- package/dist/types/index.d.ts +4 -1
- package/dist/types/networkRequestTransmitter.d.ts +1 -0
- package/dist/types/plugins/funcSpanTransformer.d.ts +31 -0
- package/dist/types/plugins/funcspanEsbuildPlugin.d.ts +28 -0
- package/dist/types/plugins/funcspanRollupPlugin.d.ts +28 -0
- package/dist/types/plugins/funcspanTscPlugin.d.ts +35 -0
- package/dist/types/plugins/funcspanVitePlugin.d.ts +27 -0
- package/dist/types/plugins/funcspanWebpackLoader.d.ts +1 -0
- package/dist/types/plugins/funcspanWebpackPlugin.d.ts +32 -0
- package/package.json +49 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const q=require("@babel/parser"),O=require("@babel/traverse"),W=require("@babel/generator"),M=require("@babel/types"),u=require("path"),C=require("fs"),D=require("./source-map-rHHEdpre.cjs");function w(l){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const s in l)if(s!=="default"){const E=Object.getOwnPropertyDescriptor(l,s);Object.defineProperty(o,s,E.get?E:{enumerable:!0,get:()=>l[s]})}}return o.default=l,Object.freeze(o)}const e=w(M),I=O.default||O,N=W.default||W;function v(l){const o=[];for(const s of l)e.isIdentifier(s)?o.push(s.name):e.isRestElement(s)&&e.isIdentifier(s.argument)?o.push(`...${s.argument.name}`):e.isAssignmentPattern(s)&&e.isIdentifier(s.left)?o.push(s.left.name):e.isObjectPattern(s)?o.push("{}"):e.isArrayPattern(s)?o.push("[]"):o.push("_");return o}exports.transformFunctionSpans=async function(l,o,s={}){const{projectRoot:E=process.cwd(),includeNodeModules:_=[],debug:g=!1}=s;if(o.includes("node_modules")&&!_.some(n=>o.includes(`node_modules/${n}`)))return{code:l,modified:!1,functionsWrapped:0};const F=u.relative(E,o).replace(/\\/g,"/");let x;g&&console.log(`[FuncSpan Transform] Processing: ${F}`);try{x=q.parse(l,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy","classProperties","objectRestSpread","asyncGenerators","dynamicImport","optionalCatchBinding","optionalChaining","nullishCoalescingOperator"]})}catch(n){return g&&console.error(`[FuncSpan Transform] Parse error in ${F}:`,n),{code:l,modified:!1,functionsWrapped:0}}let k=null,T=null;try{const n=C.readFileSync(`${o}.map`,"utf-8");k=await new D.sourceMapExports.SourceMapConsumer(JSON.parse(n))}catch{}const P=(n,i)=>{if(k){const r=k.originalPositionFor({line:n,column:i});if(r.line!==null&&r.column!==null)return!T&&r.source&&(T=r.source),{line:r.line,column:r.column,source:r.source||void 0}}return{line:n,column:i}};let L=!1,h=0;const y=new Set;if(I(x,{FunctionDeclaration(n){const i=n.node.id?.name;if(!i)return;const r=`decl_${i}`;if(y.has(r))return;g&&console.log(`[FuncSpan Transform] Wrapping function declaration: ${i}`);const t=n.node.loc?.start.line??0,a=n.node.loc?.start.column??0,c=P(t,a),{line:d,column:p}=c;let m=F;if(c.source){const j=u.resolve(u.dirname(o),c.source);m=u.relative(E,j).replace(/\\/g,"/")}!g||d===t&&p===a||console.log(`[FuncSpan Transform] Mapped ${t}:${a} → ${d}:${p} in ${m}`);const S=v(n.node.params),b=e.callExpression(e.identifier("captureFunctionSpan"),[e.identifier(i),e.stringLiteral(i),e.stringLiteral(m),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(d)),e.objectProperty(e.identifier("column"),e.numericLiteral(p)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(S.map(j=>e.stringLiteral(j))))])]),$=e.expressionStatement(e.assignmentExpression("=",e.identifier(i),b));n.insertAfter($),L=!0,h++,y.add(r)},VariableDeclarator(n){const i=n.node.id,r=n.node.init;if(!e.isIdentifier(i)||!r||!e.isFunctionExpression(r)&&!e.isArrowFunctionExpression(r))return;const t=i.name,a=`var_${t}`;if(y.has(a))return;g&&console.log(`[FuncSpan Transform] Wrapping variable function: ${t}`);const c=r.loc?.start.line??0,d=r.loc?.start.column??0,p=P(c,d),{line:m,column:S}=p;let b=F;if(p.source){const f=u.resolve(u.dirname(o),p.source);b=u.relative(E,f).replace(/\\/g,"/")}!g||m===c&&S===d||console.log(`[FuncSpan Transform] Mapped ${c}:${d} → ${m}:${S} in ${b}`);const $=v(r.params),j=e.callExpression(e.identifier("captureFunctionSpan"),[r,e.stringLiteral(t),e.stringLiteral(b),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(S)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression($.map(f=>e.stringLiteral(f))))])]);n.node.init=j,L=!0,h++,y.add(a)},ClassMethod(n){if(n.node.kind==="constructor"||n.node.kind==="get"||n.node.kind==="set")return;const i=e.isIdentifier(n.node.key)?n.node.key.name:"anonymous",r=`method_${i}_${n.node.start}`;if(y.has(r))return;g&&console.log(`[FuncSpan Transform] Wrapping class method: ${i}`);const t=n.node.body,a=e.functionExpression(null,n.node.params,t,n.node.generator,n.node.async),c=e.callExpression(e.identifier("captureFunctionSpan"),[a,e.stringLiteral(i),e.stringLiteral(F)]),d=e.blockStatement([e.returnStatement(e.callExpression(e.memberExpression(c,e.identifier("call")),[e.thisExpression(),e.spreadElement(e.identifier("arguments"))]))]);n.node.body=d,L=!0,h++,y.add(r)},ObjectMethod(n){if(n.node.kind==="get"||n.node.kind==="set")return;const i=e.isIdentifier(n.node.key)?n.node.key.name:e.isStringLiteral(n.node.key)?n.node.key.value:"anonymous",r=`objmethod_${i}_${n.node.start}`;if(y.has(r))return;g&&console.log(`[FuncSpan Transform] Wrapping object method: ${i}`);const t=n.node.loc?.start.line??0,a=n.node.loc?.start.column??0,c=P(t,a),{line:d,column:p}=c;let m=F;if(c.source){const f=u.resolve(u.dirname(o),c.source);m=u.relative(E,f).replace(/\\/g,"/")}const S=v(n.node.params),b=e.functionExpression(e.identifier(i),n.node.params,n.node.body,n.node.generator,n.node.async),$=e.callExpression(e.identifier("captureFunctionSpan"),[b,e.stringLiteral(i),e.stringLiteral(m),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(d)),e.objectProperty(e.identifier("column"),e.numericLiteral(p)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(S.map(f=>e.stringLiteral(f))))])]),j=e.objectProperty(n.node.key,$,n.node.computed,!1);n.replaceWith(j),L=!0,h++,y.add(r)},ClassProperty(n){const i=n.node.key,r=n.node.value;if(!e.isIdentifier(i)||!r||!e.isFunctionExpression(r)&&!e.isArrowFunctionExpression(r))return;const t=i.name,a=`classprop_${t}_${n.node.start}`;if(y.has(a))return;g&&console.log(`[FuncSpan Transform] Wrapping class property function: ${t}`);const c=r.loc?.start.line??0,d=r.loc?.start.column??0,p=P(c,d),{line:m,column:S}=p;let b=F;if(p.source){const f=u.resolve(u.dirname(o),p.source);b=u.relative(E,f).replace(/\\/g,"/")}const $=v(r.params),j=e.callExpression(e.identifier("captureFunctionSpan"),[r,e.stringLiteral(t),e.stringLiteral(b),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(S)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression($.map(f=>e.stringLiteral(f))))])]);n.node.value=j,L=!0,h++,y.add(a)}}),L&&!(function(n){let i=!1;return I(n,{ImportDeclaration(r){e.isStringLiteral(r.node.source)&&r.node.source.value==="@sailfish-ai/sf-veritas"&&r.node.specifiers.some(t=>e.isImportSpecifier(t)&&e.isIdentifier(t.imported)&&t.imported.name==="captureFunctionSpan")&&(i=!0,r.stop())},VariableDeclarator(r){if(e.isObjectPattern(r.node.id)&&e.isCallExpression(r.node.init)&&e.isIdentifier(r.node.init.callee)&&r.node.init.callee.name==="require"){const t=r.node.init.arguments;t.length>0&&e.isStringLiteral(t[0])&&t[0].value==="@sailfish-ai/sf-veritas"&&r.node.id.properties.some(a=>e.isObjectProperty(a)&&e.isIdentifier(a.key)&&a.key.name==="captureFunctionSpan")&&(i=!0,r.stop())}}}),i})(x))if((function(n){let i=!1;return I(n,{CallExpression(r){e.isIdentifier(r.node.callee)&&r.node.callee.name==="require"&&(i=!0,r.stop())},MemberExpression(r){!e.isIdentifier(r.node.object)||r.node.object.name!=="module"&&r.node.object.name!=="exports"||(i=!0,r.stop())}}),i})(x)){const n=e.variableDeclaration("const",[e.variableDeclarator(e.objectPattern([e.objectProperty(e.identifier("captureFunctionSpan"),e.identifier("captureFunctionSpan"),!1,!0)]),e.callExpression(e.identifier("require"),[e.stringLiteral("@sailfish-ai/sf-veritas")]))]);x.program.body.unshift(n)}else{const n=e.importDeclaration([e.importSpecifier(e.identifier("captureFunctionSpan"),e.identifier("captureFunctionSpan"))],e.stringLiteral("@sailfish-ai/sf-veritas"));x.program.body.unshift(n)}if(h>0){const n=N(x,{retainLines:!0,compact:!1,sourceMaps:!0,sourceFileName:o},l);return g&&console.log(`[FuncSpan Transform] ✅ Wrapped ${h} functions in ${F}`),{code:n.code,map:n.map,modified:!0,functionsWrapped:h}}return{code:l,modified:!1,functionsWrapped:0}};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { parse as N } from "@babel/parser";
|
|
2
|
+
import C from "@babel/traverse";
|
|
3
|
+
import M from "@babel/generator";
|
|
4
|
+
import * as e from "@babel/types";
|
|
5
|
+
import { relative as E, resolve as k, dirname as v } from "path";
|
|
6
|
+
import { readFileSync as w } from "fs";
|
|
7
|
+
import { s as O } from "./source-map-Cr6YkjTd.js";
|
|
8
|
+
const W = C.default || C, A = M.default || M;
|
|
9
|
+
async function z(F, t, p = {}) {
|
|
10
|
+
const { projectRoot: $ = process.cwd(), includeNodeModules: D = [], debug: m = !1 } = p;
|
|
11
|
+
if (t.includes("node_modules") && !D.some((n) => t.includes(`node_modules/${n}`))) return { code: F, modified: !1, functionsWrapped: 0 };
|
|
12
|
+
const S = E($, t).replace(/\\/g, "/");
|
|
13
|
+
let j;
|
|
14
|
+
m && console.log(`[FuncSpan Transform] Processing: ${S}`);
|
|
15
|
+
try {
|
|
16
|
+
j = N(F, { sourceType: "module", plugins: ["typescript", "jsx", "decorators-legacy", "classProperties", "objectRestSpread", "asyncGenerators", "dynamicImport", "optionalCatchBinding", "optionalChaining", "nullishCoalescingOperator"] });
|
|
17
|
+
} catch (n) {
|
|
18
|
+
return m && console.error(`[FuncSpan Transform] Parse error in ${S}:`, n), { code: F, modified: !1, functionsWrapped: 0 };
|
|
19
|
+
}
|
|
20
|
+
let T = null, _ = null;
|
|
21
|
+
try {
|
|
22
|
+
const n = w(`${t}.map`, "utf-8");
|
|
23
|
+
T = await new O.SourceMapConsumer(JSON.parse(n));
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
const P = (n, i) => {
|
|
27
|
+
if (T) {
|
|
28
|
+
const r = T.originalPositionFor({ line: n, column: i });
|
|
29
|
+
if (r.line !== null && r.column !== null) return !_ && r.source && (_ = r.source), { line: r.line, column: r.column, source: r.source || void 0 };
|
|
30
|
+
}
|
|
31
|
+
return { line: n, column: i };
|
|
32
|
+
};
|
|
33
|
+
let L = !1, h = 0;
|
|
34
|
+
const f = /* @__PURE__ */ new Set();
|
|
35
|
+
if (W(j, { FunctionDeclaration(n) {
|
|
36
|
+
const i = n.node.id?.name;
|
|
37
|
+
if (!i) return;
|
|
38
|
+
const r = `decl_${i}`;
|
|
39
|
+
if (f.has(r)) return;
|
|
40
|
+
m && console.log(`[FuncSpan Transform] Wrapping function declaration: ${i}`);
|
|
41
|
+
const o = n.node.loc?.start.line ?? 0, s = n.node.loc?.start.column ?? 0, a = P(o, s), { line: c, column: l } = a;
|
|
42
|
+
let d = S;
|
|
43
|
+
if (a.source) {
|
|
44
|
+
const b = k(v(t), a.source);
|
|
45
|
+
d = E($, b).replace(/\\/g, "/");
|
|
46
|
+
}
|
|
47
|
+
!m || c === o && l === s || console.log(`[FuncSpan Transform] Mapped ${o}:${s} → ${c}:${l} in ${d}`);
|
|
48
|
+
const y = I(n.node.params), g = e.callExpression(e.identifier("captureFunctionSpan"), [e.identifier(i), e.stringLiteral(i), e.stringLiteral(d), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(c)), e.objectProperty(e.identifier("column"), e.numericLiteral(l)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(y.map((b) => e.stringLiteral(b))))])]), x = e.expressionStatement(e.assignmentExpression("=", e.identifier(i), g));
|
|
49
|
+
n.insertAfter(x), L = !0, h++, f.add(r);
|
|
50
|
+
}, VariableDeclarator(n) {
|
|
51
|
+
const i = n.node.id, r = n.node.init;
|
|
52
|
+
if (!e.isIdentifier(i) || !r || !e.isFunctionExpression(r) && !e.isArrowFunctionExpression(r)) return;
|
|
53
|
+
const o = i.name, s = `var_${o}`;
|
|
54
|
+
if (f.has(s)) return;
|
|
55
|
+
m && console.log(`[FuncSpan Transform] Wrapping variable function: ${o}`);
|
|
56
|
+
const a = r.loc?.start.line ?? 0, c = r.loc?.start.column ?? 0, l = P(a, c), { line: d, column: y } = l;
|
|
57
|
+
let g = S;
|
|
58
|
+
if (l.source) {
|
|
59
|
+
const u = k(v(t), l.source);
|
|
60
|
+
g = E($, u).replace(/\\/g, "/");
|
|
61
|
+
}
|
|
62
|
+
!m || d === a && y === c || console.log(`[FuncSpan Transform] Mapped ${a}:${c} → ${d}:${y} in ${g}`);
|
|
63
|
+
const x = I(r.params), b = e.callExpression(e.identifier("captureFunctionSpan"), [r, e.stringLiteral(o), e.stringLiteral(g), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(d)), e.objectProperty(e.identifier("column"), e.numericLiteral(y)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(x.map((u) => e.stringLiteral(u))))])]);
|
|
64
|
+
n.node.init = b, L = !0, h++, f.add(s);
|
|
65
|
+
}, ClassMethod(n) {
|
|
66
|
+
if (n.node.kind === "constructor" || n.node.kind === "get" || n.node.kind === "set") return;
|
|
67
|
+
const i = e.isIdentifier(n.node.key) ? n.node.key.name : "anonymous", r = `method_${i}_${n.node.start}`;
|
|
68
|
+
if (f.has(r)) return;
|
|
69
|
+
m && console.log(`[FuncSpan Transform] Wrapping class method: ${i}`);
|
|
70
|
+
const o = n.node.body, s = e.functionExpression(null, n.node.params, o, n.node.generator, n.node.async), a = e.callExpression(e.identifier("captureFunctionSpan"), [s, e.stringLiteral(i), e.stringLiteral(S)]), c = e.blockStatement([e.returnStatement(e.callExpression(e.memberExpression(a, e.identifier("call")), [e.thisExpression(), e.spreadElement(e.identifier("arguments"))]))]);
|
|
71
|
+
n.node.body = c, L = !0, h++, f.add(r);
|
|
72
|
+
}, ObjectMethod(n) {
|
|
73
|
+
if (n.node.kind === "get" || n.node.kind === "set") return;
|
|
74
|
+
const i = e.isIdentifier(n.node.key) ? n.node.key.name : e.isStringLiteral(n.node.key) ? n.node.key.value : "anonymous", r = `objmethod_${i}_${n.node.start}`;
|
|
75
|
+
if (f.has(r)) return;
|
|
76
|
+
m && console.log(`[FuncSpan Transform] Wrapping object method: ${i}`);
|
|
77
|
+
const o = n.node.loc?.start.line ?? 0, s = n.node.loc?.start.column ?? 0, a = P(o, s), { line: c, column: l } = a;
|
|
78
|
+
let d = S;
|
|
79
|
+
if (a.source) {
|
|
80
|
+
const u = k(v(t), a.source);
|
|
81
|
+
d = E($, u).replace(/\\/g, "/");
|
|
82
|
+
}
|
|
83
|
+
const y = I(n.node.params), g = e.functionExpression(e.identifier(i), n.node.params, n.node.body, n.node.generator, n.node.async), x = e.callExpression(e.identifier("captureFunctionSpan"), [g, e.stringLiteral(i), e.stringLiteral(d), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(c)), e.objectProperty(e.identifier("column"), e.numericLiteral(l)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(y.map((u) => e.stringLiteral(u))))])]), b = e.objectProperty(n.node.key, x, n.node.computed, !1);
|
|
84
|
+
n.replaceWith(b), L = !0, h++, f.add(r);
|
|
85
|
+
}, ClassProperty(n) {
|
|
86
|
+
const i = n.node.key, r = n.node.value;
|
|
87
|
+
if (!e.isIdentifier(i) || !r || !e.isFunctionExpression(r) && !e.isArrowFunctionExpression(r)) return;
|
|
88
|
+
const o = i.name, s = `classprop_${o}_${n.node.start}`;
|
|
89
|
+
if (f.has(s)) return;
|
|
90
|
+
m && console.log(`[FuncSpan Transform] Wrapping class property function: ${o}`);
|
|
91
|
+
const a = r.loc?.start.line ?? 0, c = r.loc?.start.column ?? 0, l = P(a, c), { line: d, column: y } = l;
|
|
92
|
+
let g = S;
|
|
93
|
+
if (l.source) {
|
|
94
|
+
const u = k(v(t), l.source);
|
|
95
|
+
g = E($, u).replace(/\\/g, "/");
|
|
96
|
+
}
|
|
97
|
+
const x = I(r.params), b = e.callExpression(e.identifier("captureFunctionSpan"), [r, e.stringLiteral(o), e.stringLiteral(g), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(d)), e.objectProperty(e.identifier("column"), e.numericLiteral(y)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(x.map((u) => e.stringLiteral(u))))])]);
|
|
98
|
+
n.node.value = b, L = !0, h++, f.add(s);
|
|
99
|
+
} }), L && !(function(n) {
|
|
100
|
+
let i = !1;
|
|
101
|
+
return W(n, { ImportDeclaration(r) {
|
|
102
|
+
e.isStringLiteral(r.node.source) && r.node.source.value === "@sailfish-ai/sf-veritas" && r.node.specifiers.some((o) => e.isImportSpecifier(o) && e.isIdentifier(o.imported) && o.imported.name === "captureFunctionSpan") && (i = !0, r.stop());
|
|
103
|
+
}, VariableDeclarator(r) {
|
|
104
|
+
if (e.isObjectPattern(r.node.id) && e.isCallExpression(r.node.init) && e.isIdentifier(r.node.init.callee) && r.node.init.callee.name === "require") {
|
|
105
|
+
const o = r.node.init.arguments;
|
|
106
|
+
o.length > 0 && e.isStringLiteral(o[0]) && o[0].value === "@sailfish-ai/sf-veritas" && r.node.id.properties.some((s) => e.isObjectProperty(s) && e.isIdentifier(s.key) && s.key.name === "captureFunctionSpan") && (i = !0, r.stop());
|
|
107
|
+
}
|
|
108
|
+
} }), i;
|
|
109
|
+
})(j)) if ((function(n) {
|
|
110
|
+
let i = !1;
|
|
111
|
+
return W(n, { CallExpression(r) {
|
|
112
|
+
e.isIdentifier(r.node.callee) && r.node.callee.name === "require" && (i = !0, r.stop());
|
|
113
|
+
}, MemberExpression(r) {
|
|
114
|
+
!e.isIdentifier(r.node.object) || r.node.object.name !== "module" && r.node.object.name !== "exports" || (i = !0, r.stop());
|
|
115
|
+
} }), i;
|
|
116
|
+
})(j)) {
|
|
117
|
+
const n = e.variableDeclaration("const", [e.variableDeclarator(e.objectPattern([e.objectProperty(e.identifier("captureFunctionSpan"), e.identifier("captureFunctionSpan"), !1, !0)]), e.callExpression(e.identifier("require"), [e.stringLiteral("@sailfish-ai/sf-veritas")]))]);
|
|
118
|
+
j.program.body.unshift(n);
|
|
119
|
+
} else {
|
|
120
|
+
const n = e.importDeclaration([e.importSpecifier(e.identifier("captureFunctionSpan"), e.identifier("captureFunctionSpan"))], e.stringLiteral("@sailfish-ai/sf-veritas"));
|
|
121
|
+
j.program.body.unshift(n);
|
|
122
|
+
}
|
|
123
|
+
if (h > 0) {
|
|
124
|
+
const n = A(j, { retainLines: !0, compact: !1, sourceMaps: !0, sourceFileName: t }, F);
|
|
125
|
+
return m && console.log(`[FuncSpan Transform] ✅ Wrapped ${h} functions in ${S}`), { code: n.code, map: n.map, modified: !0, functionsWrapped: h };
|
|
126
|
+
}
|
|
127
|
+
return { code: F, modified: !1, functionsWrapped: 0 };
|
|
128
|
+
}
|
|
129
|
+
function I(F) {
|
|
130
|
+
const t = [];
|
|
131
|
+
for (const p of F) e.isIdentifier(p) ? t.push(p.name) : e.isRestElement(p) && e.isIdentifier(p.argument) ? t.push(`...${p.argument.name}`) : e.isAssignmentPattern(p) && e.isIdentifier(p.left) ? t.push(p.left.name) : e.isObjectPattern(p) ? t.push("{}") : e.isArrayPattern(p) ? t.push("[]") : t.push("_");
|
|
132
|
+
return t;
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
z as t
|
|
136
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("fs"),r=require("../funcSpanTransformer-CTddGtUV.cjs");function u(o={}){const{enabled:l=!0,includeNodeModules:n=[],debug:t=!1}=o;return{name:"sailfish-funcspan-esbuild",setup(d){l&&(d.onLoad({filter:/\.(js|ts|jsx|tsx)$/},async e=>{if(e.path.includes("node_modules")&&!n.some(s=>e.path.includes(`node_modules/${s}`))||e.path.includes("@sailfish-ai/sf-veritas")||e.path.includes("jsts-backend/dist"))return null;try{const s=a.readFileSync(e.path,"utf-8"),i=await r.transformFunctionSpans(s,e.path,{projectRoot:process.cwd(),includeNodeModules:n,debug:t});if(i.modified)return{contents:i.code,loader:e.path.endsWith(".ts")||e.path.endsWith(".tsx")?"ts":"js"}}catch(s){t&&console.error(`[FuncSpan Esbuild] Error transforming ${e.path}:`,s)}return null}),t&&console.log("[FuncSpan Esbuild] Plugin initialized"))}}}exports.default=u,exports.funcspanEsbuildPlugin=u;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readFileSync as u } from "fs";
|
|
2
|
+
import { t as l } from "../funcSpanTransformer-coYDqcrs.js";
|
|
3
|
+
function p(o = {}) {
|
|
4
|
+
const { enabled: a = !0, includeNodeModules: i = [], debug: t = !1 } = o;
|
|
5
|
+
return { name: "sailfish-funcspan-esbuild", setup(d) {
|
|
6
|
+
a && (d.onLoad({ filter: /\.(js|ts|jsx|tsx)$/ }, async (s) => {
|
|
7
|
+
if (s.path.includes("node_modules") && !i.some((e) => s.path.includes(`node_modules/${e}`)) || s.path.includes("@sailfish-ai/sf-veritas") || s.path.includes("jsts-backend/dist")) return null;
|
|
8
|
+
try {
|
|
9
|
+
const e = u(s.path, "utf-8"), n = await l(e, s.path, { projectRoot: process.cwd(), includeNodeModules: i, debug: t });
|
|
10
|
+
if (n.modified) return { contents: n.code, loader: s.path.endsWith(".ts") || s.path.endsWith(".tsx") ? "ts" : "js" };
|
|
11
|
+
} catch (e) {
|
|
12
|
+
t && console.error(`[FuncSpan Esbuild] Error transforming ${s.path}:`, e);
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}), t && console.log("[FuncSpan Esbuild] Plugin initialized"));
|
|
16
|
+
} };
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
p as default,
|
|
20
|
+
p as funcspanEsbuildPlugin
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("../funcSpanTransformer-CTddGtUV.cjs");function l(r={}){const{enabled:t=!0,includeNodeModules:u=[],debug:s=!1}=r;return{name:"sailfish-funcspan-rollup",async transform(i,e){if(!t||!e.match(/\.(js|ts|jsx|tsx)$/)||e.includes("node_modules")&&!u.some(n=>e.includes(`node_modules/${n}`))||e.includes("@sailfish-ai/sf-veritas")||e.includes("jsts-backend/dist"))return null;try{const n=await o.transformFunctionSpans(i,e,{projectRoot:process.cwd(),includeNodeModules:u,debug:s});if(n.modified)return{code:n.code,map:n.map||null}}catch(n){s&&console.error(`[FuncSpan Rollup] Error transforming ${e}:`,n)}return null}}}exports.default=l,exports.funcspanRollupPlugin=l;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { t } from "../funcSpanTransformer-coYDqcrs.js";
|
|
2
|
+
function i(r = {}) {
|
|
3
|
+
const { enabled: o = !0, includeNodeModules: s = [], debug: u = !1 } = r;
|
|
4
|
+
return { name: "sailfish-funcspan-rollup", async transform(l, n) {
|
|
5
|
+
if (!o || !n.match(/\.(js|ts|jsx|tsx)$/) || n.includes("node_modules") && !s.some((e) => n.includes(`node_modules/${e}`)) || n.includes("@sailfish-ai/sf-veritas") || n.includes("jsts-backend/dist")) return null;
|
|
6
|
+
try {
|
|
7
|
+
const e = await t(l, n, { projectRoot: process.cwd(), includeNodeModules: s, debug: u });
|
|
8
|
+
if (e.modified) return { code: e.code, map: e.map || null };
|
|
9
|
+
} catch (e) {
|
|
10
|
+
u && console.error(`[FuncSpan Rollup] Error transforming ${n}:`, e);
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
} };
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
i as default,
|
|
17
|
+
i as funcspanRollupPlugin
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("fs"),C=require("glob"),N=require("path"),T=require("../funcSpanTransformer-CTddGtUV.cjs");async function d(n={}){const{outDir:f="dist",include:F=["**/*.js"],exclude:g=["**/*.test.js","**/*.spec.js","**/__tests__/**"],projectRoot:s=process.cwd(),includeNodeModules:_=[],debug:t=!1}=n,u=N.resolve(s,f);console.log("[FuncSpan TSC] Starting post-build function instrumentation..."),console.log(`[FuncSpan TSC] Output directory: ${u}`),console.log(`[FuncSpan TSC] Project root: ${s}`);const r=[];for(const o of F){const c=C.sync(o,{cwd:u,absolute:!0,ignore:g});r.push(...c)}console.log(`[FuncSpan TSC] Found ${r.length} JavaScript files to process`);let l=0,p=0;for(const o of r)try{const c=i.readFileSync(o,"utf-8"),e=await T.transformFunctionSpans(c,o,{projectRoot:s,includeNodeModules:_,debug:t});if(e.modified){if(i.writeFileSync(o,e.code,"utf-8"),e.map){const a=`${o}.map`;i.writeFileSync(a,JSON.stringify(e.map),"utf-8"),t&&console.log(`[FuncSpan TSC] Generated source map: ${a}`)}l++,p+=e.functionsWrapped,t&&console.log(`[FuncSpan TSC] Modified: ${o} (${e.functionsWrapped} functions)`)}}catch(c){console.error(`[FuncSpan TSC] Error processing ${o}:`,c)}console.log(`[FuncSpan TSC] ✅ Completed: Modified ${l} files, wrapped ${p} functions`)}async function S(){const n={outDir:process.env.SF_FUNCSPAN_OUT_DIR||"dist",debug:process.env.SF_FUNCSPAN_DEBUG==="true",includeNodeModules:process.env.SF_FUNCSPAN_INCLUDE_NODE_MODULES?process.env.SF_FUNCSPAN_INCLUDE_NODE_MODULES.split(","):[]};await d(n)}require.main===module&&S().catch(n=>{console.error("[FuncSpan TSC] Fatal error:",n),process.exit(1)}),exports.cli=S,exports.processTscFiles=d;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { readFileSync as m, writeFileSync as l } from "fs";
|
|
2
|
+
import { sync as _ } from "glob";
|
|
3
|
+
import { resolve as C } from "path";
|
|
4
|
+
import { t as N } from "../funcSpanTransformer-coYDqcrs.js";
|
|
5
|
+
async function g(n = {}) {
|
|
6
|
+
const { outDir: d = "dist", include: S = ["**/*.js"], exclude: f = ["**/*.test.js", "**/*.spec.js", "**/__tests__/**"], projectRoot: c = process.cwd(), includeNodeModules: F = [], debug: t = !1 } = n, i = C(c, d);
|
|
7
|
+
console.log("[FuncSpan TSC] Starting post-build function instrumentation..."), console.log(`[FuncSpan TSC] Output directory: ${i}`), console.log(`[FuncSpan TSC] Project root: ${c}`);
|
|
8
|
+
const r = [];
|
|
9
|
+
for (const o of S) {
|
|
10
|
+
const s = _(o, { cwd: i, absolute: !0, ignore: f });
|
|
11
|
+
r.push(...s);
|
|
12
|
+
}
|
|
13
|
+
console.log(`[FuncSpan TSC] Found ${r.length} JavaScript files to process`);
|
|
14
|
+
let u = 0, p = 0;
|
|
15
|
+
for (const o of r) try {
|
|
16
|
+
const s = m(o, "utf-8"), e = await N(s, o, { projectRoot: c, includeNodeModules: F, debug: t });
|
|
17
|
+
if (e.modified) {
|
|
18
|
+
if (l(o, e.code, "utf-8"), e.map) {
|
|
19
|
+
const a = `${o}.map`;
|
|
20
|
+
l(a, JSON.stringify(e.map), "utf-8"), t && console.log(`[FuncSpan TSC] Generated source map: ${a}`);
|
|
21
|
+
}
|
|
22
|
+
u++, p += e.functionsWrapped, t && console.log(`[FuncSpan TSC] Modified: ${o} (${e.functionsWrapped} functions)`);
|
|
23
|
+
}
|
|
24
|
+
} catch (s) {
|
|
25
|
+
console.error(`[FuncSpan TSC] Error processing ${o}:`, s);
|
|
26
|
+
}
|
|
27
|
+
console.log(`[FuncSpan TSC] ✅ Completed: Modified ${u} files, wrapped ${p} functions`);
|
|
28
|
+
}
|
|
29
|
+
async function T() {
|
|
30
|
+
const n = { outDir: process.env.SF_FUNCSPAN_OUT_DIR || "dist", debug: process.env.SF_FUNCSPAN_DEBUG === "true", includeNodeModules: process.env.SF_FUNCSPAN_INCLUDE_NODE_MODULES ? process.env.SF_FUNCSPAN_INCLUDE_NODE_MODULES.split(",") : [] };
|
|
31
|
+
await g(n);
|
|
32
|
+
}
|
|
33
|
+
require.main === module && T().catch((n) => {
|
|
34
|
+
console.error("[FuncSpan TSC] Fatal error:", n), process.exit(1);
|
|
35
|
+
});
|
|
36
|
+
export {
|
|
37
|
+
T as cli,
|
|
38
|
+
g as processTscFiles
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../funcSpanTransformer-CTddGtUV.cjs");exports.funcspanVitePlugin=function(t={}){const{enabled:i=!0,includeNodeModules:r=[],debug:s=!1}=t;return{name:"sailfish-funcspan-vite",enforce:"pre",async transform(o,e){if(!i||!e.match(/\.(js|ts|jsx|tsx)$/)||e.startsWith("\0")||e.includes("node_modules")&&!r.some(n=>e.includes(`node_modules/${n}`))||e.includes("@sailfish-ai/sf-veritas")||e.includes("jsts-backend/dist"))return null;try{const n=await l.transformFunctionSpans(o,e,{projectRoot:process.cwd(),includeNodeModules:r,debug:s});if(n.modified)return{code:n.code,map:null}}catch(n){s&&console.error(`[FuncSpan Vite] Error transforming ${e}:`,n)}return null}}};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { t as o } from "../funcSpanTransformer-coYDqcrs.js";
|
|
2
|
+
function c(t = {}) {
|
|
3
|
+
const { enabled: i = !0, includeNodeModules: r = [], debug: s = !1 } = t;
|
|
4
|
+
return { name: "sailfish-funcspan-vite", enforce: "pre", async transform(l, e) {
|
|
5
|
+
if (!i || !e.match(/\.(js|ts|jsx|tsx)$/) || e.startsWith("\0") || e.includes("node_modules") && !r.some((n) => e.includes(`node_modules/${n}`)) || e.includes("@sailfish-ai/sf-veritas") || e.includes("jsts-backend/dist")) return null;
|
|
6
|
+
try {
|
|
7
|
+
const n = await o(l, e, { projectRoot: process.cwd(), includeNodeModules: r, debug: s });
|
|
8
|
+
if (n.modified) return { code: n.code, map: null };
|
|
9
|
+
} catch (n) {
|
|
10
|
+
s && console.error(`[FuncSpan Vite] Error transforming ${e}:`, n);
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
} };
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
c as funcspanVitePlugin
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const s=require("../funcSpanTransformer-CTddGtUV.cjs");module.exports=function(t){const r=this.async(),e=this.getOptions();(async()=>{try{const o=await s.transformFunctionSpans(t,this.resourcePath,{projectRoot:e.projectRoot||process.cwd(),includeNodeModules:e.includeNodeModules||[],debug:e.debug||!1});o.modified?r(null,o.code,o.map):r(null,t)}catch(o){e.debug&&console.error(`[FuncSpan Webpack Loader] Error transforming ${this.resourcePath}:`,o),r(null,t)}})()};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as s } from "../funcSpanTransformer-coYDqcrs.js";
|
|
2
|
+
function n(t) {
|
|
3
|
+
const r = this.async(), e = this.getOptions();
|
|
4
|
+
(async () => {
|
|
5
|
+
try {
|
|
6
|
+
const o = await s(t, this.resourcePath, { projectRoot: e.projectRoot || process.cwd(), includeNodeModules: e.includeNodeModules || [], debug: e.debug || !1 });
|
|
7
|
+
o.modified ? r(null, o.code, o.map) : r(null, t);
|
|
8
|
+
} catch (o) {
|
|
9
|
+
e.debug && console.error(`[FuncSpan Webpack Loader] Error transforming ${this.resourcePath}:`, o), r(null, t);
|
|
10
|
+
}
|
|
11
|
+
})();
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
n as default
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var b=Object.defineProperty;var f=(o,e,t)=>e in o?b(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var d=(o,e,t)=>f(o,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function g(o){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>o[t]})}}return e.default=o,Object.freeze(e)}const m=g(require("path"));class i{constructor(e={}){d(this,"options");this.options={enabled:!0,includeNodeModules:[],debug:!1,...e}}apply(e){const{enabled:t,includeNodeModules:n,debug:c}=this.options;if(!t)return;const u="FuncspanWebpackPlugin";e.hooks.compilation.tap(u,l=>{l.hooks.buildModule.tap(u,r=>{r.resource&&r.resource.match(/\.(js|ts|jsx|tsx)$/)&&(!r.resource.includes("node_modules")||n?.some(s=>r.resource.includes(`node_modules/${s}`)))}),e.webpack.NormalModule.getCompilationHooks(l).loader.tap(u,(r,s)=>{if(!s.resource||!s.resource.match(/\.(js|ts|jsx|tsx)$/)||s.resource.includes("node_modules")&&!n?.some(p=>s.resource.includes(`node_modules/${p}`)))return;const a=m.join(__dirname,"funcspanWebpackLoader.cjs");s.loaders.push({loader:a,options:{projectRoot:e.context,includeNodeModules:n,debug:c}})})}),c&&console.log("[FuncSpan Webpack] Plugin initialized")}}exports.FuncspanWebpackPlugin=i,exports.default=i;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var p = Object.defineProperty;
|
|
2
|
+
var m = (s, e, n) => e in s ? p(s, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : s[e] = n;
|
|
3
|
+
var d = (s, e, n) => m(s, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
+
import * as b from "path";
|
|
5
|
+
class k {
|
|
6
|
+
constructor(e = {}) {
|
|
7
|
+
d(this, "options");
|
|
8
|
+
this.options = { enabled: !0, includeNodeModules: [], debug: !1, ...e };
|
|
9
|
+
}
|
|
10
|
+
apply(e) {
|
|
11
|
+
const { enabled: n, includeNodeModules: c, debug: t } = this.options;
|
|
12
|
+
if (!n) return;
|
|
13
|
+
const r = "FuncspanWebpackPlugin";
|
|
14
|
+
e.hooks.compilation.tap(r, (l) => {
|
|
15
|
+
l.hooks.buildModule.tap(r, (u) => {
|
|
16
|
+
u.resource && u.resource.match(/\.(js|ts|jsx|tsx)$/) && (!u.resource.includes("node_modules") || c?.some((o) => u.resource.includes(`node_modules/${o}`)));
|
|
17
|
+
}), e.webpack.NormalModule.getCompilationHooks(l).loader.tap(r, (u, o) => {
|
|
18
|
+
if (!o.resource || !o.resource.match(/\.(js|ts|jsx|tsx)$/) || o.resource.includes("node_modules") && !c?.some((a) => o.resource.includes(`node_modules/${a}`))) return;
|
|
19
|
+
const i = b.join(__dirname, "funcspanWebpackLoader.cjs");
|
|
20
|
+
o.loaders.push({ loader: i, options: { projectRoot: e.context, includeNodeModules: c, debug: t } });
|
|
21
|
+
});
|
|
22
|
+
}), t && console.log("[FuncSpan Webpack] Plugin initialized");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
k as FuncspanWebpackPlugin,
|
|
27
|
+
k as default
|
|
28
|
+
};
|