Add ~/.atom/packages to the resource load path.

This commit is contained in:
Cheng Zhao
2013-09-13 17:05:00 +08:00
parent 656793108c
commit 1b4be18dd7

View File

@@ -1,3 +1,5 @@
app = require 'app'
fs = require 'fs'
path = require 'path'
protocol = require 'protocol'
@@ -8,11 +10,18 @@ protocol = require 'protocol'
module.exports =
class AtomProtocolHandler
constructor: (@resourcePath) ->
@loadPaths = [
path.join(@resourcePath, 'node_modules')
path.join(app.getHomeDir(), '.atom', 'packages')
]
@registerAtomProtocol()
# Private: Creates the 'atom' custom protocol handler.
registerAtomProtocol: ->
protocol.registerProtocol 'atom', (request) =>
relativePath = path.normalize(request.url.substr(7))
filePath = path.join(@resourcePath, 'node_modules', relativePath)
for loadPath in @loadPaths
filePath = path.join(loadPath, relativePath)
break if fs.statSyncNoException(filePath)?
return new protocol.RequestFileJob(filePath)