-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix ts import issue * Update vitest.config.ts
- Loading branch information
Showing
2 changed files
with
24 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,27 @@ | ||
import { defineConfig } from 'vitest/config' | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
export default defineConfig({ | ||
test: { | ||
retry: 2, | ||
const fileExists = (filePath: string): boolean => fs.existsSync(filePath) | ||
|
||
const resolveJsToTs = (source: string, importer: string | undefined): string | null => { | ||
if (!importer || !source.endsWith('.js')) return null | ||
|
||
const jsFilePath = path.resolve(path.dirname(importer), source) | ||
const tsFilePath = jsFilePath.replace(/\.js$/, '.ts') | ||
|
||
// If the .js file doesn't exist but the .ts file does, resolve to the .ts file. | ||
return !fileExists(jsFilePath) && fileExists(tsFilePath) ? tsFilePath : null | ||
} | ||
|
||
const jsToTsResolver = { | ||
name: 'jsToTsResolver', | ||
resolveId(source: string, importer: string | undefined) { | ||
return resolveJsToTs(source, importer) | ||
}, | ||
} | ||
|
||
export default defineConfig({ | ||
test: { retry: 2 }, | ||
plugins: [jsToTsResolver], | ||
}) |