Skip to content

Commit 862deb0

Browse files
authored
Fix Version Files Not Working With Whitespaces (#199)
1 parent 82f43c7 commit 862deb0

File tree

7 files changed

+49
-38
lines changed

7 files changed

+49
-38
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,12 @@ task build:release
9898
```
9999

100100
You can find all the commands in the [Taskfile](./Taskfile.yml).
101+
102+
## Publish new version
103+
104+
1. Up version number in `Cargo.toml`
105+
2. Create tag on commit updating the version with said version (`vX.X.X`)
106+
3. Push both
107+
4. Wait for CI to create draft release for tag
108+
5. Edit draft release notes
109+
6. Publish

src/constants.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#[cfg(windows)]
2+
pub const EXEC_EXT: &str = ".cmd";
3+
#[cfg(not(windows))]
4+
pub const EXEC_EXT: &str = "";
5+
6+
#[cfg(target_os = "windows")]
7+
pub const PLATFORM: &str = "win";
8+
#[cfg(target_os = "macos")]
9+
pub const PLATFORM: &str = "darwin";
10+
#[cfg(target_os = "linux")]
11+
pub const PLATFORM: &str = "linux";
12+
13+
#[cfg(target_os = "windows")]
14+
pub const EXT: &str = ".zip";
15+
#[cfg(target_os = "macos")]
16+
pub const EXT: &str = ".tar.gz";
17+
#[cfg(target_os = "linux")]
18+
pub const EXT: &str = ".tar.gz";
19+
20+
#[cfg(target_arch = "x86_64")]
21+
pub const ARCH: &str = "x64";
22+
#[cfg(target_arch = "x86")]
23+
pub const ARCH: &str = "x86";
24+
#[cfg(target_arch = "aarch64")]
25+
pub const ARCH: &str = "arm64";
26+
27+
pub const X64: &str = "x64";

src/files/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn get_version_file() -> Option<VersionFile> {
5151
let contents = fs::read_to_string(existing_file);
5252

5353
if let Ok(contents) = contents {
54-
let parse_result = Range::parse(contents);
54+
let parse_result = Range::parse(contents.trim());
5555

5656
if let Ok(parse_result) = parse_result {
5757
return Some(VersionFile::Nvmrc(parse_result));

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use crate::subcommand::{
1616
};
1717

1818
mod archives;
19+
mod constants;
1920
mod files;
2021
mod node_version;
2122
mod subcommand;
22-
mod utils;
2323

2424
#[derive(Parser, Clone, Debug)]
2525
enum Subcommands {

src/node_version.rs

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,11 @@ use anyhow::{Context, Result};
99
use node_semver::{Range, Version};
1010
use serde::Deserialize;
1111

12-
use crate::{utils, Config};
13-
14-
#[cfg(target_os = "windows")]
15-
const PLATFORM: &str = "win";
16-
#[cfg(target_os = "macos")]
17-
const PLATFORM: &str = "darwin";
18-
#[cfg(target_os = "linux")]
19-
const PLATFORM: &str = "linux";
20-
21-
#[cfg(target_os = "windows")]
22-
const EXT: &str = ".zip";
23-
#[cfg(target_os = "macos")]
24-
const EXT: &str = ".tar.gz";
25-
#[cfg(target_os = "linux")]
26-
const EXT: &str = ".tar.gz";
27-
28-
#[cfg(target_arch = "x86_64")]
29-
const ARCH: &str = "x64";
30-
#[cfg(target_arch = "x86")]
31-
const ARCH: &str = "x86";
32-
#[cfg(target_arch = "aarch64")]
33-
const ARCH: &str = "arm64";
34-
35-
const X64: &str = "x64";
12+
use crate::{
13+
constants,
14+
constants::{ARCH, EXT, PLATFORM, X64},
15+
Config,
16+
};
3617

3718
pub trait NodeVersion {
3819
fn version(&self) -> &Version;
@@ -149,6 +130,7 @@ impl OnlineNodeVersion {
149130
#[cfg(target_os = "macos")]
150131
fn has_arm(&self) -> bool {
151132
for file in self.files.iter() {
133+
// We check for both ARM _and_ OSX since we don't want to fall back to x64 on other platforms.
152134
if file.contains("osx") && file.contains("arm64") {
153135
return true;
154136
}
@@ -218,8 +200,8 @@ impl InstalledNodeVersion {
218200
read_link(config.get_shims_dir()).expect("Could not read installation dir");
219201

220202
let mut required_files = vec![version_dir; 2];
221-
required_files[0].set_file_name(format!("node{}", utils::exec_ext()));
222-
required_files[1].set_file_name(format!("npm{}", utils::exec_ext()));
203+
required_files[0].set_file_name(format!("node{}", constants::EXEC_EXT));
204+
required_files[1].set_file_name(format!("npm{}", constants::EXEC_EXT));
223205

224206
if let Some(missing_file) = required_files.iter().find(|file| !file.exists()) {
225207
anyhow::bail!(

src/subcommand/install.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use node_semver::Range;
66
use ureq;
77

88
use crate::{
9-
archives, files,
9+
archives, constants, files,
1010
node_version::{
1111
filter_version_req, parse_range, InstalledNodeVersion, NodeVersion, OnlineNodeVersion,
1212
},
1313
subcommand::{switch::SwitchCommand, Action},
14-
utils, Config,
14+
Config,
1515
};
1616

1717
#[derive(Parser, Clone, Debug)]
@@ -80,7 +80,7 @@ impl Action<InstallCommand> for InstallCommand {
8080
if let Err(e) = std::process::Command::new(
8181
install_path
8282
.join("bin")
83-
.join(format!("corepack{}", utils::exec_ext())),
83+
.join(format!("corepack{}", constants::EXEC_EXT)),
8484
)
8585
.arg("enable")
8686
.output()

src/utils.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)