mirror of
https://github.com/musix-org/musix-oss
synced 2025-06-17 10:46:01 +00:00
opus
This commit is contained in:
2070
node_modules/node-pre-gyp/lib/util/abi_crosswalk.json
generated
vendored
Normal file
2070
node_modules/node-pre-gyp/lib/util/abi_crosswalk.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
87
node_modules/node-pre-gyp/lib/util/compile.js
generated
vendored
Normal file
87
node_modules/node-pre-gyp/lib/util/compile.js
generated
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = exports;
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var win = process.platform == 'win32';
|
||||
var existsSync = fs.existsSync || path.existsSync;
|
||||
var cp = require('child_process');
|
||||
|
||||
// try to build up the complete path to node-gyp
|
||||
/* priority:
|
||||
- node-gyp on ENV:npm_config_node_gyp (https://github.com/npm/npm/pull/4887)
|
||||
- node-gyp on NODE_PATH
|
||||
- node-gyp inside npm on NODE_PATH (ignore on iojs)
|
||||
- node-gyp inside npm beside node exe
|
||||
*/
|
||||
function which_node_gyp() {
|
||||
var node_gyp_bin;
|
||||
if (process.env.npm_config_node_gyp) {
|
||||
try {
|
||||
node_gyp_bin = process.env.npm_config_node_gyp;
|
||||
if (existsSync(node_gyp_bin)) {
|
||||
return node_gyp_bin;
|
||||
}
|
||||
} catch (err) { }
|
||||
}
|
||||
try {
|
||||
var node_gyp_main = require.resolve('node-gyp');
|
||||
node_gyp_bin = path.join(path.dirname(
|
||||
path.dirname(node_gyp_main)),
|
||||
'bin/node-gyp.js');
|
||||
if (existsSync(node_gyp_bin)) {
|
||||
return node_gyp_bin;
|
||||
}
|
||||
} catch (err) { }
|
||||
if (process.execPath.indexOf('iojs') === -1) {
|
||||
try {
|
||||
var npm_main = require.resolve('npm');
|
||||
node_gyp_bin = path.join(path.dirname(
|
||||
path.dirname(npm_main)),
|
||||
'node_modules/node-gyp/bin/node-gyp.js');
|
||||
if (existsSync(node_gyp_bin)) {
|
||||
return node_gyp_bin;
|
||||
}
|
||||
} catch (err) { }
|
||||
}
|
||||
var npm_base = path.join(path.dirname(
|
||||
path.dirname(process.execPath)),
|
||||
'lib/node_modules/npm/');
|
||||
node_gyp_bin = path.join(npm_base, 'node_modules/node-gyp/bin/node-gyp.js');
|
||||
if (existsSync(node_gyp_bin)) {
|
||||
return node_gyp_bin;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.run_gyp = function(args,opts,callback) {
|
||||
var shell_cmd = '';
|
||||
var cmd_args = [];
|
||||
if (opts.runtime && opts.runtime == 'node-webkit') {
|
||||
shell_cmd = 'nw-gyp';
|
||||
if (win) shell_cmd += '.cmd';
|
||||
} else {
|
||||
var node_gyp_path = which_node_gyp();
|
||||
if (node_gyp_path) {
|
||||
shell_cmd = process.execPath;
|
||||
cmd_args.push(node_gyp_path);
|
||||
} else {
|
||||
shell_cmd = 'node-gyp';
|
||||
if (win) shell_cmd += '.cmd';
|
||||
}
|
||||
}
|
||||
var final_args = cmd_args.concat(args);
|
||||
var cmd = cp.spawn(shell_cmd, final_args, {cwd: undefined, env: process.env, stdio: [ 0, 1, 2]});
|
||||
cmd.on('error', function (err) {
|
||||
if (err) {
|
||||
return callback(new Error("Failed to execute '" + shell_cmd + ' ' + final_args.join(' ') + "' (" + err + ")"));
|
||||
}
|
||||
callback(null,opts);
|
||||
});
|
||||
cmd.on('close', function (code) {
|
||||
if (code && code !== 0) {
|
||||
return callback(new Error("Failed to execute '" + shell_cmd + ' ' + final_args.join(' ') + "' (" + code + ")"));
|
||||
}
|
||||
callback(null,opts);
|
||||
});
|
||||
};
|
103
node_modules/node-pre-gyp/lib/util/handle_gyp_opts.js
generated
vendored
Normal file
103
node_modules/node-pre-gyp/lib/util/handle_gyp_opts.js
generated
vendored
Normal file
@ -0,0 +1,103 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = exports = handle_gyp_opts;
|
||||
|
||||
var fs = require('fs');
|
||||
var versioning = require('./versioning.js');
|
||||
var napi = require('./napi.js');
|
||||
|
||||
/*
|
||||
|
||||
Here we gather node-pre-gyp generated options (from versioning) and pass them along to node-gyp.
|
||||
|
||||
We massage the args and options slightly to account for differences in what commands mean between
|
||||
node-pre-gyp and node-gyp (e.g. see the difference between "build" and "rebuild" below)
|
||||
|
||||
Keep in mind: the values inside `argv` and `gyp.opts` below are different depending on whether
|
||||
node-pre-gyp is called directory, or if it is called in a `run-script` phase of npm.
|
||||
|
||||
We also try to preserve any command line options that might have been passed to npm or node-pre-gyp.
|
||||
But this is fairly difficult without passing way to much through. For example `gyp.opts` contains all
|
||||
the process.env and npm pushes a lot of variables into process.env which node-pre-gyp inherits. So we have
|
||||
to be very selective about what we pass through.
|
||||
|
||||
For example:
|
||||
|
||||
`npm install --build-from-source` will give:
|
||||
|
||||
argv == [ 'rebuild' ]
|
||||
gyp.opts.argv == { remain: [ 'install' ],
|
||||
cooked: [ 'install', '--fallback-to-build' ],
|
||||
original: [ 'install', '--fallback-to-build' ] }
|
||||
|
||||
`./bin/node-pre-gyp build` will give:
|
||||
|
||||
argv == []
|
||||
gyp.opts.argv == { remain: [ 'build' ],
|
||||
cooked: [ 'build' ],
|
||||
original: [ '-C', 'test/app1', 'build' ] }
|
||||
|
||||
*/
|
||||
|
||||
// select set of node-pre-gyp versioning info
|
||||
// to share with node-gyp
|
||||
var share_with_node_gyp = [
|
||||
'module',
|
||||
'module_name',
|
||||
'module_path',
|
||||
'napi_version',
|
||||
'node_abi_napi',
|
||||
'napi_build_version',
|
||||
'node_napi_label'
|
||||
];
|
||||
|
||||
function handle_gyp_opts(gyp, argv, callback) {
|
||||
|
||||
// Collect node-pre-gyp specific variables to pass to node-gyp
|
||||
var node_pre_gyp_options = [];
|
||||
// generate custom node-pre-gyp versioning info
|
||||
var napi_build_version = napi.get_napi_build_version_from_command_args(argv);
|
||||
var opts = versioning.evaluate(JSON.parse(fs.readFileSync('./package.json')), gyp.opts, napi_build_version);
|
||||
share_with_node_gyp.forEach(function(key) {
|
||||
var val = opts[key];
|
||||
if (val) {
|
||||
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')
|
||||
return callback(new Error("Option " + key + " required but not found by node-pre-gyp"));
|
||||
}
|
||||
});
|
||||
|
||||
// Collect options that follow the special -- which disables nopt parsing
|
||||
var unparsed_options = [];
|
||||
var double_hyphen_found = false;
|
||||
gyp.opts.argv.original.forEach(function(opt) {
|
||||
if (double_hyphen_found) {
|
||||
unparsed_options.push(opt);
|
||||
}
|
||||
if (opt == '--') {
|
||||
double_hyphen_found = true;
|
||||
}
|
||||
});
|
||||
|
||||
// We try respect and pass through remaining command
|
||||
// line options (like --foo=bar) to node-gyp
|
||||
var cooked = gyp.opts.argv.cooked;
|
||||
var node_gyp_options = [];
|
||||
cooked.forEach(function(value) {
|
||||
if (value.length > 2 && value.slice(0,2) == '--') {
|
||||
var key = value.slice(2);
|
||||
var val = cooked[cooked.indexOf(value)+1];
|
||||
if (val && val.indexOf('--') === -1) { // handle '--foo=bar' or ['--foo','bar']
|
||||
node_gyp_options.push('--' + key + '=' + val);
|
||||
} else { // pass through --foo
|
||||
node_gyp_options.push(value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var result = {'opts':opts,'gyp':node_gyp_options,'pre':node_pre_gyp_options,'unparsed':unparsed_options};
|
||||
return callback(null,result);
|
||||
}
|
205
node_modules/node-pre-gyp/lib/util/napi.js
generated
vendored
Normal file
205
node_modules/node-pre-gyp/lib/util/napi.js
generated
vendored
Normal file
@ -0,0 +1,205 @@
|
||||
"use strict";
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
module.exports = exports;
|
||||
|
||||
var versionArray = process.version
|
||||
.substr(1)
|
||||
.replace(/-.*$/, '')
|
||||
.split('.')
|
||||
.map(function(item) {
|
||||
return +item;
|
||||
});
|
||||
|
||||
var napi_multiple_commands = [
|
||||
'build',
|
||||
'clean',
|
||||
'configure',
|
||||
'package',
|
||||
'publish',
|
||||
'reveal',
|
||||
'testbinary',
|
||||
'testpackage',
|
||||
'unpublish'
|
||||
];
|
||||
|
||||
var napi_build_version_tag = 'napi_build_version=';
|
||||
|
||||
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
|
||||
if (!version) { // this code should never need to be updated
|
||||
if (versionArray[0] === 9 && versionArray[1] >= 3) version = 2; // 9.3.0+
|
||||
else if (versionArray[0] === 8) version = 1; // 8.0.0+
|
||||
}
|
||||
return version;
|
||||
};
|
||||
|
||||
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(target);
|
||||
return version ? ''+version : '';
|
||||
};
|
||||
|
||||
module.exports.validate_package_json = function(package_json, opts) { // throws Error
|
||||
|
||||
var binary = package_json.binary;
|
||||
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);
|
||||
|
||||
if (napi_build_versions) {
|
||||
napi_build_versions.forEach(function(napi_build_version){
|
||||
if (!(parseInt(napi_build_version,10) === napi_build_version && napi_build_version > 0)) {
|
||||
throw new Error("All values specified in napi_versions must be positive integers.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (napi_build_versions && (!module_path_ok || (!remote_path_ok && !package_name_ok))) {
|
||||
throw new Error("When napi_versions is specified; module_path and either remote_path or " +
|
||||
"package_name must contain the substitution string '{napi_build_version}`.");
|
||||
}
|
||||
|
||||
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 " +
|
||||
"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, 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(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.');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
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, 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, 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.indexOf(command.name) !== -1) {
|
||||
napi_build_versions.forEach(function(napi_build_version){
|
||||
var args = command.args.slice();
|
||||
args.push (napi_build_version_tag+napi_build_version);
|
||||
expanded_commands.push ({ name: command.name, args: args });
|
||||
});
|
||||
} else {
|
||||
expanded_commands.push (command);
|
||||
}
|
||||
});
|
||||
return expanded_commands;
|
||||
};
|
||||
|
||||
module.exports.get_napi_build_versions = function(package_json, opts, warnings) { // opts may be undefined
|
||||
var log = require('npmlog');
|
||||
var napi_build_versions = [];
|
||||
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) {
|
||||
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) {
|
||||
return napi_build_version_tag + napi_build_version;
|
||||
};
|
||||
|
||||
module.exports.get_napi_build_version_from_command_args = function(command_args) {
|
||||
for (var i = 0; i < command_args.length; i++) {
|
||||
var arg = command_args[i];
|
||||
if (arg.indexOf(napi_build_version_tag) === 0) {
|
||||
return parseInt(arg.substr(napi_build_version_tag.length),10);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
module.exports.swap_build_dir_out = function(napi_build_version) {
|
||||
if (napi_build_version) {
|
||||
var rm = require('rimraf');
|
||||
rm.sync(module.exports.get_build_dir(napi_build_version));
|
||||
fs.renameSync('build', module.exports.get_build_dir(napi_build_version));
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.swap_build_dir_in = function(napi_build_version) {
|
||||
if (napi_build_version) {
|
||||
var rm = require('rimraf');
|
||||
rm.sync('build');
|
||||
fs.renameSync(module.exports.get_build_dir(napi_build_version), 'build');
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.get_build_dir = function(napi_build_version) {
|
||||
return 'build-tmp-napi-v'+napi_build_version;
|
||||
};
|
||||
|
||||
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, opts);
|
||||
if (napi_build_versions) {
|
||||
var our_napi_version = module.exports.get_napi_version(opts ? opts.target : undefined);
|
||||
napi_build_versions.forEach(function(napi_build_version){
|
||||
if (napi_build_version > best_napi_build_version &&
|
||||
napi_build_version <= our_napi_version) {
|
||||
best_napi_build_version = napi_build_version;
|
||||
}
|
||||
});
|
||||
}
|
||||
return best_napi_build_version === 0 ? undefined : 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;
|
||||
};
|
26
node_modules/node-pre-gyp/lib/util/nw-pre-gyp/index.html
generated
vendored
Normal file
26
node_modules/node-pre-gyp/lib/util/nw-pre-gyp/index.html
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Node-webkit-based module test</title>
|
||||
<script>
|
||||
function nwModuleTest(){
|
||||
var util = require('util');
|
||||
var moduleFolder = require('nw.gui').App.argv[0];
|
||||
try {
|
||||
require(moduleFolder);
|
||||
} catch(e) {
|
||||
if( process.platform !== 'win32' ){
|
||||
util.log('nw-pre-gyp error:');
|
||||
util.log(e.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
process.exit(0);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="nwModuleTest()">
|
||||
<h1>Node-webkit-based module test</h1>
|
||||
</body>
|
||||
</html>
|
9
node_modules/node-pre-gyp/lib/util/nw-pre-gyp/package.json
generated
vendored
Normal file
9
node_modules/node-pre-gyp/lib/util/nw-pre-gyp/package.json
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"main": "index.html",
|
||||
"name": "nw-pre-gyp-module-test",
|
||||
"description": "Node-webkit-based module test.",
|
||||
"version": "0.0.1",
|
||||
"window": {
|
||||
"show": false
|
||||
}
|
||||
}
|
27
node_modules/node-pre-gyp/lib/util/s3_setup.js
generated
vendored
Normal file
27
node_modules/node-pre-gyp/lib/util/s3_setup.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = exports;
|
||||
|
||||
var url = require('url');
|
||||
|
||||
var URI_REGEX="^(.*)\.(s3(?:-.*)?)\.amazonaws\.com$";
|
||||
|
||||
module.exports.detect = function(to,config) {
|
||||
var uri = url.parse(to);
|
||||
var hostname_matches = uri.hostname.match(URI_REGEX);
|
||||
config.prefix = (!uri.pathname || uri.pathname == '/') ? '' : uri.pathname.replace('/','');
|
||||
if(!hostname_matches) {
|
||||
return;
|
||||
}
|
||||
if (!config.bucket) {
|
||||
config.bucket = hostname_matches[1];
|
||||
}
|
||||
if (!config.region) {
|
||||
var s3_domain = hostname_matches[2];
|
||||
if (s3_domain.slice(0,3) == 's3-' &&
|
||||
s3_domain.length >= 3) {
|
||||
// it appears the region is explicit in the url
|
||||
config.region = s3_domain.replace('s3-','');
|
||||
}
|
||||
}
|
||||
};
|
331
node_modules/node-pre-gyp/lib/util/versioning.js
generated
vendored
Normal file
331
node_modules/node-pre-gyp/lib/util/versioning.js
generated
vendored
Normal file
@ -0,0 +1,331 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = exports;
|
||||
|
||||
var path = require('path');
|
||||
var semver = require('semver');
|
||||
var url = require('url');
|
||||
var detect_libc = require('detect-libc');
|
||||
var napi = require('./napi.js');
|
||||
|
||||
var abi_crosswalk;
|
||||
|
||||
// This is used for unit testing to provide a fake
|
||||
// ABI crosswalk that emulates one that is not updated
|
||||
// for the current version
|
||||
if (process.env.NODE_PRE_GYP_ABI_CROSSWALK) {
|
||||
abi_crosswalk = require(process.env.NODE_PRE_GYP_ABI_CROSSWALK);
|
||||
} else {
|
||||
abi_crosswalk = require('./abi_crosswalk.json');
|
||||
}
|
||||
|
||||
var major_versions = {};
|
||||
Object.keys(abi_crosswalk).forEach(function(v) {
|
||||
var major = v.split('.')[0];
|
||||
if (!major_versions[major]) {
|
||||
major_versions[major] = v;
|
||||
}
|
||||
});
|
||||
|
||||
function get_electron_abi(runtime, target_version) {
|
||||
if (!runtime) {
|
||||
throw new Error("get_electron_abi requires valid runtime arg");
|
||||
}
|
||||
if (typeof target_version === 'undefined') {
|
||||
// erroneous CLI call
|
||||
throw new Error("Empty target version is not supported if electron is the target.");
|
||||
}
|
||||
// Electron guarantees that patch version update won't break native modules.
|
||||
var sem_ver = semver.parse(target_version);
|
||||
return runtime + '-v' + sem_ver.major + '.' + sem_ver.minor;
|
||||
}
|
||||
module.exports.get_electron_abi = get_electron_abi;
|
||||
|
||||
function get_node_webkit_abi(runtime, target_version) {
|
||||
if (!runtime) {
|
||||
throw new Error("get_node_webkit_abi requires valid runtime arg");
|
||||
}
|
||||
if (typeof target_version === 'undefined') {
|
||||
// erroneous CLI call
|
||||
throw new Error("Empty target version is not supported if node-webkit is the target.");
|
||||
}
|
||||
return runtime + '-v' + target_version;
|
||||
}
|
||||
module.exports.get_node_webkit_abi = get_node_webkit_abi;
|
||||
|
||||
function get_node_abi(runtime, versions) {
|
||||
if (!runtime) {
|
||||
throw new Error("get_node_abi requires valid runtime arg");
|
||||
}
|
||||
if (!versions) {
|
||||
throw new Error("get_node_abi requires valid process.versions object");
|
||||
}
|
||||
var sem_ver = semver.parse(versions.node);
|
||||
if (sem_ver.major === 0 && sem_ver.minor % 2) { // odd series
|
||||
// https://github.com/mapbox/node-pre-gyp/issues/124
|
||||
return runtime+'-v'+versions.node;
|
||||
} else {
|
||||
// process.versions.modules added in >= v0.10.4 and v0.11.7
|
||||
// https://github.com/joyent/node/commit/ccabd4a6fa8a6eb79d29bc3bbe9fe2b6531c2d8e
|
||||
return versions.modules ? runtime+'-v' + (+versions.modules) :
|
||||
'v8-' + versions.v8.split('.').slice(0,2).join('.');
|
||||
}
|
||||
}
|
||||
module.exports.get_node_abi = get_node_abi;
|
||||
|
||||
function get_runtime_abi(runtime, target_version) {
|
||||
if (!runtime) {
|
||||
throw new Error("get_runtime_abi requires valid runtime arg");
|
||||
}
|
||||
if (runtime === 'node-webkit') {
|
||||
return get_node_webkit_abi(runtime, target_version || process.versions['node-webkit']);
|
||||
} else if (runtime === 'electron') {
|
||||
return get_electron_abi(runtime, target_version || process.versions.electron);
|
||||
} else {
|
||||
if (runtime != 'node') {
|
||||
throw new Error("Unknown Runtime: '" + runtime + "'");
|
||||
}
|
||||
if (!target_version) {
|
||||
return get_node_abi(runtime,process.versions);
|
||||
} else {
|
||||
var cross_obj;
|
||||
// abi_crosswalk generated with ./scripts/abi_crosswalk.js
|
||||
if (abi_crosswalk[target_version]) {
|
||||
cross_obj = abi_crosswalk[target_version];
|
||||
} else {
|
||||
var target_parts = target_version.split('.').map(function(i) { return +i; });
|
||||
if (target_parts.length != 3) { // parse failed
|
||||
throw new Error("Unknown target version: " + target_version);
|
||||
}
|
||||
/*
|
||||
The below code tries to infer the last known ABI compatible version
|
||||
that we have recorded in the abi_crosswalk.json when an exact match
|
||||
is not possible. The reasons for this to exist are complicated:
|
||||
|
||||
- We support passing --target to be able to allow developers to package binaries for versions of node
|
||||
that are not the same one as they are running. This might also be used in combination with the
|
||||
--target_arch or --target_platform flags to also package binaries for alternative platforms
|
||||
- When --target is passed we can't therefore determine the ABI (process.versions.modules) from the node
|
||||
version that is running in memory
|
||||
- So, therefore node-pre-gyp keeps an "ABI crosswalk" (lib/util/abi_crosswalk.json) to be able to look
|
||||
this info up for all versions
|
||||
- But we cannot easily predict what the future ABI will be for released versions
|
||||
- And node-pre-gyp needs to be a `bundledDependency` in apps that depend on it in order to work correctly
|
||||
by being fully available at install time.
|
||||
- So, the speed of node releases and the bundled nature of node-pre-gyp mean that a new node-pre-gyp release
|
||||
need to happen for every node.js/io.js/node-webkit/nw.js/atom-shell/etc release that might come online if
|
||||
you want the `--target` flag to keep working for the latest version
|
||||
- Which is impractical ^^
|
||||
- Hence the below code guesses about future ABI to make the need to update node-pre-gyp less demanding.
|
||||
|
||||
In practice then you can have a dependency of your app like `node-sqlite3` that bundles a `node-pre-gyp` that
|
||||
only knows about node v0.10.33 in the `abi_crosswalk.json` but target node v0.10.34 (which is assumed to be
|
||||
ABI compatible with v0.10.33).
|
||||
|
||||
TODO: use semver module instead of custom version parsing
|
||||
*/
|
||||
var major = target_parts[0];
|
||||
var minor = target_parts[1];
|
||||
var patch = target_parts[2];
|
||||
// io.js: yeah if node.js ever releases 1.x this will break
|
||||
// but that is unlikely to happen: https://github.com/iojs/io.js/pull/253#issuecomment-69432616
|
||||
if (major === 1) {
|
||||
// look for last release that is the same major version
|
||||
// e.g. we assume io.js 1.x is ABI compatible with >= 1.0.0
|
||||
while (true) {
|
||||
if (minor > 0) --minor;
|
||||
if (patch > 0) --patch;
|
||||
var new_iojs_target = '' + major + '.' + minor + '.' + patch;
|
||||
if (abi_crosswalk[new_iojs_target]) {
|
||||
cross_obj = abi_crosswalk[new_iojs_target];
|
||||
console.log('Warning: node-pre-gyp could not find exact match for ' + target_version);
|
||||
console.log('Warning: but node-pre-gyp successfully choose ' + new_iojs_target + ' as ABI compatible target');
|
||||
break;
|
||||
}
|
||||
if (minor === 0 && patch === 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (major >= 2) {
|
||||
// look for last release that is the same major version
|
||||
if (major_versions[major]) {
|
||||
cross_obj = abi_crosswalk[major_versions[major]];
|
||||
console.log('Warning: node-pre-gyp could not find exact match for ' + target_version);
|
||||
console.log('Warning: but node-pre-gyp successfully choose ' + major_versions[major] + ' as ABI compatible target');
|
||||
}
|
||||
} else if (major === 0) { // node.js
|
||||
if (target_parts[1] % 2 === 0) { // for stable/even node.js series
|
||||
// look for the last release that is the same minor release
|
||||
// e.g. we assume node 0.10.x is ABI compatible with >= 0.10.0
|
||||
while (--patch > 0) {
|
||||
var new_node_target = '' + major + '.' + minor + '.' + patch;
|
||||
if (abi_crosswalk[new_node_target]) {
|
||||
cross_obj = abi_crosswalk[new_node_target];
|
||||
console.log('Warning: node-pre-gyp could not find exact match for ' + target_version);
|
||||
console.log('Warning: but node-pre-gyp successfully choose ' + new_node_target + ' as ABI compatible target');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!cross_obj) {
|
||||
throw new Error("Unsupported target version: " + target_version);
|
||||
}
|
||||
// emulate process.versions
|
||||
var versions_obj = {
|
||||
node: target_version,
|
||||
v8: cross_obj.v8+'.0',
|
||||
// abi_crosswalk uses 1 for node versions lacking process.versions.modules
|
||||
// process.versions.modules added in >= v0.10.4 and v0.11.7
|
||||
modules: cross_obj.node_abi > 1 ? cross_obj.node_abi : undefined
|
||||
};
|
||||
return get_node_abi(runtime, versions_obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports.get_runtime_abi = get_runtime_abi;
|
||||
|
||||
var required_parameters = [
|
||||
'module_name',
|
||||
'module_path',
|
||||
'host'
|
||||
];
|
||||
|
||||
function validate_config(package_json,opts) {
|
||||
var msg = package_json.name + ' package.json is not node-pre-gyp ready:\n';
|
||||
var missing = [];
|
||||
if (!package_json.main) {
|
||||
missing.push('main');
|
||||
}
|
||||
if (!package_json.version) {
|
||||
missing.push('version');
|
||||
}
|
||||
if (!package_json.name) {
|
||||
missing.push('name');
|
||||
}
|
||||
if (!package_json.binary) {
|
||||
missing.push('binary');
|
||||
}
|
||||
var o = package_json.binary;
|
||||
required_parameters.forEach(function(p) {
|
||||
if (missing.indexOf('binary') > -1) {
|
||||
missing.pop('binary');
|
||||
}
|
||||
if (!o || o[p] === undefined || o[p] === "") {
|
||||
missing.push('binary.' + p);
|
||||
}
|
||||
});
|
||||
if (missing.length >= 1) {
|
||||
throw new Error(msg+"package.json must declare these properties: \n" + missing.join('\n'));
|
||||
}
|
||||
if (o) {
|
||||
// enforce https over http
|
||||
var protocol = url.parse(o.host).protocol;
|
||||
if (protocol === 'http:') {
|
||||
throw new Error("'host' protocol ("+protocol+") is invalid - only 'https:' is accepted");
|
||||
}
|
||||
}
|
||||
napi.validate_package_json(package_json,opts);
|
||||
}
|
||||
|
||||
module.exports.validate_config = validate_config;
|
||||
|
||||
function eval_template(template,opts) {
|
||||
Object.keys(opts).forEach(function(key) {
|
||||
var pattern = '{'+key+'}';
|
||||
while (template.indexOf(pattern) > -1) {
|
||||
template = template.replace(pattern,opts[key]);
|
||||
}
|
||||
});
|
||||
return template;
|
||||
}
|
||||
|
||||
// url.resolve needs single trailing slash
|
||||
// to behave correctly, otherwise a double slash
|
||||
// may end up in the url which breaks requests
|
||||
// and a lacking slash may not lead to proper joining
|
||||
function fix_slashes(pathname) {
|
||||
if (pathname.slice(-1) != '/') {
|
||||
return pathname + '/';
|
||||
}
|
||||
return pathname;
|
||||
}
|
||||
|
||||
// remove double slashes
|
||||
// note: path.normalize will not work because
|
||||
// it will convert forward to back slashes
|
||||
function drop_double_slashes(pathname) {
|
||||
return pathname.replace(/\/\//g,'/');
|
||||
}
|
||||
|
||||
function get_process_runtime(versions) {
|
||||
var runtime = 'node';
|
||||
if (versions['node-webkit']) {
|
||||
runtime = 'node-webkit';
|
||||
} else if (versions.electron) {
|
||||
runtime = 'electron';
|
||||
}
|
||||
return runtime;
|
||||
}
|
||||
|
||||
module.exports.get_process_runtime = get_process_runtime;
|
||||
|
||||
var default_package_name = '{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz';
|
||||
var default_remote_path = '';
|
||||
|
||||
module.exports.evaluate = function(package_json,options,napi_build_version) {
|
||||
options = options || {};
|
||||
validate_config(package_json,options); // options is a suitable substitute for opts in this case
|
||||
var v = package_json.version;
|
||||
var module_version = semver.parse(v);
|
||||
var runtime = options.runtime || get_process_runtime(process.versions);
|
||||
var opts = {
|
||||
name: package_json.name,
|
||||
configuration: Boolean(options.debug) ? 'Debug' : 'Release',
|
||||
debug: options.debug,
|
||||
module_name: package_json.binary.module_name,
|
||||
version: module_version.version,
|
||||
prerelease: module_version.prerelease.length ? module_version.prerelease.join('.') : '',
|
||||
build: module_version.build.length ? module_version.build.join('.') : '',
|
||||
major: module_version.major,
|
||||
minor: module_version.minor,
|
||||
patch: module_version.patch,
|
||||
runtime: runtime,
|
||||
node_abi: get_runtime_abi(runtime,options.target),
|
||||
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 || '',
|
||||
platform: options.target_platform || process.platform,
|
||||
target_platform: options.target_platform || process.platform,
|
||||
arch: options.target_arch || process.arch,
|
||||
target_arch: options.target_arch || process.arch,
|
||||
libc: options.target_libc || detect_libc.family || 'unknown',
|
||||
module_main: package_json.main,
|
||||
toolset : options.toolset || '' // address https://github.com/mapbox/node-pre-gyp/issues/119
|
||||
};
|
||||
// support host mirror with npm config `--{module_name}_binary_host_mirror`
|
||||
// e.g.: https://github.com/node-inspector/v8-profiler/blob/master/package.json#L25
|
||||
// > npm install v8-profiler --profiler_binary_host_mirror=https://npm.taobao.org/mirrors/node-inspector/
|
||||
var host = process.env['npm_config_' + opts.module_name + '_binary_host_mirror'] || package_json.binary.host;
|
||||
opts.host = fix_slashes(eval_template(host,opts));
|
||||
opts.module_path = eval_template(package_json.binary.module_path,opts);
|
||||
// now we resolve the module_path to ensure it is absolute so that binding.gyp variables work predictably
|
||||
if (options.module_root) {
|
||||
// resolve relative to known module root: works for pre-binding require
|
||||
opts.module_path = path.join(options.module_root,opts.module_path);
|
||||
} else {
|
||||
// resolve relative to current working directory: works for node-pre-gyp commands
|
||||
opts.module_path = path.resolve(opts.module_path);
|
||||
}
|
||||
opts.module = path.join(opts.module_path,opts.module_name + '.node');
|
||||
opts.remote_path = package_json.binary.remote_path ? drop_double_slashes(fix_slashes(eval_template(package_json.binary.remote_path,opts))) : default_remote_path;
|
||||
var package_name = package_json.binary.package_name ? package_json.binary.package_name : default_package_name;
|
||||
opts.package_name = eval_template(package_name,opts);
|
||||
opts.staged_tarball = path.join('build/stage',opts.remote_path,opts.package_name);
|
||||
opts.hosted_path = url.resolve(opts.host,opts.remote_path);
|
||||
opts.hosted_tarball = url.resolve(opts.hosted_path,opts.package_name);
|
||||
return opts;
|
||||
};
|
Reference in New Issue
Block a user