bare-addon-resolve
Advanced tools
Comparing version 1.0.1 to 1.1.0
65
index.js
@@ -0,1 +1,2 @@ | ||
const resolve = require('bare-module-resolve') | ||
const errors = require('./lib/errors') | ||
@@ -23,3 +24,3 @@ | ||
} else { | ||
yield value.addon | ||
yield value.resolution | ||
next = generator.next() | ||
@@ -43,3 +44,3 @@ } | ||
} else { | ||
yield value.addon | ||
yield value.resolution | ||
next = generator.next() | ||
@@ -59,5 +60,5 @@ } | ||
exports.addon = function * (specifier, parentURL, opts = {}) { | ||
let { name = null, version = null, builtins = [], builtinProtocol = 'builtin:' } = opts | ||
let { name = null, version = null, builtins = [], builtinProtocol = 'builtin:', resolutions = null } = opts | ||
if (startsWithWindowsDriveLetter(specifier)) { | ||
if (exports.startsWithWindowsDriveLetter(specifier)) { | ||
specifier = '/' + specifier | ||
@@ -74,2 +75,8 @@ } | ||
if (resolutions) { | ||
if (yield * exports.preresolved(directoryURL, resolutions, opts)) { | ||
return true | ||
} | ||
} | ||
if (name === null) { | ||
@@ -94,3 +101,3 @@ const info = yield { package: new URL('package.json', directoryURL) } | ||
if (builtins.includes(name)) { | ||
yield { addon: new URL(builtinProtocol + name) } | ||
yield { resolution: new URL(builtinProtocol + name) } | ||
@@ -117,2 +124,12 @@ return true | ||
exports.preresolved = function * (directoryURL, resolutions, opts = {}) { | ||
const imports = resolutions[directoryURL.href] | ||
if (typeof imports === 'object' && imports !== null) { | ||
return yield * resolve.packageImportsExports('bare:addon', imports, directoryURL, true, opts) | ||
} | ||
return false | ||
} | ||
exports.lookupPrebuildsScope = function * lookupPrebuildsScope (url, opts = {}) { | ||
@@ -130,3 +147,3 @@ const { host = null } = opts | ||
if (scopeURL.pathname.length === 3 && isWindowsDriveLetter(scopeURL.pathname.substring(1))) break | ||
if (scopeURL.pathname.length === 3 && exports.isWindowsDriveLetter(scopeURL.pathname.substring(1))) break | ||
} while (scopeURL.pathname !== '/') | ||
@@ -143,3 +160,3 @@ } | ||
for (const ext of extensions) { | ||
yield { addon: new URL(filename + ext, parentURL) } | ||
yield { resolution: new URL(filename + ext, parentURL) } | ||
} | ||
@@ -150,34 +167,4 @@ | ||
// https://infra.spec.whatwg.org/#ascii-upper-alpha | ||
function isASCIIUpperAlpha (c) { | ||
return c >= 0x41 && c <= 0x5a | ||
} | ||
exports.isWindowsDriveLetter = resolve.isWindowsDriveLetter | ||
// https://infra.spec.whatwg.org/#ascii-lower-alpha | ||
function isASCIILowerAlpha (c) { | ||
return c >= 0x61 && c <= 0x7a | ||
} | ||
// https://infra.spec.whatwg.org/#ascii-alpha | ||
function isASCIIAlpha (c) { | ||
return isASCIIUpperAlpha(c) || isASCIILowerAlpha(c) | ||
} | ||
// https://url.spec.whatwg.org/#windows-drive-letter | ||
function isWindowsDriveLetter (input) { | ||
return input.length >= 2 && isASCIIAlpha(input.charCodeAt(0)) && ( | ||
input.charCodeAt(1) === 0x3a || | ||
input.charCodeAt(1) === 0x7c | ||
) | ||
} | ||
// https://url.spec.whatwg.org/#start-with-a-windows-drive-letter | ||
function startsWithWindowsDriveLetter (input) { | ||
return input.length >= 2 && isWindowsDriveLetter(input) && ( | ||
input.length === 2 || | ||
input.charCodeAt(2) === 0x2f || | ||
input.charCodeAt(2) === 0x5c || | ||
input.charCodeAt(2) === 0x3f || | ||
input.charCodeAt(2) === 0x23 | ||
) | ||
} | ||
exports.startsWithWindowsDriveLetter = resolve.startsWithWindowsDriveLetter |
{ | ||
"name": "bare-addon-resolve", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Low-level addon resolution algorithm for Bare", | ||
@@ -23,2 +23,5 @@ "main": "index.js", | ||
"homepage": "https://github.com/holepunchto/bare-addon-resolve#readme", | ||
"dependencies": { | ||
"bare-module-resolve": "^1.5.0" | ||
}, | ||
"devDependencies": { | ||
@@ -25,0 +28,0 @@ "brittle": "^3.2.1", |
@@ -66,2 +66,5 @@ # bare-addon-resolve | ||
extensions: [], | ||
// A map of preresolved imports with keys being serialized directory URLs and | ||
// values being "imports" maps. | ||
resolutions | ||
} | ||
@@ -95,3 +98,3 @@ ``` | ||
} else { | ||
const resolution = value.addon | ||
const resolution = value.resolution | ||
@@ -107,2 +110,4 @@ next = generator.next() | ||
#### `const generator = resolve.preresolved(directoryURL, resolutions[, options])` | ||
#### `const generator = resolve.file(filename, parentURL, isIndex[, options])` | ||
@@ -109,0 +114,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
115
20341
1
135
+ Addedbare-module-resolve@^1.5.0
+ Addedbare-module-resolve@1.10.0(transitive)
+ Addedbare-semver@1.0.1(transitive)