🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

bare-module-resolve

Package Overview
Dependencies
Maintainers
2
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bare-module-resolve - npm Package Compare versions

Comparing version
1.12.0
to
1.12.1
+5
-25
index.d.ts

@@ -85,13 +85,5 @@ import URL from 'bare-url'

export function module(
specifier: string,
parentURL: URL,
opts?: ResolveOptions
): Resolver
export function module(specifier: string, parentURL: URL, opts?: ResolveOptions): Resolver
export function url(
url: string,
parentURL: URL,
opts?: ResolveOptions
): Resolver
export function url(url: string, parentURL: URL, opts?: ResolveOptions): Resolver

@@ -105,7 +97,3 @@ export function preresolved(

export function package(
packageSpecifier: string,
parentURL: URL,
opts?: ResolveOptions
): Resolver
export function package(packageSpecifier: string, parentURL: URL, opts?: ResolveOptions): Resolver

@@ -126,7 +114,3 @@ export function packageSelf(

export function packageImports(
specifier: string,
parentURL: URL,
opts?: ResolveOptions
): Resolver
export function packageImports(specifier: string, parentURL: URL, opts?: ResolveOptions): Resolver

@@ -163,9 +147,5 @@ export function packageImportsExports(

export function directory(
dirname: string,
parentURL: URL,
opts?: ResolveOptions
): Resolver
export function directory(dirname: string, parentURL: URL, opts?: ResolveOptions): Resolver
}
export = resolve
+49
-169
const { satisfies } = require('bare-semver')
const errors = require('./lib/errors')
module.exports = exports = function resolve(
specifier,
parentURL,
opts,
readPackage
) {
module.exports = exports = function resolve(specifier, parentURL, opts, readPackage) {
if (typeof opts === 'function') {

@@ -107,9 +102,3 @@ readPackage = opts

if (imports) {
status = yield* exports.packageImportsExports(
specifier,
imports,
parentURL,
true,
opts
)
status = yield* exports.packageImportsExports(specifier, imports, parentURL, true, opts)

@@ -134,3 +123,3 @@ if (status) return status

exports.url = function* (url, parentURL, opts = {}) {
const { imports = null, deferredProtocol = 'deferred:' } = opts
const { imports = null, deferredProtocol = 'deferred:', resolutions = null } = opts

@@ -159,2 +148,13 @@ let resolution

if (resolutions) {
const imports = resolutions[parentURL.href]
if (typeof imports === 'object' && imports !== null) {
opts = {
...opts,
resolutions: { ...resolutions, [parentURL.href]: { ...imports, [specifier]: null } }
}
}
}
return yield* exports.module(specifier, parentURL, opts)

@@ -173,5 +173,3 @@ }

) {
throw errors.INVALID_MODULE_SPECIFIER(
`Module specifier '${url}' is not a valid package name`
)
throw errors.INVALID_MODULE_SPECIFIER(`Module specifier '${url}' is not a valid package name`)
}

@@ -191,9 +189,3 @@

if (typeof imports === 'object' && imports !== null) {
return yield* exports.packageImportsExports(
specifier,
imports,
parentURL,
true,
opts
)
return yield* exports.packageImportsExports(specifier, imports, parentURL, true, opts)
}

@@ -239,7 +231,3 @@

if (
packageName[0] === '.' ||
packageName.includes('\\') ||
packageName.includes('%')
) {
if (packageName[0] === '.' || packageName.includes('\\') || packageName.includes('%')) {
throw errors.INVALID_MODULE_SPECIFIER(

@@ -262,8 +250,3 @@ `Module specifier '${packageSpecifier}' is not a valid package name`

status = yield* exports.packageSelf(
packageName,
packageSubpath,
parentURL,
opts
)
status = yield* exports.packageSelf(packageName, packageSubpath, parentURL, opts)

@@ -281,8 +264,3 @@ if (status) return status

if (info.exports) {
return yield* exports.packageExports(
packageURL,
packageSubpath,
info.exports,
opts
)
return yield* exports.packageExports(packageURL, packageSubpath, info.exports, opts)
}

@@ -309,8 +287,3 @@

exports.packageSelf = function* (
packageName,
packageSubpath,
parentURL,
opts = {}
) {
exports.packageSelf = function* (packageName, packageSubpath, parentURL, opts = {}) {
for (const packageURL of exports.lookupPackageScope(parentURL, opts)) {

@@ -323,8 +296,3 @@ const info = yield { package: packageURL }

if (info.exports) {
return yield* exports.packageExports(
packageURL,
packageSubpath,
info.exports,
opts
)
return yield* exports.packageExports(packageURL, packageSubpath, info.exports, opts)
}

@@ -340,8 +308,3 @@

const status = yield* exports.file(
packageSubpath,
packageURL,
false,
opts
)
const status = yield* exports.file(packageSubpath, packageURL, false, opts)

@@ -357,8 +320,3 @@ if (status === RESOLVED) return status

exports.packageExports = function* (
packageURL,
subpath,
packageExports,
opts = {}
) {
exports.packageExports = function* (packageURL, subpath, packageExports, opts = {}) {
if (subpath === '.') {

@@ -380,9 +338,3 @@ let mainExport

if (mainExport) {
const status = yield* exports.packageTarget(
packageURL,
mainExport,
null,
false,
opts
)
const status = yield* exports.packageTarget(packageURL, mainExport, null, false, opts)

@@ -448,9 +400,3 @@ if (status) return status

if (imports) {
const status = yield* exports.packageImportsExports(
specifier,
imports,
parentURL,
true,
opts
)
const status = yield* exports.packageImportsExports(specifier, imports, parentURL, true, opts)

@@ -473,9 +419,3 @@ if (status) return status

return yield* exports.packageTarget(
packageURL,
target,
null,
isImports,
opts
)
return yield* exports.packageTarget(packageURL, target, null, isImports, opts)
}

@@ -496,4 +436,3 @@

patternTrailer === '' ||
(matchKey.endsWith(patternTrailer) &&
matchKey.length >= expansionKey.length)
(matchKey.endsWith(patternTrailer) && matchKey.length >= expansionKey.length)
) {

@@ -507,9 +446,3 @@ const target = matchObject[expansionKey]

return yield* exports.packageTarget(
packageURL,
target,
patternMatch,
isImports,
opts
)
return yield* exports.packageTarget(packageURL, target, patternMatch, isImports, opts)
}

@@ -522,7 +455,3 @@ }

exports.validateEngines = function validateEngines(
packageURL,
packageEngines,
opts = {}
) {
exports.validateEngines = function validateEngines(packageURL, packageEngines, opts = {}) {
const { engines = {} } = opts

@@ -557,9 +486,3 @@

exports.packageTarget = function* (
packageURL,
target,
patternMatch,
isImports,
opts = {}
) {
exports.packageTarget = function* (packageURL, target, patternMatch, isImports, opts = {}) {
const { conditions = [], matchedConditions = [] } = opts

@@ -619,9 +542,6 @@

status |= yield* exports.packageTarget(
packageURL,
targetValue,
patternMatch,
isImports,
{ ...opts, conditions: subset }
)
status |= yield* exports.packageTarget(packageURL, targetValue, patternMatch, isImports, {
...opts,
conditions: subset
})

@@ -637,13 +557,4 @@ matchedConditions.pop()

exports.builtinTarget = function* (
packageSpecifier,
packageVersion,
target,
opts = {}
) {
const {
builtinProtocol = 'builtin:',
conditions = [],
matchedConditions = []
} = opts
exports.builtinTarget = function* (packageSpecifier, packageVersion, target, opts = {}) {
const { builtinProtocol = 'builtin:', conditions = [], matchedConditions = [] } = opts

@@ -683,5 +594,3 @@ if (typeof target === 'string') {

const resolved = yield {
resolution: new URL(
builtinProtocol + packageSpecifier + '@' + version
)
resolution: new URL(builtinProtocol + packageSpecifier + '@' + version)
}

@@ -713,8 +622,6 @@

status |= yield* exports.builtinTarget(
packageSpecifier,
packageVersion,
targetValue,
{ ...opts, conditions: subset }
)
status |= yield* exports.builtinTarget(packageSpecifier, packageVersion, targetValue, {
...opts,
conditions: subset
})

@@ -730,7 +637,3 @@ matchedConditions.pop()

exports.conditionMatches = function* conditionMatches(
target,
conditions,
opts = {}
) {
exports.conditionMatches = function* conditionMatches(target, conditions, opts = {}) {
if (conditions.every((condition) => typeof condition === 'string')) {

@@ -771,6 +674,3 @@ const keys = Object.keys(target)

parentURL.pathname = parentURL.pathname.substring(
0,
parentURL.pathname.lastIndexOf('/')
)
parentURL.pathname = parentURL.pathname.substring(0, parentURL.pathname.lastIndexOf('/'))

@@ -792,8 +692,3 @@ if (

if (resolutions) {
for (const { resolution } of exports.preresolved(
'#package',
resolutions,
scopeURL,
opts
)) {
for (const { resolution } of exports.preresolved('#package', resolutions, scopeURL, opts)) {
if (resolution) return yield resolution

@@ -812,6 +707,3 @@ }

scopeURL.pathname = scopeURL.pathname.substring(
0,
scopeURL.pathname.lastIndexOf('/')
)
scopeURL.pathname = scopeURL.pathname.substring(0, scopeURL.pathname.lastIndexOf('/'))

@@ -840,5 +732,3 @@ if (

if (parentURL.protocol === 'file:' && /%2f|%5c/i.test(filename)) {
throw errors.INVALID_MODULE_SPECIFIER(
`Module specifier '${filename}' is invalid`
)
throw errors.INVALID_MODULE_SPECIFIER(`Module specifier '${filename}' is invalid`)
}

@@ -874,6 +764,3 @@

if (
dirname[dirname.length - 1] === '/' ||
dirname[dirname.length - 1] === '\\'
) {
if (dirname[dirname.length - 1] === '/' || dirname[dirname.length - 1] === '\\') {
directoryURL = new URL(dirname, parentURL)

@@ -888,8 +775,3 @@ } else {

if (info.exports) {
return yield* exports.packageExports(
directoryURL,
'.',
info.exports,
opts
)
return yield* exports.packageExports(directoryURL, '.', info.exports, opts)
}

@@ -934,5 +816,3 @@

// https://url.spec.whatwg.org/#start-with-a-windows-drive-letter
exports.startsWithWindowsDriveLetter = function startsWithWindowsDriveLetter(
input
) {
exports.startsWithWindowsDriveLetter = function startsWithWindowsDriveLetter(input) {
return (

@@ -939,0 +819,0 @@ input.length >= 2 &&

@@ -48,8 +48,4 @@ module.exports = class ModuleResolveError extends Error {

static UNSUPPORTED_ENGINE(msg) {
return new ModuleResolveError(
msg,
'UNSUPPORTED_ENGINE',
ModuleResolveError.UNSUPPORTED_ENGINE
)
return new ModuleResolveError(msg, 'UNSUPPORTED_ENGINE', ModuleResolveError.UNSUPPORTED_ENGINE)
}
}
{
"name": "bare-module-resolve",
"version": "1.12.0",
"version": "1.12.1",
"description": "Low-level module resolution algorithm for Bare",

@@ -41,3 +41,3 @@ "exports": {

"prettier": "^3.3.3",
"prettier-config-standard": "^7.0.0"
"prettier-config-holepunch": "^2.0.0"
},

@@ -44,0 +44,0 @@ "peerDependencies": {

@@ -20,7 +20,3 @@ # bare-module-resolve

for (const resolution of resolve(
'./file.js',
new URL('file:///directory/'),
readPackage
)) {
for (const resolution of resolve('./file.js', new URL('file:///directory/'), readPackage)) {
console.log(resolution)

@@ -39,7 +35,3 @@ }

for await (const resolution of resolve(
'./file.js',
new URL('file:///directory/'),
readPackage
)) {
for await (const resolution of resolve('./file.js', new URL('file:///directory/'), readPackage)) {
console.log(resolution)

@@ -175,3 +167,7 @@ }

1. Let `specifier` be `url.pathname`.
2. Return `module(specifier, parentURL, options)`.
2. If `options.resolutions` is set:
1. Let `imports` be `options.resolutions[parentURL]`.
2. If `imports` is a non-`null` object:
1. Set `imports[specifier]` to `null`.
3. Return `module(specifier, parentURL, options)`.
4. If `url.protocol` equals `node:`:

@@ -178,0 +174,0 @@ 1. Let `specifier` be `url.pathname`.