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
+2 -2
View File
@@ -17,8 +17,8 @@
under the License.
*/
module.exports = function addProperty(module, property, modulePath, obj) {
module.exports = function addProperty (module, property, modulePath, obj) {
obj = obj || module.exports;
// Add properties as getter to delay load the modules on first invocation
Object.defineProperty(obj, property, {
+23 -28
View File
@@ -15,32 +15,32 @@
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
*/
/* eslint no-useless-escape: 0 */
// contains PLIST utility functions
var __ = require('underscore');
var __ = require('underscore');
var plist = require('plist');
// adds node to doc at selector
module.exports.graftPLIST = graftPLIST;
function graftPLIST(doc, xml, selector) {
var obj = plist.parse('<plist>'+xml+'</plist>');
function graftPLIST (doc, xml, selector) {
var obj = plist.parse('<plist>' + xml + '</plist>');
var node = doc[selector];
if (node && Array.isArray(node) && Array.isArray(obj)){
if (node && Array.isArray(node) && Array.isArray(obj)) {
node = node.concat(obj);
for (var i =0;i<node.length; i++){
for (var j=i+1; j<node.length; ++j) {
if (nodeEqual(node[i], node[j]))
node.splice(j--,1);
for (var i = 0; i < node.length; i++) {
for (var j = i + 1; j < node.length; ++j) {
if (nodeEqual(node[i], node[j])) { node.splice(j--, 1); }
}
}
doc[selector] = node;
} else {
//plist uses objects for <dict>. If we have two dicts we merge them instead of
// plist uses objects for <dict>. If we have two dicts we merge them instead of
// overriding the old one. See CB-6472
if (node && __.isObject(node) && __.isObject(obj) && !__.isDate(node) && !__.isDate(obj)){//arrays checked above
__.extend(obj,node);
if (node && __.isObject(node) && __.isObject(obj) && !__.isDate(node) && !__.isDate(obj)) { // arrays checked above
__.extend(obj, node);
}
doc[selector] = obj;
}
@@ -50,15 +50,15 @@ function graftPLIST(doc, xml, selector) {
// removes node from doc at selector
module.exports.prunePLIST = prunePLIST;
function prunePLIST(doc, xml, selector) {
var obj = plist.parse('<plist>'+xml+'</plist>');
function prunePLIST (doc, xml, selector) {
var obj = plist.parse('<plist>' + xml + '</plist>');
pruneOBJECT(doc, selector, obj);
return true;
}
function pruneOBJECT(doc, selector, fragment) {
function pruneOBJECT (doc, selector, fragment) {
if (Array.isArray(fragment) && Array.isArray(doc[selector])) {
var empty = true;
for (var i in fragment) {
@@ -66,13 +66,11 @@ function pruneOBJECT(doc, selector, fragment) {
empty = pruneOBJECT(doc[selector], j, fragment[i]) && empty;
}
}
if (empty)
{
if (empty) {
delete doc[selector];
return true;
}
}
else if (nodeEqual(doc[selector], fragment)) {
} else if (nodeEqual(doc[selector], fragment)) {
delete doc[selector];
return true;
}
@@ -80,14 +78,11 @@ function pruneOBJECT(doc, selector, fragment) {
return false;
}
function nodeEqual(node1, node2) {
if (typeof node1 != typeof node2)
return false;
else if (typeof node1 == 'string') {
node2 = escapeRE(node2).replace(new RegExp('\\$[a-zA-Z0-9-_]+','gm'),'(.*?)');
function nodeEqual (node1, node2) {
if (typeof node1 !== typeof node2) { return false; } else if (typeof node1 === 'string') {
node2 = escapeRE(node2).replace(/\\\$\S+/gm, '(.*?)');
return new RegExp('^' + node2 + '$').test(node1);
}
else {
} else {
for (var key in node2) {
if (!nodeEqual(node1[key], node2[key])) return false;
}
@@ -96,6 +91,6 @@ function nodeEqual(node1, node2) {
}
// escape string for use in regex
function escapeRE(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '$&');
function escapeRE (str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
}
+68 -69
View File
@@ -15,32 +15,31 @@
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
/* jshint sub:true, laxcomma:true */
*/
/**
* contains XML utility functions, some of which are specific to elementtree
*/
var fs = require('fs')
, path = require('path')
, _ = require('underscore')
, et = require('elementtree')
;
var fs = require('fs');
var path = require('path');
var _ = require('underscore');
var et = require('elementtree');
var ROOT = /^\/([^\/]*)/,
ABSOLUTE = /^\/([^\/]*)\/(.*)/;
/* eslint-disable no-useless-escape */
var ROOT = /^\/([^\/]*)/;
var ABSOLUTE = /^\/([^\/]*)\/(.*)/;
/* eslint-enable no-useless-escape */
module.exports = {
// compare two et.XML nodes, see if they match
// compares tagName, text, attributes and children (recursively)
equalNodes: function(one, two) {
if (one.tag != two.tag) {
equalNodes: function (one, two) {
if (one.tag !== two.tag) {
return false;
} else if (one.text.trim() != two.text.trim()) {
} else if (one.text.trim() !== two.text.trim()) {
return false;
} else if (one._children.length != two._children.length) {
} else if (one._children.length !== two._children.length) {
return false;
}
@@ -56,13 +55,13 @@ module.exports = {
},
// adds node to doc at selector, creating parent if it doesn't exist
graftXML: function(doc, nodes, selector, after) {
graftXML: function (doc, nodes, selector, after) {
var parent = module.exports.resolveParent(doc, selector);
if (!parent) {
//Try to create the parent recursively if necessary
// Try to create the parent recursively if necessary
try {
var parentToCreate = et.XML('<' + path.basename(selector) + '>'),
parentSelector = path.dirname(selector);
var parentToCreate = et.XML('<' + path.basename(selector) + '>');
var parentSelector = path.dirname(selector);
this.graftXML(doc, [parentToCreate], parentSelector);
} catch (e) {
@@ -78,7 +77,7 @@ module.exports = {
var children = parent.getchildren();
var insertIdx = after ? findInsertIdx(children, after) : children.length;
//TODO: replace with parent.insert after the bug in ElementTree is fixed
// TODO: replace with parent.insert after the bug in ElementTree is fixed
parent.getchildren().splice(insertIdx, 0, node);
}
});
@@ -88,7 +87,7 @@ module.exports = {
// adds new attributes to doc at selector
// Will only merge if attribute has not been modified already or --force is used
graftXMLMerge: function(doc, nodes, selector, xml) {
graftXMLMerge: function (doc, nodes, selector, xml) {
var target = module.exports.resolveParent(doc, selector);
if (!target) return false;
@@ -107,7 +106,7 @@ module.exports = {
// overwrite all attributes to doc at selector with new attributes
// Will only overwrite if attribute has not been modified already or --force is used
graftXMLOverwrite: function(doc, nodes, selector, xml) {
graftXMLOverwrite: function (doc, nodes, selector, xml) {
var target = module.exports.resolveParent(doc, selector);
if (!target) return false;
@@ -132,7 +131,7 @@ module.exports = {
},
// removes node from doc at selector
pruneXML: function(doc, nodes, selector) {
pruneXML: function (doc, nodes, selector) {
var parent = module.exports.resolveParent(doc, selector);
if (!parent) return false;
@@ -149,7 +148,7 @@ module.exports = {
},
// restores attributes from doc at selector
pruneXMLRestore: function(doc, selector, xml) {
pruneXMLRestore: function (doc, selector, xml) {
var target = module.exports.resolveParent(doc, selector);
if (!target) return false;
@@ -160,7 +159,7 @@ module.exports = {
return true;
},
prunXMLRemove: function(doc, selector, nodes) {
pruneXMLRemove: function (doc, selector, nodes) {
var target = module.exports.resolveParent(doc, selector);
if (!target) return false;
@@ -177,11 +176,10 @@ module.exports = {
},
parseElementtreeSync: function (filename) {
var contents = fs.readFileSync(filename, 'utf-8');
if(contents) {
//Windows is the BOM. Skip the Byte Order Mark.
if (contents) {
// Windows is the BOM. Skip the Byte Order Mark.
contents = contents.substring(contents.indexOf('<'));
}
return new et.ElementTree(et.XML(contents));
@@ -194,7 +192,7 @@ module.exports = {
if (ROOT.test(selector)) {
tagName = selector.match(ROOT)[1];
// test for wildcard "any-tag" root selector
if (tagName == '*' || tagName === doc._root.tag) {
if (tagName === '*' || tagName === doc._root.tag) {
parent = doc._root;
// could be an absolute path, but not selecting the root
@@ -212,11 +210,12 @@ module.exports = {
}
};
function findChild(node, parent) {
var matchingKids = parent.findall(node.tag)
, i, j;
function findChild (node, parent) {
var matchingKids = parent.findall(node.tag);
var i;
var j;
for (i = 0, j = matchingKids.length ; i < j ; i++) {
for (i = 0, j = matchingKids.length; i < j; i++) {
if (module.exports.equalNodes(node, matchingKids[i])) {
return matchingKids[i];
}
@@ -224,13 +223,13 @@ function findChild(node, parent) {
return null;
}
function uniqueChild(node, parent) {
var matchingKids = parent.findall(node.tag)
, i = 0;
function uniqueChild (node, parent) {
var matchingKids = parent.findall(node.tag);
var i = 0;
if (matchingKids.length === 0) {
return true;
} else {
} else {
for (i; i < matchingKids.length; i++) {
if (module.exports.equalNodes(node, matchingKids[i])) {
return false;
@@ -244,51 +243,51 @@ function uniqueChild(node, parent) {
// of tags after which the insertion should be made. E.g. If we need to
// insert an element C, and the rule is that the order of children has to be
// As, Bs, Cs. After will be equal to "C;B;A".
function findInsertIdx(children, after) {
var childrenTags = children.map(function(child) { return child.tag; });
function findInsertIdx (children, after) {
var childrenTags = children.map(function (child) { return child.tag; });
var afters = after.split(';');
var afterIndexes = afters.map(function(current) { return childrenTags.lastIndexOf(current); });
var foundIndex = _.find(afterIndexes, function(index) { return index != -1; });
var afterIndexes = afters.map(function (current) { return childrenTags.lastIndexOf(current); });
var foundIndex = _.find(afterIndexes, function (index) { return index !== -1; });
//add to the beginning if no matching nodes are found
return typeof foundIndex === 'undefined' ? 0 : foundIndex+1;
// add to the beginning if no matching nodes are found
return typeof foundIndex === 'undefined' ? 0 : foundIndex + 1;
}
var BLACKLIST = ['platform', 'feature','plugin','engine'];
var BLACKLIST = ['platform', 'feature', 'plugin', 'engine'];
var SINGLETONS = ['content', 'author', 'name'];
function mergeXml(src, dest, platform, clobber) {
function mergeXml (src, dest, platform, clobber) {
// Do nothing for blacklisted tags.
if (BLACKLIST.indexOf(src.tag) != -1) return;
if (BLACKLIST.indexOf(src.tag) !== -1) return;
//Handle attributes
// Handle attributes
Object.getOwnPropertyNames(src.attrib).forEach(function (attribute) {
if (clobber || !dest.attrib[attribute]) {
dest.attrib[attribute] = src.attrib[attribute];
}
});
//Handle text
// Handle text
if (src.text && (clobber || !dest.text)) {
dest.text = src.text;
}
//Handle children
// Handle children
src.getchildren().forEach(mergeChild);
//Handle platform
// Handle platform
if (platform) {
src.findall('platform[@name="' + platform + '"]').forEach(function (platformElement) {
platformElement.getchildren().forEach(mergeChild);
});
}
//Handle duplicate preference tags (by name attribute)
// Handle duplicate preference tags (by name attribute)
removeDuplicatePreferences(dest);
function mergeChild (srcChild) {
var srcTag = srcChild.tag,
destChild = new et.Element(srcTag),
foundChild,
query = srcTag + '',
shouldMerge = true;
var srcTag = srcChild.tag;
var destChild = new et.Element(srcTag);
var foundChild;
var query = srcTag + '';
var shouldMerge = true;
if (BLACKLIST.indexOf(srcTag) !== -1) return;
@@ -299,11 +298,11 @@ function mergeXml(src, dest, platform, clobber) {
dest.remove(destChild);
}
} else {
//Check for an exact match and if you find one don't add
// Check for an exact match and if you find one don't add
var mergeCandidates = dest.findall(query)
.filter(function (foundChild) {
return foundChild && textMatch(srcChild, foundChild) && attribMatch(srcChild, foundChild);
});
.filter(function (foundChild) {
return foundChild && textMatch(srcChild, foundChild) && attribMatch(srcChild, foundChild);
});
if (mergeCandidates.length > 0) {
destChild = mergeCandidates[0];
@@ -316,20 +315,20 @@ function mergeXml(src, dest, platform, clobber) {
dest.append(destChild);
}
function removeDuplicatePreferences(xml) {
function removeDuplicatePreferences (xml) {
// reduce preference tags to a hashtable to remove dupes
var prefHash = xml.findall('preference[@name][@value]').reduce(function(previousValue, currentValue) {
var prefHash = xml.findall('preference[@name][@value]').reduce(function (previousValue, currentValue) {
previousValue[ currentValue.attrib.name ] = currentValue.attrib.value;
return previousValue;
}, {});
// remove all preferences
xml.findall('preference[@name][@value]').forEach(function(pref) {
xml.findall('preference[@name][@value]').forEach(function (pref) {
xml.remove(pref);
});
// write new preferences
Object.keys(prefHash).forEach(function(key, index) {
Object.keys(prefHash).forEach(function (key, index) {
var element = et.SubElement(xml, 'preference');
element.set('name', key);
element.set('value', this[key]);
@@ -340,24 +339,24 @@ function mergeXml(src, dest, platform, clobber) {
// Expose for testing.
module.exports.mergeXml = mergeXml;
function textMatch(elm1, elm2) {
var text1 = elm1.text ? elm1.text.replace(/\s+/, '') : '',
text2 = elm2.text ? elm2.text.replace(/\s+/, '') : '';
function textMatch (elm1, elm2) {
var text1 = elm1.text ? elm1.text.replace(/\s+/, '') : '';
var text2 = elm2.text ? elm2.text.replace(/\s+/, '') : '';
return (text1 === '' || text1 === text2);
}
function attribMatch(one, two) {
function attribMatch (one, two) {
var oneAttribKeys = Object.keys(one.attrib);
var twoAttribKeys = Object.keys(two.attrib);
if (oneAttribKeys.length != twoAttribKeys.length) {
if (oneAttribKeys.length !== twoAttribKeys.length) {
return false;
}
for (var i = 0; i < oneAttribKeys.length; i++) {
var attribName = oneAttribKeys[i];
if (one.attrib[attribName] != two.attrib[attribName]) {
if (one.attrib[attribName] !== two.attrib[attribName]) {
return false;
}
}