Skip to main content

@boost/module

Build Status npm version npm deps

Load and resolve custom file types at runtime with a more powerful Node.js require replacement.

import { requireModule } from '@boost/module';
const result = requireModule('./some/non-js/file.ts');

Or with next-generation loaders.

node --experimental-loader @boost/module/loader.mjs ./path/to/entry-point.mjs

Features#

  • CommonJS based importing with requireModule()
  • CommonJS interoperability with ESM-like files
  • ECMAScript module based importing with a custom ESM loader
  • Supported file types: TypeScript (.ts, .tsx)

Installation#

yarn add @boost/module

Documentation#

Index

Type aliases

GetFormatContext

GetFormatContext: Record<string, unknown>

LoaderDefaultGetFormat

LoaderDefaultGetFormat: (url: string, context: GetFormatContext) => Promise<GetFormatResult>

LoaderDefaultResolve

LoaderDefaultResolve: (specifier: string, context: ResolveContext) => Promise<ResolveResult>

LoaderDefaultTransformSource

LoaderDefaultTransformSource: (source: TransformSourceType, context: TransformSourceContext) => Promise<TransformSourceResult>

LoaderGetFormat

LoaderGetFormat: (url: string, context: GetFormatContext, defaultGetFormat: LoaderDefaultGetFormat) => Promise<GetFormatResult>

LoaderResolve

LoaderResolve: (specifier: string, context: ResolveContext, defaultResolve: LoaderDefaultResolve) => Promise<ResolveResult>

LoaderTransformSource

LoaderTransformSource: (source: TransformSourceType, context: TransformSourceContext, defaultTransformSource: LoaderDefaultTransformSource) => Promise<TransformSourceResult>

ModuleLike

ModuleLike<D, N>: N & { __esModule?: boolean; default?: D extends void ? N : D }

Return shape of a module. The default export can be typed with the D generic slot, and the named exports can be typed with an object in the N generic slot.

If there is no default export (classic Node.js exports pattern), then void can be passed to the D generic, which will populate the default property with the named exports.


Type parameters

  • D = unknown
  • N: object = {}

PathLike

PathLike: string | { toString?: any }

TransformSourceType

TransformSourceType: SharedArrayBuffer | Uint8Array | string