Skip to content

Add http client js to the playground#10165

Merged
timotheeguerin merged 6 commits into
microsoft:mainfrom
timotheeguerin:feature/http-client-js-playground
Apr 30, 2026
Merged

Add http client js to the playground#10165
timotheeguerin merged 6 commits into
microsoft:mainfrom
timotheeguerin:feature/http-client-js-playground

Conversation

@timotheeguerin
Copy link
Copy Markdown
Member

@timotheeguerin timotheeguerin commented Mar 26, 2026

Changes:

  • Adding http-client-js to the playground
  • Updating the bundler to detect more smartly what it considers a Typespec dependency that shouldn't be bundled.
  • Add a hacky vite plugin to allow multiple alloy runtimes

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 26, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/bundler@10165

commit: 59d553e

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 26, 2026

All changed packages have been documented.

  • @typespec/bundler
Show changes

@typespec/bundler - feature ✏️

Add support for alloy based emitters

@azure-sdk
Copy link
Copy Markdown
Collaborator

azure-sdk commented Mar 27, 2026

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@timotheeguerin timotheeguerin marked this pull request as ready for review April 2, 2026 17:17
Comment thread packages/bundler/src/bundler.ts Outdated
@timotheeguerin timotheeguerin added this pull request to the merge queue Apr 30, 2026
Merged via the queue into microsoft:main with commit 8d4aef4 Apr 30, 2026
30 of 31 checks passed
@timotheeguerin timotheeguerin deleted the feature/http-client-js-playground branch April 30, 2026 19:51
github-merge-queue Bot pushed a commit that referenced this pull request May 1, 2026
…nd upload (#10582)

Fixes the `Upload playground bundle` Azure DevOps pipeline step that was
failing with:

```
packages/http-client-csharp/dist/emitter/src/emitter.js:5:24: ERROR: Could not resolve "path"
packages/http-client-csharp/dist/emitter/src/lib/utils.js:4:22: ERROR: Could not resolve "child_process"
```

## Root cause

PR #10165 ("Add http client js to the playground", merged Apr 30)
removed `nodeModulesPolyfillPlugin` from
`packages/bundler/src/bundler.ts`. Until then, the bundler silently
polyfilled Node built-ins like `path`, `fs`, and `url` (and stubbed
`child_process`), which masked the fact that:

- `emitter.ts` imports `resolve` from Node `path`.
- `lib/utils.ts` imports `spawn` from `child_process` for
`execCSharpGenerator` / `execAsync`, and `lib/utils.ts` is reached
transitively from `emitter.ts` via shared helpers like
`getClientNamespaceString` / `isReadOnly`.

The `"browser"` field in `package.json` only swaps `emit-generate.js`
for `emit-generate.browser.js` — it doesn't help with these other files.
With the polyfill plugin gone, the next C# publish run hit
unresolved-module errors on those long-standing imports.

## Fix

1. Move `execCSharpGenerator`, `execAsync`, and `processJsonRpc` (the
only `child_process` users) out of `lib/utils.ts` into a new
`lib/exec-utils.ts`. `lib/exec-utils.ts` is only imported from
`emit-generate.ts` (the Node-only generation entry point), so the
browser bundle (which loads `emit-generate.browser.ts` via the `browser`
field) never reaches it.
2. Replace `import { resolve } from "path"` in `emitter.ts` with
`resolvePath` from `@typespec/compiler` (the cross-platform TypeSpec
utility used elsewhere in the emitter).
3. Update tests to import from the new location.

This is the right fix even with the polyfill plugin in place —
`child_process` was never going to work at runtime in the browser, so
relying on the bundler to silently include it was a latent footgun.

## Verified

- `npm run build:emitter` ✅
- `npm run test:emitter` ✅ 205 passed (2 skipped)
- Local `esbuild` bundle of `dist/emitter/src/emitter.js` for `platform:
'browser'` succeeds with no unresolved Node modules.

--generated by Copilot

Co-authored-by: Joshua Love <joshualove@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants