Skip to content

Commit 7ebb0a3

Browse files
authored
feat(wasm): enable utoopack watch build (#2166)
1 parent 8f33aa9 commit 7ebb0a3

File tree

7 files changed

+37
-23
lines changed

7 files changed

+37
-23
lines changed

Cargo.lock

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pack-api/src/project.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,14 @@ impl ProjectContainer {
240240
let project_fs = project_fs_operation(project)
241241
.read_strongly_consistent()
242242
.await?;
243-
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
244-
{
245-
if watch.enable {
246-
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
247-
project_fs
248-
.start_watching_with_invalidation_reason(watch.poll_interval)
249-
.await?;
250-
} else {
251-
project_fs.invalidate_with_reason(|path| invalidation::Initialize {
252-
path: RcStr::from(path),
253-
});
254-
}
243+
if watch.enable {
244+
project_fs
245+
.start_watching_with_invalidation_reason(watch.poll_interval)
246+
.await?;
247+
} else {
248+
project_fs.invalidate_with_reason(|path| invalidation::Initialize {
249+
path: RcStr::from(path),
250+
});
255251
}
256252
let output_fs = output_fs_operation(project)
257253
.read_strongly_consistent()
@@ -262,7 +258,6 @@ impl ProjectContainer {
262258
Ok(())
263259
}
264260

265-
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
266261
#[tracing::instrument(level = "info", name = "update project", skip_all)]
267262
pub async fn update(self: Vc<Self>, options: PartialProjectOptions) -> Result<()> {
268263
let PartialProjectOptions {

crates/utoo-wasm/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ tokio = { workspace = true, features = ["rt", "time", "rt-multi-thread"] }
3838
tracing-subscriber = { workspace = true }
3939
tracing-web = "0.1.3"
4040
rustc-hash = { workspace = true }
41-
tokio-fs-ext = { version = "0.5.6", features = ["wasm_offload"] }
41+
tokio-fs-ext = { version = "0.6.0", features = ["opfs_offload", "opfs_watch"] }
4242
console_error_panic_hook = { version = "0.1.7" }
43-
opfs-project = "0.1.4"
44-
lazy_static = "1.4"
43+
opfs-project = "0.1.5"
4544

4645
## turbpack specific - conditional on utoo-pack feature
4746
turbo-rcstr = { workspace = true, optional = true }

crates/utoo-wasm/src/opfs_offload.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{io, path::Path};
2-
use tokio_fs_ext::{offload, Metadata, ReadDir};
2+
use tokio_fs_ext::{offload, watch, Metadata, ReadDir};
33

44
pub struct OpfsOffload;
55

@@ -43,4 +43,13 @@ impl offload::FsOffload for OpfsOffload {
4343
async fn metadata(&self, path: impl AsRef<Path>) -> io::Result<Metadata> {
4444
opfs_project::metadata(path).await
4545
}
46+
47+
async fn watch_dir(
48+
&self,
49+
path: impl AsRef<Path>,
50+
recursive: bool,
51+
cb: impl Fn(watch::event::Event) + Send + Sync + 'static,
52+
) -> io::Result<()> {
53+
watch::watch_dir(path, recursive, cb).await
54+
}
4655
}

crates/utoo-wasm/src/project.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::str::FromStr;
44
use std::sync::Arc;
55

66
use anyhow::Context;
7+
use pack_api::project::WatchOptions;
78
use serde_wasm_bindgen::to_value;
89
use tokio_fs_ext::{DirEntry as RawDirEntry, Metadata as RawMetadata};
910
use wasm_bindgen::prelude::*;
@@ -108,6 +109,10 @@ impl Project {
108109
project_path: project_path.clone(),
109110
config,
110111
build_id: project_path.clone(),
112+
watch: WatchOptions {
113+
enable: true,
114+
..Default::default()
115+
},
111116
..Default::default()
112117
};
113118

packages/utoo-web/src/project.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ export class Project implements ProjectEndpoint {
110110
}
111111
}
112112

113-
public async install(packageLock: string): Promise<void> {
113+
public async init() {
114+
return await this.#tunnel;
115+
}
116+
117+
public async install(packageLock: string) {
114118
await this.#tunnel;
115119
return await this.remote.install(packageLock);
116120
}

0 commit comments

Comments
 (0)