updated bundled node_modules

This commit is contained in:
Steve Gill
2017-09-05 11:04:12 -07:00
parent 2377aa7ac2
commit e7a972df77
73 changed files with 3553 additions and 915 deletions
+101 -94
View File
@@ -17,8 +17,6 @@
under the License.
*/
/* jshint sub:true, laxcomma:true, laxbreak:true */
/*
A class for holidng the information currently stored in plugin.xml
It should also be able to answer questions like whether the plugin
@@ -27,14 +25,12 @@ is compatible with a given engine version.
TODO (kamrik): refactor this to not use sync functions and return promises.
*/
var path = require('path');
var fs = require('fs');
var xml_helpers = require('../util/xml-helpers');
var CordovaError = require('../CordovaError/CordovaError');
var path = require('path')
, fs = require('fs')
, xml_helpers = require('../util/xml-helpers')
, CordovaError = require('../CordovaError/CordovaError')
;
function PluginInfo(dirname) {
function PluginInfo (dirname) {
var self = this;
// METHODS
@@ -45,15 +41,15 @@ function PluginInfo(dirname) {
// Used to require a variable to be specified via --variable when installing the plugin.
// returns { key : default | null}
self.getPreferences = getPreferences;
function getPreferences(platform) {
function getPreferences (platform) {
return _getTags(self._et, 'preference', platform, _parsePreference)
.reduce(function (preferences, pref) {
preferences[pref.preference] = pref.default;
return preferences;
}, {});
.reduce(function (preferences, pref) {
preferences[pref.preference] = pref.default;
return preferences;
}, {});
}
function _parsePreference(prefTag) {
function _parsePreference (prefTag) {
var name = prefTag.attrib.name.toUpperCase();
var def = prefTag.attrib.default || null;
return {preference: name, default: def};
@@ -61,16 +57,16 @@ function PluginInfo(dirname) {
// <asset>
self.getAssets = getAssets;
function getAssets(platform) {
function getAssets (platform) {
var assets = _getTags(self._et, 'asset', platform, _parseAsset);
return assets;
}
function _parseAsset(tag) {
function _parseAsset (tag) {
var src = tag.attrib.src;
var target = tag.attrib.target;
if ( !src || !target) {
if (!src || !target) {
var msg =
'Malformed <asset> tag. Both "src" and "target" attributes'
+ 'must be specified in\n'
@@ -87,7 +83,6 @@ function PluginInfo(dirname) {
return asset;
}
// <dependency>
// Example:
// <dependency id="com.plugin.id"
@@ -95,28 +90,28 @@ function PluginInfo(dirname) {
// commit="428931ada3891801"
// subdir="some/path/here" />
self.getDependencies = getDependencies;
function getDependencies(platform) {
function getDependencies (platform) {
var deps = _getTags(
self._et,
'dependency',
platform,
_parseDependency
self._et,
'dependency',
platform,
_parseDependency
);
return deps;
}
function _parseDependency(tag) {
function _parseDependency (tag) {
var dep =
{ id : tag.attrib.id
, version: tag.attrib.version || ''
, url : tag.attrib.url || ''
, subdir : tag.attrib.subdir || ''
, commit : tag.attrib.commit
{ id: tag.attrib.id,
version: tag.attrib.version || '',
url: tag.attrib.url || '',
subdir: tag.attrib.subdir || '',
commit: tag.attrib.commit
};
dep.git_ref = dep.commit;
if ( !dep.id ) {
if (!dep.id) {
var msg =
'<dependency> tag is missing id attribute in '
+ self.filepath
@@ -126,52 +121,51 @@ function PluginInfo(dirname) {
return dep;
}
// <config-file> tag
self.getConfigFiles = getConfigFiles;
function getConfigFiles(platform) {
function getConfigFiles (platform) {
var configFiles = _getTags(self._et, 'config-file', platform, _parseConfigFile);
return configFiles;
}
function _parseConfigFile(tag) {
function _parseConfigFile (tag) {
var configFile =
{ target : tag.attrib['target']
, parent : tag.attrib['parent']
, after : tag.attrib['after']
, xmls : tag.getchildren()
// To support demuxing via versions
, versions : tag.attrib['versions']
, deviceTarget: tag.attrib['device-target']
{ target: tag.attrib['target'],
parent: tag.attrib['parent'],
after: tag.attrib['after'],
xmls: tag.getchildren(),
// To support demuxing via versions
versions: tag.attrib['versions'],
deviceTarget: tag.attrib['device-target']
};
return configFile;
}
self.getEditConfigs = getEditConfigs;
function getEditConfigs(platform) {
function getEditConfigs (platform) {
var editConfigs = _getTags(self._et, 'edit-config', platform, _parseEditConfigs);
return editConfigs;
}
function _parseEditConfigs(tag) {
function _parseEditConfigs (tag) {
var editConfig =
{ file : tag.attrib['file']
, target : tag.attrib['target']
, mode : tag.attrib['mode']
, xmls : tag.getchildren()
};
{ file: tag.attrib['file'],
target: tag.attrib['target'],
mode: tag.attrib['mode'],
xmls: tag.getchildren()
};
return editConfig;
}
// <info> tags, both global and within a <platform>
// TODO (kamrik): Do we ever use <info> under <platform>? Example wanted.
self.getInfo = getInfo;
function getInfo(platform) {
function getInfo (platform) {
var infos = _getTags(
self._et,
'info',
platform,
function(elem) { return elem.text; }
self._et,
'info',
platform,
function (elem) { return elem.text; }
);
// Filter out any undefined or empty strings.
infos = infos.filter(Boolean);
@@ -183,12 +177,12 @@ function PluginInfo(dirname) {
// <source-file src="src/ios/someLib.a" framework="true" />
// <source-file src="src/ios/someLib.a" compiler-flags="-fno-objc-arc" />
self.getSourceFiles = getSourceFiles;
function getSourceFiles(platform) {
function getSourceFiles (platform) {
var sourceFiles = _getTagsInPlatform(self._et, 'source-file', platform, _parseSourceFile);
return sourceFiles;
}
function _parseSourceFile(tag) {
function _parseSourceFile (tag) {
return {
itemType: 'source-file',
src: tag.attrib.src,
@@ -203,8 +197,8 @@ function PluginInfo(dirname) {
// Example:
// <header-file src="CDVFoo.h" />
self.getHeaderFiles = getHeaderFiles;
function getHeaderFiles(platform) {
var headerFiles = _getTagsInPlatform(self._et, 'header-file', platform, function(tag) {
function getHeaderFiles (platform) {
var headerFiles = _getTagsInPlatform(self._et, 'header-file', platform, function (tag) {
return {
itemType: 'header-file',
src: tag.attrib.src,
@@ -218,8 +212,8 @@ function PluginInfo(dirname) {
// Example:
// <resource-file src="FooPluginStrings.xml" target="res/values/FooPluginStrings.xml" device-target="win" arch="x86" versions="&gt;=8.1" />
self.getResourceFiles = getResourceFiles;
function getResourceFiles(platform) {
var resourceFiles = _getTagsInPlatform(self._et, 'resource-file', platform, function(tag) {
function getResourceFiles (platform) {
var resourceFiles = _getTagsInPlatform(self._et, 'resource-file', platform, function (tag) {
return {
itemType: 'resource-file',
src: tag.attrib.src,
@@ -237,8 +231,8 @@ function PluginInfo(dirname) {
// Example:
// <lib-file src="src/BlackBerry10/native/device/libfoo.so" arch="device" />
self.getLibFiles = getLibFiles;
function getLibFiles(platform) {
var libFiles = _getTagsInPlatform(self._et, 'lib-file', platform, function(tag) {
function getLibFiles (platform) {
var libFiles = _getTagsInPlatform(self._et, 'lib-file', platform, function (tag) {
return {
itemType: 'lib-file',
src: tag.attrib.src,
@@ -255,16 +249,16 @@ function PluginInfo(dirname) {
// Example:
// <hook type="before_build" src="scripts/beforeBuild.js" />
self.getHookScripts = getHookScripts;
function getHookScripts(hook, platforms) {
var scriptElements = self._et.findall('./hook');
function getHookScripts (hook, platforms) {
var scriptElements = self._et.findall('./hook');
if(platforms) {
if (platforms) {
platforms.forEach(function (platform) {
scriptElements = scriptElements.concat(self._et.findall('./platform[@name="' + platform + '"]/hook'));
});
}
function filterScriptByHookType(el) {
function filterScriptByHookType (el) {
return el.attrib.src && el.attrib.type && el.attrib.type.toLowerCase() === hook;
}
@@ -272,26 +266,26 @@ function PluginInfo(dirname) {
}
self.getJsModules = getJsModules;
function getJsModules(platform) {
function getJsModules (platform) {
var modules = _getTags(self._et, 'js-module', platform, _parseJsModule);
return modules;
}
function _parseJsModule(tag) {
function _parseJsModule (tag) {
var ret = {
itemType: 'js-module',
name: tag.attrib.name,
src: tag.attrib.src,
clobbers: tag.findall('clobbers').map(function(tag) { return { target: tag.attrib.target }; }),
merges: tag.findall('merges').map(function(tag) { return { target: tag.attrib.target }; }),
clobbers: tag.findall('clobbers').map(function (tag) { return { target: tag.attrib.target }; }),
merges: tag.findall('merges').map(function (tag) { return { target: tag.attrib.target }; }),
runs: tag.findall('runs').length > 0
};
return ret;
}
self.getEngines = function() {
return self._et.findall('engines/engine').map(function(n) {
self.getEngines = function () {
return self._et.findall('engines/engine').map(function (n) {
return {
name: n.attrib.name,
version: n.attrib.version,
@@ -301,26 +295,40 @@ function PluginInfo(dirname) {
});
};
self.getPlatforms = function() {
return self._et.findall('platform').map(function(n) {
self.getPlatforms = function () {
return self._et.findall('platform').map(function (n) {
return { name: n.attrib.name };
});
};
self.getPlatformsArray = function() {
return self._et.findall('platform').map(function(n) {
self.getPlatformsArray = function () {
return self._et.findall('platform').map(function (n) {
return n.attrib.name;
});
};
self.getFrameworks = function(platform) {
return _getTags(self._et, 'framework', platform, function(el) {
self.getFrameworks = function (platform, options) {
return _getTags(self._et, 'framework', platform, function (el) {
var src = el.attrib.src;
if (options) {
var vars = options.cli_variables || {};
var regExp;
// Iterate over plugin variables.
// Replace them in framework src if they exist
Object.keys(vars).forEach(function (name) {
if (vars[name]) {
regExp = new RegExp('\\$' + name, 'g');
src = src.replace(regExp, vars[name]);
}
});
}
var ret = {
itemType: 'framework',
type: el.attrib.type,
parent: el.attrib.parent,
custom: isStrTrue(el.attrib.custom),
embed: isStrTrue(el.attrib.embed),
src: el.attrib.src,
src: src,
spec: el.attrib.spec,
weak: isStrTrue(el.attrib.weak),
versions: el.attrib.versions,
@@ -334,22 +342,21 @@ function PluginInfo(dirname) {
};
self.getFilesAndFrameworks = getFilesAndFrameworks;
function getFilesAndFrameworks(platform) {
function getFilesAndFrameworks (platform, options) {
// Please avoid changing the order of the calls below, files will be
// installed in this order.
var items = [].concat(
self.getSourceFiles(platform),
self.getHeaderFiles(platform),
self.getResourceFiles(platform),
self.getFrameworks(platform),
self.getFrameworks(platform, options),
self.getLibFiles(platform)
);
return items;
}
///// End of PluginInfo methods /////
/// // End of PluginInfo methods /////
///// PluginInfo Constructor logic /////
/// // PluginInfo Constructor logic /////
self.filepath = path.join(dirname, 'plugin.xml');
if (!fs.existsSync(self.filepath)) {
throw new CordovaError('Cannot find plugin.xml for plugin "' + path.basename(dirname) + '". Please try adding it again.');
@@ -370,18 +377,18 @@ function PluginInfo(dirname) {
self.keywords = pelem.findtext('keywords');
self.info = pelem.findtext('info');
if (self.keywords) {
self.keywords = self.keywords.split(',').map( function(s) { return s.trim(); } );
self.keywords = self.keywords.split(',').map(function (s) { return s.trim(); });
}
self.getKeywordsAndPlatforms = function () {
var ret = self.keywords || [];
return ret.concat('ecosystem:cordova').concat(addCordova(self.getPlatformsArray()));
};
} // End of PluginInfo constructor.
} // End of PluginInfo constructor.
// Helper function used to prefix every element of an array with cordova-
// Useful when we want to modify platforms to be cordova-platform
function addCordova(someArray) {
var newArray = someArray.map(function(element) {
function addCordova (someArray) {
var newArray = someArray.map(function (element) {
return 'cordova-' + element;
});
return newArray;
@@ -391,37 +398,37 @@ function addCordova(someArray) {
// Get all elements of a given name. Both in root and in platform sections
// for the given platform. If transform is given and is a function, it is
// applied to each element.
function _getTags(pelem, tag, platform, transform) {
function _getTags (pelem, tag, platform, transform) {
var platformTag = pelem.find('./platform[@name="' + platform + '"]');
var tagsInRoot = pelem.findall(tag);
tagsInRoot = tagsInRoot || [];
var tagsInPlatform = platformTag ? platformTag.findall(tag) : [];
var tags = tagsInRoot.concat(tagsInPlatform);
if ( typeof transform === 'function' ) {
if (typeof transform === 'function') {
tags = tags.map(transform);
}
return tags;
}
// Same as _getTags() but only looks inside a platform section.
function _getTagsInPlatform(pelem, tag, platform, transform) {
function _getTagsInPlatform (pelem, tag, platform, transform) {
var platformTag = pelem.find('./platform[@name="' + platform + '"]');
var tags = platformTag ? platformTag.findall(tag) : [];
if ( typeof transform === 'function' ) {
if (typeof transform === 'function') {
tags = tags.map(transform);
}
return tags;
}
// Check if x is a string 'true'.
function isStrTrue(x) {
return String(x).toLowerCase() == 'true';
function isStrTrue (x) {
return String(x).toLowerCase() === 'true';
}
module.exports = PluginInfo;
// Backwards compat:
PluginInfo.PluginInfo = PluginInfo;
PluginInfo.loadPluginsDir = function(dir) {
PluginInfo.loadPluginsDir = function (dir) {
var PluginInfoProvider = require('./PluginInfoProvider');
return new PluginInfoProvider().getAllWithinSearchPath(dir);
};
+7 -7
View File
@@ -24,12 +24,12 @@ var path = require('path');
var PluginInfo = require('./PluginInfo');
var events = require('../events');
function PluginInfoProvider() {
function PluginInfoProvider () {
this._cache = {};
this._getAllCache = {};
}
PluginInfoProvider.prototype.get = function(dirName) {
PluginInfoProvider.prototype.get = function (dirName) {
var absPath = path.resolve(dirName);
if (!this._cache[absPath]) {
this._cache[absPath] = new PluginInfo(dirName);
@@ -39,7 +39,7 @@ PluginInfoProvider.prototype.get = function(dirName) {
// Normally you don't need to put() entries, but it's used
// when copying plugins, and in unit tests.
PluginInfoProvider.prototype.put = function(pluginInfo) {
PluginInfoProvider.prototype.put = function (pluginInfo) {
var absPath = path.resolve(pluginInfo.dir);
this._cache[absPath] = pluginInfo;
};
@@ -48,7 +48,7 @@ PluginInfoProvider.prototype.put = function(pluginInfo) {
// Given a dir containing multiple plugins, create a PluginInfo object for
// each of them and return as array.
// Should load them all in parallel and return a promise, but not yet.
PluginInfoProvider.prototype.getAllWithinSearchPath = function(dirName) {
PluginInfoProvider.prototype.getAllWithinSearchPath = function (dirName) {
var absPath = path.resolve(dirName);
if (!this._getAllCache[absPath]) {
this._getAllCache[absPath] = getAllHelper(absPath, this);
@@ -56,8 +56,8 @@ PluginInfoProvider.prototype.getAllWithinSearchPath = function(dirName) {
return this._getAllCache[absPath];
};
function getAllHelper(absPath, provider) {
if (!fs.existsSync(absPath)){
function getAllHelper (absPath, provider) {
if (!fs.existsSync(absPath)) {
return [];
}
// If dir itself is a plugin, return it in an array with one element.
@@ -66,7 +66,7 @@ function getAllHelper(absPath, provider) {
}
var subdirs = fs.readdirSync(absPath);
var plugins = [];
subdirs.forEach(function(subdir) {
subdirs.forEach(function (subdir) {
var d = path.join(absPath, subdir);
if (fs.existsSync(path.join(d, 'plugin.xml'))) {
try {