Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `[expect]`: Improve report when matcher fails, part 10 ([#7960](https://github.com/facebook/jest/pull/7960))
- `[pretty-format]` Support `React.memo` ([#7891](https://github.com/facebook/jest/pull/7891))
- `[jest-config]` Print error information on preset normalization error ([#7935](https://github.com/facebook/jest/pull/7935))
- `[jest-haste-map]` Add "skipPackageJson" option

### Fixes

Expand Down
10 changes: 10 additions & 0 deletions packages/jest-haste-map/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Options = {
retainAllFiles: boolean;
rootDir: string;
roots: Array<string>;
skipPackageJson?: boolean;
throwOnModuleCollision?: boolean;
useWatchman?: boolean;
watch?: boolean;
Expand All @@ -87,6 +88,7 @@ type InternalOptions = {
retainAllFiles: boolean;
rootDir: string;
roots: Array<string>;
skipPackageJson: boolean;
throwOnModuleCollision: boolean;
useWatchman: boolean;
watch: boolean;
Expand All @@ -108,6 +110,7 @@ namespace HasteMap {
const CHANGE_INTERVAL = 30;
const MAX_WAIT_TIME = 240000;
const NODE_MODULES = path.sep + 'node_modules' + path.sep;
const PACKAGE_JSON = path.sep + 'package.json';

// TypeScript doesn't like us importing from outside `rootDir`, but it doesn't
// understand `require`.
Expand Down Expand Up @@ -256,6 +259,7 @@ class HasteMap extends EventEmitter {
retainAllFiles: options.retainAllFiles,
rootDir: options.rootDir,
roots: Array.from(new Set(options.roots)),
skipPackageJson: !!options.skipPackageJson,
throwOnModuleCollision: !!options.throwOnModuleCollision,
useWatchman: options.useWatchman == null ? true : options.useWatchman,
watch: !!options.watch,
Expand Down Expand Up @@ -623,6 +627,12 @@ class HasteMap extends EventEmitter {
}

for (const relativeFilePath of hasteMap.files.keys()) {
if (
this._options.skipPackageJson &&
relativeFilePath.endsWith(PACKAGE_JSON)
) {
continue;
}
// SHA-1, if requested, should already be present thanks to the crawler.
const filePath = fastPath.resolve(
this._options.rootDir,
Expand Down