From 00e0e35c84a18f01338b949689672346c2a6c0ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Isager=20Dalsgar=C3=B0?= Date: Sat, 2 Nov 2024 10:23:43 +0100 Subject: [PATCH] Pass default `host` to resolvers --- lib/resolve/bare.js | 5 +++-- lib/resolve/node.js | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/resolve/bare.js b/lib/resolve/bare.js index 894d5bd..9c5cd6d 100644 --- a/lib/resolve/bare.js +++ b/lib/resolve/bare.js @@ -7,7 +7,8 @@ module.exports = function (entry, parentURL, opts = {}) { const { platform = runtime.platform, arch = runtime.arch, - simulator = false + simulator = false, + host = `${platform}-${arch}${simulator ? '-simulator' : ''}` } = opts let extensions @@ -19,7 +20,7 @@ module.exports = function (entry, parentURL, opts = {}) { extensions = ['.bare', '.node'] conditions = ['addon', ...conditions] - return resolve.addon(entry.specifier || '.', parentURL, { extensions, conditions, ...opts }) + return resolve.addon(entry.specifier || '.', parentURL, { extensions, conditions, host, ...opts }) } if (entry.type & lex.constants.ASSET) { diff --git a/lib/resolve/node.js b/lib/resolve/node.js index 4f9d961..76e6a6e 100644 --- a/lib/resolve/node.js +++ b/lib/resolve/node.js @@ -1,14 +1,26 @@ const lex = require('bare-module-lexer') const resolve = require('../resolve') -module.exports = function (entry, parentURL, opts) { +module.exports = function (entry, parentURL, opts = {}) { + const runtime = require('#runtime') + + const { + platform = runtime.platform, + arch = runtime.arch, + simulator = false, + host = `${platform}-${arch}${simulator ? '-simulator' : ''}` + } = opts + let extensions - let conditions + let conditions = ['node', platform, arch] + + if (simulator) conditions = [...conditions, 'simulator'] if (entry.type & lex.constants.ADDON) { extensions = ['.node'] + conditions = ['addon', ...conditions] - return resolve.addon(entry.specifier || '.', parentURL, { extensions, conditions, ...opts }) + return resolve.addon(entry.specifier || '.', parentURL, { extensions, conditions, host, ...opts }) } if (entry.type & lex.constants.REQUIRE) {