Skip to content

[python] Refactor Python emitter node imports to be browser bundleable - #10844

Merged
jenny (JennyPng) merged 6 commits into
microsoft:mainfrom
JennyPng:refactor-node-python-emitter
Jun 12, 2026
Merged

jenny (JennyPng) merged 6 commits into
microsoft:mainfrom
JennyPng:refactor-node-python-emitter

Conversation

@JennyPng

@JennyPng jenny (JennyPng) commented May 29, 2026 •

Copy link
Copy Markdown
Member
  • after polyfill plugin was removed, Python emitter is no longer browser bundleable due to Node or filesystem imports
  • extract Node calls into a separate file and swap for browser vs. non-browser

local validation:

  • Works in browser: from the typespec-azure repo, overrode and installed this branch's http-client-python and checked that /typespec-azure-playground-website is able to start when including typespec-python

@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label May 29, 2026
@pkg-pr-new

pkg-pr-new Bot commented May 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-python@10844

commit: fb66999

@github-actions

github-actions Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/http-client-python
Show changes

@typespec/http-client-python - internal ✏️

Refactor Node usage in Python emitter to make it browser bundleable

@azure-sdk-automation

azure-sdk-automation Bot commented May 29, 2026 •

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the Python HTTP client emitter to be browser-bundleable by isolating Node-only functionality behind swap-in modules selected via the package "browser" field, and by avoiding static imports that pull in Node built-ins when bundling for the browser (notably via pyodide).

Changes:

  • Adds package-level "browser" mappings to swap Node implementations for browser stubs at bundle time.
  • Extracts Node-only emit execution into node-runner.ts and adds a browser stub implementation.
  • Introduces a pyodide-loader abstraction, with a browser implementation that loads Pyodide via CDN script injection.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/http-client-python/package.json Adds "browser" field mappings to swap Node runner and Pyodide loader for browser builds.
packages/http-client-python/emitter/src/emitter.ts Removes direct Node built-in imports and delegates Node path to runNodeEmit; uses pyodide-loader abstraction.
packages/http-client-python/emitter/src/node-runner.ts New Node-only module containing filesystem/process execution and native Python/Pyodide NodeFS paths.
packages/http-client-python/emitter/src/node-runner.browser.ts New browser stub that emits a diagnostic if Node path is reached in a browser bundle.
packages/http-client-python/emitter/src/pyodide-loader.ts Node-side re-export wrapper around the pyodide package APIs.
packages/http-client-python/emitter/src/pyodide-loader.browser.ts Browser loader that injects pyodide.js via <script> instead of importing pyodide into the bundle.
.chronus/changes/refactor-node-python-emitter-2026-5-3-15-23-59.md Adds a Chronus entry documenting the internal refactor.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added compiler:core Issues for @typespec/compiler ide Issues for VS, VSCode, Monaco, etc. lib:http lib:openapi lib:rest lib:versioning lib:http-specs For issues/prs related to the @typespec/http-specs package meta:website TypeSpec.io updates tspd Issues for the tspd tool emitter:client:js Issue for the JS client emitter: @typespec/http-client-js emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp emitter:client:java Issue for the Java client emitter: @typespec/http-client-java emitter:json-schema emitter:protobuf The protobuf emitter emitter:openapi3 Issues for @typespec/openapi3 emitter openapi3:converter Issues for @typespec/openapi3 openapi to typespec converter eng ui:playground ui:type-graph-viewer labels Jun 10, 2026
@JennyPng jenny (JennyPng) removed lib:http lib:openapi lib:rest emitter:openapi3 Issues for @typespec/openapi3 emitter openapi3:converter Issues for @typespec/openapi3 openapi to typespec converter ui:playground ui:type-graph-viewer emitter:client:java Issue for the Java client emitter: @typespec/http-client-java lib:http-specs For issues/prs related to the @typespec/http-specs package emitter:client:js Issue for the JS client emitter: @typespec/http-client-js labels Jun 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

@JennyPng
jenny (JennyPng) added this pull request to the merge queue Jun 12, 2026
Merged via the queue into microsoft:main with commit 3a86d4e Jun 12, 2026
41 checks passed
@JennyPng
jenny (JennyPng) deleted the refactor-node-python-emitter branch June 12, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python eng

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants