Atom local modules in package development


#1

I am trying to write a package, so i want to use the snippets (one that comes with atom) package.
So i added

"dependencies": {
    "snippets": "0.x"
  }

to package.json.

And then i ran apm install from cwd. But it installed some package from npm not the atom one…

I also tried just using

var n = require('snippets')

without the above steps, then i am gettings "Module not found error’ for snippets.

So what is the right way for using atom packages


#2

You need to run apm update first.


#3

Still it is not working
I deleted the node_module folder and ran apm update

But this is installing git://github.com/jheusala/js-snippets.git


#4

Sorry about that, the command is apm install


#5

You should use PackageManager (https://atom.io/docs/api/v0.91.0/api/classes/PackageManager.html) which is accessible via atom.packages (https://atom.io/docs/api/v0.91.0/api/classes/Atom.html). Then, you should use some API exposed by the package to interact with it.

Naturally that begs the question ‘what’s the API’ and there may not be one. Which is a perfect opportunity for a pull request to add one :smile:.


#6

Also, if you do want to continue with the approach of requiring the package and using a package.json dependency, try using a git dependency rather than the package name (e.g. https://github.com/joefitzgerald/go-plus/blob/e280a93c586c5466bc53895b0275068aa67bd86f/package.json#L330).


#7

I used atom.packages.activePackages.snippets.mainModule.api()

Thank you :smile: