Dedupe build output#8557
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates MSAL packages’ Rollup build + packaging metadata to dedupe build artifacts and improve TypeScript type resolution for consumers using both ESM and CommonJS, primarily by generating .d.cts CommonJS type shims and updating package.json export types entries.
Changes:
- Added a shared Rollup plugin (
createCjsTypeShims) to emit CommonJS declaration shims (.d.cts) that re-export from ESM type entrypoints. - Updated package Rollup configs to stop emitting duplicate declaration files for CommonJS builds and to generate the
.d.ctsshims. - Updated
package.jsonexportsto reference.d.ctsfiles for therequire(types) condition and consolidated msal-browser subpath ESM builds.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| shared-configs/rollup-msal/index.js | Adds createCjsTypeShims plugin and exports it for reuse in package builds. |
| lib/msal-react/rollup.config.js | Generates dist/index.d.cts and disables CJS declaration emit to reduce duplicate types. |
| lib/msal-react/package.json | Points exports.require.types to dist/index.d.cts. |
| lib/msal-node/rollup.config.js | Generates dist/index.d.cts and disables CJS declaration emit. |
| lib/msal-node/package.json | Points exports.require.types to dist/index.d.cts. |
| lib/msal-common/rollup.config.js | Generates multiple .d.cts shims for main/node/browser entrypoints; disables CJS declaration emit. |
| lib/msal-common/package.json | Points exports.require.types entries to .d.cts shims across entrypoints. |
| lib/msal-browser/rollup.config.js | Consolidates ESM build inputs (main + subpaths) and generates .d.cts shims; disables CJS declaration emit for subpath CJS builds. |
| lib/msal-browser/package.json | Updates subpath and main exports to use new dist paths and .d.cts for require.types. |
shenj
left a comment
There was a problem hiding this comment.
A small note. Since the new output folder for ES is now custom_auth (previously custom_auth_path), it might be better to update the output folder for CJS to custom_auth as well to maintain consistency. I understand that this PR was meant to change only the ESM side, so it's up to you if you'd like to make this update. Thanks.
This pull request updates the packaging and build configuration for all MSAL packages to improve TypeScript type resolution for consumers using both ESM and CommonJS. The main improvements are the introduction of CommonJS type declaration shims, consolidation of subpath export builds, and updates to the
package.jsonexports to reference the correct type declaration files. These changes should resolve longstanding issues with type resolution in CommonJS environments and simplify the build process.Build process and type declaration improvements:
createCjsTypeShimsutility inshared-configs/rollup-msal/index.jsto generate CommonJS.d.ctstype declaration files that re-export types from ESM entrypoints, ensuring correct type resolution for CommonJS consumers.rollup.config.jsfiles (msal-browser,msal-common,msal-node,msal-react) to usecreateCjsTypeShimsand generate.d.ctsfiles for CommonJS exports. [1] [2] [3] [4].d.tsand.d.ts.mapfiles for CommonJS builds, preventing duplicate or unnecessary declaration files. [1] [2] [3] [4] [5] [6]Package exports and type resolution:
package.jsonexportsfields in all packages to reference the new.d.ctsfiles in thedist(ordist-browser) directories for CommonJStypesentries, instead of the previous.d.tsfiles inlib/types. [1] [2] [3] [4] [5] [6] [7]Build process simplification and consolidation:
msal-browsersubpath exports (custom_authandredirect_bridge) into the main build step, removing redundant build configurations and simplifying the output directory structure. [1] [2] [3]Summary of the most important changes:
Type Declaration and Exports Modernization
createCjsTypeShimsto generate.d.ctsfiles for CommonJS type resolution and integrated it into all package builds. [1] [2] [3] [4] [5]package.jsonexportsto point CommonJStypesto the new.d.ctsfiles indistfolders. [1] [2] [3] [4] [5] [6] [7]Build Process Improvements
msal-browsersubpaths, reducing build complexity and output directories. [1] [2] [3]