How to setup development for core modules like atom-keymap?


#1

I’m trying to setup atom-keymap module for development to fix an issue.

Since it isn’t a package I’m not quite sure how to set it up so I can load and debug it in Atom.
I’ve cloned the repo, but not sure if there is some variant of apm link I can use to link it it.
I’m guessing it then needs compiling in the main app source tree?

A few pointers on how to get this up and running would be appreciated.


Looking for best practices for iterative development on Atom
#2

Packages in ~/.atom/dev/packages override ones in ~/.atom/packages which in turn override ones built in to Atom. So you can just use apm link or apm link --dev to link it.


#3

I tried that but had an error in the console when running in dev mode.

It looked like the package manager couldn’t load atom-keymap as it doesn’t have an activate function exported.
I was guessing this was because it was a core module and needed treating differently?


#4

I just tried it:

$ git clone https://github.com/atom/atom-keymap.git
$ cd atom-keymap
$ apm link --dev
$ atom --dev

There were no errors in the console when I opened it. I suspect the error was caused by one of your changes or other packages?


#5

Oh, I’m not sure what I’m doing wrong then.

Good to know that I was attempting to do it right.
I had done the above on a clean clone of atom-keymap and was getting the error.

I am on Windows, I’m not sure if this is causing an issue.
I will have to try it again and see if I can get it working.


#6

Tried it again, following your steps exactly but it doesn’t look like it has loaded the link version this time.

I tried doing an apm install and then running it and it looks like this causes it to get loaded, but I get this error:

Failed to activate package named 'atom-keymap' TypeError: Object function KeymapManager(options) {
  var key, value;
  if (options == null) {
    options = {};
  }
  for (key in options) {
    value = options[key];
    this[key] = value;
  }
  this.keyBindings = [];
  this.queuedKeyboardEvents = [];
  this.queuedKeystrokes = [];
  this.watchSubscriptions = {};
  console.log('boom!');
} has no method 'activate'
at Package.module.exports.Package.activateNow (c:\Program Files (x86)\Atom\resources\app\src\package.js:161:27)
at c:\Program Files (x86)\Atom\resources\app\src\package.js:147:28
at Package.module.exports.Package.measure (c:\Program Files (x86)\Atom\resources\app\src\package.js:95:15)
at Package.module.exports.Package.activate (c:\Program Files (x86)\Atom\resources\app\src\package.js:141:14)
at PackageManager.module.exports.PackageManager.activatePackage (c:\Program Files (x86)\Atom\resources\app\src\package-manager.js:109:21)
at PackageManager.module.exports.PackageManager.activatePackages (c:\Program Files (x86)\Atom\resources\app\src\package-manager.js:98:14)
at PackageManager.module.exports.PackageManager.activate (c:\Program Files (x86)\Atom\resources\app\src\package-manager.js:85:19)
at Atom.module.exports.Atom.startEditorWindow (c:\Program Files (x86)\Atom\resources\app\src\atom.js:349:21)
at Object.<anonymous> (c:\Program Files (x86)\Atom\resources\app\src\window-bootstrap.js:14:8)
at Object.<anonymous> (c:\Program Files (x86)\Atom\resources\app\src\window-bootstrap.js:20:4)
at Module._compile (module.js:455:26)
at Object.Module._extensions..js (module.js:473:10)
at Module.load (C:\Program Files (x86)\Atom\resources\app\node_modules\coffee-script\lib\coffee-script\register.js:45:36)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:363:17)
at require (module.js:379:17)
at window.onload (file:///C:/Program%20Files%20(x86)/Atom/resources/app/static/index.js:20:5)

#7

You won’t be able to work on bundled packages as you normally do.

Firstly, the keymap module is loaded by the keymap-extensions file and not through the general package loading (see here), this mean that to work your own version you’ll have to hack this line to load it from your own project directory, I didn’t try it but there’s chance that you may eventually have to compile coffee to js yourself (dunno when coffeescript loading occurs during the Atom boot sequence).

Secondly, The error you encounter is due to the fact that since the keymap package is loaded in its own way it just expose the KeymapManager class and not an Atom module (with activate, deactivate and serialize methods), but since you have forked it into the .atom/dev/packages or .atom/packages directory it’s considered as a package to load and loaded as any other package, expecting an activate method.

You should first move your fork elsewhere then use a hacked version of the keymap-extensions file in order to load your project instead.

I guess @kevinsawicki or @ProbablyCorey could give us more insight on how to edit the bundled packages in a cleaner way than this.


#8

Thanks, I thought this would be the case, but wasn’t sure.

I would appreciate any follow up on the cleanest, most correct way of doing this, but at least I should be able to get my fork loaded.

That brings me on to how to execute the tests for atom-keymap. Running apm test just says the tests have failed almost instantly so I don’t think that’s correct.

Any ideas?


#9

Personally, I’d consider this a bug in atom-keymap. Either it is a package and should be loaded as all other packages are … or it is a part of Core and should be folded in.


#10

In fact the issue is more that we all assumed that all Atom packages (bundled and installed) are apm packages, but atom-keymap is a npm module (you can find it on npmjs.org), so it doesn’t have to follow the Atom packages interface and isn’t tied to Atom at all (like emissary, delegato, node-oniguruma, etc.).

If you had a look at the Atom package.json file you probably noticed that there’s two groups of dependencies: dependencies and packageDependencies, the first for npm modules, the second for apm modules.


#11

So all I should need to do is treat it like a normal npm package.

npm link

in the atom-keymap directory to create a local system link

npm link atom-keymap

in the atom directory to link that local system link into the atom node_modules instead of pulling it down during the build.

Building atom as normal will then compile with the local atom-keymap module.

I’ve tried this and it seems to work to a point, I’m just getting errors when I launch the built Atom.
The errors talk about a module mismatch somewhere in atom-keymap, so I’m doing a totally clean build to see if that fixes it.

I still don’t have any luck running the test for atom-keymap. I’ve tried npm test but the script bombs out.
I think the tests are just broken for Windows.


#12

Not sure I can help beyond that, I do have a windows system, but not configured for dev yet. But maybe this can help:

  • I’m not sure that npm commands will be of any help here. It’s a npm module, but not really used in a classical node context.
  • Looking at the .travis.yml file we can see that tests runs using the same environment packages can use to run (see this post), so npm test will not work neither.
  • Having wrote some tests for a feature in core, I had to configure Atom tests to run (see the PR here) and I also had some hard time making all things works, fortunately @kevinsawicki was kind enough to help me understanding how making the setup. But the windows setup will probably be different and the details may be not be as useful as it was for me.
  • If you got the Atom test suite running in Atom using ctrl-alt-shift-S, you’ll end up running the whole Atom suite plus all the installed packages suites, meaning that if some packages have broken tests, it’ll prevent all the suites to run, make sure to move packages that breaks outside the packages directory while working with the tests.
  • Running the whole Atom suite on my MBA takes 7/8mn, so I highly recommend to work using the focus feature of jasmine-focused, use fdescribe or fit for your tests and then remove the f prefix while submitting your work.

#13

Thanks again. I will have to see if I can get the tests running somehow.

I tried npm linking the package into atom, and doing a clean build, but I’m still getting the following error on load:

Error: Module version mismatch. Expected 13, got 11.
at Module.load (C:\Program Files (x86)\Atom\resources\app\node_modules\coffee-script\lib\coffee-script\register.js:45:36)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:363:17)
at require (module.js:379:17)
at bindings (c:\Program Files (x86)\Atom\resources\app\node_modules\atom-keymap\node_modules\pathwatcher\node_modules\bindings\bindings.js:76:44)
at Object.<anonymous> (c:\Program Files (x86)\Atom\resources\app\node_modules\atom-keymap\node_modules\pathwatcher\lib\main.js:6:32)
at Object.<anonymous> (c:\Program Files (x86)\Atom\resources\app\node_modules\atom-keymap\node_modules\pathwatcher\lib\main.js:206:4)
at Module._compile (module.js:455:26)
at Object.Module._extensions..js (module.js:473:10)
at Module.load (C:\Program Files (x86)\Atom\resources\app\node_modules\coffee-script\lib\coffee-script\register.js:45:36)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:363:17)
at require (module.js:379:17)
at Object.<anonymous> (c:\Program Files (x86)\Atom\resources\app\node_modules\atom-keymap\lib\keymap-manager.js:17:10)
at Object.<anonymous> (c:\Program Files (x86)\Atom\resources\app\node_modules\atom-keymap\lib\keymap-manager.js:514:4)
at Module._compile (module.js:455:26)
at Object.Module._extensions..js (module.js:473:10)
at Module.load (C:\Program Files (x86)\Atom\resources\app\node_modules\coffee-script\lib\coffee-script\register.js:45:36)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:363:17)
at require (module.js:379:17)
at Object.<anonymous> (c:\Program Files (x86)\Atom\resources\app\src\keymap-extensions.js:8:19)
at Object.<anonymous> (c:\Program Files (x86)\Atom\resources\app\src\keymap-extensions.js:46:4)
at Module._compile (module.js:455:26)
at Object.Module._extensions..js (module.js:473:10)
at Module.load (C:\Program Files (x86)\Atom\resources\app\node_modules\coffee-script\lib\coffee-script\register.js:45:36)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:363:17)
at require (module.js:379:17)
at Atom.module.exports.Atom.initialize (c:\Program Files (x86)\Atom\resources\app\src\atom.js:157:23)
at Object.<anonymous> (c:\Program Files (x86)\Atom\resources\app\src\window-bootstrap.js:12:8)
at Object.<anonymous> (c:\Program Files (x86)\Atom\resources\app\src\window-bootstrap.js:20:4)
at Module._compile (module.js:455:26)
at Object.Module._extensions..js (module.js:473:10)
at Module.load (C:\Program Files (x86)\Atom\resources\app\node_modules\coffee-script\lib\coffee-script\register.js:45:36)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:363:17)
at require (module.js:379:17)
at window.onload (file:///C:/Program%20Files%20(x86)/Atom/resources/app/static/index.js:20:5) index.js:29

It looks like the bindings module within the pathwatcher module is mismatching.

Any ideas why?


#14

It’s a node version error, the cpp extensions being compiled for a given version you’ll have to match the one Atom use. Atom actually use version 0.11.10, and you’re using a v0.10.x.


#15

Of course, that figures.

Should an apm install setup and compile the modules with the Atom version of node?

I may have done an npm install instead.


#16

It should, yes. And if not you can always install version 0.11.10 through nvm


#17

Once again you are correct.

Doing an apm install in atom-keymap after npm link has resulted in a build that loads and includes my console.log test line.

I can now see if I can fix the issue for windows and I can add tests I just can’t run them right now, but that’s a slightly separate issue.

Thanks again for all your help.


#18

@mcnicholls sorry for not responding sooner.

Here are the steps to run a local version of a node module NOT AN APM within Atom

$ git clone https://github.com/atom/atom-keymap.git
$ cd atom-keymap
$ npm install
$ npm link
$ apm rebuild # This is the special step, it makes the npm work with Atom's version of Node
$ cd WHERE-YOU-CLONED-ATOM
$ npm link atom-keymap
$ atom # Should work!

You’ll have to npm install and apm rebuild when you make a change to the atom-keymap code. Or you can just manually compile atom-keymap’s coffeeScript.


Looking for best practices for iterative development on Atom
#19

Thanks @ProbablyCorey

Good to know I’m almost doing it the correct way.

After doing an npm install and an apm rebuild do I need to do script/build in the atom tree or does apm rebuild automatically build and install the files?

I’m on Windows and looking to fix a few problems I’ve come across relating to the keymap as I want to use vim-mode and it’s not quite working right.

I’m initially looking at fixing atom-keymap#15. I can’t get the tests to run on Windows, but then I’m not sure I’m doing that right. What should be the correct procedure for running the tests in atom-keymap?

I have other issues, but I think they could all be related.


#20

I also documented the instructions and submitted a pull request which @ProbablyCorey merged. So if there are other tips for hacking on node modules that should be documented … let’s add those too.