Reload a package while developing


#1

Trying to develop a package, how do I reload it without quitting the entire editor? I’m trying to use emissary and it’s saying the module can’t be found, despite the fact that the whitespace package uses it…


Reload package from disk without reloading editor
Experimenting with views without constantly reloading
#2

I’m seeing the same thing. I think packages that’re in ~/.atom/packages aren’t able to resolve npm dependencies. If I move my in development package into /Applications/Atom.app/Contents/Resources/app/node_modules it loads.

As for reloading, you can use Window: Reload.


#3

Nope, that’s not true. It is possible.

How are you guys requiring your npm packages? Can you provide more details on the setup, and provide the package.json?


#4

Simply copying an existing working package into ~/.atom/packages will reproduce the error.

cp -r /Applications/Atom.app/Contents/Resources/app/node_modules/markdown-preview ~/.atom/packages/markdown-preview2

Open Atom, in the DevTools: Failed to load package named 'markdown-preview2' Error: Cannot find module 'fs-plus'


#5

Interesting, I can reproduce that. At the same time, I have another package I’m working on that does use an npm module, and that loads fine! I wonder what the difference is…


#6

package.json

{
  "name": "gofmt",
  "main": "./lib/main",
  "version": "0.0.0",
  "description": "Runs gofmt on your code",
  "repository": "https://github.com/darkhelmet/atom-gofmt",
  "license": "MIT",
  "engines": {
    "atom": ">0.50.0"
  },
  "dependencies": {
    "emissary": "1.x"
  }
}

lib/main.coffee

Gofmt = require('./gofmt')

module.exports =
  configDefaults:
    pathToBinary: 'gofmt'
    tabs: true
    tabWidth: 8

  activate: ->
    console.log("starting gofmt")
    @gofmt = new Gofmt()

  deactivate: ->
    @gofmt.destroy()

lib/gofmt.coffee

Subscriber = require('emissary').Subscriber
Spawn = require('child_process').spawn

class Gofmt
  Subscriber.includeInto(this)

  constructor: ->
    console.log("wat")
    atom.workspace.eachEditor (editor) =>
      console.log("new editor")
      @handleSave(editor)

  destroy: ->
    @unsubscribe()

  handleSave: (editor) ->
    buffer = editor.getBuffer()
    @subscribe buffer, 'saved', =>
      console.log('saved')
      console.log(editor.getGrammar().scopeName)
      path = editor.getUri()
      console.log(path)
      Spawn("gofmt #{path}")

    @subscribe buffer, 'destroyed', =>
      @unsubscribe(buffer)

module.exports = Gofmt

The error is that it can’t find module emissary.


#7

You can also use the keybinding for reloading which is ctrl-opt-cmd-L.


#8

@darkhelmetlive Not sure if you have figured it out yet, but you have to run apm install in your directory to pull in node dependencies. Then you can carry on with your plugin in ~/.atom/packages


#9

For now, or at least on Linux, it is ctrl+alt+r


#10

I’ve figured that since you were developing, you’re likely to have the chrome dev opened. Then CMD+R (CTRL+R windows and linux) should work. It does on my machine. Note that the focus needs to be on the Chrome dev tool.

Of course you can still run the 4 keys shortcuts (is-it?) ctrl+option+cmd+l.


#11

I created a package autoreload-package-service, which reloades your package on file save. You simply download it, consume its service, set it up and are ready to go…