@@ -23,7 +23,7 @@ async function editPackageJson(location: string, name: string) {
23
23
return result . isOk ( ) ;
24
24
}
25
25
26
- async function installDeps ( location : string , pm : string , verbose : boolean ) {
26
+ async function installDeps ( location : string , pm : 'npm' | 'Yarn' | 'pnpm' , verbose : boolean ) {
27
27
const value = await execa ( pm . toLowerCase ( ) , [ 'install' ] , {
28
28
stdio : verbose ? 'inherit' : undefined ,
29
29
cwd : `./${ location } /`
@@ -33,10 +33,18 @@ async function installDeps(location: string, pm: string, verbose: boolean) {
33
33
throw new Error ( 'An unknown error occurred while installing the dependencies. Try running Sapphire CLI with "--verbose" flag.' ) ;
34
34
}
35
35
36
- const oppositeLockfile = `./${ location } /${ pm === 'npm' ? 'yarn.lock' : 'package-lock.json' } ` ;
36
+ const oppositeLockfiles = {
37
+ npm : [ 'yarn.lock' , 'pnpm-lock.yaml' ] ,
38
+ yarn : [ 'package-lock.json' , 'pnpm-lock.yaml' ] ,
39
+ pnpm : [ 'package-lock.json' , 'yarn.lock' ]
40
+ } as const ;
37
41
38
- if ( await fileExists ( oppositeLockfile ) ) {
39
- await rm ( oppositeLockfile ) ;
42
+ const lockfiles = pm === 'npm' ? oppositeLockfiles . npm : pm === 'Yarn' ? oppositeLockfiles . yarn : oppositeLockfiles . pnpm ;
43
+
44
+ for ( const lockfile of lockfiles ) {
45
+ if ( await fileExists ( lockfile ) ) {
46
+ await rm ( lockfile ) ;
47
+ }
40
48
}
41
49
42
50
return true ;
@@ -103,7 +111,7 @@ async function cloneRepo(location: string, verbose: boolean) {
103
111
}
104
112
105
113
export default async ( name : string , flags : Record < string , boolean > ) => {
106
- const response = await prompts < PromptNewObjectKeys > ( PromptNew ( name , await CommandExists ( 'yarn' ) ) ) ;
114
+ const response = await prompts < PromptNewObjectKeys > ( PromptNew ( name , await CommandExists ( 'yarn' ) , await CommandExists ( 'pnpm' ) ) ) ;
107
115
108
116
if ( ! response . projectName || ! response . projectLang || ! response . projectTemplate || ! response . packageManager ) {
109
117
process . exit ( 1 ) ;
@@ -130,6 +138,10 @@ export default async (name: string, flags: Record<string, boolean>) => {
130
138
) ;
131
139
132
140
await editPackageJson ( response . projectName , projectName ) ;
141
+
142
+ if ( response . packageManager === 'pnpm' ) {
143
+ await writeFile ( `./${ response . projectName } /.npmrc` , '# pnpm only\nshamefully-hoist=true\npublic-hoist-pattern[]=@sapphire/*' ) ;
144
+ }
133
145
} ;
134
146
135
147
const jobs : [ ( ) => any , string ] [ ] = [
0 commit comments