Skip to content

Commit

Permalink
feat: add deno as package manager (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju authored Nov 14, 2024
1 parent d865517 commit aa946f3
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ const bun: AgentCommands = {
'global_uninstall': ['bun', 'remove', '-g', 0],
}

const deno: AgentCommands = {
'agent': ['deno', 0],
'run': ['deno', 'run', 0],
'install': ['deno', 'install', 0],
'frozen': ['deno', 'install', '--frozen'],
'global': ['deno', 'install', '-g', 0],
'add': ['deno', 'add', 0],
'upgrade': ['deno', 'update', 0],
'upgrade-interactive': ['deno', 'update', 0],
'execute': ['deno', 'run', 0],
'execute-local': ['deno', 'run', 0],
'uninstall': ['deno', 'remove', 0],
'global_uninstall': ['deno', 'uninstall', '-g', 0],
}

export const COMMANDS = {
'npm': <AgentCommands>{
'agent': ['npm', 0],
Expand Down Expand Up @@ -88,6 +103,7 @@ export const COMMANDS = {
run: npmRun('pnpm'),
},
'bun': bun,
'deno': deno,
} satisfies Record<Agent, AgentCommands>

/**
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ export const AGENTS: Agent[] = [
'pnpm',
'pnpm@6',
'bun',
'deno',
]

// the order here matters, more specific one comes first
export const LOCKS: Record<string, AgentName> = {
'bun.lockb': 'bun',
'deno.lock': 'deno',
'pnpm-lock.yaml': 'pnpm',
'yarn.lock': 'yarn',
'package-lock.json': 'npm',
Expand All @@ -20,6 +22,7 @@ export const LOCKS: Record<string, AgentName> = {

export const INSTALL_PAGE: Record<Agent, string> = {
'bun': 'https://bun.sh',
'deno': 'https://deno.com',
'pnpm': 'https://pnpm.io/installation',
'pnpm@6': 'https://pnpm.io/6.x/installation',
'yarn': 'https://classic.yarnpkg.com/en/docs/install',
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type Agent = 'npm' | 'yarn' | 'yarn@berry' | 'pnpm' | 'pnpm@6' | 'bun'
export type AgentName = 'npm' | 'yarn' | 'pnpm' | 'bun'
export type Agent = 'npm' | 'yarn' | 'yarn@berry' | 'pnpm' | 'pnpm@6' | 'bun' | 'deno'
export type AgentName = 'npm' | 'yarn' | 'pnpm' | 'bun' | 'deno'

export type AgentCommandValue = (string | number)[] | ((args?: string[]) => string[]) | null

Expand Down Expand Up @@ -48,7 +48,7 @@ export interface DetectResult {
/**
* Agent name without the specifier.
*
* Can be `npm`, `yarn`, `pnpm`, or `bun`.
* Can be `npm`, `yarn`, `pnpm`, `bun`, or `deno`.
*/
name: AgentName
/**
Expand Down
22 changes: 22 additions & 0 deletions test/__snapshots__/command.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ exports[`test bun run command > command handles args correctly 1`] = `
}
`;

exports[`test deno add command > command handles args correctly 1`] = `
{
"args": [
"add",
"@antfu/ni",
"-D",
],
"command": "deno",
}
`;

exports[`test deno run command > command handles args correctly 1`] = `
{
"args": [
"run",
"arg0",
"arg1-0 arg1-1",
],
"command": "deno",
}
`;

exports[`test npm add command > command handles args correctly 1`] = `
{
"args": [
Expand Down
15 changes: 15 additions & 0 deletions test/__snapshots__/detect-sync.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ exports[`lockfile > bun 1`] = `
}
`;

exports[`lockfile > deno 1`] = `
{
"agent": "deno",
"name": "deno",
}
`;

exports[`lockfile > npm 1`] = `
{
"agent": "npm",
Expand Down Expand Up @@ -52,6 +59,14 @@ exports[`packager > bun 1`] = `
}
`;

exports[`packager > deno 1`] = `
{
"agent": "deno",
"name": "deno",
"version": "2",
}
`;

exports[`packager > npm 1`] = `
{
"agent": "npm",
Expand Down
15 changes: 15 additions & 0 deletions test/__snapshots__/detect.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ exports[`lockfile > bun 1`] = `
}
`;

exports[`lockfile > deno 1`] = `
{
"agent": "deno",
"name": "deno",
}
`;

exports[`lockfile > npm 1`] = `
{
"agent": "npm",
Expand Down Expand Up @@ -52,6 +59,14 @@ exports[`packager > bun 1`] = `
}
`;

exports[`packager > deno 1`] = `
{
"agent": "deno",
"name": "deno",
"version": "2",
}
`;

exports[`packager > npm 1`] = `
{
"agent": "npm",
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions test/fixtures/packager/deno/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"packageManager": "deno@2"
}
1 change: 1 addition & 0 deletions test/user-agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('get user agent', () => {
['yarn', 'yarn/1.22.11 npm/? node/v14.17.6 darwin x64'],
['pnpm', 'pnpm/9.12.1 npm/? node/v20.17.0 linux x64'],
['bun', 'bun/1.1.8 npm/? node/v21.6.0 linux x64'],
['deno', 'deno/2.0.5 npm/? node/v21.6.0 linux x64'],
].forEach(([agent, detection]) => {
it(`${agent} detected with ${detection}`, () => {
vi.stubEnv(
Expand Down

0 comments on commit aa946f3

Please sign in to comment.