@anysphere/file-service 0.0.0-dacf38fa → 0.0.0-e0c70bcd

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.toml CHANGED
@@ -17,6 +17,10 @@ tempfile = "3.8.0"
17
17
  anyhow = "1.0.75"
18
18
  tonic = "0.9.2"
19
19
  prost = "0.11.9"
20
+ tracing = "0.1.37"
21
+ tracing-subscriber = "0.3.17"
22
+ tracing-appender = "0.2.2"
23
+ binaryornot = "1.0.0"
20
24
 
21
25
  [build-dependencies]
22
26
  napi-build = "2.0.1"
package/index.d.ts CHANGED
@@ -6,10 +6,15 @@
6
6
  export class MerkleClient {
7
7
  constructor(rootDirectory: string)
8
8
  init(): Promise<void>
9
+ computeMerkleTree(): Promise<void>
9
10
  updateFile(filePath: string): Promise<void>
10
11
  deleteFile(filePath: string): Promise<void>
11
- getSubtreeHash(path: string): Promise<string>
12
+ getSubtreeHash(relativePath: string): Promise<string>
12
13
  getNumEmbeddableFiles(): Promise<number>
13
14
  getAllFiles(): Promise<Array<string>>
15
+ getAllDirFilesToEmbed(absoluteFilePath: string): Promise<Array<string>>
16
+ getNextFileToEmbed(): Promise<Array<string>>
17
+ getSpline(absoluteFilePath: string): Promise<Array<string>>
14
18
  getHashesForFiles(files: Array<string>): Promise<Array<string>>
19
+ updateRootDirectory(rootDirectory: string): void
15
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anysphere/file-service",
3
- "version": "0.0.0-dacf38fa",
3
+ "version": "0.0.0-e0c70bcd",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "napi": {
@@ -9,7 +9,8 @@
9
9
  "additional": [
10
10
  "aarch64-apple-darwin",
11
11
  "aarch64-pc-windows-msvc",
12
- "universal-apple-darwin"
12
+ "universal-apple-darwin",
13
+ "aarch64-unknown-linux-gnu"
13
14
  ]
14
15
  }
15
16
  },
@@ -35,11 +36,12 @@
35
36
  "version": "napi version"
36
37
  },
37
38
  "optionalDependencies": {
38
- "@anysphere/file-service-win32-x64-msvc": "0.0.0-dacf38fa",
39
- "@anysphere/file-service-darwin-x64": "0.0.0-dacf38fa",
40
- "@anysphere/file-service-linux-x64-gnu": "0.0.0-dacf38fa",
41
- "@anysphere/file-service-darwin-arm64": "0.0.0-dacf38fa",
42
- "@anysphere/file-service-win32-arm64-msvc": "0.0.0-dacf38fa",
43
- "@anysphere/file-service-darwin-universal": "0.0.0-dacf38fa"
39
+ "@anysphere/file-service-win32-x64-msvc": "0.0.0-e0c70bcd",
40
+ "@anysphere/file-service-darwin-x64": "0.0.0-e0c70bcd",
41
+ "@anysphere/file-service-linux-x64-gnu": "0.0.0-e0c70bcd",
42
+ "@anysphere/file-service-darwin-arm64": "0.0.0-e0c70bcd",
43
+ "@anysphere/file-service-win32-arm64-msvc": "0.0.0-e0c70bcd",
44
+ "@anysphere/file-service-darwin-universal": "0.0.0-e0c70bcd",
45
+ "@anysphere/file-service-linux-arm64-gnu": "0.0.0-e0c70bcd"
44
46
  }
45
47
  }
package/src/file_utils.rs CHANGED
@@ -5,16 +5,15 @@
5
5
  // 4. vscode.fs.stat
6
6
 
7
7
  use anyhow::Error;
8
- use std::path::Path;
8
+ use std::{path::Path, any};
9
9
  use tokio::fs;
10
10
 
11
11
  pub fn is_in_bad_dir(file_path: &Path) -> Result<bool, Error> {
12
12
  let item_path = file_path
13
13
  .to_str()
14
14
  .ok_or(anyhow::anyhow!("Failed to convert path to string"))?;
15
- let is_bad_dir = (item_path.contains("node_modules")
16
- || item_path.contains(".git"))
17
- && !(item_path.ends_with(".git") || item_path.ends_with("node_modules"));
15
+ let is_bad_dir =
16
+ item_path.contains("node_modules") || item_path.contains(".git");
18
17
  Ok(is_bad_dir)
19
18
  }
20
19
 
@@ -38,14 +37,14 @@ pub fn is_good_file(file_path: &Path) -> Result<(), Error> {
38
37
 
39
38
  match file_name {
40
39
  "package-lock.json" | "pnpm-lock.yaml" | "yarn.lock" | "composer.lock"
41
- | "Gemfile.lock" => {
40
+ | "Gemfile.lock" | "bun.lockb" => {
42
41
  return Err(anyhow::anyhow!("File is just a lock file"));
43
42
  }
44
43
  _ => {}
45
44
  }
46
45
 
47
46
  match extension {
48
- "lock" | "bak" | "tmp" | "bin" | "exe" | "dll" | "so" => {
47
+ "lock" | "bak" | "tmp" | "bin" | "exe" | "dll" | "so" | "lockb" => {
49
48
  return Err(anyhow::anyhow!("File is just a lock file"));
50
49
  }
51
50
  _ => {}
@@ -63,7 +62,7 @@ pub fn is_good_file(file_path: &Path) -> Result<(), Error> {
63
62
  Some(extension) => match extension.to_str() {
64
63
  Some(ext_str) => {
65
64
  if bad_extensions.contains(&ext_str) {
66
- return Err(anyhow::anyhow!("File is not a valid UTF-8 string"));
65
+ return Err(anyhow::anyhow!("Binary file excluded from indexing."));
67
66
  }
68
67
  }
69
68
  None => {
@@ -89,10 +88,12 @@ pub fn is_good_file(file_path: &Path) -> Result<(), Error> {
89
88
  Ok(())
90
89
  }
91
90
 
91
+ // use binaryornot::is_binary;
92
+ // use anyhow::Context;
92
93
  // implement the buffer above:
93
94
  pub async fn is_good_file_runtime_check(
94
95
  file_path: &Path,
95
- buffer: &[u8],
96
+ _buffer: &[u8],
96
97
  ) -> Result<(), Error> {
97
98
  match get_file_size(file_path).await {
98
99
  Ok(size) if size > 2 * 1024 * 1024 => {
@@ -102,13 +103,10 @@ pub async fn is_good_file_runtime_check(
102
103
  _ => {}
103
104
  }
104
105
 
105
- for &byte in buffer.iter().take(2048) {
106
- if byte.is_ascii() {
107
- continue;
108
- } else {
109
- return Err(anyhow::anyhow!("File is not a valid UTF-8 string"));
110
- }
111
- }
106
+ // if is_binary(file_path).context("Failed to check if file is binary")? {
107
+ // return Err(anyhow::anyhow!("File is binary"));
108
+ // }
109
+
112
110
  Ok(())
113
111
  }
114
112
 
package/src/git_utils.rs CHANGED
@@ -1,10 +1,10 @@
1
1
  use std::collections::HashSet;
2
- use std::path::PathBuf;
3
2
  use std::process::Command;
4
3
 
5
4
  pub fn list_ignored_files(
6
5
  workspace_root_path: &str,
7
- ) -> Result<HashSet<PathBuf>, Box<dyn std::error::Error>> {
6
+ should_return_absolute_paths: bool,
7
+ ) -> Result<HashSet<String>, Box<dyn std::error::Error>> {
8
8
  let mut gitignored_files = HashSet::new();
9
9
 
10
10
  let commands = vec![
@@ -15,12 +15,66 @@ pub fn list_ignored_files(
15
15
  "--ignored",
16
16
  "--exclude-standard",
17
17
  ],
18
+ // FIXME(sualeh): this is super sketchy and might totally break in like a bazillion ways. i dont like it.
19
+ vec![
20
+ "sh",
21
+ "-c",
22
+ "git submodule foreach --quiet 'git ls-files --others --ignored --exclude-standard | sed \"s|^|$path/|\"'",
23
+ ],
24
+ ];
25
+
26
+ for command in commands {
27
+ let output = Command::new(&command[0])
28
+ .args(&command[1..])
29
+ .current_dir(workspace_root_path)
30
+ .output()?;
31
+
32
+ if output.status.success() {
33
+ let files = String::from_utf8(output.stdout)?
34
+ .lines()
35
+ .filter(|line| !line.is_empty())
36
+ .map(|line| {
37
+ if should_return_absolute_paths {
38
+ let mut path = std::path::PathBuf::from(workspace_root_path);
39
+ path.push(line);
40
+
41
+ match path.canonicalize() {
42
+ Ok(canonical_path) => {
43
+ canonical_path.to_string_lossy().into_owned()
44
+ }
45
+ Err(_) => String::from(line),
46
+ }
47
+ } else {
48
+ String::from(line)
49
+ }
50
+ })
51
+ .collect::<HashSet<_>>();
52
+
53
+ gitignored_files.extend(files);
54
+ }
55
+ }
56
+
57
+ Ok(gitignored_files)
58
+ }
59
+
60
+ pub fn list_ignored_files_with_absolute_paths(
61
+ workspace_root_path: &str,
62
+ ) -> Result<HashSet<String>, Box<dyn std::error::Error>> {
63
+ let mut gitignored_files = HashSet::new();
64
+
65
+ let commands = vec![
18
66
  vec![
19
67
  "git",
20
- "submodule",
21
- "foreach",
22
- "--quiet",
23
- "git ls-files --others --ignored --exclude-standard | sed 's|^|$path/|'",
68
+ "ls-files",
69
+ "--others",
70
+ "--ignored",
71
+ "--exclude-standard",
72
+ ],
73
+ // FIXME(sualeh): this is super sketchy and might totally break in like a bazillion ways. i dont like it.
74
+ vec![
75
+ "sh",
76
+ "-c",
77
+ "git submodule foreach --quiet 'git ls-files --others --ignored --exclude-standard | sed \"s|^|$path/|\"'",
24
78
  ],
25
79
  ];
26
80
 
@@ -34,7 +88,7 @@ pub fn list_ignored_files(
34
88
  let files = String::from_utf8(output.stdout)?
35
89
  .lines()
36
90
  .filter(|line| !line.is_empty())
37
- .map(|line| PathBuf::from(line))
91
+ .map(|line| String::from(line))
38
92
  .collect::<HashSet<_>>();
39
93
 
40
94
  gitignored_files.extend(files);
@@ -57,6 +111,18 @@ pub async fn is_git_ignored(
57
111
  Ok(output.status.success())
58
112
  }
59
113
 
114
+ pub async fn is_git_directory(
115
+ workspace_root_path: &str,
116
+ ) -> Result<bool, anyhow::Error> {
117
+ let output = tokio::process::Command::new("git")
118
+ .args(&["rev-parse", "--is-inside-work-tree"])
119
+ .current_dir(workspace_root_path)
120
+ .output()
121
+ .await?;
122
+
123
+ Ok(output.status.success())
124
+ }
125
+
60
126
  #[cfg(test)]
61
127
  mod tests {
62
128
  use super::*;
@@ -66,7 +132,8 @@ mod tests {
66
132
  #[test]
67
133
  fn test_no_ignored_files() {
68
134
  let dir = tempfile::tempdir().unwrap();
69
- let gitignored_files = list_ignored_files(dir.path().to_str().unwrap()).unwrap();
135
+ let gitignored_files =
136
+ list_ignored_files(dir.path().to_str().unwrap(), false).unwrap();
70
137
  Command::new("git")
71
138
  .args(&["init"])
72
139
  .current_dir(dir.path())
@@ -92,13 +159,14 @@ mod tests {
92
159
  .current_dir(dir.path())
93
160
  .output()
94
161
  .unwrap();
95
- let gitignored_files = list_ignored_files(dir.path().to_str().unwrap()).unwrap();
162
+ let gitignored_files =
163
+ list_ignored_files(dir.path().to_str().unwrap(), false).unwrap();
96
164
  println!(
97
165
  "ignored files for test_one_ignored_file: {:?}",
98
166
  gitignored_files
99
167
  );
100
168
  // assert_eq!(gitignored_files.len(), 1);
101
- assert!(gitignored_files.contains(&PathBuf::from("ignored.txt")));
169
+ assert!(gitignored_files.contains(&String::from("ignored.txt")));
102
170
  }
103
171
 
104
172
  #[test]
@@ -121,19 +189,83 @@ mod tests {
121
189
  .current_dir(dir.path())
122
190
  .output()
123
191
  .unwrap();
124
- let gitignored_files = list_ignored_files(dir.path().to_str().unwrap()).unwrap();
192
+ let gitignored_files =
193
+ list_ignored_files(dir.path().to_str().unwrap(), false).unwrap();
125
194
  println!(
126
195
  "ignored files for test_multiple_ignored_files: {:?}",
127
196
  gitignored_files
128
197
  );
129
198
  // assert_eq!(gitignored_files.len(), 2);
130
- assert!(gitignored_files.contains(&PathBuf::from("ignored1.txt")));
131
- assert!(gitignored_files.contains(&PathBuf::from("ignored2.txt")));
199
+ assert!(gitignored_files.contains(&String::from("ignored1.txt")));
200
+ assert!(gitignored_files.contains(&String::from("ignored2.txt")));
201
+ }
202
+
203
+ #[test]
204
+ fn test_git_submodule_ignored_files() {
205
+ let dir = tempfile::tempdir().unwrap();
206
+ let submodule_path = dir.path().join("submodule");
207
+ std::fs::create_dir(&submodule_path).unwrap();
208
+
209
+ let o = Command::new("git")
210
+ .args(&["init"])
211
+ .current_dir(&submodule_path)
212
+ .output()
213
+ .unwrap();
214
+ println!("git init output: {:?}", o);
215
+
216
+ let file_path = submodule_path.join("ignored.txt");
217
+ let mut file = File::create(&file_path).unwrap();
218
+ writeln!(file, "This is an ignored file.").unwrap();
219
+
220
+ let file2 = submodule_path.join("ignored2.txt");
221
+ let mut file = File::create(&file2).unwrap();
222
+ writeln!(file, "This is another ignored file.").unwrap();
223
+
224
+ let gitignore_path = submodule_path.join(".gitignore");
225
+ let mut gitignore = File::create(&gitignore_path).unwrap();
226
+ writeln!(gitignore, "*.txt").unwrap();
227
+
228
+ let o = Command::new("git")
229
+ .args(&["init"])
230
+ .current_dir(dir.path())
231
+ .output()
232
+ .unwrap();
233
+ println!("git init output: {:?}", o);
234
+
235
+ // make a commit in the submodule
236
+ let o = Command::new("git")
237
+ .args(&["add", "."])
238
+ .current_dir(&submodule_path)
239
+ .output()
240
+ .unwrap();
241
+ println!("git add output: {:?}", o);
242
+ let o = Command::new("git")
243
+ .args(&["commit", "-m", "initial commit"])
244
+ .current_dir(&submodule_path)
245
+ .output()
246
+ .unwrap();
247
+ println!("git commit output: {:?}", o);
248
+
249
+ let o = Command::new("git")
250
+ .args(&["submodule", "add", "./submodule"])
251
+ .current_dir(dir.path())
252
+ .output()
253
+ .unwrap();
254
+ println!("git submodule add output: {:?}", o);
255
+
256
+ let gitignored_files =
257
+ list_ignored_files(dir.path().to_str().unwrap(), false).unwrap();
258
+ println!(
259
+ "ignored files for test_git_submodule_ignored_files: {:?}",
260
+ gitignored_files
261
+ );
262
+ assert!(gitignored_files.contains(&String::from("submodule/ignored.txt")));
263
+ assert!(gitignored_files.contains(&String::from("submodule/ignored2.txt")));
132
264
  }
133
265
 
134
266
  #[test]
135
267
  fn test_multiple_ignored_files_in_current_dir() {
136
- let gitignored_files = list_ignored_files(".").unwrap();
268
+ let gitignored_files = list_ignored_files(".", false).unwrap();
137
269
  assert!(gitignored_files.len() > 1);
138
270
 
139
271
  // print a sample of the ignored files
@@ -147,7 +279,6 @@ mod tests {
147
279
  }
148
280
  }
149
281
 
150
-
151
282
  #[tokio::test]
152
283
  async fn test_file_not_ignored() {
153
284
  let dir = tempfile::tempdir().unwrap();
@@ -160,7 +291,10 @@ mod tests {
160
291
  .current_dir(dir.path())
161
292
  .output()
162
293
  .unwrap();
163
- let is_ignored = is_git_ignored(dir.path().to_str().unwrap(), "not_ignored.txt").await.unwrap();
294
+ let is_ignored =
295
+ is_git_ignored(dir.path().to_str().unwrap(), "not_ignored.txt")
296
+ .await
297
+ .unwrap();
164
298
  assert_eq!(is_ignored, false);
165
299
  }
166
300
 
@@ -180,7 +314,10 @@ mod tests {
180
314
  .current_dir(dir.path())
181
315
  .output()
182
316
  .unwrap();
183
- let is_ignored = is_git_ignored(dir.path().to_str().unwrap(), "ignored.txt").await.unwrap();
317
+ let is_ignored =
318
+ is_git_ignored(dir.path().to_str().unwrap(), "ignored.txt")
319
+ .await
320
+ .unwrap();
184
321
  assert_eq!(is_ignored, true);
185
322
  }
186
323
 
@@ -200,8 +337,10 @@ mod tests {
200
337
  .current_dir(dir.path())
201
338
  .output()
202
339
  .unwrap();
203
- let is_ignored = is_git_ignored(dir.path().to_str().unwrap(), "ignored.txt").await.unwrap();
340
+ let is_ignored =
341
+ is_git_ignored(dir.path().to_str().unwrap(), "ignored.txt")
342
+ .await
343
+ .unwrap();
204
344
  assert_eq!(is_ignored, true);
205
345
  }
206
-
207
346
  }