-
Notifications
You must be signed in to change notification settings - Fork 1.3k
ESM migration #1620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
ESM migration #1620
Conversation
# why # what changed # test plan <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Migrates the repo to ESM and Stagehand v3, removes legacy v2 code/evals/examples, and updates docs and tooling. Adds Bedrock and Vertex support, tightens agent prompts/metrics, and fixes screenshot mask coverage. - **Refactors** - Switch to ESM and v3 architecture; remove v2 libs, evals, and examples. - OpenAPI: replace the old cua boolean with a mode enum. - Server: enable Bedrock and include Vertex as supported providers. - Agent/UX: update usage metrics, add SupportedUnderstudyActions, enforce elementId regex, and apply screenshot masks to all matched elements. - Docs/lint: move docs to packages/docs, refresh README links, add project guidelines, and expand ESLint rules. - **CI/Workflows** - Add server SEA build, API tests, and release pipelines. - Add Stainless SDK preview builds and Claude Code automation. - Speed up CI with caching, path filters, and no Playwright browser install. - Modernize release for Trusted Publishing (npm/pnpm, caches, id-token). <sup>Written for commit 89e88af. Summary will update on new commits. <a href="https://cubic.dev/pr/browserbase/stagehand/pull/1619">Review in cubic</a></sup> <!-- End of auto-generated description by cubic. --> --------- Co-authored-by: Chromie Bot <chromie@browserbase.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
|
Greptile OverviewGreptile SummaryMigrated
The migration follows standard ESM patterns and maintains backward compatibility through dual builds. Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Dev as Developer
participant TS as TypeScript Compiler
participant Build as Build System (tsup)
participant Scripts as DOM Scripts Generator
participant Consumers as Package Consumers
Note over Dev,Consumers: ESM Migration Flow
Dev->>TS: Update tsconfig.json to ES2022 modules
Dev->>Build: Update package.json with "type": "module"
Dev->>Build: Configure dual ESM/CJS output in tsup
Dev->>Scripts: Add __dirname polyfill to scripts
Scripts->>Scripts: dirname(fileURLToPath(import.meta.url))
Dev->>TS: Remove duplicate property declarations
Note over TS: Use base class properties via inheritance
Build->>Build: Generate ESM output (dist/index.js)
Build->>Build: Generate CJS output (dist/index.cjs)
Build->>Build: Generate type definitions (dist/index.d.ts)
Consumers->>Build: Import via ESM (import)
Build-->>Consumers: Serve dist/index.js
Consumers->>Build: Require via CJS (require)
Build-->>Consumers: Serve dist/index.cjs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, 1 comment
| "target": "ES2022", | ||
| "noImplicitAny": true, | ||
| "moduleResolution": "node", | ||
| "moduleResolution": "Node", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider using "moduleResolution": "Node16" or "NodeNext" instead of "Node" for better ESM compatibility with explicit file extensions
| "moduleResolution": "Node", | |
| "moduleResolution": "NodeNext", |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/core/tsconfig.json
Line: 8:8
Comment:
consider using `"moduleResolution": "Node16"` or `"NodeNext"` instead of `"Node"` for better ESM compatibility with explicit file extensions
```suggestion
"moduleResolution": "NodeNext",
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 issue found across 15 files
Confidence score: 3/5
- There is a concrete publish-time risk:
packages/core/package.jsonomitsdist/index.cjsfrom thefilesarray, which would break CommonJS consumers when the package is published. - Severity is high (8/10) with clear user impact, so this isn’t quite a low-risk merge despite being a small change.
- Pay close attention to
packages/core/package.json- ensuredist/index.cjsis included in the published files.
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/core/package.json">
<violation number="1" location="packages/core/package.json:6">
P1: The `dist/index.cjs` file referenced here is not included in the `files` array. When published to npm, this file won't be included, breaking CommonJS support. Add `"dist/index.cjs"` to the `files` array.</violation>
</file>
Architecture diagram
sequenceDiagram
participant System as Build System (tsx)
participant Scripts as Internal Scripts
participant Builder as TSUP / TSC
participant Pkg as package.json
participant Consumer as Consumer Runtime
Note over System, Scripts: Phase 1: Internal Tooling (ESM Migration)
System->>Scripts: Execute gen*.ts (e.g., genDomScripts)
rect rgb(30, 41, 59)
Note right of Scripts: CHANGED: Path Resolution Strategy
Scripts->>Scripts: import.meta.url
Scripts->>Scripts: fileURLToPath()
Scripts->>Scripts: dirname()
Note right of Scripts: Replaces legacy CommonJS __dirname
end
Scripts->>Scripts: Generate Assets (DOM/Locator scripts)
Note over System, Consumer: Phase 2: Artifact Generation & Consumption
System->>Builder: build-js (Target ES2022)
Builder->>Builder: CHANGED: Generate ESM (.js)
Builder->>Builder: NEW: Generate CommonJS (.cjs)
Builder->>Pkg: Update Exports Definition
Note over Pkg, Consumer: NEW: Conditional Module Resolution
alt Consumer uses "import" (ESM)
Consumer->>Pkg: Resolve "@browserbasehq/stagehand"
Pkg-->>Consumer: returns dist/index.js (type: module)
else Consumer uses "require" (CJS)
Consumer->>Pkg: Resolve "@browserbasehq/stagehand"
Pkg-->>Consumer: returns dist/index.cjs
end
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| "type": "module", | ||
| "description": "An AI web browsing framework focused on simplicity and extensibility.", | ||
| "main": "./dist/index.js", | ||
| "main": "./dist/index.cjs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: The dist/index.cjs file referenced here is not included in the files array. When published to npm, this file won't be included, breaking CommonJS support. Add "dist/index.cjs" to the files array.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/package.json, line 6:
<comment>The `dist/index.cjs` file referenced here is not included in the `files` array. When published to npm, this file won't be included, breaking CommonJS support. Add `"dist/index.cjs"` to the `files` array.</comment>
<file context>
@@ -1,14 +1,22 @@
+ "type": "module",
"description": "An AI web browsing framework focused on simplicity and extensibility.",
- "main": "./dist/index.js",
+ "main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
</file context>
why
what changed
test plan