Skip to content

Commit

Permalink
Tolerate v prefix for .node-version
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Apr 19, 2023
1 parent 6cf193c commit 3cabcf3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</p>


# tea/cli 0.28.1
# tea/cli 0.28.2

`tea` puts the whole open source ecosystem at your fingertips:

Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useVirtualEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ export default async function(cwd: Path = Path.cwd()): Promise<VirtualEnv> {
}
}
if (_if(".node-version")) {
const constraint = semver.Range.parse((await f!.read()).trim())
let s = (await f!.read()).trim()
if (s.startsWith('v')) s = s.slice(1) // is allowed
const constraint = semver.Range.parse(s)
if (!constraint) throw new Error('couldn’t parse: .node-version')
pkgs.push({ project: "nodejs.org", constraint })
}
Expand Down
24 changes: 18 additions & 6 deletions tests/functional/devenv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Deno.test("dev env interactions with HOME", { sanitizeResources: false, sanitize
}

try {
const { stdout } = await run(["+tea.xyz/magic", "-Esk", "--chaste", "env"])
const { stdout } = await run(["+tea.xyz/magic", "-Esk", "--chaste", "env"])

const envVar = (key: string) => getEnvVar("/bin/zsh", stdout, key)
const srcroot = envVar("SRCROOT")
Expand Down Expand Up @@ -62,7 +62,7 @@ Deno.test("should enter dev env", { sanitizeResources: false, sanitizeOps: false
const TEA_REWIND = JSON.stringify({revert: {VAL: "REVERTED"}, unset: ["BAZ"]})

const config = { env: { SHELL: shell, TEA_REWIND } }
const { stdout } = await run(["+tea.xyz/magic", "-Esk", "--chaste", "env"], config)
const { stdout } = await run(["+tea.xyz/magic", "-Esk", "--chaste", "env"], config)

const envVar = (key: string) => getEnvVar(shell, stdout, key)
const isUnset = (key: string) => isEnvVarUnset(shell, stdout, key)
Expand Down Expand Up @@ -91,7 +91,7 @@ Deno.test("should leave dev env", { sanitizeResources: false, sanitizeOps: false
const TEA_REWIND = JSON.stringify({revert: {VAL: "REVERTED"}, unset: ["BAZ"]})

const config = { env: { SHELL: shell, TEA_REWIND } }
const { stdout } = await run(["+tea.xyz/magic", "-Esk", "--chaste", "env"], config)
const { stdout } = await run(["+tea.xyz/magic", "-Esk", "--chaste", "env"], config)

const envVar = (key: string) => getEnvVar(shell, stdout, key)
const isUnset = (key: string) => isEnvVarUnset(shell, stdout, key)
Expand All @@ -117,19 +117,31 @@ Deno.test("should provide packages in dev env", { sanitizeResources: false, sani
const {run, teaDir } = await createTestHarness()

fixturesDir.join(file).cp({into: teaDir})
const { stdout } = await run(["+tea.xyz/magic", "-Esk", "--chaste", "env"], { env: { SHELL } })
const { stdout } = await run(["+tea.xyz/magic", "-Esk", "--chaste", "env"], { env: { SHELL } })

assert(getTeaPackages(SHELL, stdout).includes(pkg), "should include nodejs dep")
})
}
})

Deno.test("tolerant .node-version parsing", { sanitizeResources: false, sanitizeOps: false }, async () => {
const SHELL = "/bin/zsh"

const {run, teaDir } = await createTestHarness()
teaDir.join(".node-version").write({ text: "\n\n\nv16\n" })

const { stdout } = await run(["+tea.xyz/magic", "-Esk", "--chaste", "env"], { env: { SHELL } })

const pkg = "nodejs.org^16"
assert(getTeaPackages(SHELL, stdout).includes(pkg), "should include nodejs dep")
})

function getEnvVar(shell: string, lines: string[], key: string): string | null {
const pattern = () => {
switch (shell) {
case "/bin/fish":
return `^set -gx ${key} '(.*)';$`
case "/bin/elvish":
case "/bin/elvish":
return `^set-env ${key} '(.*)'$`
default:
return `export ${key}='(.*)'$`
Expand All @@ -150,7 +162,7 @@ function isEnvVarUnset(shell: string, lines: string[], key:string): boolean {
switch (shell) {
case "/bin/fish":
return `^set -e ${key};$`
case "/bin/elvish":
case "/bin/elvish":
return `^unset-env ${key}$`
default:
return `unset ${key}$`
Expand Down

0 comments on commit 3cabcf3

Please sign in to comment.