Skip to content

Commit fbed1a2

Browse files
committed
refactor: prefer __filename when resolving ts version
1 parent e3d49ac commit fbed1a2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import fs from 'node:fs';
55

66
import type { TsConfigJson } from 'get-tsconfig';
77
import type { TransformPluginContext } from 'rollup';
8-
import { fileURLToPath } from 'node:url';
8+
import { fileURLToPath, pathToFileURL } from 'node:url';
99

1010
const cache = new Map<string, TsConfigJson.CompilerOptions>();
1111

@@ -61,8 +61,8 @@ export function getOptions(
6161

6262
export function checkIsLegacyTypeScript() {
6363
try {
64-
// @ts-expect-error -- It's required to using 'import.mtea.url' but i don't want to change the tsconfig.
65-
const tsPath = resolve('typescript/package.json', import.meta.url);
64+
// @ts-expect-error -- It's required to using 'import.meta.url' but i don't want to change the tsconfig.
65+
const tsPath = resolve('typescript/package.json', typeof __filename === 'string' ? pathToFileURL(__filename) : import.meta.url);
6666
const { version } = JSON.parse(fs.readFileSync(fileURLToPath(tsPath), 'utf-8'));
6767
const [major] = version.split('.');
6868
// typescript 5+ enable experimentalDecorators by default so we think it's not legacy

0 commit comments

Comments
 (0)