Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate jest-haste-map to TypeScript
Browse files Browse the repository at this point in the history
SimenB committed Feb 11, 2019
1 parent b49075e commit 05a34ec
Showing 27 changed files with 345 additions and 298 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
- `[jest-watcher]`: Migrate to TypeScript ([#7843](https://github.com/facebook/jest/pull/7843))
- `[jest-mock]`: Migrate to TypeScript ([#7847](https://github.com/facebook/jest/pull/7847), [#7850](https://github.com/facebook/jest/pull/7850))
- `[jest-worker]`: Migrate to TypeScript ([#7853](https://github.com/facebook/jest/pull/7853))
- `[jest-haste-map]`: Migrate to TypeScript ([#7854](https://github.com/facebook/jest/pull/7854))

### Performance

1 change: 0 additions & 1 deletion packages/jest-cli/src/TestSequencer.js
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ import type {Context} from 'types/Context';
import type {Test} from 'types/TestRunner';

import fs from 'fs';
// $FlowFixMe: Missing ESM export
import {getCacheFilePath} from 'jest-haste-map';

const FAIL = 0;
3 changes: 3 additions & 0 deletions packages/jest-haste-map/package.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,9 @@
},
"license": "MIT",
"main": "build/index.js",
"types": "build/index.d.ts",
"dependencies": {
"@jest/types": "^24.1.0",
"fb-watchman": "^2.0.0",
"graceful-fs": "^4.1.15",
"invariant": "^2.2.4",
@@ -23,6 +25,7 @@
"@types/graceful-fs": "^4.1.2",
"@types/invariant": "^2.2.29",
"@types/micromatch": "^3.1.0",
"@types/node": "^10.12.24",
"@types/sane": "^2.0.0"
},
"engines": {
Original file line number Diff line number Diff line change
@@ -3,66 +3,63 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import type {Glob, Path} from 'types/Config';
import type {FileData} from 'types/HasteMap';

import micromatch from 'micromatch';
import {replacePathSepForGlob} from 'jest-util';
import {Config} from '@jest/types';
import {FileData} from './types';
import * as fastPath from './lib/fast_path';
import micromatch from 'micromatch';
import H from './constants';

export default class HasteFS {
_rootDir: Path;
_files: FileData;
private readonly _rootDir: Config.Path;
private readonly _files: FileData;

constructor({rootDir, files}: {rootDir: Path, files: FileData}) {
constructor({rootDir, files}: {rootDir: Config.Path; files: FileData}) {
this._rootDir = rootDir;
this._files = files;
}

getModuleName(file: Path): ?string {
getModuleName(file: Config.Path): string | null {
const fileMetadata = this._getFileData(file);
return (fileMetadata && fileMetadata[H.ID]) || null;
}

getSize(file: Path): ?number {
getSize(file: Config.Path): number | null {
const fileMetadata = this._getFileData(file);
return (fileMetadata && fileMetadata[H.SIZE]) || null;
}

getDependencies(file: Path): ?Array<string> {
getDependencies(file: Config.Path): Array<string> | null {
const fileMetadata = this._getFileData(file);
return (fileMetadata && fileMetadata[H.DEPENDENCIES]) || null;
}

getSha1(file: Path): ?string {
getSha1(file: Config.Path): string | null {
const fileMetadata = this._getFileData(file);
return (fileMetadata && fileMetadata[H.SHA1]) || null;
}

exists(file: Path): boolean {
exists(file: Config.Path): boolean {
return this._getFileData(file) != null;
}

getAllFiles(): Array<string> {
getAllFiles(): Array<Config.Path> {
return Array.from(this.getAbsoluteFileIterator());
}

getFileIterator(): Iterator<string> {
getFileIterator(): Iterable<Config.Path> {
return this._files.keys();
}

*getAbsoluteFileIterator(): Iterator<string> {
for (const file of this._files.keys()) {
*getAbsoluteFileIterator(): Iterable<Config.Path> {
for (const file of this.getFileIterator()) {
yield fastPath.resolve(this._rootDir, file);
}
}

matchFiles(pattern: RegExp | string): Array<Path> {
matchFiles(pattern: RegExp | string): Array<Config.Path> {
if (!(pattern instanceof RegExp)) {
pattern = new RegExp(pattern);
}
@@ -75,7 +72,10 @@ export default class HasteFS {
return files;
}

matchFilesWithGlob(globs: Array<Glob>, root: ?Path): Set<Path> {
matchFilesWithGlob(
globs: Array<Config.Glob>,
root: Config.Path | null,
): Set<Config.Path> {
const files = new Set();
for (const file of this.getAbsoluteFileIterator()) {
const filePath = root ? fastPath.relative(root, file) : file;
@@ -86,7 +86,7 @@ export default class HasteFS {
return files;
}

_getFileData(file: Path) {
private _getFileData(file: Config.Path) {
const relativePath = fastPath.relative(this._rootDir, file);
return this._files.get(relativePath);
}
Original file line number Diff line number Diff line change
@@ -3,52 +3,49 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import type {Path} from 'types/Config';
import type {
import {Config} from '@jest/types';
import {
DuplicatesSet,
HTypeValue,
ModuleMetaData,
RawModuleMap,
ModuleMapData,
DuplicatesIndex,
MockData,
} from 'types/HasteMap';
} from './types';

import * as fastPath from './lib/fast_path';
import H from './constants';

const EMPTY_OBJ = {};
const EMPTY_OBJ = {} as {[key: string]: any};
const EMPTY_MAP = new Map();

export opaque type SerializableModuleMap = {
type ValueType<T> = T extends Map<T, infer V> ? V : T;

export type SerializableModuleMap = {
// There is no easier way to extract the type of the entries of a Map
duplicates: $Call<
typeof Array.from,
$Call<$PropertyType<DuplicatesIndex, 'entries'>>,
>,
map: $Call<typeof Array.from, $Call<$PropertyType<ModuleMapData, 'entries'>>>,
mocks: $Call<typeof Array.from, $Call<$PropertyType<MockData, 'entries'>>>,
rootDir: string,
duplicates: [string, ValueType<DuplicatesIndex>];
map: [string, ValueType<ModuleMapData>];
mocks: [string, ValueType<MockData>];
rootDir: Config.Path;
};

export default class ModuleMap {
_raw: RawModuleMap;
static DuplicateHasteCandidatesError: Class<DuplicateHasteCandidatesError>;
private readonly _raw: RawModuleMap;
static DuplicateHasteCandidatesError: DuplicateHasteCandidatesError;

constructor(raw: RawModuleMap) {
this._raw = raw;
}

getModule(
name: string,
platform: ?string,
supportsNativePlatform: ?boolean,
type: ?HTypeValue,
): ?Path {
platform: string | null,
supportsNativePlatform: boolean | null,
type: HTypeValue | null,
): string | null {
if (!type) {
type = H.MODULE;
}
@@ -66,13 +63,13 @@ export default class ModuleMap {

getPackage(
name: string,
platform: ?string,
supportsNativePlatform: ?boolean,
): ?Path {
platform: string | null,
_: boolean | null,
): string | null {
return this.getModule(name, platform, null, H.PACKAGE);
}

getMockModule(name: string): ?Path {
getMockModule(name: string): string | undefined {
const mockPath =
this._raw.mocks.get(name) || this._raw.mocks.get(name + '/index');
return mockPath && fastPath.resolve(this._raw.rootDir, mockPath);
@@ -113,11 +110,11 @@ export default class ModuleMap {
* extra sure. If metadata exists both in the `duplicates` object and the
* `map`, this would be a bug.
*/
_getModuleMetadata(
private _getModuleMetadata(
name: string,
platform: ?string,
platform: string | null,
supportsNativePlatform: boolean,
): ?ModuleMetaData {
): ModuleMetaData | null {
const map = this._raw.map.get(name) || EMPTY_OBJ;
const dupMap = this._raw.duplicates.get(name) || EMPTY_MAP;
if (platform != null) {
@@ -154,11 +151,11 @@ export default class ModuleMap {
return null;
}

_assertNoDuplicates(
private _assertNoDuplicates(
name: string,
platform: string,
supportsNativePlatform: boolean,
relativePathSet: ?DuplicatesSet,
relativePathSet: DuplicatesSet | null,
) {
if (relativePathSet == null) {
return;
@@ -180,7 +177,7 @@ export default class ModuleMap {
);
}

static create(rootDir: Path) {
static create(rootDir: string) {
return new ModuleMap({
duplicates: new Map(),
map: new Map(),
@@ -190,9 +187,9 @@ export default class ModuleMap {
}
}

class DuplicateHasteCandidatesError extends Error {
export class DuplicateHasteCandidatesError extends Error {
hasteName: string;
platform: ?string;
platform: string | null;
supportsNativePlatform: boolean;
duplicatesSet: DuplicatesSet;

6 changes: 2 additions & 4 deletions packages/jest-haste-map/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -6,10 +6,8 @@
*
*/

'use strict';

import crypto from 'crypto';
import {skipSuiteOnWindows} from '../../../../scripts/ConditionalTest';
const crypto = require('crypto');

function mockHashContents(contents) {
return crypto
@@ -75,7 +73,7 @@ jest.mock('sane', () => ({
WatchmanWatcher: mockWatcherConstructor,
}));

jest.mock('../lib/WatchmanWatcher.js', () => mockWatcherConstructor);
jest.mock('../lib/WatchmanWatcher', () => mockWatcherConstructor);

let mockChangedFiles;
let mockFs;
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

// This list is compiled after the MDN list of the most common MIME types (see
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
/* eslint-disable sort-keys */

@@ -16,7 +14,10 @@
* This constant key map allows to keep the map smaller without having to build
* a custom serialization library.
*/
export default {

import {HType} from './types';

const constants: HType = {
/* file map attributes */
ID: 0,
MTIME: 1,
@@ -37,3 +38,5 @@ export default {
GENERIC_PLATFORM: 'g',
NATIVE_PLATFORM: 'native',
};

export default constants;
Original file line number Diff line number Diff line change
@@ -3,30 +3,26 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import type {InternalHasteMap} from 'types/HasteMap';
import type {IgnoreMatcher, CrawlerOptions} from '../types';

import fs from 'fs';
import path from 'path';
import {spawn} from 'child_process';
import H from '../constants';
import * as fastPath from '../lib/fast_path';
import {IgnoreMatcher, InternalHasteMap, CrawlerOptions} from '../types';

type Result = Array<[/* id */ string, /* mtime */ number, /* size */ number]>;

type Callback = (
result: Array<[/* id */ string, /* mtime */ number, /* size */ number]>,
) => void;
type Callback = (result: Result) => void;

function find(
roots: Array<string>,
extensions: Array<string>,
ignore: IgnoreMatcher,
callback: Callback,
): void {
const result = [];
const result: Result = [];
let activeCalls = 0;

function search(directory: string): void {
@@ -82,7 +78,7 @@ function findNative(
ignore: IgnoreMatcher,
callback: Callback,
): void {
const args = [].concat(roots);
const args = roots.slice();
args.push('-type', 'f');
if (extensions.length) {
args.push('(');
@@ -108,7 +104,7 @@ function findNative(
.trim()
.split('\n')
.filter(x => !ignore(x));
const result = [];
const result: Result = [];
let count = lines.length;
if (!count) {
callback([]);
@@ -127,7 +123,7 @@ function findNative(
});
}

module.exports = function nodeCrawl(
export = function nodeCrawl(
options: CrawlerOptions,
): Promise<InternalHasteMap> {
if (options.mapper) {
@@ -144,13 +140,11 @@ module.exports = function nodeCrawl(
} = options;

return new Promise(resolve => {
const callback = list => {
const callback = (list: Result) => {
const files = new Map();
list.forEach(fileData => {
const filePath = fileData[0];
const [filePath, mtime, size] = fileData;
const relativeFilePath = fastPath.relative(rootDir, filePath);
const mtime = fileData[1];
const size = fileData[2];
const existingFile = data.files.get(relativeFilePath);
if (existingFile && existingFile[H.MTIME] === mtime) {
files.set(relativeFilePath, existingFile);
Original file line number Diff line number Diff line change
@@ -3,18 +3,17 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import type {InternalHasteMap} from 'types/HasteMap';
import type {CrawlerOptions} from '../types';

import * as fastPath from '../lib/fast_path';
import normalizePathSep from '../lib/normalizePathSep';
import path from 'path';
import watchman from 'fb-watchman';
import {Config} from '@jest/types';
import * as fastPath from '../lib/fast_path';
import normalizePathSep from '../lib/normalizePathSep';
import H from '../constants';
import {InternalHasteMap, CrawlerOptions, FileMetaData} from '../types';

type WatchmanRoots = Map<string, Array<string>>;

const watchmanURL =
'https://facebook.github.io/watchman/docs/troubleshooting.html';
@@ -26,23 +25,23 @@ function WatchmanError(error: Error): Error {
return error;
}

module.exports = async function watchmanCrawl(
export = async function watchmanCrawl(
options: CrawlerOptions,
): Promise<InternalHasteMap> {
const fields = ['name', 'exists', 'mtime_ms', 'size'];
const {data, extensions, ignore, rootDir, roots} = options;
const defaultWatchExpression = [
'allof',
['type', 'f'],
['anyof'].concat(extensions.map(extension => ['suffix', extension])),
['anyof', ...extensions.map(extension => ['suffix', extension])],
];
const clocks = data.clocks;
const client = new watchman.Client();

let clientError;
client.on('error', error => (clientError = WatchmanError(error)));

const cmd = (...args) =>
const cmd = (...args: Array<any>): Promise<any> =>
new Promise((resolve, reject) =>
client.command(args, (error, result) =>
error ? reject(WatchmanError(error)) : resolve(result),
@@ -57,7 +56,9 @@ module.exports = async function watchmanCrawl(
}
}

async function getWatchmanRoots(roots) {
async function getWatchmanRoots(
roots: Array<Config.Path>,
): Promise<WatchmanRoots> {
const watchmanRoots = new Map();
await Promise.all(
roots.map(async root => {
@@ -85,7 +86,7 @@ module.exports = async function watchmanCrawl(
return watchmanRoots;
}

async function queryWatchmanForDirs(rootProjectDirMappings) {
async function queryWatchmanForDirs(rootProjectDirMappings: WatchmanRoots) {
const files = new Map();
let isFresh = false;
await Promise.all(
@@ -181,7 +182,7 @@ module.exports = async function watchmanCrawl(
}

const existingFileData = data.files.get(relativeFilePath);
let nextData;
let nextData: FileMetaData;

if (existingFileData && existingFileData[H.MTIME] === mtime) {
nextData = existingFileData;
@@ -193,7 +194,7 @@ module.exports = async function watchmanCrawl(
nextData = [...existingFileData];
nextData[1] = mtime;
} else {
// See ../constants.js
// See ../constants.ts
nextData = ['', mtime, size, 0, [], sha1hex];
}

Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import path from 'path';

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/jest-haste-map/src/lib/WatchmanWatcher.js
Original file line number Diff line number Diff line change
@@ -8,9 +8,9 @@
import fs from 'fs';
import path from 'path';
import assert from 'assert';
import common from 'sane/src/common';
import watchman from 'fb-watchman';
import {EventEmitter} from 'events';
import watchman from 'fb-watchman';
import common from 'sane/src/common';
import RecrawlWarning from 'sane/src/utils/recrawl-warning-dedupe';

const CHANGE_EVENT = common.CHANGE_EVENT;
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import {extract} from '../dependencyExtractor';
2 changes: 0 additions & 2 deletions packages/jest-haste-map/src/lib/__tests__/fast_path.test.js
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@
*
*/

'use strict';

import path from 'path';
import {relative, resolve} from '../fast_path';

Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@
*
*/

'use strict';

import getPlatformExtension from '../getPlatformExtension';

describe('getPlatformExtension', () => {
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import isRegExpSupported from '../isRegExpSupported';
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import isRegExpSupported from './isRegExpSupported';
@@ -13,22 +11,23 @@ import isRegExpSupported from './isRegExpSupported';
const NOT_A_DOT = isRegExpSupported('(?<!\\.\\s*)')
? '(?<!\\.\\s*)'
: '(?:^|[^.]\\s*)';
const CAPTURE_STRING_LITERAL = pos => `([\`'"])([^'"\`]*?)(?:\\${pos})`;
const CAPTURE_STRING_LITERAL = (pos: number) =>
`([\`'"])([^'"\`]*?)(?:\\${pos})`;
const WORD_SEPARATOR = '\\b';
const LEFT_PARENTHESIS = '\\(';
const RIGHT_PARENTHESIS = '\\)';
const WHITESPACE = '\\s*';
const OPTIONAL_COMMA = '(:?,\\s*)?';

function createRegExp(parts, flags) {
function createRegExp(parts: Array<string>, flags: string) {
return new RegExp(parts.join(''), flags);
}

function alternatives(...parts) {
function alternatives(...parts: Array<string>) {
return `(?:${parts.join('|')})`;
}

function functionCallStart(...names) {
function functionCallStart(...names: Array<string>) {
return [
NOT_A_DOT,
WORD_SEPARATOR,
@@ -78,7 +77,7 @@ const JEST_EXTENSIONS_RE = createRegExp(
export function extract(code: string): Set<string> {
const dependencies = new Set();

const addDependency = (match: string, q: string, dep: string) => {
const addDependency = (match: string, _: string, dep: string) => {
dependencies.add(dep);
return match;
};
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import path from 'path';
Original file line number Diff line number Diff line change
@@ -3,22 +3,15 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

const SUPPORTED_PLATFORM_EXTS = {
android: true,
ios: true,
native: true,
web: true,
};
const SUPPORTED_PLATFORM_EXTS = new Set(['android', 'ios', 'native', 'web']);

// Extract platform extension: index.ios.js -> ios
export default function getPlatformExtension(
file: string,
platforms?: Array<string>,
): ?string {
): string | null {
const last = file.lastIndexOf('.');
const secondToLast = file.lastIndexOf('.', last - 1);
if (secondToLast === -1) {
@@ -30,5 +23,5 @@ export default function getPlatformExtension(
if (platforms && platforms.indexOf(platform) !== -1) {
return platform;
}
return SUPPORTED_PLATFORM_EXTS[platform] ? platform : null;
return SUPPORTED_PLATFORM_EXTS.has(platform) ? platform : null;
}
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

export default function isRegExpSupported(value: string): boolean {
Original file line number Diff line number Diff line change
@@ -3,13 +3,11 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

const path = require('path');
import path from 'path';

let normalizePathSep;
let normalizePathSep: (string: string) => string;
if (path.sep === '/') {
normalizePathSep = (filePath: string) => filePath;
} else {
44 changes: 0 additions & 44 deletions packages/jest-haste-map/src/types.js

This file was deleted.

104 changes: 104 additions & 0 deletions packages/jest-haste-map/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* 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.
*/

import {Config} from '@jest/types';
import ModuleMap from './ModuleMap';
import HasteFS from './HasteFS';

export type IgnoreMatcher = (item: string) => boolean;
export type Mapper = (item: string) => Array<string> | null;

export type WorkerMessage = {
computeDependencies: boolean;
computeSha1: boolean;
dependencyExtractor?: string;
rootDir: string;
filePath: string;
hasteImplModulePath?: string;
};

export type WorkerMetadata = {
dependencies: Array<string> | undefined | null;
id: string | undefined | null;
module: ModuleMetaData | undefined | null;
sha1: string | undefined | null;
};

export type CrawlerOptions = {
computeSha1: boolean;
data: InternalHasteMap;
extensions: Array<string>;
forceNodeFilesystemAPI: boolean;
ignore: IgnoreMatcher;
mapper?: Mapper | null;
rootDir: string;
roots: Array<string>;
};

export type HasteImpl = {
getHasteName(filePath: Config.Path): string | void;
};

export type FileData = Map<Config.Path, FileMetaData>;

export type FileMetaData = [
/* id */ string,
/* mtime */ number,
/* size */ number,
/* visited */ 0 | 1,
/* dependencies */ Array<string>,
/* sha1 */ string | null | undefined
];

export type MockData = Map<string, Config.Path>;
export type ModuleMapData = Map<string, ModuleMapItem>;
export type WatchmanClocks = Map<Config.Path, string>;
export type HasteRegExp = RegExp | ((str: string) => boolean);

export type DuplicatesSet = Map<string, /* type */ number>;
export type DuplicatesIndex = Map<string, Map<string, DuplicatesSet>>;

export type InternalHasteMap = {
clocks: WatchmanClocks;
duplicates: DuplicatesIndex;
files: FileData;
map: ModuleMapData;
mocks: MockData;
};

export type HasteMap = {
hasteFS: HasteFS;
moduleMap: ModuleMap;
__hasteMapForTest?: InternalHasteMap | null;
};

export type RawModuleMap = {
rootDir: Config.Path;
duplicates: DuplicatesIndex;
map: ModuleMapData;
mocks: MockData;
};

type ModuleMapItem = {[platform: string]: ModuleMetaData};
export type ModuleMetaData = [Config.Path, /* type */ number];

export type HType = {
ID: 0;
MTIME: 1;
SIZE: 2;
VISITED: 3;
DEPENDENCIES: 4;
SHA1: 5;
PATH: 0;
TYPE: 1;
MODULE: 0;
PACKAGE: 1;
GENERIC_PLATFORM: 'g';
NATIVE_PLATFORM: 'native';
};

export type HTypeValue = HType[keyof HType];
Original file line number Diff line number Diff line change
@@ -3,23 +3,20 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import type {HasteImpl, WorkerMessage, WorkerMetadata} from './types';

import crypto from 'crypto';
import path from 'path';
import fs from 'graceful-fs';
import {HasteImpl, WorkerMessage, WorkerMetadata} from './types';
import blacklist from './blacklist';
import H from './constants';
import * as dependencyExtractor from './lib/dependencyExtractor';

const PACKAGE_JSON = path.sep + 'package.json';

let hasteImpl: ?HasteImpl = null;
let hasteImplModulePath: ?string = null;
let hasteImpl: HasteImpl | null = null;
let hasteImplModulePath: string | null = null;

function sha1hex(content: string | Buffer): string {
return crypto
@@ -38,11 +35,11 @@ export async function worker(data: WorkerMessage): Promise<WorkerMetadata> {
}
hasteImplModulePath = data.hasteImplModulePath;
// $FlowFixMe: dynamic require
hasteImpl = (require(hasteImplModulePath): HasteImpl);
hasteImpl = require(hasteImplModulePath);
}

let content;
let dependencies;
let content: string | undefined;
let dependencies: Array<string> | undefined;
let id;
let module;
let sha1;
13 changes: 13 additions & 0 deletions packages/jest-haste-map/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build"
},
"references": [
{"path": "../jest-worker"},
{"path": "../jest-serializer"},
{"path": "../jest-util"},
{"path": "../jest-types"}
]
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -20,7 +20,8 @@

/* Module Resolution Options */
"moduleResolution": "node",
"esModuleInterop": true
"esModuleInterop": true,
"resolveJsonModule": true
},
"exclude": ["**/__tests__/**/*", "**/build/**/*", "**/build-es5/**/*"]
}

0 comments on commit 05a34ec

Please sign in to comment.