From 953661d6ce013cccbb69833bf015687822d1ab24 Mon Sep 17 00:00:00 2001 From: aleclarson Date: Fri, 1 Feb 2019 16:37:44 -0500 Subject: [PATCH] feat: add "skipHastePackages" option --- packages/jest-haste-map/src/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/jest-haste-map/src/index.js b/packages/jest-haste-map/src/index.js index c7c6a79ac841..58cc6c22cfbb 100644 --- a/packages/jest-haste-map/src/index.js +++ b/packages/jest-haste-map/src/index.js @@ -67,6 +67,7 @@ type Options = { retainAllFiles: boolean, rootDir: string, roots: Array, + skipHastePackages?: boolean, throwOnModuleCollision?: boolean, useWatchman?: boolean, watch?: boolean, @@ -90,6 +91,7 @@ type InternalOptions = { retainAllFiles: boolean, rootDir: string, roots: Array, + skipHastePackages: boolean, throwOnModuleCollision: boolean, useWatchman: boolean, watch: boolean, @@ -108,6 +110,7 @@ export type FS = HasteFS; 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'; const canUseWatchman = ((): boolean => { try { @@ -251,6 +254,7 @@ class HasteMap extends EventEmitter { retainAllFiles: options.retainAllFiles, rootDir: options.rootDir, roots: Array.from(new Set(options.roots)), + skipHastePackages: !!options.skipHastePackages, throwOnModuleCollision: !!options.throwOnModuleCollision, useWatchman: options.useWatchman == null ? true : options.useWatchman, watch: !!options.watch, @@ -620,6 +624,12 @@ class HasteMap extends EventEmitter { } for (const relativeFilePath of hasteMap.files.keys()) { + if ( + this._options.skipHastePackages && + relativeFilePath.endsWith(PACKAGE_JSON) + ) { + continue; + } // SHA-1, if requested, should already be present thanks to the crawler. const filePath = fastPath.resolve( this._options.rootDir,