You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[warp] Migrate core packages to warp with type-compatible browser polyfills (#37442)
## [warp] Migrate core packages to warp with type-compatible browser
polyfills
### Root tsconfig changes
- `tsconfig.src.esm.json`: Replace `WebWorker` with `DOM` +
`DOM.Iterable` in `lib`
- `tsconfig.src.cjs.json`: Add `DOM` + `DOM.Iterable` to `lib` (was
`ES2023` only)
### `@azure/core-amqp`
- Add `warp.config.yml`, remove `tshy` config and devDependency
- Add `checkNetworkConnection.common.ts` browser polyfill
### `@azure/core-client`
- Add `warp.config.yml`, remove `tshy` config and devDependency
- Add `import type` annotations to `state-cjs.cts` so tsc can type-check
the polyfill content when it is substituted under the `.ts` filename by
warp's polyfill host
- Update `vitest.config.ts` alias to point to compiled
`dist/commonjs/state.js` instead of source `state-cjs.cts` (Vite/Rollup
treats `.cts` as JavaScript and cannot parse TypeScript syntax like
`import type`)
### `@azure/core-rest-pipeline`
- Add `warp.config.yml`, remove `tshy` config and devDependency
### `@azure/core-tracing`
- Add `warp.config.yml`, remove `tshy` config and devDependency
- Add `import type` annotations to `state-cjs.cts` so tsc can type-check
the polyfill content when it is substituted under the `.ts` filename by
warp's polyfill host
- Update `vitest.config.ts` alias to point to compiled
`dist/commonjs/state.js` instead of source `state-cjs.cts` (Vite/Rollup
treats `.cts` as JavaScript and cannot parse TypeScript syntax like
`import type`)
### `@azure/core-xml`
- Add `warp.config.yml`, remove `tshy` config and devDependency
- Add local `tsconfig.src.browser.json` with `trusted-types` in `types`
(needed by `xml-browser.mts`)
- Remove triple-slash reference directives from `xml-browser.mts`
### `@typespec/ts-http-runtime`
- Add `warp.config.yml`, remove `tshy` config and devDependency
- Add/update browser polyfills: `decompressResponsePolicy-browser.mts`,
`proxyPolicy.common.ts`, `concat.common.ts`
- Update API diff reports for browser and react-native targets
- `concat.common.ts`: Export `ConcatSource` type and add
`NodeJS.ReadableStream` to its union. The browser polyfill
(`concat-browser.mts`) re-exports from `concat.common.ts`. When warp
type-checks the browser target, `multipartPolicy.ts` passes
`BodyPart.body` — whose type includes `NodeJS.ReadableStream` — into
`concat()`. So `ConcatSource` must accept that type to satisfy the
type-checker. tshy never caught this mismatch because it did not
type-check browser polyfills against their callers. The added union
member is unreachable at runtime in browser environments — the function
already throws for unsupported source types.
### warp changes
- Discover `.cts` polyfill files (search order: `.mts` → `.cts` → `.ts`)
- Add `polyfillSuffix: "-cjs"` support for CJS-specific polyfills
(tshy's module-local-state pattern)
- Add `platform: "node"` to esbuild CJS transform so it emits `0 &&
(module.exports = {...})` sentinel for Node's `cjs-module-lexer` to
detect named exports in ESM→CJS interop
- Type-check `.cts` polyfill content by substituting it under the
original `.ts` filename via the polyfill host — tsc sees TypeScript, not
a `.cts` extension
### Why vitest configs changed
The `state.ts` files in core-client and core-tracing use tshy's
module-local-state pattern: the ESM entry (`state.ts`) re-exports from
`../commonjs/state.js` so that ESM and CJS share a single state object
(preventing dual-package hazard). During tests, vitest resolves
`../commonjs/state.js` via an alias. Previously the alias pointed to the
source `state-cjs.cts` file, but Vite/Rollup treats `.cts` as JavaScript
and chokes on TypeScript syntax (`import type`). The fix is to alias to
the compiled `dist/commonjs/state.js` instead.
### Why `.cts` files need type annotations
Warp's polyfill host substitutes the `.cts` file's *content* under the
original `.ts` *filename*, so tsc type-checks it as TypeScript. The
original `.cts` files used `any`-typed variables (e.g. `let state:
any`). Adding proper `import type` declarations and explicit type
annotations (e.g. `as Instrumenter | undefined`,
`WeakMap<OperationRequest, OperationRequestInfo>`) ensures the polyfill
content is fully type-checked at build time, catching mismatches between
the CJS and ESM implementations.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0 commit comments