Logic for requiring Atom API classes


I’m wondering how to import Atom API into my own package.

For some classes I can do it like this:

{Emitter, CompositeDisposable} = require 'atom'

But that only works with a few classes. For example if I try to make use of a File like this the import fails:

{File, Directory} = require 'atom'

Is this just an oversite or is their a reason that some documented API classes are included in the atom exports and others are not? I would in particular lobby that File and Directory get added to the exports list.



File and Directory come from the node-pathwatcher module. The vast majority of packages will not need them since the Node fs module will suffice in most cases and does not require the package to take an extra dependency.


@leedohm Thanks for your response.

It certainly makes sense to me that you want to limit Atom’s exports. But in this particular case aren’t File and Directory already being “exposed” through their documentation in the extended classes API?

I guess for me coming at the API for the first time it’s a bit confusing looking at that API documentation page and trying to figure out how to access the classes without needing to dig into exports/atom.coffee to see what is actually getting exported.



I can understand that. The thing to remember is that it’s pretty rare that you instantiate these classes directly. The framework makes most of them for you and then you just use them. It’s good feedback to include though for future documentation updates or for the upcoming documentation effort that @benogle mentioned.


The blog says to use atom.project.repositoryForDirectory(directory) to get a repo for a directory. I need to get the repo for the project directory for an editor. The editor.getPath method returns a string but atom.project.repositoryForDirectory(directory) requires a Directory object. How do I get that object?


Directory and File have since been exposed through Atom, so you can now do:

{File, Directory} = require 'atom'

And it works to get access to those classes.



Thanks. I thought that was the case but it didn’t work. I went back to check my code and I had …

{Directory} = atom



Opened this Issue on atom/atom regarding the mismatch between what the API returns and what it expects: