-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Plugin system #410
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e507566
Remove unnecessary splatting of `self` in plugin tests
soenkehahn 530a79e
Add docstring to Plugin type
soenkehahn 9fe96dd
Mimic the recommended importing style in project.test.ts
soenkehahn fb3d7fa
Move common nixpkgsInput into version.json
soenkehahn 4665114
Tweak jsdocs
soenkehahn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
module Garn.ImportVersion (garnVersionSplice) where | ||
{-# LANGUAGE DeriveLift #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module Garn.ImportVersion (Versions (..), versionsSplice) where | ||
|
||
import Data.Aeson (FromJSON, eitherDecodeFileStrict') | ||
import GHC.Generics (Generic) | ||
import Language.Haskell.TH (Exp (LitE), Lit (StringL), Q, runIO) | ||
import Language.Haskell.TH (Exp, Q, runIO) | ||
import Language.Haskell.TH.Syntax (Lift (..)) | ||
|
||
newtype Version = Version | ||
{ tsLibVersion :: String | ||
data Versions = Versions | ||
{ tsLibVersion :: String, | ||
nixpkgsInput :: String | ||
} | ||
deriving stock (Generic) | ||
deriving stock (Generic, Lift) | ||
deriving anyclass (FromJSON) | ||
|
||
garnVersionSplice :: Q Exp | ||
garnVersionSplice = do | ||
version <- runIO $ eitherDecodeFileStrict' "./ts/internal/version.json" | ||
case version of | ||
Right version -> pure $ LitE $ StringL $ tsLibVersion version | ||
versionsSplice :: Q Exp | ||
versionsSplice = do | ||
versions <- runIO $ eitherDecodeFileStrict' "./ts/internal/version.json" | ||
case versions of | ||
Right (versions :: Versions) -> [|versions|] | ||
Left err -> fail err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,8 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module Garn.Utils where | ||
|
||
import Data.String.Conversions (cs) | ||
import Debug.Trace (trace) | ||
import Garn.ImportVersion (garnVersionSplice) | ||
import Text.Pretty.Simple (pShow) | ||
|
||
dbg :: (Show a) => a -> a | ||
dbg a = trace (cs $ pShow a) a | ||
|
||
garnCliVersion :: String | ||
garnCliVersion = $(garnVersionSplice) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"tsLibVersion": "v0.0.15" | ||
"tsLibVersion": "v0.0.15", | ||
"nixpkgsInputComment": "pinned to master on 2023-10-26", | ||
"nixpkgsInput": "github:NixOS/nixpkgs/6fc7203e423bbf1c8f84cccf1c4818d097612566" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
import { Check } from "./check.ts"; | ||
import { Executable } from "./executable.ts"; | ||
import { Plugin, Project } from "./project.ts"; | ||
import { describe, it } from "https://deno.land/[email protected]/testing/bdd.ts"; | ||
import * as garn from "./mod.ts"; | ||
import * as nix from "./nix.ts"; | ||
import { assertStdout, assertSuccess, runExecutable } from "./testUtils.ts"; | ||
import { Package } from "./mod.ts"; | ||
|
||
const assertTypeIsCheck = (_c: Check) => {}; | ||
const assertTypeIsExecutable = (_e: Executable) => {}; | ||
const assertTypeIsPackage = (_p: Package) => {}; | ||
const assertTypeIsCheck = (_c: garn.Check) => {}; | ||
const assertTypeIsExecutable = (_e: garn.Executable) => {}; | ||
const assertTypeIsPackage = (_p: garn.Package) => {}; | ||
|
||
const _testTypeCheckingOfAddCheck = (project: Project) => { | ||
const _testTypeCheckingOfAddCheck = (project: garn.Project) => { | ||
const p = project | ||
.addExecutable("unrelated1", "true") | ||
.addCheck("check", "true") | ||
|
@@ -23,7 +18,7 @@ const _testTypeCheckingOfAddCheck = (project: Project) => { | |
p.check``; | ||
}; | ||
|
||
const _testTypeCheckingOfAddCheckTemplate = (project: Project) => { | ||
const _testTypeCheckingOfAddCheckTemplate = (project: garn.Project) => { | ||
const p = project | ||
.addExecutable("unrelated1", "true") | ||
.addCheck("check")`true`.addExecutable("unrelated2", "true"); | ||
|
@@ -34,7 +29,7 @@ const _testTypeCheckingOfAddCheckTemplate = (project: Project) => { | |
p.check``; | ||
}; | ||
|
||
const _testTypeCheckingOfAddExecutable = (project: Project) => { | ||
const _testTypeCheckingOfAddExecutable = (project: garn.Project) => { | ||
const p = project | ||
.addExecutable("unrelated1", "true") | ||
.addExecutable("shell", "true") | ||
|
@@ -46,7 +41,7 @@ const _testTypeCheckingOfAddExecutable = (project: Project) => { | |
p.shell``; | ||
}; | ||
|
||
const _testTypeCheckingOfAddExecutableTemplate = (project: Project) => { | ||
const _testTypeCheckingOfAddExecutableTemplate = (project: garn.Project) => { | ||
const p = project | ||
.addExecutable("unrelated1", "true") | ||
.addExecutable("shell")`true`.addExecutable("unrelated2", "true"); | ||
|
@@ -61,7 +56,7 @@ describe("Project.add", () => { | |
it("allows adding fields with .add", () => { | ||
const project = garn | ||
.mkProject({ description: "" }, {}) | ||
.add((self) => ({ ...self, foo: garn.shell("echo foo") })); | ||
.add((_self) => ({ foo: garn.shell("echo foo") })); | ||
const output = runExecutable(project.foo); | ||
assertSuccess(output); | ||
assertStdout(output, "foo\n"); | ||
|
@@ -73,8 +68,8 @@ describe("Project.add", () => { | |
{ description: "", defaultEnvironment: garn.emptyEnvironment }, | ||
{}, | ||
) | ||
.withDevTools([garn.mkPackage(nix.nixRaw`pkgs.hello`, "")]) | ||
.add((self) => ({ ...self, foo: self.shell("hello") })); | ||
.withDevTools([garn.mkPackage(garn.nix.nixRaw`pkgs.hello`, "")]) | ||
.add((self) => ({ foo: self.shell("hello") })); | ||
const output = runExecutable(project.foo); | ||
assertSuccess(output); | ||
assertStdout(output, "Hello, world!\n"); | ||
|
@@ -92,7 +87,7 @@ describe("Project.add", () => { | |
`, | ||
}, | ||
) | ||
.add((self) => ({ ...self, foo: self.shell`${self.package}/bin/main` })); | ||
.add((self) => ({ foo: self.shell`${self.package}/bin/main` })); | ||
const output = runExecutable(project.foo); | ||
assertSuccess(output); | ||
assertStdout(output, "main executable\n"); | ||
|
@@ -137,7 +132,7 @@ describe("Project.add", () => { | |
}); | ||
|
||
it("provides a nice type synonym for plugins that add a field", () => { | ||
const plugin: Plugin<{ addedField: garn.Package }> = (p) => ({ | ||
const plugin: garn.Plugin<{ addedField: garn.Package }> = (_p) => ({ | ||
addedField: garn.build``, | ||
}); | ||
const project = garn | ||
|
@@ -152,7 +147,9 @@ describe("Project.add", () => { | |
}); | ||
|
||
it("provides a nice type synonym for plugins that add multiple fields", () => { | ||
const plugin: Plugin<{ one: garn.Package; two: garn.Check }> = (p) => ({ | ||
const plugin: garn.Plugin<{ one: garn.Package; two: garn.Check }> = ( | ||
_p, | ||
) => ({ | ||
one: garn.build``, | ||
two: garn.check(""), | ||
}); | ||
|
@@ -169,9 +166,10 @@ describe("Project.add", () => { | |
}); | ||
|
||
it("provides a nice interface for plugins that depend on a non-standard field", () => { | ||
const plugin: Plugin<{ addedField: Executable }, { dep: Package }> = ( | ||
p, | ||
) => ({ | ||
const plugin: garn.Plugin< | ||
{ addedField: garn.Executable }, | ||
{ dep: garn.Package } | ||
> = (p) => ({ | ||
addedField: garn.shell`${p.dep}/bin/whatever`, | ||
}); | ||
const project = garn | ||
|
@@ -188,7 +186,7 @@ describe("Project.add", () => { | |
}); | ||
|
||
it("allows overwriting fields", () => { | ||
const plugin: Plugin<{ field: Package }> = (p) => ({ | ||
const plugin: garn.Plugin<{ field: garn.Package }> = (_p) => ({ | ||
field: garn.build``, | ||
}); | ||
const project = garn | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forget - what's the status of including
nodePackage
in nixpkgs? If it's merged, then this should be changed. If not, then reminder to change this (and the website!) when it is merged.(Maybe cc @alexdavid)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, not merged yet. Here's the PR: #382.