Skip to content

Commit fb759d6

Browse files
authored
Allow multiple unicodes (#61)
* Fixes pkgxdev/pantry#4104 * Refs pkgxdev/pkgx#899
1 parent fc63474 commit fb759d6

File tree

6 files changed

+77
-7
lines changed

6 files changed

+77
-7
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
provides:
22
- bin/npm
3+
4+
dependencies:
5+
unicode.org: ^73

fixtures/projects/python.org/package.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ interprets:
77

88
platforms:
99
- darwin
10+
11+
dependencies:
12+
unicode.org: ^71

fixtures/projects/unicode.org/package.yml

Whitespace-only changes.

src/plumbing/hydrate.test.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals } from "deno/assert/mod.ts"
1+
import { assert, assertEquals, assertRejects } from "deno/assert/mod.ts"
22
import { describe, it } from "deno/testing/bdd.ts"
33
import { PackageRequirement } from "../types.ts"
44
import * as semver from "../utils/semver.ts"
@@ -80,4 +80,50 @@ describe("hydrate()", () => {
8080

8181
assertEquals(nodes, 1)
8282
})
83+
84+
it("hydrates.unicode.org", async function() {
85+
const pkgs = [
86+
{ project: 'npmjs.com', constraint: new semver.Range('*') },
87+
{ project: 'python.org', constraint: new semver.Range('~3.9') }
88+
]
89+
90+
const rv = await hydrate(pkgs, (pkg: PackageRequirement, _dry: boolean) => {
91+
if (pkg.project === 'python.org') {
92+
return Promise.resolve([
93+
{ project: 'unicode.org', constraint: new semver.Range('^73') }
94+
])
95+
} else {
96+
return Promise.resolve([
97+
{ project: 'unicode.org', constraint: new semver.Range('^71') }
98+
])
99+
}
100+
})
101+
102+
const unicodes = rv.pkgs.filter(x => x.project === 'unicode.org')
103+
const constraints = new Set(unicodes.map(x => x.constraint.toString()))
104+
assertEquals(constraints.size, 2)
105+
assert(constraints.has("^71"))
106+
assert(constraints.has("^73"))
107+
})
108+
109+
it("hydrates.cannot-intersect", async function() {
110+
const pkgs = [
111+
{ project: 'npmjs.com', constraint: new semver.Range('*') },
112+
{ project: 'python.org', constraint: new semver.Range('~3.9') }
113+
]
114+
115+
const rv = hydrate(pkgs, (pkg: PackageRequirement, _dry: boolean) => {
116+
if (pkg.project === 'python.org') {
117+
return Promise.resolve([
118+
{ project: 'nodejs.com', constraint: new semver.Range('^73') }
119+
])
120+
} else {
121+
return Promise.resolve([
122+
{ project: 'nodejs.com', constraint: new semver.Range('^71') }
123+
])
124+
}
125+
})
126+
127+
await assertRejects(() => rv)
128+
})
83129
})

src/plumbing/hydrate.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export default async function hydrate(
5555
const initial_set = new Set(dry.map(x => x.project))
5656
const stack: Node[] = []
5757

58+
const additional_unicodes: semver.Range[] = []
59+
5860
// Starting the DFS loop for each package in the dry list
5961
for (const pkg of dry) {
6062
let new_node = graph[pkg.project]
@@ -80,8 +82,19 @@ export default async function hydrate(
8082
} else {
8183
let child_node = graph[dep.project]
8284
if (child_node) {
83-
// Intersect constraints
84-
child_node.pkg.constraint = semver.intersect(child_node.pkg.constraint, dep.constraint)
85+
try {
86+
// Intersect constraints
87+
child_node.pkg.constraint = semver.intersect(child_node.pkg.constraint, dep.constraint)
88+
} catch (e) {
89+
if (dep.project == 'unicode.org') {
90+
// we handle unicode.org for now to allow situations like:
91+
// https://github.com/pkgxdev/pantry/issues/4104
92+
// https://github.com/pkgxdev/pkgx/issues/899
93+
additional_unicodes.push(dep.constraint)
94+
} else {
95+
throw e
96+
}
97+
}
8598
} else {
8699
child_node = new Node(dep, current_node)
87100
graph[dep.project] = child_node
@@ -98,6 +111,9 @@ export default async function hydrate(
98111
.sort((a, b) => b.count() - a.count())
99112
.map(({pkg}) => pkg)
100113

114+
// see above explanation
115+
pkgs.push(...additional_unicodes.map(constraint => ({ project: "unicode.org", constraint })))
116+
101117
//TODO strictly we need to record precisely the bootstrap version constraint
102118
const bootstrap_required = new Set(pkgs.compact(({project}) => bootstrap.has(project) && project))
103119

src/utils/flock.deno.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ export async function flock(path: Path) {
1212
// ^^ write is also necessary
1313
}
1414

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

1819
return async () => {
1920
try {
20-
await Deno.funlock(fd)
21+
// denolint-disable-next-line deno-deprecated-deno-api
22+
await Deno.funlock(file.rid)
2123
} finally {
22-
Deno.close(fd)
24+
file.close()
2325
}
2426
if (Deno.build.os == 'windows') path.rm()
2527
}

0 commit comments

Comments
 (0)