diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f1bcdd4..51aed6c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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/action@v3.0.1 env: SKIP: ghjk-resolve diff --git a/deno.lock b/deno.lock index 56220f3..840393d 100644 --- a/deno.lock +++ b/deno.lock @@ -108,6 +108,17 @@ "https://deno.land/std@0.116.0/path/posix.ts": "34349174b9cd121625a2810837a82dd8b986bbaaad5ade690d1de75bbb4555b2", "https://deno.land/std@0.116.0/path/separator.ts": "8fdcf289b1b76fd726a508f57d3370ca029ae6976fcde5044007f062e643ff1c", "https://deno.land/std@0.116.0/path/win32.ts": "11549e8c6df8307a8efcfa47ad7b2a75da743eac7d4c89c9723a944661c8bd2e", + "https://deno.land/std@0.134.0/_util/assert.ts": "e94f2eb37cebd7f199952e242c77654e43333c1ac4c5c700e929ea3aa5489f74", + "https://deno.land/std@0.134.0/_util/os.ts": "49b92edea1e82ba295ec946de8ffd956ed123e2948d9bd1d3e901b04e4307617", + "https://deno.land/std@0.134.0/path/_constants.ts": "df1db3ffa6dd6d1252cc9617e5d72165cd2483df90e93833e13580687b6083c3", + "https://deno.land/std@0.134.0/path/_interface.ts": "ee3b431a336b80cf445441109d089b70d87d5e248f4f90ff906820889ecf8d09", + "https://deno.land/std@0.134.0/path/_util.ts": "c1e9686d0164e29f7d880b2158971d805b6e0efc3110d0b3e24e4b8af2190d2b", + "https://deno.land/std@0.134.0/path/common.ts": "bee563630abd2d97f99d83c96c2fa0cca7cee103e8cb4e7699ec4d5db7bd2633", + "https://deno.land/std@0.134.0/path/glob.ts": "cb5255638de1048973c3e69e420c77dc04f75755524cb3b2e160fe9277d939ee", + "https://deno.land/std@0.134.0/path/mod.ts": "4275129bb766f0e475ecc5246aa35689eeade419d72a48355203f31802640be7", + "https://deno.land/std@0.134.0/path/posix.ts": "663e4a6fe30a145f56aa41a22d95114c4c5582d8b57d2d7c9ed27ad2c47636bb", + "https://deno.land/std@0.134.0/path/separator.ts": "fe1816cb765a8068afb3e8f13ad272351c85cbc739af56dacfc7d93d710fe0f9", + "https://deno.land/std@0.134.0/path/win32.ts": "e7bdf63e8d9982b4d8a01ef5689425c93310ece950e517476e22af10f41a136e", "https://deno.land/std@0.213.0/archive/_common.ts": "85edd5cdd4324833f613c1bc055f8e2f935cc9229c6b3044421268d9959997ef", "https://deno.land/std@0.213.0/archive/untar.ts": "7677c136f2188cd8c33363ccaaee6e77d4ca656cca3e2093d08de8f294d4353d", "https://deno.land/std@0.213.0/assert/_constants.ts": "a271e8ef5a573f1df8e822a6eb9d09df064ad66a4390f21b3e31f820a38e0975", @@ -439,6 +450,14 @@ "https://deno.land/x/json_hash@0.2.0/canon.ts": "ce7c07abd871cd7f0eb1280ad9f58f6382f02f84a217898ce977cf35ad315877", "https://deno.land/x/jszip@0.11.0/mod.ts": "5661ddc18e9ac9c07e3c5d2483bc912a7022b6af0d784bb7b05035973e640ba1", "https://deno.land/x/jszip@0.11.0/types.ts": "1528d1279fbb64dd118c371331c641a3a5eff2b594336fb38a7659cf4c53b2d1", + "https://deno.land/x/os_paths@v7.2.0/dist/esm/lib/OSPaths.js": "db4f5f05765a1c862e7b1e0f0c293fc752e94e213eabff19f3c03af9b2164f98", + "https://deno.land/x/os_paths@v7.2.0/src/mod.deno.ts": "5e34d7c1a033665276a1a06e3957a52218bf4711a801f38cf92978aacfad5666", + "https://deno.land/x/os_paths@v7.2.0/src/platform-adapters/_base.ts": "ca9adf679709824e070631921932620ab4dc2a39fff9706f95592d1620e34dc6", + "https://deno.land/x/os_paths@v7.2.0/src/platform-adapters/deno.deno.ts": "d184d709522bf2703dc12ff335eb6a10d758a3a5dd4d97524d2aef9d3d448c13", + "https://deno.land/x/xdg_portable@v10.6.0/dist/esm/lib/XDG.js": "4c04a45149d66e4ca29ea914aac137e7b0f0b6a8ef431ffc63fef46bc3747064", + "https://deno.land/x/xdg_portable@v10.6.0/src/mod.deno.ts": "e478cc109794bfc130ec81711f9a20d594e6fad848f796c68b75dbe510683c39", + "https://deno.land/x/xdg_portable@v10.6.0/src/platform-adapters/_base.ts": "c79a7f0e5b1d77e23cbc6c782a02958573338e9dfa644a7aa5a1f7c402ff56ef", + "https://deno.land/x/xdg_portable@v10.6.0/src/platform-adapters/deno.deno.ts": "5f5852dc4588c10ad8fd0450421fa728741838cf5839a209d53323ccc9ed4c00", "https://esm.sh/jszip@3.7.1": "f3872a819b015715edb05f81d973b5cd05d3d213d8eb28293ca5471fe7a71773", "https://esm.sh/v135/jszip@3.7.1/denonext/jszip.mjs": "d31d7f9e0de9c6db3c07ca93f7301b756273d4dccb41b600461978fc313504c9" } diff --git a/deps/install.ts b/deps/install.ts new file mode 100644 index 0000000..ba2dc07 --- /dev/null +++ b/deps/install.ts @@ -0,0 +1 @@ +export { default as xdg } from "https://deno.land/x/xdg_portable@v10.6.0/src/mod.deno.ts"; diff --git a/ghjk.ts b/ghjk.ts index e8b3e33..54b207f 100644 --- a/ghjk.ts +++ b/ghjk.ts @@ -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 = { diff --git a/install.sh b/install.sh index 0d7a076..1eaa503 100755 --- a/install.sh +++ b/install.sh @@ -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 < = { @@ -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; diff --git a/install/utils.ts b/install/utils.ts index f89cd2b..a679684 100644 --- a/install/utils.ts +++ b/install/utils.ts @@ -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, @@ -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, diff --git a/modules/envs/posix.ts b/modules/envs/posix.ts index e9d0f21..d7466dd 100644 --- a/modules/envs/posix.ts +++ b/modules/envs/posix.ts @@ -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(( @@ -211,7 +211,7 @@ async function writeActivators( key, val .replace(gcx.ghjkDir.toString(), "$" + ghjkDirVar) - .replace(gcx.ghjkShareDir.toString(), "$" + shareDirVar), + .replace(gcx.ghjkDataDir.toString(), "$" + dataDirVar), ]), ), }; @@ -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`, @@ -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`, @@ -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`, @@ -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`, diff --git a/modules/ports/mod.ts b/modules/ports/mod.ts index 99d6d5c..98f9b7b 100644 --- a/modules/ports/mod.ts +++ b/modules/ports/mod.ts @@ -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; } diff --git a/modules/ports/sync.ts b/modules/ports/sync.ts index c39e659..9a0ad98 100644 --- a/modules/ports/sync.ts +++ b/modules/ports/sync.ts @@ -53,7 +53,7 @@ export type SyncCtx = Awaited>; 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([ diff --git a/modules/tasks/mod.ts b/modules/tasks/mod.ts index b0f5935..c5349c2 100644 --- a/modules/tasks/mod.ts +++ b/modules/tasks/mod.ts @@ -97,7 +97,7 @@ export class TasksModule extends ModuleBase { 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; diff --git a/modules/types.ts b/modules/types.ts index f1c23ce..561fa2b 100644 --- a/modules/types.ts +++ b/modules/types.ts @@ -16,7 +16,7 @@ export type ModuleManifest = zod.infer; export type GhjkCtx = { ghjkfilePath?: Path; ghjkDir: Path; - ghjkShareDir: Path; + ghjkDataDir: Path; blackboard: Map; }; diff --git a/scripts/dev.ts b/scripts/dev.ts index 65b2577..d6e737c 100755 --- a/scripts/dev.ts +++ b/scripts/dev.ts @@ -31,7 +31,7 @@ exec ${ghjkExePath.resolve().toString()} "$@"`, const env: Record = { 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(), @@ -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); diff --git a/src/deno_systems/bindings.ts b/src/deno_systems/bindings.ts index 84e3021..496d2cd 100644 --- a/src/deno_systems/bindings.ts +++ b/src/deno_systems/bindings.ts @@ -40,7 +40,7 @@ await prepareSystems(args); async function prepareSystems(args: zod.infer) { 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, diff --git a/src/denort/worker.rs b/src/denort/worker.rs index 9a36e4c..ff877e7 100644 --- a/src/denort/worker.rs +++ b/src/denort/worker.rs @@ -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>, diff --git a/src/ghjk/ext/callbacks.rs b/src/ghjk/ext/callbacks.rs index bbcc72a..72507ad 100644 --- a/src/ghjk/ext/callbacks.rs +++ b/src/ghjk/ext/callbacks.rs @@ -118,8 +118,8 @@ pub fn worker(config: &ExtConfig) -> Option { 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(); diff --git a/src/ghjk/host/hashfile.rs b/src/ghjk/host/hashfile.rs index 5904dd2..aa5fb2b 100644 --- a/src/ghjk/host/hashfile.rs +++ b/src/ghjk/host/hashfile.rs @@ -130,6 +130,9 @@ async fn file_digests( hcx: &HostCtx, read_files: Vec<&Path>, ) -> Res>> { + // 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() @@ -199,7 +202,6 @@ async fn file_content_digest_hash( path: &Path, ) -> Res { 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()), diff --git a/src/ghjk/js/runtime.js b/src/ghjk/js/runtime.js index b03bd45..2931f83 100644 --- a/src/ghjk/js/runtime.js +++ b/src/ghjk/js/runtime.js @@ -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} diff --git a/src/ghjk/log.rs b/src/ghjk/log.rs index 28325d7..34279bb 100644 --- a/src/ghjk/log.rs +++ b/src/ghjk/log.rs @@ -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() { diff --git a/src/ghjk/systems/deno/cli.rs b/src/ghjk/systems/deno/cli.rs index 2d20c5b..8820714 100644 --- a/src/ghjk/systems/deno/cli.rs +++ b/src/ghjk/systems/deno/cli.rs @@ -1,3 +1,6 @@ +//! Types and conversions for runtime specified CLI commands +//! from deno systems + use crate::{interlude::*, systems::CliCommandAction}; #[derive(Debug, Deserialize)] diff --git a/src/ghjk/utils.rs b/src/ghjk/utils.rs index 937e0a3..c582840 100644 --- a/src/ghjk/utils.rs +++ b/src/ghjk/utils.rs @@ -168,7 +168,7 @@ pub async fn hash_reader(reader: T) -> Res { 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); diff --git a/utils/mod.ts b/utils/mod.ts index 330f085..ab0d689 100644 --- a/utils/mod.ts +++ b/utils/mod.ts @@ -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", );