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

Commit

Permalink
refactor: detect packageManager using sink helper
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jul 22, 2022
1 parent 5277912 commit d74b209
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 20 deletions.
6 changes: 3 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { tasks } from './Tasks'
import { greet } from './src/Chalk/greet'
import { showArt } from './src/Chalk/art'
import { getHelp } from './src/Chalk/help'
import { getState, packageManager } from './src/Helpers'
import { getState } from './src/Helpers'

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

Expand All @@ -58,7 +58,7 @@ export async function runTasks(args: string[]) {
* Setup state
*/
const state = await getState(projectPath, {
client: packageManager,
client: utils.getPackageManager(projectPath),
projectName: argv.name,
debug: argv.debug,
boilerplate: argv.boilerplate,
Expand Down
3 changes: 1 addition & 2 deletions src/Chalk/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
*/

import { logger } from '@adonisjs/sink'
import type { SupportedPackageManager } from '../Helpers'

/**
* Text to show on the help screen. Its simple and hence writing it
* by hand is fine
*/
export const getHelp = (packageManager: SupportedPackageManager) => {
export const getHelp = (packageManager: 'npm' | 'pnpm' | 'yarn') => {
const runSentence =
packageManager === 'yarn'
? 'yarn create adonis-ts-app'
Expand Down
3 changes: 1 addition & 2 deletions src/Contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

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

/**
* Shape of task functions
Expand All @@ -27,7 +26,7 @@ export type CliState = {
baseName: string
absPath: string
debug: boolean
client: SupportedPackageManager
client: 'npm' | 'pnpm' | 'yarn'
boilerplate: 'web' | 'api' | 'slim'
projectName: string
eslint: boolean
Expand Down
14 changes: 1 addition & 13 deletions src/Helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function getState(
projectName?: string
eslint?: boolean
prettier?: boolean
client: SupportedPackageManager
client: 'npm' | 'pnpm' | 'yarn'
encore?: boolean
}
): Promise<CliState> {
Expand Down Expand Up @@ -196,15 +196,3 @@ export function getInstallMessage(list: string[]): string {

return dependencies.join(', ')
}

export type SupportedPackageManager = typeof packageManager

/**
* Detect what package manager is in used, fallback to npm.
*/
export const packageManager =
process.env.npm_execpath && process.env.npm_execpath.includes('yarn')
? 'yarn'
: process.env.npm_execpath && process.env.npm_execpath.includes('pnpm')
? 'pnpm'
: 'npm'

0 comments on commit d74b209

Please sign in to comment.