Skip to content

Tsconfig module standardization#113

Draft
amacneil wants to merge 8 commits intomainfrom
cursor/tsconfig-module-standardization-ceb3
Draft

Tsconfig module standardization#113
amacneil wants to merge 8 commits intomainfrom
cursor/tsconfig-module-standardization-ceb3

Conversation

@amacneil
Copy link
Copy Markdown
Contributor

Modernize TypeScript configuration and package exports to standardize all packages to use native ESM.

This PR updates all packages to use native ESM by setting type: module and exports fields in package.json, and extending @foxglove/tsconfig/node.json. It removes legacy CJS build configurations and updates internal imports to use .js extensions. This is a breaking change (semver major) for consumers relying on CJS require(). Workarounds for external dependencies lacking proper NodeNext exports are included.


Open in Cursor Open in Web

Major changes:
- All packages now use type:module for ESM
- Replace main with exports in all package.json
- Extend @foxglove/tsconfig/node.json in all tsconfig files
- Add .js extensions to all relative imports (ESM requirement)
- Delete tsconfig.cjs.json files (no more dual CJS/ESM builds)
- Delete tsconfig.eslint.json and tsconfig.dts.json files
- Update Jest configs for ESM support
- Rename webpack.config.js and neTransformer.js to .cjs
- Add type declarations for packages without NodeNext exports

BREAKING CHANGE: All packages now require ESM imports.
CJS consumers must use dynamic import() instead of require().

Co-authored-by: adrian <adrian@foxglove.dev>
@cursor
Copy link
Copy Markdown
Contributor

cursor Bot commented Jan 30, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

cursoragent and others added 7 commits January 30, 2026 03:05
Co-authored-by: adrian <adrian@foxglove.dev>
- Add NODE_OPTIONS='--experimental-vm-modules' to Jest test scripts for ESM support
- Fix xmlrpc examples with type:module and verbatimModuleSyntax:false
- Use ESM-compatible directory resolution (fileURLToPath) instead of __dirname
- Add jest setup files for custom matchers (rosmsg2-serialization) and polyfills (rosbag2-web)
- Update rosmsg webpack to output ESM format instead of commonjs2
- Fix nearley import for ESM compatibility (use default import)
- Restore benchmark scripts and dependencies to rosmsg-serialization
- Fix CI workflow to call correct package for benchmark

Co-authored-by: adrian <adrian@foxglove.dev>
Consistent ordering: name, version, description, license, private (if relevant),
type:module, keywords, repository, author, homepage, exports, files, bin,
scripts, engines, dependencies, devDependencies

Co-authored-by: adrian <adrian@foxglove.dev>
Co-authored-by: adrian <adrian@foxglove.dev>
The rosmsg package uses webpack to bundle with nearley-loader, which outputs
CommonJS format. Having type:module in package.json caused Node.js to try to
load the CJS bundle as ESM, breaking imports in Jest ESM mode.

Also reverted attempted .ts import extension changes - the approach doesn't
work well with webpack's CJS output and Jest ESM mode due to CJS/ESM interop
issues. Keeping .js extensions in imports.

Co-authored-by: adrian <adrian@foxglove.dev>
The upstream @foxglove/tsconfig/node.json already has rewriteRelativeImportExtensions: true.
Since our source imports already use .js extensions, the rewriting works correctly and
we don't need to override it to false.

Co-authored-by: adrian <adrian@foxglove.dev>
- Remove webpack and related dependencies (ts-loader, nearley-loader, webpack-cli)
- Add compile-grammar.js script to compile nearley grammar to ESM format
- Move moo and nearley from devDependencies to dependencies (runtime requirements)
- Add type: module to package.json now that we output proper ESM
- Remove tsconfig.webpack.json and webpack.config.cjs
- Add ros1Grammar.d.ts for TypeScript type definitions
- Add generated grammar file to .gitignore and eslint ignores

This simplifies the build process by using tsc directly instead of webpack,
resulting in proper ESM output with named exports.

Co-authored-by: adrian <adrian@foxglove.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants