Skip to content

Commit

Permalink
feat: add sourcemap support
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed Dec 22, 2021
1 parent 57b8eff commit b2f3cac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@types/mocha": "^5.2.7",
"@types/mz": "^0.0.32",
"@types/node": "^12.12.7",
"@types/source-map-support": "^0.5.4",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/parser": "^4.11.1",
"chalk": "2.4.1",
Expand All @@ -72,6 +73,7 @@
"lines-and-columns": "^1.1.6",
"mz": "^2.7.0",
"pirates": "^4.0.1",
"source-map-support": "^0.5.21",
"ts-interface-checker": "^0.1.9"
},
"engines": {
Expand Down
15 changes: 15 additions & 0 deletions src/register.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as pirates from "pirates";
import sourceMapSupport from "source-map-support";

import {Options, transform} from "./index";

Expand Down Expand Up @@ -29,23 +30,36 @@ export function addHook(
);
}

let sourceMapInstalled = false;

const installSourceMap = (): void => {
if (sourceMapInstalled) return;
sourceMapInstalled = true;
sourceMapSupport.install();
};

export function registerJS(hookOptions?: HookOptions): RevertFunction {
installSourceMap();
return addHook(".js", {transforms: ["imports", "flow", "jsx"]}, hookOptions);
}

export function registerJSX(hookOptions?: HookOptions): RevertFunction {
installSourceMap();
return addHook(".jsx", {transforms: ["imports", "flow", "jsx"]}, hookOptions);
}

export function registerTS(hookOptions?: HookOptions): RevertFunction {
installSourceMap();
return addHook(".ts", {transforms: ["imports", "typescript"]}, hookOptions);
}

export function registerTSX(hookOptions?: HookOptions): RevertFunction {
installSourceMap();
return addHook(".tsx", {transforms: ["imports", "typescript", "jsx"]}, hookOptions);
}

export function registerTSLegacyModuleInterop(hookOptions?: HookOptions): RevertFunction {
installSourceMap();
return addHook(
".ts",
{
Expand All @@ -57,6 +71,7 @@ export function registerTSLegacyModuleInterop(hookOptions?: HookOptions): Revert
}

export function registerTSXLegacyModuleInterop(hookOptions?: HookOptions): RevertFunction {
installSourceMap();
return addHook(
".tsx",
{
Expand Down

0 comments on commit b2f3cac

Please sign in to comment.