From 01526d30ab470b2872ac98f62d6a8712d78eddbc Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Thu, 16 Jul 2015 13:37:42 -0400 Subject: [PATCH 1/2] Install ES2015 String polyfills in tool code, too. --- tools/main-transpile-wrapper.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/main-transpile-wrapper.js b/tools/main-transpile-wrapper.js index cd8b314766..2a67408173 100644 --- a/tools/main-transpile-wrapper.js +++ b/tools/main-transpile-wrapper.js @@ -15,11 +15,12 @@ babelRegister(); // #RemoveInProd this line is removed in isopack.js // run all its callbacks in Fibers. global.Promise = require("meteor-promise"); -// Globally install ES2015-complaint Symbol, Map, and Set, patching the -// native implementations if they are available. +// Install ES2015-complaint polyfills for Symbol, Map, Set, and String, +// patching the native implementations if they are available. require("core-js/es6/symbol"); require("core-js/es6/map"); require("core-js/es6/set"); +require("core-js/es6/string"); // Include helpers from NPM so that the compiler doesn't need to add boilerplate // at the top of every file From 0679da7cf431e98f9c58414eed37bef7f895d249 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Thu, 16 Jul 2015 13:54:12 -0400 Subject: [PATCH 2/2] Use String#{starts,ends}With instead of ad-hoc utility functions. --- tools/commands-packages.js | 11 +++-------- tools/tropohouse.js | 8 ++++---- tools/updater.js | 2 +- tools/utils.js | 6 ------ 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/tools/commands-packages.js b/tools/commands-packages.js index 1e532aaac5..704c2545cf 100644 --- a/tools/commands-packages.js +++ b/tools/commands-packages.js @@ -64,16 +64,11 @@ var formatAsList = function (list, options) { return _.map(list, formatter).join(", "); }; -var endsWith = function (s, suffix) { - return s.length >= suffix.length && - s.substr(s.length - suffix.length) === suffix; -}; - var removeIfEndsWith = function (s, suffix) { - if (!endsWith(s, suffix)) { - return s; + if (s.endsWith(suffix)) { + return s.substring(0, s.length - suffix.length); } - return s.substring(0, s.length - suffix.length); + return s; }; var formatArchitecture = function (s) { diff --git a/tools/tropohouse.js b/tools/tropohouse.js index a9d6bb649a..0744553e65 100644 --- a/tools/tropohouse.js +++ b/tools/tropohouse.js @@ -201,8 +201,8 @@ _.extend(exports.Tropohouse.prototype, { } var latestMeteorSymlink = self.latestMeteorSymlink(); - if (utils.startsWith(latestMeteorSymlink, - packagesDirectoryName + files.pathSep)) { + if (latestMeteorSymlink.startsWith(packagesDirectoryName + + files.pathSep)) { var rest = latestMeteorSymlink.substr( packagesDirectoryName.length + files.pathSep.length); @@ -234,7 +234,7 @@ _.extend(exports.Tropohouse.prototype, { // it points to. if (packageEscaped === latestToolPackageEscaped && (version === latestToolVersion || - utils.startsWith(version, '.' + latestToolVersion + '.'))) { + version.startsWith('.' + latestToolVersion + '.'))) { return; } @@ -242,7 +242,7 @@ _.extend(exports.Tropohouse.prototype, { // operation). if (packageEscaped === currentToolPackageEscaped && (version === currentToolVersion || - utils.startsWith(version, '.' + currentToolVersion + '.'))) { + version.startsWith('.' + currentToolVersion + '.'))) { return; } diff --git a/tools/updater.js b/tools/updater.js index a63e89ce57..2e6d10f54a 100644 --- a/tools/updater.js +++ b/tools/updater.js @@ -170,7 +170,7 @@ var updateMeteorToolSymlink = function (printErrors) { var localLatestReleaseLink = tropohouse.default.latestMeteorSymlink(); - if (! utils.startsWith(localLatestReleaseLink, relativeToolPath + files.pathSep)) { + if (! localLatestReleaseLink.startsWith(relativeToolPath + files.pathSep)) { // The latest release from the catalog is not where the ~/.meteor/meteor // symlink points to. Let's make sure we have that release on disk, // and then update the symlink. diff --git a/tools/utils.js b/tools/utils.js index 5f8f70b3aa..c79b19d1a6 100644 --- a/tools/utils.js +++ b/tools/utils.js @@ -384,12 +384,6 @@ exports.isDirectory = function (dir) { return stats.isDirectory(); }; -// XXX from Underscore.String (http://epeli.github.com/underscore.string/) -exports.startsWith = function(str, starts) { - return str.length >= starts.length && - str.substring(0, starts.length) === starts; -}; - // Options: noPrefix: do not display 'Meteor ' in front of the version number. exports.displayRelease = function (track, version, options) { var catalog = require('./catalog.js');