Commit 34057d35 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 13b13ede
...@@ -1204,12 +1204,12 @@ struct HmrUpdateWithIssues { ...@@ -1204,12 +1204,12 @@ struct HmrUpdateWithIssues {
} }
#[turbo_tasks::function(operation)] #[turbo_tasks::function(operation)]
async fn hmr_update_with_issues_operation( async fn client_hmr_update_with_issues_operation(
project: ResolvedVc<Project>, project: ResolvedVc<Project>,
identifier: RcStr, identifier: RcStr,
state: ResolvedVc<VersionState>, state: ResolvedVc<VersionState>,
) -> Result<Vc<HmrUpdateWithIssues>> { ) -> 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 update = update_op.read_strongly_consistent().await?;
let issues = get_issues(update_op, NEXT_ISSUE_FILTER).await?; let issues = get_issues(update_op, NEXT_ISSUE_FILTER).await?;
let diagnostics = get_diagnostics(update_op).await?; let diagnostics = get_diagnostics(update_op).await?;
...@@ -1224,17 +1224,17 @@ async fn hmr_update_with_issues_operation( ...@@ -1224,17 +1224,17 @@ async fn hmr_update_with_issues_operation(
} }
#[turbo_tasks::function(operation)] #[turbo_tasks::function(operation)]
fn project_hmr_update_operation( fn project_client_hmr_update_operation(
project: ResolvedVc<Project>, project: ResolvedVc<Project>,
identifier: RcStr, identifier: RcStr,
state: ResolvedVc<VersionState>, state: ResolvedVc<VersionState>,
) -> Vc<Update> { ) -> Vc<Update> {
project.hmr_update(identifier, *state) project.client_hmr_update(identifier, *state)
} }
#[tracing::instrument(level = "info", name = "get HMR events", skip(project, func))] #[tracing::instrument(level = "info", name = "get HMR events", skip(project, func))]
#[napi(ts_return_type = "{ __napiType: \"RootTask\" }")] #[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>, #[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External<ProjectInstance>,
identifier: RcStr, identifier: RcStr,
func: JsFunction, func: JsFunction,
...@@ -1253,12 +1253,12 @@ pub fn project_hmr_events( ...@@ -1253,12 +1253,12 @@ pub fn project_hmr_events(
async move { async move {
let project = container.project().to_resolved().await?; let project = container.project().to_resolved().await?;
let state = project let state = project
.hmr_version_state(identifier.clone(), session) .client_hmr_version_state(identifier.clone(), session)
.to_resolved() .to_resolved()
.await?; .await?;
let update_op = 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 update = update_op.read_strongly_consistent().await?;
let HmrUpdateWithIssues { let HmrUpdateWithIssues {
update, update,
...@@ -1331,10 +1331,10 @@ struct HmrIdentifiersWithIssues { ...@@ -1331,10 +1331,10 @@ struct HmrIdentifiersWithIssues {
} }
#[turbo_tasks::function(operation)] #[turbo_tasks::function(operation)]
async fn get_hmr_identifiers_with_issues_operation( async fn get_client_hmr_identifiers_with_issues_operation(
container: ResolvedVc<ProjectContainer>, container: ResolvedVc<ProjectContainer>,
) -> Result<Vc<HmrIdentifiersWithIssues>> { ) -> 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 hmr_identifiers = hmr_identifiers_op.read_strongly_consistent().await?;
let issues = get_issues(hmr_identifiers_op, NEXT_ISSUE_FILTER).await?; let issues = get_issues(hmr_identifiers_op, NEXT_ISSUE_FILTER).await?;
let diagnostics = get_diagnostics(hmr_identifiers_op).await?; let diagnostics = get_diagnostics(hmr_identifiers_op).await?;
...@@ -1349,15 +1349,15 @@ async fn get_hmr_identifiers_with_issues_operation( ...@@ -1349,15 +1349,15 @@ async fn get_hmr_identifiers_with_issues_operation(
} }
#[turbo_tasks::function(operation)] #[turbo_tasks::function(operation)]
fn project_container_hmr_identifiers_operation( fn project_container_client_hmr_identifiers_operation(
container: ResolvedVc<ProjectContainer>, container: ResolvedVc<ProjectContainer>,
) -> Vc<Vec<RcStr>> { ) -> Vc<Vec<RcStr>> {
container.hmr_identifiers() container.client_hmr_identifiers()
} }
#[tracing::instrument(level = "info", name = "get HMR identifiers", skip_all)] #[tracing::instrument(level = "info", name = "get HMR identifiers", skip_all)]
#[napi(ts_return_type = "{ __napiType: \"RootTask\" }")] #[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>, #[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External<ProjectInstance>,
func: JsFunction, func: JsFunction,
) -> napi::Result<External<RootTask>> { ) -> napi::Result<External<RootTask>> {
...@@ -1367,7 +1367,7 @@ pub fn project_hmr_identifiers_subscribe( ...@@ -1367,7 +1367,7 @@ pub fn project_hmr_identifiers_subscribe(
func, func,
move || async move { move || async move {
let hmr_identifiers_with_issues_op = let hmr_identifiers_with_issues_op =
get_hmr_identifiers_with_issues_operation(container); get_client_hmr_identifiers_with_issues_operation(container);
let HmrIdentifiersWithIssues { let HmrIdentifiersWithIssues {
identifiers, identifiers,
issues, issues,
......
...@@ -739,10 +739,10 @@ impl ProjectContainer { ...@@ -739,10 +739,10 @@ impl ProjectContainer {
self.project().entrypoints() self.project().entrypoints()
} }
/// See [Project::hmr_identifiers]. /// See [Project::client_hmr_identifiers].
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn hmr_identifiers(self: Vc<Self>) -> Vc<Vec<RcStr>> { pub fn client_hmr_identifiers(self: Vc<Self>) -> Vc<Vec<RcStr>> {
self.project().hmr_identifiers() self.project().client_hmr_identifiers()
} }
/// Gets a source map for a particular `file_path`. If `dev` mode is disabled, this will always /// Gets a source map for a particular `file_path`. If `dev` mode is disabled, this will always
...@@ -2031,7 +2031,10 @@ impl Project { ...@@ -2031,7 +2031,10 @@ impl Project {
} }
#[turbo_tasks::function] #[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 { if let Some(map) = self.await?.versioned_content_map {
let content = map.get(self.client_relative_path().await?.join(&identifier)?); let content = map.get(self.client_relative_path().await?.join(&identifier)?);
Ok(content) Ok(content)
...@@ -2041,8 +2044,8 @@ impl Project { ...@@ -2041,8 +2044,8 @@ impl Project {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
async fn hmr_version(self: Vc<Self>, identifier: RcStr) -> Result<Vc<Box<dyn Version>>> { async fn client_hmr_version(self: Vc<Self>, identifier: RcStr) -> Result<Vc<Box<dyn Version>>> {
let content = self.hmr_content(identifier).await?; let content = self.client_hmr_content(identifier).await?;
if let Some(content) = &*content { if let Some(content) = &*content {
Ok(content.version()) Ok(content.version())
} else { } else {
...@@ -2053,12 +2056,12 @@ impl Project { ...@@ -2053,12 +2056,12 @@ impl Project {
/// Get the version state for a session. Initialized with the first seen /// Get the version state for a session. Initialized with the first seen
/// version in that session. /// version in that session.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn hmr_version_state( pub async fn client_hmr_version_state(
self: Vc<Self>, self: Vc<Self>,
identifier: RcStr, identifier: RcStr,
session: TransientInstance<()>, session: TransientInstance<()>,
) -> Result<Vc<VersionState>> { ) -> 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 // The session argument is important to avoid caching this function between
// sessions. // sessions.
...@@ -2081,13 +2084,13 @@ impl Project { ...@@ -2081,13 +2084,13 @@ impl Project {
/// Emits opaque HMR events whenever a change is detected in the chunk group /// Emits opaque HMR events whenever a change is detected in the chunk group
/// internally known as `identifier`. /// internally known as `identifier`.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn hmr_update( pub async fn client_hmr_update(
self: Vc<Self>, self: Vc<Self>,
identifier: RcStr, identifier: RcStr,
from: Vc<VersionState>, from: Vc<VersionState>,
) -> Result<Vc<Update>> { ) -> Result<Vc<Update>> {
let from = from.get(); let from = from.get();
let content = self.hmr_content(identifier).await?; let content = self.client_hmr_content(identifier).await?;
if let Some(content) = *content { if let Some(content) = *content {
Ok(content.update(from)) Ok(content.update(from))
} else { } else {
...@@ -2098,7 +2101,7 @@ impl Project { ...@@ -2098,7 +2101,7 @@ impl Project {
/// Gets a list of all HMR identifiers that can be subscribed to. This is /// 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. /// only needed for testing purposes and isn't used in real apps.
#[turbo_tasks::function] #[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 { if let Some(map) = self.await?.versioned_content_map {
Ok(map.keys_in_path(self.client_relative_path().owned().await?)) Ok(map.keys_in_path(self.client_relative_path().owned().await?))
} else { } else {
......
...@@ -311,7 +311,7 @@ export declare function projectEntrypointsSubscribe( ...@@ -311,7 +311,7 @@ export declare function projectEntrypointsSubscribe(
project: { __napiType: 'Project' }, project: { __napiType: 'Project' },
func: (...args: any[]) => any func: (...args: any[]) => any
): { __napiType: 'RootTask' } ): { __napiType: 'RootTask' }
export declare function projectHmrEvents( export declare function projectClientHmrEvents(
project: { __napiType: 'Project' }, project: { __napiType: 'Project' },
identifier: RcStr, identifier: RcStr,
func: (...args: any[]) => any func: (...args: any[]) => any
...@@ -319,7 +319,7 @@ export declare function projectHmrEvents( ...@@ -319,7 +319,7 @@ export declare function projectHmrEvents(
export interface HmrIdentifiers { export interface HmrIdentifiers {
identifiers: Array<RcStr> identifiers: Array<RcStr>
} }
export declare function projectHmrIdentifiersSubscribe( export declare function projectClientHmrIdentifiersSubscribe(
project: { __napiType: 'Project' }, project: { __napiType: 'Project' },
func: (...args: any[]) => any func: (...args: any[]) => any
): { __napiType: 'RootTask' } ): { __napiType: 'RootTask' }
......
...@@ -735,17 +735,24 @@ function bindingToApi( ...@@ -735,17 +735,24 @@ function bindingToApi(
})() })()
} }
hmrEvents(identifier: string) { clientHmrEvents(identifier: string) {
return subscribe<TurbopackResult<Update>>(true, async (callback) => 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>>( return subscribe<TurbopackResult<HmrIdentifiers>>(
false, false,
async (callback) => async (callback) =>
binding.projectHmrIdentifiersSubscribe(this._nativeProject, callback) binding.projectClientHmrIdentifiersSubscribe(
this._nativeProject,
callback
)
) )
} }
......
...@@ -243,9 +243,11 @@ export interface Project { ...@@ -243,9 +243,11 @@ export interface Project {
TurbopackResult<RawEntrypoints | {}> TurbopackResult<RawEntrypoints | {}>
> >
hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>> clientHmrEvents(
identifier: string
): AsyncIterableIterator<TurbopackResult<Update>>
hmrIdentifiersSubscribe(): AsyncIterableIterator< clientHmrIdentifiersSubscribe(): AsyncIterableIterator<
TurbopackResult<HmrIdentifiers> TurbopackResult<HmrIdentifiers>
> >
......
...@@ -599,7 +599,7 @@ export async function createHotReloaderTurbopack( ...@@ -599,7 +599,7 @@ export async function createHotReloaderTurbopack(
return return
} }
const subscription = project!.hmrEvents(id) const subscription = project!.clientHmrEvents(id)
state.subscriptions.set(id, subscription) state.subscriptions.set(id, subscription)
// The subscription will always emit once, which is the initial // 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