🐎 Resolve uncached core dependencies

Trust modules under the resource path to be there without stat-ing and
verifying.
This commit is contained in:
Kevin Sawicki
2014-10-08 14:15:24 -07:00
committed by Kevin Sawicki
parent 7926531330
commit 171411823f
2 changed files with 7 additions and 4 deletions

View File

@@ -16,6 +16,7 @@ cache =
folders: {}
ranges: {}
registered: false
resourcePath: null
loadDependencies = (modulePath, rootPath, rootMetadata, moduleCache) ->
for childPath in fs.listSync(path.join(modulePath, 'node_modules'))
@@ -99,8 +100,8 @@ getCachedModulePath = (relativePath, parentModule) ->
return unless candidates?
for version, resolvedPath of candidates
if Module._cache.hasOwnProperty(resolvedPath) and satisfies(version, range)
return resolvedPath
if Module._cache.hasOwnProperty(resolvedPath) or resolvedPath.indexOf(cache.resourcePath) is 0
return resolvedPath if satisfies(version, range)
undefined
@@ -138,14 +139,16 @@ exports.create = (modulePath) ->
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2))
undefined
exports.register = ->
exports.register = (resourcePath) ->
return if cache.registered
originalResolveFilename = Module._resolveFilename
Module._resolveFilename = (relativePath, parentModule) ->
resolvedPath = getCachedModulePath(relativePath, parentModule)
resolvedPath ? originalResolveFilename(relativePath, parentModule)
cache.registered = true
cache.resourcePath = resourcePath
undefined

View File

@@ -18,8 +18,8 @@ window.onload = function() {
require('../src/coffee-cache').register();
ModuleCache = require('../src/module-cache');
ModuleCache.register(loadSettings.resourcePath);
ModuleCache.add(loadSettings.resourcePath);
ModuleCache.register();
require(loadSettings.bootstrapScript);
ipc.sendChannel('window-command', 'window:loaded')