-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/internal resolve #4315
Merged
cpojer
merged 20 commits into
jestjs:master
from
tvald-contrib:feature/internal-resolve
Aug 22, 2017
Merged
Feature/internal resolve #4315
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e19e946
Pull resolve.sync code directly into default_resolver. (incomplete)
tvald f8e02f3
Strip out extraneous core and caller dependencies.
tvald a80d267
Pull node-modules-path into codebase as well. (incomplete)
tvald a4f2641
Remove dependency on path-parse. Assume existence of path.parse (adde…
tvald b0dd695
Use internal resolve within default_resolver.
tvald 5593152
Adhere to linter constraints.
tvald 08bc70d
Extend basic error type with code property.
tvald 942ddc7
Fix typing and remove extraneous options.
tvald d10676a
Gather helper methods at end of resolveSync().
tvald d15ec91
Rename "start" parameter to more obvious "basedir".
tvald 24e9b18
Avoid shadowing basedir variable.
tvald 7e46c07
Inline loadNodeModulesSync() method.
tvald 73ccd44
Clarify relative import vs node_modules.
tvald 513f1d2
Use import instead of require.
tvald e625b8a
Small logic and formatting simplifications.
tvald eb980f3
Use isBuiltinModule() to detect core modules. Restore use of moduleDi…
tvald b046899
Remove package dependency on resolve.
tvald 580f0c8
Make node_modules_paths available to resolver core logic, rather than…
tvald 3313380
Add standard header to node_modules_paths.js. Add adaptation note to …
tvald de104b0
Trim out unused options when calling nodeModulesPaths().
tvald File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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,59 @@ | ||
/** | ||
* Copyright (c) 2014, 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. | ||
* | ||
* Adapted from: https://github.com/substack/node-resolve | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {Path} from 'types/Config'; | ||
import path from 'path'; | ||
|
||
type NodeModulesPathsOptions = {| | ||
moduleDirectory?: Array<string>, | ||
paths?: ?Array<Path>, | ||
|}; | ||
|
||
function nodeModulesPaths( | ||
basedir: Path, | ||
options: NodeModulesPathsOptions, | ||
): Path[] { | ||
const modules = | ||
options && options.moduleDirectory | ||
? [].concat(options.moduleDirectory) | ||
: ['node_modules']; | ||
|
||
// ensure that `basedir` is an absolute path at this point, | ||
// resolving against the process' current working directory | ||
const basedirAbs = path.resolve(basedir); | ||
|
||
let prefix = '/'; | ||
if (/^([A-Za-z]:)/.test(basedirAbs)) { | ||
prefix = ''; | ||
} else if (/^\\\\/.test(basedirAbs)) { | ||
prefix = '\\\\'; | ||
} | ||
|
||
const paths = [basedirAbs]; | ||
let parsed = path.parse(basedirAbs); | ||
while (parsed.dir !== paths[paths.length - 1]) { | ||
paths.push(parsed.dir); | ||
parsed = path.parse(parsed.dir); | ||
} | ||
|
||
const dirs = paths.reduce((dirs, aPath) => { | ||
return dirs.concat( | ||
modules.map(moduleDir => { | ||
return path.join(prefix, aPath, moduleDir); | ||
}), | ||
); | ||
}, []); | ||
|
||
return options.paths ? dirs.concat(options.paths) : dirs; | ||
} | ||
|
||
module.exports = nodeModulesPaths; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the copyright header just like in other files?
Also, since it's adapted from
resolve
, an extra annotation is necessary:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 3313380