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: add deno as package manager #25

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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],
Comment on lines +64 to +65
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually not true yet, we plan to add these commands in Deno v2.1 later in November.

'execute': ['deno', 'run', 0],
'execute-local': ['deno', 'run', 0],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the same command is used here for execute and execute-local, which means this isn't working in in the Svelte CLI: sveltejs/cli#313 (review). Does Deno have some equivalent to pnpm exec or should we make a feature request for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops, my bad. We currently have no way to do it, so a feature request would be helpful. I think we could handle that with deno task --eval so it uses cross-platform shell.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, filed a request here: denoland/deno#26918

'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": "bun",
"name": "bun",
"version": "0",
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved
}
`;

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": "bun",
"name": "bun",
"version": "0",
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved
}
`;

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"
}
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