Skip to content

Commit 6b83f79

Browse files
committed
feat: add sourcemap support
1 parent 57b8eff commit 6b83f79

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@types/mocha": "^5.2.7",
5050
"@types/mz": "^0.0.32",
5151
"@types/node": "^12.12.7",
52+
"@types/source-map-support": "^0.5.4",
5253
"@typescript-eslint/eslint-plugin": "^4.11.1",
5354
"@typescript-eslint/parser": "^4.11.1",
5455
"chalk": "2.4.1",
@@ -72,6 +73,7 @@
7273
"lines-and-columns": "^1.1.6",
7374
"mz": "^2.7.0",
7475
"pirates": "^4.0.1",
76+
"source-map-support": "^0.5.21",
7577
"ts-interface-checker": "^0.1.9"
7678
},
7779
"engines": {

src/register.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as pirates from "pirates";
2+
import sourceMapSupport from "source-map-support";
23

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

@@ -29,23 +30,36 @@ export function addHook(
2930
);
3031
}
3132

33+
let sourceMapInstalled = false;
34+
35+
const installSourceMap = (): void => {
36+
if (sourceMapInstalled) return;
37+
sourceMapInstalled = true;
38+
sourceMapSupport.install();
39+
};
40+
3241
export function registerJS(hookOptions?: HookOptions): RevertFunction {
42+
installSourceMap();
3343
return addHook(".js", {transforms: ["imports", "flow", "jsx"]}, hookOptions);
3444
}
3545

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

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

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

4861
export function registerTSLegacyModuleInterop(hookOptions?: HookOptions): RevertFunction {
62+
installSourceMap();
4963
return addHook(
5064
".ts",
5165
{
@@ -57,6 +71,7 @@ export function registerTSLegacyModuleInterop(hookOptions?: HookOptions): Revert
5771
}
5872

5973
export function registerTSXLegacyModuleInterop(hookOptions?: HookOptions): RevertFunction {
74+
installSourceMap();
6075
return addHook(
6176
".tsx",
6277
{

yarn.lock

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@
168168
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.13.tgz#e743bae112bd779ac9650f907197dd2caa7f0364"
169169
integrity sha512-1x8W5OpxPq+T85OUsHRP6BqXeosKmeXRtjoF39STcdf/UWLqUsoehstZKOi0CunhVqHG17AyZgpj20eRVooK6A==
170170

171+
"@types/source-map-support@^0.5.4":
172+
version "0.5.4"
173+
resolved "https://registry.yarnpkg.com/@types/source-map-support/-/source-map-support-0.5.4.tgz#574ff6a8636bc0ebae78a8014136f749b3177d58"
174+
integrity sha512-9zGujX1sOPg32XLyfgEB/0G9ZnrjthL/Iv1ZfuAjj8LEilHZEpQSQs1scpRXPhHzGYgWiLz9ldF1cI8JhL+yMw==
175+
dependencies:
176+
source-map "^0.6.0"
177+
171178
"@typescript-eslint/eslint-plugin@^4.11.1":
172179
version "4.25.0"
173180
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.25.0.tgz#d82657b6ab4caa4c3f888ff923175fadc2f31f2a"
@@ -446,6 +453,11 @@ [email protected]:
446453
resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60"
447454
integrity sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==
448455

456+
buffer-from@^1.0.0:
457+
version "1.1.2"
458+
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5"
459+
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==
460+
449461
caching-transform@^3.0.2:
450462
version "3.0.2"
451463
resolved "https://registry.yarnpkg.com/caching-transform/-/caching-transform-3.0.2.tgz#601d46b91eca87687a281e71cef99791b0efca70"
@@ -2587,12 +2599,20 @@ socket.io@^2, socket.io@^2.3.0:
25872599
socket.io-client "2.4.0"
25882600
socket.io-parser "~3.4.0"
25892601

2602+
source-map-support@^0.5.21:
2603+
version "0.5.21"
2604+
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
2605+
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==
2606+
dependencies:
2607+
buffer-from "^1.0.0"
2608+
source-map "^0.6.0"
2609+
25902610
source-map@^0.5.0:
25912611
version "0.5.7"
25922612
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
25932613
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
25942614

2595-
source-map@^0.6.1, source-map@~0.6.1:
2615+
source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1:
25962616
version "0.6.1"
25972617
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
25982618
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==

0 commit comments

Comments
 (0)