Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract resolveFromPossibleNames to remove duplicated logic
"DRY"s the duplicated algorithm in resolvePlugin and resolvePreset
- Loading branch information
Showing
3 changed files
with
9 additions
and
4 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/babel-core/src/helpers/resolve-from-possible-names.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,5 @@ | ||
import resolve from "./resolve"; | ||
|
||
export default function resolveFromPossibleNames(possibleNames: Array<string>, dirname: string): ?string { | ||
return possibleNames.reduce((accum, curr) => accum || resolve(curr, dirname), null); | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import resolve from "./resolve"; | ||
import resolveFromPossibleNames from "./resolve-from-possible-names"; | ||
import getPossiblePluginNames from "./get-possible-plugin-names"; | ||
|
||
export default function resolvePlugin(pluginName: string, dirname: string = process.cwd()): ?string { | ||
return getPossiblePluginNames(pluginName).reduce((accum, curr) => accum || resolve(curr, dirname), null); | ||
return resolveFromPossibleNames(getPossiblePluginNames(pluginName), dirname); | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import resolve from "./resolve"; | ||
import resolveFromPossibleNames from "./resolve-from-possible-names"; | ||
import getPossiblePresetNames from "./get-possible-preset-names"; | ||
|
||
export default function resolvePreset(presetName: string, dirname: string = process.cwd()): ?string { | ||
return getPossiblePresetNames(presetName).reduce((accum, curr) => accum || resolve(curr, dirname), null); | ||
return resolveFromPossibleNames(getPossiblePresetNames(presetName), dirname); | ||
} |