Package-level declarations

Types

Link copied to clipboard
sealed external interface EnableCompileCacheResult
Link copied to clipboard
sealed external interface ImportAttributes
Link copied to clipboard
sealed external interface ImportMeta
Link copied to clipboard
typealias InitializeHook<Data> = (data: Data) -> <Error class: unknown class><<Error class: unknown class>>

The initialize hook provides a way to define a custom function that runs in the hooks thread when the hooks module is initialized. Initialization happens when the hooks module is registered via {@link register}.

Link copied to clipboard
sealed external interface LoadFnOutput
Link copied to clipboard
typealias LoadHook = (url: String, context: LoadHookContext, nextLoad: (url: String, context: LoadHookContext?) -> <Error class: unknown class><LoadFnOutput>) -> <Error class: unknown class><LoadFnOutput>

The load hook provides a way to define a custom method of determining how a URL should be interpreted, retrieved, and parsed. It is also in charge of validating the import attributes.

Link copied to clipboard
sealed external interface LoadHookContext
Link copied to clipboard
external class Module
Link copied to clipboard
sealed external interface ModuleFormat
Link copied to clipboard
typealias ModuleSource = Any
Link copied to clipboard
sealed external interface RegisterOptions<Data>
Link copied to clipboard
sealed external interface Require
Link copied to clipboard
sealed external interface RequireExtensions
Link copied to clipboard
sealed external interface RequireResolve
Link copied to clipboard
sealed external interface RequireResolveOptions
Link copied to clipboard
sealed external interface ResolveFnOutput
Link copied to clipboard
typealias ResolveHook = (specifier: String, context: ResolveHookContext, nextResolve: (specifier: String, context: ResolveHookContext?) -> <Error class: unknown class><ResolveFnOutput>) -> <Error class: unknown class><ResolveFnOutput>

The resolve hook chain is responsible for telling Node.js where to find and how to cache a given import statement or expression, or require call. It can optionally return a format (such as 'module') as a hint to the load hook. If a format is specified, the load hook is ultimately responsible for providing the final format value (and it is free to ignore the hint provided by resolve); if resolve provides a format, a custom load hook is required even if only to pass the value to the Node.js default load hook.

Link copied to clipboard
sealed external interface ResolveHookContext
Link copied to clipboard
external class SourceMap
Link copied to clipboard
sealed external interface SourceMapConstructorOptions
Link copied to clipboard
sealed external interface SourceMapPayload
Link copied to clipboard
sealed external interface SourceMapping
Link copied to clipboard
sealed external interface SourceOrigin
Link copied to clipboard
sealed external interface StripTypeScriptTypesOptions
Link copied to clipboard
sealed external interface StripTypeScriptTypesOptionsMode

Properties

Link copied to clipboard
external val builtinModules: <Error class: unknown class><String>

A list of the names of all modules provided by Node.js. Can be used to verify if a module is maintained by a third party or not.

Functions

Link copied to clipboard
external fun createRequire(path: <Error class: unknown class>): Require
external fun createRequire(path: String): Require
Link copied to clipboard
external fun enableCompileCache(cacheDir: String = definedExternally): EnableCompileCacheResult

Enable module compile cache in the current Node.js instance.

Link copied to clipboard
external fun findPackageJSON(specifier: <Error class: unknown class>): String?
external fun findPackageJSON(specifier: String): String?
external fun findPackageJSON(specifier: <Error class: unknown class>, base: <Error class: unknown class> = definedExternally): String?
external fun findPackageJSON(specifier: <Error class: unknown class>, base: String = definedExternally): String?
external fun findPackageJSON(specifier: String, base: <Error class: unknown class> = definedExternally): String?
external fun findPackageJSON(specifier: String, base: String = definedExternally): String?
Link copied to clipboard
external fun findSourceMap(path: String): SourceMap?

path is the resolved path for the file for which a corresponding source map should be fetched.

Link copied to clipboard
external fun flushCompileCache()

Flush the module compile cache accumulated from modules already loaded in the current Node.js instance to disk. This returns after all the flushing file system operations come to an end, no matter they succeed or not. If there are any errors, this will fail silently, since compile cache misses should not interfere with the actual operation of the application.

Link copied to clipboard
external fun getCompileCacheDir(): String?
Link copied to clipboard
external fun isBuiltin(moduleName: String): Boolean
Link copied to clipboard
external fun <Data> register(specifier: <Error class: unknown class>)
external fun <Data> register(specifier: String)
external fun <Data> register(    specifier: <Error class: unknown class>,     parentURL: <Error class: unknown class> = definedExternally,     options: RegisterOptions<Data> = definedExternally)
external fun <Data> register(    specifier: <Error class: unknown class>,     parentURL: String = definedExternally,     options: RegisterOptions<Data> = definedExternally)
external fun <Data> register(    specifier: String,     parentURL: <Error class: unknown class> = definedExternally,     options: RegisterOptions<Data> = definedExternally)
external fun <Data> register(specifier: String, parentURL: String = definedExternally, options: RegisterOptions<Data> = definedExternally)

Register a module that exports hooks that customize Node.js module resolution and loading behavior. See Customization hooks.

external fun <Data> register(specifier: <Error class: unknown class>, options: RegisterOptions<Data> = definedExternally)
external fun <Data> register(specifier: String, options: RegisterOptions<Data> = definedExternally)
Link copied to clipboard
external fun runMain(main: String = definedExternally)
Link copied to clipboard
external fun stripTypeScriptTypes(code: String, options: StripTypeScriptTypesOptions = definedExternally): String

module.stripTypeScriptTypes() removes type annotations from TypeScript code. It can be used to strip type annotations from TypeScript code before running it with vm.runInContext() or vm.compileFunction(). By default, it will throw an error if the code contains TypeScript features that require transformation such as Enums, see type-stripping for more information. When mode is 'transform', it also transforms TypeScript features to JavaScript, see transform TypeScript features for more information. When mode is 'strip', source maps are not generated, because locations are preserved. If sourceMap is provided, when mode is 'strip', an error will be thrown.

Link copied to clipboard
external fun syncBuiltinESMExports()

The module.syncBuiltinESMExports() method updates all the live bindings for builtin ES Modules to match the properties of the CommonJS exports. It does not add or remove exported names from the ES Modules.

Link copied to clipboard
external fun wrap(script: String): String