Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-buttons-repair.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 6 additions & 3 deletions packages/js-sdk/src/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,19 @@ 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)[] = []
private stackTracesEnabled: boolean = true
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
}
Expand Down
6 changes: 0 additions & 6 deletions packages/js-sdk/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading