Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Defer I/O for package requires until they're actually used #1436

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"text-buffer": "0.13.0",
"theorist": "~0.14.0",
"underscore-plus": "0.6.1",
"vm-compatibility-layer": "0.1.0"
"vm-compatibility-layer": "0.1.0",
"deferred-require": "~0.2.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be cool maintaining the sorted order of dependencies for readability?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely. I think I just used npm install --save which tacks stuff on to the end. I'll re-order.

},
"packageDependencies": {
"atom-dark-syntax": "0.10.0",
Expand Down
5 changes: 4 additions & 1 deletion src/atom-package.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
deferredRequire = require 'deferred-require'
Package = require './package'
fs = require 'fs-plus'
path = require 'path'
Expand Down Expand Up @@ -191,7 +192,9 @@ class AtomPackage extends Package
requireMainModule: ->
return @mainModule if @mainModule?
mainModulePath = @getMainModulePath()
@mainModule = require(mainModulePath) if fs.isFileSync(mainModulePath)

if fs.isFileSync(mainModulePath)
deferredRequire.run => @mainModule = require(mainModulePath)

getMainModulePath: ->
return @mainModulePath if @resolvedMainModulePath
Expand Down