Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bbc/speculate
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d5d5a3cf84ec52ae5ed835a213d70444c8c6bf56
Choose a base ref
..
head repository: bbc/speculate
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1e0b7c6f05c26c19aaf5423c9b40cfe8fa6a1db0
Choose a head ref
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -82,6 +82,16 @@ Speculate assumes that you've _already installed your npm dependencies_ when it

The generated spec file instructs your RPM building tool to run [`npm rebuild`](https://docs.npmjs.com/cli/rebuild) as part of the build process. This ensures that any native modules are rebuilt for your target environment, even if they were originally installed on a different platform.

If for some reason you do not want to rebuild your native modules, you can explicity tell speculate not to rebuild by adding the following to your `package.json`:

```json
{
"spec": {
"rebuild": false
}
}
```

A typical speculate build looks like this:

```bash
@@ -330,14 +340,25 @@ speculate --name=my-cool-api

This is useful if you are using private NPM packages which start with an `@`.

### Replace hyphens in npm version number

Running rpmbuild on an npm package with a hyphen in its version number throws an error. If your package's version number contains hyphens (e.g. it is a prerelease), you may wish to replace them so that the rpm can be built. You can tell speculate to replace these with tildes by adding the `replaceHyphens` property to your package's spec block:

```json
{
"spec": {
"replaceHyphens": true
}
}
```

### Mocking and node-gyp

[Mock](https://github.com/rpm-software-management/mock) is a really useful tool to ensure that your RPM builds in a clean environment, without accidentally depending on something your system that you havn't added to the `require` list.

While the RPM is being built by `mock`, it does not have any access to the Internet. This is good because it ensures that you get consistent builds. It also means the build won't fail, if a server outside of your control is offline. However it can cause node-gyp to fail, if it can't find the node header files on your system.

Make sure your have the a build dependency on: `nodejs-devel`. This places the node header files in `/usr/include/node`:
If you are using [NodeSource](https://github.com/nodesource/distributions), then you will need to make sure your have a build dependency on: `nodejs-devel`. This places the node header files in `/usr/include/node`:

```json
{
@@ -355,4 +376,4 @@ Then add the following line to `/etc/mock/site-defaults.cfg`:
config_opts['environment']['npm_config_nodedir'] = '/usr'
```

This will tell node-gyp where to find the node header files on your system.
This will tell node-gyp where to find the node.js header files on your system.
11 changes: 9 additions & 2 deletions lib/spec.js
Original file line number Diff line number Diff line change
@@ -18,6 +18,12 @@ function getReleaseNumber(release) {
return defaultRelease;
}

function getVersionNumber({ spec, version }) {
const replaceHyphens = getValueFromSpec(spec, 'replaceHyphens', false);

return replaceHyphens ? version.replace(/-/g, '~') : version;
}

function getValueFromSpec(spec, key, fallback) {
if (spec && key in spec) {
return spec[key];
@@ -46,9 +52,10 @@ module.exports = function (pkg, release) {
buildRequires: getValueFromSpec(pkg.spec, 'buildRequires', []),
postInstallCommands: getValueFromSpec(pkg.spec, 'post', []),
nodeVersion: getValueFromSpec(pkg.spec, 'nodeVersion'),
version: pkg.version,
version: getVersionNumber(pkg),
license: pkg.license,
prune: getValueFromSpec(pkg.spec, 'prune', true)
prune: getValueFromSpec(pkg.spec, 'prune', true),
rebuild: getValueFromSpec(pkg.spec, 'rebuild', true)
},
getExecutableFiles(pkg),
getServiceProperties(pkg)
Loading