Skip to content

Commit 363aa90

Browse files
authored
chore: update binding files and minor tweaks (#279)
1 parent 9ceae3b commit 363aa90

4 files changed

Lines changed: 436 additions & 422 deletions

File tree

packages/cli/binding/index.js

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const isMuslFromChildProcess = () => {
6767
function requireNative() {
6868
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
6969
try {
70-
nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
70+
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
7171
} catch (err) {
7272
loadErrors.push(err)
7373
}
@@ -109,7 +109,24 @@ function requireNative() {
109109
}
110110
} else if (process.platform === 'win32') {
111111
if (process.arch === 'x64') {
112+
if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
113+
try {
114+
return require('./vite-plus.win32-x64-gnu.node')
115+
} catch (e) {
116+
loadErrors.push(e)
117+
}
112118
try {
119+
const binding = require('@vite-plus-win32-x64-gnu')
120+
const bindingPackageVersion = require('@vite-plus-win32-x64-gnu/package.json').version
121+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
122+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
123+
}
124+
return binding
125+
} catch (e) {
126+
loadErrors.push(e)
127+
}
128+
} else {
129+
try {
113130
return require('./vite-plus.win32-x64-msvc.node')
114131
} catch (e) {
115132
loadErrors.push(e)
@@ -124,6 +141,7 @@ function requireNative() {
124141
} catch (e) {
125142
loadErrors.push(e)
126143
}
144+
}
127145
} else if (process.arch === 'ia32') {
128146
try {
129147
return require('./vite-plus.win32-ia32-msvc.node')
@@ -349,6 +367,40 @@ function requireNative() {
349367
loadErrors.push(e)
350368
}
351369
}
370+
} else if (process.arch === 'loong64') {
371+
if (isMusl()) {
372+
try {
373+
return require('./vite-plus.linux-loong64-musl.node')
374+
} catch (e) {
375+
loadErrors.push(e)
376+
}
377+
try {
378+
const binding = require('@vite-plus-linux-loong64-musl')
379+
const bindingPackageVersion = require('@vite-plus-linux-loong64-musl/package.json').version
380+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
381+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
382+
}
383+
return binding
384+
} catch (e) {
385+
loadErrors.push(e)
386+
}
387+
} else {
388+
try {
389+
return require('./vite-plus.linux-loong64-gnu.node')
390+
} catch (e) {
391+
loadErrors.push(e)
392+
}
393+
try {
394+
const binding = require('@vite-plus-linux-loong64-gnu')
395+
const bindingPackageVersion = require('@vite-plus-linux-loong64-gnu/package.json').version
396+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
397+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
398+
}
399+
return binding
400+
} catch (e) {
401+
loadErrors.push(e)
402+
}
403+
}
352404
} else if (process.arch === 'riscv64') {
353405
if (isMusl()) {
354406
try {
@@ -478,22 +530,32 @@ function requireNative() {
478530
nativeBinding = requireNative()
479531

480532
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
533+
let wasiBinding = null
534+
let wasiBindingError = null
481535
try {
482-
nativeBinding = require('./vite-plus.wasi.cjs')
536+
wasiBinding = require('./vite-plus.wasi.cjs')
537+
nativeBinding = wasiBinding
483538
} catch (err) {
484539
if (process.env.NAPI_RS_FORCE_WASI) {
485-
loadErrors.push(err)
540+
wasiBindingError = err
486541
}
487542
}
488543
if (!nativeBinding) {
489544
try {
490-
nativeBinding = require('@vite-plus-wasm32-wasi')
545+
wasiBinding = require('@vite-plus-wasm32-wasi')
546+
nativeBinding = wasiBinding
491547
} catch (err) {
492548
if (process.env.NAPI_RS_FORCE_WASI) {
549+
wasiBindingError.cause = err
493550
loadErrors.push(err)
494551
}
495552
}
496553
}
554+
if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
555+
const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
556+
error.cause = wasiBindingError
557+
throw error
558+
}
497559
}
498560

499561
if (!nativeBinding) {
@@ -502,7 +564,12 @@ if (!nativeBinding) {
502564
`Cannot find native binding. ` +
503565
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
504566
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
505-
{ cause: loadErrors }
567+
{
568+
cause: loadErrors.reduce((err, cur) => {
569+
cur.cause = err
570+
return cur
571+
}),
572+
},
506573
)
507574
}
508575
throw new Error(`Failed to load native binding`)

packages/tools/src/sync-remote-deps.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,13 @@ function mergePnpmWorkspaces(
222222
}
223223
}
224224

225-
result.catalog = catalog;
225+
// Sort catalog keys alphabetically
226+
result.catalog = Object.keys(catalog)
227+
.sort()
228+
.reduce((sorted, key) => {
229+
sorted[key] = catalog[key];
230+
return sorted;
231+
}, {} as Record<string, string>);
226232

227233
// Merge minimumReleaseAgeExclude
228234
const excludeSet = new Set(main.minimumReleaseAgeExclude || []);

0 commit comments

Comments
 (0)