node-pre-gyp
Advanced tools
Comparing version 0.10.3 to 0.11.0
# node-pre-gyp changelog | ||
## 0.11.0 | ||
- Fixed double-install problem with node v10 | ||
- Significant N-API improvements (https://github.com/mapbox/node-pre-gyp/pull/405) | ||
## 0.10.3 | ||
@@ -4,0 +9,0 @@ |
@@ -24,3 +24,3 @@ "use strict"; | ||
compile.run_gyp(final_args,result.opts,function(err) { | ||
if (!err && result.opts.napi_build_version) { | ||
if (result.opts.napi_build_version) { | ||
napi.swap_build_dir_out(result.opts.napi_build_version); | ||
@@ -27,0 +27,0 @@ } |
@@ -95,2 +95,3 @@ "use strict"; | ||
var extractCount = 0; | ||
var hasResponse = false; | ||
var tar = require('tar'); | ||
@@ -126,3 +127,3 @@ | ||
req.on('close', function () { | ||
if (extractCount === 0) { | ||
if (!hasResponse) { | ||
return callback(new Error('Connection closed while downloading tarball file')); | ||
@@ -137,2 +138,3 @@ } | ||
} | ||
hasResponse = true; | ||
if (res.statusCode !== 200) { | ||
@@ -139,0 +141,0 @@ badDownload = true; |
@@ -138,3 +138,3 @@ "use strict"; | ||
this.todo = napi.expand_commands (package_json, commands); | ||
this.todo = napi.expand_commands (package_json, this.opts, commands); | ||
@@ -141,0 +141,0 @@ // support for inheriting config env variables from npm |
@@ -12,4 +12,4 @@ "use strict"; | ||
exports.validate = function(package_json) { | ||
versioning.validate_config(package_json); | ||
exports.validate = function(package_json,opts) { | ||
versioning.validate_config(package_json,opts); | ||
}; | ||
@@ -22,6 +22,6 @@ | ||
var package_json = require(package_json_path); | ||
versioning.validate_config(package_json); | ||
versioning.validate_config(package_json,opts); | ||
var napi_build_version; | ||
if (napi.get_napi_build_versions (package_json)) { | ||
napi_build_version = napi.get_best_napi_build_version(package_json); | ||
if (napi.get_napi_build_versions (package_json, opts)) { | ||
napi_build_version = napi.get_best_napi_build_version(package_json, opts); | ||
} | ||
@@ -28,0 +28,0 @@ opts = opts || {}; |
@@ -16,3 +16,3 @@ "use strict"; | ||
]; | ||
commands = napi.expand_commands(package_json, commands); | ||
commands = napi.expand_commands(package_json, gyp.opts, commands); | ||
for (var i = commands.length; i !== 0; i--) { | ||
@@ -19,0 +19,0 @@ gyp.todo.unshift(commands[i-1]); |
@@ -13,3 +13,3 @@ "use strict"; | ||
var installArgs = []; | ||
var napi_build_version = napi.get_best_napi_build_version(package_json); | ||
var napi_build_version = napi.get_best_napi_build_version(package_json, gyp.opts); | ||
if (napi_build_version != null) installArgs = [ napi.get_command_arg (napi_build_version) ]; | ||
@@ -16,0 +16,0 @@ gyp.todo.unshift( |
@@ -1781,3 +1781,11 @@ { | ||
"v8": "6.7" | ||
}, | ||
"10.7.0": { | ||
"node_abi": 64, | ||
"v8": "6.7" | ||
}, | ||
"10.8.0": { | ||
"node_abi": 64, | ||
"v8": "6.7" | ||
} | ||
} |
@@ -50,3 +50,4 @@ "use strict"; | ||
'node_abi_napi', | ||
'napi_build_version' | ||
'napi_build_version', | ||
'node_napi_label' | ||
]; | ||
@@ -65,4 +66,6 @@ | ||
node_pre_gyp_options.push('--' + key + '=' + val); | ||
} else if (key === 'napi_build_version') { | ||
node_pre_gyp_options.push('--' + key + '=0'); | ||
} else { | ||
if (key !== 'napi_version' && key !== 'node_abi_napi' && key !== 'napi_build_version') | ||
if (key !== 'napi_version' && key !== 'node_abi_napi') | ||
return callback(new Error("Option " + key + " required but not found by node-pre-gyp")); | ||
@@ -69,0 +72,0 @@ } |
@@ -5,2 +5,3 @@ "use strict"; | ||
var rm = require('rimraf'); | ||
var log = require('npmlog'); | ||
@@ -31,4 +32,5 @@ module.exports = exports; | ||
module.exports.get_napi_version = function() { | ||
module.exports.get_napi_version = function(target) { // target may be undefined | ||
// returns the non-zero numeric napi version or undefined if napi is not supported. | ||
// correctly supporting target requires an updated cross-walk | ||
var version = process.versions.napi; // can be undefined | ||
@@ -42,14 +44,16 @@ if (!version) { // this code should never need to be updated | ||
module.exports.get_napi_version_as_string = function() { | ||
module.exports.get_napi_version_as_string = function(target) { | ||
// returns the napi version as a string or an empty string if napi is not supported. | ||
var version = module.exports.get_napi_version(); | ||
var version = module.exports.get_napi_version(target); | ||
return version ? ''+version : ''; | ||
}; | ||
module.exports.validate_package_json = function(package_json) { // return err | ||
module.exports.validate_package_json = function(package_json, opts) { // throws Error | ||
var binary = package_json.binary; | ||
var module_path_ok = binary.module_path && binary.module_path.indexOf('{napi_build_version}') !== -1; | ||
var remote_path_ok = binary.remote_path && binary.remote_path.indexOf('{napi_build_version}') !== -1; | ||
var package_name_ok = binary.package_name && binary.package_name.indexOf('{napi_build_version}') !== -1; | ||
var napi_build_versions = module.exports.get_napi_build_versions(package_json); | ||
var module_path_ok = pathOK(binary.module_path); | ||
var remote_path_ok = pathOK(binary.remote_path); | ||
var package_name_ok = pathOK(binary.package_name); | ||
var napi_build_versions = module.exports.get_napi_build_versions(package_json,opts,true); | ||
var napi_build_versions_raw = module.exports.get_napi_build_versions_raw(package_json); | ||
@@ -69,3 +73,3 @@ if (napi_build_versions) { | ||
if ((module_path_ok || remote_path_ok || package_name_ok) && !napi_build_versions) { | ||
if ((module_path_ok || remote_path_ok || package_name_ok) && !napi_build_versions_raw) { | ||
throw new Error("When the substitution string '{napi_build_version}` is specified in " + | ||
@@ -75,20 +79,32 @@ "module_path, remote_path, or package_name; napi_versions must also be specified."); | ||
if (napi_build_versions && !module.exports.get_best_napi_build_version(package_json)) { | ||
if (napi_build_versions && !module.exports.get_best_napi_build_version(package_json, opts) && | ||
module.exports.build_napi_only(package_json)) { | ||
throw new Error( | ||
'The N-API version of this Node instance is ' + module.exports.get_napi_version() + '. ' + | ||
'This module supports N-API version(s) ' + module.exports.get_napi_build_versions(package_json) + '. ' + | ||
'The N-API version of this Node instance is ' + module.exports.get_napi_version(opts ? opts.target : undefined) + '. ' + | ||
'This module supports N-API version(s) ' + module.exports.get_napi_build_versions_raw(package_json) + '. ' + | ||
'This Node instance cannot run this module.'); | ||
} | ||
if (napi_build_versions_raw && !napi_build_versions && module.exports.build_napi_only(package_json)) { | ||
throw new Error( | ||
'The N-API version of this Node instance is ' + module.exports.get_napi_version(opts ? opts.target : undefined) + '. ' + | ||
'This module supports N-API version(s) ' + module.exports.get_napi_build_versions_raw(package_json) + '. ' + | ||
'This Node instance cannot run this module.'); | ||
} | ||
}; | ||
module.exports.expand_commands = function(package_json, commands) { | ||
function pathOK (path) { | ||
return path && (path.indexOf('{napi_build_version}') !== -1 || path.indexOf('{node_napi_label}') !== -1); | ||
} | ||
module.exports.expand_commands = function(package_json, opts, commands) { | ||
var expanded_commands = []; | ||
var napi_build_versions = module.exports.get_napi_build_versions(package_json); | ||
var napi_build_versions = module.exports.get_napi_build_versions(package_json, opts); | ||
commands.forEach(function(command){ | ||
if (napi_build_versions && command.name === 'install') { | ||
var napi_build_version = module.exports.get_best_napi_build_version(package_json); | ||
var napi_build_version = module.exports.get_best_napi_build_version(package_json, opts); | ||
var args = napi_build_version ? [ napi_build_version_tag+napi_build_version ] : [ ]; | ||
expanded_commands.push ({ name: command.name, args: args }); | ||
} else if (napi_build_versions && napi_multiple_commands.includes(command.name)) { | ||
} else if (napi_build_versions && napi_multiple_commands.indexOf(command.name) !== -1) { | ||
napi_build_versions.forEach(function(napi_build_version){ | ||
@@ -106,12 +122,39 @@ var args = command.args.slice(); | ||
module.exports.get_napi_build_versions = function(package_json) { | ||
module.exports.get_napi_build_versions = function(package_json, opts, warnings) { // opts may be undefined | ||
var napi_build_versions = []; | ||
if (package_json.binary && package_json.binary.napi_versions) { // remove duplicates | ||
var supported_napi_version = module.exports.get_napi_version(opts ? opts.target : undefined); | ||
// remove duplicates, verify each napi version can actaully be built | ||
if (package_json.binary && package_json.binary.napi_versions) { | ||
package_json.binary.napi_versions.forEach(function(napi_version) { | ||
if (!napi_build_versions.includes(napi_version)) napi_build_versions.push(napi_version); | ||
var duplicated = napi_build_versions.indexOf(napi_version) !== -1; | ||
if (!duplicated && supported_napi_version && napi_version <= supported_napi_version) { | ||
napi_build_versions.push(napi_version); | ||
} else if (warnings && !duplicated && supported_napi_version) { | ||
log.info('This Node instance does not support builds for N-API version', napi_version); | ||
} | ||
}); | ||
} | ||
if (opts && opts["build-latest-napi-version-only"]) { | ||
var latest_version = 0; | ||
napi_build_versions.forEach(function(napi_version) { | ||
if (napi_version > latest_version) latest_version = napi_version; | ||
}); | ||
napi_build_versions = latest_version ? [ latest_version ] : []; | ||
} | ||
return napi_build_versions.length ? napi_build_versions : undefined; | ||
}; | ||
module.exports.get_napi_build_versions_raw = function(package_json) { | ||
var napi_build_versions = []; | ||
// remove duplicates | ||
if (package_json.binary && package_json.binary.napi_versions) { | ||
package_json.binary.napi_versions.forEach(function(napi_version) { | ||
if (napi_build_versions.indexOf(napi_version) === -1) { | ||
napi_build_versions.push(napi_version); | ||
} | ||
}); | ||
} | ||
return napi_build_versions.length ? napi_build_versions : undefined; | ||
}; | ||
module.exports.get_command_arg = function(napi_build_version) { | ||
@@ -149,7 +192,7 @@ return napi_build_version_tag + napi_build_version; | ||
module.exports.get_best_napi_build_version = function(package_json) { | ||
module.exports.get_best_napi_build_version = function(package_json, opts) { | ||
var best_napi_build_version = 0; | ||
var napi_build_versions = module.exports.get_napi_build_versions (package_json); | ||
var napi_build_versions = module.exports.get_napi_build_versions (package_json, opts); | ||
if (napi_build_versions) { | ||
var our_napi_version = module.exports.get_napi_version(); | ||
var our_napi_version = module.exports.get_napi_version(opts ? opts.target : undefined); | ||
napi_build_versions.forEach(function(napi_build_version){ | ||
@@ -164,1 +207,6 @@ if (napi_build_version > best_napi_build_version && | ||
}; | ||
module.exports.build_napi_only = function(package_json) { | ||
return package_json.binary && package_json.binary.package_name && | ||
package_json.binary.package_name.indexOf('{node_napi_label}') === -1; | ||
}; |
@@ -195,3 +195,3 @@ "use strict"; | ||
function validate_config(package_json) { | ||
function validate_config(package_json,opts) { | ||
var msg = package_json.name + ' package.json is not node-pre-gyp ready:\n'; | ||
@@ -230,3 +230,3 @@ var missing = []; | ||
} | ||
napi.validate_package_json(package_json); | ||
napi.validate_package_json(package_json,opts); | ||
} | ||
@@ -281,3 +281,3 @@ | ||
options = options || {}; | ||
validate_config(package_json); | ||
validate_config(package_json,options); // options is a suitable substitute for opts in this case | ||
var v = package_json.version; | ||
@@ -299,5 +299,6 @@ var module_version = semver.parse(v); | ||
node_abi: get_runtime_abi(runtime,options.target), | ||
node_abi_napi: napi.get_napi_version() ? 'napi' : get_runtime_abi(runtime,options.target), | ||
napi_version: napi.get_napi_version(), // non-zero numeric, undefined if unsupported | ||
napi_build_version: napi_build_version, // undefined if not specified | ||
node_abi_napi: napi.get_napi_version(options.target) ? 'napi' : get_runtime_abi(runtime,options.target), | ||
napi_version: napi.get_napi_version(options.target), // non-zero numeric, undefined if unsupported | ||
napi_build_version: napi_build_version || '', | ||
node_napi_label: napi_build_version ? 'napi-v' + napi_build_version : get_runtime_abi(runtime,options.target), | ||
target: options.target || '', | ||
@@ -304,0 +305,0 @@ platform: options.target_platform || process.platform, |
{ | ||
"name": "node-pre-gyp", | ||
"description": "Node.js native addon binary install tool", | ||
"version": "0.10.3", | ||
"version": "0.11.0", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "native", |
@@ -128,3 +128,3 @@ # node-pre-gyp | ||
NOte: in the past we recommended putting `node-pre-gyp` in the `bundledDependencies`, but we no longer recommend this. In the past there were npm bugs (with node versions 0.10.x) that could lead to node-pre-gyp not being available at the right time during install (unless we bundled). This should no longer be the case. Also, for a time we recommended using `"preinstall": "npm install node-pre-gyp"` as an alternative method to avoid needing to bundle. But this did not behave predictably across all npm versions - see https://github.com/mapbox/node-pre-gyp/issues/260 for the details. So we do not recommend using `preinstall` to install `node-pre-gyp`. More history on this at https://github.com/strongloop/fsevents/issues/157#issuecomment-265545908. | ||
Note: in the past we recommended putting `node-pre-gyp` in the `bundledDependencies`, but we no longer recommend this. In the past there were npm bugs (with node versions 0.10.x) that could lead to node-pre-gyp not being available at the right time during install (unless we bundled). This should no longer be the case. Also, for a time we recommended using `"preinstall": "npm install node-pre-gyp"` as an alternative method to avoid needing to bundle. But this did not behave predictably across all npm versions - see https://github.com/mapbox/node-pre-gyp/issues/260 for the details. So we do not recommend using `preinstall` to install `node-pre-gyp`. More history on this at https://github.com/strongloop/fsevents/issues/157#issuecomment-265545908. | ||
@@ -320,3 +320,3 @@ ##### The `binary` object has three required properties | ||
### Defining `NAPI_BUILD_VERSION` for the C/C++ code | ||
### Defining `NAPI_VERSION` for the C/C++ code | ||
@@ -327,8 +327,10 @@ The `napi_build_version` value is communicated to the C/C++ code by adding this code to the `binding.gyp` file: | ||
"defines": [ | ||
"NAPI_BUILD_VERSION=<(napi_build_version)", | ||
"NAPI_VERSION=<(napi_build_version)", | ||
] | ||
``` | ||
This ensures that `NAPI_BUILD_VERSION`, an integer value, is declared appropriately to the C/C++ code for each build. | ||
This ensures that `NAPI_VERSION`, an integer value, is declared appropriately to the C/C++ code for each build. | ||
> Note that earlier versions of this document recommended defining the symbol `NAPI_BUILD_VERSION`. `NAPI_VERSION` is prefered because it used by the N-API C/C++ headers to configure the specific N-API veriosn being requested. | ||
### Path and file naming requirements in `package.json` | ||
@@ -338,3 +340,3 @@ | ||
Specifically, when performing N-API builds, the `{napi_build_version}` text substitution string *must* be present in the `module_path` property. In addition, the `{napi_build_version}` text substitution string *must* be present in either the `remote_path` or `package_name` property. (No problem if it's in both.) | ||
Specifically, when performing N-API builds, the `{napi_build_version}` text configuration value *must* be present in the `module_path` property. In addition, the `{napi_build_version}` text configuration value *must* be present in either the `remote_path` or `package_name` property. (No problem if it's in both.) | ||
@@ -354,5 +356,38 @@ Here's an example: | ||
## Supporting both N-API and NAN builds | ||
You may have a legacy native add-on that you wish to continue supporting for those versions of Node that do not support N-API, as you add N-API support for later Node versions. This can be accomplished by specifying the `node_napi_label` configuration value in the package.json `binary.package_name` property. | ||
Placing the configuration value `node_napi_label` in the package.json `binary.package_name` property instructs `node-pre-gyp` to build all viable N-API binaries supported by the current Node instance. If the current Node instance does not support N-API, `node-pre-gyp` will request a traditional, non-N-API build. | ||
The configuration value `node_napi_label` is set by `node-pre-gyp` to the type of build created, `napi` or `node`, and the version number. For N-API builds, the string contains the N-API version nad has values like `napi-v3`. For traditional, non-N-API builds, the string contains the ABI version with values like `node-v46`. | ||
Here's how the `binary` configuration above might be changed to support both N-API and NAN builds: | ||
```js | ||
"binary": { | ||
"module_name": "your_module", | ||
"module_path": "./lib/binding/{node_napi_label}", | ||
"remote_path": "./{module_name}/v{version}/{configuration}/", | ||
"package_name": "{platform}-{arch}-{node_napi_label}.tar.gz", | ||
"host": "https://your_bucket.s3-us-west-1.amazonaws.com", | ||
"napi_versions": [1,3] | ||
} | ||
``` | ||
The C/C++ symbol `NAPI_VERSION` can be used to distinguish N-API and non-N-API builds. The value of `NAPI_VERSION` is set to the integer N-API version for N-API builds and is set to `0` for non-N-API builds. | ||
For example: | ||
```C | ||
#if NAPI_VERSION | ||
// N-API code goes here | ||
#else | ||
// NAN code goes here | ||
#endif | ||
``` | ||
### Two additional configuration values | ||
For those who need them in legacy projects, two additional configuration values are available for all builds. | ||
The following two configuration values, which were implemented in previous versions of `node-pre-gyp`, continue to exist, but have been replaced by the `node_napi_label` configuration value described above. | ||
@@ -359,0 +394,0 @@ 1. `napi_version` If N-API is supported by the currently executing Node instance, this value is the N-API version number supported by Node. If N-API is not supported, this value is an empty string. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
145873
3393
694