Skip to content

Commit

Permalink
perf: remove excess deps
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jun 6, 2020
1 parent eb16c31 commit 2224c79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@
"@rollup/plugin-replace": "^2.3.3",
"cac": "^6.5.10",
"consola": "^2.12.2",
"cross-spawn": "^7.0.3",
"defu": "^2.0.4",
"esm": "^3.2.25",
"fs-extra": "^9.0.1",
"pify": "^5.0.0",
"rollup-plugin-license": "^2.1.0",
"sort-package-json": "^1.44.0",
"v8-compile-cache": "^2.1.1"
Expand All @@ -75,11 +73,9 @@
"@babel/preset-env": "^7.10.2",
"@babel/preset-typescript": "^7.10.1",
"@release-it/conventional-changelog": "^1.1.4",
"@types/cross-spawn": "^6.0.2",
"@types/fs-extra": "^9.0.1",
"@types/jest": "^25.2.3",
"@types/lodash": "^4.14.155",
"@types/pify": "^3.0.2",
"@typescript-eslint/eslint-plugin": "^3.1.0",
"@typescript-eslint/parser": "^3.1.0",
"babel-loader": "^8.1.0",
Expand Down
24 changes: 7 additions & 17 deletions src/package/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { resolve } from 'path'
import spawn from 'cross-spawn'
import { existsSync, readJSONSync, writeFile, copy, remove } from 'fs-extra'

import consola, { Consola } from 'consola'
import _glob from 'glob'
import pify from 'pify'
import execa from 'execa'
import { rollup, watch, RollupOptions, RollupError } from 'rollup'
import sortPackageJson from 'sort-package-json'

import type { PackageJson } from '../config/package-json'
import { rollupConfig, NuxtRollupOptions } from '../config/rollup'
import { sortObjectKeys, tryRequire, RequireProperties } from '../utils'
import { sortObjectKeys, tryRequire, RequireProperties, glob } from '../utils'
import type { PackageHooks, HookOptions } from './hooks'

export interface PackageOptions {
Expand All @@ -36,7 +34,6 @@ const DEFAULTS: PackageOptions = {
hooks: {},
}

const glob = pify(_glob)
export class Package {
options: PackageOptions
logger: Consola
Expand Down Expand Up @@ -326,31 +323,24 @@ export class Package {
}

exec(command: string, args: string, silent = false) {
const r = spawn.sync(command, args.split(' '), {
const fullCommand = `${command} ${args}`
const r = execa.commandSync(fullCommand, {
cwd: this.options.rootDir,
env: process.env,
})

if (!silent) {
const fullCommand = command + ' ' + args
if (r.error) {
this.logger.error(fullCommand, r.error)
if (r.failed) {
this.logger.error(fullCommand, r.stderr.trim())
} else {
this.logger.success(fullCommand, r.output)
this.logger.success(fullCommand, r.stdout.trim())
}
}

return {
error: r.error,
pid: r.pid,
status: r.status,
signal: r.signal,
stdout: String(r.stdout).trim(),
stderr: String(r.stderr).trim(),
output: (r.output || [])
.map(l => String(l).trim())
.filter(l => l.length)
.join('\n'),
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import _esm from 'esm'
import _glob from 'glob'

const esm = _esm(module)

export const glob = (pattern: string) =>
new Promise<string[]>((resolve, reject) =>
_glob(pattern, (err, matches) => {
if (err) return reject(err)
resolve(matches)
})
)

export const sortObjectKeys = <T>(obj: Record<string, T>) =>
Object.fromEntries(
Object.entries(obj).sort(([key1], [key2]) => +key2 - +key1)
Expand Down

0 comments on commit 2224c79

Please sign in to comment.