Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: package lock and download-on-demand #1802

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions fastn-core/src/apis/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,8 @@ pub async fn clear_(
for package in query.package.iter() {
if package.eq("main") {
// TODO: List directories and files other than main
fastn_core::utils::remove_except(
&config.ds.root(),
&[".packages", ".build"],
&config.ds,
)
.await?;
fastn_core::utils::remove_except(&config.ds.root(), &[".fastn", ".build"], &config.ds)
.await?;
} else {
let path = config.packages_root.join(package);
if path
Expand Down
4 changes: 2 additions & 2 deletions fastn-core/src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,12 @@ async fn handle_static_route(
}

// the path can start with slash or -/. If later, it is a static file from our dependencies, so
// we have to look for them inside .packages.
// we have to look for them inside .fastn/package-cache.
let path = match path.strip_prefix("/-/") {
Some(path) if path.starts_with(package_name) => {
path.strip_prefix(package_name).unwrap_or(path).to_string()
}
Some(path) => format!(".packages/{path}"),
Some(path) => format!(".fastn/package-cache/{path}"),
None => path.to_string(),
};

Expand Down
50 changes: 33 additions & 17 deletions fastn-core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ impl Config {
) -> fastn_core::Result<Vec<fastn_ds::Path>> {
let mut ignored_files = vec![
".history".to_string(),
".packages".to_string(),
".fastn/package-cache".to_string(),
".tracks".to_string(),
"fastn".to_string(),
"rust-toolchain".to_string(),
Expand Down Expand Up @@ -731,7 +731,7 @@ impl Config {
id = new_id.to_string();
}
if !package.name.eq(self.package.name.as_str()) {
add_packages = format!(".packages/{}/", package.name);
add_packages = format!(".fastn/package-cache/{}/", package.name);
}
}
let id = {
Expand Down Expand Up @@ -776,7 +776,7 @@ impl Config {
id = new_id.to_string();
}
if !package.name.eq(self.package.name.as_str()) {
add_packages = format!(".packages/{}/", package.name);
add_packages = format!(".fastn/package-cache/{}/", package.name);
}
}
let id = {
Expand Down Expand Up @@ -860,20 +860,24 @@ impl Config {
)
.await
{
let base = root.join(".packages").join(package.name.as_str());
let base = root
.join(".fastn/package-cache")
.join(package.name.as_str());
ds.write_content(&base.join("index.ftd"), string.into_bytes())
.await?;
return Ok(format!(".packages/{}/index.ftd", package.name));
return Ok(format!(".fastn/package-cache/{}/index.ftd", package.name));
}
if let Ok(string) = crate::http::http_get_str(
format!("{}/README.md", base.trim_end_matches('/')).as_str(),
)
.await
{
let base = root.join(".packages").join(package.name.as_str());
let base = root
.join(".fastn/package-cache")
.join(package.name.as_str());
ds.write_content(&base.join("README.md"), string.into_bytes())
.await?;
return Ok(format!(".packages/{}/README.md", package.name));
return Ok(format!(".fastn/package-cache/{}/README.md", package.name));
}
return Err(fastn_core::Error::UsageError {
message: "File not found".to_string(),
Expand All @@ -889,9 +893,11 @@ impl Config {
Some((prefix, id)) => (format!("/{}", prefix), id.to_string()),
None => ("".to_string(), id),
};
let base = root
.join(".packages")
.join(format!("{}{}", package.name.as_str(), prefix));
let base = root.join(".fastn/package-cache").join(format!(
"{}{}",
package.name.as_str(),
prefix
));
let file_path = base.join(format!("{}.ftd", id));
ds.write_content(&file_path, string.into_bytes()).await?;
return Ok(file_path.to_string());
Expand All @@ -901,7 +907,10 @@ impl Config {
)
.await
{
let base = root.join(".packages").join(package.name.as_str()).join(id);
let base = root
.join(".fastn/package-cache")
.join(package.name.as_str())
.join(id);
let file_path = base.join("index.ftd");
ds.write_content(&file_path, string.into_bytes()).await?;
return Ok(file_path.to_string());
Expand All @@ -910,20 +919,27 @@ impl Config {
crate::http::http_get_str(format!("{}/{}.md", base.trim_end_matches('/'), id).as_str())
.await
{
let base = root.join(".packages").join(package.name.as_str());
let base = root
.join(".fastn/package-cache")
.join(package.name.as_str());
ds.write_content(&base.join(format!("{}.md", id)), string.into_bytes())
.await?;
return Ok(format!(".packages/{}/{}.md", package.name, id));
return Ok(format!(".fastn/package-cache/{}/{}.md", package.name, id));
}
if let Ok(string) = crate::http::http_get_str(
format!("{}/{}/README.md", base.trim_end_matches('/'), id).as_str(),
)
.await
{
let base = root.join(".packages").join(package.name.as_str());
let base = root
.join(".fastn/package-cache")
.join(package.name.as_str());
ds.write_content(&base.join(format!("{}/README.md", id)), string.into_bytes())
.await?;
return Ok(format!(".packages/{}/{}/README.md", package.name, id));
return Ok(format!(
".fastn/package-cache/{}/{}/README.md",
package.name, id
));
}
Err(fastn_core::Error::UsageError {
message: "File not found".to_string(),
Expand All @@ -939,7 +955,7 @@ impl Config {
let mut add_packages = "".to_string();
if let Some(new_id) = id.strip_prefix("-/") {
id = new_id.to_string();
add_packages = ".packages/".to_string()
add_packages = ".fastn/package-cache/".to_string()
}
let mut id = id
.split_once("-/")
Expand Down Expand Up @@ -1103,7 +1119,7 @@ impl Config {
let fastn_doc = utils::fastn_doc(&ds, &fastn_ds::Path::new("FASTN.ftd")).await?;
let config_temp = config_temp::ConfigTemp::read(&ds).await?;
let mut package = fastn_core::Package::from_fastn_doc(&ds, &fastn_doc)?;
let package_root = ds.root().join(".packages");
let package_root = ds.root().join(".fastn/package-cache");
let all_packages = {
let mut all_packages = std::collections::BTreeMap::new();
all_packages.insert(package.name.to_string(), package.to_owned());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- import: fastn

-- fastn.package: ftd-lang.github.io/fastn-ui
zip: https://codeload.github.com/fastn-stack/fastn-ui/zip/refs/heads/main

-- fastn.dependency: fastn-community.github.io/roboto-mono










Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- ftd.code code-page:
caption file-name:
optional body content:
string lang:
lang: $lang
if: $content is not null

$content
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- import: fastn

-- optional string title:
$always-include$: true


-- object create-cr-obj:
function: http
method: post
url: -/create-cr/
title: $title



-- ftd.column create-cr:
spacing: 40
padding: 40

--- ftd.input:
width: fill
placeholder: CR title
$on-input$: $title=$VALUE
padding-horizontal: 10
padding-vertical: $fastn.space.space-2
background-color: $fastn.color.main.background.step-1
color: $fastn.color.main.text-strong
border-width: 0
cursor: text

--- ftd.text: Create CR
padding: 10
border-radius: 8
color: $fastn.color.main.cta-secondary.text
background-color: $fastn.color.main.cta-secondary.base
$on-click$: message-host $create-cr-obj


Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.