Skip to content

Commit

Permalink
feat: support for deno install (#74)
Browse files Browse the repository at this point in the history
* feat: support for `deno install`

* docs: add deno

* chore: add Deno to current package manager candidates

* chore: clarify a comment
  • Loading branch information
ryuapp authored Oct 10, 2024
1 parent a6f3993 commit db904ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit db904ba

Please sign in to comment.