Skip to content

Commit

Permalink
fix: address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed Dec 30, 2024
1 parent f7afd37 commit 27f9cbc
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
# pre commit runs ghjk. We'll always see changes
# to lock.json since GITHUB_TOKEN is different
# in the CI
- run: deno task self print config
- run: deno task self envs cook -t lock-sed
- uses: pre-commit/[email protected]
env:
SKIP: ghjk-resolve
Expand Down
19 changes: 19 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions deps/install.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as xdg } from "https://deno.land/x/[email protected]/src/mod.deno.ts";
2 changes: 1 addition & 1 deletion ghjk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { sedLock } from "./std.ts";
import { downloadFile, DownloadFileArgs } from "./utils/mod.ts";
import { unarchive } from "./utils/unarchive.ts";

// keep in sync with deno's reqs
// keep in sync with the deno repo's ./rust-toolchain.toml
const RUST_VERSION = "1.82.0";

const installs = {
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ printf "Detected version: %s\n" "$VERSION"
ASSET="$NAME-v$VERSION-$PLATFORM"
DOWNLOAD_URL="$RELEASE_URL/download/v$VERSION/$ASSET.$EXT"

if curl --fail --silent --location --output "$TMP_DIR/$ASSET.$EXT" "$DOWNLOAD_URL"; then
if curl --fail --silent --location --tlsv1.2 --proto '=https' --output "$TMP_DIR/$ASSET.$EXT" "$DOWNLOAD_URL"; then
printf "Downloaded successfully: %s\n" "$ASSET.$EXT"
else
cat >&2 <<EOF
Expand Down
29 changes: 23 additions & 6 deletions install/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
// relying on --frozen-lockfile

import getLogger from "../utils/logger.ts";
import { $, dirs, importRaw } from "../utils/mod.ts";
import { $, importRaw } from "../utils/mod.ts";
import type { Path } from "../utils/mod.ts";
import { xdg } from "../deps/install.ts";

const logger = getLogger(import.meta);

Expand Down Expand Up @@ -97,20 +98,36 @@ async function filterAddContent(
interface InstallArgs {
homeDir: string;
ghjkDataDir: string;
ghjkConfigDir: string;
shellsToHook?: string[];
/** The mark used when adding the hook to the user's shell rcs.
* Override to allow multiple hooks in your rc.
*/
shellHookMarker: string;
}

function getHomeDir() {
switch (Deno.build.os) {
case "linux":
case "darwin":
return Deno.env.get("HOME") ?? null;
case "windows":
return Deno.env.get("USERPROFILE") ?? null;
default:
return null;
}
}
const homeDir = getHomeDir();
if (!homeDir) {
throw new Error("cannot find home dir");
}

export const defaultInstallArgs: InstallArgs = {
ghjkDataDir: $.path(dirs().shareDir).resolve("ghjk").toString(),
homeDir: dirs().homeDir,
// remove first the xdg.data suffix added in windows by lib
ghjkDataDir: $.path(xdg.data().replace("xdg.data", "")).resolve("ghjk")
.toString(),
homeDir,
shellsToHook: [],
shellHookMarker: "ghjk-hook-default",
ghjkConfigDir: $.path(dirs().configDir).toString(),
};

const shellConfig: Record<string, string> = {
Expand All @@ -134,7 +151,7 @@ export async function install(
await unpackVFS(
await getHooksVfs(),
ghjkDataDir,
[[/__GHJK_SHARE_DIR__/g, ghjkDataDir.toString()]],
[[/__GHJK_DATA_DIR__/g, ghjkDataDir.toString()]],
);
for (const shell of args.shellsToHook ?? Object.keys(shellConfig)) {
const { homeDir } = args;
Expand Down
2 changes: 2 additions & 0 deletions install/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { GhjkCtx } from "../modules/types.ts";

/**
* Returns a simple posix function to invoke the ghjk CLI.
* This shim assumes it's running inside the ghjk embedded deno runtime.
*/
export function ghjk_sh(
gcx: GhjkCtx,
Expand All @@ -17,6 +18,7 @@ export function ghjk_sh(

/**
* Returns a simple fish function to invoke the ghjk CLI.
* This shim assumes it's running inside the ghjk embedded deno runtime.
*/
export function ghjk_fish(
gcx: GhjkCtx,
Expand Down
15 changes: 6 additions & 9 deletions modules/envs/posix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ async function writeActivators(
onExitHooks: [string, string[]][],
) {
const ghjkDirVar = "_ghjk_dir";
const shareDirVar = "_ghjk_share_dir";
const dataDirVar = "_ghjk_data_dir";
pathVars = {
...Object.fromEntries(
Object.entries(pathVars).map((
Expand All @@ -211,7 +211,7 @@ async function writeActivators(
key,
val
.replace(gcx.ghjkDir.toString(), "$" + ghjkDirVar)
.replace(gcx.ghjkShareDir.toString(), "$" + shareDirVar),
.replace(gcx.ghjkDataDir.toString(), "$" + dataDirVar),
]),
),
};
Expand Down Expand Up @@ -249,7 +249,7 @@ async function writeActivators(
``,
`# the following variables are used to make the script more human readable`,
`${ghjkDirVar}="${gcx.ghjkDir.toString()}"`,
`${shareDirVar}="${gcx.ghjkShareDir.toString()}"`,
`${dataDirVar}="${gcx.ghjkDataDir.toString()}"`,
``,
`export GHJK_CLEANUP_POSIX="";`,
`# env vars`,
Expand Down Expand Up @@ -302,10 +302,7 @@ async function writeActivators(
}),
``,
`# hooks that want to invoke ghjk are made to rely`,
`# on this shim instead to improve latency`,
// the ghjk executable is itself a shell script
// which execs deno, we remove the middleman here
// also, the ghjk executable is optional
`# on this shim to improve to improve reliablity`,
ghjk_sh(gcx, ghjkShimName),
``,
`# only run the hooks in interactive mode`,
Expand Down Expand Up @@ -343,7 +340,7 @@ async function writeActivators(
``,
`# the following variables are used to make the script more human readable`,
`set ${ghjkDirVar} "${gcx.ghjkDir.toString()}"`,
`set ${shareDirVar} "${gcx.ghjkShareDir.toString()}"`,
`set ${dataDirVar} "${gcx.ghjkDataDir.toString()}"`,
``,
`# env vars`,
`# we keep track of old values before this script is run`,
Expand Down Expand Up @@ -373,7 +370,7 @@ async function writeActivators(
}),
``,
`# hooks that want to invoke ghjk are made to rely`,
`# on this shim to improve latency`,
`# on this shim to improve to improve reliablity`,
ghjk_fish(gcx, ghjkShimName),
``,
`# only run the hooks in interactive mode`,
Expand Down
6 changes: 2 additions & 4 deletions modules/ports/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,11 @@ async function outdatedCommand(
}

if (updateInstallFlag) {
const installName = updateInstallFlag;
// TODO: convert from install name to install id, after port module refactor
let installId!: string;
const installId = updateInstallFlag;
const newVersion = latest.get(installId);
if (!newVersion) {
logger().info(
`Error while fetching the latest version for: ${installName}`,
`Error while fetching the latest version for: ${installId}`,
);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/ports/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type SyncCtx = Awaited<ReturnType<typeof syncCtxFromGhjk>>;
export async function syncCtxFromGhjk(
gcx: GhjkCtx,
) {
const portsPath = await $.path(gcx.ghjkShareDir).resolve("ports")
const portsPath = await $.path(gcx.ghjkDataDir).resolve("ports")
.ensureDir();
const [installsPath, downloadsPath, tmpPath] = (
await Promise.all([
Expand Down
2 changes: 1 addition & 1 deletion modules/tasks/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class TasksModule extends ModuleBase<TasksLockEnt> {
const entry = lockValidator.parse(raw);

if (entry.version != "0") {
throw new Error(`unexepected version tag deserializing lockEntry`);
throw new Error(`unexpected version tag deserializing lockEntry`);
}

return entry;
Expand Down
2 changes: 1 addition & 1 deletion modules/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type ModuleManifest = zod.infer<typeof moduleManifest>;
export type GhjkCtx = {
ghjkfilePath?: Path;
ghjkDir: Path;
ghjkShareDir: Path;
ghjkDataDir: Path;
blackboard: Map<string, unknown>;
};

Expand Down
6 changes: 3 additions & 3 deletions scripts/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ exec ${ghjkExePath.resolve().toString()} "$@"`,
const env: Record<string, string> = {
BASH_ENV: `${ghjkDataDir.toString()}/env.bash`,
ZDOTDIR: ghjkDataDir.toString(),
GHJK_SHARE_DIR: ghjkDataDir.toString(),
GHJK_DATA_DIR: ghjkDataDir.toString(),
PATH: `${ghjkDataDir.toString()}:${Deno.env.get("PATH")}`,
GHJK_CONFIG_DIR: devDir.toString(),
// HOME: devDir.toString(),
Expand All @@ -49,12 +49,12 @@ await install({
shellsToHook: [],
});

// await $`${ghjkShareDir.join("ghjk").toString()} print config`
// await $`${ghjkDataDir.join("ghjk").toString()} print config`
// .cwd(devDir.toString())
// .clearEnv()
// .env(env);
//
// await $`${ghjkShareDir.join("ghjk").toString()} envs cook`
// await $`${ghjkDataDir.join("ghjk").toString()} envs cook`
// .cwd(devDir.toString())
// .clearEnv()
// .env(env);
Expand Down
2 changes: 1 addition & 1 deletion src/deno_systems/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ await prepareSystems(args);
async function prepareSystems(args: zod.infer<typeof prepareArgs>) {
const gcx = {
ghjkDir: $.path(args.config.ghjkdir),
ghjkShareDir: $.path(args.config.data_dir),
ghjkDataDir: $.path(args.config.data_dir),
ghjkfilePath: args.config.ghjkfile
? $.path(args.config.ghjkfile)
: undefined,
Expand Down
7 changes: 4 additions & 3 deletions src/denort/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ use deno::{
// thread tag used for basic sanity checks
pub const WORKER_THREAD_NAME: &str = "denort-worker-thread";

/// This starts a new thread and uses it to run all the tasks
/// that'll need to touch deno internals. Deno is single threaded.
/// This starts a new task to run all the work
/// that'll need to touch deno internals.
/// Deno is single threaded and this expects to run on single threaded runtimes.
///
/// Returned handles will use channels internally to communicate to this worker.
/// The returned handle will use channels internally to communicate to this worker.
pub async fn worker(
flags: deno::args::Flags,
custom_extensions_cb: Option<Arc<deno::worker::CustomExtensionsCb>>,
Expand Down
4 changes: 2 additions & 2 deletions src/ghjk/ext/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ pub fn worker(config: &ExtConfig) -> Option<Callbacks> {
mut rx,
term_signal,
} = {
let mut mutex = config.callbacks_rx.lock().expect_or_log("mutex err");
mutex.take()?
let mut line = config.callbacks_rx.lock().expect_or_log("mutex err");
line.take()?
};

let callbacks = Callbacks::default();
Expand Down
4 changes: 3 additions & 1 deletion src/ghjk/host/hashfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ async fn file_digests(
hcx: &HostCtx,
read_files: Vec<&Path>,
) -> Res<IndexMap<PathBuf, Option<String>>> {
// FIXME: this will exhaust memory if the number of files is large
// ConcurrentStream supports limiting concurrency but has a bug
// tracked at https://github.com/yoshuawuyts/futures-concurrency/issues/203
futures::future::join_all(
read_files
.into_iter()
Expand Down Expand Up @@ -199,7 +202,6 @@ async fn file_content_digest_hash(
path: &Path,
) -> Res<SharedFileContentDigestFuture> {
let path = path.to_owned();

use dashmap::mapref::entry::*;
match hcx.file_hash_memo.entry(path.clone()) {
Entry::Occupied(occupied_entry) => Ok(occupied_entry.get().clone()),
Expand Down
4 changes: 0 additions & 4 deletions src/ghjk/js/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
//! This file provides the import point for types and values defined in:
// - ./00_runtime.js: which is preloaded by the custom deno runtime
// - ./runtime.d.ts: which types the objects from the preload
//
// The preload directly adds the Ghjk object the global scope but we can hide
// that implementation detail and users will "import" `Ghjk` from this file instead.
// Or at least that is what will appear to be happening to in the type system.

/**
* @type {import('./runtime.d.ts').GhjkNs}
Expand Down
5 changes: 1 addition & 4 deletions src/ghjk/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,9 @@ Args: {args:?}
eyre_panic_hook(panic_info);
// - Tokio does not exit the process when a task panics, so we define a custom
// panic hook to implement this behaviour.
// std::process::exit(1);
std::process::exit(1);
}));

// // FIXME: for some reason, the tests already have
// // an eyre_hook
// #[cfg(not(test))]
_eyre_hook.install().unwrap();

if std::env::var("RUST_LOG").is_err() {
Expand Down
3 changes: 3 additions & 0 deletions src/ghjk/systems/deno/cli.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Types and conversions for runtime specified CLI commands
//! from deno systems
use crate::{interlude::*, systems::CliCommandAction};

#[derive(Debug, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion src/ghjk/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub async fn hash_reader<T: tokio::io::AsyncRead>(reader: T) -> Res<String> {
use sha2::Digest;
use tokio::io::*;
let mut hash = sha2::Sha256::new();
let mut buf = vec![0u8; 4096];
let mut buf = vec![0u8; 65536];

let reader = tokio::io::BufReader::new(reader);

Expand Down
25 changes: 0 additions & 25 deletions utils/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,31 +306,6 @@ export async function findEntryRecursive(path: string | Path, name: string) {
}
}

export function homeDir() {
switch (Deno.build.os) {
case "linux":
case "darwin":
return Deno.env.get("HOME") ?? null;
case "windows":
return Deno.env.get("USERPROFILE") ?? null;
default:
return null;
}
}

export function dirs() {
const home = homeDir();
if (!home) {
throw new Error("cannot find home dir");
}
return {
homeDir: home,
// FIXME: use proper xdg dirs
shareDir: $.path(home).resolve(".local", "share"),
configDir: $.path(home).resolve(".config", "ghjk"),
};
}

export const AVAIL_CONCURRENCY = Number.parseInt(
Deno.env.get("DENO_JOBS") ?? "1",
);
Expand Down

0 comments on commit 27f9cbc

Please sign in to comment.