Skip to content

Commit

Permalink
Add options argument to addHook to pass to pirates.addHook (#571)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Gordon Leigh authored Dec 29, 2020
1 parent 2c53710 commit 5795a83
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/register.ts
Original file line number Diff line number Diff line change
@@ -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, {
Expand All @@ -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]},
);
}

Expand Down

0 comments on commit 5795a83

Please sign in to comment.