Skip to content

Commit

Permalink
chore: create new @jest/source-maps package
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Mar 3, 2019
1 parent 4c25942 commit 3d1e501
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
- `[jest-validate]`: Migrate to TypeScript ([#7991](https://github.com/facebook/jest/pull/7991))
- `[docs]`: Update CONTRIBUTING.md to add information about running jest with `jest-circus` locally ([#8013](https://github.com/facebook/jest/pull/8013)).
- `[@jest/core]`: Migrate to TypeScript ([#7998](https://github.com/facebook/jest/pull/7998))
- `[@jest/source-map]`: Extract `getCallsite` function from `jest-util` into a new separate package ([#8029](https://github.com/facebook/jest/pull/8029))

### Performance

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ PASS __tests__/console.test.js
15 | });
16 |
at BufferedConsole.log (../../packages/jest-util/build/BufferedConsole.js:172:10)
at BufferedConsole.log (../../packages/jest-util/build/BufferedConsole.js:180:10)
at log (__tests__/console.test.js:13:13)
`;
1 change: 1 addition & 0 deletions packages/jest-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"types": "build/index.d.ts",
"dependencies": {
"@jest/environment": "^24.1.0",
"@jest/source-map": "^24.1.0",
"@jest/transform": "^24.1.0",
"@jest/types": "^24.1.0",
"@types/yargs": "^12.0.2",
Expand Down
7 changes: 4 additions & 3 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
*/

import path from 'path';
import {Config, SourceMaps} from '@jest/types';
import {Config} from '@jest/types';
import {
Jest,
JestEnvironment,
LocalModuleRequire,
Module,
} from '@jest/environment';
import {SourceMapRegistry} from '@jest/source-map';
import jestMock, {MockFunctionMetadata} from 'jest-mock';
import HasteMap, {ModuleMap} from 'jest-haste-map';
import {formatStackTrace, separateMessageFromStack} from 'jest-message-util';
Expand Down Expand Up @@ -102,7 +103,7 @@ class Runtime {
private _shouldAutoMock: boolean;
private _shouldMockModuleCache: BooleanObject;
private _shouldUnmockTransitiveDependenciesCache: BooleanObject;
private _sourceMapRegistry: SourceMaps.SourceMapRegistry;
private _sourceMapRegistry: SourceMapRegistry;
private _scriptTransformer: ScriptTransformer;
private _transitiveShouldMock: BooleanObject;
private _unmockList: RegExp | undefined;
Expand Down Expand Up @@ -523,7 +524,7 @@ class Runtime {
}, {});
}

getSourceMaps(): SourceMaps.SourceMapRegistry {
getSourceMaps(): SourceMapRegistry {
return this._sourceMapRegistry;
}

Expand Down
1 change: 1 addition & 0 deletions packages/jest-runtime/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{"path": "../jest-regex-util"},
{"path": "../jest-resolve"},
{"path": "../jest-snapshot"},
{"path": "../jest-source-map"},
{"path": "../jest-types"},
{"path": "../jest-util"},
{"path": "../jest-validate"},
Expand Down
3 changes: 3 additions & 0 deletions packages/jest-source-map/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/__mocks__/**
**/__tests__/**
src
24 changes: 24 additions & 0 deletions packages/jest-source-map/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@jest/source-map",
"version": "24.1.0",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
"directory": "packages/jest-source-map"
},
"license": "MIT",
"main": "build/index.js",
"types": "build/index.d.ts",
"dependencies": {
"callsites": "^3.0.0",
"graceful-fs": "^4.1.15",
"source-map": "^0.6.0"
},
"devDependencies": {
"@types/graceful-fs": "^4.1.2"
},
"engines": {
"node": ">= 6"
},
"gitHead": "634e5a54f46b2a62d1dc81a170562e6f4e55ad60"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import fs from 'graceful-fs';
import callsites, {CallSite} from 'callsites';
import {SourceMapConsumer} from 'source-map';
import {SourceMaps} from '@jest/types';
import {SourceMapRegistry} from './types';

// Copied from https://github.com/rexxars/sourcemap-decorate-callsites/blob/5b9735a156964973a75dc62fd2c7f0c1975458e8/lib/index.js#L113-L158
const addSourceMapConsumer = (
Expand Down Expand Up @@ -46,10 +46,7 @@ const addSourceMapConsumer = (
});
};

export default (
level: number,
sourceMaps?: SourceMaps.SourceMapRegistry | null,
) => {
export default (level: number, sourceMaps?: SourceMapRegistry | null) => {
const levelAfterThisCall = level + 1;
const stack = callsites()[levelAfterThisCall];
const sourceMapFileName = sourceMaps && sourceMaps[stack.getFileName() || ''];
Expand Down
9 changes: 9 additions & 0 deletions packages/jest-source-map/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

export {default as getCallsite} from './getCallsite';
export {SourceMapRegistry} from './types';
File renamed without changes.
7 changes: 7 additions & 0 deletions packages/jest-source-map/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build"
}
}
3 changes: 1 addition & 2 deletions packages/jest-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import * as Config from './Config';
import * as Console from './Console';
import * as Matchers from './Matchers';
import * as SourceMaps from './SourceMaps';
import * as TestResult from './TestResult';
import * as Global from './Global';

export {Config, Console, Matchers, SourceMaps, TestResult, Global};
export {Config, Console, Matchers, TestResult, Global};
1 change: 1 addition & 0 deletions packages/jest-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"types": "build/index.d.ts",
"dependencies": {
"@jest/fake-timers": "^24.1.0",
"@jest/source-map": "^24.1.0",
"@jest/types": "^24.1.0",
"@types/node": "*",
"callsites": "^3.0.0",
Expand Down
12 changes: 5 additions & 7 deletions packages/jest-util/src/BufferedConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ import assert from 'assert';
import {Console} from 'console';
import {format} from 'util';
import chalk from 'chalk';
import {Console as ConsoleType, SourceMaps} from '@jest/types';
import getCallsite from './getCallsite';
import {Console as ConsoleType} from '@jest/types';
import {getCallsite, SourceMapRegistry} from '@jest/source-map';

export default class BufferedConsole extends Console {
private _buffer: ConsoleType.ConsoleBuffer;
private _counters: ConsoleType.LogCounters;
private _timers: ConsoleType.LogTimers;
private _groupDepth: number;
private _getSourceMaps: () => SourceMaps.SourceMapRegistry | null | undefined;
private _getSourceMaps: () => SourceMapRegistry | null | undefined;

constructor(
getSourceMaps: () => SourceMaps.SourceMapRegistry | null | undefined,
) {
constructor(getSourceMaps: () => SourceMapRegistry | null | undefined) {
const buffer: ConsoleType.ConsoleBuffer = [];
super({
write: (message: string) => {
Expand All @@ -42,7 +40,7 @@ export default class BufferedConsole extends Console {
type: ConsoleType.LogType,
message: ConsoleType.LogMessage,
level?: number | null,
sourceMaps?: SourceMaps.SourceMapRegistry | null,
sourceMaps?: SourceMapRegistry | null,
) {
const callsite = getCallsite(level != null ? level : 2, sourceMaps);
const origin = callsite.getFileName() + ':' + callsite.getLineNumber();
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

// TODO: Remove this export in the next major
import {JestFakeTimers as FakeTimers} from '@jest/fake-timers';
import {getCallsite} from '@jest/source-map';
import BufferedConsole from './BufferedConsole';
import clearLine from './clearLine';
import CustomConsole from './CustomConsole';
Expand All @@ -18,7 +19,6 @@ import getConsoleOutput from './getConsoleOutput';
import installCommonGlobals from './installCommonGlobals';
import NullConsole from './NullConsole';
import isInteractive from './isInteractive';
import getCallsite from './getCallsite';
import setGlobal from './setGlobal';
import deepCyclicCopy from './deepCyclicCopy';
import convertDescriptorToString from './convertDescriptorToString';
Expand Down
1 change: 1 addition & 0 deletions packages/jest-util/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"references": [
{"path": "../jest-fake-timers"},
{"path": "../jest-source-map"},
{"path": "../jest-types"}
]
}
10 changes: 1 addition & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1784,14 +1784,6 @@
"@types/prop-types" "*"
csstype "^2.2.0"

"@types/readable-stream@^2.3.0":
version "2.3.1"
resolved "https://registry.yarnpkg.com/@types/readable-stream/-/readable-stream-2.3.1.tgz#59d458b51c84c585caea06e296e2225057c9ea8e"
integrity sha512-Dp6t95yGEOm2y669mQrSl0kUg+oL+bJEiCWMyDv0Yq+FcVvjzNRLTAqJks2LDBYYrazZXNI7lZXq3lp7MOvt4A==
dependencies:
"@types/node" "*"
safe-buffer "*"

"@types/resolve@*":
version "0.0.8"
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194"
Expand Down Expand Up @@ -11516,7 +11508,7 @@ rxjs@^6.4.0:
dependencies:
tslib "^1.9.0"

safe-buffer@*, safe-buffer@5.1.2, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
[email protected], safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
Expand Down

0 comments on commit 3d1e501

Please sign in to comment.