Browse Source
I am still not sure this will fix the graphic IDE issue, but it will most certainly fix the rehashing issues. Still need to consider how to tackle the IDE issue. Hmm. Maybe I have the strangest idea. I will try.remotes/origin/add-with-shims
![gal@spitfire.co.il](/assets/img/avatar_default.png)
13 changed files with 195 additions and 11 deletions
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
use crate::config::FnmConfig; |
||||
use log::info; |
||||
use std::io::Write; |
||||
use std::path::PathBuf; |
||||
|
||||
#[cfg(not(windows))] |
||||
const SHIM_CONTENT: &[u8] = include_bytes!("./unix.sh"); |
||||
|
||||
#[cfg(windows)] |
||||
const SHIM_CONTENT: &[u8] = include_bytes!("./windows.cmd"); |
||||
|
||||
pub type Error = std::io::Error; |
||||
|
||||
/// Creates shims for a path and returns the shim directory
|
||||
pub fn store_shim(config: &FnmConfig) -> Result<PathBuf, Error> { |
||||
let dir = shims_dir(config)?; |
||||
let executable_path = dir.join(if cfg!(not(windows)) { |
||||
"node" |
||||
} else { |
||||
"node.cmd" |
||||
}); |
||||
|
||||
if executable_path.exists() { |
||||
return Ok(dir); |
||||
} |
||||
|
||||
info!("Creating a shim at {}", executable_path.display()); |
||||
let mut file = std::fs::File::create(&executable_path)?; |
||||
|
||||
#[cfg(not(windows))] |
||||
{ |
||||
use std::os::unix::prelude::PermissionsExt; |
||||
info!("Setting file permissions to 777"); |
||||
let mut perm = file.metadata()?.permissions(); |
||||
perm.set_mode(0o777); |
||||
file.set_permissions(perm)?; |
||||
}; |
||||
|
||||
file.write_all(SHIM_CONTENT)?; |
||||
|
||||
Ok(dir) |
||||
} |
||||
|
||||
fn shims_dir(config: &FnmConfig) -> Result<PathBuf, std::io::Error> { |
||||
let path = config.base_dir_with_default().join("shims"); |
||||
std::fs::create_dir_all(&path)?; |
||||
Ok(path) |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
use tempfile::tempdir; |
||||
|
||||
#[test] |
||||
fn test_shim() { |
||||
let base_dir = tempdir().unwrap(); |
||||
let config = FnmConfig::default().with_base_dir(Some(base_dir.into_path())); |
||||
let dir = shims_dir(&config).unwrap(); |
||||
assert!(dir.exists()); |
||||
} |
||||
} |
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env sh |
||||
|
||||
fnm exec --using-current -- node "$@" |
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
@echo off |
||||
|
||||
fnm exec --using-current -- node %* |
||||
|
||||
@echo on |
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
--- |
||||
source: tests/feature_tests/mod.rs |
||||
expression: "&source.trim()" |
||||
|
||||
--- |
||||
set -e |
||||
shopt -s expand_aliases |
||||
|
||||
eval "$(fnm env --with-shims)" |
||||
fnm install v8.11.3 |
||||
fnm use v8.11.3 |
||||
if [ "$(node -v)" != "v8.11.3" ]; then |
||||
echo 'Expected Node version to be "v8.11.3", Got: '"$(node -v)" |
||||
exit 1 |
||||
fi |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
--- |
||||
source: tests/feature_tests/mod.rs |
||||
expression: "&source.trim()" |
||||
|
||||
--- |
||||
fnm env --with-shims | source |
||||
fnm install v8.11.3 |
||||
fnm use v8.11.3 |
||||
if test (node -v) != "v8.11.3" |
||||
echo 'Expected Node version to be "v8.11.3", Got: '(node -v) |
||||
exit 1 |
||||
end |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
--- |
||||
source: tests/feature_tests/mod.rs |
||||
expression: "&source.trim()" |
||||
|
||||
--- |
||||
$ErrorActionPreference = "Stop" |
||||
fnm env --with-shims | Out-String | Invoke-Expression |
||||
fnm install v8.11.3 |
||||
fnm use v8.11.3 |
||||
If ("$(node -v)" -ne "v8.11.3") { |
||||
Write-Output ('Expected Node version to be "v8.11.3", Got: ' + $(node -v)) |
||||
exit 1 |
||||
} |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
--- |
||||
source: tests/feature_tests/mod.rs |
||||
expression: "&source.trim()" |
||||
|
||||
--- |
||||
FOR /f "tokens=*" %i IN ('fnm env --with-shims') DO CALL %i |
||||
fnm install v8.11.3 |
||||
fnm use v8.11.3 |
||||
node -v | findstr v8.11.3 |
||||
if %errorlevel% neq 0 ( |
||||
echo Node version does not match "v8.11.3" |
||||
exit 1 |
||||
) |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
--- |
||||
source: tests/feature_tests/mod.rs |
||||
expression: "&source.trim()" |
||||
|
||||
--- |
||||
set -e |
||||
eval "$(fnm env --with-shims)" |
||||
fnm install v8.11.3 |
||||
fnm use v8.11.3 |
||||
if [ "$(node -v)" != "v8.11.3" ]; then |
||||
echo 'Expected Node version to be "v8.11.3", Got: '"$(node -v)" |
||||
exit 1 |
||||
fi |
Loading…
Reference in new issue