chore: shim react/jsx-runtime to compile JSX modules

This commit is contained in:
PalmDevs 2025-05-01 12:11:33 +07:00
parent ce07a1d6bf
commit ddb603211b
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
5 changed files with 24 additions and 2 deletions

View file

@ -8,6 +8,7 @@
"moduleResolution": "bundler",
"verbatimModuleSyntax": true,
"noEmit": true,
"jsx": "preserve",
// Type checking
"strict": true,
"skipLibCheck": true,

View file

@ -2,6 +2,7 @@ import { transform } from '@swc/core'
import { $, main } from 'bun'
import chalk from 'chalk'
import { type OutputChunk, type RolldownPlugin, rolldown } from 'rolldown'
import { aliasPlugin } from 'rolldown/experimental'
import pkg from '../package.json'
@ -33,6 +34,14 @@ export default async function build(dev = false, log = true) {
},
plugins: [
swcPlugin(),
aliasPlugin({
entries: [
{
find: 'react/jsx-runtime',
replacement: './shims/react~jsx-runtime.ts',
},
],
}),
hermesCPlugin({
flags: [
dev ? '-Og' : '-O',

View file

@ -12,7 +12,7 @@ console.info(chalk.redBright(`\nRevenge ${chalk.white(`v${pkg.version}`)}\n`))
const cwdify = (path: string) => join(process.cwd(), path)
const Sources = ['src', 'lib', 'plugins'].map(cwdify)
const ExitTriggers = ['scripts', 'package.json', 'bun.lock'].map(cwdify)
const ExitTriggers = ['scripts', 'shims', 'package.json', 'bun.lock'].map(cwdify)
const debouncedBuildDev = debounce(() => ((needRebuild = false), build(true).catch(console.error)), 250)

View file

@ -0,0 +1,12 @@
import { ReactJsxRuntime } from '@revenge-mod/react'
import { getProxyTarget, isProxy } from '@revenge-mod/utils/proxy'
import type { ElementType } from 'react'
const { jsx: _jsx, jsxs: _jsxs, Fragment } = ReactJsxRuntime
const jsx = ((type, ...args) =>
_jsx(isProxy(type as object) ? (getProxyTarget(type as object) as ElementType) : type, ...args)) as typeof _jsx
const jsxs = ((type, ...args) =>
_jsxs(isProxy(type as object) ? (getProxyTarget(type as object) as ElementType) : type, ...args)) as typeof _jsxs
export { jsx, jsxs, Fragment }

View file

@ -6,5 +6,5 @@
"~plugins/*": ["./plugins/*"]
}
},
"include": ["lib", "plugins", "src"]
"include": ["lib", "plugins", "src", "shims"]
}