-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add runtime loader to rewrite .ts paths
- Loading branch information
Showing
5 changed files
with
34 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { URL } from "node:url" | ||
import { existsSync } from "node:fs" | ||
import path from "node:path" | ||
|
||
export async function resolve(specifier, context, nextResolve) { | ||
// Only handle relative or absolute paths without extensions | ||
if ( | ||
(specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/")) && | ||
!path.extname(specifier) | ||
) { | ||
// Try with .ts extension first | ||
const tsFile = `${specifier}.ts` | ||
const resolvedTsPath = new URL(tsFile, context.parentURL).href | ||
return { | ||
url: resolvedTsPath, | ||
shortCircuit: true, | ||
} | ||
} | ||
|
||
// Let Node.js handle it if no match | ||
return nextResolve(specifier) | ||
} |
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
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