Skip to content

Commit

Permalink
fix(vite.config.ts): try manually fixing the sourcemap url refs in .d…
Browse files Browse the repository at this point in the history
….cts files
  • Loading branch information
waldronmatt committed May 31, 2024
1 parent 4963719 commit e375b45
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 150 deletions.
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "20.11.30",
"@types/react": "18.2.73",
"@types/react-dom": "18.2.23",
"@vitejs/plugin-react-swc": "3.6.0",
Expand Down
23 changes: 22 additions & 1 deletion packages/ui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */
import { defineConfig } from 'vite';
import fs from 'fs-extra';
import react from '@vitejs/plugin-react-swc';
Expand Down Expand Up @@ -36,11 +40,28 @@ export default defineConfig({
// see https://www.typescriptlang.org/docs/handbook/modules/reference.html#node16-nodenext and
// https://publint.dev/rules#export_types_invalid_format
await Promise.all(
// Ideally, this plugin will support different types in the future
// See https://github.com/qmhc/vite-plugin-dts/issues/267
files.map(async (file) => {
// Generate the new files with the new .c.ts/.c.ts.map naming
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 });

// Update sourceMappingURL references
if (newFilePath.endsWith('.d.cts')) {
const content = await fs.readFile(newFilePath, 'utf-8');
const updatedContent = content.replace(/\/\/# sourceMappingURL=.*\.d\.ts\.map/g, (match) =>
match.replace('.d.ts.map', '.d.cts.map'),
);
await fs.writeFile(newFilePath, updatedContent, 'utf-8');
}

// Update source map file references
if (newFilePath.endsWith('.d.cts.map')) {
const content = await fs.readJson(newFilePath);
content.file = content.file.replace('.d.ts', '.d.cts');
await fs.writeJson(newFilePath, content);
}
}),
);
},
Expand Down
157 changes: 8 additions & 149 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 e375b45

Please sign in to comment.