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 { ...@@ -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
...@@ -2037,7 +2037,10 @@ impl Project { ...@@ -2037,7 +2037,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)
...@@ -2047,8 +2050,8 @@ impl Project { ...@@ -2047,8 +2050,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 {
...@@ -2059,12 +2062,12 @@ impl Project { ...@@ -2059,12 +2062,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.
...@@ -2087,13 +2090,13 @@ impl Project { ...@@ -2087,13 +2090,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 {
...@@ -2104,7 +2107,7 @@ impl Project { ...@@ -2104,7 +2107,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 {
......
...@@ -257,7 +257,7 @@ async fn hmr( ...@@ -257,7 +257,7 @@ async fn hmr(
tracing::info!("HMR..."); tracing::info!("HMR...");
let session = TransientInstance::new(()); let session = TransientInstance::new(());
let idents = tt let idents = tt
.run(async move { project.hmr_identifiers().await }) .run(async move { project.client_hmr_identifiers().await })
.await?; .await?;
let start = Instant::now(); let start = Instant::now();
for ident in idents { for ident in idents {
...@@ -270,8 +270,8 @@ async fn hmr( ...@@ -270,8 +270,8 @@ async fn hmr(
let session = session.clone(); let session = session.clone();
async move { async move {
let project = project.project(); let project = project.project();
let state = project.hmr_version_state(ident.clone(), session); let state = project.client_hmr_version_state(ident.clone(), session);
project.hmr_update(ident.clone(), state).await?; project.client_hmr_update(ident.clone(), state).await?;
Ok(Vc::<()>::cell(())) Ok(Vc::<()>::cell(()))
} }
}); });
......
...@@ -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,
......
...@@ -313,7 +313,7 @@ export declare function projectEntrypointsSubscribe( ...@@ -313,7 +313,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
...@@ -321,7 +321,7 @@ export declare function projectHmrEvents( ...@@ -321,7 +321,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
)
) )
} }
......
...@@ -246,9 +246,11 @@ export interface Project { ...@@ -246,9 +246,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>
> >
......
...@@ -667,7 +667,7 @@ export async function createHotReloaderTurbopack( ...@@ -667,7 +667,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