Skip to content

Error: No native build was found for platform #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
chandirag opened this issue May 20, 2024 · 9 comments
Open

Error: No native build was found for platform #66

chandirag opened this issue May 20, 2024 · 9 comments

Comments

@chandirag
Copy link

What version of pkg are you using?

5.10.0

What version of Node.js are you using?

18.18.2

What operating system are you using?

Ubuntu 22.04.4 LTS

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

node18-linuxstatic-armv7

Describe the Bug

My project uses the node-serialport library. I am getting the following error when trying to run the compiled binary:

pkg/prelude/bootstrap.js:1872
      throw error;
      ^

Error: No native build was found for platform=linux arch=arm runtime=node abi=108 uv=1 armv=default libc=glibc node=18.18.2
    loaded from: /snapshot/my-project/node_modules/@serialport/bindings-cpp

    at Function.<anonymous> (/snapshot/my-project/node_modules/node-gyp-build/node-gyp-build.js:60:9)
    at load (/snapshot/my-project/node_modules/node-gyp-build/node-gyp-build.js:22:30)
    at Object.<anonymous> (/snapshot/my-project/node_modules/@serialport/bindings-cpp/dist/load-bindings.js:11:46)
    at Module._compile (pkg/prelude/bootstrap.js:1930:22)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at Module.require (pkg/prelude/bootstrap.js:1851:31)
    at require (node:internal/modules/cjs/helpers:119:18)

Node.js v18.18.2

I also get the following warning during compilation (when running npm run package):

> [email protected]
prebuild-install warn install No prebuilt binaries found (target=18.18.2 runtime=node arch=armv7 libc= platform=undefined)
prebuild-install warn install No prebuilt binaries found (target=18.18.2 runtime=node arch=armv7 libc= platform=undefined)
prebuild-install warn install No prebuilt binaries found (target=18.18.2 runtime=node arch=armv7 libc= platform=undefined)
prebuild-install warn install No prebuilt binaries found (target=18.18.2 runtime=node arch=armv7 libc= platform=undefined)
prebuild-install warn install No prebuilt binaries found (target=18.18.2 runtime=node arch=armv7 libc= platform=undefined)
prebuild-install warn install No prebuilt binaries found (target=18.18.2 runtime=node arch=armv7 libc= platform=undefined)
prebuild-install warn install No prebuilt binaries found (target=18.18.2 runtime=node arch=armv7 libc= platform=undefined)
prebuild-install warn install No prebuilt binaries found (target=18.18.2 runtime=node arch=armv7 libc= platform=undefined)
prebuild-install warn install No prebuilt binaries found (target=18.18.2 runtime=node arch=armv7 libc= platform=undefined)
prebuild-install warn install No prebuilt binaries found (target=18.18.2 runtime=node arch=armv7 libc= platform=undefined)
prebuild-install warn install No prebuilt binaries found (target=v18.18.2 runtime=node arch=armv7 libc= platform=undefined)

I have the following package.json:

{
	"name": "my-project",
	"version": "0.0.1",
	"description": "",
	"bin": "dist/src/main.js",
	"scripts": {
		"build": "nest build",
		"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
		"start": "nest start",
		"package": "npm run build && mkdir -p bin && npx pkg ."
	},
	"dependencies": {
		"@nestjs/common": "^10.0.0",
		"@nestjs/config": "^3.2.2",
		"@nestjs/core": "^10.0.0",
		"@nestjs/platform-express": "^10.0.0",
		...
		"serialport": "^10.5.0",
	},
	"devDependencies": {
		"@nestjs/cli": "^10.0.0",
		"@nestjs/schematics": "^10.0.0",
		"@nestjs/testing": "^10.3.8",
		...
	},
	"pkg": {
		"scripts": "dist/**/*.js",
		"targets": [
			"node18-linuxstatic-armv7"
		],
		"assets": [
			"./node_modules/@serialport/bindings-cpp/**"
		],
		"outputPath": "bin"
	}
}

What I've already tried:

  • Downgrading serialport. Tried the latest (v12.0.0) as well as older versions (v10.5.0)
  • Tried adding the following under pkg "assets" (#61, #1903, #1660):
    • "./node_modules/@serialport/bindings-cpp/**"
    • "./node_modules/@serialport/bindings-cpp/prebuilds",
    • "./node_modules/@serialport/**/*"
  • I also tried copying the prebuilds directory to the same directory as the output 'bin/' #1660

I still keep getting the above error. Any help is appreciated.

Expected Behavior

Compiled binary to execute without throwing Error: No native build was found for platform=linux arch=arm runtime=node abi=108 uv=1 armv=default libc=glibc node=18.18.2

To Reproduce

Compiling any new node project which utilizes the serial port library

  • Serialport v12.0.0
  • pkg v5.10.0
  • node v18.18.2
@DaniRey
Copy link

DaniRey commented Apr 17, 2025

@chandirag did you ever resolve this issue?

We are facing the same problem with

pkg: 6.3.2
node: 22.13.1
serialport: 12.0.1

We try to build for a Raspberry Pi 4 Model B Rev 1.5 with BCM2835.

When removing the serialport dependency, we can run both node22-linuxstatic-arm64 and node22-linuxstatic-armv7. My understanding is, that we have a 32bit armv7 chip, nevertheless both executable work.

After adding the dependency they both fail with different errors.

node22-linuxstatic-arm64

pkg/prelude/bootstrap.js:1876
      throw error;
      ^

Error: Dynamic loading not supported
    at process.dlopen (pkg/prelude/bootstrap.js:2260:28)
    at Module._extensions..node (node:internal/modules/cjs/loader:1729:18)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
    at Module._load (node:internal/modules/cjs/loader:1127:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at Module.require (pkg/prelude/bootstrap.js:1855:31)
    at require (node:internal/modules/helpers:136:16)
    at load (/snapshot/ibn-app-2/node_modules/node-gyp-build/node-gyp-build.js:22:10) {
  code: 'ERR_DLOPEN_FAILED'
}

Node.js v22.13.1

node22-linuxstatic-armv7

pkg/prelude/bootstrap.js:1876
      throw error;
      ^

Error: No native build was found for platform=linux arch=arm runtime=node abi=127 uv=1 armv=default libc=glibc node=22.13.1
    loaded from: /snapshot/ibn-app-2/node_modules/@serialport/bindings-cpp

    at load.resolve.load.path (/snapshot/ibn-app-2/node_modules/node-gyp-build/node-gyp-build.js:60:9)
    at load (/snapshot/ibn-app-2/node_modules/node-gyp-build/node-gyp-build.js:22:30)
    at Object.<anonymous> (/snapshot/ibn-app-2/node_modules/@serialport/bindings-cpp/dist/load-bindings.js:11:46)
    at Module._compile (node:internal/modules/cjs/loader:1566:14)
    at Module._compile (pkg/prelude/bootstrap.js:1941:32)
    at Module._extensions..js (node:internal/modules/cjs/loader:1703:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
    at Module._load (node:internal/modules/cjs/loader:1127:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)

Node.js v22.13.1

When I add export DEBUG_PKG=1 to the console and build the executable with --debug, I get the following files listed.

      @serialport                           1.7 MB 
        binding-mock                       11.5 KB 
          package.json                      1.5 KB 
          dist                              9.9 KB 
            index.js                        9.9 KB 
        bindings-cpp                        1.6 MB 
          package.json                      2.8 KB 
          prebuilds                         1.5 MB 
            android-arm                    91.2 KB 
              node.napi.armv7.node         91.2 KB 
            android-arm64                 129.4 KB 
              node.napi.armv8.node        129.4 KB 
            darwin-x64+arm64              282.3 KB 
              node.napi.node              282.3 KB 
            linux-arm                     228.6 KB 
              node.napi.armv6.node        114.3 KB 
              node.napi.armv7.node        114.3 KB 
            linux-arm64                   143.3 KB 
              node.napi.armv8.node        143.3 KB 
            linux-x64                     301.5 KB 
              node.napi.glibc.node        151.3 KB 
              node.napi.musl.node         150.2 KB 
            win32-ia32                    175.0 KB 
              node.napi.node              175.0 KB 
            win32-x64                     224.0 KB 
              node.napi.node              224.0 KB 
          dist                             32.4 KB 
            index.js                        1.9 KB 
            darwin.js                       5.1 KB 
            linux.js                        5.2 KB 
            win32.js                        5.6 KB 
            errors.js                    304 Bytes 
            load-bindings.js                2.3 KB 
            poller.js                       3.4 KB 
            unix-read.js                    2.2 KB 
            unix-write.js                   2.4 KB 
            linux-list.js                   3.5 KB 
            win32-sn-parser.js           463 Bytes 
          node_modules                     48.5 KB 
            debug                          41.4 KB 
              package.json                  1.4 KB 
              LICENSE                       1.1 KB 
              README.md                    22.0 KB 
              src                          16.9 KB 
                index.js                 314 Bytes 
                browser.js                  5.9 KB 
                common.js                   6.1 KB 
                node.js                     4.6 KB 
            ms                              3.6 KB 
              package.json               705 Bytes 
              index.js                      3.0 KB 
            @serialport                     3.5 KB 
              parser-readline               1.5 KB 
                package.json             652 Bytes 
                dist                     866 Bytes 
                  index.js               866 Bytes 
              parser-delimiter              2.0 KB 
                package.json             583 Bytes 
                dist                        1.4 KB 
                  index.js                  1.4 KB 
        parser-byte-length                  2.0 KB 
          package.json                   585 Bytes 
          dist                              1.4 KB 
            index.js                        1.4 KB 
        parser-cctalk                       2.3 KB 
          package.json                   580 Bytes 
          dist                              1.7 KB 
            index.js                        1.7 KB 
        parser-delimiter                    2.1 KB 
          package.json                   583 Bytes 
          dist                              1.5 KB 
            index.js                        1.5 KB 
        parser-inter-byte-timeout           2.6 KB 
          package.json                   592 Bytes 
          dist                              2.1 KB 
            index.js                        2.1 KB 
        parser-packet-length                2.7 KB 
          package.json                   525 Bytes 
          dist                              2.2 KB 
            index.js                        2.2 KB 
        parser-readline                     1.5 KB 
          package.json                   652 Bytes 
          dist                           866 Bytes 
            index.js                     866 Bytes 
        parser-ready                        2.3 KB 
          package.json                   579 Bytes 
          dist                              1.7 KB 
            index.js                        1.7 KB 
        parser-regex                        1.9 KB 
          package.json                   579 Bytes 
          dist                              1.3 KB 
            index.js                        1.3 KB 
        parser-slip-encoder                 6.1 KB 
          package.json                   586 Bytes 
          dist                              5.5 KB 
            index.js                     847 Bytes 
            decoder.js                      2.5 KB 
            encoder.js                      2.1 KB 
        parser-spacepacket                  7.3 KB 
          package.json                   585 Bytes 
          dist                              6.7 KB 
            index.js                        5.1 KB 
            utils.js                        1.6 KB 
        stream                             61.4 KB 
          package.json                   709 Bytes 
          dist                             15.7 KB 
            index.js                       15.7 KB 
          node_modules                     45.0 KB 
            debug                          41.4 KB 
              package.json                  1.4 KB 
              LICENSE                       1.1 KB 
              README.md                    22.0 KB 
              src                          16.9 KB 
                index.js                 314 Bytes 
                browser.js                  5.9 KB 
                common.js                   6.1 KB 
                node.js                     4.6 KB 
            ms                              3.6 KB 
              package.json               705 Bytes 
              index.js                      3.0 KB 
        bindings-interface                  1.3 KB 
          package.json                      1.3 KB 
          dist                            15 Bytes 
            index.js                      15 Bytes 

Any ideas on how to solve this issue?

@DaniRey
Copy link

DaniRey commented Apr 17, 2025

Totally forgot to mention. We also build a Windows version, which works like a charm.

What also works is copying the target\transpiled folder to a RaspberryPi and running it with a pre-installed node version.

Therefore I assume it is either an issue with the pre-built node executable, or with the selection of the correct pre-built version of serialport.

This is an extract of our package.json

  "bin": "target/transpiled/bundle.cjs",
  "pkg": {
    "targets": [
      "node22-win-x64",
      "node22-linuxstatic-arm64",
      "node22-linuxstatic-armv7"
    ],
    "assets": [
      "target/transpiled",
      "node_modules/node-gyp-build/**",
      "node_modules/@serialport/bindings-cpp/**"
    ],
    "outputPath": "target/bin"
  },
  "scripts": {
    "dev": "nodemon -x tsx src/main.ts",
    "serve": "node target/transpiled/bundle.cjs",
    "vite": "vite",
    "build": "vite build --emptyOutDir --mode production",
    "roll": "rollup --config",
    "dist-win": "pkg . --no-bytecode --public-packages \"*\" --public --debug -C GZip",
    "dist": "npm run build && npm run roll && npm run dist-win"
  }

@robertsLando
Copy link
Member

Please share pkg command output with --debug flag. Then run the result package with DEBUG_PKG=2 env var and share the run output as well

Does this happens also with older pkg versions?

@DaniRey
Copy link

DaniRey commented Apr 17, 2025

Thanks a lot for your feedback @robertsLando

I just checked with pkg 5.16.1 instead of 6.3.2, the result is the same. Let me know, if I should check with a specific other version, or different node version.

Log of pkg command with --debug

logs_37302883146.zip

Log of start of node22_linuxstatic_armv7 executable with DEBUG_PKG=2

linuxstatic_armv7_debug2.txt

@robertsLando
Copy link
Member

robertsLando commented Apr 18, 2025

@DaniRey The most useful are the logs when you start the application as them show all the reads that are done on filesystem the problem is that the last line I see there are:

fs.readSync []
fs.readdirSync [
  '/snapshot/ibn-app-2/node_modules/@serialport/bindings-cpp/prebuilds/linux-arm'
]
fs.readSync []
fs.readdirSync [ '/home/solar21/Desktop/prebuilds' ]

did you trimmed the output or the logs stop there? In this cases what I do in order to understand the issue is to put some logs in module files that cause the issue like: /node_modules/@serialport/bindings-cpp/dist/load-bindings.js:11:46

Try to check if they are loading a wrong path, put some console logs then trigger a new pkg build and execute it to see if you understand what's wrong. If needed then pkg supports patching of files (I already do this to support some modules like node pino). Example:

"pkg": {
		"scripts": [
			 <....>
		],
		"assets": [
			<...>
		],
		"patches": {
			"./node_modules/thread-stream/lib/worker.js": [
				"worker = (await realImport(filename))",
				"worker = realRequire(decodeURIComponent(filename.replace(process.platform === 'win32' ? 'file:///' : 'file://', '')))"
			],
			"./node_modules/pino/lib/transport-stream.js": [
				"fn = (await realImport(toLoad))",
				"fn = realRequire(target)"
			],
			"./node_modules/fontkit/dist/main.cjs": [
				"new TextDecoder('ascii');",
				"new TextDecoder('utf-8');"
			]
		}

@DaniRey
Copy link

DaniRey commented Apr 18, 2025

@robertsLando that's the full log, I started the application from the desktop.

The trick with patching should get us going. I'll use it to add some additional logging and then hopefully to patch require the way we need it. I too suspect that this is where the problem lays.

I'll try it after the holidays. Thank you for the support.

@robertsLando
Copy link
Member

@DaniRey I suggest to reproduce this with a very small script first to speed up testing. Please share your findings then, I have a feel serialport changed something in how it loads binaries that broke pkg lookup. I could take a look at this maybe next week but cannot promise anything

@DaniRey
Copy link

DaniRey commented Apr 18, 2025

Ok, we're making progress. Here is a minimal project setup https://github.com/DaniRey/pkg_serialport_friendship

The reason the native serialport module is not found, is that "armv" is set to "default" in node22_linuxstatic_armv7.

When I modify node_modules/node-gyp-build/node-gyp-build.js and add the following line (plus some logging).

if (armv === "default") armv = "7"

the lookup works, but unfortunately I then get ERR_DLOPEN_FAILED. By the way, the whole setup still works as expected on windows.

./pkg_serialport_friendship-linuxstatic-armv7 
Found tuple: android-arm with arch arm and platform android
Found tuple: android-arm64 with arch arm64 and platform android
Found tuple: darwin-x64+arm64 with arch x64,arm64 and platform darwin
Found tuple: linux-arm with arch arm and platform linux
Found tuple: linux-arm64 with arch arm64 and platform linux
Found tuple: linux-x64 with arch x64 and platform linux
Found tuple: win32-ia32 with arch ia32 and platform win32
Found tuple: win32-x64 with arch x64 and platform win32
Looking for tuple with platform linux and arch arm abi 127 runtime node uv 1 armv 7 libc glibc
Found prebuild: node.napi.armv6.node with tags {"file":"node.napi.armv6.node","specificity":3,"runtime":"node","napi":true,"armv":"6"}
Found prebuild: node.napi.armv7.node with tags {"file":"node.napi.armv7.node","specificity":3,"runtime":"node","napi":true,"armv":"7"}
going to call require with: /snapshot/pkg_serialport_friendship/node_modules/@serialport/bindings-cpp/prebuilds/linux-arm/node.napi.armv7.node
pkg/prelude/bootstrap.js:1872
      throw error;
      ^

Error: Dynamic loading not supported
    at process.dlopen (pkg/prelude/bootstrap.js:2256:28)
    at Module._extensions..node (node:internal/modules/cjs/loader:1719:18)
    at Module.load (node:internal/modules/cjs/loader:1322:32)
    at Module._load (node:internal/modules/cjs/loader:1132:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1344:12)
    at Module.require (pkg/prelude/bootstrap.js:1851:31)
    at require (node:internal/modules/helpers:141:16)
    at load (/snapshot/pkg_serialport_friendship/node_modules/node-gyp-build/node-gyp-build.js:22:10) {
  code: 'ERR_DLOPEN_FAILED'
}

Node.js v22.10.0

The fully modified version of node_modules/node-gyp-build/node-gyp-build.js is as follows

var fs = require('fs')
var path = require('path')
var os = require('os')

// Workaround to fix webpack's build warnings: 'the request of a dependency is an expression'
var runtimeRequire = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require // eslint-disable-line

var vars = (process.config && process.config.variables) || {}
var prebuildsOnly = !!process.env.PREBUILDS_ONLY
var abi = process.versions.modules // TODO: support old node where this is undef
var runtime = isElectron() ? 'electron' : (isNwjs() ? 'node-webkit' : 'node')

var arch = process.env.npm_config_arch || os.arch()
var platform = process.env.npm_config_platform || os.platform()
var libc = process.env.LIBC || (isAlpine(platform) ? 'musl' : 'glibc')
var armv = process.env.ARM_VERSION || (arch === 'arm64' ? '8' : vars.arm_version) || ''
var uv = (process.versions.uv || '').split('.')[0]

module.exports = load

function load (dir) {
  return runtimeRequire(load.resolve(dir))
}

load.resolve = load.path = function (dir) {
  dir = path.resolve(dir || '.')

  try {
    var name = runtimeRequire(path.join(dir, 'package.json')).name.toUpperCase().replace(/-/g, '_')
    if (process.env[name + '_PREBUILD']) dir = process.env[name + '_PREBUILD']
  } catch (err) {}

  if (!prebuildsOnly) {
    var release = getFirst(path.join(dir, 'build/Release'), matchBuild)
    if (release) return release

    var debug = getFirst(path.join(dir, 'build/Debug'), matchBuild)
    if (debug) return debug
  }

  var prebuild = resolve(dir)
  if (prebuild) return prebuild

  var nearby = resolve(path.dirname(process.execPath))
  if (nearby) return nearby

  var target = [
    'platform=' + platform,
    'arch=' + arch,
    'runtime=' + runtime,
    'abi=' + abi,
    'uv=' + uv,
    armv ? 'armv=' + armv : '',
    'libc=' + libc,
    'node=' + process.versions.node,
    process.versions.electron ? 'electron=' + process.versions.electron : '',
    typeof __webpack_require__ === 'function' ? 'webpack=true' : '' // eslint-disable-line
  ].filter(Boolean).join(' ')

  throw new Error('No native build was found for ' + target + '\n    loaded from: ' + dir + '\n')

  function resolve (dir) {
    // Find matching "prebuilds/<platform>-<arch>" directory
    var tuples = readdirSync(path.join(dir, 'prebuilds')).map(parseTuple)
    tuples.forEach(t => console.log(`Found tuple: ${t.name} with arch ${t.architectures} and platform ${t.platform}`))
    if (armv === "default") armv = "7"
    console.log("Looking for tuple with platform " + platform + " and arch " + arch + " abi " + abi + " runtime " + runtime + " uv " + uv + " armv " + armv + " libc " + libc)
    var tuple = tuples.filter(matchTuple(platform, arch)).sort(compareTuples)[0]
    if (!tuple) return

    // Find most specific flavor first
    var prebuilds = path.join(dir, 'prebuilds', tuple.name)
    var parsed = readdirSync(prebuilds).map(parseTags)
    parsed.forEach(p => console.log(`Found prebuild: ${p.file} with tags ${JSON.stringify(p)}`))
    var candidates = parsed.filter(matchTags(runtime, abi))
    var winner = candidates.sort(compareTags(runtime))[0]
    if (winner) console.log(`going to call require with: ${path.join(prebuilds, winner.file)}`)
    if (winner) return path.join(prebuilds, winner.file)
  }
}

function readdirSync (dir) {
  try {
    return fs.readdirSync(dir)
  } catch (err) {
    return []
  }
}

function getFirst (dir, filter) {
  var files = readdirSync(dir).filter(filter)
  return files[0] && path.join(dir, files[0])
}

function matchBuild (name) {
  return /\.node$/.test(name)
}

function parseTuple (name) {
  // Example: darwin-x64+arm64
  var arr = name.split('-')
  if (arr.length !== 2) return

  var platform = arr[0]
  var architectures = arr[1].split('+')

  if (!platform) return
  if (!architectures.length) return
  if (!architectures.every(Boolean)) return

  return { name, platform, architectures }
}

function matchTuple (platform, arch) {
  return function (tuple) {
    if (tuple == null) return false
    if (tuple.platform !== platform) return false
    return tuple.architectures.includes(arch)
  }
}

function compareTuples (a, b) {
  // Prefer single-arch prebuilds over multi-arch
  return a.architectures.length - b.architectures.length
}

function parseTags (file) {
  var arr = file.split('.')
  var extension = arr.pop()
  var tags = { file: file, specificity: 0 }

  if (extension !== 'node') return

  for (var i = 0; i < arr.length; i++) {
    var tag = arr[i]

    if (tag === 'node' || tag === 'electron' || tag === 'node-webkit') {
      tags.runtime = tag
    } else if (tag === 'napi') {
      tags.napi = true
    } else if (tag.slice(0, 3) === 'abi') {
      tags.abi = tag.slice(3)
    } else if (tag.slice(0, 2) === 'uv') {
      tags.uv = tag.slice(2)
    } else if (tag.slice(0, 4) === 'armv') {
      tags.armv = tag.slice(4)
    } else if (tag === 'glibc' || tag === 'musl') {
      tags.libc = tag
    } else {
      continue
    }

    tags.specificity++
  }

  return tags
}

function matchTags (runtime, abi) {
  return function (tags) {
    if (tags == null) return false
    if (tags.runtime !== runtime && !runtimeAgnostic(tags)) return false
    if (tags.abi !== abi && !tags.napi) return false
    if (tags.uv && tags.uv !== uv) return false
    if (tags.armv && tags.armv !== armv) return false
    if (tags.libc && tags.libc !== libc) return false

    return true
  }
}

function runtimeAgnostic (tags) {
  return tags.runtime === 'node' && tags.napi
}

function compareTags (runtime) {
  // Precedence: non-agnostic runtime, abi over napi, then by specificity.
  return function (a, b) {
    if (a.runtime !== b.runtime) {
      return a.runtime === runtime ? -1 : 1
    } else if (a.abi !== b.abi) {
      return a.abi ? -1 : 1
    } else if (a.specificity !== b.specificity) {
      return a.specificity > b.specificity ? -1 : 1
    } else {
      return 0
    }
  }
}

function isNwjs () {
  return !!(process.versions && process.versions.nw)
}

function isElectron () {
  if (process.versions && process.versions.electron) return true
  if (process.env.ELECTRON_RUN_AS_NODE) return true
  return typeof window !== 'undefined' && window.process && window.process.type === 'renderer'
}

function isAlpine (platform) {
  return platform === 'linux' && fs.existsSync('/etc/alpine-release')
}

// Exposed for unit tests
// TODO: move to lib
load.parseTags = parseTags
load.matchTags = matchTags
load.compareTags = compareTags
load.parseTuple = parseTuple
load.matchTuple = matchTuple
load.compareTuples = compareTuples

@DaniRey
Copy link

DaniRey commented Apr 18, 2025

This might be related to astefanutti/scratch-node#3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants