Skip to content

Commit

Permalink
Fix hydrate edge cases (pkgxdev#419)
Browse files Browse the repository at this point in the history
* Fix hydrate edge cases

This depended on the order of passed pkgs and that we would skip dry nodes already processed.

Fixes pkgxdev#403

* wip
  • Loading branch information
mxcl authored Mar 1, 2023
1 parent 6e5612a commit df02b72
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 40 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ As a bonus the installer also updates tea.
## “Now see here fella’, I \*hate\* installers…”

Package managers can’t install themselves (`#cantfix`).
How about installing via `brew` or Docker instead?
But there’s other ways:

```sh
$ brew install teaxyz/pkgs/tea-cli
Expand All @@ -233,7 +233,7 @@ $ brew install teaxyz/pkgs/tea-cli
$ docker run --rm -it ghcr.io/teaxyz/infuser
```

> <details><summary><i>Other ways to install tea</i></summary><br>
> <details><summary><i>Even more ways to install tea</i></summary><br>
>
> Take your pick:
>
Expand Down Expand Up @@ -266,9 +266,11 @@ $ docker run --rm -it ghcr.io/teaxyz/infuser
# ^^ https://github.com/teaxyz/setup
```
Our action installs your deps and makes them (and tea) accessible to the rest
[Our action] installs your deps and makes them (and tea) accessible to the rest
of the workflow.

[Our action]: https://github.com/teaxyz/setup

&nbsp;


Expand Down
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"tea": {
"dependencies": {
"deno.land": "^1.30"
"deno.land": "^1.31.1"
}
},
"importMap": "import-map.json"
Expand Down
12 changes: 8 additions & 4 deletions src/prefab/hydrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default async function hydrate(
const ascend = async (node: Node, children: Set<string>) => {

for (const dep of await get_deps(node.pkg, initial_set.has(node.project))) {

if (children.has(dep.project)) {
if (!bootstrap.has(dep.project)) {
console.warn(`${dep.project} must be bootstrapped to build ${node.project}`)
Expand Down Expand Up @@ -93,10 +94,13 @@ export default async function hydrate(
}

for (const pkg of dry) {
if (pkg.project in graph) continue
const new_node = new Node(pkg)
graph[pkg.project] = new_node
await go(new_node)
if (pkg.project in graph) {
graph[pkg.project].pkg.constraint = semver.intersect(graph[pkg.project].pkg.constraint, pkg.constraint)
} else {
const new_node = new Node(pkg)
graph[pkg.project] = new_node
await go(new_node)
}
}

const pkgs = Object.values(graph)
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export enum Verbosity {

// when we support more variants of these that require specification
// we will tuple a version in with each eg. 'darwin' | ['windows', 10 | 11 | '*']
export const SupportedPlatforms = ["darwin", "linux", "windows"] as const
export const SupportedPlatforms = ["darwin" , "linux" , "windows" , "freebsd" , "netbsd" , "aix" , "solaris" , "illumos"] as const
export type SupportedPlatform = typeof SupportedPlatforms[number]

export const SupportedArchitectures = ["x86-64", "aarch64"] as const
Expand Down
31 changes: 0 additions & 31 deletions tests/integration/hydrate.test.ts

This file was deleted.

82 changes: 82 additions & 0 deletions tests/unit/hydrate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { assertEquals } from "deno/testing/asserts.ts"
import suite from "../integration.suite.ts"
import { PackageRequirement } from "types"
import * as semver from "utils/semver.ts"
import { it } from "deno/testing/bdd.ts"
import { hydrate } from "prefab"

it(suite, "hydrates.1", async function() {
const pkgs = [
{ project: 'nodejs.org', constraint: new semver.Range('*') },
{ project: 'nodejs.org', constraint: new semver.Range('>=18.14') }
]

const rv1 = semver.intersect(pkgs[0].constraint, pkgs[1].constraint)
assertEquals(rv1.toString(), '>=18.14')

const rv = await hydrate(pkgs, (_a: PackageRequirement, _b: boolean) => Promise.resolve([]))

let nodes = 0
for (const pkg of rv.pkgs) {
if (pkg.project === 'nodejs.org') {
nodes++
assertEquals(pkg.constraint.toString(), '>=18.14')
}
}

assertEquals(nodes, 1)
})

it(suite, "hydrates.2", async function() {
const pkgs = [
{ project: 'pipenv.pypa.io', 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 === 'pipenv.pypa.io') {
return Promise.resolve([
{ project: 'python.org', constraint: new semver.Range('>=3.7') }
])
} else {
return Promise.resolve([])
}
})

let nodes = 0
for (const pkg of rv.pkgs) {
if (pkg.project === 'python.org') {
assertEquals(pkg.constraint.toString(), '~3.9')
nodes++
}
}

assertEquals(nodes, 1)
})

it(suite, "hydrates.3", async function() {
const pkgs = [
{ project: 'pipenv.pypa.io', 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 === 'pipenv.pypa.io') {
return Promise.resolve([
{ project: 'python.org', constraint: new semver.Range('~3.9.1') }
])
} else {
return Promise.resolve([])
}
})

let nodes = 0
for (const pkg of rv.pkgs) {
if (pkg.project === 'python.org') {
assertEquals(pkg.constraint.toString(), '~3.9.1')
nodes++
}
}

assertEquals(nodes, 1)
})

0 comments on commit df02b72

Please sign in to comment.