Skip to content

Commit

Permalink
Only detect version for expected package manager (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x80 authored Jun 9, 2024
1 parent d14f61c commit 95715a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@ on:
jobs:
everything:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18]
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v4
with:
version: 8
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
node-version: 20
cache: "pnpm"
- name: Install dependencies
run: pnpm install
Expand Down
13 changes: 10 additions & 3 deletions src/lib/package-manager/helpers/infer-from-files.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "fs-extra";
import { execSync } from "node:child_process";
import path from "node:path";
import { getErrorMessage } from "~/lib/utils";
import { getMajorVersion } from "~/lib/utils/get-major-version";
import type { PackageManager, PackageManagerName } from "../names";
import { getLockfileFileName, supportedPackageManagerNames } from "../names";
Expand All @@ -9,10 +10,16 @@ export function inferFromFiles(workspaceRoot: string): PackageManager {
for (const name of supportedPackageManagerNames) {
const lockfileName = getLockfileFileName(name);

const version = getVersion(name);

if (fs.existsSync(path.join(workspaceRoot, lockfileName))) {
return { name, version, majorVersion: getMajorVersion(version) };
try {
const version = getVersion(name);

return { name, version, majorVersion: getMajorVersion(version) };
} catch (err) {
throw new Error(
`Failed to find package manager version for ${name}: ${getErrorMessage(err)}`
);
}
}
}

Expand Down

0 comments on commit 95715a1

Please sign in to comment.