Skip to content
Merged
Show file tree
Hide file tree
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
77 changes: 72 additions & 5 deletions packages/cli/binding/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const isMuslFromChildProcess = () => {
function requireNative() {
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
try {
nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
} catch (err) {
loadErrors.push(err)
}
Expand Down Expand Up @@ -109,7 +109,24 @@ function requireNative() {
}
} else if (process.platform === 'win32') {
if (process.arch === 'x64') {
if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
try {
return require('./vite-plus.win32-x64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@vite-plus-win32-x64-gnu')
const bindingPackageVersion = require('@vite-plus-win32-x64-gnu/package.json').version
if (bindingPackageVersion !== '0.0.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.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
Comment thread
fengmk2 marked this conversation as resolved.
try {
return require('./vite-plus.win32-x64-msvc.node')
} catch (e) {
loadErrors.push(e)
Expand All @@ -124,6 +141,7 @@ function requireNative() {
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'ia32') {
try {
return require('./vite-plus.win32-ia32-msvc.node')
Expand Down Expand Up @@ -349,6 +367,40 @@ function requireNative() {
loadErrors.push(e)
}
}
} else if (process.arch === 'loong64') {
if (isMusl()) {
try {
return require('./vite-plus.linux-loong64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@vite-plus-linux-loong64-musl')
const bindingPackageVersion = require('@vite-plus-linux-loong64-musl/package.json').version
if (bindingPackageVersion !== '0.0.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.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./vite-plus.linux-loong64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@vite-plus-linux-loong64-gnu')
const bindingPackageVersion = require('@vite-plus-linux-loong64-gnu/package.json').version
if (bindingPackageVersion !== '0.0.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.0.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 {
Expand Down Expand Up @@ -478,22 +530,32 @@ function requireNative() {
nativeBinding = requireNative()

if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
let wasiBinding = null
let wasiBindingError = null
try {
nativeBinding = require('./vite-plus.wasi.cjs')
wasiBinding = require('./vite-plus.wasi.cjs')
nativeBinding = wasiBinding
} catch (err) {
if (process.env.NAPI_RS_FORCE_WASI) {
loadErrors.push(err)
wasiBindingError = err
}
}
if (!nativeBinding) {
try {
nativeBinding = require('@vite-plus-wasm32-wasi')
wasiBinding = require('@vite-plus-wasm32-wasi')
nativeBinding = wasiBinding
} catch (err) {
if (process.env.NAPI_RS_FORCE_WASI) {
wasiBindingError.cause = err
Comment thread
Brooooooklyn marked this conversation as resolved.
loadErrors.push(err)
}
}
}
if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
error.cause = wasiBindingError
throw error
}
}

if (!nativeBinding) {
Expand All @@ -502,7 +564,12 @@ if (!nativeBinding) {
`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.',
{ cause: loadErrors }
{
cause: loadErrors.reduce((err, cur) => {
cur.cause = err
return cur
}),
Comment thread
Brooooooklyn marked this conversation as resolved.
},
)
}
throw new Error(`Failed to load native binding`)
Expand Down
8 changes: 7 additions & 1 deletion packages/tools/src/sync-remote-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,13 @@ function mergePnpmWorkspaces(
}
}

result.catalog = catalog;
// Sort catalog keys alphabetically
result.catalog = Object.keys(catalog)
.sort()
.reduce((sorted, key) => {
sorted[key] = catalog[key];
return sorted;
}, {} as Record<string, string>);

// Merge minimumReleaseAgeExclude
const excludeSet = new Set(main.minimumReleaseAgeExclude || []);
Expand Down
Loading