Skip to content

Commit 1b6ef16

Browse files
committed
fix: 🚑 fixed windows cli bug
Switched to renaming `pkg/` to `dist/pkg/` with `fs` rather than `rm`.
1 parent f1e825b commit 1b6ef16

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

packages/perseus-cli/src/build.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::cmd::run_stage;
22
use crate::errors::*;
33
use console::{style, Emoji};
44
use std::path::PathBuf;
5+
use std::fs;
56

67
// Emojis for stages
78
static GENERATING: Emoji<'_, '_> = Emoji("🔨", "");
@@ -36,19 +37,25 @@ pub fn build_internal(dir: PathBuf, num_steps: u8) -> Result<i32> {
3637
)?);
3738
// WASM building
3839
handle_exit_code!(run_stage(
39-
vec![
40-
"wasm-pack build --target web",
41-
// Move the `pkg/` directory into `dist/pkg/`
42-
"rm -rf dist/pkg",
43-
"mv pkg/ dist/",
44-
],
40+
vec!["wasm-pack build --target web"],
4541
&target,
4642
format!(
4743
"{} {} Building your app to WASM",
4844
style(format!("[2/{}]", num_steps)).bold().dim(),
4945
BUILDING
5046
)
5147
)?);
48+
// Move the `pkg/` directory into `dist/pkg/`
49+
let pkg_dir = target.join("dist/pkg");
50+
if pkg_dir.exists() {
51+
if let Err(err) = fs::remove_dir_all(&pkg_dir) {
52+
bail!(ErrorKind::MovePkgDirFailed(err.to_string()));
53+
}
54+
}
55+
// The `fs::rename()` function will fail on Windows if the destination already exists, so this should work (we've just deleted it as per https://github.com/rust-lang/rust/issues/31301#issuecomment-177117325)
56+
if let Err(err) = fs::rename(target.join("pkg"), target.join("dist/pkg")) {
57+
bail!(ErrorKind::MovePkgDirFailed(err.to_string()));
58+
}
5259
// JS bundle generation
5360
handle_exit_code!(run_stage(
5461
vec!["rollup main.js --format iife --file dist/pkg/bundle.js"],

packages/perseus-cli/src/errors.rs

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ error_chain! {
6969
description("port in PORT environment variable couldn't be parsed as number")
7070
display("Couldn't parse 'PORT' environment variable as a number, please check that you've provided the correct value. Error was: '{}'.", err)
7171
}
72+
/// For when moving the `pkg/` directory to `dist/pkg/` fails.
73+
MovePkgDirFailed(err: String) {
74+
description("couldn't move `pkg/` to `dist/pkg/`")
75+
display("Couldn't move `.perseus/pkg/` to `.perseus/dist/pkg`. Error was: '{}'.", err)
76+
}
7277
}
7378
}
7479

0 commit comments

Comments
 (0)