diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-04-20 03:09:25 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-04-24 16:14:29 +0200 |
commit | 82f2b76e25a4a67e01ec67e5ebe39d14ad771ea8 (patch) | |
tree | 965f6eb89b84d65a62b49008fd972c004832ccd1 /node_modules/gulp-util/lib | |
parent | e6e0cbc387c2a77b48e4065c229daa65bf1aa0fa (diff) |
Reorganize module loading.
We now use webpack instead of SystemJS, effectively bundling modules
into one file (plus commons chunks) for every entry point. This results
in a much smaller extension size (almost half). Furthermore we use
yarn/npm even for extension run-time dependencies. This relieves us
from manually vendoring and building dependencies. It's also easier to
understand for new developers familiar with node.
Diffstat (limited to 'node_modules/gulp-util/lib')
-rw-r--r-- | node_modules/gulp-util/lib/File.js | 1 | ||||
-rw-r--r-- | node_modules/gulp-util/lib/PluginError.js | 114 | ||||
-rw-r--r-- | node_modules/gulp-util/lib/beep.js | 3 | ||||
-rw-r--r-- | node_modules/gulp-util/lib/buffer.js | 2 | ||||
-rw-r--r-- | node_modules/gulp-util/lib/colors.js | 1 | ||||
-rw-r--r-- | node_modules/gulp-util/lib/date.js | 1 | ||||
-rw-r--r-- | node_modules/gulp-util/lib/env.js | 2 | ||||
-rw-r--r-- | node_modules/gulp-util/lib/isBuffer.js | 2 | ||||
-rw-r--r-- | node_modules/gulp-util/lib/isNull.js | 2 | ||||
-rw-r--r-- | node_modules/gulp-util/lib/isStream.js | 2 | ||||
-rw-r--r-- | node_modules/gulp-util/lib/linefeed.js | 1 | ||||
-rw-r--r-- | node_modules/gulp-util/lib/log.js | 16 | ||||
-rw-r--r-- | node_modules/gulp-util/lib/replaceExtension.js | 9 | ||||
-rw-r--r-- | node_modules/gulp-util/lib/template.js | 14 |
14 files changed, 114 insertions, 56 deletions
diff --git a/node_modules/gulp-util/lib/File.js b/node_modules/gulp-util/lib/File.js deleted file mode 100644 index 690a508a6..000000000 --- a/node_modules/gulp-util/lib/File.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('vinyl');
\ No newline at end of file diff --git a/node_modules/gulp-util/lib/PluginError.js b/node_modules/gulp-util/lib/PluginError.js index 6640346ed..d60159ab1 100644 --- a/node_modules/gulp-util/lib/PluginError.js +++ b/node_modules/gulp-util/lib/PluginError.js @@ -1,22 +1,32 @@ var util = require('util'); -var colors = require('./colors'); +var arrayDiffer = require('array-differ'); +var arrayUniq = require('array-uniq'); +var chalk = require('chalk'); +var objectAssign = require('object-assign'); + +var nonEnumberableProperties = ['name', 'message', 'stack']; +var propertiesNotToDisplay = nonEnumberableProperties.concat(['plugin', 'showStack', 'showProperties', '__safety', '_stack']); // wow what a clusterfuck var parseOptions = function(plugin, message, opt) { - if (!opt) opt = {}; + opt = opt || {}; if (typeof plugin === 'object') { opt = plugin; - } else if (message instanceof Error) { - opt.error = message; - opt.plugin = plugin; - } else if (typeof message === 'object') { - opt = message; - opt.plugin = plugin; - } else if (typeof opt === 'object') { + } else { + if (message instanceof Error) { + opt.error = message; + } else if (typeof message === 'object') { + opt = message; + } else { + opt.message = message; + } opt.plugin = plugin; - opt.message = message; } - return opt; + + return objectAssign({ + showStack: false, + showProperties: true + }, opt); }; function PluginError(plugin, message, opt) { @@ -25,19 +35,19 @@ function PluginError(plugin, message, opt) { Error.call(this); var options = parseOptions(plugin, message, opt); - - this.plugin = options.plugin; - this.showStack = options.showStack === true; - - var properties = ['name', 'message', 'fileName', 'lineNumber', 'stack']; + var self = this; // if options has an error, grab details from it if (options.error) { - properties.forEach(function(prop) { - if (prop in options.error) this[prop] = options.error[prop]; - }, this); + // These properties are not enumerable, so we have to add them explicitly. + arrayUniq(Object.keys(options.error).concat(nonEnumberableProperties)) + .forEach(function(prop) { + self[prop] = options.error[prop]; + }); } + var properties = ['name', 'message', 'fileName', 'lineNumber', 'stack', 'showStack', 'showProperties', 'plugin']; + // options object can override properties.forEach(function(prop) { if (prop in options) this[prop] = options[prop]; @@ -46,8 +56,18 @@ function PluginError(plugin, message, opt) { // defaults if (!this.name) this.name = 'Error'; - // TODO: figure out why this explodes mocha - if (!this.stack) Error.captureStackTrace(this, arguments.callee || this.constructor); + if (!this.stack) { + // Error.captureStackTrace appends a stack property which relies on the toString method of the object it is applied to. + // Since we are using our own toString method which controls when to display the stack trace if we don't go through this + // safety object, then we'll get stack overflow problems. + var safety = { + toString: function() { + return this._messageWithDetails() + '\nStack:'; + }.bind(this) + }; + Error.captureStackTrace(safety, arguments.callee || this.constructor); + this.__safety = safety; + } if (!this.plugin) throw new Error('Missing plugin name'); if (!this.message) throw new Error('Missing error message'); @@ -55,10 +75,56 @@ function PluginError(plugin, message, opt) { util.inherits(PluginError, Error); +PluginError.prototype._messageWithDetails = function() { + var messageWithDetails = 'Message:\n ' + this.message; + var details = this._messageDetails(); + + if (details !== '') { + messageWithDetails += '\n' + details; + } + + return messageWithDetails; +}; + +PluginError.prototype._messageDetails = function() { + if (!this.showProperties) { + return ''; + } + + var properties = arrayDiffer(Object.keys(this), propertiesNotToDisplay); + + if (properties.length === 0) { + return ''; + } + + var self = this; + properties = properties.map(function stringifyProperty(prop) { + return ' ' + prop + ': ' + self[prop]; + }); + + return 'Details:\n' + properties.join('\n'); +}; + PluginError.prototype.toString = function () { - var sig = this.name+' in plugin \''+colors.cyan(this.plugin)+'\''; - var msg = this.showStack ? (this._stack || this.stack) : this.message; - return sig+'\n'+msg; + var sig = chalk.red(this.name) + ' in plugin \'' + chalk.cyan(this.plugin) + '\''; + var detailsWithStack = function(stack) { + return this._messageWithDetails() + '\nStack:\n' + stack; + }.bind(this); + + var msg; + if (this.showStack) { + if (this.__safety) { // There is no wrapped error, use the stack captured in the PluginError ctor + msg = this.__safety.stack; + } else if (this._stack) { + msg = detailsWithStack(this._stack); + } else { // Stack from wrapped error + msg = detailsWithStack(this.stack); + } + } else { + msg = this._messageWithDetails(); + } + + return sig + '\n' + msg; }; module.exports = PluginError; diff --git a/node_modules/gulp-util/lib/beep.js b/node_modules/gulp-util/lib/beep.js deleted file mode 100644 index 5473d7548..000000000 --- a/node_modules/gulp-util/lib/beep.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = function() { - process.stdout.write('\x07'); -}; diff --git a/node_modules/gulp-util/lib/buffer.js b/node_modules/gulp-util/lib/buffer.js index 4cb064aca..26c940db1 100644 --- a/node_modules/gulp-util/lib/buffer.js +++ b/node_modules/gulp-util/lib/buffer.js @@ -12,4 +12,4 @@ module.exports = function(fn) { cb(); }; return through.obj(push, end); -};
\ No newline at end of file +}; diff --git a/node_modules/gulp-util/lib/colors.js b/node_modules/gulp-util/lib/colors.js deleted file mode 100644 index bc8049406..000000000 --- a/node_modules/gulp-util/lib/colors.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('chalk');
\ No newline at end of file diff --git a/node_modules/gulp-util/lib/date.js b/node_modules/gulp-util/lib/date.js deleted file mode 100644 index 935793cc6..000000000 --- a/node_modules/gulp-util/lib/date.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('dateformat');
\ No newline at end of file diff --git a/node_modules/gulp-util/lib/env.js b/node_modules/gulp-util/lib/env.js index ea1e03e4a..ee17c0e30 100644 --- a/node_modules/gulp-util/lib/env.js +++ b/node_modules/gulp-util/lib/env.js @@ -1,4 +1,4 @@ var parseArgs = require('minimist'); var argv = parseArgs(process.argv.slice(2)); -module.exports = argv;
\ No newline at end of file +module.exports = argv; diff --git a/node_modules/gulp-util/lib/isBuffer.js b/node_modules/gulp-util/lib/isBuffer.js index 0e23782c4..7c52f78c9 100644 --- a/node_modules/gulp-util/lib/isBuffer.js +++ b/node_modules/gulp-util/lib/isBuffer.js @@ -4,4 +4,4 @@ var Buffer = buf.Buffer; // could use Buffer.isBuffer but this is the same exact thing... module.exports = function(o) { return typeof o === 'object' && o instanceof Buffer; -};
\ No newline at end of file +}; diff --git a/node_modules/gulp-util/lib/isNull.js b/node_modules/gulp-util/lib/isNull.js index 403bb30e8..7f22c63ae 100644 --- a/node_modules/gulp-util/lib/isNull.js +++ b/node_modules/gulp-util/lib/isNull.js @@ -1,3 +1,3 @@ module.exports = function(v) { return v === null; -};
\ No newline at end of file +}; diff --git a/node_modules/gulp-util/lib/isStream.js b/node_modules/gulp-util/lib/isStream.js index 9ce0929b0..6b54e123b 100644 --- a/node_modules/gulp-util/lib/isStream.js +++ b/node_modules/gulp-util/lib/isStream.js @@ -2,4 +2,4 @@ var Stream = require('stream').Stream; module.exports = function(o) { return !!o && o instanceof Stream; -};
\ No newline at end of file +}; diff --git a/node_modules/gulp-util/lib/linefeed.js b/node_modules/gulp-util/lib/linefeed.js deleted file mode 100644 index 5b0dfa4b1..000000000 --- a/node_modules/gulp-util/lib/linefeed.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = '\n';
\ No newline at end of file diff --git a/node_modules/gulp-util/lib/log.js b/node_modules/gulp-util/lib/log.js index e33d15ed9..bb843beef 100644 --- a/node_modules/gulp-util/lib/log.js +++ b/node_modules/gulp-util/lib/log.js @@ -1,10 +1,14 @@ -var colors = require('./colors'); -var date = require('./date'); +var hasGulplog = require('has-gulplog'); module.exports = function(){ - var time = '['+colors.grey(date(new Date(), 'HH:MM:ss'))+']'; - var args = Array.prototype.slice.call(arguments); - args.unshift(time); - console.log.apply(console, args); + if(hasGulplog()){ + // specifically deferring loading here to keep from registering it globally + var gulplog = require('gulplog'); + gulplog.info.apply(gulplog, arguments); + } else { + // specifically defering loading because it might not be used + var fancylog = require('fancy-log'); + fancylog.apply(null, arguments); + } return this; }; diff --git a/node_modules/gulp-util/lib/replaceExtension.js b/node_modules/gulp-util/lib/replaceExtension.js deleted file mode 100644 index 3f76938e4..000000000 --- a/node_modules/gulp-util/lib/replaceExtension.js +++ /dev/null @@ -1,9 +0,0 @@ -var path = require('path'); - -module.exports = function(npath, ext) { - if (typeof npath !== 'string') return npath; - if (npath.length === 0) return npath; - - var nFileName = path.basename(npath, path.extname(npath))+ext; - return path.join(path.dirname(npath), nFileName); -};
\ No newline at end of file diff --git a/node_modules/gulp-util/lib/template.js b/node_modules/gulp-util/lib/template.js index c467820f3..eef3bb376 100644 --- a/node_modules/gulp-util/lib/template.js +++ b/node_modules/gulp-util/lib/template.js @@ -1,17 +1,21 @@ var template = require('lodash.template'); +var reEscape = require('lodash._reescape'); +var reEvaluate = require('lodash._reevaluate'); var reInterpolate = require('lodash._reinterpolate'); var forcedSettings = { - escape: /<%-([\s\S]+?)%>/g, - evaluate: /<%([\s\S]+?)%>/g, + escape: reEscape, + evaluate: reEvaluate, interpolate: reInterpolate }; -module.exports = function(tmpl, data){ - var fn = template(tmpl, null, forcedSettings); +module.exports = function(tmpl, data) { + var fn = template(tmpl, forcedSettings); var wrapped = function(o) { - if (typeof o === 'undefined' || typeof o.file === 'undefined') throw new Error('Failed to provide the current file as "file" to the template'); + if (typeof o === 'undefined' || typeof o.file === 'undefined') { + throw new Error('Failed to provide the current file as "file" to the template'); + } return fn(o); }; |