import-meta-ponyfill
Version:
This library implements some standard interfaces of [import.meta](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta) with the aim of resolving the confusion caused by multiple standards in Node.js. It includes unified
95 lines (94 loc) • 3.33 kB
text/typescript
import { URL } from "node:url";
declare global {
interface ImportMeta {
}
}
export interface PonyfillImportMeta extends ImportMeta {
/** A string representation of the fully qualified module URL. When the
* module is loaded locally, the value will be a file URL (e.g.
* `file:///path/module.ts`).
*
* You can also parse the string as a URL to determine more information about
* how the current module was loaded. For example to determine if a module was
* local or not:
*
* ```ts
* const url = new URL(import.meta.url);
* if (url.protocol === "file:") {
* console.log("this module was loaded locally");
* }
* ```
*/
url: string;
/**
* A function that returns the resolved specifier,
* see [`import.meta.resolve(specifier)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve),
* even attempting to return a result for non-existent paths.
*
* ```ts
* console.log(import.meta.resolve("./foo.js"));
* // file:///dev/foo.js
* ```
*
* @param specifier The module specifier to resolve relative to `parent`.
* @param parent The absolute parent module URL to resolve from.
* @returns The absolute (`file:`) URL string for the resolved module.
*/
resolve(specifier: string, parent?: string | URL | undefined): string;
/**
* A function that returns resolved specifier as if it would be imported
* using `import.meta.resolve(specifier) or require.resolve(specifier)`.
*
* ```ts
* console.log(import.meta.nodeResolve("./foo.js"));
* // file:///dev/foo.js
* ```
*
* @param specifier The module specifier to resolve relative to `parent`.
* @param parent The absolute parent module URL to resolve from.
* @returns The absolute (`file:`) URL string for the resolved module.
*/
nodeResolve(specifier: string, parent?: string | URL | undefined): string;
/** A flag that indicates if the current module is the main module that was
* called when starting the program under Deno.
*
* ```ts
* if (import.meta.main) {
* // this was loaded as the main module, maybe do some bootstrapping
* }
* ```
*/
main: boolean;
/** The absolute path of the current module.
*
* This property is only provided for local modules (ie. using `file://` URLs).
*
* Example:
* ```
* // Unix
* console.log(import.meta.filename); // /home/alice/my_module.ts
*
* // Windows
* console.log(import.meta.filename); // C:\alice\my_module.ts
* ```
*/
filename: string;
/** The absolute path of the directory containing the current module.
*
* This property is only provided for local modules (ie. using `file://` URLs).
*
* * Example:
* ```
* // Unix
* console.log(import.meta.dirname); // /home/alice
*
* // Windows
* console.log(import.meta.dirname); // C:\alice
* ```
*/
dirname: string;
}
export declare const import_meta_ponyfill_commonjs: any;
export declare const import_meta_ponyfill_esmodule: any;
export { import_meta_ponyfill_esmodule as import_meta_ponyfill };
export default import_meta_ponyfill_esmodule;