Commit 05da4427 authored by Will Binns-Smith's avatar Will Binns-Smith

Rename HMR functions to client_hmr_* for clarity

Rename all HMR-related functions to explicitly include "client" prefix
to distinguish from upcoming server HMR functions:

- hmr_content -> client_hmr_content
- hmr_version -> client_hmr_version
- hmr_version_state -> client_hmr_version_state
- hmr_update -> client_hmr_update
- hmr_identifiers -> client_hmr_identifiers
- hmrEvents -> clientHmrEvents
- hmrIdentifiersSubscribe -> clientHmrIdentifiersSubscribe
parent 6431c857
......@@ -739,10 +739,10 @@ impl ProjectContainer {
self.project().entrypoints()
}
/// See [Project::hmr_identifiers].
/// See [Project::client_hmr_identifiers].
#[turbo_tasks::function]
pub fn hmr_identifiers(self: Vc<Self>) -> Vc<Vec<RcStr>> {
self.project().hmr_identifiers()
pub fn client_hmr_identifiers(self: Vc<Self>) -> Vc<Vec<RcStr>> {
self.project().client_hmr_identifiers()
}
/// Gets a source map for a particular `file_path`. If `dev` mode is disabled, this will always
......@@ -2037,7 +2037,10 @@ impl Project {
}
#[turbo_tasks::function]
async fn hmr_content(self: Vc<Self>, identifier: RcStr) -> Result<Vc<OptionVersionedContent>> {
async fn client_hmr_content(
self: Vc<Self>,
identifier: RcStr,
) -> Result<Vc<OptionVersionedContent>> {
if let Some(map) = self.await?.versioned_content_map {
let content = map.get(self.client_relative_path().await?.join(&identifier)?);
Ok(content)
......@@ -2047,8 +2050,8 @@ impl Project {
}
#[turbo_tasks::function]
async fn hmr_version(self: Vc<Self>, identifier: RcStr) -> Result<Vc<Box<dyn Version>>> {
let content = self.hmr_content(identifier).await?;
async fn client_hmr_version(self: Vc<Self>, identifier: RcStr) -> Result<Vc<Box<dyn Version>>> {
let content = self.client_hmr_content(identifier).await?;
if let Some(content) = &*content {
Ok(content.version())
} else {
......@@ -2059,12 +2062,12 @@ impl Project {
/// Get the version state for a session. Initialized with the first seen
/// version in that session.
#[turbo_tasks::function]
pub async fn hmr_version_state(
pub async fn client_hmr_version_state(
self: Vc<Self>,
identifier: RcStr,
session: TransientInstance<()>,
) -> Result<Vc<VersionState>> {
let version = self.hmr_version(identifier);
let version = self.client_hmr_version(identifier);
// The session argument is important to avoid caching this function between
// sessions.
......@@ -2087,13 +2090,13 @@ impl Project {
/// Emits opaque HMR events whenever a change is detected in the chunk group
/// internally known as `identifier`.
#[turbo_tasks::function]
pub async fn hmr_update(
pub async fn client_hmr_update(
self: Vc<Self>,
identifier: RcStr,
from: Vc<VersionState>,
) -> Result<Vc<Update>> {
let from = from.get();
let content = self.hmr_content(identifier).await?;
let content = self.client_hmr_content(identifier).await?;
if let Some(content) = *content {
Ok(content.update(from))
} else {
......@@ -2104,7 +2107,7 @@ impl Project {
/// Gets a list of all HMR identifiers that can be subscribed to. This is
/// only needed for testing purposes and isn't used in real apps.
#[turbo_tasks::function]
pub async fn hmr_identifiers(self: Vc<Self>) -> Result<Vc<Vec<RcStr>>> {
pub async fn client_hmr_identifiers(self: Vc<Self>) -> Result<Vc<Vec<RcStr>>> {
if let Some(map) = self.await?.versioned_content_map {
Ok(map.keys_in_path(self.client_relative_path().owned().await?))
} else {
......
......@@ -257,7 +257,7 @@ async fn hmr(
tracing::info!("HMR...");
let session = TransientInstance::new(());
let idents = tt
.run(async move { project.hmr_identifiers().await })
.run(async move { project.client_hmr_identifiers().await })
.await?;
let start = Instant::now();
for ident in idents {
......@@ -270,8 +270,8 @@ async fn hmr(
let session = session.clone();
async move {
let project = project.project();
let state = project.hmr_version_state(ident.clone(), session);
project.hmr_update(ident.clone(), state).await?;
let state = project.client_hmr_version_state(ident.clone(), session);
project.client_hmr_update(ident.clone(), state).await?;
Ok(Vc::<()>::cell(()))
}
});
......
......@@ -1204,12 +1204,12 @@ struct HmrUpdateWithIssues {
}
#[turbo_tasks::function(operation)]
async fn hmr_update_with_issues_operation(
async fn client_hmr_update_with_issues_operation(
project: ResolvedVc<Project>,
identifier: RcStr,
state: ResolvedVc<VersionState>,
) -> Result<Vc<HmrUpdateWithIssues>> {
let update_op = project_hmr_update_operation(project, identifier, state);
let update_op = project_client_hmr_update_operation(project, identifier, state);
let update = update_op.read_strongly_consistent().await?;
let issues = get_issues(update_op, NEXT_ISSUE_FILTER).await?;
let diagnostics = get_diagnostics(update_op).await?;
......@@ -1224,17 +1224,17 @@ async fn hmr_update_with_issues_operation(
}
#[turbo_tasks::function(operation)]
fn project_hmr_update_operation(
fn project_client_hmr_update_operation(
project: ResolvedVc<Project>,
identifier: RcStr,
state: ResolvedVc<VersionState>,
) -> Vc<Update> {
project.hmr_update(identifier, *state)
project.client_hmr_update(identifier, *state)
}
#[tracing::instrument(level = "info", name = "get HMR events", skip(project, func))]
#[napi(ts_return_type = "{ __napiType: \"RootTask\" }")]
pub fn project_hmr_events(
pub fn project_client_hmr_events(
#[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External<ProjectInstance>,
identifier: RcStr,
func: JsFunction,
......@@ -1253,12 +1253,12 @@ pub fn project_hmr_events(
async move {
let project = container.project().to_resolved().await?;
let state = project
.hmr_version_state(identifier.clone(), session)
.client_hmr_version_state(identifier.clone(), session)
.to_resolved()
.await?;
let update_op =
hmr_update_with_issues_operation(project, identifier.clone(), state);
client_hmr_update_with_issues_operation(project, identifier.clone(), state);
let update = update_op.read_strongly_consistent().await?;
let HmrUpdateWithIssues {
update,
......@@ -1331,10 +1331,10 @@ struct HmrIdentifiersWithIssues {
}
#[turbo_tasks::function(operation)]
async fn get_hmr_identifiers_with_issues_operation(
async fn get_client_hmr_identifiers_with_issues_operation(
container: ResolvedVc<ProjectContainer>,
) -> Result<Vc<HmrIdentifiersWithIssues>> {
let hmr_identifiers_op = project_container_hmr_identifiers_operation(container);
let hmr_identifiers_op = project_container_client_hmr_identifiers_operation(container);
let hmr_identifiers = hmr_identifiers_op.read_strongly_consistent().await?;
let issues = get_issues(hmr_identifiers_op, NEXT_ISSUE_FILTER).await?;
let diagnostics = get_diagnostics(hmr_identifiers_op).await?;
......@@ -1349,15 +1349,15 @@ async fn get_hmr_identifiers_with_issues_operation(
}
#[turbo_tasks::function(operation)]
fn project_container_hmr_identifiers_operation(
fn project_container_client_hmr_identifiers_operation(
container: ResolvedVc<ProjectContainer>,
) -> Vc<Vec<RcStr>> {
container.hmr_identifiers()
container.client_hmr_identifiers()
}
#[tracing::instrument(level = "info", name = "get HMR identifiers", skip_all)]
#[napi(ts_return_type = "{ __napiType: \"RootTask\" }")]
pub fn project_hmr_identifiers_subscribe(
pub fn project_client_hmr_identifiers_subscribe(
#[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External<ProjectInstance>,
func: JsFunction,
) -> napi::Result<External<RootTask>> {
......@@ -1367,7 +1367,7 @@ pub fn project_hmr_identifiers_subscribe(
func,
move || async move {
let hmr_identifiers_with_issues_op =
get_hmr_identifiers_with_issues_operation(container);
get_client_hmr_identifiers_with_issues_operation(container);
let HmrIdentifiersWithIssues {
identifiers,
issues,
......
......@@ -313,7 +313,7 @@ export declare function projectEntrypointsSubscribe(
project: { __napiType: 'Project' },
func: (...args: any[]) => any
): { __napiType: 'RootTask' }
export declare function projectHmrEvents(
export declare function projectClientHmrEvents(
project: { __napiType: 'Project' },
identifier: RcStr,
func: (...args: any[]) => any
......@@ -321,7 +321,7 @@ export declare function projectHmrEvents(
export interface HmrIdentifiers {
identifiers: Array<RcStr>
}
export declare function projectHmrIdentifiersSubscribe(
export declare function projectClientHmrIdentifiersSubscribe(
project: { __napiType: 'Project' },
func: (...args: any[]) => any
): { __napiType: 'RootTask' }
......
......@@ -735,17 +735,24 @@ function bindingToApi(
})()
}
hmrEvents(identifier: string) {
clientHmrEvents(identifier: string) {
return subscribe<TurbopackResult<Update>>(true, async (callback) =>
binding.projectHmrEvents(this._nativeProject, identifier, callback)
binding.projectClientHmrEvents(
this._nativeProject,
identifier,
callback
)
)
}
hmrIdentifiersSubscribe() {
clientHmrIdentifiersSubscribe() {
return subscribe<TurbopackResult<HmrIdentifiers>>(
false,
async (callback) =>
binding.projectHmrIdentifiersSubscribe(this._nativeProject, callback)
binding.projectClientHmrIdentifiersSubscribe(
this._nativeProject,
callback
)
)
}
......
......@@ -246,9 +246,11 @@ export interface Project {
TurbopackResult<RawEntrypoints | {}>
>
hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>
clientHmrEvents(
identifier: string
): AsyncIterableIterator<TurbopackResult<Update>>
hmrIdentifiersSubscribe(): AsyncIterableIterator<
clientHmrIdentifiersSubscribe(): AsyncIterableIterator<
TurbopackResult<HmrIdentifiers>
>
......
......@@ -667,7 +667,7 @@ export async function createHotReloaderTurbopack(
return
}
const subscription = project!.hmrEvents(id)
const subscription = project!.clientHmrEvents(id)
state.subscriptions.set(id, subscription)
// The subscription will always emit once, which is the initial
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment