diff --git a/deno.json b/deno.json index e6d5329..0d75dbe 100644 --- a/deno.json +++ b/deno.json @@ -12,7 +12,7 @@ }, "pkgx": "deno^1.33.3 npm", "tasks": { - "test": "deno test --parallel --unstable -A", + "test": "deno test --parallel --unstable --allow-env --allow-read --allow-net=dist.pkgx.dev,github.com,codeload.github.com --allow-write --allow-run=tar,uname,/bin/sh,foo,'C:\\Windows\\system32\\cmd.exe'", "typecheck": "deno check --unstable ./mod.ts", "dnt": ".github/deno-to-node.ts" }, diff --git a/src/hooks/useConfig.ts b/src/hooks/useConfig.ts index 2edb24c..3305802 100644 --- a/src/hooks/useConfig.ts +++ b/src/hooks/useConfig.ts @@ -19,43 +19,42 @@ export interface Config { git?: Path } -function platform_cache_default() { +function platform_cache_default(home: Path, { LOCALAPPDATA }: { LOCALAPPDATA?: string }) { switch (Deno.build.os) { case 'darwin': - return Path.home().join('Library/Caches') + return home.join('Library/Caches') case 'windows': - return flatmap(Deno.env.get("LOCALAPPDATA"), Path.abs) ?? Path.home().join('AppData/Local') + return flatmap(LOCALAPPDATA, Path.abs) ?? home.join('AppData/Local') default: - return Path.home().join('.cache') + return home.join('.cache') } } -function platform_data_home_default() { +function platform_data_home_default(home: Path, { LOCALAPPDATA }: { LOCALAPPDATA?: string }) { switch (host().platform) { case 'darwin': - return Path.home().join("Library/Application Support") + return home.join("Library/Application Support") case 'windows': { - const LOCALAPPDATA = Deno.env.get('LOCALAPPDATA') if (LOCALAPPDATA) { - return new Path(LOCALAPPDATA).join("pkgx") + return new Path(LOCALAPPDATA) } else { - return Path.home().join("AppData/Local/pkgx") + return home.join("AppData/Local") }} default: - return Path.home().join(".local/share") + return home.join(".local/share") } } const SEP = Deno.build.os == 'windows' ? ';' : ':' export function ConfigDefault(env = Deno.env.toObject()): Config { - const prefix = flatmap(env['PKGX_DIR']?.trim(), x => new Path(x)) ?? Path.home().join('.pkgx') + const home = flatmap(env['PKGX_HOME'], x => new Path(x)) ?? Path.home() + const prefix = flatmap(env['PKGX_DIR']?.trim(), x => new Path(x)) ?? home.join('.pkgx') const pantries = env['PKGX_PANTRY_PATH']?.split(SEP).compact(x => flatmap(x.trim(), x => Path.abs(x) ?? Path.cwd().join(x))) ?? [] - const cache = (flatmap(env["XDG_CACHE_HOME"], Path.abs) ?? platform_cache_default()).join("pkgx") - const data = (flatmap(env["XDG_DATA_HOME"], Path.abs) ?? platform_data_home_default()).join("pkgx") + const cache = (flatmap(env["XDG_CACHE_HOME"], Path.abs) ?? platform_cache_default(home, env)).join("pkgx") + const data = (flatmap(env["XDG_DATA_HOME"], Path.abs) ?? platform_data_home_default(home, env)).join("pkgx") const isCI = boolize(env['CI']) ?? false const UserAgent = flatmap(getv(), v => `libpkgx/${v}`) ?? 'libpkgx' - //TODO prefer 'xz' on Linux (as well) if supported const compression = !isCI && host().platform == 'darwin' ? 'xz' : 'gz' diff --git a/src/hooks/useTestConfig.ts b/src/hooks/useTestConfig.ts index 9d827f8..87baa8e 100644 --- a/src/hooks/useTestConfig.ts +++ b/src/hooks/useTestConfig.ts @@ -6,10 +6,7 @@ export function useBaseTestConfig(env?: Record) { env ??= {} /// always prefer a new prefix - env.HOME ??= Path.mktemp().string - env.PKGX_DIR ??= Path.mktemp().string - env.XDG_DATA_HOME ??= Path.mktemp().string - env.XDG_CACHE_HOME ??= Path.mktemp().string + env.PKGX_HOME ??= Path.mktemp().string const config = ConfigDefault(env) if ('UserAgent' in env) { diff --git a/src/plumbing/resolve.test.ts b/src/plumbing/resolve.test.ts index 52dc448..ac4e3b2 100644 --- a/src/plumbing/resolve.test.ts +++ b/src/plumbing/resolve.test.ts @@ -11,7 +11,7 @@ import SemVer from "../utils/semver.ts" import Path from "../utils/Path.ts" Deno.test("resolve cellar.has", { - permissions: {'read': true, 'env': ["TMPDIR", "TMP", "TEMP", "HOME"], 'write': [Deno.env.get("TMPDIR") || Deno.env.get("TMP") || Deno.env.get("TEMP") || "/tmp"] } + permissions: {'read': true, 'env': ["TMPDIR", "TMP", "TEMP"], 'write': [Deno.env.get("TMPDIR") || Deno.env.get("TMP") || Deno.env.get("TEMP") || "/tmp"] } }, async runner => { const prefix = useTestConfig().prefix const pkg = { project: "foo", version: new SemVer("1.0.0") } diff --git a/src/utils/semver.test.ts b/src/utils/semver.test.ts index 90a5d23..bdae291 100644 --- a/src/utils/semver.test.ts +++ b/src/utils/semver.test.ts @@ -258,6 +258,17 @@ Deno.test("semver", async test => { // const c = semver.intersect(a, b) // assertEquals(c.toString(), "^11.3,^12.2") // }) + + /* https://github.com/pkgxdev/libpkgx/issues/42 */ + await test.step(">=1<1.0.19", async test => { + await test.step("1", () => { new semver.Range(">=1<1.0.19") }) + await test.step("2", () => { new semver.Range(">=1.0<1.0.19") }) + await test.step("3", () => { + assertEquals(new semver.Range(">=1<2").toString(), "^1") + }) + + assert(new SemVer("1").lt(new SemVer("1.0.19")), "1.0.0 is less than 1.0.19") + }) }) }) diff --git a/src/utils/semver.ts b/src/utils/semver.ts index 5486fbe..4eff91a 100644 --- a/src/utils/semver.ts +++ b/src/utils/semver.ts @@ -330,8 +330,10 @@ function zip(a: T[], b: U[]) { function _compare(a: SemVer, b: SemVer): number { - for (const [c,d] of zip(cmpcomponents(a), cmpcomponents(b))) { - if (c != d) return (c ?? 0) - (d ?? 0) + for (let [c,d] of zip(cmpcomponents(a), cmpcomponents(b))) { + c ??= 0 + d ??= 0 + if (c !== d) return c - d } return 0