Only try to require main module once

This commit is contained in:
Kevin Sawicki
2015-03-03 16:40:39 -08:00
parent 628380ff3d
commit a2d9ba2d2e
2 changed files with 6 additions and 5 deletions

View File

@@ -2,7 +2,7 @@
Package = require '../src/package'
{Disposable} = require 'atom'
describe "PackageManager", ->
fdescribe "PackageManager", ->
workspaceElement = null
beforeEach ->
@@ -269,9 +269,8 @@ describe "PackageManager", ->
addErrorHandler = jasmine.createSpy()
atom.notifications.onDidAddNotification(addErrorHandler)
expect(-> atom.packages.activatePackage("package-that-throws-an-exception")).not.toThrow()
expect(addErrorHandler.callCount).toBe 2
expect(addErrorHandler.callCount).toBe 1
expect(addErrorHandler.argsForCall[0][0].message).toContain("Failed to load the package-that-throws-an-exception package")
expect(addErrorHandler.argsForCall[1][0].message).toContain("Failed to activate the package-that-throws-an-exception package")
describe "when the package is not found", ->
it "rejects the promise", ->

View File

@@ -376,7 +376,7 @@ class Package
@activateStylesheets()
requireMainModule: ->
return @mainModule if @mainModule?
return @mainModule if @mainModuleRequired
unless @isCompatible()
console.warn """
Failed to require the main module of '#{@name}' because it requires an incompatible native module.
@@ -384,7 +384,9 @@ class Package
"""
return
mainModulePath = @getMainModulePath()
@mainModule = require(mainModulePath) if fs.isFileSync(mainModulePath)
if fs.isFileSync(mainModulePath)
@mainModuleRequired = true
@mainModule = require(mainModulePath)
getMainModulePath: ->
return @mainModulePath if @resolvedMainModulePath