Skip to content

Commit

Permalink
feat(resolve): automatically add node_modules to search path
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 27, 2021
1 parent ebb2ef5 commit 7b03715
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/resolve.ts
Expand Up @@ -47,11 +47,20 @@ function _resolve (id: string, opts: ResolveOptions = {}): string {
const conditionsSet = opts.conditions ? new Set(opts.conditions) : DEFAULT_CONDITIONS_SET

// Search paths
const urls: URL[] = (Array.isArray(opts.url) ? opts.url : [opts.url])
const _urls: URL[] = (Array.isArray(opts.url) ? opts.url : [opts.url])
.filter(Boolean)
.map(u => new URL(normalizeid(u.toString())))
if (!urls.length) {
urls.push(DEFAULT_URL)
if (!_urls.length) {
_urls.push(DEFAULT_URL)
}
const urls = [..._urls]
// TODO: Consider pnp
for (const url of _urls) {
if (url.protocol === 'file:' && !url.pathname.includes('node_modules')) {
const newURL = new URL(url)
newURL.pathname += '/node_modules'
urls.push(newURL)
}
}

let resolved
Expand Down

0 comments on commit 7b03715

Please sign in to comment.