You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`node-pre-gyp` stands between [npm](https://github.com/npm/npm) and [node-gyp](https://github.com/Tootallnate/node-gyp) and offers a cross-platform method of binary deployment.
11
11
12
-
`node-pre-gyp` stands between [npm](https://github.com/npm/npm) and [node-gyp](https://github.com/Tootallnate/node-gyp). It offers two main things:
12
+
### Features
13
13
14
-
- A command line tool called `node-pre-gyp` that can install your package from a binary or publish it.
15
-
- Javascript code that can be required to dynamically find your module: `require('node-pre-gyp').find`
14
+
- A command line tool called `node-pre-gyp` that can install your package's c++ module from a binary.
15
+
- A variety of developer targeted commands for packaging, testing, and publishing binaries.
16
+
- A Javascript module that can dynamically require your installed binary: `require('node-pre-gyp').find`
16
17
17
-
For a hello world example of a Node.js C++ module packaged with `node-pre-gyp` see <https://github.com/springmeyer/node-addon-example>.
For a hello world example of a module packaged with `node-pre-gyp` see <https://github.com/springmeyer/node-addon-example> and [the wiki ](https://github.com/mapbox/node-pre-gyp/wiki/Modules-using-node-pre-gyp) for real world examples.
28
19
29
20
## Depends
30
21
@@ -38,7 +29,7 @@ For more examples see the [test apps](test/).
38
29
39
30
But you can also install it globally:
40
31
41
-
npm install node-pre-gyp -g
32
+
npm install node-pre-gyp -g
42
33
43
34
## Usage
44
35
@@ -63,15 +54,32 @@ You can also chain commands:
63
54
64
55
node-pre-gyp clean build unpublish publish info
65
56
66
-
### Configuring your module to use node-pre-gyp
57
+
### Options
58
+
59
+
Options include:
60
+
61
+
-`-C/--directory`: run the command in this directory
62
+
-`--build-from-source`: build from source instead of using pre-built binary
63
+
-`--fallback-to-build`: fallback to building from source if pre-built binary is not available
64
+
-`--target=0.10.25`: Pass the target node or node-webkit version to compile against
65
+
66
+
Both `--build-from-source` and `--fallback-to-build` can be passed alone or they can provide values. You can pass `--fallback-to-build=false` to override the option as declared in package.json. In addition to being able to pass `--build-from-source` you can also pass `--build-from-source=myapp` where `myapp` is the name of your module.
67
+
68
+
For example: `npm install --build-from-source=myapp`. This is useful if:
69
+
70
+
-`myapp` is referenced in the package.json of a larger app and therefore `myapp` is being installed as a dependent with `npm install`.
71
+
- The larger app also depends on other modules installed with `node-pre-gyp`
72
+
- You only want to trigger a source compile for `myapp` and the other modules.
73
+
74
+
### Configuring
67
75
68
-
**1) Add new entries to your `package.json`**
76
+
This is guide to configuring your module to use node-pre-gyp.
69
77
70
-
We need to:
78
+
#### 1) Add new entries to your `package.json`
71
79
72
-
- Add node-pre-gyp as a bundled dependency
80
+
- Add `node-pre-gyp` as a bundled dependency
73
81
- Add a custom `install` script
74
-
-Add a `binary` object
82
+
-Declare a `binary` object
75
83
76
84
This looks like:
77
85
@@ -90,33 +98,33 @@ This looks like:
90
98
}
91
99
```
92
100
93
-
#### The `binary` object has three required properties
101
+
#####The `binary` object has three required properties
94
102
95
-
##### module_name
103
+
######module_name
96
104
97
105
The name of your native node module.This must match the name passed to [the NODE_MODULE macro](http://nodejs.org/api/addons.html#addons_hello_world) and should not include the `.node` extension.
98
106
99
-
##### module_path
107
+
######module_path
100
108
101
109
The location your native module is placed after a build. This should be an empty directory without other javascript files. This is because everything in the directory will be packaged in the binary tarball and when unpack anything inside the directory will be overwritten with the contents of the tarball. **
102
110
103
-
##### host
111
+
######host
104
112
105
113
A url to the remote location where you've published tarball binaries (must be `https` not `http`)
106
114
107
-
#### The `binary` object has two optional properties
115
+
#####The `binary` object has two optional properties
108
116
109
-
##### remote_path
117
+
######remote_path
110
118
111
119
It **is recommended** that you customize this property. This is an extra path to use for publishing and finding remote tarballs. The default value for `remote_path` is `""` meaning that if you do not provide it then all packages will be published at the base of the `host`. It is recommended to provide a value like `./{module_name}/v{version}` to help organize remote packages in the case that you choose to publish multiple node addons to the same `host`. **
112
120
113
-
##### package_name
121
+
######package_name
114
122
115
123
It is **not recommended** to override this property. This is the versioned name of the remote tarball containing the binary `.node` module and any supporting files you've placed inside the `module_path`. If you do not provide it in your `package.json` then it defaults to `{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz` which is a versioning string capable of supporting any remove lookup of your modules across all of its pubished versions and various node versions, platforms and architectures. But if you only wish to support windows you could could change it to `{module_name}-v{version}-{node_abi}-win32-{arch}.tar.gz`. See [Versioning](#versioning for details) about what each variable evaluates to. **
116
124
117
125
** Properties supporting versioning mean that they will be evaluated against known node-pre-gyp variables. See [Versioning](#versioning for details).
118
126
119
-
**4) Dynamically require your `.node`
127
+
#### 2) Dynamically require your `.node`
120
128
121
129
Inside the main js file that requires your addon module you are likely currently doing:
122
130
@@ -139,7 +147,7 @@ var binding_path = binary.find(path.resolve(path.join(__dirname,'./package.json'
139
147
var binding =require(binding_path);
140
148
```
141
149
142
-
**5) Build and package your app**
150
+
#### 3) Build and package your app
143
151
144
152
Now build your module from source:
145
153
@@ -149,11 +157,11 @@ The `--build-from-source` tells `node-pre-gyp` to not look for a remote package
149
157
150
158
Now `node-pre-gyp` should now also be installed as a local dependency so the command line tool it offers can be found at `./node_modules/.bin/node-pre-gyp`.
151
159
152
-
**6) Test**
160
+
#### 4) Test
153
161
154
162
Now `npm test` should work just as it did before.
155
163
156
-
**7) Publish the tarball**
164
+
#### 5) Publish the tarball
157
165
158
166
Then package your app:
159
167
@@ -175,11 +183,11 @@ You can also host your binaries elsewhere. To do this requires:
175
183
- You manually publish the binary created by the `package` command to an `https` endpoint
176
184
- Ensure that the `host` value points to your custom `https` endpoint.
177
185
178
-
**8) Automating builds**
186
+
#### 6) Automate builds
179
187
180
188
Now you need to publish builds for all the platforms and node versions you wish to support. This is best automated. See [Travis Automation](#travis-automation) for how to auto-publish builds on OS X and Linux. On windows consider using a script [like this](https://github.com/mapbox/node-sqlite3/blob/master/scripts/build.bat) to quickly create and publish binaries and check out <https://appveyor.com>.
181
189
182
-
**9) You're done!**
190
+
#### 7) You're done!
183
191
184
192
Now publish your package to the npm registry. Users will now be able to install your module from a binary.
185
193
@@ -322,22 +330,6 @@ Or you could automatically detect if the git branch is a tag:
322
330
Remember this publishing is not the same as `npm publish`. We're just talking about the
323
331
binary module here and not your entire npm package. To automate the publishing of your entire package to npm on travis see http://about.travis-ci.org/docs/user/deployment/npm/
324
332
325
-
### Options
326
-
327
-
Options include:
328
-
329
-
- `-C/--directory`: run the command in this directory
330
-
- `--build-from-source`: build from source instead of using pre-built binary
331
-
- `--fallback-to-build`: fallback to building from source if pre-built binary is not available
332
-
333
-
Both `--build-from-source` and `--fallback-to-build` can be passed alone or they can provide values. So, in addition to being able to pass `--build-from-source` you can also pass `--build-from-source=myapp` where `myapp` is the name of your module.
334
-
335
-
For example: `npm install --build-from-source=myapp`. This is useful if:
336
-
337
-
- `myapp`is referenced in the package.json of a larger app and therefore `myapp` is being installed as a dependent with `npm install`.
338
-
- The larger app also depends on other modules installed with `node-pre-gyp`
339
-
- You only want to trigger a source compile for `myapp` and the other modules.
340
-
341
333
# Versioning
342
334
343
335
The versioning template accepts these variables, which will get evaluated by `node-pre-gyp` depending on your system and any custom build flags you passed.
0 commit comments