Skip to content

Commit 958affe

Browse files
committed
feat: create new @jest/transform package
1 parent e760ec4 commit 958affe

File tree

19 files changed

+127
-56
lines changed

19 files changed

+127
-56
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
- `[jest-resolve]`: Migrate to TypeScript ([#7871](https://github.com/facebook/jest/pull/7871))
4141
- `[@jest/reporter]`: New package extracted from `jest-cli` ([#7902](https://github.com/facebook/jest/pull/7902))
4242
- `[jest-snapshot]`: Migrate to TypeScript ([#7899](https://github.com/facebook/jest/pull/7899))
43+
- `[@jest/transform]`: New package extracted from `jest-runtime`
4344

4445
### Performance
4546

packages/jest-cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "build/jest.js",
66
"dependencies": {
77
"@jest/reporters": "^24.1.0",
8+
"@jest/transform": "^24.1.0",
89
"ansi-escapes": "^3.0.0",
910
"chalk": "^2.0.1",
1011
"exit": "^0.1.2",

packages/jest-cli/src/runGlobalHook.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {Test} from 'types/TestRunner';
1313
import {extname} from 'path';
1414
import pEachSeries from 'p-each-series';
1515
import {addHook} from 'pirates';
16-
import Runtime from 'jest-runtime';
16+
import {ScriptTransformer} from '@jest/transform';
1717

1818
// copied from https://github.com/babel/babel/blob/56044c7851d583d498f919e9546caddf8f80a72f/packages/babel-helpers/src/helpers.js#L558-L562
1919
function _interopRequireDefault(obj) {
@@ -52,7 +52,7 @@ export default ({
5252
: // Fallback to first config
5353
allTests[0].context.config;
5454

55-
const transformer = new Runtime.ScriptTransformer(projectConfig);
55+
const transformer = new ScriptTransformer(projectConfig);
5656

5757
// Load the transformer to avoid a cycle where we need to load a
5858
// transformer in order to transform it in the require hooks

packages/jest-reporters/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"version": "24.1.0",
55
"main": "build/index.js",
66
"dependencies": {
7+
"@jest/transform": "^24.1.0",
78
"chalk": "^2.0.1",
89
"exit": "^0.1.2",
910
"glob": "^7.1.2",
10-
"jest-runtime": "^24.1.0",
1111
"istanbul-api": "^2.1.1",
1212
"istanbul-lib-coverage": "^2.0.2",
1313
"istanbul-lib-instrument": "^3.0.1",

packages/jest-reporters/src/generateEmptyCoverage.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {GlobalConfig, ProjectConfig, Path} from 'types/Config';
1111

1212
import {readInitialCoverage} from 'istanbul-lib-instrument';
1313
import {classes} from 'istanbul-lib-coverage';
14-
import Runtime from 'jest-runtime';
14+
import {shouldInstrument, ScriptTransformer} from '@jest/transform';
1515

1616
export type CoverageWorkerResult = {|
1717
coverage: any,
@@ -33,9 +33,9 @@ export default function(
3333
collectCoverageFrom: globalConfig.collectCoverageFrom,
3434
collectCoverageOnlyFrom: globalConfig.collectCoverageOnlyFrom,
3535
};
36-
if (Runtime.shouldInstrument(filename, coverageOptions, config)) {
36+
if (shouldInstrument(filename, coverageOptions, config)) {
3737
// Transform file with instrumentation to make sure initial coverage data is well mapped to original code.
38-
const {code, mapCoverage, sourceMapPath} = new Runtime.ScriptTransformer(
38+
const {code, mapCoverage, sourceMapPath} = new ScriptTransformer(
3939
config,
4040
).transformSource(filename, source, true);
4141
const extracted = readInitialCoverage(code);

packages/jest-runtime/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"main": "build/index.js",
1111
"dependencies": {
1212
"@babel/core": "^7.1.0",
13+
"@jest/transform": "^24.1.0",
1314
"babel-plugin-istanbul": "^5.1.0",
1415
"chalk": "^2.0.1",
1516
"convert-source-map": "^1.4.0",

packages/jest-runtime/src/__tests__/instrumentation.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import vm from 'vm';
1212
import path from 'path';
1313
import os from 'os';
14-
import ScriptTransformer from '../ScriptTransformer';
14+
import {ScriptTransformer} from '@jest/transform';
1515

1616
jest.mock('vm');
1717

packages/jest-runtime/src/helpers.js

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,9 @@
55
import type {Path} from 'types/Config';
66

77
import path from 'path';
8-
import chalk from 'chalk';
98
import slash from 'slash';
109
import glob from 'glob';
1110

12-
const DOT = ' \u2022 ';
13-
14-
export const enhanceUnexpectedTokenMessage = (e: Error) => {
15-
e.stack =
16-
`${chalk.bold.red('Jest encountered an unexpected token')}
17-
18-
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
19-
20-
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
21-
22-
Here's what you can do:
23-
${DOT}To have some of your "node_modules" files transformed, you can specify a custom ${chalk.bold(
24-
'"transformIgnorePatterns"',
25-
)} in your config.
26-
${DOT}If you need a custom transformation specify a ${chalk.bold(
27-
'"transform"',
28-
)} option in your config.
29-
${DOT}If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the ${chalk.bold(
30-
'"moduleNameMapper"',
31-
)} config option.
32-
33-
You'll find more details and examples of these config options in the docs:
34-
${chalk.cyan('https://jestjs.io/docs/en/configuration.html')}
35-
36-
${chalk.bold.red('Details:')}
37-
38-
` + e.stack;
39-
40-
return e;
41-
};
42-
4311
export const findSiblingsWithFileExtension = (
4412
moduleFileExtensions: Array<string>,
4513
from: Path,

packages/jest-runtime/src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ import Resolver from 'jest-resolve';
2424
import {createDirectory, deepCyclicCopy} from 'jest-util';
2525
import {escapePathForRegex} from 'jest-regex-util';
2626
import Snapshot from 'jest-snapshot';
27+
import {ScriptTransformer, shouldInstrument} from '@jest/transform';
2728
import fs from 'graceful-fs';
2829
import stripBOM from 'strip-bom';
29-
import ScriptTransformer from './ScriptTransformer';
30-
import shouldInstrument from './shouldInstrument';
3130
import {run as cliRun} from './cli';
3231
import {options as cliOptions} from './cli/args';
3332
import {findSiblingsWithFileExtension} from './helpers';

packages/jest-transform/.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/__mocks__/**
2+
**/__tests__/**
3+
src

0 commit comments

Comments
 (0)