Skip to content

Commit 910cd41

Browse files
Copilothi-ogawasapphi-red
authored
fix(react-swc): remove __filename and __dirname checks (#920)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: hi-ogawa <[email protected]> Co-authored-by: sapphi-red <[email protected]> Co-authored-by: 翠 <[email protected]>
1 parent a2d76d9 commit 910cd41

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

packages/plugin-react-swc/src/index.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { readFileSync } from 'node:fs'
2-
import { dirname, join } from 'node:path'
3-
import { fileURLToPath } from 'node:url'
2+
import { join } from 'node:path'
43
import { createRequire } from 'node:module'
54
import {
65
type JscTarget,
@@ -21,15 +20,7 @@ import {
2120
import * as vite from 'vite'
2221
import { exactRegex } from '@rolldown/pluginutils'
2322

24-
/* eslint-disable no-restricted-globals */
25-
const _dirname =
26-
typeof __dirname !== 'undefined'
27-
? __dirname
28-
: dirname(fileURLToPath(import.meta.url))
29-
const resolve = createRequire(
30-
typeof __filename !== 'undefined' ? __filename : import.meta.url,
31-
).resolve
32-
/* eslint-enable no-restricted-globals */
23+
const resolve = createRequire(import.meta.url).resolve
3324

3425
type Options = {
3526
/**
@@ -114,7 +105,8 @@ const react = (_options?: Options): Plugin[] => {
114105
handler: (id) =>
115106
id === runtimePublicPath
116107
? readFileSync(
117-
join(_dirname, 'refresh-runtime.js'),
108+
// eslint-disable-next-line n/no-unsupported-features/node-builtins -- import.meta.dirname is stable in the newer versions and the API has not changed
109+
join(import.meta.dirname, 'refresh-runtime.js'),
118110
'utf-8',
119111
).replace(
120112
/__README_URL__/g,

0 commit comments

Comments
 (0)