CB-12003 updated node_modules

This commit is contained in:
Steve Gill
2016-10-17 10:50:30 -07:00
parent 2e37d2c253
commit 0b710a86a9
36 changed files with 602 additions and 299 deletions
+136 -15
View File
@@ -148,6 +148,11 @@ function add_plugin_changes(pluginInfo, plugin_vars, is_top_level, should_increm
}
else {
var isConflictingInfo = is_conflicting(edit_config_changes, platform_config.config_munge, self, plugin_force);
if (isConflictingInfo.conflictWithConfigxml) {
throw new Error(pluginInfo.id +
' cannot be added. <edit-config> changes in this plugin conflicts with <edit-config> changes in config.xml. Conflicts must be resolved before plugin can be added.');
}
if (plugin_force) {
CordovaLogger.get().log(CordovaLogger.WARN, '--force is used. edit-config will overwrite conflicts if any. Conflicting plugins may not work as expected.');
@@ -170,7 +175,67 @@ function add_plugin_changes(pluginInfo, plugin_vars, is_top_level, should_increm
config_munge = self.generate_plugin_config_munge(pluginInfo, plugin_vars, edit_config_changes);
}
}
// global munge looks at all plugins' changes to config files
self = munge_helper(should_increment, self, platform_config, config_munge);
// Move to installed/dependent_plugins
self.platformJson.addPlugin(pluginInfo.id, plugin_vars || {}, is_top_level);
return self;
}
// Handle edit-config changes from config.xml
PlatformMunger.prototype.add_config_changes = add_config_changes;
function add_config_changes(config, should_increment) {
var self = this;
var platform_config = self.platformJson.root;
var config_munge;
var edit_config_changes = null;
if(config.getEditConfigs) {
edit_config_changes = config.getEditConfigs(self.platform);
}
if (!edit_config_changes || edit_config_changes.length === 0) {
// There are no edit-config changes to add, return here
return self;
}
else {
var isConflictingInfo = is_conflicting(edit_config_changes, platform_config.config_munge, self, true /*always force overwrite other edit-config*/);
if(isConflictingInfo.conflictFound) {
var conflict_munge;
var conflict_file;
if (Object.keys(isConflictingInfo.configxmlMunge.files).length !== 0) {
// silently remove conflicting config.xml munges so new munges can be added
conflict_munge = mungeutil.decrement_munge(platform_config.config_munge, isConflictingInfo.configxmlMunge);
for (conflict_file in conflict_munge.files) {
self.apply_file_munge(conflict_file, conflict_munge.files[conflict_file], /* remove = */ true);
}
}
if (Object.keys(isConflictingInfo.conflictingMunge.files).length !== 0) {
CordovaLogger.get().log(CordovaLogger.WARN, 'Conflict found, edit-config changes from config.xml will overwrite plugin.xml changes');
// remove conflicting plugin.xml munges
conflict_munge = mungeutil.decrement_munge(platform_config.config_munge, isConflictingInfo.conflictingMunge);
for (conflict_file in conflict_munge.files) {
self.apply_file_munge(conflict_file, conflict_munge.files[conflict_file], /* remove = */ true);
}
}
}
// Add config.xml edit-config munges
config_munge = self.generate_config_xml_munge(config, edit_config_changes, 'config.xml');
}
self = munge_helper(should_increment, self, platform_config, config_munge);
// Move to installed/dependent_plugins
return self;
}
function munge_helper(should_increment, self, platform_config, config_munge) {
// global munge looks at all changes to config files
// TODO: The should_increment param is only used by cordova-cli and is going away soon.
// If should_increment is set to false, avoid modifying the global_munge (use clone)
@@ -196,11 +261,10 @@ function add_plugin_changes(pluginInfo, plugin_vars, is_top_level, should_increm
});
/* jshint loopfunc:false */
}
self.apply_file_munge(file, munge.files[file]);
}
// Move to installed/dependent_plugins
self.platformJson.addPlugin(pluginInfo.id, plugin_vars || {}, is_top_level);
return self;
}
@@ -221,6 +285,39 @@ function reapply_global_munge () {
return self;
}
// generate_plugin_config_munge
// Generate the munge object from config.xml
PlatformMunger.prototype.generate_config_xml_munge = generate_config_xml_munge;
function generate_config_xml_munge(config, edit_config_changes, type) {
var munge = { files: {} };
var changes = edit_config_changes;
var id;
if(!changes) {
return munge;
}
if (type === 'config.xml') {
id = type;
}
else {
id = config.id;
}
changes.forEach(function(change) {
change.xmls.forEach(function(xml) {
// 1. stringify each xml
var stringified = (new et.ElementTree(xml)).write({xml_declaration:false});
// 2. add into munge
if (change.mode) {
mungeutil.deep_add(munge, change.file, change.target, { xml: stringified, count: 1, mode: change.mode, id: id });
}
});
});
return munge;
}
// generate_plugin_config_munge
// Generate the munge object from plugin.xml + vars
@@ -335,7 +432,9 @@ function generate_plugin_config_munge(pluginInfo, vars, edit_config_changes) {
}
// 2. add into munge
if (change.mode) {
mungeutil.deep_add(munge, change.file, change.target, { xml: stringified, count: 1, mode: change.mode, plugin: pluginInfo.id });
if (change.mode !== 'remove') {
mungeutil.deep_add(munge, change.file, change.target, { xml: stringified, count: 1, mode: change.mode, plugin: pluginInfo.id });
}
}
else {
mungeutil.deep_add(munge, change.target, change.parent, { xml: stringified, count: 1, after: change.after });
@@ -348,7 +447,9 @@ function generate_plugin_config_munge(pluginInfo, vars, edit_config_changes) {
function is_conflicting(editchanges, config_munge, self, force) {
var files = config_munge.files;
var conflictFound = false;
var conflictWithConfigxml = false;
var conflictingMunge = { files: {} };
var configxmlMunge = { files: {} };
var conflictingParent;
var conflictingPlugin;
@@ -378,23 +479,43 @@ function is_conflicting(editchanges, config_munge, self, force) {
conflictingParent = editchange.target;
}
if (target.length !== 0) {
// conflict has been found, exit and throw an error
if (target && target.length !== 0) {
// conflict has been found
conflictFound = true;
if (!force) {
// since there has been modifications to the attributes at this target,
// the current plugin should not modify the attributes
conflictingPlugin = target[0].plugin;
return;
}
// need to find all conflicts when --force is used, track conflicting munges
mungeutil.deep_add(conflictingMunge, editchange.file, conflictingParent, target[0]);
if (editchange.id === 'config.xml') {
if (target[0].id === 'config.xml') {
// Keep track of config.xml/config.xml edit-config conflicts
mungeutil.deep_add(configxmlMunge, editchange.file, conflictingParent, target[0]);
}
else {
// Keep track of config.xml x plugin.xml edit-config conflicts
mungeutil.deep_add(conflictingMunge, editchange.file, conflictingParent, target[0]);
}
}
else {
if (target[0].id === 'config.xml') {
// plugin.xml cannot overwrite config.xml changes even if --force is used
conflictWithConfigxml = true;
return;
}
if (force) {
// Need to find all conflicts when --force is used, track conflicting munges
mungeutil.deep_add(conflictingMunge, editchange.file, conflictingParent, target[0]);
}
else {
// plugin cannot overwrite other plugin changes without --force
conflictingPlugin = target[0].plugin;
return;
}
}
}
}
});
return {conflictFound: conflictFound, conflictingPlugin: conflictingPlugin, conflictingMunge: conflictingMunge};
return {conflictFound: conflictFound, conflictingPlugin: conflictingPlugin, conflictingMunge: conflictingMunge,
configxmlMunge: configxmlMunge, conflictWithConfigxml:conflictWithConfigxml};
}
// Go over the prepare queue and apply the config munges for each plugin
+12
View File
@@ -110,6 +110,9 @@ ConfigFile.prototype.graft_child = function ConfigFile_graft_child(selector, xml
case 'overwrite':
result = modules.xml_helpers.graftXMLOverwrite(self.data, xml_to_graft, selector, xml_child);
break;
case 'remove':
result= true;
break;
default:
result = modules.xml_helpers.graftXML(self.data, xml_to_graft, selector, xml_child.after);
}
@@ -137,6 +140,9 @@ ConfigFile.prototype.prune_child = function ConfigFile_prune_child(selector, xml
case 'overwrite':
result = modules.xml_helpers.pruneXMLRestore(self.data, selector, xml_child);
break;
case 'remove':
result = modules.xml_helpers.prunXMLRemove(self.data, selector, xml_to_graft);
break;
default:
result = modules.xml_helpers.pruneXML(self.data, xml_to_graft, selector);
}
@@ -193,6 +199,12 @@ function resolveConfigFilePath(project_dir, platform, file) {
return filepath;
}
// XXX this checks for android studio projects
// only if none of the options above are satisfied does this get called
if(platform === 'android' && !fs.existsSync(filepath)) {
filepath = path.join(project_dir, 'app', 'src', 'main', 'res', 'xml', 'config.xml');
}
// None of the special cases matched, returning project_dir/file.
return filepath;
}
+42 -2
View File
@@ -448,10 +448,19 @@ ConfigParser.prototype = {
return accesses.map(function(access){
var minimum_tls_version = access.attrib['minimum-tls-version']; /* String */
var requires_forward_secrecy = access.attrib['requires-forward-secrecy']; /* Boolean */
var requires_certificate_transparency = access.attrib['requires-certificate-transparency']; /* Boolean */
var allows_arbitrary_loads_in_web_content = access.attrib['allows-arbitrary-loads-in-web-content']; /* Boolean */
var allows_arbitrary_loads_in_media = access.attrib['allows-arbitrary-loads-in-media']; /* Boolean */
var allows_local_networking = access.attrib['allows-local-networking']; /* Boolean */
return {
'origin': access.attrib.origin,
'minimum_tls_version': minimum_tls_version,
'requires_forward_secrecy' : requires_forward_secrecy
'requires_forward_secrecy' : requires_forward_secrecy,
'requires_certificate_transparency' : requires_certificate_transparency,
'allows_arbitrary_loads_in_web_content' : allows_arbitrary_loads_in_web_content,
'allows_arbitrary_loads_in_media' : allows_arbitrary_loads_in_media,
'allows_local_networking' : allows_local_networking
};
});
},
@@ -461,13 +470,44 @@ ConfigParser.prototype = {
return allow_navigations.map(function(allow_navigation){
var minimum_tls_version = allow_navigation.attrib['minimum-tls-version']; /* String */
var requires_forward_secrecy = allow_navigation.attrib['requires-forward-secrecy']; /* Boolean */
var requires_certificate_transparency = allow_navigation.attrib['requires-certificate-transparency']; /* Boolean */
return {
'href': allow_navigation.attrib.href,
'minimum_tls_version': minimum_tls_version,
'requires_forward_secrecy' : requires_forward_secrecy
'requires_forward_secrecy' : requires_forward_secrecy,
'requires_certificate_transparency' : requires_certificate_transparency
};
});
},
/* Get all the allow-intent tags */
getAllowIntents: function() {
var allow_intents = this.doc.findall('./allow-intent');
return allow_intents.map(function(allow_intent){
return {
'href': allow_intent.attrib.href
};
});
},
/* Get all edit-config tags */
getEditConfigs: function(platform) {
var platform_tag = this.doc.find('./platform[@name="' + platform + '"]');
var platform_edit_configs = platform_tag ? platform_tag.findall('edit-config') : [];
var edit_configs = this.doc.findall('edit-config').concat(platform_edit_configs);
return edit_configs.map(function(tag) {
var editConfig =
{
file : tag.attrib['file'],
target : tag.attrib['target'],
mode : tag.attrib['mode'],
id : 'config.xml',
xmls : tag.getchildren()
};
return editConfig;
});
},
write:function() {
fs.writeFileSync(this.path, this.doc.write({indent: 4}), 'utf-8');
}
+38 -44
View File
@@ -285,14 +285,14 @@ function mergeAndUpdateDir(sourceDirs, targetDir, options, log) {
}
// Scan the files in each of the source directories.
var sourceMaps = [];
for (var i in sourceDirs) {
var sourceFullPath = path.join(rootDir, sourceDirs[i]);
if (!fs.existsSync(sourceFullPath)) {
throw new Error("Source directory does not exist: " + sourceDirs[i]);
}
sourceMaps[i] = mapDirectory(rootDir, sourceDirs[i], include, exclude);
}
var sourceMaps = sourceDirs.map(function (sourceDir) {
return path.join(rootDir, sourceDir);
}).map(function (sourcePath) {
if (!fs.existsSync(sourcePath)) {
throw new Error("Source directory does not exist: " + sourcePath);
}
return mapDirectory(rootDir, path.relative(rootDir, sourcePath), include, exclude);
});
// Scan the files in the target directory, if it exists.
var targetMap = {};
@@ -331,46 +331,40 @@ function mapDirectory(rootDir, subDir, include, exclude) {
function mapSubdirectory(rootDir, subDir, relativeDir, include, exclude, dirMap) {
var itemMapped = false;
var items = fs.readdirSync(path.join(rootDir, subDir, relativeDir));
for (var i in items) {
var relativePath = path.join(relativeDir, items[i]);
// Skip any files or directories (and everything under) that match an exclude glob.
if (matchGlobArray(relativePath, exclude)) {
continue;
}
items.forEach(function(item) {
var relativePath = path.join(relativeDir, item);
if(!matchGlobArray(relativePath, exclude)) {
// Stats obtained here (required at least to know where to recurse in directories)
// are saved for later, where the modified times may also be used. This minimizes
// the number of file I/O operations performed.
var fullPath = path.join(rootDir, subDir, relativePath);
var stats = fs.statSync(fullPath);
// Stats obtained here (required at least to know where to recurse in directories)
// are saved for later, where the modified times may also be used. This minimizes
// the number of file I/O operations performed.
var fullPath = path.join(rootDir, subDir, relativePath);
var stats = fs.statSync(fullPath);
if (stats.isDirectory()) {
// Directories are included if either something under them is included or they
// match an include glob.
if (mapSubdirectory(rootDir, subDir, relativePath, include, exclude, dirMap) ||
matchGlobArray(relativePath, include)) {
dirMap[relativePath] = { subDir: subDir, stats: stats };
itemMapped = true;
}
} else if (stats.isFile()) {
// Files are included only if they match an include glob.
if (matchGlobArray(relativePath, include)) {
dirMap[relativePath] = { subDir: subDir, stats: stats };
itemMapped = true;
if (stats.isDirectory()) {
// Directories are included if either something under them is included or they
// match an include glob.
if (mapSubdirectory(rootDir, subDir, relativePath, include, exclude, dirMap) ||
matchGlobArray(relativePath, include)) {
dirMap[relativePath] = { subDir: subDir, stats: stats };
itemMapped = true;
}
} else if (stats.isFile()) {
// Files are included only if they match an include glob.
if (matchGlobArray(relativePath, include)) {
dirMap[relativePath] = { subDir: subDir, stats: stats };
itemMapped = true;
}
}
}
}
});
return itemMapped;
}
function matchGlobArray(path, globs) {
for (var i in globs) {
if (minimatch(path, globs[i])) {
return true;
}
}
return false;
return globs.some(function(elem) {
return minimatch(path, elem, {dot:true});
});
}
}
@@ -384,7 +378,7 @@ function mergePathMaps(sourceMaps, targetMap, targetDir) {
// Target stats will be filled in below for targets that exist.
var pathMap = {};
sourceMaps.forEach(function (sourceMap) {
for (var sourceSubPath in sourceMap) {
Object.keys(sourceMap).forEach(function(sourceSubPath){
var sourceEntry = sourceMap[sourceSubPath];
pathMap[sourceSubPath] = {
targetPath: path.join(targetDir, sourceSubPath),
@@ -392,12 +386,12 @@ function mergePathMaps(sourceMaps, targetMap, targetDir) {
sourcePath: path.join(sourceEntry.subDir, sourceSubPath),
sourceStats: sourceEntry.stats
};
}
});
});
// Fill in target stats for targets that exist, and create entries
// for targets that don't have any corresponding sources.
for (var subPath in targetMap) {
Object.keys(targetMap).forEach(function(subPath){
var entry = pathMap[subPath];
if (entry) {
entry.targetStats = targetMap[subPath].stats;
@@ -409,7 +403,7 @@ function mergePathMaps(sourceMaps, targetMap, targetDir) {
sourceStats: null
};
}
}
});
return pathMap;
}
+17
View File
@@ -160,6 +160,23 @@ module.exports = {
return true;
},
prunXMLRemove: function(doc, selector, nodes) {
var target = module.exports.resolveParent(doc, selector);
if (!target) return false;
nodes.forEach(function (node) {
var attributes = node.attrib;
for (var attribute in attributes) {
if (target.attrib[attribute]) {
delete target.attrib[attribute];
}
}
});
return true;
},
parseElementtreeSync: function (filename) {
var contents = fs.readFileSync(filename, 'utf-8');