bare-addon-resolve
Advanced tools
Comparing version 1.7.2 to 1.8.0
160
index.js
@@ -228,3 +228,3 @@ const resolve = require('bare-module-resolve') | ||
exports.lookupPrebuildsScope = function* lookupPrebuildsScope(url, opts = {}) { | ||
const { resolutions = null, host = null } = opts | ||
const { resolutions = null } = opts | ||
@@ -242,8 +242,6 @@ if (resolutions) { | ||
if (host === null) return | ||
const scopeURL = new URL(url.href) | ||
do { | ||
yield new URL('prebuilds/' + host + '/', scopeURL) | ||
yield new URL('prebuilds/', scopeURL) | ||
@@ -280,3 +278,9 @@ scopeURL.pathname = scopeURL.pathname.substring( | ||
exports.directory = function* (dirname, version, parentURL, opts = {}) { | ||
const { resolutions = null, builtins = [] } = opts | ||
const { | ||
resolutions = null, | ||
host = null, // Shorthand for single host resolution | ||
hosts = host !== null ? [host] : [], | ||
builtins = [], | ||
matchedConditions = [] | ||
} = opts | ||
@@ -312,3 +316,3 @@ let directoryURL | ||
if (typeof info.name === 'string' && info.name !== '') { | ||
name = info.name.replace(/\//g, '+') | ||
name = info.name.replace(/\//g, '+').replace(/^@/, '') | ||
} else { | ||
@@ -334,12 +338,26 @@ return false | ||
for (const prebuildsURL of exports.lookupPrebuildsScope(directoryURL, opts)) { | ||
if (version !== null) { | ||
if (yield* exports.file(name + '@' + version, prebuildsURL, opts)) { | ||
yielded = true | ||
for (const host of hosts) { | ||
const conditions = host.split('-') | ||
matchedConditions.push(...conditions) | ||
if (version !== null) { | ||
if ( | ||
yield* exports.file( | ||
host + '/' + name + '@' + version, | ||
prebuildsURL, | ||
opts | ||
) | ||
) { | ||
yielded = true | ||
} | ||
} | ||
} | ||
if (unversioned) { | ||
if (yield* exports.file(name, prebuildsURL, opts)) { | ||
yielded = true | ||
if (unversioned) { | ||
if (yield* exports.file(host + '/' + name, prebuildsURL, opts)) { | ||
yielded = true | ||
} | ||
} | ||
for (const _ of conditions) matchedConditions.pop() | ||
} | ||
@@ -356,81 +374,77 @@ } | ||
exports.linked = function* (name, version = null, opts = {}) { | ||
const { linked = true, linkedProtocol = 'linked:', host = null } = opts | ||
const { | ||
linked = true, | ||
linkedProtocol = 'linked:', | ||
host = null, // Shorthand for single host resolution | ||
hosts = host !== null ? [host] : [], | ||
matchedConditions = [] | ||
} = opts | ||
if (linked === false || host === null) return false | ||
if (linked === false || hosts.length === 0) return false | ||
if (host.startsWith('darwin-')) { | ||
if (version !== null) { | ||
yield { | ||
resolution: new URL( | ||
linkedProtocol + 'lib' + name + '.' + version + '.dylib' | ||
) | ||
let yielded = false | ||
for (const host of hosts) { | ||
const [platform = null] = host.split('-', 1) | ||
if (platform === null) continue | ||
matchedConditions.push(platform) | ||
if (platform === 'darwin' || platform === 'ios') { | ||
if (version !== null) { | ||
if (platform === 'darwin') { | ||
yield { | ||
resolution: new URL(`${linkedProtocol}lib${name}.${version}.dylib`) | ||
} | ||
} | ||
yield { | ||
resolution: new URL( | ||
`${linkedProtocol}${name}.${version}.framework/${name}.${version}` | ||
) | ||
} | ||
} | ||
yield { | ||
resolution: new URL( | ||
linkedProtocol + | ||
name + | ||
'.' + | ||
version + | ||
'.framework/' + | ||
name + | ||
'.' + | ||
version | ||
) | ||
if (platform === 'darwin') { | ||
yield { | ||
resolution: new URL(`${linkedProtocol}lib${name}.dylib`) | ||
} | ||
} | ||
} | ||
yield { resolution: new URL(linkedProtocol + 'lib' + name + '.dylib') } | ||
yield { resolution: new URL(linkedProtocol + name + '.framework/' + name) } | ||
return true | ||
} | ||
if (host.startsWith('ios-')) { | ||
if (version !== null) { | ||
yield { | ||
resolution: new URL( | ||
linkedProtocol + | ||
name + | ||
'.' + | ||
version + | ||
'.framework/' + | ||
name + | ||
'.' + | ||
version | ||
) | ||
resolution: new URL(`${linkedProtocol}${name}.framework/${name}`) | ||
} | ||
} | ||
yield { resolution: new URL(linkedProtocol + name + '.framework/' + name) } | ||
yielded = true | ||
} else if (platform === 'linux' || platform === 'android') { | ||
if (version !== null) { | ||
yield { | ||
resolution: new URL(`${linkedProtocol}lib${name}.${version}.so`) | ||
} | ||
} | ||
return true | ||
} | ||
if (host.startsWith('linux-') || host.startsWith('android-')) { | ||
if (version !== null) { | ||
yield { | ||
resolution: new URL( | ||
linkedProtocol + 'lib' + name + '.' + version + '.so' | ||
) | ||
resolution: new URL(`${linkedProtocol}lib${name}.so`) | ||
} | ||
} | ||
yield { resolution: new URL(linkedProtocol + 'lib' + name + '.so') } | ||
yielded = true | ||
} else if (platform === 'win32') { | ||
if (version !== null) { | ||
yield { | ||
resolution: new URL(`${linkedProtocol}${name}-${version}.dll`) | ||
} | ||
} | ||
return true | ||
} | ||
if (host.startsWith('win32-')) { | ||
if (version !== null) { | ||
yield { | ||
resolution: new URL(linkedProtocol + name + '-' + version + '.dll') | ||
resolution: new URL(`${linkedProtocol}${name}.dll`) | ||
} | ||
yielded = true | ||
} | ||
yield { resolution: new URL(linkedProtocol + name + '.dll') } | ||
return true | ||
matchedConditions.pop() | ||
} | ||
return false | ||
return yielded | ||
} | ||
@@ -437,0 +451,0 @@ |
{ | ||
"name": "bare-addon-resolve", | ||
"version": "1.7.2", | ||
"version": "1.8.0", | ||
"description": "Low-level addon resolution algorithm for Bare", | ||
@@ -28,3 +28,3 @@ "exports": { | ||
"dependencies": { | ||
"bare-module-resolve": "^1.8.2", | ||
"bare-module-resolve": "^1.9.0", | ||
"bare-semver": "^1.0.0" | ||
@@ -31,0 +31,0 @@ }, |
@@ -56,3 +56,3 @@ # bare-addon-resolve | ||
```js | ||
{ | ||
options = { | ||
// A list of builtin addon specifiers. If matched, the protocol of the | ||
@@ -67,6 +67,11 @@ // resolved URL will be `builtinProtocol`. | ||
linkedProtocol: 'linked:', | ||
// The `<platform>-<arch>` combination to look for when resolving dynamic | ||
// addons. If `null`, only builtin specifiers can be resolved. In Bare, | ||
// pass `Bare.Addon.host`. | ||
host: null, | ||
// The supported import conditions. "default" is always recognized. | ||
conditions: [], | ||
// An array reference which will contain the matched conditions when yielding | ||
// resolutions. | ||
matchedConditions: [], | ||
// The `<platform>-<arch>` combinations to look for when resolving dynamic | ||
// addons. If empty, only builtin specifiers can be resolved. In Bare, | ||
// pass `[Bare.Addon.host]`. | ||
hosts: [], | ||
// The file extensions to look for when resolving dynamic addons. | ||
@@ -73,0 +78,0 @@ extensions: [], |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27076
376
139
Updatedbare-module-resolve@^1.9.0