Repository navigation
[code-infra] Write declarations with tsdown in build-new - #2061
Conversation
Deploy previewBundle sizeTotal Size Change: 0B(0.00%) - Total Gzip Change: 0B(0.00%) Show details for 79 more bundles@mui/internal-docs-infra/abstractCreateDemo parsed: 0B(0.00%) gzip: 0B(0.00%) PerformanceNo regressions in 8 benchmarks · ran 1m 14s · details Check out the code infra dashboard for more information about this PR. |
b86fd01 to
897e771
Compare
4f6f154 to
fa3fa94
Compare
67ccccb to
c539df6
Compare
c539df6 to
c5db471
Compare
c5db471 to
b7f95ff
Compare
b7f95ff to
91b1e28
Compare
91b1e28 to
3e47c34
Compare
3e47c34 to
01977af
Compare
01977af to
692362b
Compare
692362b to
f0de1d6
Compare
brijeshb42
left a comment
There was a problem hiding this comment.
PR review
One verified, non-blocking issue in global declaration copying.
Bugs (1)
1. 🟠 Preserve dependencies of copied global declarations
Location: packages/code-infra/src/utils/dtsExportsPlugin.mjs:82–87
The plugin copies a global declaration and marks its import external, but never follows that declaration’s references.
Failure scenario: index.d.ts imports ./globals.js; globals.d.ts references ./nested.d.ts and uses a type declared there. The build copies globals.d.ts but omits nested.d.ts. Consumers receive TS6053 (missing file) and TS2304 (missing type).
Verified with the actual build-new handler: source declarations and legacy createTypes output pass TypeScript checking; the new output fails.
Fix: Copy referenced declaration dependencies recursively, or preserve the legacy behavior of copying all source declarations. Add a regression fixture covering this chain.
Tests (0)
No findings.
Simplifications (0)
No findings.
Docs (0)
No findings.
Verdict
Approve after nits — the narrow global-declaration case needs dependency preservation.
Checks: 57 existing build/declaration tests passed; changed JavaScript syntax checks and diff whitespace checks passed. Full repository builds and downstream package validation were not run. No additional hypotheses or pre-existing issues are reported.
No files changed or published; the worktree is clean. No open questions.
Auto-merge was disabled for another pull request in the stack
2bb13f1 to
8c074e5
Compare
8c074e5 to
dff8464
Compare
94a3fee to
11fae2c
Compare
| * @param {string} cwd | ||
| * @returns {Promise<string>} The `tsconfig.build.json` to emit declarations with. | ||
| */ | ||
| async function getTsconfig(cwd) { |
There was a problem hiding this comment.
We don't already have this functionality anywhere in this repo?
There was a problem hiding this comment.
moved it to getTsconfig in typescript.mjs and used it in both build and build-new (6a9abb6). the tsc lookup is different - findTscPair returns the .bin shim, which rolldown-plugin-dts can't spawn on Windows, so build-new resolves the native binary through getExePath
6a9abb6 to
bd6b66d
Compare
Emit declarations through tsdown's dts with the workspace TypeScript 7
`tsc` and the package's `tsconfig.build.json`, as `code-infra build`
does. `--no-buildTypes` skips them.
`cjsDefault: false` keeps CJS declarations on `export default`,
matching the named-exports JS interop.
rolldown-plugin-dts appends `export {}` to declarations, which turns
off implicit exports in hand-written `.d.ts` files. A load plugin adds
`export` to their top-level declarations; it is registered through
`inputOptions` so the CJS declaration pass runs it too.
A .d.ts file without imports or exports declares globals. Bundled by rolldown-plugin-dts it became a module, and the side-effect import that pulled it in was dropped, so published types referenced names that no longer existed. code-infra build keeps both; imports of such files now stay external and the file is copied unchanged.
The declaration plugin only parses and inserts text, so it uses Rolldown's own parser and magic string instead of Babel, which stays for running Babel plugins.
A global declaration that a module imports is copied as-is, but the files it pulls in with `/// <reference path>` were left behind, so consumers hit TS6053 and TS2304. Follow those references recursively and copy the local declarations too, as `code-infra build` ships every source declaration.
rolldown-plugin-dts spawns the tsc path build-new passes it. On Windows node_modules/.bin/tsc is a shell script, so the spawn failed with ENOENT (material-ui's Windows CI). The path now comes from the workspace's TypeScript 7 package through its getExePath, as rolldown-plugin-dts finds tsgo by default.
Re-export imported declarations directly so module augmentation reaches the original interface through package subpaths. Cover CJS and ESM declarations through tsdown and TypeScript 7.
Only `@mui/material`'s `Popover.d.ts` relied on implicit exports, and it now exports its declarations. No package imports a global declaration file, so building without the copy changes no output. What remains is the re-export rewrite module augmentation needs.
build and build-new both need the package's tsconfig.build.json to emit declarations. Use one getTsconfig in typescript.mjs for both.
bd6b66d to
4733bdb
Compare
code-infra build-newnow writes.d.tsfiles, likecode-infra build --tsgo.--no-buildTypesskips them.tsdown generates them with the workspace's TypeScript 7
tscand the package'stsconfig.build.json. On top of that:Re-exports are rewritten. tsdown's declaration bundler turns
export * from './toolbar.js'intoOn TypeScript 7 this breaks augmentation when the same interface is augmented through two packages, as in mui-x Premium:
dtsExportsPluginrewrites the output toexport { Props } from './toolbar.js';, which works liketsc'sexport *output. TS 6 handles both forms.CJS declarations keep
export default(cjsDefault: false), matching the JS output.Babel skips
.d.tsfiles. tsdown passes them through user plugins, and Babel can't parse them.package.jsongetstypesconditions.buildandbuild-newsharegetTsconfig(typescript.mjs) to findtsconfig.build.json.Hand-written
.d.tsfiles need explicitexports: the bundler drops declarations that TypeScript exports implicitly. Only@mui/material'sPopover.d.tsrelied on that; mui/material-ui#49802 fixes it.Known gap: types reached through
export * as nscan fail with TS2694 (6 errors in mui-x charts). #2076 fixes it.Checked against
code-infra build --tsgo:package.jsonis identical, and the exported type names match for docs-infra, test-utils, typescript-api-extractor, benchmark, mui-utils, mui-material and x-internals.dtsExportsPlugin.test.mjsreproduces the Premium case above with TS 7, for CJS and ESM.Part of #413