Skip to content

Commit

Permalink
feat: ghjk init ts-lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed Jan 5, 2025
1 parent 5504688 commit ecfedaa
Show file tree
Hide file tree
Showing 35 changed files with 695 additions and 356 deletions.
26 changes: 13 additions & 13 deletions .ghjk/lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@
"lock-sed": {
"ty": "denoFile@v1",
"key": "lock-sed",
"envKey": "bciqocjamyeiuh6llwcdqg4q4ceantuzpbm5bmnlz7pkqz4r2ca7w2eq"
"envKey": "bciqei2rn3w6xakdaaapst7yyp36wjmz3txqtja24gl5v3fgwqcsa34i"
},
"cache-v8": {
"ty": "denoFile@v1",
Expand All @@ -430,52 +430,52 @@
}
]
},
"bciqfnku2tswsz4gapwhys5ox5uiyzcb5r7bmuwzljjeziljcu7efroi": {
"bciqenvipb7pm4gge77liqnjhvdv7nhckd6kqjg3bhc3pc6e4g6o2zwa": {
"desc": "the default default environment.",
"provides": [
{
"ty": "posix.envVar",
"key": "RUST_LOG",
"val": "info,deno::npm=info,deno::file_fetcher=info,swc_ecma_transforms_base=info,swc_common=info,h2=info,rustls=info,mio=info,hyper_util=info"
"val": "info,runtime=debug,tokio=debug,deno::npm=info,deno::file_fetcher=info,swc_ecma_transforms_base=info,swc_common=info,h2=info,rustls=info,mio=info,hyper_util=info"
},
{
"ty": "ghjk.ports.InstallSetRef",
"setId": "ghjkEnvProvInstSet___main"
}
]
},
"bciqocjamyeiuh6llwcdqg4q4ceantuzpbm5bmnlz7pkqz4r2ca7w2eq": {
"bciqei2rn3w6xakdaaapst7yyp36wjmz3txqtja24gl5v3fgwqcsa34i": {
"provides": [
{
"ty": "posix.envVar",
"key": "RUST_LOG",
"val": "info,deno::npm=info,deno::file_fetcher=info,swc_ecma_transforms_base=info,swc_common=info,h2=info,rustls=info,mio=info,hyper_util=info"
"val": "info,runtime=debug,tokio=debug,deno::npm=info,deno::file_fetcher=info,swc_ecma_transforms_base=info,swc_common=info,h2=info,rustls=info,mio=info,hyper_util=info"
},
{
"ty": "ghjk.ports.InstallSetRef",
"setId": "ghjkEnvProvInstSet___main"
}
]
},
"bciqex5g2cetqvfipwhu6fb3mmyke3y6jvrscjrykf2zl7wfwupiqhca": {
"bciqm23m6kl7m2mdbjmcjoleysme4gwtkzeeqrbyrpydpm3fvx3bn25a": {
"provides": [
{
"ty": "posix.envVar",
"key": "RUST_LOG",
"val": "info,deno::npm=info,deno::file_fetcher=info,swc_ecma_transforms_base=info,swc_common=info,h2=info,rustls=info,mio=info,hyper_util=info"
"val": "info,runtime=debug,tokio=debug,deno::npm=info,deno::file_fetcher=info,swc_ecma_transforms_base=info,swc_common=info,h2=info,rustls=info,mio=info,hyper_util=info"
},
{
"ty": "ghjk.ports.InstallSetRef",
"setId": "ghjkEnvProvInstSet____rust"
}
]
},
"bciqgcwltl3sbuyrqlhxz2spihe2asdzrgt3axosw3mre7ived23syhy": {
"bciqddyi4oxhgfvgejlmq5s4psdv3ajzc7unzyc2kq35q6nlix6c4yai": {
"provides": [
{
"ty": "posix.envVar",
"key": "RUST_LOG",
"val": "info,deno::npm=info,deno::file_fetcher=info,swc_ecma_transforms_base=info,swc_common=info,h2=info,rustls=info,mio=info,hyper_util=info"
"val": "info,runtime=debug,tokio=debug,deno::npm=info,deno::file_fetcher=info,swc_ecma_transforms_base=info,swc_common=info,h2=info,rustls=info,mio=info,hyper_util=info"
},
{
"ty": "posix.envVar",
Expand All @@ -491,10 +491,10 @@
},
"defaultEnv": "dev",
"envsNamed": {
"main": "bciqfnku2tswsz4gapwhys5ox5uiyzcb5r7bmuwzljjeziljcu7efroi",
"_rust": "bciqex5g2cetqvfipwhu6fb3mmyke3y6jvrscjrykf2zl7wfwupiqhca",
"ci": "bciqex5g2cetqvfipwhu6fb3mmyke3y6jvrscjrykf2zl7wfwupiqhca",
"dev": "bciqgcwltl3sbuyrqlhxz2spihe2asdzrgt3axosw3mre7ived23syhy"
"main": "bciqenvipb7pm4gge77liqnjhvdv7nhckd6kqjg3bhc3pc6e4g6o2zwa",
"_rust": "bciqm23m6kl7m2mdbjmcjoleysme4gwtkzeeqrbyrpydpm3fvx3bn25a",
"ci": "bciqm23m6kl7m2mdbjmcjoleysme4gwtkzeeqrbyrpydpm3fvx3bn25a",
"dev": "bciqddyi4oxhgfvgejlmq5s4psdv3ajzc7unzyc2kq35q6nlix6c4yai"
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ jobs:
# need cmake to build the rust deps
# need coreutils on max for the `timeout` command
run: brew install fish zsh coreutils cmake
- run: deno task test
- run: |
deno task test-rust
deno task test-doc
deno task test
# test-action:
# runs-on: ubuntu-latest
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ Ghjk is primarily configured through constructs called "environments" or "envs"
They serve as recipes for making (mostly) reproducible posix shells.

```ts
// NOTE: `ghjk.ts` files are expected to export this sophon object
export { sophon } from "https://raw.github.com/metatypedev/ghjk/v0.3.0-rc.1/mod.ts";
import { file } from "https://raw.github.com/metatypedev/ghjk/v0.3.0-rc.1/mod.ts";
// ports are small programs that install sowtware to your envs
import * as ports from "https://raw.github.com/metatypedev/ghjk/v0.3.0-rc.1/ports/mod.ts";

// NOTE: `ghjk.ts` files are expected to export this ghjk object
export const ghjk = file({});
const ghjk = file({});

// top level `install`s go to the `main` env
ghjk.install(ports.protoc());
Expand Down
1 change: 1 addition & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"tasks": {
"test": "cargo build -p ghjk && deno test --unstable-worker-options --unstable-kv -A tests/*",
"test-doc": "cargo build -p ghjk && deno test --unstable-worker-options --unstable-kv -A --doc **/*.ts",
"test-rust": "cargo test",
"ghjk": "cargo run -p ghjk",
"cache": "deno cache deps/*",
"check": "deno run -A ./tools/check.ts",
Expand Down
8 changes: 2 additions & 6 deletions docs/installation-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

| Env vars | Desc | Default |
| -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
| `GHJK_VERSION` | Git tag/ref of the ghjk repo to install from. | Latest release tag. |
| `GHJK_SHARE_DIR` | Root directory for ghjk installation. | `$HOME/.local/share/ghjk` |
| `VERSION` | Git tag/ref of the ghjk repo to install from. | Latest release tag. |
| `GHJK_DATA_DIR` | Data directory for ghjk installation. | `$HOME/.local/share/ghjk` |
| `GHJK_INSTALLER_URL` | Uri to the typescript section of installer script. | `install.ts` file from the ghjk repo under |
| `GHJK_INSTALL_EXE_DIR` | Location to install the `ghjk` exec. | `$HOME/.local/bin` |
| `GHJK_INSTALL_SKIP_EXE` | Weather or not to skip install the `ghjk` CLI to `GHJK_INSTALL_EXE_DIR`. | `false` |
| `GHJK_INSTALL_DENO_EXEC` | Alternative deno exec to use. If provided, no separate Deno CLI is downloaded. It's generally preferable for ghjk to manage it's own Deno versions still. | A Deno CLI is installed to `$GHJK_SHARE_DIR/bin` |
| `DENO_VERSION` | Deno version to install if `GHJK_INSTALL_DENO_EXEC` is not test. | Deno version used for ghjk development. |
| `GHJK_INSTALL_HOOK_SHELLS` | Comma separated list of shells to hook. | `bash,fish,zsh` |
| `GHJK_INSTALL_HOOK_MARKER` | Marker to use when installing shell hooks. | `ghjk-hook-marker` |
| | | |
| `GHJK_INSTALL_NO_LOCKFILE` | Disable use of a Deno lockfile for the ghjk program. | |
25 changes: 14 additions & 11 deletions docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ Look through the following snippet to understand the basic structure of a `ghjk.
// one's using. For example
// https://raw.github.com/metatypedev/ghjk/v0.3.0-rc.1/
import { file } from ".../mod.ts";
// all ghjk.ts files are expected to export this special `sophon` object
export { sophon } from ".../mod.ts";
// import the port for the node program
import node from ".../ports/node.ts";

// all ghjk.ts files are expected to export this special `ghjk` object
export const ghjk = file();
// Create the ghjk object using the file functiono. This modifies
// the sophon exported above and may only be called once during
// serialization.
const ghjk = file();

// install programs (ports) into your env
ghjk.install(
Expand Down Expand Up @@ -106,11 +110,10 @@ Thankfully, through the great sandbox provided through Deno's implementation, th
- The contents of the ghjkfile
- Files accessed during serialization
- Environment variables read during serialization
- Configuration used by the ghjk cli

This doesn't cover everything though and the `ghjk.ts` implementation generally assumes a declarative paradigm of programming.
You'll generally want to avoid any logic that's deterministic on inputs like time or RNGs.

There are still a couple of glaring omissions from this list that will be addressed as ghjk matures.
You'll generally want to avoid any logic that's not deterministic and depends on inputs like time or RNGs.
If you encounter any edge cases or want to force re-serialization, you can remove the hashfile at `.ghjk/hash.json` which contains hashes for change tracking.

```bash
Expand Down Expand Up @@ -140,7 +143,7 @@ The best way to resolve ghjk merge conflicts is to:
- In git, easier to remove any changes in the merge and revert to the base/HEAD branch
- Re-serialize by invoking the ghjk CLI

This simple steps make sure that the _lockfile_ reflect what's in the latest _ghjkfile_ without needing to re-resolve the world.
These simple steps make sure that the _lockfile_ reflect what's in the latest _ghjkfile_ without needing to re-resolve the world.
Of course, if the discarded version of the lockfile contained new versions, they'll be re-resolved possibly to a different version.
But generally, if the versions specified in ghjkfile are tight enough, it'll resolve the same values as before.
If versions are important, it's good to explicitly specify them in your ghjkfile.
Expand Down Expand Up @@ -211,7 +214,7 @@ ghjk.env("my-env")

By default, your ghjkfile has an env called `main`.
Envs can inherit from each other and by default inherit from the `main` environment.
Inheritance is additive based for most env properties and allows easy composition.
Inheritance is additive on most env properties and allows easy composition.
Please look at the [envs example](../examples/envs/ghjk.ts) or the [kitchen sink](../examples/kitchen/ghjk.ts) example which show all the knobs available on envs.

You can then access the envs feature under the `envs` section of the CLI:
Expand Down Expand Up @@ -403,23 +406,23 @@ The primarily difference between the two scenarios is how activation of envs is
The standard installation script is the best way to install ghjk in CI environments.
The environment [variables](./installation-vars.md) used for the installer customization come in extra handy here.
Namely, it's good practice to:
- Make sure the `$GHJK_VERSION` is the one used by the ghjkfile.
- Specify `$GHJK_SHARE_DIR` to a location that can be cached by your CI tooling. This is where ports get installed.
- Make sure the `$VERSION` is the one used by the ghjkfile.
- Specify `$GHJK_DATA_DIR` to a location that can be cached by your CI tooling. This is where ports get installed.
- Specify `$GHJK_INSTALL_EXE_DIR` to a location that you know will be in `$PATH`. This is where the ghjk CLI gets installed to.

```dockerfile
# sample of how one would install ghjk for use in a Dockerfile
ARG GHJK_VERSION=v0.3.0-rc.1
# /usr/bin is available in $PATH by default making ghjk immediately avail
RUN curl -fsSL "https://raw.github.com/metatypedev/ghjk/$GHJK_VERSION/install.sh" \
RUN curl -fsSL "https://raw.github.com/metatypedev/ghjk/${GHJK_VERSION}/install.sh" \
| GHJK_INSTALL_EXE_DIR=/usr/bin sh
```

### Activation

When working on non-interactive shells, the ghjk shell hooks are not available.
This means that the default environment won't be activated for that CWD nor will any changes occur on changing directories.
It also prevents the `ghjk envs activate` command from functioning which requires that these hooks be run before each command.
It also prevents the `ghjk sync` and `ghjk envs activate` commands from functioning which requires that these hooks be run before each command.
In such scenarios, one can directly `source` the activation script for the target env from the `.ghjk` directory.

```bash
Expand Down
3 changes: 2 additions & 1 deletion examples/env_vars/ghjk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { sophon } from "../../hack.ts";
import { file } from "../../hack.ts";

export const ghjk = file({
const ghjk = file({
defaultEnv: "empty",
envs: [{ name: "empty", inherit: false }],
defaultBaseEnv: "empty",
Expand Down
2 changes: 1 addition & 1 deletion examples/envs/ghjk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { ghjk } from "../../hack.ts";
export { sophon } from "../../hack.ts";
import { config, env, install, task } from "../../hack.ts";
import * as ports from "../../ports/mod.ts";

Expand Down
3 changes: 2 additions & 1 deletion examples/kitchen/ghjk.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { stdDeps } from "../../files/mod.ts";
export { sophon } from "../../mod.ts";
import { file } from "../../mod.ts";
import * as ports from "../../ports/mod.ts";

// we need this export for this file to be a valid ghjkfile
// it's the one thing used by the ghjk host implementation to
// interact with your ghjkfile
export const ghjk = file({
const ghjk = file({
// configre an empty env so that no ports are avail by default in our workdir
defaultEnv: "empty",
envs: [{ name: "empty", inherit: false }],
Expand Down
2 changes: 1 addition & 1 deletion examples/many_installs/ghjk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { ghjk } from "../../hack.ts";
export { sophon } from "../../hack.ts";
import { config, install } from "../../hack.ts";
import * as ports from "../../ports/mod.ts";

Expand Down
2 changes: 1 addition & 1 deletion examples/tasks/ghjk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { ghjk } from "../../hack.ts";
export { sophon } from "../../hack.ts";
import { logger, task } from "../../hack.ts";
import * as ports from "../../ports/mod.ts";

Expand Down
3 changes: 2 additions & 1 deletion examples/template.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @ts-nocheck: Deno based

export { sophon } from "../mod.ts"; // template-import
import { file } from "../mod.ts"; // template-import
// import * as ports from "../ports/mod.ts"; // template-import

// This export is necessary for typescript ghjkfiles
export const ghjk = file({
const ghjk = file({
// allows usage of ports that depend on node/python
// enableRuntimes: true,
});
Expand Down
9 changes: 4 additions & 5 deletions files/deno/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { shimDenoNamespace } from "../../utils/worker.ts";
import { zod } from "../../deps/common.ts";
import { Ghjk } from "../../src/ghjk/js/runtime.js";

// TODO: shim Deno.exit to avoid killing whole program

const serializeArgs = zod.object({
uri: zod.string(),
});
Expand All @@ -20,15 +22,12 @@ async function serialize(args: zod.infer<typeof serializeArgs>) {
const { setup: setupLogger } = await import("../../utils/logger.ts");
setupLogger();
const mod = await import(args.uri);
if (!mod.ghjk) {
throw new Error(`ghjk.ts does not export a ghjk object: ${args.uri}`);
}
if (!mod.ghjk.sophon) {
if (!mod.sophon) {
throw new Error(
`no sophon found on exported ghjk object from ghjk.ts: ${args.uri}`,
);
}
const rawConfig = await mod.ghjk.sophon.getConfig(args.uri, mod.secureConfig);
const rawConfig = await mod.sophon.getConfig(args.uri, mod.secureConfig);
const config = JSON.parse(JSON.stringify(rawConfig));
return {
config,
Expand Down
10 changes: 5 additions & 5 deletions files/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,16 +555,16 @@ export class Ghjkfile {
envsNamed: {},
};
const workingSet = indie;
// console.log({
// indie,
// deps,
// });
/* $.dbg("graph", {
indie,
deps,
}); */
while (workingSet.length > 0) {
const item = workingSet.pop()!;
const final = all[item];

const base = this.#mergeEnvs(final.envBaseResolved ?? [], final.key);
// console.log({ parents: final.envBaseResolved, child: final.key, base });
// $.dbg("processing", { parents: final.envBaseResolved, child: final.key, base });

const finalVars = {
...base.vars,
Expand Down
9 changes: 5 additions & 4 deletions ghjk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-nocheck: Ghjkfile based on Deno

import { file } from "./mod.ts";
export { sophon } from "./mod.ts";
import { $, file } from "./mod.ts";

import * as ports from "./ports/mod.ts";
import { switchMap } from "./port.ts";
Expand All @@ -9,7 +10,7 @@ import { downloadFile, DownloadFileArgs } from "./utils/mod.ts";
import { unarchive } from "./utils/unarchive.ts";
import dummy from "./ports/dummy.ts";

export const ghjk = file({});
const ghjk = file({});

const DENO_VERSION = "2.1.2";
// keep in sync with the deno repo's ./rust-toolchain.toml
Expand Down Expand Up @@ -81,8 +82,8 @@ ghjk.env("main")
// "deno",
],
"DEBUG": [
// "runtime",
// "tokio",
"runtime",
"tokio",
],
"INFO": [
"deno::npm",
Expand Down
3 changes: 2 additions & 1 deletion hack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
//! import the functions defined herin and mess with your ghjkfile.

export * from "./mod.ts";
export { sophon } from "./mod.ts";
import { file } from "./mod.ts";
import logger from "./utils/logger.ts";

export const ghjk = Object.freeze(file());
const ghjk = file();
export const config = Object.freeze(firstCallerCheck(ghjk.config));
export const env = Object.freeze(firstCallerCheck(ghjk.env));
export const install = Object.freeze(firstCallerCheck(ghjk.install));
Expand Down
2 changes: 1 addition & 1 deletion host/init/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async function handleVscodeSettings(
});
const parsedConfig = unwrapZodRes(schema.safeParse(originalConfig), {
originalConfig,
}, "unexpected JSON discovored at .vscode/settings.json");
}, "unexpected JSON discovered at .vscode/settings.json");

let writeOut = false;

Expand Down
Loading

0 comments on commit ecfedaa

Please sign in to comment.