Skip to content

Commit

Permalink
fix(tasks): default allowedPortDeps
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed Jan 11, 2024
1 parent c0626d7 commit 65019fd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
16 changes: 14 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,20 @@ export function install(...configs: InstallConfigFat[]) {
export type TaskDefNice =
& Omit<TaskFnDef, "env" | "name" | "dependsOn">
& Partial<Pick<TaskFnDef, "dependsOn">>
& Partial<TaskEnv>;
& Partial<Omit<TaskEnv, "allowedPortDeps">>
& { 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,
Expand All @@ -80,7 +92,7 @@ export function task(name: string, config: TaskDefNice) {
env: {
installs: config.installs ?? [],
env: config.env ?? {},
allowedPortDeps: config.allowedPortDeps ?? {},
allowedPortDeps,
},
};
return name;
Expand Down
12 changes: 11 additions & 1 deletion modules/tasks/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
);
Expand Down
32 changes: 30 additions & 2 deletions tests/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<E2eTestCase, "ePoints" | "tsGhjkfileStr"> & {
ePoint: string;
Expand Down Expand Up @@ -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`;
},
Expand All @@ -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: [
Expand Down

0 comments on commit 65019fd

Please sign in to comment.