Skip to content
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
16 changes: 4 additions & 12 deletions packages/plugin-react-swc/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { readFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { join } from 'node:path'
import { createRequire } from 'node:module'
import {
type JscTarget,
Expand All @@ -21,15 +20,7 @@ import {
import * as vite from 'vite'
import { exactRegex } from '@rolldown/pluginutils'

/* eslint-disable no-restricted-globals */
const _dirname =
typeof __dirname !== 'undefined'
? __dirname
: dirname(fileURLToPath(import.meta.url))
const resolve = createRequire(
typeof __filename !== 'undefined' ? __filename : import.meta.url,
).resolve
/* eslint-enable no-restricted-globals */
const resolve = createRequire(import.meta.url).resolve

type Options = {
/**
Expand Down Expand Up @@ -114,7 +105,8 @@ const react = (_options?: Options): Plugin[] => {
handler: (id) =>
id === runtimePublicPath
? readFileSync(
join(_dirname, 'refresh-runtime.js'),
// 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
join(import.meta.dirname, 'refresh-runtime.js'),
'utf-8',
).replace(
/__README_URL__/g,
Expand Down
Loading