declare namespace _exports { export { LoadArgs, Metadata }; } declare function _exports(core: { readonly logger: import("@contrast/logger").Logger; readonly messages: import("@contrast/common").Messages; readonly appInfo: import("@contrast/common").AppInfo; depHooks: DepHooks; }): DepHooks; declare namespace _exports { export { DepHooks }; } export = _exports; type LoadArgs = { request: string; parent: Module; }; type Metadata = import("./package-finder").Metadata; /** * @typedef {Object} LoadArgs * @property {string} request * @property {Module} parent */ /** @typedef {import('./package-finder').Metadata} Metadata */ /** * Allows clients to register function handlers which run as a 'post-hook' at * require-time. */ declare class DepHooks { /** * @param {Object} opts * @param {import('pino').Logger} opts.logger * @param {import('@contrast/common').Messages} opts.messages * @param {import('@contrast/common').AppInfo} opts.appInfo */ constructor({ logger, messages, appInfo }: { logger: import("pino").Logger; messages: import("@contrast/common").Messages; appInfo: import("@contrast/common").AppInfo; }); /** @type {import('pino').Logger} */ logger: import("pino").Logger; /** @type {import('@contrast/common').Messages} */ messages: import("@contrast/common").Messages; /** @type {HandlerInvoker} */ invoker: HandlerInvoker; /** @type {ExportHandlerRegistry} */ registry: ExportHandlerRegistry; /** @type {WeakMap} */ requiredModules: WeakMap; /** @type {Set} */ resets: Set; /** * Registers handlers to run after the described module is required. * @template {Object} T * @param {ExportHookDescriptor.Descriptor | string} descriptor describes the module to hook * @param {ExportHookDescriptor.Handler[]} handlers the function hooks to execute after require */ register(descriptor: ExportHookDescriptor.Descriptor | string, ...handlers: ExportHookDescriptor.Handler[]): void; /** Alias for `DepHooks#resolve` */ resolve: (descriptor: ExportHookDescriptor.Descriptor | string, ...handlers: ExportHookDescriptor.Handler[]) => void; /** * Provided with an export, a collection of handlers, and metadata, will * invoke only the handlers which have not yet run on the export instance. * @template {Object} T * @param {T} xport the exported value of a required module * @param {ExportHookDescriptor.Handler[]} handlers the function hooks to execute on require * @param {Metadata} metadata the export's metadata * @returns {T} */ runRequireHandlers(xport: T, handlers: ExportHookDescriptor.Handler[], metadata: Metadata): T; /** * Checks if module name exists in resets set. If so, it will remove it from * the set as well as remove it from the invoker WeakMap. This will force * instrumentation handlers to re-run. This use case is only used for testing * of the node agent in certain cases. * @template {Object} T * @param {string} request the string passed to require() * @param {T} xport the exported value of a required module */ maybeClearHandlers(request: string, xport: T): void; /** * Instruments the Module._load method (invoked by require) to run registered handlers _after_ the modules * have loaded/compiled. Any value returned by the handlers will replace the return value of Module._load * and thus replace the export. This only works when the modules are required, but not imported. This is * due to how Node's ModuleWrap works, as it sets the export from the cjsExportCache and not from the return * value of Module._load like require does. In order to replace a target CJS export that is imported, we * also need to patch _compile (see below). We cannot replace the value of a built-in that is imported, but * we haven't had the need (we only really need to do that if an export is a function we need to patch e.g. * fastify, or connect middleware). We don't limit the Module._load patch to patching only built-ins, because * we need to support dep-hook handlers that need to run multiple times (via rerun option method that is * passed to handlers). * * This also instruments the _compile instance method with very similar logic to to the Module._load patch. * By patching _compile, we can set the value of module.exports directly in an earlier in the stage of CJS * module loading which occurs before the module is cached. This way we _can_ replace the export if the target * module is imported. The _compile function gets called exactly once per loaded module (excluding built-ins). * * @see https://github.com/nodejs/node/blob/main/lib/internal/modules/cjs/loader.js * @see https://github.com/nodejs/node/blob/main/lib/internal/modules/esm/translators.js */ install(): void; originalLoad: any; originalCompile: any; /** * Resets Module's _load method to the original value. */ uninstall(): void; /** * Resets the seen handlers for a given module - they will be re-run on next * require. * @param {string} request the string passed to require() */ reset(request: string): void; } import Module = require("module"); import HandlerInvoker = require("./handler-invoker"); import ExportHandlerRegistry = require("./export-handler-registry"); import ExportHookDescriptor = require("./export-hook-descriptor"); //# sourceMappingURL=index.d.ts.map