Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bare-addon-resolve

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bare-addon-resolve - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

155

index.js

@@ -58,4 +58,2 @@ const resolve = require('bare-module-resolve')

exports.addon = function * (specifier, parentURL, opts = {}) {
let { name = null, version = null, builtins = [], builtinProtocol = 'builtin:', resolutions = null } = opts
if (exports.startsWithWindowsDriveLetter(specifier)) {

@@ -65,63 +63,67 @@ specifier = '/' + specifier

let directoryURL
if (specifier[specifier.length - 1] === '/' || specifier[specifier.length - 1] === '\\') {
directoryURL = new URL(specifier, parentURL)
} else {
directoryURL = new URL(specifier + '/', parentURL)
if (specifier === '.' || specifier === '..' || specifier[0] === '/' || specifier[0] === '\\' || specifier.startsWith('./') || specifier.startsWith('.\\') || specifier.startsWith('../') || specifier.startsWith('..\\')) {
return yield * exports.directory(specifier, parentURL, opts)
}
if (resolutions) {
if (yield * exports.preresolved(directoryURL, resolutions, opts)) {
return true
}
}
return yield * exports.package(specifier, parentURL, opts)
}
if (name === null) {
const info = yield { package: new URL('package.json', directoryURL) }
exports.package = function * (packageSpecifier, parentURL, opts = {}) {
let packageName
if (info) {
if (typeof info.name === 'string' && info.name !== '') {
name = info.name.replace(/\//g, '+')
} else {
return false
}
if (packageSpecifier === '') {
throw errors.INVALID_ADDON_SPECIFIER(`Addon specifier '${packageSpecifier}' is not a valid package name`)
}
if (typeof info.version === 'string' && info.version !== '') {
version = info.version
}
} else {
return false
if (packageSpecifier[0] !== '@') {
packageName = packageSpecifier.split('/', 1).join()
} else {
if (!packageSpecifier.includes('/')) {
throw errors.INVALID_ADDON_SPECIFIER(`Addon specifier '${packageSpecifier}' is not a valid package name`)
}
packageName = packageSpecifier.split('/', 2).join('/')
}
if (version !== null) {
if (builtins.includes(name + '@' + version)) {
yield { resolution: new URL(builtinProtocol + name + '@' + version) }
return true
}
if (packageName[0] === '.' || packageName.includes('\\') || packageName.includes('%')) {
throw errors.INVALID_ADDON_SPECIFIER(`Addon specifier '${packageSpecifier}' is not a valid package name`)
}
if (builtins.includes(name)) {
yield { resolution: new URL(builtinProtocol + name) }
const packageSubpath = '.' + packageSpecifier.substring(packageName.length)
if (yield * exports.packageSelf(packageName, packageSubpath, parentURL, opts)) {
return true
}
let yielded = false
parentURL = new URL(parentURL.href)
for (const prebuildsURL of exports.lookupPrebuildsScope(directoryURL, opts)) {
if (version !== null) {
if (yield * exports.file(name + '@' + version, prebuildsURL, opts)) {
yielded = true
}
do {
const packageURL = new URL('node_modules/' + packageName + '/', parentURL)
parentURL.pathname = parentURL.pathname.substring(0, parentURL.pathname.lastIndexOf('/'))
const info = yield { package: new URL('package.json', packageURL) }
if (info) {
return yield * exports.directory(packageSubpath, packageURL, opts)
}
} while (parentURL.pathname !== '/')
if (yield * exports.file(name, prebuildsURL, opts)) {
yielded = true
return false
}
exports.packageSelf = function * (packageName, packageSubpath, parentURL, opts = {}) {
for (const packageURL of resolve.lookupPackageScope(parentURL, opts)) {
const info = yield { package: packageURL }
if (info) {
if (info.name === packageName) {
return yield * exports.directory(packageSubpath, packageURL, opts)
}
break
}
}
return yielded
return false
}

@@ -169,4 +171,71 @@

exports.directory = function * (dirname, parentURL, opts = {}) {
const { builtins = [], builtinProtocol = 'builtin:', resolutions = null } = opts
let directoryURL
if (dirname[dirname.length - 1] === '/' || dirname[dirname.length - 1] === '\\') {
directoryURL = new URL(dirname, parentURL)
} else {
directoryURL = new URL(dirname + '/', parentURL)
}
if (resolutions) {
if (yield * exports.preresolved(directoryURL, resolutions, opts)) {
return true
}
}
let name = null
let version = null
const info = yield { package: new URL('package.json', directoryURL) }
if (info) {
if (typeof info.name === 'string' && info.name !== '') {
name = info.name.replace(/\//g, '+')
} else {
return false
}
if (typeof info.version === 'string' && info.version !== '') {
version = info.version
}
} else {
return false
}
if (version !== null) {
if (builtins.includes(name + '@' + version)) {
yield { resolution: new URL(builtinProtocol + name + '@' + version) }
return true
}
}
if (builtins.includes(name)) {
yield { resolution: new URL(builtinProtocol + name) }
return true
}
let yielded = false
for (const prebuildsURL of exports.lookupPrebuildsScope(directoryURL, opts)) {
if (version !== null) {
if (yield * exports.file(name + '@' + version, prebuildsURL, opts)) {
yielded = true
}
}
if (yield * exports.file(name, prebuildsURL, opts)) {
yielded = true
}
}
return yielded
}
exports.isWindowsDriveLetter = resolve.isWindowsDriveLetter
exports.startsWithWindowsDriveLetter = resolve.startsWithWindowsDriveLetter
{
"name": "bare-addon-resolve",
"version": "1.2.0",
"version": "1.3.0",
"description": "Low-level addon resolution algorithm for Bare",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -108,8 +108,12 @@ # bare-addon-resolve

#### `const generator = resolve.package(packageSpecifier, parentURL[, options])`
#### `const generator = resolve.preresolved(directoryURL, resolutions[, options])`
#### `const generator = resolve.file(filename, parentURL, isIndex[, options])`
#### `const generator = resolve.file(filename, parentURL[, options])`
#### `const generator = resolve.directory(dirname, parentURL[, options])`
## License
Apache-2.0
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc