Skip to content

Commit d7d5c9d

Browse files
committed
locally require lib in each developer command
1 parent 6b5bc33 commit d7d5c9d

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

lib/developer.coffee

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
_ = require 'underscore-plus'
2-
path = require 'path'
3-
fs = require 'fs-plus'
41
{Emitter, Disposable, BufferedProcess, CompositeDisposable} = require 'atom'
52

63
Base = require './base'
7-
generateIntrospectionReport = null
84
settings = require './settings'
95
getEditorState = null
106

11-
invalidateRequireCacheForPackage = (packPath) ->
12-
Object.keys(require.cache)
13-
.filter (p) -> p.startsWith(packPath + path.sep)
14-
.forEach (p) -> delete require.cache[p]
15-
167
class Developer
17-
init: (service) ->
18-
{getEditorState} = service
8+
init: (_getEditorState) ->
9+
getEditorState = _getEditorState
1910
@devEnvironmentByBuffer = new Map
2011
@reloadSubscriptionByBuffer = new Map
2112

@@ -39,11 +30,10 @@ class Developer
3930
subscriptions
4031

4132
reportRequireCache: ({focus, excludeNodModules}) ->
42-
{inspect} = require 'util'
43-
path = require 'path'
33+
pathSeparator = require('path').sep
4434
packPath = atom.packages.getLoadedPackage("vim-mode-plus").path
4535
cachedPaths = Object.keys(require.cache)
46-
.filter (p) -> p.startsWith(packPath + path.sep)
36+
.filter (p) -> p.startsWith(packPath + pathSeparator)
4737
.map (p) -> p.replace(packPath, '')
4838

4939
for cachedPath in cachedPaths
@@ -82,10 +72,17 @@ class Developer
8272
console.log 'total', inspect(total)
8373

8474
reload: (reloadDependencies) ->
75+
pathSeparator = require('path').sep
76+
8577
packages = ['vim-mode-plus']
8678
if reloadDependencies
8779
packages.push(settings.get('devReloadPackages')...)
8880

81+
invalidateRequireCacheForPackage = (packPath) ->
82+
Object.keys(require.cache)
83+
.filter (p) -> p.startsWith(packPath + pathSeparator)
84+
.forEach (p) -> delete require.cache[p]
85+
8986
deactivate = (packName) ->
9087
console.log "- deactivating #{packName}"
9188
packPath = atom.packages.getLoadedPackage(packName).path
@@ -109,7 +106,8 @@ class Developer
109106
atom.commands.add('atom-text-editor', "vim-mode-plus:#{name}", fn)
110107

111108
clearDebugOutput: (name, fn) ->
112-
filePath = fs.normalize(settings.get('debugOutputFilePath'))
109+
{normalize} = require('fs-plus')
110+
filePath = normalize(settings.get('debugOutputFilePath'))
113111
options = {searchAllPanes: true, activatePane: false}
114112
atom.workspace.open(filePath, options).then (editor) ->
115113
editor.setText('')
@@ -148,6 +146,8 @@ class Developer
148146
".has-persistent-selection": '%'
149147

150148
getCommandSpecs: ->
149+
_ = require 'underscore-plus'
150+
151151
compactSelector = (selector) ->
152152
pattern = ///(#{_.keys(selectorMap).map(_.escapeRegExp).join('|')})///g
153153
selector.split(/,\s*/g).map (scope) ->
@@ -190,6 +190,8 @@ class Developer
190190

191191
kinds = ["Operator", "Motion", "TextObject", "InsertMode", "MiscCommand", "Scroll"]
192192
generateSummaryTableForCommandSpecs: (specs, {header}={}) ->
193+
_ = require 'underscore-plus'
194+
193195
grouped = _.groupBy(specs, 'kind')
194196
str = ""
195197
for kind in kinds when specs = grouped[kind]
@@ -243,7 +245,9 @@ class Developer
243245
args: ['-g', editor.getPath(), "+call cursor(#{row+1}, #{column+1})"]
244246

245247
generateIntrospectionReport: ->
246-
generateIntrospectionReport ?= require './introspection'
248+
_ = require 'underscore-plus'
249+
generateIntrospectionReport = require './introspection'
250+
247251
generateIntrospectionReport _.values(Base.getClassRegistry()),
248252
excludeProperties: [
249253
'run'

0 commit comments

Comments
 (0)