Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for deno install #74

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Install dependencies after cloning template.
npm create hono@latest ./my-app -- --install
```

### `-p, --pm <pnpm|bun|npm|yarn>`
### `-p, --pm <pnpm|bun|deno|npm|yarn>`

Allows you to specify which package manager to use.

Expand Down
14 changes: 13 additions & 1 deletion src/hooks/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import { execa } from 'execa'
import { createSpinner } from 'nanospinner'
import { projectDependenciesHook } from '../hook'

type PackageManager = 'npm' | 'bun' | 'pnpm' | 'yarn'
type PackageManager = 'npm' | 'bun' | 'deno' | 'pnpm' | 'yarn'

const knownPackageManagers: { [key: string]: string } = {
npm: 'npm install',
bun: 'bun install',
deno: 'deno install',
pnpm: 'pnpm install',
yarn: 'yarn',
}
Expand Down Expand Up @@ -44,6 +45,16 @@ const registerInstallationHook = (

// hide install dependencies option if no package manager is installed
if (!installedPackageManagerNames.length) return
// If version 1 of Deno is installed, it will not be suggested because it doesn't have "deno install".
if (installedPackageManagerNames.includes('deno')) {
const { stdout } = await execa('deno', ['-v'])
if (stdout.split(' ')[1].split('.')[0] == '1') {
installedPackageManagerNames.splice(
installedPackageManagerNames.indexOf('deno'),
1,
)
}
}

if (typeof installArg === 'boolean') {
installDeps = installArg
Expand Down Expand Up @@ -106,6 +117,7 @@ function getCurrentPackageManager(): PackageManager {
const agent = process.env.npm_config_user_agent || 'npm' // Types say it might be undefined, just being cautious;

if (agent.startsWith('bun')) return 'bun'
if (agent.startsWith('deno')) return 'deno'
if (agent.startsWith('pnpm')) return 'pnpm'
if (agent.startsWith('yarn')) return 'yarn'

Expand Down