@boost/module
Version:
Module resolving and loading utilities with TypeScript support.
31 lines • 1.44 kB
TypeScript
/// <reference types="node" />
import type { ModuleLike, PathLike } from './types';
/**
* Works in a similar fashion to the native NodeJS `require()`, but can also
* import custom file types like TypeScript, and also returns a module shape
* that aligns with the ESM loader specification.
*
* When loading custom file types, the extension in the file path is optional,
* as NodeJS will iterate through each extension until a file is found.
*
* ```ts
* import { requireModule } from '@boost/module';
*
* const result = requireModule('../../some/module');
* ```
*
* Caveats and differences:
*
* - CommonJS files that utilize `module.exports` (default export) will have this
* value returned under a `default` property, instead of being returned directly.
* - CommonJS files that utilize multiple `exports.<name>` (named exports) will
* have these values returned as properties on the result object, and will also
* be found on the `default` property.
* - "ES module like" files will be returned as-is. These are files that are built
* with Babel or TypeScript and export an `__esModule` internal property.
*
* These changes align with `import()` and the ES module system. We made this
* decision for consistency and reliability.
*/
export declare function requireModule<D = unknown, N extends object = {}>(path: PathLike, requirer?: NodeRequire): ModuleLike<D, N>;
//# sourceMappingURL=requireModule.d.ts.map