-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose resolveImports and improve docs
- Loading branch information
Showing
4 changed files
with
82 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,36 @@ | ||
// CommonJS | ||
|
||
export interface CommonjsContext { | ||
__filename: string | ||
__dirname: string | ||
} | ||
export type createCommonJS = (importMeta: ImportMeta) => CommonjsContext | ||
|
||
// Resolve | ||
|
||
export interface ResolveOptions { | ||
from?: string | URL | ||
conditions?: string[] | ||
} | ||
|
||
export type ResolveFn<T> = (id: string, opts: ResolveOptions) => T | ||
export type resolve = ResolveFn<Promise<string>> | ||
export type resolveSync = ResolveFn<string> | ||
export type resolvePath = ResolveFn<Promise<string>> | ||
export type resolveSync = ResolveFn<string> | ||
export type resolvePathSync = ResolveFn<string> | ||
export type createResolve = (defaults: ResolveOptions) => ResolveFn<Promise<string>> | ||
export type resolveImports = (code: string, opts: ResolveOptions) => Promise<string> | ||
|
||
export type createResolve = (from: ImportMeta|string) => ResolveFn<Promise<string>> | ||
|
||
export interface EvaluateOptions extends ResolveOptions { | ||
from?: URL | string | ||
} | ||
export interface ReadOptions extends ResolveOptions { | ||
} | ||
// Evaluate | ||
|
||
export interface EvaluateOptions extends ResolveOptions {} | ||
|
||
export type loadModule = (id: string, opts?: EvaluateOptions) => Promise<any> | ||
export type evalModule = (code: string, opts?: EvaluateOptions) => Promise<any> | ||
export type readModule = (id: string, opts?: ReadOptions) => Promise<any> | ||
export type readModule = (id: string, opts?: ResolveOptions) => Promise<any> | ||
export type toDataURL = (code: string) => string | ||
|
||
// Path Utils | ||
|
||
export type fileURLToPath = (id: URL | string) => string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { resolvePath, createResolve } from 'mlly' | ||
import { resolvePath, createResolve, resolveImports } from 'mlly' | ||
|
||
const importResolve = createResolve(import.meta) | ||
console.log(await importResolve('./cjs.mjs')) | ||
import.meta.resolve = import.meta.resolve || createResolve({ from : import.meta.url }) | ||
|
||
console.log(await import.meta.resolve('./cjs.mjs')) | ||
|
||
console.log(await resolvePath('./cjs.mjs', { from: import.meta.url })) | ||
|
||
console.log(await resolveImports(`import foo from './eval.mjs'`, { from: import.meta.url })) |