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"