🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

usb

Package Overview
Dependencies
Maintainers
3
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

usb - npm Package Compare versions

Comparing version
3.0.0-alpha.6
to
3.0.0
+21
LICENSE.md
The MIT License (MIT)
Copyright (c) 2026 Rob Moran
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+1
-0

@@ -38,2 +38,3 @@ import { UsbDevice, Emitter } from '../index.js';

protected listenerCount: number;
protected eventListeners: Map<string, Set<EventListener>>;
protected knownDevices: Map<string, UsbDevice>;

@@ -40,0 +41,0 @@ constructor(options?: USBOptions);

+30
-21

@@ -105,2 +105,3 @@ "use strict";

this.listenerCount = 0;
this.eventListeners = new Map();
this.knownDevices = new Map();

@@ -130,5 +131,11 @@ this.deviceConnectCallback = async (device) => {

}
const existingListeners = this.eventListeners.get(type) || new Set();
const hadListeners = this.listenerCount > 0;
super.addEventListener(type, listener);
this.listenerCount++;
if (this.listenerCount === 1) {
if (!existingListeners.has(listener)) {
existingListeners.add(listener);
this.eventListeners.set(type, existingListeners);
this.listenerCount++;
}
if (!hadListeners && this.listenerCount > 0) {
this.nativeEmitter.addAttach(this.deviceConnectCallback);

@@ -143,5 +150,12 @@ this.nativeEmitter.addDetach(this.deviceDisconnectCallback);

}
const existingListeners = this.eventListeners.get(type);
const removed = existingListeners ? existingListeners.delete(callback) : false;
super.removeEventListener(type, callback);
this.listenerCount--;
if (this.listenerCount === 0) {
if (removed) {
this.listenerCount--;
if (existingListeners && existingListeners.size === 0) {
this.eventListeners.delete(type);
}
}
if (removed && this.listenerCount === 0) {
this.nativeEmitter.removeAttach();

@@ -210,21 +224,16 @@ this.nativeEmitter.removeDetach();

}
try {
// If no devicesFound function, select the first device found
const device = this.options.devicesFound ? await this.options.devicesFound(devices) : devices[0];
if (!device) {
throw new NamedError('Failed to execute \'requestDevice\' on \'USB\': No device selected.', 'NotFoundError');
}
this.authorisedDevices.add({
vendorId: device.vendorId,
productId: device.productId,
classCode: device.deviceClass,
subclassCode: device.deviceSubclass,
protocolCode: device.deviceProtocol,
serialNumber: device.serialNumber || undefined
});
return device;
}
catch (error) {
// If no devicesFound function, select the first device found
const device = this.options.devicesFound ? await this.options.devicesFound(devices) : devices[0];
if (!device) {
throw new NamedError('Failed to execute \'requestDevice\' on \'USB\': No device selected.', 'NotFoundError');
}
this.authorisedDevices.add({
vendorId: device.vendorId,
productId: device.productId,
classCode: device.deviceClass,
subclassCode: device.deviceSubclass,
protocolCode: device.deviceProtocol,
serialNumber: device.serialNumber || undefined
});
return device;
}

@@ -231,0 +240,0 @@ /**

+66
-56

@@ -80,4 +80,4 @@ // prettier-ignore

const bindingPackageVersion = require('@node-usb/usb-android-arm64/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -97,4 +97,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-android-arm-eabi/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -119,4 +119,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-win32-x64-gnu/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -136,4 +136,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-win32-x64-msvc/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -154,4 +154,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-win32-ia32-msvc/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -171,4 +171,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-win32-arm64-msvc/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -191,4 +191,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-darwin-universal/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -208,4 +208,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-darwin-x64/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -225,4 +225,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-darwin-arm64/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -246,4 +246,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-freebsd-x64/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -263,4 +263,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-freebsd-arm64/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -285,4 +285,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-linux-x64-musl/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -302,4 +302,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-linux-x64-gnu/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -321,4 +321,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-linux-arm64-musl/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -338,4 +338,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-linux-arm64-gnu/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -357,4 +357,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-linux-arm-musleabihf/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -374,4 +374,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-linux-arm-gnueabihf/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -393,4 +393,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-linux-loong64-musl/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -410,4 +410,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-linux-loong64-gnu/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -429,4 +429,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-linux-riscv64-musl/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -446,4 +446,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-linux-riscv64-gnu/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -464,4 +464,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-linux-ppc64-gnu/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -481,4 +481,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-linux-s390x-gnu/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -502,4 +502,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-openharmony-arm64/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -519,4 +519,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-openharmony-x64/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -536,4 +536,4 @@ return binding

const bindingPackageVersion = require('@node-usb/usb-openharmony-arm/package.json').version
if (bindingPackageVersion !== '3.0.0-alpha.6' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.6 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
if (bindingPackageVersion !== '3.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 3.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}

@@ -554,3 +554,13 @@ return binding

if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
// NAPI_RS_FORCE_WASI is a tri-state flag:
// unset / any other value → native binding preferred, WASI is only a fallback
// 'true' → force WASI fallback even if native loaded
// 'error' → force WASI and throw if no WASI binding is found
// 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.
const forceWasi =
process.env.NAPI_RS_FORCE_WASI === 'true' || process.env.NAPI_RS_FORCE_WASI === 'error'
if (!nativeBinding || forceWasi) {
let wasiBinding = null

@@ -562,7 +572,7 @@ let wasiBindingError = null

} catch (err) {
if (process.env.NAPI_RS_FORCE_WASI) {
if (forceWasi) {
wasiBindingError = err
}
}
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
if (!nativeBinding || forceWasi) {
try {

@@ -572,3 +582,3 @@ wasiBinding = require('@node-usb/usb-wasm32-wasi')

} catch (err) {
if (process.env.NAPI_RS_FORCE_WASI) {
if (forceWasi) {
if (!wasiBindingError) {

@@ -575,0 +585,0 @@ wasiBindingError = err

@@ -5,3 +5,3 @@ {

"license": "MIT",
"version": "3.0.0-alpha.6",
"version": "3.0.0",
"main": "dist/index.js",

@@ -49,2 +49,4 @@ "engines": {

"build:all": "npm run build && npm run build:ts",
"format": "cargo fmt",
"format:check": "cargo fmt -- --check",
"full-test": "mocha --timeout 10000 --require coffeescript/register test/*.coffee",

@@ -58,11 +60,15 @@ "prepublishOnly": "napi prepublish -t npm",

"dependencies": {
"@types/w3c-web-usb": "^1.0.13"
"@types/w3c-web-usb": "^1.0.14"
},
"devDependencies": {
"@napi-rs/cli": "^3.2.0",
"@napi-rs/cli": "^3.7.0",
"coffeescript": "^2.7.0",
"mocha": "^11.7.5",
"typedoc": "^0.28.16",
"typescript": "^5.9.3"
"mocha": "^11.7.6",
"typedoc": "^0.28.19",
"typescript": "^6.0.3"
},
"overrides": {
"diff": "9.0.0",
"serialize-javascript": "7.0.5"
},
"napi": {

@@ -90,13 +96,13 @@ "binaryName": "usb",

"optionalDependencies": {
"@node-usb/usb-win32-x64-msvc": "3.0.0-alpha.6",
"@node-usb/usb-darwin-x64": "3.0.0-alpha.6",
"@node-usb/usb-linux-x64-gnu": "3.0.0-alpha.6",
"@node-usb/usb-linux-x64-musl": "3.0.0-alpha.6",
"@node-usb/usb-linux-arm64-gnu": "3.0.0-alpha.6",
"@node-usb/usb-win32-ia32-msvc": "3.0.0-alpha.6",
"@node-usb/usb-linux-arm-gnueabihf": "3.0.0-alpha.6",
"@node-usb/usb-darwin-arm64": "3.0.0-alpha.6",
"@node-usb/usb-linux-arm64-musl": "3.0.0-alpha.6",
"@node-usb/usb-win32-arm64-msvc": "3.0.0-alpha.6"
"@node-usb/usb-win32-x64-msvc": "3.0.0",
"@node-usb/usb-darwin-x64": "3.0.0",
"@node-usb/usb-linux-x64-gnu": "3.0.0",
"@node-usb/usb-linux-x64-musl": "3.0.0",
"@node-usb/usb-linux-arm64-gnu": "3.0.0",
"@node-usb/usb-win32-ia32-msvc": "3.0.0",
"@node-usb/usb-linux-arm-gnueabihf": "3.0.0",
"@node-usb/usb-darwin-arm64": "3.0.0",
"@node-usb/usb-linux-arm64-musl": "3.0.0",
"@node-usb/usb-win32-arm64-msvc": "3.0.0"
}
}

@@ -11,2 +11,4 @@ # USB Library for Node.JS

For the previous v2.x.x version of node-usb, please see https://github.com/node-usb/node-usb.
# License

@@ -155,8 +157,10 @@ [MIT](LICENSE.md)

# APIs
Since `v3.0.0`, the `node-usb` API follows the WebUSB specification which can be found here:
Since `v3.0.0`, the API exclusively follows the WebUSB specification which can be found here:
https://wicg.github.io/webusb/
Two versions of the WebUSB API exist by default:
If you want to use the older `Legacy API`, please install [v2.x.x of node-usb](https://github.com/node-usb/node-usb).
Two versions of the API exist by default:
- `usb` - which exposes all functionality in an unrestricted manner (e.g. without needing to `requestDevice()` first)

@@ -163,0 +167,0 @@ - `webusb` - which follows the WebUSB specification exactly and requires the user to authorise devices via `requestDevice()` first.

The MIT License (MIT)
Copyright (c) 2026 Rob Moran
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.