Skip to content

Commit

Permalink
feat: add "skipPackageJson" option (#7778)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson authored and cpojer committed Feb 28, 2019
1 parent 438a178 commit df3eb5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
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
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

0 comments on commit df3eb5e

Please sign in to comment.