Skip to content

Commit

Permalink
tighter code
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Dec 2, 2022
1 parent 49cb0d6 commit e2976a4
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/hooks/useVirtualEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import useRequirementsFile, { RequirementsFile } from "./useRequirementsFile.ts"
import { PackageRequirement } from "types"
import SemVer, * as semver from "semver"
import { TeaError } from "utils"
import { flatmap, TeaError } from "utils"
import { useFlags } from "hooks"
import Path from "path"

Expand Down Expand Up @@ -65,11 +65,9 @@ export default async function useVirtualEnv(opts?: { cwd: Path }): Promise<Virtu

if (files.length < 1) throw new TeaError("not-found: virtual-env", ctx)

const { file, version: req_version } = files.find(x => x.file.basename() == "README.md") ?? files[0]
const { file, version: version_README } = files.find(x => x.file.basename() == "README.md") ?? files[0]

const version_file = srcroot.join("VERSION").isFile()

const version = version_file ? semver.parse(await version_file.read()) ?? req_version : req_version
const version = flatmap(srcroot.join("VERSION").isFile(), x => semver.parse(x.string)) ?? version_README

const pkgs = files.flatMap(x => x.pkgs)

Expand Down

0 comments on commit e2976a4

Please sign in to comment.