Skip to content

Commit

Permalink
fix: make url optional in resolver created with createResolve (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl committed Jun 16, 2022
1 parent 37d5bcc commit 7c1bda4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/resolve.ts
Expand Up @@ -118,7 +118,7 @@ export function resolvePath (id: string, opts?: ResolveOptions) {
}

export function createResolve (defaults?: ResolveOptions) {
return (id, url) => {
return (id: string, url?: ResolveOptions['url']) => {
return resolve(id, { url, ...defaults })
}
}
4 changes: 3 additions & 1 deletion test/fixture/eval-err.mjs
@@ -1,4 +1,6 @@
async function test() {
// @ts-nocheck
// eslint-disable-next-line require-await
async function test () {
throw new Error('Something went wrong in eval-err module!')
}

Expand Down
6 changes: 3 additions & 3 deletions test/fixture/resolve.mjs
@@ -1,9 +1,9 @@
import { resolvePath, createResolve, resolveImports } from 'mlly'

import.meta.resolve = createResolve({ url: import.meta.url })
console.log(await import.meta.resolve('./cjs.mjs'))
const resolve = createResolve({ url: import.meta.url })
console.log(await resolve('./cjs.mjs'))

console.log(await resolvePath('./cjs.mjs', { url: import.meta.url }))
console.log(await resolvePath('./foo', { url: import.meta.url }))

console.log(await resolveImports(`import foo from './eval.mjs'`, { url: import.meta.url }))
console.log(await resolveImports('import foo from \'./eval.mjs\'', { url: import.meta.url }))
5 changes: 5 additions & 0 deletions tsconfig.json
Expand Up @@ -3,7 +3,12 @@
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"esModuleInterop": true,
"checkJs": true,
"paths": {
"mlly": ["./"]
},
"types": [
"node"
]
Expand Down

0 comments on commit 7c1bda4

Please sign in to comment.