@bitfab/sdk 0.76.1 → 0.76.3
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/{babelPlugin-BpEeVvk4.cjs → babelPlugin-C4ERQ8DW.cjs} +118 -69
- package/dist/babelPlugin-C4ERQ8DW.cjs.map +1 -0
- package/dist/{babelPlugin-PgjdBuQe.js → babelPlugin-tupc_WZS.js} +50 -1
- package/dist/babelPlugin-tupc_WZS.js.map +1 -0
- package/dist/baml.cjs +1 -1
- package/dist/baml.js +1 -1
- package/dist/bamlPeer-BxJO7-pm.cjs +169 -0
- package/dist/bamlPeer-BxJO7-pm.cjs.map +1 -0
- package/dist/bamlPeer-CWPgBSlJ.js +109 -0
- package/dist/bamlPeer-CWPgBSlJ.js.map +1 -0
- package/dist/{http-ykHGNcju.cjs → http-7exfDbAK.cjs} +68 -3
- package/dist/{http-DS1QjBvx.js.map → http-7exfDbAK.cjs.map} +1 -1
- package/dist/{http-DS1QjBvx.js → http-BA7vmvuC.js} +56 -3
- package/dist/http-BA7vmvuC.js.map +1 -0
- package/dist/{index-BYv4DSsY.d.cts → index-CmO7Xmwl.d.cts} +1 -1
- package/dist/{index-BYv4DSsY.d.ts → index-CmO7Xmwl.d.ts} +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/{loaderRuntime-0huddOOP.d.ts → loaderRuntime-AETv8Pt4.d.ts} +1 -1
- package/dist/{loaderRuntime-CslfDFO7.d.cts → loaderRuntime-BGUu666e.d.cts} +1 -1
- package/dist/node.cjs +2 -2
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +2 -2
- package/dist/{registryCommand-D1VgfJjC.js → registryCommand-M1u4H9PI.js} +30 -14
- package/dist/registryCommand-M1u4H9PI.js.map +1 -0
- package/dist/replayCli.js +1 -1
- package/dist/seedCli.js +1 -1
- package/dist/{src-CLkegn-P.cjs → src-BMMKf1sR.cjs} +35 -34
- package/dist/src-BMMKf1sR.cjs.map +1 -0
- package/dist/{src-BJjbR3Nq.js → src-CYs1uXoX.js} +35 -34
- package/dist/src-CYs1uXoX.js.map +1 -0
- package/dist/transform/babel.cjs +1 -1
- package/dist/transform/babel.d.cts +1 -1
- package/dist/transform/babel.d.ts +1 -1
- package/dist/transform/babel.js +1 -1
- package/dist/transform/bun.d.cts +1 -1
- package/dist/transform/bun.d.ts +1 -1
- package/dist/transform/esbuild.d.cts +1 -1
- package/dist/transform/esbuild.d.ts +1 -1
- package/dist/transform/loaderRuntime.cjs +3 -3
- package/dist/transform/loaderRuntime.d.cts +1 -1
- package/dist/transform/loaderRuntime.d.ts +1 -1
- package/dist/transform/loaderRuntime.js +3 -3
- package/dist/transform/nest.d.cts +1 -1
- package/dist/transform/nest.d.ts +1 -1
- package/dist/transform/next.d.cts +1 -1
- package/dist/transform/next.d.ts +1 -1
- package/dist/transform/nodeLoader.js +56 -2
- package/dist/transform/nodeLoader.js.map +1 -1
- package/dist/transform/rolldown.d.cts +1 -1
- package/dist/transform/rolldown.d.ts +1 -1
- package/dist/transform/rollup.d.cts +1 -1
- package/dist/transform/rollup.d.ts +1 -1
- package/dist/transform/rsbuild.d.cts +1 -1
- package/dist/transform/rsbuild.d.ts +1 -1
- package/dist/transform/rspack.d.cts +1 -1
- package/dist/transform/rspack.d.ts +1 -1
- package/dist/transform/swc.cjs +1 -1
- package/dist/transform/swc.d.cts +1 -1
- package/dist/transform/swc.d.ts +1 -1
- package/dist/transform/swc.js +1 -1
- package/dist/transform/unplugin.cjs +2 -2
- package/dist/transform/unplugin.d.cts +1 -1
- package/dist/transform/unplugin.d.ts +1 -1
- package/dist/transform/unplugin.js +2 -2
- package/dist/transform/vite.d.cts +1 -1
- package/dist/transform/vite.d.ts +1 -1
- package/dist/transform/webpack.d.cts +1 -1
- package/dist/transform/webpack.d.ts +1 -1
- package/dist/{transform-Cdg7CSbP.cjs → transform-CcNCVr8A.cjs} +2 -2
- package/dist/{transform-Cdg7CSbP.cjs.map → transform-CcNCVr8A.cjs.map} +1 -1
- package/dist/{transform-BhazCKOg.js → transform-mb6EwHsJ.js} +2 -2
- package/dist/{transform-BhazCKOg.js.map → transform-mb6EwHsJ.js.map} +1 -1
- package/dist/{transformOptions-BsjCELkh.d.cts → transformOptions-uNuIpBAA.d.cts} +2 -0
- package/dist/{transformOptions-BsjCELkh.d.ts → transformOptions-uNuIpBAA.d.ts} +2 -0
- package/package.json +1 -1
- package/dist/babelPlugin-BpEeVvk4.cjs.map +0 -1
- package/dist/babelPlugin-PgjdBuQe.js.map +0 -1
- package/dist/bamlPeer-5Ohpq8q9.cjs +0 -74
- package/dist/bamlPeer-5Ohpq8q9.cjs.map +0 -1
- package/dist/bamlPeer-Dyeb3e5o.js +0 -20
- package/dist/bamlPeer-Dyeb3e5o.js.map +0 -1
- package/dist/http-ykHGNcju.cjs.map +0 -1
- package/dist/registryCommand-D1VgfJjC.js.map +0 -1
- package/dist/src-BJjbR3Nq.js.map +0 -1
- package/dist/src-CLkegn-P.cjs.map +0 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
let fs = require("fs");
|
|
2
|
+
let path = require("path");
|
|
1
3
|
//#region ../bitfab-typescript-transform/src/transformOptions.ts
|
|
2
4
|
const AUTO_TRACE_FUNCTION_ID_VERSION = "ts-auto-v1";
|
|
3
5
|
const AUTO_TRACE_TRANSFORM_MARKER = "__bitfab_auto_trace_transformed_v1__";
|
|
@@ -28,43 +30,43 @@ function propertyName(node, types) {
|
|
|
28
30
|
if (types.isStringLiteral(node)) return node.value;
|
|
29
31
|
return null;
|
|
30
32
|
}
|
|
31
|
-
function functionName(path, types) {
|
|
32
|
-
const node = path.node;
|
|
33
|
+
function functionName(path$1, types) {
|
|
34
|
+
const node = path$1.node;
|
|
33
35
|
if (types.isFunctionDeclaration(node) || types.isFunctionExpression(node)) {
|
|
34
36
|
if (node.id) return node.id.name;
|
|
35
37
|
}
|
|
36
38
|
if ((types.isClassMethod(node) || types.isObjectMethod(node)) && !node.computed && types.isIdentifier(node.key)) return node.key.name;
|
|
37
|
-
const parent = path.parentPath?.node;
|
|
39
|
+
const parent = path$1.parentPath?.node;
|
|
38
40
|
if (types.isVariableDeclarator(parent)) return propertyName(parent.id, types) ?? "anonymous";
|
|
39
41
|
if (types.isObjectProperty(parent) && !parent.computed) return propertyName(parent.key, types) ?? "anonymous";
|
|
40
42
|
if (types.isClassProperty(parent) && !parent.computed) {
|
|
41
43
|
const name = propertyName(parent.key, types);
|
|
42
44
|
if (name) return name;
|
|
43
45
|
}
|
|
44
|
-
const { line, column } = sourcePosition(path);
|
|
46
|
+
const { line, column } = sourcePosition(path$1);
|
|
45
47
|
return `anonymous-${line}-${column}`;
|
|
46
48
|
}
|
|
47
49
|
const JEV_METHOD = "systemOne";
|
|
48
|
-
function isJevMethodDefinition(path, types) {
|
|
49
|
-
const parent = path.parentPath?.node;
|
|
50
|
-
return (types.isClassMethod(path.node) || types.isObjectMethod(path.node) || types.isObjectProperty(parent) || types.isClassProperty(parent)) && functionName(path, types) === JEV_METHOD;
|
|
50
|
+
function isJevMethodDefinition(path$2, types) {
|
|
51
|
+
const parent = path$2.parentPath?.node;
|
|
52
|
+
return (types.isClassMethod(path$2.node) || types.isObjectMethod(path$2.node) || types.isObjectProperty(parent) || types.isClassProperty(parent)) && functionName(path$2, types) === JEV_METHOD;
|
|
51
53
|
}
|
|
52
54
|
function isInstrumentableFunction(node, types) {
|
|
53
55
|
if (node.generator || types.isClassPrivateMethod(node)) return false;
|
|
54
56
|
return !(types.isClassMethod(node) || types.isObjectMethod(node)) || node.kind === "method";
|
|
55
57
|
}
|
|
56
|
-
function sourcePosition(path) {
|
|
57
|
-
const start = ((path.parentPath?.isExportDeclaration() ? path.parentPath.node : void 0) ?? path.node).loc?.start;
|
|
58
|
+
function sourcePosition(path$3) {
|
|
59
|
+
const start = ((path$3.parentPath?.isExportDeclaration() ? path$3.parentPath.node : void 0) ?? path$3.node).loc?.start;
|
|
58
60
|
return {
|
|
59
61
|
line: start?.line ?? 0,
|
|
60
62
|
column: start?.column ?? 0
|
|
61
63
|
};
|
|
62
64
|
}
|
|
63
|
-
function qualifiedFunctionName(path, types) {
|
|
64
|
-
const ownName = functionName(path, types);
|
|
65
|
+
function qualifiedFunctionName(path$4, types) {
|
|
66
|
+
const ownName = functionName(path$4, types);
|
|
65
67
|
if (ownName.startsWith("anonymous-")) return ownName;
|
|
66
68
|
const scopes = [];
|
|
67
|
-
let ancestor = path.parentPath;
|
|
69
|
+
let ancestor = path$4.parentPath;
|
|
68
70
|
while (ancestor) {
|
|
69
71
|
if (ancestor.isFunction()) {
|
|
70
72
|
if (!isInstrumentableFunction(ancestor.node, types)) {
|
|
@@ -88,9 +90,9 @@ function qualifiedFunctionName(path, types) {
|
|
|
88
90
|
}
|
|
89
91
|
return [...scopes, ownName].join(".");
|
|
90
92
|
}
|
|
91
|
-
function isTraceDecoratorRoot(path, types) {
|
|
92
|
-
const node = path.node;
|
|
93
|
-
const parent = path.parentPath?.node;
|
|
93
|
+
function isTraceDecoratorRoot(path$5, types) {
|
|
94
|
+
const node = path$5.node;
|
|
95
|
+
const parent = path$5.parentPath?.node;
|
|
94
96
|
const decorated = types.isClassMethod(node) || types.isClassPrivateMethod(node) ? node : types.isClassProperty(parent) && parent.value === node ? parent : null;
|
|
95
97
|
if (!decorated) return false;
|
|
96
98
|
return decorated.decorators?.some((decorator) => {
|
|
@@ -100,11 +102,11 @@ function isTraceDecoratorRoot(path, types) {
|
|
|
100
102
|
return types.isMemberExpression(callee) && !callee.computed && types.isIdentifier(callee.property, { name: "trace" });
|
|
101
103
|
}) ?? false;
|
|
102
104
|
}
|
|
103
|
-
function withNodeFunctionName(path, types) {
|
|
104
|
-
if (path.node.arguments.length > 2) return null;
|
|
105
|
-
const callee = path.node.callee;
|
|
105
|
+
function withNodeFunctionName(path$6, types) {
|
|
106
|
+
if (path$6.node.arguments.length > 2) return null;
|
|
107
|
+
const callee = path$6.node.callee;
|
|
106
108
|
if (!types.isMemberExpression(callee) || callee.computed || !types.isIdentifier(callee.property, { name: "withNode" })) return null;
|
|
107
|
-
const fn = path.node.arguments[path.node.arguments.length - 1];
|
|
109
|
+
const fn = path$6.node.arguments[path$6.node.arguments.length - 1];
|
|
108
110
|
if (types.isIdentifier(fn)) return fn.name;
|
|
109
111
|
if (types.isMemberExpression(fn) && !fn.computed) return propertyName(fn.property, types);
|
|
110
112
|
if (types.isFunctionExpression(fn) && fn.id) return fn.id.name;
|
|
@@ -113,13 +115,55 @@ function withNodeFunctionName(path, types) {
|
|
|
113
115
|
const BAML_GENERATED_HEADER = "This file was generated by BAML";
|
|
114
116
|
const BAML_CLIENT_CLASSES = /* @__PURE__ */ new Set(["BamlAsyncClient", "BamlSyncClient"]);
|
|
115
117
|
const BAML_OPTIONS_PARAMETER = "__baml_options__";
|
|
118
|
+
const BAML_PACKAGE = "@boundaryml/baml";
|
|
119
|
+
const DEFAULT_BAML_REGISTRATION_MODULE = "@bitfab/sdk/baml";
|
|
120
|
+
function importsBamlAtRuntime(program, types) {
|
|
121
|
+
return program.body.some((statement) => types.isImportDeclaration(statement) && statement.source.value === BAML_PACKAGE && statement.importKind !== "type" && statement.specifiers.some((specifier) => !types.isImportSpecifier(specifier) || specifier.importKind !== "type"));
|
|
122
|
+
}
|
|
123
|
+
const SDK_PACKAGE_PATH = [
|
|
124
|
+
"node_modules",
|
|
125
|
+
"@bitfab",
|
|
126
|
+
"sdk",
|
|
127
|
+
"package.json"
|
|
128
|
+
];
|
|
129
|
+
const BAML_REGISTRATION_EXPORT = "./baml";
|
|
130
|
+
const sdkExportsBamlRegistrationByDirectory = /* @__PURE__ */ new Map();
|
|
131
|
+
function readPackageJson(path$7) {
|
|
132
|
+
try {
|
|
133
|
+
return JSON.parse((0, fs.readFileSync)(path$7, "utf8"));
|
|
134
|
+
} catch {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function exportsBamlRegistration(packageJson) {
|
|
139
|
+
if (typeof packageJson !== "object" || packageJson === null) return false;
|
|
140
|
+
const exports = packageJson.exports;
|
|
141
|
+
return typeof exports === "object" && exports !== null && BAML_REGISTRATION_EXPORT in exports;
|
|
142
|
+
}
|
|
143
|
+
function nearestSdkExportsBamlRegistration(directory) {
|
|
144
|
+
const cached = sdkExportsBamlRegistrationByDirectory.get(directory);
|
|
145
|
+
if (cached !== void 0) return cached;
|
|
146
|
+
const packageJson = readPackageJson((0, path.join)(directory, ...SDK_PACKAGE_PATH));
|
|
147
|
+
const parent = (0, path.dirname)(directory);
|
|
148
|
+
const exported = packageJson !== void 0 ? exportsBamlRegistration(packageJson) : parent !== directory && nearestSdkExportsBamlRegistration(parent);
|
|
149
|
+
sdkExportsBamlRegistrationByDirectory.set(directory, exported);
|
|
150
|
+
return exported;
|
|
151
|
+
}
|
|
152
|
+
function defaultRegistrationResolves(filename) {
|
|
153
|
+
return (0, path.isAbsolute)(filename) && nearestSdkExportsBamlRegistration((0, path.dirname)(filename));
|
|
154
|
+
}
|
|
155
|
+
function bamlRegistrationModuleFor(filename, configured) {
|
|
156
|
+
if (configured === false) return null;
|
|
157
|
+
if (configured !== void 0) return configured;
|
|
158
|
+
return defaultRegistrationResolves(filename) ? DEFAULT_BAML_REGISTRATION_MODULE : null;
|
|
159
|
+
}
|
|
116
160
|
function isBamlGeneratedSource(code) {
|
|
117
161
|
return code.slice(0, 4096).includes(BAML_GENERATED_HEADER);
|
|
118
162
|
}
|
|
119
|
-
function isBamlClientMethod(path, types) {
|
|
120
|
-
const node = path.node;
|
|
163
|
+
function isBamlClientMethod(path$8, types) {
|
|
164
|
+
const node = path$8.node;
|
|
121
165
|
if (!types.isClassMethod(node) || node.kind !== "method" || node.static) return false;
|
|
122
|
-
const classPath = path.parentPath?.parentPath;
|
|
166
|
+
const classPath = path$8.parentPath?.parentPath;
|
|
123
167
|
if (!classPath || !(classPath.isClassDeclaration() || classPath.isClassExpression()) || !classPath.node.id || !BAML_CLIENT_CLASSES.has(classPath.node.id.name)) return false;
|
|
124
168
|
const parameters = runtimeParameters(node, types);
|
|
125
169
|
const last = parameters[parameters.length - 1];
|
|
@@ -131,10 +175,10 @@ function bamlOptionsDeclaration(callerOptions, withCollector, types) {
|
|
|
131
175
|
function runtimeParameters(node, types) {
|
|
132
176
|
return node.params.filter((parameter) => !types.isIdentifier(parameter, { name: "this" }));
|
|
133
177
|
}
|
|
134
|
-
function parameterInputs(path, types) {
|
|
178
|
+
function parameterInputs(path$9, types) {
|
|
135
179
|
const elements = [];
|
|
136
|
-
for (const [index, parameter] of runtimeParameters(path.node, types).entries()) {
|
|
137
|
-
if (!types.isArrowFunctionExpression(path.node)) {
|
|
180
|
+
for (const [index, parameter] of runtimeParameters(path$9.node, types).entries()) {
|
|
181
|
+
if (!types.isArrowFunctionExpression(path$9.node)) {
|
|
138
182
|
if (types.isRestElement(parameter)) elements.push(types.spreadElement(types.callExpression(types.memberExpression(types.arrayExpression([types.spreadElement(types.identifier("arguments"))]), types.identifier("slice")), [types.numericLiteral(index)])));
|
|
139
183
|
else elements.push(types.memberExpression(types.identifier("arguments"), types.numericLiteral(index), true));
|
|
140
184
|
continue;
|
|
@@ -144,11 +188,11 @@ function parameterInputs(path, types) {
|
|
|
144
188
|
}
|
|
145
189
|
return types.arrayExpression(elements);
|
|
146
190
|
}
|
|
147
|
-
function needsArgumentWrapper(path, types) {
|
|
148
|
-
return types.isArrowFunctionExpression(path.node) && path.node.params.some((parameter) => !types.isIdentifier(parameter) && !(types.isRestElement(parameter) && types.isIdentifier(parameter.argument)));
|
|
191
|
+
function needsArgumentWrapper(path$10, types) {
|
|
192
|
+
return types.isArrowFunctionExpression(path$10.node) && path$10.node.params.some((parameter) => !types.isIdentifier(parameter) && !(types.isRestElement(parameter) && types.isIdentifier(parameter.argument)));
|
|
149
193
|
}
|
|
150
|
-
function isRestWrapper(path, types) {
|
|
151
|
-
const parameters = runtimeParameters(path.node, types);
|
|
194
|
+
function isRestWrapper(path$11, types) {
|
|
195
|
+
const parameters = runtimeParameters(path$11.node, types);
|
|
152
196
|
return parameters.length === 1 && types.isRestElement(parameters[0]);
|
|
153
197
|
}
|
|
154
198
|
function isNamedMember(node, name, types) {
|
|
@@ -250,13 +294,13 @@ function recordedCallTarget(node, types) {
|
|
|
250
294
|
function isOptionalChain(node, types) {
|
|
251
295
|
return types.isOptionalMemberExpression(node) || types.isOptionalCallExpression(node);
|
|
252
296
|
}
|
|
253
|
-
function continuesOptionalChain(path, types) {
|
|
254
|
-
const parent = path.parent;
|
|
255
|
-
return types.isOptionalMemberExpression(parent) && parent.object === path.node || types.isOptionalCallExpression(parent) && parent.callee === path.node;
|
|
297
|
+
function continuesOptionalChain(path$12, types) {
|
|
298
|
+
const parent = path$12.parent;
|
|
299
|
+
return types.isOptionalMemberExpression(parent) && parent.object === path$12.node || types.isOptionalCallExpression(parent) && parent.callee === path$12.node;
|
|
256
300
|
}
|
|
257
|
-
function rewriteRecordedClientCall(path, state, types) {
|
|
301
|
+
function rewriteRecordedClientCall(path$13, state, types) {
|
|
258
302
|
if (state.skipFile || state.bamlGenerated) return;
|
|
259
|
-
const node = path.node;
|
|
303
|
+
const node = path$13.node;
|
|
260
304
|
const target = recordedCallTarget(node, types);
|
|
261
305
|
const identifier = target === null ? void 0 : state.recordedCallIdentifiers?.get(target.call.runtimeExport);
|
|
262
306
|
if (target === null || identifier === void 0) return;
|
|
@@ -264,10 +308,10 @@ function rewriteRecordedClientCall(path, state, types) {
|
|
|
264
308
|
const optionalReceiver = types.isOptionalMemberExpression(node.callee) && node.callee.optional;
|
|
265
309
|
const optionalMethod = types.isOptionalCallExpression(node) && node.optional;
|
|
266
310
|
if (types.isOptionalCallExpression(node)) {
|
|
267
|
-
if (continuesOptionalChain(path, types) || !optionalReceiver && isOptionalChain(receiver, types)) return;
|
|
311
|
+
if (continuesOptionalChain(path$13, types) || !optionalReceiver && isOptionalChain(receiver, types)) return;
|
|
268
312
|
}
|
|
269
313
|
const guarded = optionalReceiver || optionalMethod;
|
|
270
|
-
const receiverReference = guarded && !path.scope.isStatic(receiver) ? path.scope.generateDeclaredUidIdentifier(recordedCall.receiverHint) : null;
|
|
314
|
+
const receiverReference = guarded && !path$13.scope.isStatic(receiver) ? path$13.scope.generateDeclaredUidIdentifier(recordedCall.receiverHint) : null;
|
|
271
315
|
const receiverValue = () => receiverReference === null ? types.cloneNode(receiver) : types.cloneNode(receiverReference);
|
|
272
316
|
const call = types.callExpression(types.cloneNode(identifier), recordedCall.endpoint === void 0 ? [receiverValue(), ...node.arguments] : [
|
|
273
317
|
types.stringLiteral(recordedCall.endpoint),
|
|
@@ -278,14 +322,14 @@ function rewriteRecordedClientCall(path, state, types) {
|
|
|
278
322
|
state.usedRuntime = true;
|
|
279
323
|
state.usedRecordedCalls?.add(recordedCall.runtimeExport);
|
|
280
324
|
if (!guarded) {
|
|
281
|
-
path.replaceWith(call);
|
|
325
|
+
path$13.replaceWith(call);
|
|
282
326
|
return;
|
|
283
327
|
}
|
|
284
328
|
const firstReceiver = receiverReference === null ? types.cloneNode(receiver) : types.assignmentExpression("=", types.cloneNode(receiverReference), receiver);
|
|
285
329
|
const missing = (value) => types.binaryExpression("==", value, types.nullLiteral());
|
|
286
330
|
const methodOf = (value) => types.memberExpression(value, types.identifier(method));
|
|
287
331
|
const test = optionalReceiver ? optionalMethod ? types.logicalExpression("||", missing(firstReceiver), missing(methodOf(receiverValue()))) : missing(firstReceiver) : missing(methodOf(firstReceiver));
|
|
288
|
-
path.replaceWith(types.conditionalExpression(test, types.unaryExpression("void", types.numericLiteral(0)), call));
|
|
332
|
+
path$13.replaceWith(types.conditionalExpression(test, types.unaryExpression("void", types.numericLiteral(0)), call));
|
|
289
333
|
}
|
|
290
334
|
function bitfabBabelPlugin(api) {
|
|
291
335
|
const { types } = api;
|
|
@@ -293,22 +337,27 @@ function bitfabBabelPlugin(api) {
|
|
|
293
337
|
name: "bitfab-auto-trace",
|
|
294
338
|
visitor: {
|
|
295
339
|
Program: {
|
|
296
|
-
enter(path, state) {
|
|
297
|
-
state.skipFile = !shouldTransformBitfabFile(state.file.opts.filename ?? "unknown", state.opts) || path.scope.hasBinding("__bitfab_auto_trace_transformed_v1__") || path.node.directives.some((directive) => directive.value.value === "use client");
|
|
298
|
-
state.runtimeIdentifier = path.scope.generateUidIdentifier("bitfabAutoSpan");
|
|
299
|
-
state.activeIdentifier = path.scope.generateUidIdentifier("bitfabAutoTraceActive");
|
|
300
|
-
state.wrapperIdentifier = path.scope.generateUidIdentifier("bitfabAutoWrap");
|
|
301
|
-
state.recordedCallIdentifiers = new Map(RECORDED_CALL_RUNTIMES.map((call) => [call.runtimeExport, path.scope.generateUidIdentifier(call.identifierHint)]));
|
|
340
|
+
enter(path$14, state) {
|
|
341
|
+
state.skipFile = !shouldTransformBitfabFile(state.file.opts.filename ?? "unknown", state.opts) || path$14.scope.hasBinding("__bitfab_auto_trace_transformed_v1__") || path$14.node.directives.some((directive) => directive.value.value === "use client");
|
|
342
|
+
state.runtimeIdentifier = path$14.scope.generateUidIdentifier("bitfabAutoSpan");
|
|
343
|
+
state.activeIdentifier = path$14.scope.generateUidIdentifier("bitfabAutoTraceActive");
|
|
344
|
+
state.wrapperIdentifier = path$14.scope.generateUidIdentifier("bitfabAutoWrap");
|
|
345
|
+
state.recordedCallIdentifiers = new Map(RECORDED_CALL_RUNTIMES.map((call) => [call.runtimeExport, path$14.scope.generateUidIdentifier(call.identifierHint)]));
|
|
302
346
|
state.bamlGenerated = isBamlGeneratedSource(state.file.code ?? "");
|
|
303
347
|
state.definitions = [];
|
|
304
348
|
state.usedRuntime = false;
|
|
305
349
|
state.usedWrapper = false;
|
|
306
350
|
state.usedRecordedCalls = /* @__PURE__ */ new Set();
|
|
307
351
|
},
|
|
308
|
-
exit(path, state) {
|
|
352
|
+
exit(path$15, state) {
|
|
353
|
+
const bamlRegistrationModule = !state.skipFile && state.bamlGenerated && importsBamlAtRuntime(path$15.node, types) ? bamlRegistrationModuleFor(sourceFilename(state.file.opts.filename ?? ""), state.opts.bamlRegistrationModule) : null;
|
|
354
|
+
if (bamlRegistrationModule !== null) {
|
|
355
|
+
path$15.unshiftContainer("body", types.importDeclaration([], types.stringLiteral(bamlRegistrationModule)));
|
|
356
|
+
state.file.metadata[AUTO_TRACE_TRANSFORM_MARKER] = true;
|
|
357
|
+
}
|
|
309
358
|
if (state.skipFile || !state.usedRuntime || !state.runtimeIdentifier || !state.activeIdentifier || !state.wrapperIdentifier) return;
|
|
310
359
|
state.file.metadata[AUTO_TRACE_TRANSFORM_MARKER] = true;
|
|
311
|
-
path.unshiftContainer("body", [
|
|
360
|
+
path$15.unshiftContainer("body", [
|
|
312
361
|
types.importDeclaration([
|
|
313
362
|
types.importSpecifier(state.runtimeIdentifier, types.identifier("__bitfabAutoSpan")),
|
|
314
363
|
types.importSpecifier(state.activeIdentifier, types.identifier("__bitfabAutoTraceActive")),
|
|
@@ -323,30 +372,30 @@ function bitfabBabelPlugin(api) {
|
|
|
323
372
|
]);
|
|
324
373
|
}
|
|
325
374
|
},
|
|
326
|
-
CallExpression: { exit(path, state) {
|
|
375
|
+
CallExpression: { exit(path$16, state) {
|
|
327
376
|
if (state.skipFile) return;
|
|
328
|
-
if (recordedCallTarget(path.node, types) !== null) {
|
|
329
|
-
rewriteRecordedClientCall(path, state, types);
|
|
377
|
+
if (recordedCallTarget(path$16.node, types) !== null) {
|
|
378
|
+
rewriteRecordedClientCall(path$16, state, types);
|
|
330
379
|
return;
|
|
331
380
|
}
|
|
332
|
-
const configuredName = withNodeFunctionName(path, types);
|
|
381
|
+
const configuredName = withNodeFunctionName(path$16, types);
|
|
333
382
|
if (configuredName === null) return;
|
|
334
|
-
if (path.node.arguments.length === 1) path.node.arguments.push(types.identifier("undefined"));
|
|
335
|
-
path.node.arguments.push(types.stringLiteral(configuredName));
|
|
383
|
+
if (path$16.node.arguments.length === 1) path$16.node.arguments.push(types.identifier("undefined"));
|
|
384
|
+
path$16.node.arguments.push(types.stringLiteral(configuredName));
|
|
336
385
|
} },
|
|
337
|
-
OptionalCallExpression: { exit(path, state) {
|
|
338
|
-
rewriteRecordedClientCall(path, state, types);
|
|
386
|
+
OptionalCallExpression: { exit(path$17, state) {
|
|
387
|
+
rewriteRecordedClientCall(path$17, state, types);
|
|
339
388
|
} },
|
|
340
|
-
Function: { exit(path, state) {
|
|
341
|
-
const node = path.node;
|
|
342
|
-
if (state.skipFile || node._bitfabInstrumented || !isInstrumentableFunction(node, types) || isTraceDecoratorRoot(path, types) || !state.runtimeIdentifier || !state.activeIdentifier || !state.wrapperIdentifier) return;
|
|
343
|
-
const bamlMethod = state.bamlGenerated === true && isBamlClientMethod(path, types);
|
|
389
|
+
Function: { exit(path$18, state) {
|
|
390
|
+
const node = path$18.node;
|
|
391
|
+
if (state.skipFile || node._bitfabInstrumented || !isInstrumentableFunction(node, types) || isTraceDecoratorRoot(path$18, types) || !state.runtimeIdentifier || !state.activeIdentifier || !state.wrapperIdentifier) return;
|
|
392
|
+
const bamlMethod = state.bamlGenerated === true && isBamlClientMethod(path$18, types);
|
|
344
393
|
if (state.bamlGenerated && !bamlMethod) return;
|
|
345
|
-
if (isJevMethodDefinition(path, types)) return;
|
|
346
|
-
const name = qualifiedFunctionName(path, types);
|
|
394
|
+
if (isJevMethodDefinition(path$18, types)) return;
|
|
395
|
+
const name = qualifiedFunctionName(path$18, types);
|
|
347
396
|
if (name.startsWith("anonymous-")) return;
|
|
348
397
|
const normalizedFilename = autoTraceFilename(state.file.opts.filename ?? "unknown", state.opts.cwd ?? state.file.opts.cwd ?? process.cwd());
|
|
349
|
-
const { line, column } = sourcePosition(path);
|
|
398
|
+
const { line, column } = sourcePosition(path$18);
|
|
350
399
|
const definition = types.objectExpression([
|
|
351
400
|
types.objectProperty(types.identifier("id"), types.stringLiteral(autoTraceFunctionId(normalizedFilename, name))),
|
|
352
401
|
types.objectProperty(types.identifier("name"), types.stringLiteral(name)),
|
|
@@ -355,13 +404,13 @@ function bitfabBabelPlugin(api) {
|
|
|
355
404
|
types.objectProperty(types.identifier("column"), types.numericLiteral(column)),
|
|
356
405
|
...node.async ? [types.objectProperty(types.identifier("async"), types.booleanLiteral(true))] : [],
|
|
357
406
|
...bamlMethod ? [types.objectProperty(types.identifier("baml"), types.booleanLiteral(true))] : [],
|
|
358
|
-
...isRestWrapper(path, types) ? [types.objectProperty(types.identifier("wrapper"), types.booleanLiteral(true))] : []
|
|
407
|
+
...isRestWrapper(path$18, types) ? [types.objectProperty(types.identifier("wrapper"), types.booleanLiteral(true))] : []
|
|
359
408
|
]);
|
|
360
|
-
const definitionIdentifier = path.scope.getProgramParent().generateUidIdentifier("bitfabAutoDefinition");
|
|
409
|
+
const definitionIdentifier = path$18.scope.getProgramParent().generateUidIdentifier("bitfabAutoDefinition");
|
|
361
410
|
state.definitions?.push(types.variableDeclaration("const", [types.variableDeclarator(definitionIdentifier, definition)]));
|
|
362
|
-
if (needsArgumentWrapper(path, types)) {
|
|
411
|
+
if (needsArgumentWrapper(path$18, types)) {
|
|
363
412
|
node._bitfabInstrumented = true;
|
|
364
|
-
path.replaceWith(types.callExpression(types.cloneNode(state.wrapperIdentifier), [types.cloneNode(definitionIdentifier), node]));
|
|
413
|
+
path$18.replaceWith(types.callExpression(types.cloneNode(state.wrapperIdentifier), [types.cloneNode(definitionIdentifier), node]));
|
|
365
414
|
state.usedRuntime = true;
|
|
366
415
|
state.usedWrapper = true;
|
|
367
416
|
return;
|
|
@@ -369,12 +418,12 @@ function bitfabBabelPlugin(api) {
|
|
|
369
418
|
const originalBody = types.isBlockStatement(node.body) ? node.body : types.blockStatement([types.returnStatement(node.body)]);
|
|
370
419
|
const directives = originalBody.directives;
|
|
371
420
|
originalBody.directives = [];
|
|
372
|
-
const callerOptions = bamlMethod ? path.scope.generateUidIdentifier("bitfabBamlOptions") : void 0;
|
|
373
|
-
const withCollector = bamlMethod ? path.scope.generateUidIdentifier("bitfabBamlWithCollector") : void 0;
|
|
421
|
+
const callerOptions = bamlMethod ? path$18.scope.generateUidIdentifier("bitfabBamlOptions") : void 0;
|
|
422
|
+
const withCollector = bamlMethod ? path$18.scope.generateUidIdentifier("bitfabBamlWithCollector") : void 0;
|
|
374
423
|
const tracedBody = callerOptions && withCollector ? types.blockStatement([bamlOptionsDeclaration(callerOptions, withCollector, types), ...types.cloneNode(originalBody, true).body], []) : types.cloneNode(originalBody, true);
|
|
375
424
|
node.body = types.blockStatement([types.ifStatement(types.callExpression(types.cloneNode(state.activeIdentifier), []), types.blockStatement([...callerOptions ? [types.variableDeclaration("const", [types.variableDeclarator(callerOptions, types.identifier(BAML_OPTIONS_PARAMETER))])] : [], types.returnStatement(types.callExpression(types.cloneNode(state.runtimeIdentifier), [
|
|
376
425
|
types.cloneNode(definitionIdentifier),
|
|
377
|
-
parameterInputs(path, types),
|
|
426
|
+
parameterInputs(path$18, types),
|
|
378
427
|
types.arrowFunctionExpression(withCollector ? [types.cloneNode(withCollector)] : [], tracedBody, node.async ?? false)
|
|
379
428
|
]))])), ...originalBody.body], directives);
|
|
380
429
|
node._bitfabInstrumented = true;
|
|
@@ -409,4 +458,4 @@ Object.defineProperty(exports, "sourceFilename", {
|
|
|
409
458
|
}
|
|
410
459
|
});
|
|
411
460
|
|
|
412
|
-
//# sourceMappingURL=babelPlugin-
|
|
461
|
+
//# sourceMappingURL=babelPlugin-C4ERQ8DW.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"babelPlugin-C4ERQ8DW.cjs","names":["path","readFileSync","join","dirname","isAbsolute"],"sources":["../../bitfab-typescript-transform/src/transformOptions.ts","../../bitfab-typescript-transform/src/babelPlugin.ts"],"sourcesContent":["export interface BitfabTransformOptions {\n /** Module that exports the automatic span runtime. */\n runtimeModule?: string\n /** Module imported at the top of BAML's generated client files so the SDK can use the `@boundaryml/baml` the bundler loads. Pass `false` to import nothing. Defaults to `\"@bitfab/sdk/baml\"`, added only when it resolves from the file's folder. */\n bamlRegistrationModule?: string | false\n /** Working directory removed from generated function IDs. */\n cwd?: string\n /** Return false to leave a file unchanged. */\n include?: (filename: string) => boolean\n}\n\nconst AUTO_TRACE_FUNCTION_ID_VERSION = \"ts-auto-v1\"\nexport const AUTO_TRACE_TRANSFORM_MARKER =\n \"__bitfab_auto_trace_transformed_v1__\"\n\nexport function autoTraceFunctionId(file: string, name: string): string {\n return `${AUTO_TRACE_FUNCTION_ID_VERSION}:${file}#${name}`\n}\n\nexport function sourceFilename(filename: string): string {\n return filename.replace(/\\\\/g, \"/\").split(/[?#]/, 1)[0] ?? \"\"\n}\n\nexport function autoTraceFilename(filename: string, cwd: string): string {\n const normalized = sourceFilename(filename)\n const normalizedCwd = cwd.replace(/\\\\/g, \"/\").replace(/\\/$/, \"\")\n return normalized.startsWith(`${normalizedCwd}/`)\n ? normalized.slice(normalizedCwd.length + 1)\n : normalized\n}\n\nexport function shouldTransformBitfabFile(\n filename: string,\n options: BitfabTransformOptions,\n): boolean {\n if (!filename) {\n return false\n }\n if (options.include && !options.include(filename)) {\n return false\n }\n\n const normalized = sourceFilename(filename)\n const normalizedCwd = options.cwd?.replace(/\\\\/g, \"/\").replace(/\\/$/, \"\")\n const isAbsolute =\n normalized.startsWith(\"/\") || /^[A-Za-z]:\\//.test(normalized)\n if (\n normalizedCwd &&\n isAbsolute &&\n normalized !== normalizedCwd &&\n !normalized.startsWith(`${normalizedCwd}/`)\n ) {\n return false\n }\n return (\n !normalized.includes(\"/node_modules/\") &&\n !normalized.endsWith(\".d.ts\") &&\n /\\.[cm]?[jt]sx?$/.test(normalized)\n )\n}\n","import { readFileSync } from \"node:fs\"\nimport { dirname, isAbsolute, join } from \"node:path\"\nimport type { NodePath, PluginObject, PluginPass } from \"@babel/core\"\nimport type * as BabelTypes from \"@babel/types\"\nimport type { BitfabTransformOptions } from \"./transformOptions.js\"\nimport {\n AUTO_TRACE_TRANSFORM_MARKER,\n autoTraceFilename,\n autoTraceFunctionId,\n shouldTransformBitfabFile,\n sourceFilename,\n} from \"./transformOptions.js\"\n\ntype BabelTypesApi = typeof BabelTypes\n\ntype BitfabPluginOptions = BitfabTransformOptions\n\ninterface BitfabPluginState extends PluginPass {\n opts: BitfabPluginOptions\n runtimeIdentifier?: ReturnType<BabelTypesApi[\"identifier\"]>\n activeIdentifier?: ReturnType<BabelTypesApi[\"identifier\"]>\n wrapperIdentifier?: ReturnType<BabelTypesApi[\"identifier\"]>\n recordedCallIdentifiers?: Map<string, ReturnType<BabelTypesApi[\"identifier\"]>>\n definitions?: Array<ReturnType<BabelTypesApi[\"variableDeclaration\"]>>\n skipFile?: boolean\n bamlGenerated?: boolean\n usedRuntime?: boolean\n usedWrapper?: boolean\n usedRecordedCalls?: Set<string>\n}\n\ninterface InstrumentedFunction {\n _bitfabInstrumented?: boolean\n}\n\nfunction propertyName(\n node: BabelTypes.Node | null | undefined,\n types: BabelTypesApi,\n): string | null {\n if (types.isIdentifier(node)) {\n return node.name\n }\n if (types.isStringLiteral(node)) {\n return node.value\n }\n return null\n}\n\nfunction functionName(\n path: NodePath<BabelTypes.Function>,\n types: BabelTypesApi,\n): string {\n const node = path.node\n if (types.isFunctionDeclaration(node) || types.isFunctionExpression(node)) {\n if (node.id) {\n return node.id.name\n }\n }\n\n if (\n (types.isClassMethod(node) || types.isObjectMethod(node)) &&\n !node.computed &&\n types.isIdentifier(node.key)\n ) {\n return node.key.name\n }\n\n const parent = path.parentPath?.node\n if (types.isVariableDeclarator(parent)) {\n return propertyName(parent.id, types) ?? \"anonymous\"\n }\n if (types.isObjectProperty(parent) && !parent.computed) {\n return propertyName(parent.key, types) ?? \"anonymous\"\n }\n if (types.isClassProperty(parent) && !parent.computed) {\n const name = propertyName(parent.key, types)\n if (name) {\n return name\n }\n }\n\n const { line, column } = sourcePosition(path)\n return `anonymous-${line}-${column}`\n}\n\nconst JEV_METHOD = \"systemOne\"\n\nfunction isJevMethodDefinition(\n path: NodePath<BabelTypes.Function>,\n types: BabelTypesApi,\n): boolean {\n const parent = path.parentPath?.node\n const isMethod =\n types.isClassMethod(path.node) ||\n types.isObjectMethod(path.node) ||\n types.isObjectProperty(parent) ||\n types.isClassProperty(parent)\n return isMethod && functionName(path, types) === JEV_METHOD\n}\n\nfunction isInstrumentableFunction(\n node: BabelTypes.Function,\n types: BabelTypesApi,\n): boolean {\n if (node.generator || types.isClassPrivateMethod(node)) {\n return false\n }\n return (\n !(types.isClassMethod(node) || types.isObjectMethod(node)) ||\n node.kind === \"method\"\n )\n}\n\nfunction sourcePosition(path: NodePath<BabelTypes.Function>): {\n line: number\n column: number\n} {\n const exportDeclaration = path.parentPath?.isExportDeclaration()\n ? path.parentPath.node\n : undefined\n const start = (exportDeclaration ?? path.node).loc?.start\n return { line: start?.line ?? 0, column: start?.column ?? 0 }\n}\n\nfunction qualifiedFunctionName(\n path: NodePath<BabelTypes.Function>,\n types: BabelTypesApi,\n): string {\n const ownName = functionName(path, types)\n if (ownName.startsWith(\"anonymous-\")) {\n return ownName\n }\n const scopes: string[] = []\n let ancestor: NodePath | null = path.parentPath\n while (ancestor) {\n if (ancestor.isFunction()) {\n if (!isInstrumentableFunction(ancestor.node, types)) {\n ancestor = ancestor.parentPath\n continue\n }\n const name = functionName(\n ancestor as NodePath<BabelTypes.Function>,\n types,\n )\n if (!name.startsWith(\"anonymous-\")) {\n scopes.unshift(name)\n }\n } else if (\n (ancestor.isClassDeclaration() || ancestor.isClassExpression()) &&\n ancestor.node.id\n ) {\n scopes.unshift(ancestor.node.id.name)\n } else if (ancestor.isObjectExpression()) {\n const parent = ancestor.parentPath?.node\n if (types.isVariableDeclarator(parent)) {\n const name = propertyName(parent.id, types)\n if (name) {\n scopes.unshift(name)\n }\n } else if (types.isObjectProperty(parent) && !parent.computed) {\n const name = propertyName(parent.key, types)\n if (name) {\n scopes.unshift(name)\n }\n }\n }\n ancestor = ancestor.parentPath\n }\n return [...scopes, ownName].join(\".\")\n}\n\nfunction isTraceDecoratorRoot(\n path: NodePath<BabelTypes.Function>,\n types: BabelTypesApi,\n): boolean {\n const node = path.node\n const parent = path.parentPath?.node\n const decorated =\n types.isClassMethod(node) || types.isClassPrivateMethod(node)\n ? node\n : types.isClassProperty(parent) && parent.value === node\n ? parent\n : null\n if (!decorated) {\n return false\n }\n\n return (\n decorated.decorators?.some((decorator) => {\n const expression = decorator.expression\n if (!types.isCallExpression(expression)) {\n return false\n }\n const callee = expression.callee\n return (\n types.isMemberExpression(callee) &&\n !callee.computed &&\n types.isIdentifier(callee.property, { name: \"trace\" })\n )\n }) ?? false\n )\n}\n\nfunction withNodeFunctionName(\n path: NodePath<BabelTypes.CallExpression>,\n types: BabelTypesApi,\n): string | null {\n if (path.node.arguments.length > 2) {\n return null\n }\n const callee = path.node.callee\n if (\n !types.isMemberExpression(callee) ||\n callee.computed ||\n !types.isIdentifier(callee.property, { name: \"withNode\" })\n ) {\n return null\n }\n const fn = path.node.arguments[path.node.arguments.length - 1]\n if (types.isIdentifier(fn)) {\n return fn.name\n }\n if (types.isMemberExpression(fn) && !fn.computed) {\n return propertyName(fn.property, types)\n }\n if (types.isFunctionExpression(fn) && fn.id) {\n return fn.id.name\n }\n return null\n}\n\nconst BAML_GENERATED_HEADER = \"This file was generated by BAML\"\nconst BAML_CLIENT_CLASSES = new Set([\"BamlAsyncClient\", \"BamlSyncClient\"])\nconst BAML_OPTIONS_PARAMETER = \"__baml_options__\"\n\nconst BAML_PACKAGE = \"@boundaryml/baml\"\nconst DEFAULT_BAML_REGISTRATION_MODULE = \"@bitfab/sdk/baml\"\n\nfunction importsBamlAtRuntime(\n program: BabelTypes.Program,\n types: BabelTypesApi,\n): boolean {\n return program.body.some(\n (statement) =>\n types.isImportDeclaration(statement) &&\n statement.source.value === BAML_PACKAGE &&\n statement.importKind !== \"type\" &&\n statement.specifiers.some(\n (specifier) =>\n !types.isImportSpecifier(specifier) ||\n specifier.importKind !== \"type\",\n ),\n )\n}\n\nconst SDK_PACKAGE_PATH = [\"node_modules\", \"@bitfab\", \"sdk\", \"package.json\"]\nconst BAML_REGISTRATION_EXPORT = \"./baml\"\nconst sdkExportsBamlRegistrationByDirectory = new Map<string, boolean>()\n\nfunction readPackageJson(path: string): unknown {\n try {\n return JSON.parse(readFileSync(path, \"utf8\"))\n } catch {\n return undefined\n }\n}\n\nfunction exportsBamlRegistration(packageJson: unknown): boolean {\n if (typeof packageJson !== \"object\" || packageJson === null) {\n return false\n }\n const exports = (packageJson as { exports?: unknown }).exports\n return (\n typeof exports === \"object\" &&\n exports !== null &&\n BAML_REGISTRATION_EXPORT in exports\n )\n}\n\nfunction nearestSdkExportsBamlRegistration(directory: string): boolean {\n const cached = sdkExportsBamlRegistrationByDirectory.get(directory)\n if (cached !== undefined) {\n return cached\n }\n const packageJson = readPackageJson(join(directory, ...SDK_PACKAGE_PATH))\n const parent = dirname(directory)\n const exported =\n packageJson !== undefined\n ? exportsBamlRegistration(packageJson)\n : parent !== directory && nearestSdkExportsBamlRegistration(parent)\n sdkExportsBamlRegistrationByDirectory.set(directory, exported)\n return exported\n}\n\nfunction defaultRegistrationResolves(filename: string): boolean {\n return (\n isAbsolute(filename) && nearestSdkExportsBamlRegistration(dirname(filename))\n )\n}\n\nfunction bamlRegistrationModuleFor(\n filename: string,\n configured: string | false | undefined,\n): string | null {\n if (configured === false) {\n return null\n }\n if (configured !== undefined) {\n return configured\n }\n return defaultRegistrationResolves(filename)\n ? DEFAULT_BAML_REGISTRATION_MODULE\n : null\n}\n\nfunction isBamlGeneratedSource(code: string): boolean {\n return code.slice(0, 4096).includes(BAML_GENERATED_HEADER)\n}\n\nfunction isBamlClientMethod(\n path: NodePath<BabelTypes.Function>,\n types: BabelTypesApi,\n): boolean {\n const node = path.node\n if (!types.isClassMethod(node) || node.kind !== \"method\" || node.static) {\n return false\n }\n const classPath = path.parentPath?.parentPath\n if (\n !classPath ||\n !(classPath.isClassDeclaration() || classPath.isClassExpression()) ||\n !classPath.node.id ||\n !BAML_CLIENT_CLASSES.has(classPath.node.id.name)\n ) {\n return false\n }\n const parameters = runtimeParameters(node, types)\n const last = parameters[parameters.length - 1]\n return types.isIdentifier(last, { name: BAML_OPTIONS_PARAMETER })\n}\n\nfunction bamlOptionsDeclaration(\n callerOptions: BabelTypes.Identifier,\n withCollector: BabelTypes.Identifier,\n types: BabelTypesApi,\n): BabelTypes.VariableDeclaration {\n return types.variableDeclaration(\"const\", [\n types.variableDeclarator(\n types.identifier(BAML_OPTIONS_PARAMETER),\n types.conditionalExpression(\n types.binaryExpression(\n \"===\",\n types.cloneNode(withCollector),\n types.identifier(\"undefined\"),\n ),\n types.cloneNode(callerOptions),\n types.callExpression(types.cloneNode(withCollector), [\n types.cloneNode(callerOptions),\n types.memberExpression(\n types.thisExpression(),\n types.identifier(\"bamlOptions\"),\n ),\n ]),\n ),\n ),\n ])\n}\n\nfunction runtimeParameters(\n node: BabelTypes.Function,\n types: BabelTypesApi,\n): BabelTypes.Function[\"params\"] {\n return node.params.filter(\n (parameter) => !types.isIdentifier(parameter, { name: \"this\" }),\n )\n}\n\nfunction parameterInputs(\n path: NodePath<BabelTypes.Function>,\n types: BabelTypesApi,\n): ReturnType<BabelTypesApi[\"arrayExpression\"]> {\n const elements: Array<BabelTypes.Expression | BabelTypes.SpreadElement> = []\n\n for (const [index, parameter] of runtimeParameters(\n path.node,\n types,\n ).entries()) {\n if (!types.isArrowFunctionExpression(path.node)) {\n if (types.isRestElement(parameter)) {\n elements.push(\n types.spreadElement(\n types.callExpression(\n types.memberExpression(\n types.arrayExpression([\n types.spreadElement(types.identifier(\"arguments\")),\n ]),\n types.identifier(\"slice\"),\n ),\n [types.numericLiteral(index)],\n ),\n ),\n )\n } else {\n elements.push(\n types.memberExpression(\n types.identifier(\"arguments\"),\n types.numericLiteral(index),\n true,\n ),\n )\n }\n continue\n }\n\n if (types.isIdentifier(parameter)) {\n elements.push(types.identifier(parameter.name))\n } else if (\n types.isRestElement(parameter) &&\n types.isIdentifier(parameter.argument)\n ) {\n elements.push(\n types.spreadElement(types.identifier(parameter.argument.name)),\n )\n }\n }\n\n return types.arrayExpression(elements)\n}\n\nfunction needsArgumentWrapper(\n path: NodePath<BabelTypes.Function>,\n types: BabelTypesApi,\n): boolean {\n return (\n types.isArrowFunctionExpression(path.node) &&\n path.node.params.some(\n (parameter) =>\n !types.isIdentifier(parameter) &&\n !(\n types.isRestElement(parameter) &&\n types.isIdentifier(parameter.argument)\n ),\n )\n )\n}\n\nfunction isRestWrapper(\n path: NodePath<BabelTypes.Function>,\n types: BabelTypesApi,\n): boolean {\n const parameters = runtimeParameters(path.node, types)\n return parameters.length === 1 && types.isRestElement(parameters[0])\n}\n\ntype RecordedCallNode =\n | BabelTypes.CallExpression\n | BabelTypes.OptionalCallExpression\n\ninterface RecordedClientCall {\n methods: readonly string[]\n endpoint?: string\n runtimeExport: string\n identifierHint: string\n receiverHint: string\n matchesReceiver: (\n receiver: BabelTypes.Expression,\n types: BabelTypesApi,\n ) => boolean\n}\n\nfunction isNamedMember(\n node: BabelTypes.Node,\n name: string,\n types: BabelTypesApi,\n): node is BabelTypes.MemberExpression | BabelTypes.OptionalMemberExpression {\n return (\n (types.isMemberExpression(node) ||\n types.isOptionalMemberExpression(node)) &&\n !node.computed &&\n types.isIdentifier(node.property, { name })\n )\n}\n\nfunction isChatCompletionsReceiver(\n receiver: BabelTypes.Expression,\n types: BabelTypesApi,\n): boolean {\n return (\n isNamedMember(receiver, \"completions\", types) &&\n isNamedMember(receiver.object, \"chat\", types)\n )\n}\n\nfunction isMessagesReceiver(\n receiver: BabelTypes.Expression,\n types: BabelTypesApi,\n): boolean {\n return (\n isNamedMember(receiver, \"messages\", types) &&\n !isNamedMember(receiver.object, \"beta\", types)\n )\n}\n\nfunction isResponsesReceiver(\n receiver: BabelTypes.Expression,\n types: BabelTypesApi,\n): boolean {\n return isNamedMember(receiver, \"responses\", types)\n}\n\nfunction isEmbeddingsReceiver(\n receiver: BabelTypes.Expression,\n types: BabelTypesApi,\n): boolean {\n return isNamedMember(receiver, \"embeddings\", types)\n}\n\nfunction isTranscriptionsReceiver(\n receiver: BabelTypes.Expression,\n types: BabelTypesApi,\n): boolean {\n return (\n isNamedMember(receiver, \"transcriptions\", types) &&\n isNamedMember(receiver.object, \"audio\", types)\n )\n}\n\nfunction isModelsReceiver(\n receiver: BabelTypes.Expression,\n types: BabelTypesApi,\n): boolean {\n return isNamedMember(receiver, \"models\", types)\n}\n\nconst CLIENT_CALL_RUNTIME = {\n runtimeExport: \"__bitfabAutoClientCall\",\n identifierHint: \"bitfabAutoClientCall\",\n receiverHint: \"bitfabClientCallReceiver\",\n}\n\nconst RECORDED_CLIENT_CALLS: readonly RecordedClientCall[] = [\n {\n methods: [JEV_METHOD],\n runtimeExport: \"__bitfabAutoJev\",\n identifierHint: \"bitfabAutoJev\",\n receiverHint: \"bitfabJevReceiver\",\n matchesReceiver: () => true,\n },\n {\n ...CLIENT_CALL_RUNTIME,\n endpoint: \"chat.completions\",\n methods: [\"create\", \"parse\", \"stream\"],\n matchesReceiver: isChatCompletionsReceiver,\n },\n {\n ...CLIENT_CALL_RUNTIME,\n endpoint: \"embeddings\",\n methods: [\"create\"],\n matchesReceiver: isEmbeddingsReceiver,\n },\n {\n ...CLIENT_CALL_RUNTIME,\n endpoint: \"audio.transcriptions\",\n methods: [\"create\"],\n matchesReceiver: isTranscriptionsReceiver,\n },\n {\n ...CLIENT_CALL_RUNTIME,\n endpoint: \"messages\",\n methods: [\"create\", \"parse\", \"stream\"],\n matchesReceiver: isMessagesReceiver,\n },\n {\n ...CLIENT_CALL_RUNTIME,\n endpoint: \"responses\",\n methods: [\"create\", \"parse\", \"stream\"],\n matchesReceiver: isResponsesReceiver,\n },\n {\n ...CLIENT_CALL_RUNTIME,\n endpoint: \"models\",\n methods: [\"generateContent\", \"generateContentStream\"],\n matchesReceiver: isModelsReceiver,\n },\n]\n\nconst RECORDED_CALL_RUNTIMES = [\n ...new Map(\n RECORDED_CLIENT_CALLS.map((call) => [call.runtimeExport, call]),\n ).values(),\n]\n\nfunction recordedCallTarget(\n node: RecordedCallNode,\n types: BabelTypesApi,\n): {\n call: RecordedClientCall\n receiver: BabelTypes.Expression\n method: string\n} | null {\n const callee = node.callee\n if (\n !(\n types.isMemberExpression(callee) ||\n types.isOptionalMemberExpression(callee)\n ) ||\n callee.computed ||\n !types.isIdentifier(callee.property) ||\n types.isSuper(callee.object)\n ) {\n return null\n }\n const method = callee.property.name\n const receiver = callee.object\n const call = RECORDED_CLIENT_CALLS.find(\n (candidate) =>\n candidate.methods.includes(method) &&\n candidate.matchesReceiver(receiver, types),\n )\n return call === undefined ? null : { call, receiver, method }\n}\n\nfunction isOptionalChain(node: BabelTypes.Node, types: BabelTypesApi): boolean {\n return (\n types.isOptionalMemberExpression(node) ||\n types.isOptionalCallExpression(node)\n )\n}\n\nfunction continuesOptionalChain(\n path: NodePath<BabelTypes.OptionalCallExpression>,\n types: BabelTypesApi,\n): boolean {\n const parent = path.parent\n return (\n (types.isOptionalMemberExpression(parent) && parent.object === path.node) ||\n (types.isOptionalCallExpression(parent) && parent.callee === path.node)\n )\n}\n\nfunction rewriteRecordedClientCall(\n path: NodePath<RecordedCallNode>,\n state: BitfabPluginState,\n types: BabelTypesApi,\n): void {\n if (state.skipFile || state.bamlGenerated) {\n return\n }\n const node = path.node\n const target = recordedCallTarget(node, types)\n const identifier =\n target === null\n ? undefined\n : state.recordedCallIdentifiers?.get(target.call.runtimeExport)\n if (target === null || identifier === undefined) {\n return\n }\n const { call: recordedCall, receiver, method } = target\n const optionalReceiver =\n types.isOptionalMemberExpression(node.callee) && node.callee.optional\n const optionalMethod = types.isOptionalCallExpression(node) && node.optional\n if (types.isOptionalCallExpression(node)) {\n if (\n continuesOptionalChain(\n path as NodePath<BabelTypes.OptionalCallExpression>,\n types,\n ) ||\n (!optionalReceiver && isOptionalChain(receiver, types))\n ) {\n return\n }\n }\n const guarded = optionalReceiver || optionalMethod\n const receiverReference =\n guarded && !path.scope.isStatic(receiver)\n ? path.scope.generateDeclaredUidIdentifier(recordedCall.receiverHint)\n : null\n const receiverValue = (): BabelTypes.Expression =>\n receiverReference === null\n ? types.cloneNode(receiver)\n : types.cloneNode(receiverReference)\n const call = types.callExpression(\n types.cloneNode(identifier),\n recordedCall.endpoint === undefined\n ? [receiverValue(), ...node.arguments]\n : [\n types.stringLiteral(recordedCall.endpoint),\n receiverValue(),\n types.stringLiteral(method),\n ...node.arguments,\n ],\n )\n state.usedRuntime = true\n state.usedRecordedCalls?.add(recordedCall.runtimeExport)\n if (!guarded) {\n path.replaceWith(call)\n return\n }\n const firstReceiver =\n receiverReference === null\n ? types.cloneNode(receiver)\n : types.assignmentExpression(\n \"=\",\n types.cloneNode(receiverReference),\n receiver,\n )\n const missing = (value: BabelTypes.Expression): BabelTypes.BinaryExpression =>\n types.binaryExpression(\"==\", value, types.nullLiteral())\n const methodOf = (value: BabelTypes.Expression): BabelTypes.Expression =>\n types.memberExpression(value, types.identifier(method))\n const test = optionalReceiver\n ? optionalMethod\n ? types.logicalExpression(\n \"||\",\n missing(firstReceiver),\n missing(methodOf(receiverValue())),\n )\n : missing(firstReceiver)\n : missing(methodOf(firstReceiver))\n path.replaceWith(\n types.conditionalExpression(\n test,\n types.unaryExpression(\"void\", types.numericLiteral(0)),\n call,\n ),\n )\n}\n\n/**\n * Babel adapter for Bitfab's experimental automatic call-span runtime.\n *\n * @experimental The transform protocol and generated function identities may\n * change before the feature is stable.\n */\nexport default function bitfabBabelPlugin(api: {\n types: BabelTypesApi\n}): PluginObject<BitfabPluginState> {\n const { types } = api\n\n return {\n name: \"bitfab-auto-trace\",\n visitor: {\n Program: {\n enter(path: NodePath<BabelTypes.Program>, state: BitfabPluginState) {\n const filename = state.file.opts.filename ?? \"unknown\"\n state.skipFile =\n !shouldTransformBitfabFile(filename, state.opts) ||\n path.scope.hasBinding(AUTO_TRACE_TRANSFORM_MARKER) ||\n path.node.directives.some(\n (directive) => directive.value.value === \"use client\",\n )\n state.runtimeIdentifier =\n path.scope.generateUidIdentifier(\"bitfabAutoSpan\")\n state.activeIdentifier = path.scope.generateUidIdentifier(\n \"bitfabAutoTraceActive\",\n )\n state.wrapperIdentifier =\n path.scope.generateUidIdentifier(\"bitfabAutoWrap\")\n state.recordedCallIdentifiers = new Map(\n RECORDED_CALL_RUNTIMES.map((call) => [\n call.runtimeExport,\n path.scope.generateUidIdentifier(call.identifierHint),\n ]),\n )\n state.bamlGenerated = isBamlGeneratedSource(state.file.code ?? \"\")\n state.definitions = []\n state.usedRuntime = false\n state.usedWrapper = false\n state.usedRecordedCalls = new Set()\n },\n exit(path: NodePath<BabelTypes.Program>, state: BitfabPluginState) {\n const bamlRegistrationModule =\n !state.skipFile &&\n state.bamlGenerated &&\n importsBamlAtRuntime(path.node, types)\n ? bamlRegistrationModuleFor(\n sourceFilename(state.file.opts.filename ?? \"\"),\n state.opts.bamlRegistrationModule,\n )\n : null\n if (bamlRegistrationModule !== null) {\n path.unshiftContainer(\n \"body\",\n types.importDeclaration(\n [],\n types.stringLiteral(bamlRegistrationModule),\n ),\n )\n state.file.metadata[AUTO_TRACE_TRANSFORM_MARKER] = true\n }\n if (\n state.skipFile ||\n !state.usedRuntime ||\n !state.runtimeIdentifier ||\n !state.activeIdentifier ||\n !state.wrapperIdentifier\n ) {\n return\n }\n\n state.file.metadata[AUTO_TRACE_TRANSFORM_MARKER] = true\n path.unshiftContainer(\"body\", [\n types.importDeclaration(\n [\n types.importSpecifier(\n state.runtimeIdentifier,\n types.identifier(\"__bitfabAutoSpan\"),\n ),\n types.importSpecifier(\n state.activeIdentifier,\n types.identifier(\"__bitfabAutoTraceActive\"),\n ),\n ...(state.usedWrapper\n ? [\n types.importSpecifier(\n state.wrapperIdentifier,\n types.identifier(\"__bitfabAutoWrap\"),\n ),\n ]\n : []),\n ...RECORDED_CALL_RUNTIMES.flatMap((call) => {\n const identifier = state.recordedCallIdentifiers?.get(\n call.runtimeExport,\n )\n return state.usedRecordedCalls?.has(call.runtimeExport) &&\n identifier\n ? [\n types.importSpecifier(\n identifier,\n types.identifier(call.runtimeExport),\n ),\n ]\n : []\n }),\n ],\n types.stringLiteral(\n state.opts.runtimeModule ?? \"@bitfab/sdk/auto\",\n ),\n ),\n types.variableDeclaration(\"const\", [\n types.variableDeclarator(\n types.identifier(AUTO_TRACE_TRANSFORM_MARKER),\n types.assignmentExpression(\n \"=\",\n types.memberExpression(\n types.identifier(\"globalThis\"),\n types.identifier(AUTO_TRACE_TRANSFORM_MARKER),\n ),\n types.booleanLiteral(true),\n ),\n ),\n ]),\n ...(state.definitions ?? []),\n ])\n },\n },\n CallExpression: {\n exit(\n path: NodePath<BabelTypes.CallExpression>,\n state: BitfabPluginState,\n ) {\n if (state.skipFile) {\n return\n }\n if (recordedCallTarget(path.node, types) !== null) {\n rewriteRecordedClientCall(path, state, types)\n return\n }\n const configuredName = withNodeFunctionName(path, types)\n if (configuredName === null) {\n return\n }\n if (path.node.arguments.length === 1) {\n path.node.arguments.push(types.identifier(\"undefined\"))\n }\n path.node.arguments.push(types.stringLiteral(configuredName))\n },\n },\n OptionalCallExpression: {\n exit(\n path: NodePath<BabelTypes.OptionalCallExpression>,\n state: BitfabPluginState,\n ) {\n rewriteRecordedClientCall(path, state, types)\n },\n },\n Function: {\n exit(path: NodePath<BabelTypes.Function>, state: BitfabPluginState) {\n const node = path.node as typeof path.node & InstrumentedFunction\n if (\n state.skipFile ||\n node._bitfabInstrumented ||\n !isInstrumentableFunction(node, types) ||\n isTraceDecoratorRoot(path, types) ||\n !state.runtimeIdentifier ||\n !state.activeIdentifier ||\n !state.wrapperIdentifier\n ) {\n return\n }\n const bamlMethod =\n state.bamlGenerated === true && isBamlClientMethod(path, types)\n if (state.bamlGenerated && !bamlMethod) {\n return\n }\n if (isJevMethodDefinition(path, types)) {\n return\n }\n const name = qualifiedFunctionName(path, types)\n if (name.startsWith(\"anonymous-\")) {\n return\n }\n const normalizedFilename = autoTraceFilename(\n state.file.opts.filename ?? \"unknown\",\n state.opts.cwd ?? state.file.opts.cwd ?? process.cwd(),\n )\n const { line, column } = sourcePosition(path)\n const definition = types.objectExpression([\n types.objectProperty(\n types.identifier(\"id\"),\n types.stringLiteral(\n autoTraceFunctionId(normalizedFilename, name),\n ),\n ),\n types.objectProperty(\n types.identifier(\"name\"),\n types.stringLiteral(name),\n ),\n types.objectProperty(\n types.identifier(\"file\"),\n types.stringLiteral(normalizedFilename),\n ),\n types.objectProperty(\n types.identifier(\"line\"),\n types.numericLiteral(line),\n ),\n types.objectProperty(\n types.identifier(\"column\"),\n types.numericLiteral(column),\n ),\n ...(node.async\n ? [\n types.objectProperty(\n types.identifier(\"async\"),\n types.booleanLiteral(true),\n ),\n ]\n : []),\n ...(bamlMethod\n ? [\n types.objectProperty(\n types.identifier(\"baml\"),\n types.booleanLiteral(true),\n ),\n ]\n : []),\n ...(isRestWrapper(path, types)\n ? [\n types.objectProperty(\n types.identifier(\"wrapper\"),\n types.booleanLiteral(true),\n ),\n ]\n : []),\n ])\n const definitionIdentifier = path.scope\n .getProgramParent()\n .generateUidIdentifier(\"bitfabAutoDefinition\")\n state.definitions?.push(\n types.variableDeclaration(\"const\", [\n types.variableDeclarator(definitionIdentifier, definition),\n ]),\n )\n\n if (needsArgumentWrapper(path, types)) {\n node._bitfabInstrumented = true\n path.replaceWith(\n types.callExpression(types.cloneNode(state.wrapperIdentifier), [\n types.cloneNode(definitionIdentifier),\n node as BabelTypes.ArrowFunctionExpression,\n ]),\n )\n state.usedRuntime = true\n state.usedWrapper = true\n return\n }\n\n const originalBody = types.isBlockStatement(node.body)\n ? node.body\n : types.blockStatement([types.returnStatement(node.body)])\n const directives = originalBody.directives\n originalBody.directives = []\n\n const callerOptions = bamlMethod\n ? path.scope.generateUidIdentifier(\"bitfabBamlOptions\")\n : undefined\n const withCollector = bamlMethod\n ? path.scope.generateUidIdentifier(\"bitfabBamlWithCollector\")\n : undefined\n const tracedBody =\n callerOptions && withCollector\n ? types.blockStatement(\n [\n bamlOptionsDeclaration(callerOptions, withCollector, types),\n ...types.cloneNode(originalBody, true).body,\n ],\n [],\n )\n : types.cloneNode(originalBody, true)\n const body = types.blockStatement(\n [\n types.ifStatement(\n types.callExpression(\n types.cloneNode(state.activeIdentifier),\n [],\n ),\n types.blockStatement([\n ...(callerOptions\n ? [\n types.variableDeclaration(\"const\", [\n types.variableDeclarator(\n callerOptions,\n types.identifier(BAML_OPTIONS_PARAMETER),\n ),\n ]),\n ]\n : []),\n types.returnStatement(\n types.callExpression(\n types.cloneNode(state.runtimeIdentifier),\n [\n types.cloneNode(definitionIdentifier),\n parameterInputs(path, types),\n types.arrowFunctionExpression(\n withCollector ? [types.cloneNode(withCollector)] : [],\n tracedBody,\n node.async ?? false,\n ),\n ],\n ),\n ),\n ]),\n ),\n ...originalBody.body,\n ],\n directives,\n )\n node.body = body\n node._bitfabInstrumented = true\n state.usedRuntime = true\n },\n },\n },\n }\n}\n"],"mappings":";;;AAWA,MAAM,iCAAiC;AACvC,MAAa,8BACX;AAEF,SAAgB,oBAAoB,MAAc,MAAsB;CACtE,OAAO,GAAG,+BAA+B,GAAG,KAAK,GAAG;AACtD;AAEA,SAAgB,eAAe,UAA0B;CACvD,OAAO,SAAS,QAAQ,OAAO,GAAG,CAAC,CAAC,MAAM,QAAQ,CAAC,CAAC,CAAC,MAAM;AAC7D;AAEA,SAAgB,kBAAkB,UAAkB,KAAqB;CACvE,MAAM,aAAa,eAAe,QAAQ;CAC1C,MAAM,gBAAgB,IAAI,QAAQ,OAAO,GAAG,CAAC,CAAC,QAAQ,OAAO,EAAE;CAC/D,OAAO,WAAW,WAAW,GAAG,cAAc,EAAE,IAC5C,WAAW,MAAM,cAAc,SAAS,CAAC,IACzC;AACN;AAEA,SAAgB,0BACd,UACA,SACS;CACT,IAAI,CAAC,UACH,OAAO;CAET,IAAI,QAAQ,WAAW,CAAC,QAAQ,QAAQ,QAAQ,GAC9C,OAAO;CAGT,MAAM,aAAa,eAAe,QAAQ;CAC1C,MAAM,gBAAgB,QAAQ,KAAK,QAAQ,OAAO,GAAG,CAAC,CAAC,QAAQ,OAAO,EAAE;CACxE,MAAM,a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,aAAa,IAClB,GACA,UAEa;IACf,KAAK,sBAAsB;IAC3B,MAAM,cAAc;GACtB,EACF;EACF;CACF;AACF"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { dirname, isAbsolute, join } from "path";
|
|
1
3
|
//#region ../bitfab-typescript-transform/src/transformOptions.ts
|
|
2
4
|
const AUTO_TRACE_FUNCTION_ID_VERSION = "ts-auto-v1";
|
|
3
5
|
const AUTO_TRACE_TRANSFORM_MARKER = "__bitfab_auto_trace_transformed_v1__";
|
|
@@ -113,6 +115,48 @@ function withNodeFunctionName(path, types) {
|
|
|
113
115
|
const BAML_GENERATED_HEADER = "This file was generated by BAML";
|
|
114
116
|
const BAML_CLIENT_CLASSES = /* @__PURE__ */ new Set(["BamlAsyncClient", "BamlSyncClient"]);
|
|
115
117
|
const BAML_OPTIONS_PARAMETER = "__baml_options__";
|
|
118
|
+
const BAML_PACKAGE = "@boundaryml/baml";
|
|
119
|
+
const DEFAULT_BAML_REGISTRATION_MODULE = "@bitfab/sdk/baml";
|
|
120
|
+
function importsBamlAtRuntime(program, types) {
|
|
121
|
+
return program.body.some((statement) => types.isImportDeclaration(statement) && statement.source.value === BAML_PACKAGE && statement.importKind !== "type" && statement.specifiers.some((specifier) => !types.isImportSpecifier(specifier) || specifier.importKind !== "type"));
|
|
122
|
+
}
|
|
123
|
+
const SDK_PACKAGE_PATH = [
|
|
124
|
+
"node_modules",
|
|
125
|
+
"@bitfab",
|
|
126
|
+
"sdk",
|
|
127
|
+
"package.json"
|
|
128
|
+
];
|
|
129
|
+
const BAML_REGISTRATION_EXPORT = "./baml";
|
|
130
|
+
const sdkExportsBamlRegistrationByDirectory = /* @__PURE__ */ new Map();
|
|
131
|
+
function readPackageJson(path) {
|
|
132
|
+
try {
|
|
133
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
134
|
+
} catch {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function exportsBamlRegistration(packageJson) {
|
|
139
|
+
if (typeof packageJson !== "object" || packageJson === null) return false;
|
|
140
|
+
const exports = packageJson.exports;
|
|
141
|
+
return typeof exports === "object" && exports !== null && BAML_REGISTRATION_EXPORT in exports;
|
|
142
|
+
}
|
|
143
|
+
function nearestSdkExportsBamlRegistration(directory) {
|
|
144
|
+
const cached = sdkExportsBamlRegistrationByDirectory.get(directory);
|
|
145
|
+
if (cached !== void 0) return cached;
|
|
146
|
+
const packageJson = readPackageJson(join(directory, ...SDK_PACKAGE_PATH));
|
|
147
|
+
const parent = dirname(directory);
|
|
148
|
+
const exported = packageJson !== void 0 ? exportsBamlRegistration(packageJson) : parent !== directory && nearestSdkExportsBamlRegistration(parent);
|
|
149
|
+
sdkExportsBamlRegistrationByDirectory.set(directory, exported);
|
|
150
|
+
return exported;
|
|
151
|
+
}
|
|
152
|
+
function defaultRegistrationResolves(filename) {
|
|
153
|
+
return isAbsolute(filename) && nearestSdkExportsBamlRegistration(dirname(filename));
|
|
154
|
+
}
|
|
155
|
+
function bamlRegistrationModuleFor(filename, configured) {
|
|
156
|
+
if (configured === false) return null;
|
|
157
|
+
if (configured !== void 0) return configured;
|
|
158
|
+
return defaultRegistrationResolves(filename) ? DEFAULT_BAML_REGISTRATION_MODULE : null;
|
|
159
|
+
}
|
|
116
160
|
function isBamlGeneratedSource(code) {
|
|
117
161
|
return code.slice(0, 4096).includes(BAML_GENERATED_HEADER);
|
|
118
162
|
}
|
|
@@ -306,6 +350,11 @@ function bitfabBabelPlugin(api) {
|
|
|
306
350
|
state.usedRecordedCalls = /* @__PURE__ */ new Set();
|
|
307
351
|
},
|
|
308
352
|
exit(path, state) {
|
|
353
|
+
const bamlRegistrationModule = !state.skipFile && state.bamlGenerated && importsBamlAtRuntime(path.node, types) ? bamlRegistrationModuleFor(sourceFilename(state.file.opts.filename ?? ""), state.opts.bamlRegistrationModule) : null;
|
|
354
|
+
if (bamlRegistrationModule !== null) {
|
|
355
|
+
path.unshiftContainer("body", types.importDeclaration([], types.stringLiteral(bamlRegistrationModule)));
|
|
356
|
+
state.file.metadata[AUTO_TRACE_TRANSFORM_MARKER] = true;
|
|
357
|
+
}
|
|
309
358
|
if (state.skipFile || !state.usedRuntime || !state.runtimeIdentifier || !state.activeIdentifier || !state.wrapperIdentifier) return;
|
|
310
359
|
state.file.metadata[AUTO_TRACE_TRANSFORM_MARKER] = true;
|
|
311
360
|
path.unshiftContainer("body", [
|
|
@@ -386,4 +435,4 @@ function bitfabBabelPlugin(api) {
|
|
|
386
435
|
//#endregion
|
|
387
436
|
export { sourceFilename as i, AUTO_TRACE_TRANSFORM_MARKER as n, shouldTransformBitfabFile as r, bitfabBabelPlugin as t };
|
|
388
437
|
|
|
389
|
-
//# sourceMappingURL=babelPlugin-
|
|
438
|
+
//# sourceMappingURL=babelPlugin-tupc_WZS.js.map
|