Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use file url to import tsx at runtime #1171

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/config/ts-path.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {access} from 'node:fs/promises'
import {join, relative as pathRelative, sep} from 'node:path'
import {pathToFileURL} from 'node:url'
import * as TSNode from 'ts-node'

import Cache from '../cache'
Expand Down Expand Up @@ -85,11 +86,15 @@ async function registerTsx(root: string, moduleType: 'commonjs' | 'module' | und
if (!tsxPath) return
debug('registering tsx at', root)
debug('tsx path:', tsxPath)
const {register} = await import(tsxPath)
const {href} = pathToFileURL(tsxPath)
debug('tsx href:', href)
const {register} = await import(href)
debug('Successfully imported tsx')
register()
REGISTERED.add(root)
} catch {
} catch (error) {
debug(`Could not find tsx. Skipping tsx registration for ${root}.`)
debug(error)
}
}

Expand All @@ -104,8 +109,10 @@ async function registerTSNode(root: string, tsconfig: TSConfig): Promise<void> {

try {
tsNode = require(tsNodePath)
} catch {
debug('Successfully required ts-node')
} catch (error) {
debug(`Could not find ts-node at ${tsNodePath}. Skipping ts-node registration for ${root}.`)
debug(error)
memoizedWarn(
`Could not find ts-node at ${tsNodePath}. Please ensure that ts-node is a devDependency. Falling back to compiled source.`,
)
Expand Down
Loading