From 5795a83b87d0005dd4796ede03eeef6944c26428 Mon Sep 17 00:00:00 2001 From: Gordon Leigh Date: Tue, 29 Dec 2020 04:18:07 +0000 Subject: [PATCH] Add options argument to addHook to pass to pirates.addHook (#571) I've added an optional argument to addHook to pass through to pirates. You would use it like this: addHook(".js", { transforms: ["imports"] }, { ignoreNodeModules: false }); I also removed the ts-ignore comment because pirates has types now. --- src/register.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/register.ts b/src/register.ts index bb69f288..ae7b93c8 100644 --- a/src/register.ts +++ b/src/register.ts @@ -1,9 +1,13 @@ -// @ts-ignore: no types available. import * as pirates from "pirates"; import {Options, transform} from "./index"; -export function addHook(extension: string, options: Options): void { +export interface HookOptions { + matcher?: (code: string) => boolean; + ignoreNodeModules?: boolean; +} + +export function addHook(extension: string, options: Options, hookOptions?: HookOptions): void { pirates.addHook( (code: string, filePath: string): string => { const {code: transformedCode, sourceMap} = transform(code, { @@ -15,7 +19,7 @@ export function addHook(extension: string, options: Options): void { const suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${mapBase64}`; return `${transformedCode}\n${suffix}`; }, - {exts: [extension]}, + {...hookOptions, exts: [extension]}, ); }