Skip to content

Commit

Permalink
feat: experimental support for deno v2 (#158)
Browse files Browse the repository at this point in the history
* feat: add initial support for deno

* fix: deno implementation

* style: consistent pm properties

Co-authored-by: Horu <73709188+HigherOrderLogic@users.noreply.github.com>

* ci: setup deno

* ci: setup deno for autofix too

* lint

* remove majorVersion

---------

Co-authored-by: Horu <73709188+HigherOrderLogic@users.noreply.github.com>
Co-authored-by: Pooya Parsa <pooya@pi0.io>
  • Loading branch information
3 people authored Nov 26, 2024
1 parent 73193d6 commit c7448e4
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export async function executeCommand(
options: Pick<OperationOptions, "cwd" | "silent"> = {},
): Promise<void> {
const xArgs: [string, string[]] =
command === "npm" || command === "bun" || !(await hasCorepack())
command === "npm" ||
command === "bun" ||
command === "deno" ||
!(await hasCorepack())
? [command, args]
: ["corepack", [command, ...args]];

Expand Down
9 changes: 9 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 12 additions & 1 deletion src/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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)) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type PackageManagerName = "npm" | "yarn" | "pnpm" | "bun";
export type PackageManagerName = "npm" | "yarn" | "pnpm" | "bun" | "deno";

export type PackageManager = {
name: PackageManagerName;
Expand Down
8 changes: 8 additions & 0 deletions test/_shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ export type Fixture = {

export const fixtures = (
[
{
name: "deno",
packageManager: "deno",
},
{
name: "deno-workspace",
packageManager: "deno",
},
{
name: "bun",
packageManager: "bun",
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/deno-workspace/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"imports": { "consola": "npm:consola@3.2.2" }
}
21 changes: 21 additions & 0 deletions test/fixtures/deno-workspace/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions test/fixtures/deno-workspace/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "fixture-deno-workspace",
"private": true,
"dependencies": {
"consola": "3.2.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "workspace-a",
"version": "0.0.0",
"private": true,
"dependencies": {}
}
3 changes: 3 additions & 0 deletions test/fixtures/deno/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"imports": { "consola": "npm:consola@3.2.2" }
}
21 changes: 21 additions & 0 deletions test/fixtures/deno/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions test/fixtures/deno/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "fixture-deno",
"private": true,
"dependencies": {
"consola": "3.2.2"
}
}

0 comments on commit c7448e4

Please sign in to comment.