Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

feat: smaller bundle size, cut lodash imports #107

Merged
merged 7 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/action/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _ from 'lodash'
import castArray from 'lodash/castArray'
import {inspect} from 'util'

/* eslint-disable-next-line @typescript-eslint/interface-name-prefix */
Expand Down Expand Up @@ -196,6 +196,6 @@ export class ActionBase {
* write to the real stdout/stderr
*/
protected _write(std: 'stdout' | 'stderr', s: string | string[]) {
this.stdmockOrigs[std].apply(process[std], _.castArray(s) as [string])
this.stdmockOrigs[std].apply(process[std], castArray(s) as [string])
}
}
6 changes: 3 additions & 3 deletions src/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tslint:disable

import * as _ from 'lodash'
import maxBy from 'lodash/maxBy'

import deps from './deps'

Expand All @@ -17,14 +17,14 @@ export function renderList(items: IListItem[]): string {
if (items.length === 0) {
return ''
}
const maxLength = (_.maxBy(items, '[0].length') as any)[0].length
const maxLength = (maxBy(items, '[0].length') as any)[0].length
const lines = items.map(i => {
let left = i[0]
let right = i[1]
if (!right) {
return left
}
left = `${_.padEnd(left, maxLength)}`
left = left.padEnd(maxLength)
right = linewrap(maxLength + 2, right)
return `${left} ${right}`
})
Expand Down
13 changes: 7 additions & 6 deletions src/styled/table.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {flags as F} from '@oclif/command'
import {stdtermwidth} from '@oclif/screen'
import chalk from 'chalk'
import capitalize from 'lodash/capitalize'
import sumBy from 'lodash/sumBy'
import {safeDump} from 'js-yaml'
import * as _ from 'lodash'
import {inspect} from 'util'

const sw = require('string-width')
Expand All @@ -19,7 +20,7 @@ class Table<T extends object> {
const col = columns[key]
const extended = col.extended || false
const get = col.get || ((row: any) => row[key])
const header = typeof col.header === 'string' ? col.header : _.capitalize(key.replace(/_/g, ' '))
const header = typeof col.header === 'string' ? col.header : capitalize(key.replace(/_/g, ' '))
const minWidth = Math.max(col.minWidth || 0, sw(header) + 1)

return {
Expand Down Expand Up @@ -202,7 +203,7 @@ class Table<T extends object> {
if (options['no-truncate'] || (!process.stdout.isTTY && !process.env.CLI_UX_SKIP_TTY_CHECK)) return

// don't shorten if there is enough screen width
const dataMaxWidth = _.sumBy(columns, c => c.width!)
const dataMaxWidth = sumBy(columns, c => c.width!)
const overWidth = dataMaxWidth - maxWidth
if (overWidth <= 0) return

Expand All @@ -214,15 +215,15 @@ class Table<T extends object> {
// if sum(minWidth's) is greater than term width
// nothing can be done so
// display all as minWidth
const dataMinWidth = _.sumBy(columns, c => c.minWidth!)
const dataMinWidth = sumBy(columns, c => c.minWidth!)
if (dataMinWidth >= maxWidth) return

// some wiggle room left, add it back to "needy" columns
let wiggleRoom = maxWidth - dataMinWidth
const needyCols = _.sortBy(columns.map(c => ({key: c.key, needs: c.maxWidth! - c.width!})), c => c.needs)
const needyCols = columns.map(c => ({key: c.key, needs: c.maxWidth! - c.width!})).sort((a, b) => a.needs - b.needs)
for (const {key, needs} of needyCols) {
if (!needs) continue
const col = _.find(columns, c => (key === c.key))
const col = columns.find(c => key === c.key)
if (!col) continue
if (wiggleRoom > needs) {
col.width = col.width! + needs
Expand Down