Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

fix(js-sdk): unpin useDefineForClassFields — make caller-directory resolution emit-invariant (#1539)

Mish Ushakov64e9bc02b6eb
diff --git a/.changeset/lucky-buttons-repair.md b/.changeset/lucky-buttons-repair.md
new file mode 100644
index 000000000..3e1e2ad04
--- /dev/null
+++ b/.changeset/lucky-buttons-repair.md
@@ -0,0 +1,5 @@
+---
+'e2b': patch
+---
+
+Resolve the template builder's default file context path in the constructor instead of a class field initializer. Under `[[Define]]` class-field semantics (the default at `target: es2022+`), field initializers run in an extra `<instance_members_initializer>` stack frame, which threw off the fixed-depth caller-directory resolution — `.copy()` sources resolved against the SDK's own directory instead of the caller's. The constructor-body call is emit-invariant, so the `useDefineForClassFields: false` pin in tsconfig is no longer needed and has been removed.
diff --git a/packages/js-sdk/src/template/index.ts b/packages/js-sdk/src/template/index.ts
index 7e75c92d6..5d1176f52 100644
--- a/packages/js-sdk/src/template/index.ts
+++ b/packages/js-sdk/src/template/index.ts
@@ -66,8 +66,7 @@ export class TemplateBase
// Force the next layer to be rebuilt
private forceNextLayer: boolean = false
private instructions: Instruction[] = []
- private fileContextPath: PathLike =
- runtime === 'browser' ? '.' : (getCallerDirectory(STACK_TRACE_DEPTH) ?? '.')
+ private fileContextPath: PathLike
private fileIgnorePatterns: string[] = []
private logsRefreshFrequency: number = 200
private stackTraces: (string | undefined)[] = []
@@ -75,7 +74,11 @@ export class TemplateBase
private stackTracesOverride: string | undefined = undefined
constructor(options?: TemplateOptions) {
- this.fileContextPath = options?.fileContextPath ?? this.fileContextPath
+ this.fileContextPath =
+ options?.fileContextPath ??
+ (runtime === 'browser'
+ ? '.'
+ : (getCallerDirectory(STACK_TRACE_DEPTH) ?? '.'))
this.fileIgnorePatterns =
options?.fileIgnorePatterns ?? this.fileIgnorePatterns
}
diff --git a/packages/js-sdk/tsconfig.json b/packages/js-sdk/tsconfig.json
index c922e3151..f81cbc5da 100644
--- a/packages/js-sdk/tsconfig.json
+++ b/packages/js-sdk/tsconfig.json
@@ -3,12 +3,6 @@
"outDir": "dist",
"target": "es2022",
"module": "esnext",
- // Keep assignment (not `[[Define]]`) semantics for class fields. `target:
- // es2022` would default this to `true`, which changes class-field emit and
- // shifts stack frames — breaking the template builder's fixed-depth caller
- // resolution (getCallerDirectory / per-step stack traces). Adopting define
- // semantics should be a separate, deliberately tested change.
- "useDefineForClassFields": false,
"lib": [
"dom",
"es2022"