Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple unicodes #61

Merged
merged 2 commits into from
Jan 27, 2024
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
3 changes: 3 additions & 0 deletions fixtures/projects/npmjs.com/package.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
provides:
- bin/npm

dependencies:
unicode.org: ^73
3 changes: 3 additions & 0 deletions fixtures/projects/python.org/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ interprets:

platforms:
- darwin

dependencies:
unicode.org: ^71
Empty file.
48 changes: 47 additions & 1 deletion src/plumbing/hydrate.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "deno/assert/mod.ts"
import { assert, assertEquals, assertRejects } from "deno/assert/mod.ts"
import { describe, it } from "deno/testing/bdd.ts"
import { PackageRequirement } from "../types.ts"
import * as semver from "../utils/semver.ts"
Expand Down Expand Up @@ -80,4 +80,50 @@ describe("hydrate()", () => {

assertEquals(nodes, 1)
})

it("hydrates.unicode.org", async function() {
const pkgs = [
{ project: 'npmjs.com', constraint: new semver.Range('*') },
{ project: 'python.org', constraint: new semver.Range('~3.9') }
]

const rv = await hydrate(pkgs, (pkg: PackageRequirement, _dry: boolean) => {
if (pkg.project === 'python.org') {
return Promise.resolve([
{ project: 'unicode.org', constraint: new semver.Range('^73') }
])
} else {
return Promise.resolve([
{ project: 'unicode.org', constraint: new semver.Range('^71') }
])
}
})

const unicodes = rv.pkgs.filter(x => x.project === 'unicode.org')
const constraints = new Set(unicodes.map(x => x.constraint.toString()))
assertEquals(constraints.size, 2)
assert(constraints.has("^71"))
assert(constraints.has("^73"))
})

it("hydrates.cannot-intersect", async function() {
const pkgs = [
{ project: 'npmjs.com', constraint: new semver.Range('*') },
{ project: 'python.org', constraint: new semver.Range('~3.9') }
]

const rv = hydrate(pkgs, (pkg: PackageRequirement, _dry: boolean) => {
if (pkg.project === 'python.org') {
return Promise.resolve([
{ project: 'nodejs.com', constraint: new semver.Range('^73') }
])
} else {
return Promise.resolve([
{ project: 'nodejs.com', constraint: new semver.Range('^71') }
])
}
})

await assertRejects(() => rv)
})
})
20 changes: 18 additions & 2 deletions src/plumbing/hydrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export default async function hydrate(
const initial_set = new Set(dry.map(x => x.project))
const stack: Node[] = []

const additional_unicodes: semver.Range[] = []

// Starting the DFS loop for each package in the dry list
for (const pkg of dry) {
let new_node = graph[pkg.project]
Expand All @@ -80,8 +82,19 @@ export default async function hydrate(
} else {
let child_node = graph[dep.project]
if (child_node) {
// Intersect constraints
child_node.pkg.constraint = semver.intersect(child_node.pkg.constraint, dep.constraint)
try {
// Intersect constraints
child_node.pkg.constraint = semver.intersect(child_node.pkg.constraint, dep.constraint)
} catch (e) {
if (dep.project == 'unicode.org') {
// we handle unicode.org for now to allow situations like:
// https://github.com/pkgxdev/pantry/issues/4104
// https://github.com/pkgxdev/pkgx/issues/899
additional_unicodes.push(dep.constraint)
} else {
throw e
}
}
} else {
child_node = new Node(dep, current_node)
graph[dep.project] = child_node
Expand All @@ -98,6 +111,9 @@ export default async function hydrate(
.sort((a, b) => b.count() - a.count())
.map(({pkg}) => pkg)

// see above explanation
pkgs.push(...additional_unicodes.map(constraint => ({ project: "unicode.org", constraint })))

//TODO strictly we need to record precisely the bootstrap version constraint
const bootstrap_required = new Set(pkgs.compact(({project}) => bootstrap.has(project) && project))

Expand Down
10 changes: 6 additions & 4 deletions src/utils/flock.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ export async function flock(path: Path) {
// ^^ write is also necessary
}

const { rid: fd } = await Deno.open(path.string, opts)
await Deno.flock(fd, true)
const file = await Deno.open(path.string, opts)
// denolint-disable-next-line deno-deprecated-deno-api
await Deno.flock(file.rid, true)

return async () => {
try {
await Deno.funlock(fd)
// denolint-disable-next-line deno-deprecated-deno-api
await Deno.funlock(file.rid)
} finally {
Deno.close(fd)
file.close()
}
if (Deno.build.os == 'windows') path.rm()
}
Expand Down
Loading