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

Fix/server macro defaults #3403

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(cli): Updated logic to resolve out_dir paths relative to workspace
Nathy-bajo committed Dec 18, 2024
commit d601484a17366dee7987906dbb761a6ef6bb8671
7 changes: 7 additions & 0 deletions packages/cli/src/config/app.rs
Original file line number Diff line number Diff line change
@@ -8,8 +8,15 @@ pub(crate) struct ApplicationConfig {

#[serde(default)]
pub(crate) sub_package: Option<String>,

#[serde(default = "out_dir_default")]
pub(crate) out_dir: PathBuf,
}

pub(crate) fn asset_dir_default() -> PathBuf {
PathBuf::from("assets")
}

pub(crate) fn out_dir_default() -> PathBuf {
PathBuf::from("dist")
Copy link
Contributor

@hackartists hackartists Dec 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may break the deployment script due to changing default build artifact directory. How about returning PathBuf for target/dx, which is current out directory described in dioxus_crate.rs:100

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hackartists Hello!
I think this is the PR you're referring to #3393
And I already made that change there

}
1 change: 1 addition & 0 deletions packages/cli/src/config/dioxus_config.rs
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ impl Default for DioxusConfig {
application: ApplicationConfig {
asset_dir: asset_dir_default(),
sub_package: None,
out_dir: out_dir_default(),
},
web: WebConfig {
app: WebAppConfig {
18 changes: 15 additions & 3 deletions packages/cli/src/dioxus_crate.rs
Original file line number Diff line number Diff line change
@@ -97,9 +97,21 @@ impl DioxusCrate {
/// is "distributed" after building an application (configurable in the
/// `Dioxus.toml`).
fn out_dir(&self) -> PathBuf {
let dir = self.workspace_dir().join("target").join("dx");
std::fs::create_dir_all(&dir).unwrap();
dir
// Resolve the out_dir based on the configuration or default
let out_dir_config = self.config.application.out_dir.clone();
// Resolve relative paths against the workspace root
let resolved_out_dir = if out_dir_config.is_relative() {
self.workspace_dir().join(out_dir_config)
} else {
out_dir_config
};

// Create the directory and handle potential errors
if let Err(e) = std::fs::create_dir_all(&resolved_out_dir) {
tracing::error!("Failed to create output directory: {}", e);
}

resolved_out_dir
}

/// Create a workdir for the given platform
16 changes: 9 additions & 7 deletions packages/cli/src/wasm_bindgen.rs
Original file line number Diff line number Diff line change
@@ -57,10 +57,14 @@ impl WasmBindgen {
args.push(&self.out_name);

// Out dir
let out_dir = self
let canonical_out_dir = self
.out_dir
.canonicalize()
.expect("out_dir should resolve to a valid path");

let out_dir = canonical_out_dir
.to_str()
.expect("input_path should be valid utf8");
.expect("out_dir should be valid UTF-8");

args.push("--out-dir");
args.push(out_dir);
@@ -342,11 +346,9 @@ impl WasmBindgenBuilder {
}
}

pub fn out_dir(self, out_dir: &Path) -> Self {
Self {
out_dir: out_dir.to_path_buf(),
..self
}
pub fn out_dir(mut self, out_dir: &Path) -> Self {
self.out_dir = out_dir.canonicalize().expect("Invalid out_dir path");
self
}

pub fn out_name(self, out_name: &str) -> Self {