mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
5a6e37e5cf
### 🚀 Features -ca649e0ecma: Define math constants as known globals and resolve their types (#26585) (Armano) -9ef028ccodegen: Add `ascii_only` option (#25994) (Samuel Attard) -80a76a0minifier: Negate binary comparison for `typeof x < 'u'` (#26367) (Armano) ### 🐛 Bug Fixes -8ca76daparser: Reject `accessor` modifiers on methods (#26617) (camc314) -1916f31parser: Reject `readonly` modifier on constructors (#26612) (camc314) -1c42008parser: Handle escaped let in for loops (#26583) (camc314) -d21d5cfparser: Recognize annotated empty arrows in conditionals (#26537) (camc314) -d7713adparser: Classify Unicode line breaks in block comments (#26536) (camc314) -75cd919transformer: Preserve receivers in private optional chains (#26535) (camc314) -b32d25dparser: Reject escaped import-phase keywords (#26534) (camc314) -47b8311parser: Recognize contextual binding names in type lookaheads (#26532) (camc314) -d6b6705parser: Require arrow separator in TypeScript function types (#26529) (camc314) -e98beefparser: Disambiguate await using in for initializers (#26527) (camc314) -92afee6parser: Allow parenthesized JSX comma expressions with preserve_parens=false (#26524) (camc314) -31508b1parser: Reject return types on constructor overloads (#26523) (camc314) -a091fc4parser: Validate await context for await using declarations (#26495) (camc314) -5501e86parser: Disallow in expressions in using for-loop initializers (#26490) (camc314) -c8e5fa7parser: Allow escaped type names in import and export specifiers (#26487) (camc314) -2dcee2fparser: Reject async modifiers on class fields (#26486) (camc314) -973d58eparser: Require comma after TypeScript this parameter (#26480) (camc314) -32d00c5codegen: Preserve instantiation expression precedence (#26424) (camc314) -cfa47abparser: Allow `in` expressions in class static blocks (#26423) (camc314) -5986187packages/codegen: Preserve private-in right operand precedence (#26420) (camc314) -f8e6c6cpackages/codegen: Preserve in restriction through yield arguments (#26421) (camc314) -d61e3bfparser: Validate TS named tuple rest elements (#26419) (camc314) -ae6c386codegen: Preserve in restriction through yield arguments (#26413) (camc314) -42ac916codegen: Preserve private-in right operand precedence (#26411) (camc314) -10521b2parser: Allow escaped type default import bindings (#26409) (camc314) -72cb5e3parser: Reject rest parameters in getters (#26400) (camc314) -6e15ad5packages/codegen: Print matching quoted import names as identifiers (#26404) (camc314) -bbbb4bcpackages/codegen: Preserve private-in left operand precedence (#26403) (camc314) -a111b5bpackages/codegen: Print accessibility modifiers before abstract (#26402) (camc314) -4e76602parser: Allow `in` in arrow block bodies within `for` initializers (#26395) (camc314) -b20fc19parser: Reject partially parenthesized mixed coalesce expressions (#26394) (camc314) ### ⚡ Performance -1f902a6isolated_declarations: Key scope maps by `Ident` (#26380) (Dunqing) -a242469minfiier: Reduce allocs when creating indirect access (#26601) (Armano) -5b4787fminifier: Update chain expressions in place (#26544) (Armano) -0bc1661minifier: Try merging before creating new expression statements (#26556) (Armano) -c78d707minifier: Process newly created stmt in handle_if_statement (#26541) (Armano) -029c84bminfier: Update expressions in place when substituting alternate syntax (#26460) (Armano) -d198982codegen: Outline postfix source mapping work (#26450) (camc314) -53f006eecmascript: Format small integer literals with itoa (#26446) (camc314) -8bfb8c0codegen: Avoid duplicate sourcemap name lookups (#26441) (camc314) ### 📚 Documentation -38533acast: Move type annotation span comment to span field (#26522) (camc314)
716 lines
30 KiB
JavaScript
716 lines
30 KiB
JavaScript
/* eslint-disable */
|
|
// @ts-nocheck
|
|
/* auto-generated by NAPI-RS */
|
|
|
|
import { createRequire } from 'module'
|
|
const require = createRequire(import.meta.url)
|
|
|
|
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-relay.android-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-android-arm64')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-android-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.android-arm-eabi.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-android-arm-eabi')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-android-arm-eabi/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.win32-x64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-win32-x64-gnu')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-win32-x64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./transform-relay.win32-x64-msvc.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-win32-x64-msvc')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-win32-x64-msvc/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.win32-ia32-msvc.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-win32-ia32-msvc')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-win32-ia32-msvc/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.win32-arm64-msvc.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-win32-arm64-msvc')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-win32-arm64-msvc/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.darwin-universal.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-darwin-universal')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-darwin-universal/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.darwin-x64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-darwin-x64')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-darwin-x64/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.darwin-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-darwin-arm64')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-darwin-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.freebsd-x64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-freebsd-x64')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-freebsd-x64/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.freebsd-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-freebsd-arm64')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-freebsd-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.linux-x64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-linux-x64-musl')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-x64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./transform-relay.linux-x64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-linux-x64-gnu')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-x64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.linux-arm64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-linux-arm64-musl')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-arm64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./transform-relay.linux-arm64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-linux-arm64-gnu')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-arm64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.linux-arm-musleabihf.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-linux-arm-musleabihf')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-arm-musleabihf/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./transform-relay.linux-arm-gnueabihf.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-linux-arm-gnueabihf')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-arm-gnueabihf/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.linux-loong64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-linux-loong64-musl')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-loong64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./transform-relay.linux-loong64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-linux-loong64-gnu')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-loong64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.linux-riscv64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-linux-riscv64-musl')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-riscv64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./transform-relay.linux-riscv64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-linux-riscv64-gnu')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-riscv64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.linux-ppc64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-linux-ppc64-gnu')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-ppc64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.linux-s390x-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-linux-s390x-gnu')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-s390x-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.openharmony-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-openharmony-arm64')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-openharmony-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.openharmony-x64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-openharmony-x64')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-openharmony-x64/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.openharmony-arm.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-transform-relay/binding-openharmony-arm')
|
|
const bindingPackageVersion = require('@oxc-transform-relay/binding-openharmony-arm/package.json').version
|
|
if (bindingPackageVersion !== '0.150.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.150.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-relay.wasi.cjs', false, ['./transform-relay.wasm32-wasi.debug.wasm', './transform-relay.wasm32-wasi.wasm'])
|
|
candidateFailed = candidateError !== null
|
|
if (!candidateFailed) {
|
|
wasiBinding = require('./transform-relay.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-relay/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-relay/binding-wasm32-wasi/package.json').version
|
|
if (bindingPackageVersion !== '0.150.0') {
|
|
throw new Error(`WASI binding package version mismatch, expected 0.150.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
}
|
|
wasiBinding = require('@oxc-transform-relay/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 }
|