Skip to content

Commit 2af6d2a

Browse files
authored
Merge pull request #532 from cspotcode/import-babel-on-demand
Import babel deps on-demand, skipping if skipBabel is true
2 parents 6e530aa + fdebcd9 commit 2af6d2a

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/postprocess.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@
22
* Postprocess step. Based on babel-jest: https://github.com/facebook/jest/blob/master/packages/babel-jest/src/index.js
33
* https://github.com/facebook/jest/blob/9b157c3a7c325c3971b2aabbe4c8ab4ce0b0c56d/packages/babel-jest/src/index.js
44
*/
5-
import * as babel from 'babel-core';
6-
import istanbulPlugin from 'babel-plugin-istanbul';
7-
import * as jestPreset from 'babel-preset-jest';
5+
import * as __types__babel from 'babel-core';
6+
import __types__istanbulPlugin from 'babel-plugin-istanbul';
7+
import * as __types__jestPreset from 'babel-preset-jest';
8+
let babel: typeof __types__babel;
9+
let istanbulPlugin: typeof __types__istanbulPlugin;
10+
let jestPreset: typeof __types__jestPreset;
11+
function importBabelDeps() {
12+
if (babel) {
13+
return;
14+
}
15+
babel = require('babel-core');
16+
istanbulPlugin = require('babel-plugin-istanbul').default;
17+
jestPreset = require('babel-preset-jest');
18+
}
819
import { CompilerOptions } from 'typescript/lib/typescript';
920
import {
1021
BabelTransformOptions,
@@ -37,6 +48,7 @@ export function postProcessCode(
3748
function createBabelTransformer(
3849
options: BabelTransformOptions,
3950
): PostProcessHook {
51+
importBabelDeps();
4052
options = {
4153
...options,
4254
plugins: options.plugins || [],

0 commit comments

Comments
 (0)