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(cli): Updated logic to resolve out_dir paths relative to workspace #3393

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions packages/cli/src/config/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
1 change: 1 addition & 0 deletions packages/cli/src/config/dioxus_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 15 additions & 3 deletions packages/cli/src/dioxus_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions packages/cli/src/wasm_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down