@@ -3,7 +3,7 @@ import { promises as fs, existsSync } from 'node:fs';
33import { dirname , resolve } from 'node:path' ;
44import { fileURLToPath } from 'node:url' ;
55import * as prompts from '@clack/prompts' ;
6- import { installPackage , detectPackageManager } from '@antfu/install-pkg ' ;
6+ import { execa } from 'execa ' ;
77import * as kl from 'kolorist' ;
88
99const s = prompts . spinner ( ) ;
@@ -16,13 +16,11 @@ const brandColor = /** @type {const} */ ([174, 128, 255]);
1616 //
1717 // Don't love the flag, need to find a better name.
1818 const skipHint = process . argv . slice ( 2 ) . includes ( '--skip-hints' ) ;
19- const packageManager =
20- ( await detectPackageManager ( ) ) ??
21- ( / y a r n / . test ( process . env . npm_execpath )
22- ? 'yarn'
23- : process . env . PNPM_PACKAGE_NAME
24- ? 'pnpm'
25- : 'npm' ) ;
19+ const packageManager = / y a r n / . test ( process . env . npm_execpath )
20+ ? 'yarn'
21+ : process . env . PNPM_PACKAGE_NAME
22+ ? 'pnpm'
23+ : 'npm' ;
2624
2725 prompts . intro (
2826 kl . trueColor ( ...brandColor ) (
@@ -214,7 +212,7 @@ async function templateDir(from, to, useTS) {
214212
215213/**
216214 * @param {string } to
217- * @param {import('@antfu/install-pkg').Agent } packageManager
215+ * @param {'yarn' | 'pnpm' | 'npm' } packageManager
218216 * @param {ConfigOptions } opts
219217 */
220218async function installDeps ( to , packageManager , opts ) {
@@ -223,15 +221,34 @@ async function installDeps(to, packageManager, opts) {
223221
224222 const installOpts = {
225223 packageManager,
226- cwd : to ,
227- silent : true ,
228- }
224+ to,
225+ } ;
229226
230227 if ( opts . useTS ) devDependencies . push ( 'typescript' ) ;
231228 if ( opts . useRouter ) dependencies . push ( 'preact-iso' ) ;
232229 if ( opts . usePrerender ) dependencies . push ( 'preact-iso' , 'preact-render-to-string' )
233230 if ( opts . useESLint ) devDependencies . push ( 'eslint' , 'eslint-config-preact' ) ;
234231
235- await installPackage ( dependencies , { ...installOpts } ) ;
236- devDependencies . length && installPackage ( devDependencies , { ...installOpts , dev : true } ) ;
232+ await installPackages ( dependencies , { ...installOpts } ) ;
233+ devDependencies . length && installPackages ( devDependencies , { ...installOpts , dev : true } ) ;
234+ }
235+
236+ /**
237+ * @param {string[] } pkgs
238+ * @param {{ packageManager: 'yarn' | 'pnpm' | 'npm', to: string, dev?: boolean } } opts
239+ */
240+ function installPackages ( pkgs , opts ) {
241+ return execa (
242+ opts . packageManager ,
243+ [
244+ // `yarn add` will fail if nothing is provided
245+ opts . packageManager === 'yarn' ? ( pkgs . length ? 'add' : '' ) : 'install' ,
246+ opts . dev ? '-D' : '' ,
247+ ...pkgs ,
248+ ] . filter ( Boolean ) ,
249+ {
250+ stdio : 'ignore' ,
251+ cwd : opts . to ,
252+ } ,
253+ ) ;
237254}
0 commit comments