Skip to content

Commit

Permalink
Experiment 1
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdavid committed Nov 13, 2023
1 parent 26003ca commit b05b4e1
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions ts/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Environment } from "./environment.ts";
import { Executable, mkShellExecutable } from "./executable.ts";
import { hasTag } from "./internal/utils.ts";
import { NixStrLitInterpolatable } from "./nix.ts";
import { Package, mkShellPackage } from "./package.ts";
import { mkShellPackage, Package } from "./package.ts";
import { markAsMayNotExport } from "./internal/may_not_export.ts";

/**
Expand All @@ -15,16 +15,16 @@ import { markAsMayNotExport } from "./internal/may_not_export.ts";
*/
export type Project = ProjectHelpers & ProjectData;

type ProjectData = {
export type ProjectData = {
tag: "project";
description: string;
defaultEnvironment?: Environment;
defaultExecutable?: Executable;
};

export type Plugin<Dependencies, Additions> = <T extends ProjectData>(
project: T & Dependencies,
) => Omit<T, keyof Additions> & Additions;
export type Plugin<Additions> = (
project: Project
) => Additions;

type ProjectHelpers = {
/**
Expand Down Expand Up @@ -82,10 +82,10 @@ type ProjectHelpers = {
* .add(self => self.addExecutable("codegen")`${self.mainPackage}/bin/codegen`)
* ```
*/
add<T extends ProjectData, U extends ProjectData>(
add<T extends Project, Additions>(
this: T,
fn: (p: T) => U,
): U;
fn: Plugin<Additions>,
): Omit<T, keyof Additions> & Additions;

/**
* Adds an `Executable` with the given name to the Project
Expand Down Expand Up @@ -219,11 +219,14 @@ const proxyEnvironmentHelpers = (): ProjectHelpers => ({
return mkShellPackage(defaultEnvironment, s, ...args);
},

add<T extends ProjectData, U extends ProjectData>(
add<T extends Project, Additions>(
this: T,
fn: (p: T) => U,
): U {
return fn(this);
fn: Plugin<Additions>
): Omit<T, keyof Additions> & Additions {
return {
...this,
...fn(this),
};
},

addExecutable<T extends ProjectData, Name extends string>(
Expand Down Expand Up @@ -256,8 +259,7 @@ const proxyEnvironmentHelpers = (): ProjectHelpers => ({
[
`${exportName} exports the return type of "addExecutable", but this is not the proper usage of addExecutable.`,
'Did you forget the template literal? Example usage: project.addExecutable("executable-name")`shell script to run`',
].join(" "),
);
].join(" "));
return templateLiteralFn;
},

Expand Down Expand Up @@ -291,8 +293,7 @@ const proxyEnvironmentHelpers = (): ProjectHelpers => ({
[
`${exportName} exports the return type of "addCheck", but this is not the proper usage of addCheck.`,
'Did you forget the template literal? Example usage: project.addCheck("check-name")`shell script to run`',
].join(" "),
);
].join(" "));
return templateLiteralFn;
},

Expand Down

0 comments on commit b05b4e1

Please sign in to comment.