From 75c63edf87769f6e85ce78d371578f85440c2084 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Thu, 9 Jul 2026 20:41:42 +0200 Subject: [PATCH] fix(js-sdk): make caller-directory resolution robust to class-field emit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolve the template builder's default fileContextPath in the constructor body instead of a class field initializer. With [[Define]] class-field semantics (the default at target es2022+), field initializers run in an extra stack frame, shifting the fixed-depth stack walk in getCallerDirectory by one — .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 the js-sdk tsconfig is no longer needed. Co-Authored-By: Claude Fable 5 --- .changeset/lucky-buttons-repair.md | 5 +++++ packages/js-sdk/src/template/index.ts | 9 ++++++--- packages/js-sdk/tsconfig.json | 6 ------ 3 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 .changeset/lucky-buttons-repair.md diff --git a/.changeset/lucky-buttons-repair.md b/.changeset/lucky-buttons-repair.md new file mode 100644 index 0000000000..3e1e2ad041 --- /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 `` 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 7e75c92d69..5d1176f52a 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 c922e31514..f81cbc5dac 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"