Skip to content

Commit

Permalink
Merge pull request #410 from lijunle/ts-once
Browse files Browse the repository at this point in the history
Avoid transpile the TypeScript code twice.

closes #406, closes #407
  • Loading branch information
kulshekhar committed Jan 5, 2018
2 parents 31315fe + a594d6e commit 9eef99a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
@@ -1,7 +1,7 @@
[*.ts]
indent_style = space
indent_size = 4
indent_size = 2

[*.tsx]
indent_style = space
indent_size = 4
indent_size = 2
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -27,6 +27,7 @@ Ihor Chulinda <ichulinda@gmail.com>
J Cheyo Jimenez <cheyo@masters3d.com>
Jim Cummins <jimthedev@gmail.com>
Joscha Feth <joscha@feth.com>
Junle Li <lijunle@gmail.com>
Justin Bay <jwbay@users.noreply.github.com>
Kulshekhar Kabra <kulshekhar@users.noreply.github.com>
Kyle Roach <kroach.work@gmail.com>
Expand Down
23 changes: 0 additions & 23 deletions src/default-retrieve-file-handler.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/install.ts
@@ -1,10 +1,9 @@
import * as sourceMapSupport from 'source-map-support';
import { defaultRetrieveFileHandler } from './default-retrieve-file-handler';

export function install() {
export function install(filePath: string, fileContent: string) {
const options: sourceMapSupport.Options = {};

options.retrieveFile = defaultRetrieveFileHandler;
options.retrieveFile = path => (path === filePath ? fileContent : undefined);

/* tslint:disable */
// disabling tslint because the types for the source-map-support version
Expand Down
16 changes: 5 additions & 11 deletions src/preprocessor.ts
Expand Up @@ -58,17 +58,11 @@ export function process(
transformOptions,
);

const modified = injectSourcemapHook(outputText);

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

return modified;
}
Expand Down
10 changes: 8 additions & 2 deletions src/utils.ts
Expand Up @@ -189,10 +189,16 @@ export function cacheFile(
}
}

export function injectSourcemapHook(src: string): string {
export function injectSourcemapHook(
filePath: string,
typeScriptCode: string,
src: string,
): string {
const start = src.length > 12 ? src.substr(1, 10) : '';

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

return start === 'use strict'
? `'use strict';${sourceMapHook};${src}`
Expand Down

0 comments on commit 9eef99a

Please sign in to comment.