Skip to content

fix(codegen): format .mts and .cts output files - #5626

Open
kkatalz wants to merge 1 commit into
reduxjs:masterfrom
kkatalz:fix/format-mts-and-cts-output-files
Open

kkatalz wants to merge 1 commit into
reduxjs:masterfrom
kkatalz:fix/format-mts-and-cts-output-files

Conversation

@kkatalz

@kkatalz kkatalz commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Setting outputFile to something like ./api.mts or ./api.cts makes the codegen throw instead of writing the file:

Generating petApi.mts
UndefinedParserError: No parser and no file path given, couldn't infer a parser.

prettify picks the parser from the output file's extension, and EXTENSION_TO_PARSER only knows ts and tsx on the TypeScript side:

parser = EXTENSION_TO_PARSER[fileExtension];

So for mts/cts the parser is undefined, Prettier gets neither a parser nor a file path, and it throws before fs.writeFileSync runs. This adds mts and cts next to ts, both mapped to 'typescript'. I didn't add mjs/cjs, since the generated code is TypeScript either way. Unknown extensions still throw, like the @throws on prettify says.

No issue for this one. It only takes a plain config to hit: outputFile accepts any path, and the package already supports .mts API files under esmExtensions.

The new test.each(['mts', 'cts']) in generateEndpoints.test.ts generates the same options to out.ts and out.<ext> and expects identical files. Both fail on master with the UndefinedParserError and pass here. All 132 codegen tests pass, with no type errors.

`EXTENSION_TO_PARSER` had `ts` and `tsx` but not `mts` or `cts`, so an
`outputFile` ending in `.mts` or `.cts` got no parser and `prettier.format`
threw `UndefinedParserError` before the file was written.
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Prettier parser map now recognizes .mts and .cts files as TypeScript. Tests verify that generated output for both extensions matches .ts output with the same options.

Changes: OpenAPI Code Generation

Layer / File(s) Summary
Map and verify TypeScript extensions
packages/rtk-query-codegen-openapi/src/utils/prettier.ts, packages/rtk-query-codegen-openapi/test/generateEndpoints.test.ts
The parser map assigns the TypeScript parser to .mts and .cts. Tests compare generated output for each extension with .ts output under the same options.
Merge Risk: Minimal · up to 08f64

Codegen with an outputFile ending in .mts or .cts now formats correctly instead of failing with an undefined-parser error. The change is small and tested, and no merge-blocking risk remains.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 45eb037 and 08f64d7.

Files selected for processing: 2

  • packages/rtk-query-codegen-openapi/src/utils/prettier.ts
  • packages/rtk-query-codegen-openapi/test/generateEndpoints.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

@reduxjs/rtk-codemods

npm i https://pkg.pr.new/@reduxjs/rtk-codemods@08f64d7 -D
yarn add https://pkg.pr.new/@reduxjs/rtk-codemods@08f64d7.tgz -D
pnpm add https://pkg.pr.new/@reduxjs/rtk-codemods@08f64d7.tgz -D
bun add https://pkg.pr.new/@reduxjs/rtk-codemods@08f64d7.tgz -D

@rtk-query/codegen-openapi

npm i https://pkg.pr.new/@rtk-query/codegen-openapi@08f64d7 -D
yarn add https://pkg.pr.new/@rtk-query/codegen-openapi@08f64d7.tgz -D
pnpm add https://pkg.pr.new/@rtk-query/codegen-openapi@08f64d7.tgz -D
bun add https://pkg.pr.new/@rtk-query/codegen-openapi@08f64d7.tgz -D

@rtk-query/graphql-request-base-query

npm i https://pkg.pr.new/@rtk-query/graphql-request-base-query@08f64d7 -D
yarn add https://pkg.pr.new/@rtk-query/graphql-request-base-query@08f64d7.tgz -D
pnpm add https://pkg.pr.new/@rtk-query/graphql-request-base-query@08f64d7.tgz -D
bun add https://pkg.pr.new/@rtk-query/graphql-request-base-query@08f64d7.tgz -D

@reduxjs/toolkit

npm i https://pkg.pr.new/@reduxjs/toolkit@08f64d7 -D
yarn add https://pkg.pr.new/@reduxjs/toolkit@08f64d7.tgz -D
pnpm add https://pkg.pr.new/@reduxjs/toolkit@08f64d7.tgz -D
bun add https://pkg.pr.new/@reduxjs/toolkit@08f64d7.tgz -D

commit: 08f64d7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant