element-plus/build/utils.ts
三咲智子 f9e192535f
refactor: replace yarn with pnpm (#3571)
* refactor: replace yarn with pnpm

* chore: install pnpm

* chore: disable cache

* ignore pnpm-lock.yaml

* resolve deps

* setup pnpm
2021-09-23 08:12:37 +08:00

55 lines
1.3 KiB
TypeScript

import path from 'path'
import os from 'os'
import getWorkspacePackages from '@pnpm/find-workspace-packages'
import chalk from 'chalk'
import { compRoot, projRoot } from './paths'
export const getDeps = (pkgPath: string): string[] => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkgJson = require(pkgPath)
const { dependencies } = pkgJson
return Object.keys(dependencies)
}
export const getCpuCount = () => os.cpus().length
export const getPkgs = () => getWorkspacePackages(projRoot)
export const getExternals = async (options: { full: boolean }) => {
const monoPackages = (await getPkgs())
.map((pkg) => pkg.manifest.name)
.filter((name): name is string => !!name)
return (id: string) => {
const packages: string[] = ['vue']
if (!options.full) {
const compPkg = path.resolve(compRoot, './package.json')
const depPackages = getDeps(compPkg)
packages.push('@vue', ...monoPackages, ...depPackages)
}
return [...new Set(packages)].some(
(pkg) => id === pkg || id.startsWith(`${pkg}/`)
)
}
}
export function yellow(str: string) {
console.log(chalk.cyan(str))
}
export function green(str: string) {
console.log(chalk.green(str))
}
export function red(str: string) {
console.error(chalk.red(str))
}
export function errorAndExit(e: Error) {
red(e.message)
process.exit(1)
}