From a9748f6cc6e79b763a0b668517abb96eb5e85227 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 30 Apr 2014 15:03:14 +0800 Subject: [PATCH] :memo: Say some more about native node modules. --- docs/tutorial/use-native-node-module.md | 28 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/docs/tutorial/use-native-node-module.md b/docs/tutorial/use-native-node-module.md index 7caed97c..41e1ef43 100644 --- a/docs/tutorial/use-native-node-module.md +++ b/docs/tutorial/use-native-node-module.md @@ -1,10 +1,11 @@ # Use native node modules -Since atom-shell is using a different V8 version from the official node, you -need to build native module against atom-shell's headers to use them. +The native node modules are supported by atom-shell, but since atom-shell is +using a different V8 version from official node, you need to use `apm` instead +of `npm` to install node modules. -The [apm](https://github.com/atom/apm) provided a easy way to do this, after -installing it you could use it to install dependencies just like using `npm`: +The usage of [apm](https://github.com/atom/apm) is quite similar to `npm`, to +install dependencies from `package.json` of current project, just do: ```bash $ cd /path/to/atom-shell/project/ @@ -12,12 +13,25 @@ $ apm install . ``` But you should notice that `apm install module` wont' work because it will -install a user package for [Atom](https://github.com/atom/atom) instead. +install a user package for [Atom Editor](https://github.com/atom/atom) instead. + +## Native node module compability + +Since node v0.11.x, there were vital changes of V8 API, so generally all native +modules written for node v0.10.x wouldn't work for node v0.11.x, and since +atom-shell internally uses node v0.11.9, it carries with the same problem. + +To solve it, you should use modules that support both node v0.10.x and v0.11.x, +and [many modules](https://www.npmjs.org/browse/depended/nan) do support the +both now. For old modules that only support node v0.10.x, you should use the +[nan](https://github.com/rvagg/nan) module to port it to v0.11.x. + +## Other ways of installing native modules Apart from `apm`, you can also use `node-gyp` and `npm` to manually build the native modules. -## The node-gyp way +### The node-gyp way First you need to check which node release atom-shell is carrying via `process.version` (at the time of writing it is v0.10.5), then you can @@ -32,7 +46,7 @@ The `HOME=~/.atom-shell-gyp` changes where to find development headers. The `--target=0.10.5` is specifying node's version. The `--dist-url=...` specifies where to download the headers. -## The npm way +### The npm way ```bash export npm_config_disturl=https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist -- 2.43.0