@bitfab/sdk 0.65.3 → 0.65.5
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/autoTrace-CZu0BXhG.js +270 -0
- package/dist/autoTrace-CZu0BXhG.js.map +1 -0
- package/dist/autoTrace-KM9pYqk9.cjs +395 -0
- package/dist/autoTrace-KM9pYqk9.cjs.map +1 -0
- package/dist/autoTrace.cjs +15 -353
- package/dist/autoTrace.d.cts +44 -44
- package/dist/autoTrace.d.ts +44 -44
- package/dist/autoTrace.js +1 -28
- package/dist/babelPlugin-C70OxrqA.js +209 -0
- package/dist/babelPlugin-C70OxrqA.js.map +1 -0
- package/dist/babelPlugin-Nta4-VcL.cjs +232 -0
- package/dist/babelPlugin-Nta4-VcL.cjs.map +1 -0
- package/dist/http-CG1Irqxx.js +2154 -0
- package/dist/http-CG1Irqxx.js.map +1 -0
- package/dist/index-BFkAwvuc.d.cts +4410 -0
- package/dist/index-BFkAwvuc.d.ts +4410 -0
- package/dist/index.cjs +48 -12501
- package/dist/index.d.cts +2 -4426
- package/dist/index.d.ts +2 -4426
- package/dist/index.js +3 -96
- package/dist/loaderRuntime-0huddOOP.d.ts +12 -0
- package/dist/loaderRuntime-CslfDFO7.d.cts +12 -0
- package/dist/node.cjs +56 -12517
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +2 -1
- package/dist/node.d.ts +2 -1
- package/dist/node.js +10 -105
- package/dist/node.js.map +1 -1
- package/dist/registryCommand-Di8x0YoJ.js +1111 -0
- package/dist/registryCommand-Di8x0YoJ.js.map +1 -0
- package/dist/replayCli.js +49 -87
- package/dist/replayCli.js.map +1 -1
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/seedCli.js +10 -24
- package/dist/seedCli.js.map +1 -1
- package/dist/src-BRKm0P_S.cjs +8434 -0
- package/dist/src-BRKm0P_S.cjs.map +1 -0
- package/dist/src-CfFkki5l.js +6011 -0
- package/dist/src-CfFkki5l.js.map +1 -0
- package/dist/transform/babel.cjs +5 -422
- package/dist/transform/babel.d.cts +16 -16
- package/dist/transform/babel.d.ts +16 -16
- package/dist/transform/babel.js +1 -7
- package/dist/transform/bun.cjs +9 -478
- package/dist/transform/bun.cjs.map +1 -1
- package/dist/transform/bun.d.cts +5 -7
- package/dist/transform/bun.d.ts +5 -7
- package/dist/transform/bun.js +6 -11
- package/dist/transform/bun.js.map +1 -1
- package/dist/transform/esbuild.cjs +9 -478
- package/dist/transform/esbuild.cjs.map +1 -1
- package/dist/transform/esbuild.d.cts +5 -7
- package/dist/transform/esbuild.d.ts +5 -7
- package/dist/transform/esbuild.js +6 -11
- package/dist/transform/esbuild.js.map +1 -1
- package/dist/transform/loaderRuntime.cjs +85 -532
- package/dist/transform/loaderRuntime.cjs.map +1 -1
- package/dist/transform/loaderRuntime.d.cts +2 -12
- package/dist/transform/loaderRuntime.d.ts +2 -12
- package/dist/transform/loaderRuntime.js +56 -98
- package/dist/transform/loaderRuntime.js.map +1 -1
- package/dist/transform/nest.cjs +12 -481
- package/dist/transform/nest.cjs.map +1 -1
- package/dist/transform/nest.d.cts +8 -9
- package/dist/transform/nest.d.ts +8 -9
- package/dist/transform/nest.js +9 -14
- package/dist/transform/nest.js.map +1 -1
- package/dist/transform/next.cjs +56 -528
- package/dist/transform/next.cjs.map +1 -1
- package/dist/transform/next.d.cts +25 -25
- package/dist/transform/next.d.ts +24 -24
- package/dist/transform/next.js +52 -60
- package/dist/transform/next.js.map +1 -1
- package/dist/transform/nodeLoader.js +260 -506
- package/dist/transform/nodeLoader.js.map +1 -1
- package/dist/transform/register.js +4 -1
- package/dist/transform/register.js.map +1 -1
- package/dist/transform/rolldown.cjs +9 -478
- package/dist/transform/rolldown.cjs.map +1 -1
- package/dist/transform/rolldown.d.cts +5 -7
- package/dist/transform/rolldown.d.ts +5 -7
- package/dist/transform/rolldown.js +6 -11
- package/dist/transform/rolldown.js.map +1 -1
- package/dist/transform/rollup.cjs +9 -478
- package/dist/transform/rollup.cjs.map +1 -1
- package/dist/transform/rollup.d.cts +5 -7
- package/dist/transform/rollup.d.ts +5 -7
- package/dist/transform/rollup.js +6 -11
- package/dist/transform/rollup.js.map +1 -1
- package/dist/transform/rsbuild.cjs +9 -478
- package/dist/transform/rsbuild.cjs.map +1 -1
- package/dist/transform/rsbuild.d.cts +5 -7
- package/dist/transform/rsbuild.d.ts +5 -7
- package/dist/transform/rsbuild.js +6 -11
- package/dist/transform/rsbuild.js.map +1 -1
- package/dist/transform/rspack.cjs +9 -478
- package/dist/transform/rspack.cjs.map +1 -1
- package/dist/transform/rspack.d.cts +5 -7
- package/dist/transform/rspack.d.ts +5 -7
- package/dist/transform/rspack.js +6 -11
- package/dist/transform/rspack.js.map +1 -1
- package/dist/transform/swc.cjs +18 -486
- package/dist/transform/swc.cjs.map +1 -1
- package/dist/transform/swc.d.cts +15 -14
- package/dist/transform/swc.d.ts +15 -14
- package/dist/transform/swc.js +14 -32
- package/dist/transform/swc.js.map +1 -1
- package/dist/transform/unplugin.cjs +20 -476
- package/dist/transform/unplugin.cjs.map +1 -1
- package/dist/transform/unplugin.d.cts +4 -6
- package/dist/transform/unplugin.d.ts +4 -6
- package/dist/transform/unplugin.js +19 -8
- package/dist/transform/unplugin.js.map +1 -1
- package/dist/transform/vite.cjs +9 -478
- package/dist/transform/vite.cjs.map +1 -1
- package/dist/transform/vite.d.cts +5 -7
- package/dist/transform/vite.d.ts +5 -7
- package/dist/transform/vite.js +6 -11
- package/dist/transform/vite.js.map +1 -1
- package/dist/transform/webpack.cjs +9 -478
- package/dist/transform/webpack.cjs.map +1 -1
- package/dist/transform/webpack.d.cts +5 -7
- package/dist/transform/webpack.d.ts +5 -7
- package/dist/transform/webpack.js +6 -11
- package/dist/transform/webpack.js.map +1 -1
- package/dist/transform-BcyUocwm.js +36 -0
- package/dist/transform-BcyUocwm.js.map +1 -0
- package/dist/transform-BjxHGGKc.cjs +47 -0
- package/dist/transform-BjxHGGKc.cjs.map +1 -0
- package/dist/transformOptions-BsjCELkh.d.cts +11 -0
- package/dist/transformOptions-BsjCELkh.d.ts +11 -0
- package/package.json +5 -5
- package/dist/autoTrace.cjs.map +0 -1
- package/dist/autoTrace.js.map +0 -1
- package/dist/chunk-BRMGNMDO.js +0 -1176
- package/dist/chunk-BRMGNMDO.js.map +0 -1
- package/dist/chunk-CLP2L5PU.js +0 -2547
- package/dist/chunk-CLP2L5PU.js.map +0 -1
- package/dist/chunk-HLH7TN2A.js +0 -2060
- package/dist/chunk-HLH7TN2A.js.map +0 -1
- package/dist/chunk-LCV2JYXL.js +0 -2979
- package/dist/chunk-LCV2JYXL.js.map +0 -1
- package/dist/chunk-MT36GJMW.js +0 -106
- package/dist/chunk-MT36GJMW.js.map +0 -1
- package/dist/chunk-NRE5CJPR.js +0 -6874
- package/dist/chunk-NRE5CJPR.js.map +0 -1
- package/dist/chunk-PTCLRG4E.js +0 -28
- package/dist/chunk-PTCLRG4E.js.map +0 -1
- package/dist/chunk-QRNHRY7F.js +0 -270
- package/dist/chunk-QRNHRY7F.js.map +0 -1
- package/dist/chunk-YVJAOGHE.js +0 -45
- package/dist/chunk-YVJAOGHE.js.map +0 -1
- package/dist/chunk-Z26K57WZ.js +0 -1912
- package/dist/chunk-Z26K57WZ.js.map +0 -1
- package/dist/chunk-ZG6SHKEF.js +0 -404
- package/dist/chunk-ZG6SHKEF.js.map +0 -1
- package/dist/http-VN52X47M.js +0 -24
- package/dist/http-VN52X47M.js.map +0 -1
- package/dist/http-WP4YPPKC.js +0 -23
- package/dist/http-WP4YPPKC.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/replay-463SEV53.js +0 -28
- package/dist/replay-463SEV53.js.map +0 -1
- package/dist/replay-OT4A4HVF.js +0 -29
- package/dist/replay-OT4A4HVF.js.map +0 -1
- package/dist/transform/babel.cjs.map +0 -1
- package/dist/transform/babel.js.map +0 -1
- package/dist/transformOptions-Df2_Chtc.d.cts +0 -10
- package/dist/transformOptions-Df2_Chtc.d.ts +0 -10
|
@@ -1,564 +1,318 @@
|
|
|
1
|
-
// ../bitfab-typescript-transform/src/nodeLoader.ts
|
|
2
|
-
import { readFile } from "fs/promises";
|
|
3
1
|
import { createRequire } from "module";
|
|
4
|
-
import {
|
|
2
|
+
import { readFile } from "fs/promises";
|
|
3
|
+
import { dirname, isAbsolute, relative, resolve as resolve$1 } from "path";
|
|
5
4
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
6
|
-
|
|
7
|
-
// ../bitfab-typescript-transform/src/loaderRuntime.ts
|
|
8
|
-
import { dirname } from "path";
|
|
9
|
-
import {
|
|
10
|
-
transformFromAstSync,
|
|
11
|
-
transformSync as transformSync2
|
|
12
|
-
} from "@babel/core";
|
|
5
|
+
import { transformFromAstSync, transformSync } from "@babel/core";
|
|
13
6
|
import decoratorsPlugin from "@babel/plugin-proposal-decorators";
|
|
14
7
|
import commonJsPlugin from "@babel/plugin-transform-modules-commonjs";
|
|
15
8
|
import reactJsxPlugin from "@babel/plugin-transform-react-jsx";
|
|
16
9
|
import typeScriptPlugin from "@babel/plugin-transform-typescript";
|
|
17
10
|
import { getTsconfig, parseTsconfig } from "get-tsconfig";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var AUTO_TRACE_TRANSFORM_MARKER = "__bitfab_auto_trace_transformed_v1__";
|
|
11
|
+
//#region ../bitfab-typescript-transform/src/transformOptions.ts
|
|
12
|
+
const AUTO_TRACE_FUNCTION_ID_VERSION = "ts-auto-v1";
|
|
13
|
+
const AUTO_TRACE_TRANSFORM_MARKER = "__bitfab_auto_trace_transformed_v1__";
|
|
22
14
|
function autoTraceFunctionId(file, name) {
|
|
23
|
-
|
|
15
|
+
return `${AUTO_TRACE_FUNCTION_ID_VERSION}:${file}#${name}`;
|
|
24
16
|
}
|
|
25
17
|
function sourceFilename(filename) {
|
|
26
|
-
|
|
18
|
+
return filename.replace(/\\/g, "/").split(/[?#]/, 1)[0] ?? "";
|
|
27
19
|
}
|
|
28
20
|
function autoTraceFilename(filename, cwd) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
const normalized = sourceFilename(filename);
|
|
22
|
+
const normalizedCwd = cwd.replace(/\\/g, "/").replace(/\/$/, "");
|
|
23
|
+
return normalized.startsWith(`${normalizedCwd}/`) ? normalized.slice(normalizedCwd.length + 1) : normalized;
|
|
32
24
|
}
|
|
33
25
|
function shouldTransformBitfabFile(filename, options) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const normalizedCwd = options.cwd?.replace(/\\/g, "/").replace(/\/$/, "");
|
|
42
|
-
const isAbsolute2 = normalized.startsWith("/") || /^[A-Za-z]:\//.test(normalized);
|
|
43
|
-
if (normalizedCwd && isAbsolute2 && normalized !== normalizedCwd && !normalized.startsWith(`${normalizedCwd}/`)) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
return !normalized.includes("/node_modules/") && !normalized.endsWith(".d.ts") && /\.[cm]?[jt]sx?$/.test(normalized);
|
|
26
|
+
if (!filename) return false;
|
|
27
|
+
if (options.include && !options.include(filename)) return false;
|
|
28
|
+
const normalized = sourceFilename(filename);
|
|
29
|
+
const normalizedCwd = options.cwd?.replace(/\\/g, "/").replace(/\/$/, "");
|
|
30
|
+
const isAbsolute = normalized.startsWith("/") || /^[A-Za-z]:\//.test(normalized);
|
|
31
|
+
if (normalizedCwd && isAbsolute && normalized !== normalizedCwd && !normalized.startsWith(`${normalizedCwd}/`)) return false;
|
|
32
|
+
return !normalized.includes("/node_modules/") && !normalized.endsWith(".d.ts") && /\.[cm]?[jt]sx?$/.test(normalized);
|
|
47
33
|
}
|
|
48
|
-
|
|
49
|
-
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region ../bitfab-typescript-transform/src/babelPlugin.ts
|
|
50
36
|
function propertyName(node, types) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (types.isStringLiteral(node)) {
|
|
55
|
-
return node.value;
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
37
|
+
if (types.isIdentifier(node)) return node.name;
|
|
38
|
+
if (types.isStringLiteral(node)) return node.value;
|
|
39
|
+
return null;
|
|
58
40
|
}
|
|
59
41
|
function functionName(path, types) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return propertyName(parent.key, types) ?? "anonymous";
|
|
75
|
-
}
|
|
76
|
-
if (types.isClassProperty(parent) && !parent.computed) {
|
|
77
|
-
const name = propertyName(parent.key, types);
|
|
78
|
-
if (name) {
|
|
79
|
-
return name;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const { line, column } = sourcePosition(path);
|
|
83
|
-
return `anonymous-${line}-${column}`;
|
|
42
|
+
const node = path.node;
|
|
43
|
+
if (types.isFunctionDeclaration(node) || types.isFunctionExpression(node)) {
|
|
44
|
+
if (node.id) return node.id.name;
|
|
45
|
+
}
|
|
46
|
+
if ((types.isClassMethod(node) || types.isObjectMethod(node)) && !node.computed && types.isIdentifier(node.key)) return node.key.name;
|
|
47
|
+
const parent = path.parentPath?.node;
|
|
48
|
+
if (types.isVariableDeclarator(parent)) return propertyName(parent.id, types) ?? "anonymous";
|
|
49
|
+
if (types.isObjectProperty(parent) && !parent.computed) return propertyName(parent.key, types) ?? "anonymous";
|
|
50
|
+
if (types.isClassProperty(parent) && !parent.computed) {
|
|
51
|
+
const name = propertyName(parent.key, types);
|
|
52
|
+
if (name) return name;
|
|
53
|
+
}
|
|
54
|
+
const { line, column } = sourcePosition(path);
|
|
55
|
+
return `anonymous-${line}-${column}`;
|
|
84
56
|
}
|
|
85
57
|
function isInstrumentableFunction(node, types) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
return !(types.isClassMethod(node) || types.isObjectMethod(node)) || node.kind === "method";
|
|
58
|
+
if (node.generator || types.isClassPrivateMethod(node)) return false;
|
|
59
|
+
return !(types.isClassMethod(node) || types.isObjectMethod(node)) || node.kind === "method";
|
|
90
60
|
}
|
|
91
61
|
function sourcePosition(path) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
62
|
+
const start = ((path.parentPath?.isExportDeclaration() ? path.parentPath.node : void 0) ?? path.node).loc?.start;
|
|
63
|
+
return {
|
|
64
|
+
line: start?.line ?? 0,
|
|
65
|
+
column: start?.column ?? 0
|
|
66
|
+
};
|
|
95
67
|
}
|
|
96
68
|
function qualifiedFunctionName(path, types) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
scopes.unshift(name);
|
|
124
|
-
}
|
|
125
|
-
} else if (types.isObjectProperty(parent) && !parent.computed) {
|
|
126
|
-
const name = propertyName(parent.key, types);
|
|
127
|
-
if (name) {
|
|
128
|
-
scopes.unshift(name);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
ancestor = ancestor.parentPath;
|
|
133
|
-
}
|
|
134
|
-
return [...scopes, ownName].join(".");
|
|
69
|
+
const ownName = functionName(path, types);
|
|
70
|
+
if (ownName.startsWith("anonymous-")) return ownName;
|
|
71
|
+
const scopes = [];
|
|
72
|
+
let ancestor = path.parentPath;
|
|
73
|
+
while (ancestor) {
|
|
74
|
+
if (ancestor.isFunction()) {
|
|
75
|
+
if (!isInstrumentableFunction(ancestor.node, types)) {
|
|
76
|
+
ancestor = ancestor.parentPath;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const name = functionName(ancestor, types);
|
|
80
|
+
if (!name.startsWith("anonymous-")) scopes.unshift(name);
|
|
81
|
+
} else if ((ancestor.isClassDeclaration() || ancestor.isClassExpression()) && ancestor.node.id) scopes.unshift(ancestor.node.id.name);
|
|
82
|
+
else if (ancestor.isObjectExpression()) {
|
|
83
|
+
const parent = ancestor.parentPath?.node;
|
|
84
|
+
if (types.isVariableDeclarator(parent)) {
|
|
85
|
+
const name = propertyName(parent.id, types);
|
|
86
|
+
if (name) scopes.unshift(name);
|
|
87
|
+
} else if (types.isObjectProperty(parent) && !parent.computed) {
|
|
88
|
+
const name = propertyName(parent.key, types);
|
|
89
|
+
if (name) scopes.unshift(name);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
ancestor = ancestor.parentPath;
|
|
93
|
+
}
|
|
94
|
+
return [...scopes, ownName].join(".");
|
|
135
95
|
}
|
|
136
96
|
function isTraceDecoratorRoot(path, types) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
const callee = expression.callee;
|
|
149
|
-
return types.isMemberExpression(callee) && !callee.computed && types.isIdentifier(callee.property, { name: "trace" });
|
|
150
|
-
}) ?? false;
|
|
97
|
+
const node = path.node;
|
|
98
|
+
const parent = path.parentPath?.node;
|
|
99
|
+
const decorated = types.isClassMethod(node) || types.isClassPrivateMethod(node) ? node : types.isClassProperty(parent) && parent.value === node ? parent : null;
|
|
100
|
+
if (!decorated) return false;
|
|
101
|
+
return decorated.decorators?.some((decorator) => {
|
|
102
|
+
const expression = decorator.expression;
|
|
103
|
+
if (!types.isCallExpression(expression)) return false;
|
|
104
|
+
const callee = expression.callee;
|
|
105
|
+
return types.isMemberExpression(callee) && !callee.computed && types.isIdentifier(callee.property, { name: "trace" });
|
|
106
|
+
}) ?? false;
|
|
151
107
|
}
|
|
152
108
|
function withNodeFunctionName(path, types) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (types.isIdentifier(fn)) {
|
|
162
|
-
return fn.name;
|
|
163
|
-
}
|
|
164
|
-
if (types.isMemberExpression(fn) && !fn.computed) {
|
|
165
|
-
return propertyName(fn.property, types);
|
|
166
|
-
}
|
|
167
|
-
if (types.isFunctionExpression(fn) && fn.id) {
|
|
168
|
-
return fn.id.name;
|
|
169
|
-
}
|
|
170
|
-
return null;
|
|
109
|
+
if (path.node.arguments.length > 2) return null;
|
|
110
|
+
const callee = path.node.callee;
|
|
111
|
+
if (!types.isMemberExpression(callee) || callee.computed || !types.isIdentifier(callee.property, { name: "withNode" })) return null;
|
|
112
|
+
const fn = path.node.arguments[path.node.arguments.length - 1];
|
|
113
|
+
if (types.isIdentifier(fn)) return fn.name;
|
|
114
|
+
if (types.isMemberExpression(fn) && !fn.computed) return propertyName(fn.property, types);
|
|
115
|
+
if (types.isFunctionExpression(fn) && fn.id) return fn.id.name;
|
|
116
|
+
return null;
|
|
171
117
|
}
|
|
172
118
|
function runtimeParameters(node, types) {
|
|
173
|
-
|
|
174
|
-
(parameter) => !types.isIdentifier(parameter, { name: "this" })
|
|
175
|
-
);
|
|
119
|
+
return node.params.filter((parameter) => !types.isIdentifier(parameter, { name: "this" }));
|
|
176
120
|
}
|
|
177
121
|
function parameterInputs(path, types) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
types.arrayExpression([
|
|
190
|
-
types.spreadElement(types.identifier("arguments"))
|
|
191
|
-
]),
|
|
192
|
-
types.identifier("slice")
|
|
193
|
-
),
|
|
194
|
-
[types.numericLiteral(index)]
|
|
195
|
-
)
|
|
196
|
-
)
|
|
197
|
-
);
|
|
198
|
-
} else {
|
|
199
|
-
elements.push(
|
|
200
|
-
types.memberExpression(
|
|
201
|
-
types.identifier("arguments"),
|
|
202
|
-
types.numericLiteral(index),
|
|
203
|
-
true
|
|
204
|
-
)
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
if (types.isIdentifier(parameter)) {
|
|
210
|
-
elements.push(types.identifier(parameter.name));
|
|
211
|
-
} else if (types.isRestElement(parameter) && types.isIdentifier(parameter.argument)) {
|
|
212
|
-
elements.push(
|
|
213
|
-
types.spreadElement(types.identifier(parameter.argument.name))
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return types.arrayExpression(elements);
|
|
122
|
+
const elements = [];
|
|
123
|
+
for (const [index, parameter] of runtimeParameters(path.node, types).entries()) {
|
|
124
|
+
if (!types.isArrowFunctionExpression(path.node)) {
|
|
125
|
+
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)])));
|
|
126
|
+
else elements.push(types.memberExpression(types.identifier("arguments"), types.numericLiteral(index), true));
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (types.isIdentifier(parameter)) elements.push(types.identifier(parameter.name));
|
|
130
|
+
else if (types.isRestElement(parameter) && types.isIdentifier(parameter.argument)) elements.push(types.spreadElement(types.identifier(parameter.argument.name)));
|
|
131
|
+
}
|
|
132
|
+
return types.arrayExpression(elements);
|
|
218
133
|
}
|
|
219
134
|
function needsArgumentWrapper(path, types) {
|
|
220
|
-
|
|
221
|
-
(parameter) => !types.isIdentifier(parameter) && !(types.isRestElement(parameter) && types.isIdentifier(parameter.argument))
|
|
222
|
-
);
|
|
135
|
+
return types.isArrowFunctionExpression(path.node) && path.node.params.some((parameter) => !types.isIdentifier(parameter) && !(types.isRestElement(parameter) && types.isIdentifier(parameter.argument)));
|
|
223
136
|
}
|
|
224
137
|
function isRestWrapper(path, types) {
|
|
225
|
-
|
|
226
|
-
|
|
138
|
+
const parameters = runtimeParameters(path.node, types);
|
|
139
|
+
return parameters.length === 1 && types.isRestElement(parameters[0]);
|
|
227
140
|
}
|
|
228
141
|
function bitfabBabelPlugin(api) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
path.node.arguments.push(types.identifier("undefined"));
|
|
303
|
-
}
|
|
304
|
-
path.node.arguments.push(types.stringLiteral(configuredName));
|
|
305
|
-
}
|
|
306
|
-
},
|
|
307
|
-
Function: {
|
|
308
|
-
exit(path, state) {
|
|
309
|
-
const node = path.node;
|
|
310
|
-
if (state.skipFile || node._bitfabInstrumented || !isInstrumentableFunction(node, types) || isTraceDecoratorRoot(path, types) || !state.runtimeIdentifier || !state.activeIdentifier || !state.wrapperIdentifier) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
const name = qualifiedFunctionName(path, types);
|
|
314
|
-
if (name.startsWith("anonymous-")) {
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
const normalizedFilename = autoTraceFilename(
|
|
318
|
-
state.file.opts.filename ?? "unknown",
|
|
319
|
-
state.opts.cwd ?? state.file.opts.cwd ?? process.cwd()
|
|
320
|
-
);
|
|
321
|
-
const { line, column } = sourcePosition(path);
|
|
322
|
-
const definition = types.objectExpression([
|
|
323
|
-
types.objectProperty(
|
|
324
|
-
types.identifier("id"),
|
|
325
|
-
types.stringLiteral(
|
|
326
|
-
autoTraceFunctionId(normalizedFilename, name)
|
|
327
|
-
)
|
|
328
|
-
),
|
|
329
|
-
types.objectProperty(
|
|
330
|
-
types.identifier("name"),
|
|
331
|
-
types.stringLiteral(name)
|
|
332
|
-
),
|
|
333
|
-
types.objectProperty(
|
|
334
|
-
types.identifier("file"),
|
|
335
|
-
types.stringLiteral(normalizedFilename)
|
|
336
|
-
),
|
|
337
|
-
types.objectProperty(
|
|
338
|
-
types.identifier("line"),
|
|
339
|
-
types.numericLiteral(line)
|
|
340
|
-
),
|
|
341
|
-
types.objectProperty(
|
|
342
|
-
types.identifier("column"),
|
|
343
|
-
types.numericLiteral(column)
|
|
344
|
-
),
|
|
345
|
-
...node.async ? [
|
|
346
|
-
types.objectProperty(
|
|
347
|
-
types.identifier("async"),
|
|
348
|
-
types.booleanLiteral(true)
|
|
349
|
-
)
|
|
350
|
-
] : [],
|
|
351
|
-
...isRestWrapper(path, types) ? [
|
|
352
|
-
types.objectProperty(
|
|
353
|
-
types.identifier("wrapper"),
|
|
354
|
-
types.booleanLiteral(true)
|
|
355
|
-
)
|
|
356
|
-
] : []
|
|
357
|
-
]);
|
|
358
|
-
const definitionIdentifier = path.scope.getProgramParent().generateUidIdentifier("bitfabAutoDefinition");
|
|
359
|
-
state.definitions?.push(
|
|
360
|
-
types.variableDeclaration("const", [
|
|
361
|
-
types.variableDeclarator(definitionIdentifier, definition)
|
|
362
|
-
])
|
|
363
|
-
);
|
|
364
|
-
if (needsArgumentWrapper(path, types)) {
|
|
365
|
-
node._bitfabInstrumented = true;
|
|
366
|
-
path.replaceWith(
|
|
367
|
-
types.callExpression(types.cloneNode(state.wrapperIdentifier), [
|
|
368
|
-
types.cloneNode(definitionIdentifier),
|
|
369
|
-
node
|
|
370
|
-
])
|
|
371
|
-
);
|
|
372
|
-
state.usedRuntime = true;
|
|
373
|
-
state.usedWrapper = true;
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
const originalBody = types.isBlockStatement(node.body) ? node.body : types.blockStatement([types.returnStatement(node.body)]);
|
|
377
|
-
const directives = originalBody.directives;
|
|
378
|
-
originalBody.directives = [];
|
|
379
|
-
const body = types.blockStatement(
|
|
380
|
-
[
|
|
381
|
-
types.ifStatement(
|
|
382
|
-
types.callExpression(
|
|
383
|
-
types.cloneNode(state.activeIdentifier),
|
|
384
|
-
[]
|
|
385
|
-
),
|
|
386
|
-
types.blockStatement([
|
|
387
|
-
types.returnStatement(
|
|
388
|
-
types.callExpression(
|
|
389
|
-
types.cloneNode(state.runtimeIdentifier),
|
|
390
|
-
[
|
|
391
|
-
types.cloneNode(definitionIdentifier),
|
|
392
|
-
parameterInputs(path, types),
|
|
393
|
-
types.arrowFunctionExpression(
|
|
394
|
-
[],
|
|
395
|
-
types.cloneNode(originalBody, true),
|
|
396
|
-
node.async ?? false
|
|
397
|
-
)
|
|
398
|
-
]
|
|
399
|
-
)
|
|
400
|
-
)
|
|
401
|
-
])
|
|
402
|
-
),
|
|
403
|
-
...originalBody.body
|
|
404
|
-
],
|
|
405
|
-
directives
|
|
406
|
-
);
|
|
407
|
-
node.body = body;
|
|
408
|
-
node._bitfabInstrumented = true;
|
|
409
|
-
state.usedRuntime = true;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
};
|
|
142
|
+
const { types } = api;
|
|
143
|
+
return {
|
|
144
|
+
name: "bitfab-auto-trace",
|
|
145
|
+
visitor: {
|
|
146
|
+
Program: {
|
|
147
|
+
enter(path, state) {
|
|
148
|
+
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");
|
|
149
|
+
state.runtimeIdentifier = path.scope.generateUidIdentifier("bitfabAutoSpan");
|
|
150
|
+
state.activeIdentifier = path.scope.generateUidIdentifier("bitfabAutoTraceActive");
|
|
151
|
+
state.wrapperIdentifier = path.scope.generateUidIdentifier("bitfabAutoWrap");
|
|
152
|
+
state.definitions = [];
|
|
153
|
+
state.usedRuntime = false;
|
|
154
|
+
state.usedWrapper = false;
|
|
155
|
+
},
|
|
156
|
+
exit(path, state) {
|
|
157
|
+
if (state.skipFile || !state.usedRuntime || !state.runtimeIdentifier || !state.activeIdentifier || !state.wrapperIdentifier) return;
|
|
158
|
+
state.file.metadata[AUTO_TRACE_TRANSFORM_MARKER] = true;
|
|
159
|
+
path.unshiftContainer("body", [
|
|
160
|
+
types.importDeclaration([
|
|
161
|
+
types.importSpecifier(state.runtimeIdentifier, types.identifier("__bitfabAutoSpan")),
|
|
162
|
+
types.importSpecifier(state.activeIdentifier, types.identifier("__bitfabAutoTraceActive")),
|
|
163
|
+
...state.usedWrapper ? [types.importSpecifier(state.wrapperIdentifier, types.identifier("__bitfabAutoWrap"))] : []
|
|
164
|
+
], types.stringLiteral(state.opts.runtimeModule ?? "@bitfab/sdk/auto")),
|
|
165
|
+
types.variableDeclaration("const", [types.variableDeclarator(types.identifier(AUTO_TRACE_TRANSFORM_MARKER), types.assignmentExpression("=", types.memberExpression(types.identifier("globalThis"), types.identifier(AUTO_TRACE_TRANSFORM_MARKER)), types.booleanLiteral(true)))]),
|
|
166
|
+
...state.definitions ?? []
|
|
167
|
+
]);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
CallExpression: { exit(path, state) {
|
|
171
|
+
if (state.skipFile) return;
|
|
172
|
+
const configuredName = withNodeFunctionName(path, types);
|
|
173
|
+
if (configuredName === null) return;
|
|
174
|
+
if (path.node.arguments.length === 1) path.node.arguments.push(types.identifier("undefined"));
|
|
175
|
+
path.node.arguments.push(types.stringLiteral(configuredName));
|
|
176
|
+
} },
|
|
177
|
+
Function: { exit(path, state) {
|
|
178
|
+
const node = path.node;
|
|
179
|
+
if (state.skipFile || node._bitfabInstrumented || !isInstrumentableFunction(node, types) || isTraceDecoratorRoot(path, types) || !state.runtimeIdentifier || !state.activeIdentifier || !state.wrapperIdentifier) return;
|
|
180
|
+
const name = qualifiedFunctionName(path, types);
|
|
181
|
+
if (name.startsWith("anonymous-")) return;
|
|
182
|
+
const normalizedFilename = autoTraceFilename(state.file.opts.filename ?? "unknown", state.opts.cwd ?? state.file.opts.cwd ?? process.cwd());
|
|
183
|
+
const { line, column } = sourcePosition(path);
|
|
184
|
+
const definition = types.objectExpression([
|
|
185
|
+
types.objectProperty(types.identifier("id"), types.stringLiteral(autoTraceFunctionId(normalizedFilename, name))),
|
|
186
|
+
types.objectProperty(types.identifier("name"), types.stringLiteral(name)),
|
|
187
|
+
types.objectProperty(types.identifier("file"), types.stringLiteral(normalizedFilename)),
|
|
188
|
+
types.objectProperty(types.identifier("line"), types.numericLiteral(line)),
|
|
189
|
+
types.objectProperty(types.identifier("column"), types.numericLiteral(column)),
|
|
190
|
+
...node.async ? [types.objectProperty(types.identifier("async"), types.booleanLiteral(true))] : [],
|
|
191
|
+
...isRestWrapper(path, types) ? [types.objectProperty(types.identifier("wrapper"), types.booleanLiteral(true))] : []
|
|
192
|
+
]);
|
|
193
|
+
const definitionIdentifier = path.scope.getProgramParent().generateUidIdentifier("bitfabAutoDefinition");
|
|
194
|
+
state.definitions?.push(types.variableDeclaration("const", [types.variableDeclarator(definitionIdentifier, definition)]));
|
|
195
|
+
if (needsArgumentWrapper(path, types)) {
|
|
196
|
+
node._bitfabInstrumented = true;
|
|
197
|
+
path.replaceWith(types.callExpression(types.cloneNode(state.wrapperIdentifier), [types.cloneNode(definitionIdentifier), node]));
|
|
198
|
+
state.usedRuntime = true;
|
|
199
|
+
state.usedWrapper = true;
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const originalBody = types.isBlockStatement(node.body) ? node.body : types.blockStatement([types.returnStatement(node.body)]);
|
|
203
|
+
const directives = originalBody.directives;
|
|
204
|
+
originalBody.directives = [];
|
|
205
|
+
node.body = types.blockStatement([types.ifStatement(types.callExpression(types.cloneNode(state.activeIdentifier), []), types.blockStatement([types.returnStatement(types.callExpression(types.cloneNode(state.runtimeIdentifier), [
|
|
206
|
+
types.cloneNode(definitionIdentifier),
|
|
207
|
+
parameterInputs(path, types),
|
|
208
|
+
types.arrowFunctionExpression([], types.cloneNode(originalBody, true), node.async ?? false)
|
|
209
|
+
]))])), ...originalBody.body], directives);
|
|
210
|
+
node._bitfabInstrumented = true;
|
|
211
|
+
state.usedRuntime = true;
|
|
212
|
+
} }
|
|
213
|
+
}
|
|
214
|
+
};
|
|
414
215
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
import { transformSync } from "@babel/core";
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region ../bitfab-typescript-transform/src/transform.ts
|
|
418
218
|
function parserPlugins(filename) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
219
|
+
const path = sourceFilename(filename);
|
|
220
|
+
const typescript = /\.[cm]?tsx?$/.test(path);
|
|
221
|
+
const jsx = /\.tsx$/.test(path) || /\.[cm]?jsx?$/.test(path);
|
|
222
|
+
return [
|
|
223
|
+
...typescript ? ["typescript"] : [],
|
|
224
|
+
...jsx ? ["jsx"] : [],
|
|
225
|
+
"decorators"
|
|
226
|
+
];
|
|
427
227
|
}
|
|
428
|
-
|
|
429
|
-
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region ../bitfab-typescript-transform/src/loaderRuntime.ts
|
|
430
230
|
function readCompilerOptions(filename, configuredPath) {
|
|
431
|
-
|
|
432
|
-
return config?.compilerOptions ?? {};
|
|
231
|
+
return (configuredPath ? parseTsconfig(configuredPath) : getTsconfig(dirname(filename))?.config)?.compilerOptions ?? {};
|
|
433
232
|
}
|
|
434
233
|
function reactJsxOptions(compilerOptions) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
pragmaFrag: compilerOptions.jsxFragmentFactory
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
];
|
|
448
|
-
}
|
|
449
|
-
return [
|
|
450
|
-
reactJsxPlugin,
|
|
451
|
-
{
|
|
452
|
-
runtime: "automatic",
|
|
453
|
-
importSource: compilerOptions.jsxImportSource ?? "react"
|
|
454
|
-
}
|
|
455
|
-
];
|
|
234
|
+
if (compilerOptions.jsx === "react") return [reactJsxPlugin, {
|
|
235
|
+
runtime: "classic",
|
|
236
|
+
...compilerOptions.jsxFactory && { pragma: compilerOptions.jsxFactory },
|
|
237
|
+
...compilerOptions.jsxFragmentFactory && { pragmaFrag: compilerOptions.jsxFragmentFactory }
|
|
238
|
+
}];
|
|
239
|
+
return [reactJsxPlugin, {
|
|
240
|
+
runtime: "automatic",
|
|
241
|
+
importSource: compilerOptions.jsxImportSource ?? "react"
|
|
242
|
+
}];
|
|
456
243
|
}
|
|
457
244
|
function compilePlugins(filename, compilerOptions, format) {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
]
|
|
470
|
-
] : [],
|
|
471
|
-
[
|
|
472
|
-
decoratorsPlugin,
|
|
473
|
-
{
|
|
474
|
-
version: compilerOptions.experimentalDecorators ? "legacy" : "2023-11"
|
|
475
|
-
}
|
|
476
|
-
],
|
|
477
|
-
...hasJsx ? [reactJsxOptions(compilerOptions)] : [],
|
|
478
|
-
...isCommonJs ? [commonJsPlugin] : []
|
|
479
|
-
];
|
|
245
|
+
const path = sourceFilename(filename);
|
|
246
|
+
const isTypeScript = /\.[cm]?tsx?$/.test(path);
|
|
247
|
+
const hasJsx = /\.[jt]sx$/.test(path);
|
|
248
|
+
const isCommonJs = format === "commonjs" || path.endsWith(".cts");
|
|
249
|
+
return [
|
|
250
|
+
...isTypeScript ? [[typeScriptPlugin, { onlyRemoveTypeImports: compilerOptions.verbatimModuleSyntax === true }]] : [],
|
|
251
|
+
[decoratorsPlugin, { version: compilerOptions.experimentalDecorators ? "legacy" : "2023-11" }],
|
|
252
|
+
...hasJsx ? [reactJsxOptions(compilerOptions)] : [],
|
|
253
|
+
...isCommonJs ? [commonJsPlugin] : []
|
|
254
|
+
];
|
|
480
255
|
}
|
|
481
256
|
function transformBitfabModuleToJavaScript(source, filename, options = {}, format, sourceMapMode = "external") {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
if (compiled?.code === void 0 || compiled.code === null) {
|
|
512
|
-
throw new Error(`Bitfab could not compile ${sourceFile}`);
|
|
513
|
-
}
|
|
514
|
-
return {
|
|
515
|
-
code: compiled.code,
|
|
516
|
-
...compiled.map ? { map: JSON.stringify(compiled.map) } : {}
|
|
517
|
-
};
|
|
257
|
+
const { tsconfig, ...transformOptions } = options;
|
|
258
|
+
if (!shouldTransformBitfabFile(filename, transformOptions)) return { code: source };
|
|
259
|
+
const sourceFile = sourceFilename(filename);
|
|
260
|
+
const instrumented = transformSync(source, {
|
|
261
|
+
ast: true,
|
|
262
|
+
babelrc: false,
|
|
263
|
+
code: false,
|
|
264
|
+
configFile: false,
|
|
265
|
+
filename: sourceFile,
|
|
266
|
+
parserOpts: {
|
|
267
|
+
plugins: parserPlugins(filename),
|
|
268
|
+
sourceType: "module"
|
|
269
|
+
},
|
|
270
|
+
plugins: [[bitfabBabelPlugin, transformOptions]]
|
|
271
|
+
});
|
|
272
|
+
if (!instrumented?.ast) throw new Error(`Bitfab could not parse ${sourceFile}`);
|
|
273
|
+
const compiled = transformFromAstSync(instrumented.ast, source, {
|
|
274
|
+
babelrc: false,
|
|
275
|
+
cloneInputAst: false,
|
|
276
|
+
configFile: false,
|
|
277
|
+
filename: sourceFile,
|
|
278
|
+
plugins: compilePlugins(filename, readCompilerOptions(filename, tsconfig), format),
|
|
279
|
+
sourceMaps: sourceMapMode === "inline" ? "inline" : true
|
|
280
|
+
});
|
|
281
|
+
if (compiled?.code === void 0 || compiled.code === null) throw new Error(`Bitfab could not compile ${sourceFile}`);
|
|
282
|
+
return {
|
|
283
|
+
code: compiled.code,
|
|
284
|
+
...compiled.map ? { map: JSON.stringify(compiled.map) } : {}
|
|
285
|
+
};
|
|
518
286
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region ../bitfab-typescript-transform/src/nodeLoader.ts
|
|
289
|
+
const runtimeParentURL = process.env.BITFAB_SDK_RESOLVE_FROM === void 0 ? import.meta.url : pathToFileURL(resolve$1(process.env.BITFAB_SDK_RESOLVE_FROM)).href;
|
|
522
290
|
async function resolve(specifier, context, nextResolve) {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
291
|
+
return specifier === "bitfab:runtime/auto" ? nextResolve("@bitfab/sdk/auto", {
|
|
292
|
+
...context,
|
|
293
|
+
parentURL: runtimeParentURL
|
|
294
|
+
}) : nextResolve(specifier, context);
|
|
527
295
|
}
|
|
528
296
|
function runtimeFormat(format, filename) {
|
|
529
|
-
|
|
297
|
+
return format?.startsWith("commonjs") || /\.c(?:js|ts)$/.test(filename) ? "commonjs" : "module";
|
|
530
298
|
}
|
|
531
299
|
function isInsideWorkingDirectory(filename) {
|
|
532
|
-
|
|
533
|
-
|
|
300
|
+
const path = relative(process.cwd(), filename);
|
|
301
|
+
return path !== ".." && !path.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) && !isAbsolute(path);
|
|
534
302
|
}
|
|
535
303
|
async function load(url, context, nextLoad) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
source,
|
|
547
|
-
filename,
|
|
548
|
-
format === "commonjs" ? {
|
|
549
|
-
runtimeModule: createRequire(runtimeParentURL).resolve("@bitfab/sdk/auto")
|
|
550
|
-
} : { runtimeModule: "bitfab:runtime/auto" },
|
|
551
|
-
format,
|
|
552
|
-
"inline"
|
|
553
|
-
);
|
|
554
|
-
return {
|
|
555
|
-
format,
|
|
556
|
-
shortCircuit: true,
|
|
557
|
-
source: transformed.code
|
|
558
|
-
};
|
|
304
|
+
if (!url.startsWith("file:")) return nextLoad(url, context);
|
|
305
|
+
const filename = fileURLToPath(url);
|
|
306
|
+
if (!isInsideWorkingDirectory(filename) || !shouldTransformBitfabFile(filename, {})) return nextLoad(url, context);
|
|
307
|
+
const source = await readFile(filename, "utf8");
|
|
308
|
+
const format = runtimeFormat(context.format, filename);
|
|
309
|
+
return {
|
|
310
|
+
format,
|
|
311
|
+
shortCircuit: true,
|
|
312
|
+
source: transformBitfabModuleToJavaScript(source, filename, format === "commonjs" ? { runtimeModule: createRequire(runtimeParentURL).resolve("@bitfab/sdk/auto") } : { runtimeModule: "bitfab:runtime/auto" }, format, "inline").code
|
|
313
|
+
};
|
|
559
314
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
};
|
|
315
|
+
//#endregion
|
|
316
|
+
export { load, resolve };
|
|
317
|
+
|
|
564
318
|
//# sourceMappingURL=nodeLoader.js.map
|