diff --git a/.github/workflows/autofix.yml b/.github/workflows/autofix.yml index feba346..0024eb3 100644 --- a/.github/workflows/autofix.yml +++ b/.github/workflows/autofix.yml @@ -15,6 +15,9 @@ jobs: - uses: actions/checkout@v4 - run: corepack enable - uses: oven-sh/setup-bun@v2 + - uses: denoland/setup-deno@v2 + with: + deno-version: v2.x - uses: actions/setup-node@v4 with: node-version: 18 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c69a5ee..97d23f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,9 @@ jobs: - run: corepack enable - uses: oven-sh/setup-bun@v2 if: ${{ matrix.os != 'windows-latest' }} + - uses: denoland/setup-deno@v2 + with: + deno-version: v2.x - uses: actions/setup-node@v4 with: node-version: 18 diff --git a/src/_utils.ts b/src/_utils.ts index 515796a..1dc61cf 100644 --- a/src/_utils.ts +++ b/src/_utils.ts @@ -51,7 +51,10 @@ export async function executeCommand( options: Pick = {}, ): Promise { const xArgs: [string, string[]] = - command === "npm" || command === "bun" || !(await hasCorepack()) + command === "npm" || + command === "bun" || + command === "deno" || + !(await hasCorepack()) ? [command, args] : ["corepack", [command, ...args]]; diff --git a/src/api.ts b/src/api.ts index 1c1fce1..b1ce855 100644 --- a/src/api.ts +++ b/src/api.ts @@ -29,6 +29,7 @@ export async function installDependencies( yarn: ["install", "--immutable"], bun: ["install", "--frozen-lockfile"], pnpm: ["install", "--frozen-lockfile"], + deno: ["install", "--frozen"], }; const commandArgs = options.frozenLockFile @@ -61,6 +62,14 @@ export async function addDependency( const names = Array.isArray(name) ? name : [name]; + if (resolvedOptions.packageManager.name === "deno") { + for (let i = 0; i < names.length; i++) { + if (!/^(npm|jsr|file):.+$/.test(names[i])) { + names[i] = `npm:${names[i]}`; + } + } + } + // TOOD: we might filter for empty values too for more safety if (names.length === 0) { return; diff --git a/src/package-manager.ts b/src/package-manager.ts index 7f3a6cf..95a9860 100644 --- a/src/package-manager.ts +++ b/src/package-manager.ts @@ -62,6 +62,12 @@ export const packageManagers: PackageManager[] = [ lockFile: "yarn.lock", files: [".yarnrc.yml"], }, + { + name: "deno", + command: "deno", + lockFile: "deno.lock", + files: ["deno.json"], + }, ] as const; /** @@ -78,7 +84,7 @@ export async function detectPackageManager( const detected = await findup( resolve(cwd || "."), async (path) => { - // 1. Use `packageManager` field from package.json + // 1. Use `packageManager` field from package.json / deno.json if (!options.ignorePackageJSON) { const packageJSONPath = join(path, "package.json"); if (existsSync(packageJSONPath)) { @@ -102,6 +108,11 @@ export async function detectPackageManager( }; } } + + const denoJSONPath = join(path, "deno.json"); + if (existsSync(denoJSONPath)) { + return packageManagers.find((pm) => pm.name === "deno"); + } } // 2. Use implicit file detection diff --git a/src/types.ts b/src/types.ts index b0441a9..c088cb1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -export type PackageManagerName = "npm" | "yarn" | "pnpm" | "bun"; +export type PackageManagerName = "npm" | "yarn" | "pnpm" | "bun" | "deno"; export type PackageManager = { name: PackageManagerName; diff --git a/test/_shared.ts b/test/_shared.ts index a11d182..db27aa0 100644 --- a/test/_shared.ts +++ b/test/_shared.ts @@ -13,6 +13,14 @@ export type Fixture = { export const fixtures = ( [ + { + name: "deno", + packageManager: "deno", + }, + { + name: "deno-workspace", + packageManager: "deno", + }, { name: "bun", packageManager: "bun", diff --git a/test/fixtures/deno-workspace/deno.json b/test/fixtures/deno-workspace/deno.json new file mode 100644 index 0000000..bad0408 --- /dev/null +++ b/test/fixtures/deno-workspace/deno.json @@ -0,0 +1,3 @@ +{ + "imports": { "consola": "npm:consola@3.2.2" } +} diff --git a/test/fixtures/deno-workspace/deno.lock b/test/fixtures/deno-workspace/deno.lock new file mode 100644 index 0000000..9c42cbd --- /dev/null +++ b/test/fixtures/deno-workspace/deno.lock @@ -0,0 +1,21 @@ +{ + "version": "4", + "specifiers": { + "npm:consola@3.2.2": "3.2.2" + }, + "npm": { + "consola@3.2.2": { + "integrity": "sha512-r921u0vbF4lQsoIqYvSSER+yZLPQGijOHrYcWoCNVNBZmn/bRR+xT/DgerTze/nLD9TTGzdDa378TVhx7RDOYg==" + } + }, + "workspace": { + "dependencies": [ + "npm:consola@3.2.2" + ], + "packageJson": { + "dependencies": [ + "npm:consola@3.2.2" + ] + } + } +} diff --git a/test/fixtures/deno-workspace/package.json b/test/fixtures/deno-workspace/package.json new file mode 100644 index 0000000..7f74bbe --- /dev/null +++ b/test/fixtures/deno-workspace/package.json @@ -0,0 +1,7 @@ +{ + "name": "fixture-deno-workspace", + "private": true, + "dependencies": { + "consola": "3.2.2" + } +} diff --git a/test/fixtures/deno-workspace/packages/workspace-a/package.json b/test/fixtures/deno-workspace/packages/workspace-a/package.json new file mode 100644 index 0000000..418f008 --- /dev/null +++ b/test/fixtures/deno-workspace/packages/workspace-a/package.json @@ -0,0 +1,6 @@ +{ + "name": "workspace-a", + "version": "0.0.0", + "private": true, + "dependencies": {} +} diff --git a/test/fixtures/deno/deno.json b/test/fixtures/deno/deno.json new file mode 100644 index 0000000..bad0408 --- /dev/null +++ b/test/fixtures/deno/deno.json @@ -0,0 +1,3 @@ +{ + "imports": { "consola": "npm:consola@3.2.2" } +} diff --git a/test/fixtures/deno/deno.lock b/test/fixtures/deno/deno.lock new file mode 100644 index 0000000..9c42cbd --- /dev/null +++ b/test/fixtures/deno/deno.lock @@ -0,0 +1,21 @@ +{ + "version": "4", + "specifiers": { + "npm:consola@3.2.2": "3.2.2" + }, + "npm": { + "consola@3.2.2": { + "integrity": "sha512-r921u0vbF4lQsoIqYvSSER+yZLPQGijOHrYcWoCNVNBZmn/bRR+xT/DgerTze/nLD9TTGzdDa378TVhx7RDOYg==" + } + }, + "workspace": { + "dependencies": [ + "npm:consola@3.2.2" + ], + "packageJson": { + "dependencies": [ + "npm:consola@3.2.2" + ] + } + } +} diff --git a/test/fixtures/deno/package.json b/test/fixtures/deno/package.json new file mode 100644 index 0000000..24e5238 --- /dev/null +++ b/test/fixtures/deno/package.json @@ -0,0 +1,7 @@ +{ + "name": "fixture-deno", + "private": true, + "dependencies": { + "consola": "3.2.2" + } +}