Skip to content

Commit

Permalink
fix(vite.config.ts): generate valid cjs .d.ts files by fixing the inv…
Browse files Browse the repository at this point in the history
…alid ext
  • Loading branch information
waldronmatt committed May 31, 2024
1 parent d9a4db5 commit cfdae68
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/types/cjs/index.c.ts",
"types": "./dist/types/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
}
},
Expand Down
5 changes: 3 additions & 2 deletions packages/ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ export default defineConfig({
// Since TypeScript 5.0, it has emphasized that type files (*.d.ts) are also affected by its ESM and CJS context.
// This means that you can't share a single type file for both ESM and CJS exports of your library.
// You need to have two type files when dual-publishing your library.
// see https://publint.dev/rules#export_types_invalid_format
// see https://www.typescriptlang.org/docs/handbook/modules/reference.html#node16-nodenext and
// https://publint.dev/rules#export_types_invalid_format
await Promise.all(
files.map(async (file) => {
// Generate the new files with the new .c.ts/.c.ts.map naming
const newFilePath = file.replace(/\.d\.ts(\.map)?$/, '.c.ts$1');
const newFilePath = file.replace(/\.d\.ts(\.map)?$/, '.d.cts$1');
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
await fs.move(file, newFilePath, { overwrite: true });
}),
Expand Down
157 changes: 150 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cfdae68

Please sign in to comment.