From 78f9787502d45f8b4909d5509748b0f95ea36c0b Mon Sep 17 00:00:00 2001 From: NullVoxPopuli-ai-agent Date: Fri, 5 Jun 2026 16:17:16 -0400 Subject: [PATCH] fix(loaders): make generated binding loaders Node 12 compatible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The NAPI-RS-generated binding loaders are not parseable by Node 12, which the packages still declare support for (engines: ">= 12"): - `require('node:fs')` — the `node:` scheme in CommonJS `require()` is only supported on Node >= 14.18 / 16, so it throws on Node 12. - `process.report?.getReport` / `process.config?.variables?.…` — optional chaining (`?.`) landed in Node 14, so Node 12 fails to parse the module entirely. Downlevel both to plain `require('fs')` and `&&` guards so the loaders load on every Node version the packages claim to support. Applies to all six native binding loaders. Co-Authored-By: Claude Opus 4.8 (1M context) --- packages/argon2/index.js | 6 +++--- packages/bcrypt/binding.js | 6 +++--- packages/crc32/index.js | 6 +++--- packages/jieba/index.js | 6 +++--- packages/jsonwebtoken/index.js | 6 +++--- packages/xxhash/index.js | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/argon2/index.js b/packages/argon2/index.js index c99b2c50..10b05c52 100644 --- a/packages/argon2/index.js +++ b/packages/argon2/index.js @@ -3,7 +3,7 @@ // @ts-nocheck /* auto-generated by NAPI-RS */ -const { readFileSync } = require('node:fs') +const { readFileSync } = require('fs') let nativeBinding = null const loadErrors = [] @@ -33,7 +33,7 @@ const isMuslFromFilesystem = () => { const isMuslFromReport = () => { let report = null - if (typeof process.report?.getReport === 'function') { + if (process.report && typeof process.report.getReport === 'function') { process.report.excludeNetwork = true report = process.report.getReport() } @@ -105,7 +105,7 @@ 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') { + 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('./argon2.win32-x64-gnu.node') } catch (e) { diff --git a/packages/bcrypt/binding.js b/packages/bcrypt/binding.js index 14e7acd8..a2f830b9 100644 --- a/packages/bcrypt/binding.js +++ b/packages/bcrypt/binding.js @@ -3,7 +3,7 @@ // @ts-nocheck /* auto-generated by NAPI-RS */ -const { readFileSync } = require('node:fs') +const { readFileSync } = require('fs') let nativeBinding = null const loadErrors = [] @@ -33,7 +33,7 @@ const isMuslFromFilesystem = () => { const isMuslFromReport = () => { let report = null - if (typeof process.report?.getReport === 'function') { + if (process.report && typeof process.report.getReport === 'function') { process.report.excludeNetwork = true report = process.report.getReport() } @@ -105,7 +105,7 @@ 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') { + 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('./bcrypt.win32-x64-gnu.node') } catch (e) { diff --git a/packages/crc32/index.js b/packages/crc32/index.js index e1ff8e20..35cf23d1 100644 --- a/packages/crc32/index.js +++ b/packages/crc32/index.js @@ -3,7 +3,7 @@ // @ts-nocheck /* auto-generated by NAPI-RS */ -const { readFileSync } = require('node:fs') +const { readFileSync } = require('fs') let nativeBinding = null const loadErrors = [] @@ -33,7 +33,7 @@ const isMuslFromFilesystem = () => { const isMuslFromReport = () => { let report = null - if (typeof process.report?.getReport === 'function') { + if (process.report && typeof process.report.getReport === 'function') { process.report.excludeNetwork = true report = process.report.getReport() } @@ -105,7 +105,7 @@ 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') { + 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('./crc32.win32-x64-gnu.node') } catch (e) { diff --git a/packages/jieba/index.js b/packages/jieba/index.js index 548b56c6..58ed2e30 100644 --- a/packages/jieba/index.js +++ b/packages/jieba/index.js @@ -3,7 +3,7 @@ // @ts-nocheck /* auto-generated by NAPI-RS */ -const { readFileSync } = require('node:fs') +const { readFileSync } = require('fs') let nativeBinding = null const loadErrors = [] @@ -33,7 +33,7 @@ const isMuslFromFilesystem = () => { const isMuslFromReport = () => { let report = null - if (typeof process.report?.getReport === 'function') { + if (process.report && typeof process.report.getReport === 'function') { process.report.excludeNetwork = true report = process.report.getReport() } @@ -105,7 +105,7 @@ 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') { + 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('./jieba.win32-x64-gnu.node') } catch (e) { diff --git a/packages/jsonwebtoken/index.js b/packages/jsonwebtoken/index.js index cc98387e..5866e0cf 100644 --- a/packages/jsonwebtoken/index.js +++ b/packages/jsonwebtoken/index.js @@ -3,7 +3,7 @@ // @ts-nocheck /* auto-generated by NAPI-RS */ -const { readFileSync } = require('node:fs') +const { readFileSync } = require('fs') let nativeBinding = null const loadErrors = [] @@ -33,7 +33,7 @@ const isMuslFromFilesystem = () => { const isMuslFromReport = () => { let report = null - if (typeof process.report?.getReport === 'function') { + if (process.report && typeof process.report.getReport === 'function') { process.report.excludeNetwork = true report = process.report.getReport() } @@ -105,7 +105,7 @@ 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') { + 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('./jsonwebtoken.win32-x64-gnu.node') } catch (e) { diff --git a/packages/xxhash/index.js b/packages/xxhash/index.js index 5e6bdd5a..ec677c46 100644 --- a/packages/xxhash/index.js +++ b/packages/xxhash/index.js @@ -3,7 +3,7 @@ // @ts-nocheck /* auto-generated by NAPI-RS */ -const { readFileSync } = require('node:fs') +const { readFileSync } = require('fs') let nativeBinding = null const loadErrors = [] @@ -33,7 +33,7 @@ const isMuslFromFilesystem = () => { const isMuslFromReport = () => { let report = null - if (typeof process.report?.getReport === 'function') { + if (process.report && typeof process.report.getReport === 'function') { process.report.excludeNetwork = true report = process.report.getReport() } @@ -105,7 +105,7 @@ 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') { + 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('./xxhash.win32-x64-gnu.node') } catch (e) {