Skip to content

Commit 16ac2db

Browse files
authored
refactor(wasm): simplify build logic by removing PackProject impl (#2536)
1 parent 5ee8a7c commit 16ac2db

2 files changed

Lines changed: 60 additions & 66 deletions

File tree

crates/utoo-wasm/src/pack.rs

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -68,54 +68,6 @@ pub struct PackProject {
6868
pub dev: bool,
6969
}
7070

71-
impl PackProject {
72-
pub async fn build(&self) -> Result<TurbopackResult> {
73-
let start = Instant::now();
74-
let turbo_tasks = self.turbo_tasks.clone();
75-
let container = self.container;
76-
let (entrypoints, issues, diags) = turbo_tasks
77-
.run_once(async move {
78-
let entrypoints_with_issues_op =
79-
get_all_written_entrypoints_with_issues_operation(container);
80-
81-
let EntrypointsWithIssues {
82-
entrypoints,
83-
issues,
84-
diagnostics,
85-
effects,
86-
} = &*entrypoints_with_issues_op
87-
.read_strongly_consistent()
88-
.await?;
89-
effects.apply().await?;
90-
91-
Ok((entrypoints.clone(), issues.clone(), diagnostics.clone()))
92-
})
93-
.await?;
94-
95-
tracing::info!("all project entrypoints wrote to disk.");
96-
97-
tracing::info!(
98-
"pack tasks with {} apps {} libraries finished in {:?}",
99-
entrypoints
100-
.apps
101-
.as_ref()
102-
.map(|apps| apps.0.len())
103-
.unwrap_or_default(),
104-
entrypoints
105-
.libraries
106-
.as_ref()
107-
.map(|libraries| libraries.0.len())
108-
.unwrap_or_default(),
109-
start.elapsed()
110-
);
111-
112-
Ok(TurbopackResult {
113-
issues: issues.iter().map(|i| Issue::from(&**i)).collect(),
114-
diagnostics: diags.iter().map(|d| Diagnostic::from(d)).collect(),
115-
})
116-
}
117-
}
118-
11971
pub fn create_turbo_tasks() -> Result<BundlerTurboTasks> {
12072
Ok(BundlerTurboTasks::Memory(TurboTasks::new(
12173
turbo_tasks_backend::TurboTasksBackend::new(
@@ -376,7 +328,49 @@ pub async fn build() -> std::result::Result<JsValue, wasm_bindgen::JsError> {
376328

377329
runtime()
378330
.spawn(async move {
379-
let result = pack_project.build().await?;
331+
let start = Instant::now();
332+
let turbo_tasks = pack_project.turbo_tasks.clone();
333+
let container = pack_project.container;
334+
let (entrypoints, issues, diags) = turbo_tasks
335+
.run_once(async move {
336+
let entrypoints_with_issues_op =
337+
get_all_written_entrypoints_with_issues_operation(container);
338+
339+
let EntrypointsWithIssues {
340+
entrypoints,
341+
issues,
342+
diagnostics,
343+
effects,
344+
} = &*entrypoints_with_issues_op
345+
.read_strongly_consistent()
346+
.await?;
347+
effects.apply().await?;
348+
349+
Ok((entrypoints.clone(), issues.clone(), diagnostics.clone()))
350+
})
351+
.await?;
352+
353+
tracing::info!("all project entrypoints wrote to disk.");
354+
355+
tracing::info!(
356+
"pack tasks with {} apps {} libraries finished in {:?}",
357+
entrypoints
358+
.apps
359+
.as_ref()
360+
.map(|apps| apps.0.len())
361+
.unwrap_or_default(),
362+
entrypoints
363+
.libraries
364+
.as_ref()
365+
.map(|libraries| libraries.0.len())
366+
.unwrap_or_default(),
367+
start.elapsed()
368+
);
369+
370+
let result = TurbopackResult {
371+
issues: issues.iter().map(|i| Issue::from(&**i)).collect(),
372+
diagnostics: diags.iter().map(|d| Diagnostic::from(d)).collect(),
373+
};
380374
let json_str =
381375
serde_json::to_string(&result).map_err(|e| anyhow::anyhow!(e.to_string()))?;
382376
Ok::<String, anyhow::Error>(json_str)

packages/utoo-web/src/utoo/index.d.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,6 @@ export function workerCreated(worker_id: number): void;
178178
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
179179

180180
export interface InitOutput {
181-
readonly __wbg_project_free: (a: number, b: number) => void;
182-
readonly project_build: () => any;
183-
readonly project_cwd: () => [number, number];
184-
readonly project_deps: (a: number, b: number, c: number) => any;
185-
readonly project_entrypointsSubscribe: (a: any) => any;
186-
readonly project_gzip: (a: any) => any;
187-
readonly project_hmrEvents: (a: number, b: number, c: any) => any;
188-
readonly project_init: (a: number, b: number) => void;
189-
readonly project_install: (a: number, b: number, c: number) => any;
190-
readonly project_setCwd: (a: number, b: number) => void;
191-
readonly project_sigMd5: (a: any) => any;
192-
readonly project_updateInfoSubscribe: (a: number, b: any) => void;
193-
readonly project_writeAllToDisk: (a: any) => void;
194181
readonly getWasmMemory: () => any;
195182
readonly getWasmModule: () => any;
196183
readonly initLogFilter: (a: number, b: number) => void;
@@ -226,6 +213,19 @@ export interface InitOutput {
226213
readonly fs_write: (a: number, b: number, c: any) => any;
227214
readonly fs_writeString: (a: number, b: number, c: number, d: number) => any;
228215
readonly fs_writeSync: (a: number, b: number, c: any) => [number, number];
216+
readonly __wbg_project_free: (a: number, b: number) => void;
217+
readonly project_build: () => any;
218+
readonly project_cwd: () => [number, number];
219+
readonly project_deps: (a: number, b: number, c: number) => any;
220+
readonly project_entrypointsSubscribe: (a: any) => any;
221+
readonly project_gzip: (a: any) => any;
222+
readonly project_hmrEvents: (a: number, b: number, c: any) => any;
223+
readonly project_init: (a: number, b: number) => void;
224+
readonly project_install: (a: number, b: number, c: number) => any;
225+
readonly project_setCwd: (a: number, b: number) => void;
226+
readonly project_sigMd5: (a: any) => any;
227+
readonly project_updateInfoSubscribe: (a: number, b: any) => void;
228+
readonly project_writeAllToDisk: (a: any) => void;
229229
readonly __wbg_roottask_free: (a: number, b: number) => void;
230230
readonly registerWorkerScheduler: (a: any, b: any) => void;
231231
readonly workerCreated: (a: number) => void;
@@ -253,18 +253,18 @@ export interface InitOutput {
253253
readonly wasmtaskmessage_data: (a: number) => any;
254254
readonly __wbg_createsyncaccesshandleoptions_free: (a: number, b: number) => void;
255255
readonly wasm_thread_entry_point: (a: number) => void;
256-
readonly wasm_bindgen__closure__destroy__hdc0c9a5abebea22a: (a: number, b: number) => void;
256+
readonly wasm_bindgen__closure__destroy__h63d5de465208a3de: (a: number, b: number) => void;
257257
readonly wasm_bindgen__closure__destroy__h00341c46fa27177b: (a: number, b: number) => void;
258258
readonly wasm_bindgen__closure__destroy__h391e6789779e56da: (a: number, b: number) => void;
259259
readonly wasm_bindgen__closure__destroy__h96856d441dbabdfc: (a: number, b: number) => void;
260260
readonly wasm_bindgen__closure__destroy__hcd544267e9a8b41a: (a: number, b: number) => void;
261-
readonly wasm_bindgen__closure__destroy__h72493b8ecc7a2fa9: (a: number, b: number) => void;
261+
readonly wasm_bindgen__closure__destroy__h0c0bb14a934213b9: (a: number, b: number) => void;
262262
readonly wasm_bindgen__convert__closures_____invoke__hb6c1c61344794a50: (a: number, b: number, c: any, d: any) => void;
263263
readonly wasm_bindgen__convert__closures_____invoke__h1c90b71c761ed3b8: (a: number, b: number, c: any) => void;
264264
readonly wasm_bindgen__convert__closures_____invoke__hf447be52ec002243: (a: number, b: number, c: any) => void;
265265
readonly wasm_bindgen__convert__closures________invoke__h717385505976dc94: (a: number, b: number, c: any) => void;
266-
readonly wasm_bindgen__convert__closures_____invoke__h3d4d60f9cefb0572: (a: number, b: number, c: any) => void;
267-
readonly wasm_bindgen__convert__closures_____invoke__hcdaa890baa3d79c0: (a: number, b: number) => void;
266+
readonly wasm_bindgen__convert__closures_____invoke__he45664fa0a7bdef9: (a: number, b: number, c: any) => void;
267+
readonly wasm_bindgen__convert__closures_____invoke__h8f9fd2338557149f: (a: number, b: number) => void;
268268
readonly wasm_bindgen__convert__closures_____invoke__h3fb07518adc4b25d: (a: number, b: number) => void;
269269
readonly memory: WebAssembly.Memory;
270270
readonly __wbindgen_malloc: (a: number, b: number) => number;

0 commit comments

Comments
 (0)