Skip to content

Fix Python playground bundle esbuild failure by isolating browser-safe YAML util - #11811

Merged
iscai-msft merged 3 commits into
microsoft:mainfrom
iscai-msft:investigate-python-publish
Sep 1, 2026
Merged

iscai-msft merged 3 commits into
microsoft:mainfrom
iscai-msft:investigate-python-publish

Conversation

@iscai-msft

Copy link
Copy Markdown
Member

Summary

PR #11800 fixed the pip/PyPI authentication failure in the Python playground publish job, but a subsequent publish build (6772679) failed later in the same job, at the "Upload playground bundle" step:

✘ [ERROR] Could not resolve "child_process"
✘ [ERROR] Could not resolve "crypto"
✘ [ERROR] Could not resolve "fs/promises"
✘ [ERROR] Could not resolve "os"
    packages/http-client-python/dist/emitter/external-process.js

Root cause

emitter.ts imports dumpCodeModelToYaml from external-process.ts for use on the browser/Pyodide code path. However, external-process.ts also contains Node-only code (execAsync, saveCodeModelAsYaml) that uses child_process, crypto, fs/promises, and os.

Only node-runner.js is swapped out for a browser-safe stub via the "browser" field in package.json; emitter.ts is not. As a result, when esbuild bundles the emitter for the browser playground (platform: "browser"), it pulls in all of external-process.ts, including the Node-only imports, which can't be resolved for a browser target.

Fix

Extracted dumpCodeModelToYaml (a pure, browser-safe YAML serialization helper) into a new yaml-utils.ts module. Both emitter.ts (browser path) and external-process.ts (Node-only path, still used by node-runner.ts) now import it from there, so no Node builtins leak into the browser bundle.

Validation

  • npx tsc -p ./emitter/tsconfig.build.json — passes with no errors
  • npx tsx ./eng/scripts/ci/run-tests.ts --emitter — 21/21 tests pass
  • Reproduced the exact esbuild failure against the pre-fix code (via createTypeSpecBundle from @typespec/bundler) and confirmed it is resolved after this change.

iscai-msft and others added 2 commits September 1, 2026 14:10
…e YAML util

emitter.ts imports dumpCodeModelToYaml from external-process.ts for use on
the browser/Pyodide path, but external-process.ts also contains Node-only
code (execAsync, saveCodeModelAsYaml) using child_process/crypto/fs/os.
Since emitter.ts isn't swapped for a browser stub (only node-runner.js is),
esbuild bundled the whole file with platform: browser, failing to resolve
those Node builtins during the playground bundle upload step.

Move dumpCodeModelToYaml into a new browser-safe yaml-utils.ts module and
have both emitter.ts and external-process.ts import it from there.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@pkg-pr-new

pkg-pr-new Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

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

commit: c1bdc52

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

This pull request fixes a browser-playground bundling failure for @typespec/http-client-python by preventing Node-only dependencies from being pulled into the browser (Pyodide) bundle.

Changes:

  • Extracted dumpCodeModelToYaml into a new browser-safe module (yaml-utils.ts) so it can be used from the browser code path without importing Node built-ins.
  • Updated emitter.ts (browser/Pyodide path) and external-process.ts (Node-only path) to import dumpCodeModelToYaml from the new module.
  • Updated the existing YAML-quoting test to reference the new module and renamed the suite to match.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

File Description
packages/http-client-python/emitter/test/yaml-utils.test.ts Updates test imports and suite name to validate YAML quoting via the new browser-safe helper module.
packages/http-client-python/emitter/src/yaml-utils.ts Introduces a dedicated browser-safe YAML serialization helper used by both browser and Node paths.
packages/http-client-python/emitter/src/external-process.ts Removes inline YAML dump logic and reuses the extracted helper while keeping Node-only process/file code here.
packages/http-client-python/emitter/src/emitter.ts Switches the browser/Pyodide path to use the new YAML helper without importing Node-only modules.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings September 1, 2026 18:16
@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

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

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

Fix playground bundle publish failing with esbuild errors ("Could not resolve child_process/crypto/fs/promises/os") by moving the browser-safe YAML serialization helper out of a module that also contains Node-only code

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 5 out of 5 changed files in this pull request and generated no new comments.

@azure-sdk-automation

azure-sdk-automation Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@iscai-msft
iscai-msft enabled auto-merge September 1, 2026 18:56
@iscai-msft
iscai-msft added this pull request to the merge queue Sep 1, 2026
Merged via the queue into microsoft:main with commit 43fd68b Sep 1, 2026
41 of 42 checks passed
@iscai-msft
iscai-msft deleted the investigate-python-publish branch September 1, 2026 20:29
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants