Skip to content

Commit 9eef99a

Browse files
authored
Merge pull request #410 from lijunle/ts-once
Avoid transpile the TypeScript code twice. closes #406, closes #407
2 parents 31315fe + a594d6e commit 9eef99a

6 files changed

Lines changed: 18 additions & 41 deletions

File tree

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[*.ts]
22
indent_style = space
3-
indent_size = 4
3+
indent_size = 2
44

55
[*.tsx]
66
indent_style = space
7-
indent_size = 4
7+
indent_size = 2

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Ihor Chulinda <ichulinda@gmail.com>
2727
J Cheyo Jimenez <cheyo@masters3d.com>
2828
Jim Cummins <jimthedev@gmail.com>
2929
Joscha Feth <joscha@feth.com>
30+
Junle Li <lijunle@gmail.com>
3031
Justin Bay <jwbay@users.noreply.github.com>
3132
Kulshekhar Kabra <kulshekhar@users.noreply.github.com>
3233
Kyle Roach <kroach.work@gmail.com>

src/default-retrieve-file-handler.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/install.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as sourceMapSupport from 'source-map-support';
2-
import { defaultRetrieveFileHandler } from './default-retrieve-file-handler';
32

4-
export function install() {
3+
export function install(filePath: string, fileContent: string) {
54
const options: sourceMapSupport.Options = {};
65

7-
options.retrieveFile = defaultRetrieveFileHandler;
6+
options.retrieveFile = path => (path === filePath ? fileContent : undefined);
87

98
/* tslint:disable */
109
// disabling tslint because the types for the source-map-support version

src/preprocessor.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,11 @@ export function process(
5858
transformOptions,
5959
);
6060

61-
const modified = injectSourcemapHook(outputText);
62-
63-
if (tsJestConfig.enableInternalCache === true) {
64-
// This config is undocumented.
65-
// This has been made configurable for now to ensure that
66-
// if this breaks something for existing users, there's a quick fix
67-
// in place.
68-
// If this doesn't cause a problem, this if block will be removed
69-
// in a future version
70-
cacheFile(jestConfig, filePath, modified);
71-
}
61+
const modified = injectSourcemapHook(
62+
filePath,
63+
tsTranspiled.outputText,
64+
outputText,
65+
);
7266

7367
return modified;
7468
}

src/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,16 @@ export function cacheFile(
189189
}
190190
}
191191

192-
export function injectSourcemapHook(src: string): string {
192+
export function injectSourcemapHook(
193+
filePath: string,
194+
typeScriptCode: string,
195+
src: string,
196+
): string {
193197
const start = src.length > 12 ? src.substr(1, 10) : '';
194198

195-
const sourceMapHook = `require('ts-jest').install()`;
199+
const filePathParam = JSON.stringify(filePath);
200+
const codeParam = JSON.stringify(typeScriptCode);
201+
const sourceMapHook = `require('ts-jest').install(${filePathParam}, ${codeParam})`;
196202

197203
return start === 'use strict'
198204
? `'use strict';${sourceMapHook};${src}`

0 commit comments

Comments
 (0)