From c4dc8d61c31202fe1bedf800257855faeb1023e4 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 3 Dec 2019 23:07:47 +0800 Subject: [PATCH] refactor: remove unnecessary padEnd & padStart shims Both features are already supported in Node.js v8+ --- packages/@vue/cli-service/lib/commands/help.js | 5 ++--- packages/@vue/cli-service/package.json | 1 - packages/@vue/cli-shared-utils/lib/logger.js | 3 +-- packages/@vue/cli-shared-utils/package.json | 1 - yarn.lock | 18 ------------------ 5 files changed, 3 insertions(+), 25 deletions(-) diff --git a/packages/@vue/cli-service/lib/commands/help.js b/packages/@vue/cli-service/lib/commands/help.js index a88bf257f..f649885d7 100644 --- a/packages/@vue/cli-service/lib/commands/help.js +++ b/packages/@vue/cli-service/lib/commands/help.js @@ -1,5 +1,4 @@ const { chalk } = require('@vue/cli-shared-utils') -const padEnd = require('string.prototype.padend') const getPadLength = require('../util/getPadLength') module.exports = (api, options) => { @@ -23,7 +22,7 @@ module.exports = (api, options) => { if (name !== 'help') { const opts = commands[name].opts || {} console.log(` ${ - chalk.blue(padEnd(name, padLength)) + chalk.blue(name.padEnd(padLength)) }${ opts.description || '' }`) @@ -47,7 +46,7 @@ module.exports = (api, options) => { const padLength = getPadLength(opts.options) for (const [flags, description] of Object.entries(opts.options)) { console.log(` ${ - chalk.blue(padEnd(flags, padLength)) + chalk.blue(flags.padEnd(padLength)) }${ description }`) diff --git a/packages/@vue/cli-service/package.json b/packages/@vue/cli-service/package.json index b8f74f7f0..977a4c982 100644 --- a/packages/@vue/cli-service/package.json +++ b/packages/@vue/cli-service/package.json @@ -66,7 +66,6 @@ "read-pkg": "^5.1.1", "slash": "^3.0.0", "ssri": "^7.1.0", - "string.prototype.padend": "^3.0.0", "terser-webpack-plugin": "^2.2.1", "thread-loader": "^2.1.3", "url-loader": "^2.2.0", diff --git a/packages/@vue/cli-shared-utils/lib/logger.js b/packages/@vue/cli-shared-utils/lib/logger.js index 47d12ba3e..c0afeea1d 100644 --- a/packages/@vue/cli-shared-utils/lib/logger.js +++ b/packages/@vue/cli-shared-utils/lib/logger.js @@ -1,7 +1,6 @@ const chalk = require('chalk') const stripAnsi = require('strip-ansi') const readline = require('readline') -const padStart = require('string.prototype.padstart') const EventEmitter = require('events') exports.events = new EventEmitter() @@ -20,7 +19,7 @@ const format = (label, msg) => { return msg.split('\n').map((line, i) => { return i === 0 ? `${label} ${line}` - : padStart(line, stripAnsi(label).length) + : line.padStart(stripAnsi(label).length) }).join('\n') } diff --git a/packages/@vue/cli-shared-utils/package.json b/packages/@vue/cli-shared-utils/package.json index a9ff19ba3..c2ca48392 100644 --- a/packages/@vue/cli-shared-utils/package.json +++ b/packages/@vue/cli-shared-utils/package.json @@ -31,7 +31,6 @@ "request": "^2.87.0", "request-promise-native": "^1.0.8", "semver": "^6.1.0", - "string.prototype.padstart": "^3.0.0", "strip-ansi": "^6.0.0" }, "publishConfig": { diff --git a/yarn.lock b/yarn.lock index 5c8084730..3ef921bbb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15891,24 +15891,6 @@ string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.0" -string.prototype.padend@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/string.prototype.padend/-/string.prototype.padend-3.0.0.tgz#f3aaef7c1719f170c5eab1c32bf780d96e21f2f0" - integrity sha1-86rvfBcZ8XDF6rHDK/eA2W4h8vA= - dependencies: - define-properties "^1.1.2" - es-abstract "^1.4.3" - function-bind "^1.0.2" - -string.prototype.padstart@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/string.prototype.padstart/-/string.prototype.padstart-3.0.0.tgz#5bcfad39f4649bb2d031292e19bcf0b510d4b242" - integrity sha1-W8+tOfRkm7LQMSkuGbzwtRDUskI= - dependencies: - define-properties "^1.1.2" - es-abstract "^1.4.3" - function-bind "^1.0.2" - string.prototype.trimleft@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/string.prototype.trimleft/-/string.prototype.trimleft-2.1.0.tgz#6cc47f0d7eb8d62b0f3701611715a3954591d634"