| 51 | } |
| 52 | |
| 53 | export const installPackages = async (pkg: string) => { |
| 54 | // Edit package.json |
| 55 | |
| 56 | const file = editPkgJson('package.json') |
| 57 | |
| 58 | const allDeps = Object.keys(file.get('dependencies')) |
| 59 | |
| 60 | // Replace "workspace:*" with "latest" |
| 61 | |
| 62 | const thDeps = allDeps.filter((x) => x.startsWith('@tinyhttp')) |
| 63 | |
| 64 | const newDeps = {} |
| 65 | |
| 66 | for (const dep of thDeps) newDeps[dep] = 'latest' |
| 67 | |
| 68 | file |
| 69 | .set('dependencies', { |
| 70 | ...file.get('dependencies'), |
| 71 | ...newDeps |
| 72 | }) |
| 73 | .save() |
| 74 | |
| 75 | const depCount = |
| 76 | (Object.keys(file.get('dependencies')) || []).length + (Object.keys(file.get('devDependencies')) || []).length |
| 77 | |
| 78 | const spinner = ora() |
| 79 | |
| 80 | spinner.start(colorette.cyan(`Installing ${depCount} package${depCount > 1 ? 's' : ''} with ${pkg} 📦`)) |
| 81 | |
| 82 | try { |
| 83 | await runCmd(`${pkg} ${pkg === 'yarn' ? 'add' : 'i'}`) |
| 84 | } catch { |
| 85 | throw new Error('Failed to install packages') |
| 86 | } |
| 87 | |
| 88 | spinner.stop() |
| 89 | } |
| 90 | |
| 91 | const ESLINT_JS_CONFIG = ` |
| 92 | { |