From 90c72dccc485cde047e6892d1c3711bfcebabf48 Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Wed, 25 Sep 2024 13:18:33 -0500 Subject: [PATCH] feat: added postinstall hook (#2654) Fixes #1014 --- docs/dev-tools/index.md | 7 +++++++ e2e/plugins/test_tiny | 2 +- src/backend/mod.rs | 26 +++++++++++++++++++++----- src/config/mod.rs | 9 +++++---- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/docs/dev-tools/index.md b/docs/dev-tools/index.md index e92ad22ee..cced2be4b 100644 --- a/docs/dev-tools/index.md +++ b/docs/dev-tools/index.md @@ -155,5 +155,12 @@ mise plugins may accept configuration in the form of tool options specified in ` mytool = { version = '3.10', foo = 'bar' } ``` +All tools can accept a `postinstall` option which is a shell command to run after the tool is installed: + +```toml +[tools] +node = { version = '20', postinstall = 'corepack enable' } +``` + Unfortunately at the time of this writing, it's not possible to specify this via the CLI in `mise use` or other commands though. See diff --git a/e2e/plugins/test_tiny b/e2e/plugins/test_tiny index 6aa995df4..8363bf2eb 100644 --- a/e2e/plugins/test_tiny +++ b/e2e/plugins/test_tiny @@ -2,7 +2,7 @@ cat >.mise.toml < eyre::Result<()> { + CmdLineRunner::new(&*env::SHELL) + .env(&*env::PATH_KEY, CorePlugin::path_env_with_tv_path(&ctx.tv)?) + .with_pr(ctx.pr.as_ref()) + .arg("-c") + .arg(script) + .envs(self.exec_env(&CONFIG, ctx.ts, &ctx.tv)?) + .execute()?; + Ok(()) + } fn install_version_impl(&self, ctx: &InstallContext) -> eyre::Result<()>; fn uninstall_version( &self, diff --git a/src/config/mod.rs b/src/config/mod.rs index 7aebd6266..b4ebd17dc 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -50,18 +50,19 @@ pub struct Config { tool_request_set: OnceCell, } -static CONFIG: RwLock>> = RwLock::new(None); +pub static CONFIG: Lazy> = Lazy::new(Config::get); +static _CONFIG: RwLock>> = RwLock::new(None); impl Config { pub fn get() -> Arc { Self::try_get().unwrap() } pub fn try_get() -> Result> { - if let Some(config) = &*CONFIG.read().unwrap() { + if let Some(config) = &*_CONFIG.read().unwrap() { return Ok(config.clone()); } let config = Arc::new(Self::load()?); - *CONFIG.write().unwrap() = Some(config.clone()); + *_CONFIG.write().unwrap() = Some(config.clone()); Ok(config) } pub fn load() -> Result { @@ -416,7 +417,7 @@ impl Config { #[cfg(test)] pub fn reset() { Settings::reset(None); - CONFIG.write().unwrap().take(); + _CONFIG.write().unwrap().take(); } }