Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
27 changes: 13 additions & 14 deletions src/hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
5 changes: 1 addition & 4 deletions src/hooks/useTestConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ export function useBaseTestConfig(env?: Record<string, string>) {
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/plumbing/resolve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
Expand Down
11 changes: 11 additions & 0 deletions src/utils/semver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})
})

Expand Down
6 changes: 4 additions & 2 deletions src/utils/semver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,10 @@ function zip<T, U>(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

Expand Down