Skip to content

Commit df3eb5e

Browse files
aleclarsoncpojer
authored andcommitted
feat: add "skipPackageJson" option (#7778)
1 parent 438a178 commit df3eb5e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- `[expect]`: Improve report when matcher fails, part 10 ([#7960](https://github.com/facebook/jest/pull/7960))
99
- `[pretty-format]` Support `React.memo` ([#7891](https://github.com/facebook/jest/pull/7891))
1010
- `[jest-config]` Print error information on preset normalization error ([#7935](https://github.com/facebook/jest/pull/7935))
11+
- `[jest-haste-map]` Add "skipPackageJson" option
1112

1213
### Fixes
1314

packages/jest-haste-map/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type Options = {
6464
retainAllFiles: boolean;
6565
rootDir: string;
6666
roots: Array<string>;
67+
skipPackageJson?: boolean;
6768
throwOnModuleCollision?: boolean;
6869
useWatchman?: boolean;
6970
watch?: boolean;
@@ -87,6 +88,7 @@ type InternalOptions = {
8788
retainAllFiles: boolean;
8889
rootDir: string;
8990
roots: Array<string>;
91+
skipPackageJson: boolean;
9092
throwOnModuleCollision: boolean;
9193
useWatchman: boolean;
9294
watch: boolean;
@@ -108,6 +110,7 @@ namespace HasteMap {
108110
const CHANGE_INTERVAL = 30;
109111
const MAX_WAIT_TIME = 240000;
110112
const NODE_MODULES = path.sep + 'node_modules' + path.sep;
113+
const PACKAGE_JSON = path.sep + 'package.json';
111114

112115
// TypeScript doesn't like us importing from outside `rootDir`, but it doesn't
113116
// understand `require`.
@@ -256,6 +259,7 @@ class HasteMap extends EventEmitter {
256259
retainAllFiles: options.retainAllFiles,
257260
rootDir: options.rootDir,
258261
roots: Array.from(new Set(options.roots)),
262+
skipPackageJson: !!options.skipPackageJson,
259263
throwOnModuleCollision: !!options.throwOnModuleCollision,
260264
useWatchman: options.useWatchman == null ? true : options.useWatchman,
261265
watch: !!options.watch,
@@ -623,6 +627,12 @@ class HasteMap extends EventEmitter {
623627
}
624628

625629
for (const relativeFilePath of hasteMap.files.keys()) {
630+
if (
631+
this._options.skipPackageJson &&
632+
relativeFilePath.endsWith(PACKAGE_JSON)
633+
) {
634+
continue;
635+
}
626636
// SHA-1, if requested, should already be present thanks to the crawler.
627637
const filePath = fastPath.resolve(
628638
this._options.rootDir,

0 commit comments

Comments
 (0)