Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit d74b209

Browse files
committed
refactor: detect packageManager using sink helper
1 parent 5277912 commit d74b209

File tree

4 files changed

+6
-20
lines changed

4 files changed

+6
-20
lines changed

index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { tasks } from './Tasks'
1616
import { greet } from './src/Chalk/greet'
1717
import { showArt } from './src/Chalk/art'
1818
import { getHelp } from './src/Chalk/help'
19-
import { getState, packageManager } from './src/Helpers'
19+
import { getState } from './src/Helpers'
2020

2121
/**
2222
* Running all the tasks to create a new project.
@@ -42,7 +42,7 @@ export async function runTasks(args: string[]) {
4242
* Show help when no arguments are passed
4343
*/
4444
if (!argv._.length) {
45-
console.log(getHelp(packageManager))
45+
console.log(getHelp(utils.getPackageManager(process.cwd())))
4646
return
4747
}
4848

@@ -58,7 +58,7 @@ export async function runTasks(args: string[]) {
5858
* Setup state
5959
*/
6060
const state = await getState(projectPath, {
61-
client: packageManager,
61+
client: utils.getPackageManager(projectPath),
6262
projectName: argv.name,
6363
debug: argv.debug,
6464
boilerplate: argv.boilerplate,

src/Chalk/help.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
*/
99

1010
import { logger } from '@adonisjs/sink'
11-
import type { SupportedPackageManager } from '../Helpers'
1211

1312
/**
1413
* Text to show on the help screen. Its simple and hence writing it
1514
* by hand is fine
1615
*/
17-
export const getHelp = (packageManager: SupportedPackageManager) => {
16+
export const getHelp = (packageManager: 'npm' | 'pnpm' | 'yarn') => {
1817
const runSentence =
1918
packageManager === 'yarn'
2019
? 'yarn create adonis-ts-app'

src/Contracts/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import { logger as sinkLogger, files } from '@adonisjs/sink'
1111
import { ApplicationContract } from '@ioc:Adonis/Core/Application'
12-
import type { SupportedPackageManager } from '../Helpers'
1312

1413
/**
1514
* Shape of task functions
@@ -27,7 +26,7 @@ export type CliState = {
2726
baseName: string
2827
absPath: string
2928
debug: boolean
30-
client: SupportedPackageManager
29+
client: 'npm' | 'pnpm' | 'yarn'
3130
boilerplate: 'web' | 'api' | 'slim'
3231
projectName: string
3332
eslint: boolean

src/Helpers/index.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function getState(
3030
projectName?: string
3131
eslint?: boolean
3232
prettier?: boolean
33-
client: SupportedPackageManager
33+
client: 'npm' | 'pnpm' | 'yarn'
3434
encore?: boolean
3535
}
3636
): Promise<CliState> {
@@ -196,15 +196,3 @@ export function getInstallMessage(list: string[]): string {
196196

197197
return dependencies.join(', ')
198198
}
199-
200-
export type SupportedPackageManager = typeof packageManager
201-
202-
/**
203-
* Detect what package manager is in used, fallback to npm.
204-
*/
205-
export const packageManager =
206-
process.env.npm_execpath && process.env.npm_execpath.includes('yarn')
207-
? 'yarn'
208-
: process.env.npm_execpath && process.env.npm_execpath.includes('pnpm')
209-
? 'pnpm'
210-
: 'npm'

0 commit comments

Comments
 (0)