Merge pull request #34 from luhmann/add-tsconfig-support

Use "compilerOptions" from projects "tsconfig.json" for jest
This commit is contained in:
William Monk
2017-04-12 14:14:47 +01:00
committed by GitHub
2 changed files with 20 additions and 7 deletions

View File

@@ -1,21 +1,33 @@
// Copyright 2004-present Facebook. All Rights Reserved.
const fs = require('fs');
const tsc = require('typescript');
const tsconfigPath = require('app-root-path').resolve('/tsconfig.json');
let compilerConfig = {
module: tsc.ModuleKind.CommonJS,
jsx: tsc.JsxEmit.React,
}
if (fs.existsSync(tsconfigPath)) {
try {
const tsconfig = require(tsconfigPath);
if (tsconfig && tsconfig.compilerOptions) {
compilerConfig = tsconfig.compilerOptions;
}
} catch (e) { /* Do nothing - default is set */ }
}
module.exports = {
process(src, path) {
if (path.endsWith('.ts') || path.endsWith('.tsx')) {
return tsc.transpile(
src,
{
module: tsc.ModuleKind.CommonJS,
jsx: tsc.JsxEmit.React,
},
path,
[]
compilerConfig,
path, []
);
}
return src;
},
};

View File

@@ -24,6 +24,7 @@
"react-scripts-ts": "./bin/react-scripts-ts.js"
},
"dependencies": {
"app-root-path": "^2.0.1",
"autoprefixer": "6.7.2",
"case-sensitive-paths-webpack-plugin": "1.1.4",
"chalk": "1.1.3",