|
1 | 1 | import { readFile, opendir } from "node:fs/promises"; |
2 | | -import { URL, fileURLToPath } from "node:url"; |
3 | | - |
4 | | -import { transform } from "sucrase"; |
| 2 | +import process from "node:process"; |
| 3 | +import { URL } from "node:url"; |
5 | 4 |
|
6 | 5 | /** |
7 | 6 | * Maps all the possible import specifier to the absolute URL of the source file. |
@@ -95,18 +94,11 @@ export async function resolve(urlStr, context, next) { |
95 | 94 | } |
96 | 95 |
|
97 | 96 | export async function load(urlStr, context, next) { |
98 | | - const url = new URL(urlStr); |
99 | | - if (url.pathname.endsWith(".ts")) { |
100 | | - const { source } = await next(urlStr, { ...context, format: "module" }); |
101 | | - return { |
102 | | - source: transform(source.toString("utf-8"), { |
103 | | - transforms: ["typescript"], |
104 | | - disableESTransforms: true, |
105 | | - filePath: fileURLToPath(url), |
106 | | - }).code, |
107 | | - format: "module", |
108 | | - }; |
109 | | - } else { |
110 | | - return next(urlStr, context); |
| 97 | + if (!process.features.typescript) { |
| 98 | + const url = new URL(urlStr); |
| 99 | + if (url.pathname.endsWith(".ts")) { |
| 100 | + context = { ...context, format: "module-typescript" }; |
| 101 | + } |
111 | 102 | } |
| 103 | + return next(urlStr, context); |
112 | 104 | } |
0 commit comments