fix(bun): //native not using workspace dependencies (#7833)

* fix: `//native` not using workspace dependencies

Signed-off-by: pyranota <pyra@duck.com>

* proper fix

Signed-off-by: pyranota <pyra@duck.com>

* make code cleaner

Signed-off-by: pyranota <pyra@duck.com>

---------

Signed-off-by: pyranota <pyra@duck.com>
This commit is contained in:
Pyra
2026-02-06 15:04:36 +00:00
committed by GitHub
parent 7dd63a7429
commit df0ae90a2c
3 changed files with 23 additions and 18 deletions
+7 -10
View File
@@ -898,7 +898,7 @@ pub mod workspace_dependencies {
time::{Duration, Instant},
};
use crate::{error, scripts::ScriptLang, workspace_dependencies::WorkspaceDependencies, DB};
use crate::{error, workspace_dependencies::WorkspaceDependencies, DB};
make_static! {
/// Workspace Dependencies by id and workspace cache.
@@ -908,7 +908,7 @@ pub mod workspace_dependencies {
/// Cache for checking if default/unnamed workspace dependencies exist for a workspace and language.
/// Cache key: (workspace_id, language)
/// Cache value: (exists: bool, cached_at timestamp)
static ref DEFAULT_WD_EXISTS_CACHE: quick_cache::sync::Cache<(String, ScriptLang), (bool, Instant)> = quick_cache::sync::Cache::new(500);
static ref DEFAULT_WD_EXISTS_CACHE: quick_cache::sync::Cache<(String, String), (bool, Instant)> = quick_cache::sync::Cache::new(500);
}
/// Cache timeout for existence checks (10 seconds)
pub const EXISTS_CACHE_TIMEOUT: Duration = Duration::from_secs(10);
@@ -926,15 +926,15 @@ pub mod workspace_dependencies {
}
pub fn get_cached_is_unnamed_workspace_dependencies_exists<'c>(
language: ScriptLang,
dependencies_filename: String,
workspace_id: String,
) -> Option<bool> {
let exists_key = (workspace_id.to_string(), language);
let exists_key = (workspace_id.to_string(), dependencies_filename);
if let Some((exists, cached_at)) = DEFAULT_WD_EXISTS_CACHE.get(&exists_key) {
if cached_at.elapsed() < EXISTS_CACHE_TIMEOUT {
tracing::debug!(
workspace_id = %workspace_id,
?language,
exists,
"cache hit for unnamed workspace dependencies existence"
);
@@ -942,7 +942,6 @@ pub mod workspace_dependencies {
} else {
tracing::debug!(
workspace_id = %workspace_id,
?language,
"cache expired for unnamed workspace dependencies existence"
);
DEFAULT_WD_EXISTS_CACHE.remove(&exists_key);
@@ -950,24 +949,22 @@ pub mod workspace_dependencies {
} else {
tracing::debug!(
workspace_id = %workspace_id,
?language,
"cache miss for unnamed workspace dependencies existence"
);
}
None
}
pub fn set_cached_is_unnamed_workspace_dependencies_exists<'c>(
language: ScriptLang,
dependencies_filename: String,
workspace_id: String,
exists: bool,
) {
tracing::debug!(
workspace_id = %workspace_id,
?language,
exists,
"setting cache for unnamed workspace dependencies existence"
);
let exists_key = (workspace_id.to_string(), language);
let exists_key = (workspace_id.to_string(), dependencies_filename);
DEFAULT_WD_EXISTS_CACHE.insert(exists_key, (exists, Instant::now()));
}
}
+4 -3
View File
@@ -111,7 +111,7 @@ impl ScriptLang {
use ScriptLang::*;
Some(
match self {
Bun | Bunnative => "package.json",
Bun | Bunnative | Nativets => "package.json",
Python3 => "requirements.in",
// Go => "go.mod",
Php => "composer.json",
@@ -144,7 +144,7 @@ impl ScriptLang {
}
match self {
// TODO: Maybe use regex
Bun | Bunnative => WorkspaceDependenciesAnnotatedRefs::parse(
Bun | Bunnative | Nativets => WorkspaceDependenciesAnnotatedRefs::parse(
"//",
"package_json",
code,
@@ -984,7 +984,8 @@ pub async fn clone_script<'c>(
s
} else {
return Err(crate::error::Error::NotFound(format!(
"Non-archived script with path '{}' not found", path
"Non-archived script with path '{}' not found",
path
)));
};
@@ -178,6 +178,13 @@ impl WorkspaceDependencies {
?name,
"fetching latest workspace dependencies id"
);
// Bunnative and Nativets workspace dependencies go under Bun language
let language = match language {
ScriptLang::Nativets | ScriptLang::Bunnative => ScriptLang::Bun,
l => l,
};
let result = sqlx::query_scalar!(
r#"
SELECT id FROM workspace_dependencies
@@ -209,13 +216,13 @@ impl WorkspaceDependencies {
workspace_id: &str,
conn: Connection,
) -> error::Result<Option<Self>> {
if language.as_dependencies_filename().is_none() {
let Some(dependencies_filename) = language.as_dependencies_filename() else {
return Ok(None);
}
};
if name.is_none()
&& get_cached_is_unnamed_workspace_dependencies_exists(
language,
dependencies_filename.clone(),
workspace_id.to_owned(),
)
.map(|exists| exists == false)
@@ -237,7 +244,7 @@ impl WorkspaceDependencies {
else {
if name.is_none() {
set_cached_is_unnamed_workspace_dependencies_exists(
language,
dependencies_filename.clone(),
workspace_id.to_owned(),
false,
);
@@ -277,7 +284,7 @@ impl WorkspaceDependencies {
if name.is_none() {
set_cached_is_unnamed_workspace_dependencies_exists(
language,
dependencies_filename,
workspace_id.to_owned(),
wd.is_some(),
);