feat(typescript): add opt-in esmOnly flag for ESM-only SDK output - #17503
Merged
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
SDK Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on Full benchmark table (click to expand)
main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via |
…m packages Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
iamnamananand996
approved these changes
Sep 11, 2026
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.
Description
Linear ticket: Refs (none — customer request, Auth0 Pylon #22973)
Adds an opt-in
esmOnlycustom config flag to the TypeScript SDK generator. When enabled, the generated package ships only the existing ESM build — decoupling it from the combined CJS package — to avoid the Dual Package Hazard. Nothing changes for the default (CJS + ESM) generation;esmOnlyreuses the existing ESM pipeline (tsconfig.esm.json,rename-to-esm-files.mjs/.d.mtsoutput) and simply drops the CJS half.With
esmOnly: truethe generatedpackage.jsonbecomes:{ "type": "module", "main": "./dist/esm/index.mjs", "module": "./dist/esm/index.mjs", "types": "./dist/esm/index.d.mts", "exports": { ".": { "types": "./dist/esm/index.d.mts", "default": "./dist/esm/index.mjs" }, "./package.json": "./package.json" }, "scripts": { "build": "pnpm build:esm" } }tsconfig.cjs.jsonandbuild:cjsare not generated; roottsconfig.jsonextendstsconfig.esm.json. The bundled CJS rename script is emitted asscripts/rename-to-esm-files.cjs(instead of.js) because"type": "module"would otherwise make Node execute the CommonJS script as ESM.Unsupported combinations fail fast with a clear error rather than silently ignoring the flag:
esmOnly + useLegacyExportsesmOnly + bundleoutputEsmbuild fixThis PR also fixes a pre-existing bug in
outputEsm: truepackages (reproduced against the Auth0 config): they are marked"type": "module", sobuild:esm'snode scripts/rename-to-esm-files.jscrashed withReferenceError: require is not defined in ES module scope. The.cjshelper treatment now applies to any"type": "module"package (esmOnly || outputEsm):outputEsmpackages remain dual-published (CJS + ESM) — only the helper's extension changes (identical contents), so the compileddist/esmoutput is unchanged (verified byte-identical on the Auth0 SDK: 1444 files, empty recursive diff betweenoutputEsmandesmOnlybuilds).Changes Made
esmOnlyadded toTypescriptCustomConfigSchema,SdkCustomConfig, threaded throughSdkGeneratorCli→SdkGenerator→SimpleTypescriptProject/AsIsManagerSimpleTypescriptProject: ESM-onlypackage.json(type,main/types, exports map withoutrequire/CJS conditions, incl. subpackage exports), skiptsconfig.cjs.json, root tsconfig extends ESM config,buildruns onlybuild:esmAsIsManager/SimpleTypescriptProject: emit and invoke the rename script as.cjsfor any"type": "module"package (esmOnlyoroutputEsm)SdkGeneratorCli: throw onesmOnly + useLegacyExportsandesmOnly + bundlesimple-api/esm-onlyandsimple-api/output-esmoutput variants (seed/ts-sdk/seed.yml) with generated fixturesadd-esm-only-flag.yml(feat) andfix-output-esm-rename-script.yml(fix) undergenerators/typescript/sdk/changes/unreleased/Testing
SimpleTypescriptProject.test.tscovering default (dual CJS+ESM,.jshelper),outputEsm: true(still dual,.cjshelper), andesmOnly: true; all 33 tests in the package passesm-onlyseed fixture, ranpnpm install && pnpm build(compiles, 126 files renamed to.mjs/.d.mts), verified Nodeimportresolves root and/usersubpath exports, andpublintpasses. Generated the newoutput-esmfixture and ranpnpm install && pnpm build: bothbuild:cjsandbuild:esmnow succeed (previouslybuild:esmcrashed on main). Verified default fixtures are byte-identical to before (no snapshot changes with the flags off). Seed's Docker validator image could not be pulled in this environment (network-restricted), so full seed validation should run in CI.Written by Devin