mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
4a4a1fb2e7
### 💥 BREAKING CHANGES -365274epackages/codegen: [**BREAKING**] `printSync` return an object (#25720) (overlookmotel) ### 🚀 Features -6a7eb60packages/codegen: Alter capitalization of `sourceFilename` option (#25854) (overlookmotel) -300763fpackages/codegen: Add full source map support (#25585) (camc314) -a169e4anapi/minify: Expose property name mangling options (#24741) (Dunqing) -2f5cdb1minifier: Add property name mangling (#24740) (Dunqing) -4922141mangler: Deduplicate private accessor names (#25601) (camc314) -1c4f519napi: Add Relay transform plugin (#25503) (Boshen) -a4478e9codegen: Add `oxc-codegen` package (#25488) (overlookmotel) ### 🐛 Bug Fixes -0fbcf64codegen: Validate sourcemap options (#25860) (camc314) -345f981react_compiler: Skip node_modules by default (#25859) (Boshen) -ab81f3fminifier: Drop side-effect-free additions (#25639) (Dunqing) -241c559napi/minify: Accept RegExp for property filters (#25827) (Dunqing) -4cc7ea4codegen: Reject invalid indent options (#25807) (camc314) -53f9295isolated-declarations: Preserve undefined for defaulted any (#25292) (camc314) -8ab883acodegen: Preserve property key annotations (#25766) (Dunqing) -b13fd48minifier: Model uninitialized module vars as undefined (#25497) (Dunqing) -f6000acecmascript: Fold `**` with `Number::exponentiate`, not IEEE `pow` (#25644) (Kotaro Chikuba) -b846abcisolated-declarations: Handle ambient expando properties (#25655) (camc314) -dec0a86react-compiler: Standardize diagnostics (#25702) (Boshen) -fca2e0cparser: Reject initialized lexical declarations in for-in (#25700) (Boshen) -ae9be8fparser: Forbid type parameters on quoted constructors (#25696) (Boshen) -c5f188areact-compiler: Use Babel v1 validation defaults (#25676) (Boshen) -db44651napi: Disable reuseWorker in browser bindings (#25640) (leaysgur) -ce35d47react_compiler: Preserve JSX import source pragmas (#25592) (Boshen) -059784dsemantic: Respect shadowed `Infinity` and `NaN` in enum evaluation (#25604) (camc314) -bb5a232minifier: Keep variable declaration initilized with class when keepNames is enabled (#25584) (sapphi-red) -f49229dminifier: Keep side effects when rotating bitwise operands (#25596) (Kotaro Chikuba) -e82495becmascript: Derive `ToNumber` of `!x` from `ToBoolean` (#25595) (Kotaro Chikuba) -509931bsemantic: Classify global references per identifier (#25608) (camc314) -80484cemangler: Correct base54 safety comment (#25606) (camc314) -c1369a7codegen: Resolve private names in class heritage (#25588) (camc314) -c002f29codegen: Escape sources for empty import specifiers (#25586) (camc314) -0c68b7festree: Emit `decorators` on `FormalParameterRest` (#25582) (camc314) -cdf1846semantic: Allow legacy escapes in JSX attributes (#25576) (Boshen) -e75e102minifier: Preserve block statement in labeled iteration statements (#25162) (Armano) -771d79amangler: Exclude non-manglable symbols from slot assignment (#25539) (sapphi-red) -76b19f5minifier: Avoid duplicating large folded strings (#25532) (Dunqing) -59e8895codegen: Validate starting indent level (#25550) (camc314) -88b34f2clippy: Remove unneeded `unsafe` (#25551) (camc314) -23a7ad0parser: Stop delimited lists at end of file (#25542) (Boshen) -73acba9parser: Preserve fatal errors during await reparse (#25541) (Boshen) -c3e99d1minifier: Avoid invalid octal escapes in template folds (#25495) (Dunqing) -b4e6a9ecodegen: Output newline after `export default interface` (#25487) (overlookmotel) -5fcf683minifier: Correct issue with try finally termination (#25185) (Armano) -1645d93react_compiler: Preserve source spans (#25462) (Boshen) -8d7f9cfreact_compiler: Honor eslint suppressions (#25394) (Boshen) ### ⚡ Performance -568203eecmascript: Use binary search for known globals (#25817) (Boshen) -c84ede3estree_tokens: Share JS token update entry point (#25826) (Boshen) - 9a6e862 minifier: Move owned statements directly (#25835) (Dunqing) -61b2aefminifier: Move owned AST nodes directly (#25837) (Dunqing) -673b04bminifier: Replace expressions without take_in dummies (#25836) (Dunqing) -63ff8eflinter: Outline diagnostic construction (#25762) (Boshen) -621808ediagnostics: Measure graphemes lazily (#25723) (Boshen) -f62ed0ediagnostics: Optimize graphical number rendering (#25715) (Boshen) -7152834diagnostics: Reduce graphical formatting overhead (#25714) (Boshen) -10fc4b7diagnostics: Reduce graphical rendering allocations (#25711) (Boshen) -9c8ababdiagnostics: Batch graphical reports (#25710) (Boshen) -757f3d4mangler: Share allocated names across reused slots (#25605) (camc314) -5444cbfcodegen: Skip escaping harmless `<` tokens (#25564) (camc314) ### 📚 Documentation -58f7ab9packages/codegen: Reformat docs and comments (#25848) (overlookmotel) -627466etransform-react: Document all options (#25800) (Boshen) -ce03ac1packages/codegen: Fix JSDoc comments for `printSync` (#25722) (overlookmotel) -386a699packages/codegen: Correct JSDoc comment (#25716) (overlookmotel) -31e571dmangler: Update code example (#25599) (camc314) -fd62354codegen: Revamp package readme (#25560) (camc314) -ffa3153codegen: Clarify raw transfer Node requirement (#25565) (camc314) -c5d4063codegen: Clarify binary walk allocations (#25562) (camc314) -5703d7acodegen: Correct stale printer comments (#25561) (camc314) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
718 lines
30 KiB
JavaScript
718 lines
30 KiB
JavaScript
// prettier-ignore
|
|
/* eslint-disable */
|
|
// @ts-nocheck
|
|
/* auto-generated by NAPI-RS */
|
|
|
|
import { createRequire } from 'module'
|
|
const require = createRequire(import.meta.url)
|
|
const __dirname = new URL('.', import.meta.url).pathname
|
|
|
|
const { readFileSync } = require('fs')
|
|
let nativeBinding = null
|
|
const loadErrors = []
|
|
|
|
const isMusl = () => {
|
|
let musl = false
|
|
if (process.platform === 'linux') {
|
|
musl = isMuslFromFilesystem()
|
|
if (musl === null) {
|
|
musl = isMuslFromReport()
|
|
}
|
|
if (musl === null) {
|
|
musl = isMuslFromChildProcess()
|
|
}
|
|
}
|
|
return musl
|
|
}
|
|
|
|
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
|
|
const isMuslFromFilesystem = () => {
|
|
try {
|
|
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
const isMuslFromReport = () => {
|
|
let report = null
|
|
if (process.report && typeof process.report.getReport === 'function') {
|
|
process.report.excludeNetwork = true
|
|
report = process.report.getReport()
|
|
}
|
|
if (!report) {
|
|
return null
|
|
}
|
|
if (report.header && report.header.glibcVersionRuntime) {
|
|
return false
|
|
}
|
|
if (Array.isArray(report.sharedObjects)) {
|
|
if (report.sharedObjects.some(isFileMusl)) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
const isMuslFromChildProcess = () => {
|
|
try {
|
|
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
} catch (e) {
|
|
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
return false
|
|
}
|
|
}
|
|
|
|
function requireNative() {
|
|
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
try {
|
|
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
} catch (err) {
|
|
loadErrors.push(err)
|
|
}
|
|
} else if (process.platform === 'android') {
|
|
if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./transform-react.android-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-android-arm64')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-android-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm') {
|
|
try {
|
|
return require('./transform-react.android-arm-eabi.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-android-arm-eabi')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-android-arm-eabi/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'win32') {
|
|
if (process.arch === 'x64') {
|
|
if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
|
|
try {
|
|
return require('./transform-react.win32-x64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-win32-x64-gnu')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-win32-x64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./transform-react.win32-x64-msvc.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-win32-x64-msvc')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-win32-x64-msvc/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'ia32') {
|
|
try {
|
|
return require('./transform-react.win32-ia32-msvc.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-win32-ia32-msvc')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-win32-ia32-msvc/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./transform-react.win32-arm64-msvc.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-win32-arm64-msvc')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-win32-arm64-msvc/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'darwin') {
|
|
try {
|
|
return require('./transform-react.darwin-universal.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-darwin-universal')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-darwin-universal/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
if (process.arch === 'x64') {
|
|
try {
|
|
return require('./transform-react.darwin-x64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-darwin-x64')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-darwin-x64/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./transform-react.darwin-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-darwin-arm64')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-darwin-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'freebsd') {
|
|
if (process.arch === 'x64') {
|
|
try {
|
|
return require('./transform-react.freebsd-x64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-freebsd-x64')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-freebsd-x64/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./transform-react.freebsd-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-freebsd-arm64')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-freebsd-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'linux') {
|
|
if (process.arch === 'x64') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./transform-react.linux-x64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-linux-x64-musl')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-linux-x64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./transform-react.linux-x64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-linux-x64-gnu')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-linux-x64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'arm64') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./transform-react.linux-arm64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-linux-arm64-musl')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-linux-arm64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./transform-react.linux-arm64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-linux-arm64-gnu')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-linux-arm64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'arm') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./transform-react.linux-arm-musleabihf.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-linux-arm-musleabihf')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-linux-arm-musleabihf/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./transform-react.linux-arm-gnueabihf.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-linux-arm-gnueabihf')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-linux-arm-gnueabihf/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'loong64') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./transform-react.linux-loong64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-linux-loong64-musl')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-linux-loong64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./transform-react.linux-loong64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-linux-loong64-gnu')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-linux-loong64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'riscv64') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./transform-react.linux-riscv64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-linux-riscv64-musl')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-linux-riscv64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./transform-react.linux-riscv64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-linux-riscv64-gnu')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-linux-riscv64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'ppc64') {
|
|
try {
|
|
return require('./transform-react.linux-ppc64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-linux-ppc64-gnu')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-linux-ppc64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 's390x') {
|
|
try {
|
|
return require('./transform-react.linux-s390x-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-linux-s390x-gnu')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-linux-s390x-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'openharmony') {
|
|
if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./transform-react.openharmony-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-openharmony-arm64')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-openharmony-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'x64') {
|
|
try {
|
|
return require('./transform-react.openharmony-x64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-openharmony-x64')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-openharmony-x64/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm') {
|
|
try {
|
|
return require('./transform-react.openharmony-arm.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-react/binding-openharmony-arm')
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-openharmony-arm/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
}
|
|
}
|
|
|
|
function createLoadErrorChain(errors) {
|
|
return errors.reduce((previous, current) => {
|
|
let message
|
|
try {
|
|
message =
|
|
current && typeof current.message === 'string'
|
|
? current.message
|
|
: String(current)
|
|
} catch {
|
|
message = 'Unknown error'
|
|
}
|
|
const error = new Error(message)
|
|
error.cause = previous
|
|
return error
|
|
}, null)
|
|
}
|
|
|
|
// NAPI_RS_FORCE_WASI is a tri-state flag:
|
|
// unset / any other value → native binding preferred, WASI is only a fallback
|
|
// 'true' → prefer WASI, but retain native as a lazy fallback
|
|
// 'error' → require WASI without initializing a native fallback
|
|
// Treating any non-empty string as truthy (the historical behavior) meant
|
|
// NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
|
|
// the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
|
|
//
|
|
// NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
|
|
// WASI loading. It never crosses into another flavor or falls back to native.
|
|
const __napiWasiFlavors = ["wasm32-wasi"]
|
|
const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
|
|
const __napiWasiFlavorRequested =
|
|
typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
|
|
if (
|
|
__napiWasiFlavorRequested &&
|
|
__napiWasiFlavors.indexOf(__napiWasiFlavor) === -1
|
|
) {
|
|
throw new Error(
|
|
'Unsupported WASI flavor "' +
|
|
__napiWasiFlavor +
|
|
'". Available flavors: ' +
|
|
__napiWasiFlavors.join(', '),
|
|
)
|
|
}
|
|
const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
|
|
const forceWasi =
|
|
process.env.NAPI_RS_FORCE_WASI === 'true' ||
|
|
forceWasiError ||
|
|
__napiWasiFlavorRequested
|
|
|
|
if (!forceWasi) {
|
|
nativeBinding = requireNative()
|
|
}
|
|
|
|
if (!nativeBinding || forceWasi) {
|
|
let wasiBinding = null
|
|
let wasiBindingLoaded = false
|
|
const wasiBindingErrors = []
|
|
const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
|
|
try {
|
|
require.resolve(specifier)
|
|
} catch (resolveError) {
|
|
if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
|
|
throw resolveError
|
|
}
|
|
if (isPackage) {
|
|
try {
|
|
require.resolve(specifier + '/package.json')
|
|
} catch (packageError) {
|
|
if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
|
|
return resolveError
|
|
}
|
|
// An exports restriction proves the package exists even when its
|
|
// package.json is not public. Preserve the root resolution failure.
|
|
throw resolveError
|
|
}
|
|
// The package exists but its main/export target is broken.
|
|
throw resolveError
|
|
}
|
|
return resolveError
|
|
}
|
|
if (localArtifacts) {
|
|
let artifactError = null
|
|
for (let i = 0; i < localArtifacts.length; i++) {
|
|
try {
|
|
require.resolve(localArtifacts[i])
|
|
return null
|
|
} catch (resolveError) {
|
|
if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
|
|
throw resolveError
|
|
}
|
|
artifactError = resolveError
|
|
}
|
|
}
|
|
return artifactError
|
|
}
|
|
return null
|
|
}
|
|
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
|
|
let candidateError = null
|
|
let candidateFailed = false
|
|
try {
|
|
candidateError = __napiWasiResolveCandidate('./transform-react.wasi.cjs', false, ["./transform-react.wasm32-wasi.debug.wasm","./transform-react.wasm32-wasi.wasm"])
|
|
candidateFailed = candidateError !== null
|
|
if (!candidateFailed) {
|
|
wasiBinding = require('./transform-react.wasi.cjs')
|
|
nativeBinding = wasiBinding
|
|
wasiBindingLoaded = true
|
|
}
|
|
} catch (err) {
|
|
candidateError = err
|
|
candidateFailed = true
|
|
}
|
|
if (candidateFailed) {
|
|
wasiBindingErrors.push(candidateError)
|
|
loadErrors.push(candidateError)
|
|
}
|
|
}
|
|
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
|
|
let candidateError = null
|
|
let candidateFailed = false
|
|
try {
|
|
candidateError = __napiWasiResolveCandidate('@oxc-transform-react/binding-wasm32-wasi', true, undefined)
|
|
candidateFailed = candidateError !== null
|
|
if (!candidateFailed) {
|
|
if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
const bindingPackageVersion = require('@oxc-transform-react/binding-wasm32-wasi/package.json').version
|
|
if (bindingPackageVersion !== '0.145.0') {
|
|
throw new Error(`WASI binding package version mismatch, expected 0.145.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
}
|
|
wasiBinding = require('@oxc-transform-react/binding-wasm32-wasi')
|
|
nativeBinding = wasiBinding
|
|
wasiBindingLoaded = true
|
|
}
|
|
} catch (err) {
|
|
candidateError = err
|
|
candidateFailed = true
|
|
}
|
|
if (candidateFailed) {
|
|
wasiBindingErrors.push(candidateError)
|
|
loadErrors.push(candidateError)
|
|
}
|
|
}
|
|
if (
|
|
!wasiBindingLoaded &&
|
|
forceWasi &&
|
|
!forceWasiError &&
|
|
!__napiWasiFlavorRequested
|
|
) {
|
|
nativeBinding = requireNative()
|
|
}
|
|
if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
|
|
const error = new Error(
|
|
__napiWasiFlavorRequested
|
|
? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
|
|
: 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
|
|
)
|
|
error.cause = createLoadErrorChain(wasiBindingErrors)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
if (!nativeBinding && globalThis.process?.versions?.["webcontainer"]) {
|
|
try {
|
|
nativeBinding = require('./webcontainer-fallback.cjs');
|
|
} catch (err) {
|
|
loadErrors.push(err)
|
|
}
|
|
}
|
|
|
|
if (!nativeBinding) {
|
|
if (loadErrors.length > 0) {
|
|
const error = new Error(
|
|
`Cannot find native binding. ` +
|
|
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
)
|
|
// assign instead of the `new Error(message, { cause })` options form,
|
|
// which Node < 16.9 silently ignores
|
|
error.cause = createLoadErrorChain(loadErrors)
|
|
throw error
|
|
}
|
|
throw new Error(`Failed to load native binding`)
|
|
}
|
|
|
|
const { Severity, transform, transformSync } = nativeBinding
|
|
export { Severity }
|
|
export { transform }
|
|
export { transformSync }
|