Skip to content

Commit

Permalink
fix: TS import issue (#92)
Browse files Browse the repository at this point in the history
* fix ts import issue

* Update vitest.config.ts
  • Loading branch information
fwuensche authored Sep 9, 2024
1 parent 2b3a599 commit bef3eb1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/sh.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import child_process from 'child_process'
import { debug } from './log.ts'
import { debug } from './log.js'

// From https://stackoverflow.com/a/68958420/9847645, to avoid 200Kb limit causing ENOBUFS errors for large output
const sh = (cmd, { throwOnError = true } = {}) =>
Expand Down
26 changes: 23 additions & 3 deletions vitest.config.ts
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],
})

0 comments on commit bef3eb1

Please sign in to comment.