bare-addon-resolve
Advanced tools
Comparing version 1.8.0 to 1.9.0
206
index.js
@@ -30,4 +30,3 @@ const resolve = require('bare-module-resolve') | ||
} else { | ||
yield value.resolution | ||
next = generator.next() | ||
next = generator.next(yield value.resolution) | ||
} | ||
@@ -50,4 +49,3 @@ } | ||
} else { | ||
yield value.resolution | ||
next = generator.next() | ||
next = generator.next(yield value.resolution) | ||
} | ||
@@ -65,2 +63,10 @@ } | ||
const { UNRESOLVED, YIELDED, RESOLVED } = resolve.constants | ||
exports.constants = { | ||
UNRESOLVED, | ||
YIELDED, | ||
RESOLVED | ||
} | ||
exports.addon = function* (specifier, parentURL, opts = {}) { | ||
@@ -73,12 +79,14 @@ const { resolutions = null } = opts | ||
let status | ||
if (resolutions) { | ||
if (yield* resolve.preresolved(specifier, resolutions, parentURL, opts)) { | ||
return true | ||
} | ||
} | ||
status = yield* resolve.preresolved(specifier, resolutions, parentURL, opts) | ||
if (yield* exports.url(specifier, parentURL, opts)) { | ||
return true | ||
if (status) return status | ||
} | ||
status = yield* exports.url(specifier, parentURL, opts) | ||
if (status) return status | ||
let version = null | ||
@@ -121,8 +129,8 @@ | ||
} catch { | ||
return false | ||
return UNRESOLVED | ||
} | ||
yield { resolution } | ||
const resolved = yield { resolution } | ||
return true | ||
return resolved ? RESOLVED : YIELDED | ||
} | ||
@@ -168,14 +176,12 @@ | ||
if ( | ||
yield* exports.packageSelf( | ||
packageName, | ||
packageSubpath, | ||
packageVersion, | ||
parentURL, | ||
opts | ||
) | ||
) { | ||
return true | ||
} | ||
const status = yield* exports.packageSelf( | ||
packageName, | ||
packageSubpath, | ||
packageVersion, | ||
parentURL, | ||
opts | ||
) | ||
if (status) return status | ||
parentURL = new URL(parentURL.href) | ||
@@ -203,3 +209,3 @@ | ||
return false | ||
return UNRESOLVED | ||
} | ||
@@ -231,3 +237,3 @@ | ||
return false | ||
return UNRESOLVED | ||
} | ||
@@ -262,4 +268,5 @@ | ||
exports.isWindowsDriveLetter(scopeURL.pathname.substring(1)) | ||
) | ||
) { | ||
break | ||
} | ||
} while (scopeURL.pathname !== '' && scopeURL.pathname !== '/') | ||
@@ -277,7 +284,13 @@ } | ||
let status = UNRESOLVED | ||
for (const ext of extensions) { | ||
yield { resolution: new URL(filename + ext, parentURL) } | ||
if (yield { resolution: new URL(filename + ext, parentURL) }) { | ||
return RESOLVED | ||
} | ||
status = YIELDED | ||
} | ||
return extensions.length > 0 | ||
return status | ||
} | ||
@@ -308,7 +321,10 @@ | ||
if (resolutions) { | ||
if ( | ||
yield* resolve.preresolved('bare:addon', resolutions, directoryURL, opts) | ||
) { | ||
return true | ||
} | ||
const status = yield* resolve.preresolved( | ||
'bare:addon', | ||
resolutions, | ||
directoryURL, | ||
opts | ||
) | ||
if (status) return status | ||
} | ||
@@ -326,7 +342,7 @@ | ||
} else { | ||
return false | ||
return UNRESOLVED | ||
} | ||
if (typeof info.version === 'string' && info.version !== '') { | ||
if (version !== null && info.version !== version) return false | ||
if (version !== null && info.version !== version) return UNRESOLVED | ||
@@ -336,12 +352,14 @@ version = info.version | ||
} else { | ||
return false | ||
return UNRESOLVED | ||
} | ||
if (yield* resolve.builtinTarget(name, version, builtins, opts)) { | ||
return true | ||
} | ||
let status | ||
let yielded = false | ||
status = yield* resolve.builtinTarget(name, version, builtins, opts) | ||
if (status) return status | ||
for (const prebuildsURL of exports.lookupPrebuildsScope(directoryURL, opts)) { | ||
status = UNRESOLVED | ||
for (const host of hosts) { | ||
@@ -353,17 +371,11 @@ const conditions = host.split('-') | ||
if (version !== null) { | ||
if ( | ||
yield* exports.file( | ||
host + '/' + name + '@' + version, | ||
prebuildsURL, | ||
opts | ||
) | ||
) { | ||
yielded = true | ||
} | ||
status |= yield* exports.file( | ||
host + '/' + name + '@' + version, | ||
prebuildsURL, | ||
opts | ||
) | ||
} | ||
if (unversioned) { | ||
if (yield* exports.file(host + '/' + name, prebuildsURL, opts)) { | ||
yielded = true | ||
} | ||
status |= yield* exports.file(host + '/' + name, prebuildsURL, opts) | ||
} | ||
@@ -373,9 +385,7 @@ | ||
} | ||
} | ||
if (yield* exports.linked(name, version, opts)) { | ||
yielded = true | ||
if (status === RESOLVED) return status | ||
} | ||
return yielded | ||
return yield* exports.linked(name, version, opts) | ||
} | ||
@@ -392,5 +402,5 @@ | ||
if (linked === false || hosts.length === 0) return false | ||
if (linked === false || hosts.length === 0) return UNRESOLVED | ||
let yielded = false | ||
let status = UNRESOLVED | ||
@@ -406,50 +416,84 @@ for (const host of hosts) { | ||
if (version !== null) { | ||
if (platform === 'darwin') { | ||
if ( | ||
yield { | ||
resolution: new URL(`${linkedProtocol}lib${name}.${version}.dylib`) | ||
resolution: new URL( | ||
`${linkedProtocol}${name}.${version}.framework/${name}.${version}` | ||
) | ||
} | ||
) { | ||
return RESOLVED | ||
} | ||
yield { | ||
resolution: new URL( | ||
`${linkedProtocol}${name}.${version}.framework/${name}.${version}` | ||
) | ||
if (platform === 'darwin') { | ||
if ( | ||
yield { | ||
resolution: new URL( | ||
`${linkedProtocol}lib${name}.${version}.dylib` | ||
) | ||
} | ||
) { | ||
return RESOLVED | ||
} | ||
} | ||
} | ||
if (platform === 'darwin') { | ||
if ( | ||
yield { | ||
resolution: new URL(`${linkedProtocol}lib${name}.dylib`) | ||
resolution: new URL(`${linkedProtocol}${name}.framework/${name}`) | ||
} | ||
) { | ||
return RESOLVED | ||
} | ||
yield { | ||
resolution: new URL(`${linkedProtocol}${name}.framework/${name}`) | ||
if (platform === 'darwin') { | ||
if ( | ||
yield { | ||
resolution: new URL(`${linkedProtocol}lib${name}.dylib`) | ||
} | ||
) { | ||
return RESOLVED | ||
} | ||
} | ||
yielded = true | ||
status = YIELDED | ||
} else if (platform === 'linux' || platform === 'android') { | ||
if (version !== null) { | ||
yield { | ||
resolution: new URL(`${linkedProtocol}lib${name}.${version}.so`) | ||
if ( | ||
yield { | ||
resolution: new URL(`${linkedProtocol}lib${name}.${version}.so`) | ||
} | ||
) { | ||
return RESOLVED | ||
} | ||
} | ||
yield { | ||
resolution: new URL(`${linkedProtocol}lib${name}.so`) | ||
if ( | ||
yield { | ||
resolution: new URL(`${linkedProtocol}lib${name}.so`) | ||
} | ||
) { | ||
return RESOLVED | ||
} | ||
yielded = true | ||
status = YIELDED | ||
} else if (platform === 'win32') { | ||
if (version !== null) { | ||
yield { | ||
resolution: new URL(`${linkedProtocol}${name}-${version}.dll`) | ||
if ( | ||
yield { | ||
resolution: new URL(`${linkedProtocol}${name}-${version}.dll`) | ||
} | ||
) { | ||
return RESOLVED | ||
} | ||
} | ||
yield { | ||
resolution: new URL(`${linkedProtocol}${name}.dll`) | ||
if ( | ||
yield { | ||
resolution: new URL(`${linkedProtocol}${name}.dll`) | ||
} | ||
) { | ||
return RESOLVED | ||
} | ||
yielded = true | ||
status = YIELDED | ||
} | ||
@@ -460,3 +504,3 @@ | ||
return yielded | ||
return status | ||
} | ||
@@ -463,0 +507,0 @@ |
{ | ||
"name": "bare-addon-resolve", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "Low-level addon resolution algorithm for Bare", | ||
@@ -28,3 +28,3 @@ "exports": { | ||
"dependencies": { | ||
"bare-module-resolve": "^1.9.0", | ||
"bare-module-resolve": "^1.10.0", | ||
"bare-semver": "^1.0.0" | ||
@@ -31,0 +31,0 @@ }, |
@@ -93,5 +93,27 @@ # bare-addon-resolve | ||
The following generator functions implement the resolution algorithm. To drive the generator functions, a loop like the following can be used: | ||
The following generator functions implement the resolution algorithm. The yielded values have the following shape: | ||
**Package manifest** | ||
```js | ||
next.value = { | ||
package: URL | ||
} | ||
``` | ||
If the package manifest identified by `next.value.package` exists, `generator.next()` must be passed the parsed JSON value of the manifest. If it does not exist, pass `null` instead. | ||
**Resolution candidate** | ||
```js | ||
next.value = { | ||
resolution: URL | ||
} | ||
``` | ||
If the addon identified by `next.value.resolution` exists, `generator.next()` may be passed `true` to signal that the resolution for the current set of conditions has been identified. If it does not exist, pass `false` instead. | ||
To drive the generator functions, a loop like the following can be used: | ||
```js | ||
const generator = resolve.addon(specifier, parentURL) | ||
@@ -105,3 +127,4 @@ | ||
if (value.package) { | ||
const info = /* Read and parse `value.package` if it exists, otherwise `null` */; | ||
// Read and parse `value.package` if it exists, otherwise `null` | ||
let info | ||
@@ -112,3 +135,6 @@ next = generator.next(info) | ||
next = generator.next() | ||
// `true` if `resolution` was the correct candidate, otherwise `false` | ||
let resolved | ||
next = generator.next(resolved) | ||
} | ||
@@ -115,0 +141,0 @@ } |
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
28591
409
165
Updatedbare-module-resolve@^1.10.0