build: emit the ESM bundles for ES2018 - #57
Merged
Conversation
At ES2015 TypeScript downlevels `async`/`await`, object rest and `for await…of` into `__awaiter` / `__rest` / `__asyncValues`, and emits each helper guarded by a top-level `this` — which is `undefined` in an ES module, so esbuild warned on every file carrying one while bundling cma-client-browser. The guard is harmless (it falls through to the inline helper), but the noise is avoidable: ES2018 has all three natively and the helpers disappear. The CommonJS output and `dist/types` are untouched. `dist/esm` now expects an ES2018 runtime; the browser bundle already targeted it. Claude-Session: https://claude.ai/code/session_01Dw3PG2vUep69n8te7emzyQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
npm run buildprinted a wall of esbuild warnings while bundlingcma-client-browser:They were harmless. With
target: es2015TypeScript has to downlevelasync/await, object rest andfor await…ofinto its own__awaiter/__rest/__asyncValueshelpers, and it emits each one guarded by(this && this.__awaiter) || function (…) {…}so the CommonJS emit can reuse a copy hoisted ontoexports. In an ES module top-levelthisisundefinedby spec, so esbuild substitutingundefinedis exactly right — the guard short-circuits and the inline helper is used.Rather than silence the warning, this removes its cause: ES2018 has all three constructs natively (async/await landed in ES2017, object rest and
for await…ofin ES2018), so TypeScript emits no helpers at all and the shipped code is the code we wrote.pollJobResult.jsis now a plainexport async function, andgrep "this && this.__"finds nothing left under anydist/esm.Eight
packages/*/tsconfig.esm.jsonmove to"target": "es2018", each gaining a matching"lib"because the root tsconfig pinses2017andfor await…ofneedsSymbol.asyncIteratordeclared.cma-client-analysisis untouched — it runstscalone and has nodist/esm.The CommonJS output and
dist/typesare byte-identical to before; CJS keeps its ES2015 target, where top-levelthisisexportsand nothing warns. The one consequence for users is thatdist/esmnow expects an ES2018 runtime — Node 10+, browsers withSymbol.asyncIterator. The bundle incma-client-browser/esbuild.tsalready targeted ES2018, so this makes the rest of the repo consistent with it.Changeset is
minorfor the eight packages that build an ESM output.Test plan
npm run build— 9/9 tasks green, no esbuild warnings.https://claude.ai/code/session_01Dw3PG2vUep69n8te7emzyQ