From f38052242ac2b479e78550723d4bc2e77d2044ac Mon Sep 17 00:00:00 2001 From: Natoandro Date: Sat, 13 Jan 2024 03:37:25 +0300 Subject: [PATCH] fix: fix typo (#32) * fix(install): typo in `install.sh` * fix: fix typo * fix(tasks): default allowedPortDeps --------- Co-authored-by: Yohe-Am <56622350+Yohe-Am@users.noreply.github.com> --- README.md | 2 +- install.sh | 4 ++-- mod.ts | 16 ++++++++++++++-- modules/tasks/exec.ts | 12 +++++++++++- tests/tasks.ts | 32 ++++++++++++++++++++++++++++++-- 5 files changed, 58 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 50269818..f38a831e 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ ghjk /jk/ is a programmable runtime manager. # stable curl -fsSL https://raw.githubusercontent.com/metatypedev/ghjk/main/install.sh | bash # latest (main) -curl -fsSL https://raw.githubusercontent.com/metatypedev/ghjk/main/install.sh | GHJK_VERISON=main bash +curl -fsSL https://raw.githubusercontent.com/metatypedev/ghjk/main/install.sh | GHJK_VERSION=main bash ``` In your project, create a configuration file `ghjk.ts`: diff --git a/install.sh b/install.sh index 7debc3e4..3b2b5194 100755 --- a/install.sh +++ b/install.sh @@ -15,7 +15,7 @@ fi # if custom deno bin is not set, install one if [ -z "${GHJK_INSTALL_DENO_EXEC+x}" ]; then - GHJK_INSTALL_DENO_EXEC="$GHJK_DIR/bin/deno" + GHJK_INSTALL_DENO_EXEC="$GHJK_SHARE_DIR/bin/deno" if [ ! -f "$GHJK_INSTALL_DENO_EXEC" ] || [ "$DENO_VERSION" != "v$("$GHJK_INSTALL_DENO_EXEC" --version | head -n 1 | cut -d ' ' -f 2)" ]; then echo "GHJK_INSTALL_DENO_EXEC not set, installing deno $DENO_VERSION for ghjk" @@ -25,7 +25,7 @@ if [ -z "${GHJK_INSTALL_DENO_EXEC+x}" ]; then exit 1 fi - curl -fsSL https://deno.land/x/install/install.sh | DENO_INSTALL="$GHJK_DIR" sh -s "$DENO_VERSION" >/dev/null + curl -fsSL https://deno.land/x/install/install.sh | DENO_INSTALL="$GHJK_SHARE_DIR" sh -s "$DENO_VERSION" >/dev/null fi fi diff --git a/mod.ts b/mod.ts index e48e0f81..6361b7e1 100644 --- a/mod.ts +++ b/mod.ts @@ -70,8 +70,20 @@ export function install(...configs: InstallConfigFat[]) { export type TaskDefNice = & Omit & Partial> - & Partial; + & Partial> + & { allowedPortDeps?: AllowedPortDep[] }; export function task(name: string, config: TaskDefNice) { + const allowedPortDeps = Object.fromEntries([ + ...(config.allowedPortDeps ?? + // only add the stdDeps if the task specifies installs + (config.installs ? stdDeps() : [])) + .map((dep) => + [ + dep.manifest.name, + portsValidators.allowedPortDep.parse(dep), + ] as const + ), + ]); tasks[name] = { name, fn: config.fn, @@ -80,7 +92,7 @@ export function task(name: string, config: TaskDefNice) { env: { installs: config.installs ?? [], env: config.env ?? {}, - allowedPortDeps: config.allowedPortDeps ?? {}, + allowedPortDeps, }, }; return name; diff --git a/modules/tasks/exec.ts b/modules/tasks/exec.ts index 4cc87117..ba82a162 100644 --- a/modules/tasks/exec.ts +++ b/modules/tasks/exec.ts @@ -152,7 +152,17 @@ export async function execTask( taskName, args, { - ...installEnvs, + ...Deno.env.toObject(), + ...Object.fromEntries( + Object.entries(installEnvs).map( + ( + [key, val], + ) => [ + key, + key.match(/PATH/i) ? `${val}:${Deno.env.get(key) ?? ""}` : val, + ], + ), + ), ...taskEnv.env.env, }, ); diff --git a/tests/tasks.ts b/tests/tasks.ts index 6e501bd0..d77941c7 100644 --- a/tests/tasks.ts +++ b/tests/tasks.ts @@ -6,7 +6,8 @@ import { type TaskDefTest, tsGhjkFileFromInstalls, } from "./utils.ts"; -import { protoc } from "../ports/mod.ts"; +import * as ghjk from "../mod.ts"; +import * as ports from "../ports/mod.ts"; type CustomE2eTestCase = Omit & { ePoint: string; @@ -47,7 +48,7 @@ test (ghjk x greet world) = 'Hello moon!'`, name: "ports", tasks: [{ name: "protoc", - installs: [protoc()], + installs: [ports.protoc()], fn: async ({ $ }) => { await $`protoc --version`; }, @@ -56,6 +57,33 @@ test (ghjk x greet world) = 'Hello moon!'`, stdin: ` ghjk x protoc`, }, + { + name: "port_deps", + tasks: [{ + name: "test", + // node depends on tar_aa + installs: [...ports.pipi({ packageName: "pre-commit" })], + allowedPortDeps: ghjk.stdDeps({ enableRuntimes: true }), + fn: async ({ $ }) => { + await $`pre-commit --version`; + }, + }], + ePoint: `fish`, + stdin: `ghjk x test`, + }, + { + name: "default_port_deps", + tasks: [{ + name: "test", + // node depends on tar_aa + installs: [ports.node()], + fn: async ({ $ }) => { + await $`node --version`; + }, + }], + ePoint: `fish`, + stdin: `ghjk x test`, + }, { name: "dependencies", tasks: [