Skip to content

Commit

Permalink
fix(types): make options optional
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 27, 2021
1 parent 477d76e commit 9240f07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/eval.ts
Expand Up @@ -23,7 +23,7 @@ export async function evalModule (code: string, opts: EvaluateOptions = {}): Pro
})
}

export function transformModule (code: string, opts: EvaluateOptions): Promise<string> {
export function transformModule (code: string, opts?: EvaluateOptions): Promise<string> {
// Convert JSON to module
if (opts.url && opts.url.endsWith('.json')) {
return Promise.resolve('export default ' + code)
Expand All @@ -37,7 +37,7 @@ export function transformModule (code: string, opts: EvaluateOptions): Promise<s
return Promise.resolve(code)
}

export async function resolveImports (code: string, opts: EvaluateOptions): Promise<string> {
export async function resolveImports (code: string, opts?: EvaluateOptions): Promise<string> {
const imports = Array.from(code.matchAll(EVAL_ESM_IMPORT_RE)).map(m => m[0])
if (!imports.length) {
return code
Expand Down
10 changes: 5 additions & 5 deletions src/resolve.ts
Expand Up @@ -86,26 +86,26 @@ function _resolve (id: string, opts: ResolveOptions = {}): string {
/**
* @deprecated please use `resolve` instead of `resolveSync`
*/
export function resolveSync (id: string, opts: ResolveOptions): string {
export function resolveSync (id: string, opts?: ResolveOptions): string {
return _resolve(id, opts)
}

export function resolve (id: string, opts: ResolveOptions): Promise<string> {
export function resolve (id: string, opts?: ResolveOptions): Promise<string> {
return pcall(resolveSync, id, opts)
}

/**
* @deprecated please use `resolvePath` instead of `resolvePathSync`
*/
export function resolvePathSync (id: string, opts: ResolveOptions) {
export function resolvePathSync (id: string, opts?: ResolveOptions) {
return fileURLToPath(resolveSync(id, opts))
}

export function resolvePath (id: string, opts: ResolveOptions) {
export function resolvePath (id: string, opts?: ResolveOptions) {
return pcall(resolvePathSync, id, opts)
}

export function createResolve (defaults: ResolveOptions) {
export function createResolve (defaults?: ResolveOptions) {
return (id, url) => {
return resolve(id, { url, ...defaults })
}
Expand Down

0 comments on commit 9240f07

Please sign in to comment.