-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metro-bundler: ResolutionRequest: extract FileNameResolver
Summary: I want to untangle `ResolutionRequest` once and for all, that starts by pulling stuff out :-) Reviewed By: cpojer Differential Revision: D5155316 fbshipit-source-id: a46ee9b40c6705edcac169adcfdffe25058ec810
- Loading branch information
1 parent
3fecc28
commit 3aedbbb
Showing
2 changed files
with
47 additions
and
29 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packager/src/node-haste/DependencyGraph/FileNameResolver.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @flow | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
export type Options = {| | ||
+dirPath: string, | ||
+doesFileExist: (filePath: string) => boolean, | ||
|}; | ||
|
||
/** | ||
* When resolving a single module we want to keep track of the list of paths | ||
* we tried to find. This class is a way to aggregate all the tries easily. | ||
*/ | ||
class FileNameResolver { | ||
_options: Options; | ||
_tentativeFileNames: Array<string>; | ||
|
||
constructor(options: Options) { | ||
this._options = options; | ||
this._tentativeFileNames = []; | ||
} | ||
|
||
getTentativeFileNames(): $ReadOnlyArray<string> { | ||
return this._tentativeFileNames; | ||
} | ||
|
||
tryToResolveFileName(fileName: string): boolean { | ||
this._tentativeFileNames.push(fileName); | ||
const filePath = path.join(this._options.dirPath, fileName); | ||
return this._options.doesFileExist(filePath); | ||
} | ||
} | ||
|
||
module.exports = FileNameResolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters