UNPKG

716 BJavaScriptView Raw
1const tsc = require('typescript');
2const crypto = require('crypto');
3
4const babelTransformer = require('./javascript');
5const tsConfig = require('../../../tsconfig.json');
6
7module.exports = {
8 getCacheKey(src, path, configString) {
9 return crypto
10 .createHash('md5')
11 .update(src)
12 .update(configString)
13 .digest('hex');
14 },
15 process(src, path, ...rest) {
16 if (path.endsWith('.ts') || path.endsWith('.tsx')) {
17 const tsOutput = tsc.transpile(
18 src,
19 tsConfig.compilerOptions,
20 path,
21 []
22 );
23
24 const fakeJSPath = path.replace(/\.tsx?$/, '.js');
25 return babelTransformer.process(tsOutput, fakeJSPath, ...rest);
26 }
27 return src;
28 },
29};