Skip to content

Commit

Permalink
Add isCorePath helper
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsawicki committed Oct 15, 2014
1 parent 4c17c9e commit bb92b86
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/module-cache.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ cache =
ranges: {}
registered: false
resourcePath: null
resourcePathWithTrailingSlash: null

# isAbsolute is inlined from fs-plus so that fs-plus itself can be required
# from this cache.
Expand All @@ -23,6 +24,9 @@ else
isAbsolute = (pathToCheck) ->
pathToCheck and pathToCheck[0] is '/'

isCorePath = (pathToCheck) ->
pathToCheck.indexOf(cache.resourcePathWithTrailingSlash) is 0

loadDependencies = (modulePath, rootPath, rootMetadata, moduleCache) ->
fs = require 'fs-plus'

Expand Down Expand Up @@ -98,14 +102,15 @@ resolveFilePath = (relativePath, parentModule) ->
return if relativePath[relativePath.length - 1] is '/'

resolvedPath = path.resolve(path.dirname(parentModule.filename), relativePath)
if resolvedPath.indexOf(cache.resourcePath) is 0
extension = path.extname(resolvedPath)
if extension
return resolvedPath if cache.extensions[extension]?.has(resolvedPath)
else
for extension, paths of cache.extensions
resolvedPathWithExtension = "#{resolvedPath}#{extension}"
return resolvedPathWithExtension if paths.has(resolvedPathWithExtension)
return unless isCorePath(resolvedPath)

extension = path.extname(resolvedPath)
if extension
return resolvedPath if cache.extensions[extension]?.has(resolvedPath)
else
for extension, paths of cache.extensions
resolvedPathWithExtension = "#{resolvedPath}#{extension}"
return resolvedPathWithExtension if paths.has(resolvedPathWithExtension)

return

Expand All @@ -131,7 +136,7 @@ resolveModulePath = (relativePath, parentModule) ->
return unless candidates?

for version, resolvedPath of candidates
if Module._cache.hasOwnProperty(resolvedPath) or resolvedPath.indexOf(cache.resourcePath) is 0
if Module._cache.hasOwnProperty(resolvedPath) or isCorePath(resolvedPath)
return resolvedPath if satisfies(version, range)

return
Expand Down Expand Up @@ -214,6 +219,7 @@ exports.register = ({resourcePath, devMode}={}) ->

cache.registered = true
cache.resourcePath = resourcePath
cache.resourcePathWithTrailingSlash = "#{resourcePath}#{path.sep}"
registerBuiltins(devMode)

return
Expand Down

0 comments on commit bb92b86

Please sign in to comment.