@repokit/core 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Cargo.lock CHANGED
@@ -988,7 +988,7 @@ checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c"
988
988
 
989
989
  [[package]]
990
990
  name = "repokit"
991
- version = "4.0.0"
991
+ version = "4.0.1"
992
992
  dependencies = [
993
993
  "alphanumeric-sort",
994
994
  "colored",
package/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "repokit"
3
- version = "4.0.0"
3
+ version = "4.0.1"
4
4
  edition = "2024"
5
5
 
6
6
  [[bin]]
@@ -1,4 +1,4 @@
1
- CURRENT_VERSION="4.0.0"
1
+ CURRENT_VERSION="4.0.1"
2
2
  CWD=$(pwd)
3
3
 
4
4
  REPLACEMENT="/node_modules"
@@ -37,14 +37,17 @@ VERSION_FILE=".version"
37
37
  SETTINGS_FILE=".settings"
38
38
  REPO_CACHE_DIRECTORY="$CACHE_DIRECTORY/$ROOT_COMMIT"
39
39
 
40
- CACHED_THEME=""
40
+ OLD_SCHEMA_CACHED_THEME=""
41
+ OLD_SCHEMA_CACHED_VERSION="$CURRENT_VERSION"
41
42
 
42
- if [ -f "$OLD_CACHE_FILE" ] && [ -n "$ROOT_COMMIT" ] && [ ! -f "$REPO_CACHE_DIRECTORY/$SETTINGS_FILE" ]; then
43
+ if [ -f "$OLD_CACHE_FILE" ]; then
43
44
  {
44
- read -r
45
- read -r CACHED_THEME
45
+ read -r OLD_SCHEMA_CACHED_VERSION
46
+ read -r OLD_SCHEMA_CACHED_THEME
46
47
  } < "$OLD_CACHE_FILE"
47
- echo "CACHED THEME $CACHED_THEME"
48
+ if [ ! -n "$ROOT_COMMIT" ] || [ -f "$REPO_CACHE_DIRECTORY/$SETTINGS_FILE" ]; then
49
+ OLD_SCHEMA_CACHED_THEME=""
50
+ fi
48
51
  fi
49
52
 
50
53
  if [ ! -d "$CACHE_DIRECTORY" ]; then
@@ -58,16 +61,16 @@ if [ -n "$ROOT_COMMIT" ]; then
58
61
  mkdir "$ROOT_COMMIT"
59
62
  fi
60
63
  cd $ROOT_COMMIT;
61
- if [ -n "$CACHED_THEME" ] && [ ! -f "$SETTINGS_FILE" ]; then
64
+ if [ -n "$OLD_SCHEMA_CACHED_THEME" ] && [ ! -f "$SETTINGS_FILE" ]; then
62
65
  touch "$SETTINGS_FILE"
63
- echo "$CACHED_THEME\n" > "$SETTINGS_FILE"
66
+ echo "$OLD_SCHEMA_CACHED_THEME\n" > "$SETTINGS_FILE"
64
67
  fi
65
68
  cd "../"
66
69
  fi
67
70
 
68
71
  if [ -f $VERSION_FILE ]; then
69
72
  read -r CACHED_VERSION < "$VERSION_FILE"
70
- if [ "$CACHED_VERSION" == "$CURRENT_VERSION" ]; then
73
+ if [ "$CACHED_VERSION" == "$CURRENT_VERSION" ] && [ "$CACHED_VERSION" == "$OLD_SCHEMA_CACHED_VERSION" ]; then
71
74
  exit 0;
72
75
  fi
73
76
  else
@@ -76,6 +79,15 @@ fi
76
79
 
77
80
  echo "$CURRENT_VERSION\n" > "$VERSION_FILE"
78
81
 
82
+ cd ../
83
+
84
+ if [ -f "$OLD_CACHE_FILE" ]; then
85
+ TEMP_FILE=".repokit_tmp";
86
+ printf "$CURRENT_VERSION\n" > "$TEMP_FILE"
87
+ tail +2 "$OLD_CACHE_FILE" >> "$TEMP_FILE"
88
+ mv "$TEMP_FILE" "$OLD_CACHE_FILE"
89
+ fi
90
+
79
91
  cd $CWD
80
92
 
81
93
  echo "Compiling from $CWD"
@@ -1,5 +1,6 @@
1
1
  pub mod crawl_cache;
2
2
  pub mod file_cache;
3
+ pub mod old_cache;
3
4
  pub mod repokit_version_resolver;
4
5
  pub mod settings_cache;
5
6
  pub mod version_cache;
@@ -0,0 +1,35 @@
1
+ use std::{env::home_dir, path::PathBuf, sync::LazyLock};
2
+
3
+ use crate::caches::{file_cache::FileCache, version_cache::VERSION_REGEX};
4
+
5
+ static OLD_CACHE_FILE: &str = ".repokit";
6
+
7
+ static OLD_CACHE_FILE_PATH: LazyLock<Option<PathBuf>> = LazyLock::new(home_dir);
8
+
9
+ pub struct OldCache;
10
+
11
+ impl FileCache for OldCache {
12
+ fn cache_file(&self) -> &str {
13
+ OLD_CACHE_FILE
14
+ }
15
+
16
+ fn cache_directory(&self) -> &Option<PathBuf> {
17
+ &OLD_CACHE_FILE_PATH
18
+ }
19
+ }
20
+
21
+ impl OldCache {
22
+ pub fn new() -> Self {
23
+ OldCache {}
24
+ }
25
+
26
+ pub fn get_version(&self) -> Option<String> {
27
+ if let Some((mut lines, _)) = self.read() {
28
+ let version = self.unwrap_line(lines.nth(0), "");
29
+ if VERSION_REGEX.is_match(&version) {
30
+ return Some(version);
31
+ }
32
+ }
33
+ None
34
+ }
35
+ }
@@ -9,7 +9,10 @@ use futures::{executor::block_on, join};
9
9
  use regex::Regex;
10
10
 
11
11
  use crate::{
12
- caches::{file_cache::FileCache, repokit_version_resolver::RepoKitVersionResolver},
12
+ caches::{
13
+ file_cache::FileCache, old_cache::OldCache,
14
+ repokit_version_resolver::RepoKitVersionResolver,
15
+ },
13
16
  context::file_system::FileSystem,
14
17
  logger::logger::Logger,
15
18
  };
@@ -18,19 +21,19 @@ use crate::{
18
21
  pub struct VersionCache {
19
22
  pub runtime_version: String,
20
23
  pub installed_version: String,
24
+ pub old_cache_path_version: String,
21
25
  pub cache_directory: Option<PathBuf>,
22
26
  }
23
27
 
24
- static UNKNOWN: &str = "UNKNOWN";
25
-
26
28
  pub static VERSION_REGEX: LazyLock<Regex> =
27
29
  LazyLock::new(|| Regex::new(r#"\d*\.\d*.\d*"#).unwrap());
28
30
 
29
31
  impl VersionCache {
30
32
  pub fn new(cache_directory: &Option<PathBuf>) -> Self {
31
33
  VersionCache {
32
- runtime_version: UNKNOWN.to_string(),
33
- installed_version: UNKNOWN.to_string(),
34
+ runtime_version: "".to_string(),
35
+ installed_version: "".to_string(),
36
+ old_cache_path_version: "".to_string(),
34
37
  cache_directory: cache_directory.clone(),
35
38
  }
36
39
  }
@@ -46,9 +49,10 @@ impl VersionCache {
46
49
  }
47
50
 
48
51
  pub async fn initialize(&mut self, files: &FileSystem) {
49
- let (runtime_result, install_result) = join!(
52
+ let (runtime_result, install_result, old_cache_path_version) = join!(
50
53
  self.runtime_version(),
51
- self.installed_repokit_version(files)
54
+ self.installed_repokit_version(files),
55
+ self.get_old_cache_path_version(),
52
56
  );
53
57
  if let Some(installed_version) = install_result {
54
58
  self.installed_version = installed_version;
@@ -56,8 +60,13 @@ impl VersionCache {
56
60
  if let Some(runtime_version) = runtime_result {
57
61
  self.runtime_version = runtime_version;
58
62
  }
59
- if self.installed_version != self.runtime_version
60
- && VERSION_REGEX.is_match(&self.installed_version)
63
+ if let Some(old_cache_version) = old_cache_path_version {
64
+ self.old_cache_path_version = old_cache_version;
65
+ }
66
+ if (self.installed_version != self.runtime_version)
67
+ || (self.installed_version != self.old_cache_path_version
68
+ && !self.old_cache_path_version.is_empty())
69
+ && VERSION_REGEX.is_match(&self.installed_version)
61
70
  {
62
71
  self.hop_to_installed_version(files);
63
72
  }
@@ -115,6 +124,11 @@ impl VersionCache {
115
124
  }
116
125
  None
117
126
  }
127
+
128
+ async fn get_old_cache_path_version(&self) -> Option<String> {
129
+ let old_cache = OldCache::new();
130
+ old_cache.get_version()
131
+ }
118
132
  }
119
133
 
120
134
  impl FileCache for VersionCache {
@@ -1,31 +1,32 @@
1
1
  use futures::{executor::block_on, join};
2
- use normalize_path::NormalizePath;
3
- use shellexpand::tilde;
4
2
  use std::{
3
+ env::home_dir,
5
4
  fs::create_dir_all,
6
- path::{Path, PathBuf},
5
+ path::PathBuf,
7
6
  };
8
7
 
9
8
  use crate::{
10
9
  caches::{
11
- crawl_cache::CrawlCache, file_cache::FileCache, settings_cache::SettingsCache,
12
- version_cache::VersionCache,
10
+ crawl_cache::CrawlCache, file_cache::FileCache,
11
+ settings_cache::SettingsCache, version_cache::VersionCache,
13
12
  },
14
13
  context::{file_system::FileSystem, git_scope::GitScope},
15
14
  };
16
15
 
17
16
  #[derive(Clone)]
18
17
  pub struct CacheScope {
18
+ pub crawl_cache: CrawlCache,
19
19
  pub version_cache: VersionCache,
20
20
  pub settings_cache: SettingsCache,
21
- pub crawl_cache: CrawlCache,
22
21
  }
23
22
 
24
23
  static CACHE_DIRECTORY: &str = ".repokit_cache";
25
24
 
26
25
  impl CacheScope {
27
26
  pub fn new(git_scope: &GitScope, file_system: &FileSystem) -> CacheScope {
28
- let cache_directory = CacheScope::resolve_cache_directory(&git_scope.root_commit_hash);
27
+ let home = home_dir();
28
+ let cache_directory =
29
+ CacheScope::resolve_cache_directory(&home, &git_scope.root_commit_hash);
29
30
  let mut instance = CacheScope {
30
31
  crawl_cache: CrawlCache::new(&cache_directory),
31
32
  version_cache: VersionCache::new(&cache_directory),
@@ -52,17 +53,11 @@ impl CacheScope {
52
53
  );
53
54
  }
54
55
 
55
- pub fn home() -> Option<PathBuf> {
56
- let expanded_path_str = tilde("~/");
57
- let path = Path::new(expanded_path_str.as_ref()).normalize();
58
- if path.is_absolute() && path.exists() {
59
- return Some(path);
60
- }
61
- None
62
- }
63
-
64
- fn resolve_cache_directory(root_commit: &Option<String>) -> Option<PathBuf> {
65
- if let Some(home) = CacheScope::home()
56
+ fn resolve_cache_directory(
57
+ home_path: &Option<PathBuf>,
58
+ root_commit: &Option<String>,
59
+ ) -> Option<PathBuf> {
60
+ if let Some(home) = home_path
66
61
  && let Some(commit_hash) = root_commit
67
62
  {
68
63
  let cache_dir = home.join(CACHE_DIRECTORY).join(commit_hash);
@@ -46,7 +46,7 @@ impl RepoKitCommand {
46
46
  failed_paths.push(path);
47
47
  }
48
48
  } else {
49
- let mut valid_command = repokit_command.expect("assertion success");
49
+ let mut valid_command = repokit_command.expect("parse success");
50
50
  valid_command.location = format!("{}/{}", git_root, valid_command.location);
51
51
  result.push(valid_command);
52
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repokit/core",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "A knowledgebase for your repository - wrapped in a CLI",
5
5
  "keywords": [
6
6
  "cli",