-
Notifications
You must be signed in to change notification settings - Fork 27.4k
/
Copy pathproject.rs
728 lines (630 loc) · 24.4 KB
/
project.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
use std::{net::SocketAddr, path::MAIN_SEPARATOR};
use anyhow::Result;
use indexmap::{map::Entry, IndexMap};
use next_core::{
all_assets_from_entries,
app_structure::find_app_dir,
emit_assets, get_edge_chunking_context, get_edge_compile_time_info,
get_edge_resolve_options_context,
middleware::middleware_files,
mode::NextMode,
next_client::{get_client_chunking_context, get_client_compile_time_info},
next_config::{JsConfig, NextConfig},
next_server::{
get_server_chunking_context, get_server_compile_time_info,
get_server_module_options_context, ServerContextType,
},
next_telemetry::NextFeatureTelemetry,
};
use serde::{Deserialize, Serialize};
use turbo_tasks::{
debug::ValueDebugFormat,
graph::{AdjacencyMap, GraphTraversal},
trace::TraceRawVcs,
Completion, Completions, IntoTraitRef, State, TaskInput, TransientInstance, TryFlatJoinIterExt,
Value, Vc,
};
use turbopack_binding::{
turbo::{
tasks_env::{EnvMap, ProcessEnv},
tasks_fs::{DiskFileSystem, FileSystem, FileSystemPath, VirtualFileSystem},
},
turbopack::{
build::BuildChunkingContext,
core::{
changed::content_changed,
chunk::ChunkingContext,
compile_time_info::CompileTimeInfo,
context::AssetContext,
diagnostics::DiagnosticExt,
environment::ServerAddr,
file_source::FileSource,
output::{OutputAsset, OutputAssets},
reference_type::{EntryReferenceSubType, ReferenceType},
resolve::{find_context_file, FindContextFileResult},
source::Source,
version::{Update, Version, VersionState, VersionedContent},
PROJECT_FILESYSTEM_NAME,
},
dev::DevChunkingContext,
ecmascript::chunk::EcmascriptChunkingContext,
node::execution_context::ExecutionContext,
turbopack::{evaluate_context::node_build_environment, ModuleAssetContext},
},
};
use crate::{
app::{AppProject, OptionAppProject},
build,
entrypoints::Entrypoints,
middleware::MiddlewareEndpoint,
pages::PagesProject,
route::{Endpoint, Route},
versioned_content_map::{OutputAssetsOperation, VersionedContentMap},
};
#[derive(Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, TraceRawVcs)]
#[serde(rename_all = "camelCase")]
pub struct ProjectOptions {
/// A root path from which all files must be nested under. Trying to access
/// a file outside this root will fail. Think of this as a chroot.
pub root_path: String,
/// A path inside the root_path which contains the app/pages directories.
pub project_path: String,
/// The contents of next.config.js, serialized to JSON.
pub next_config: String,
/// The contents of ts/config read by load-jsconfig, serialized to JSON.
pub js_config: String,
/// A map of environment variables to use when compiling code.
pub env: Vec<(String, String)>,
/// Whether to watch the filesystem for file changes.
pub watch: bool,
/// The address of the dev server.
pub server_addr: String,
}
#[derive(Serialize, Deserialize, TraceRawVcs, PartialEq, Eq, ValueDebugFormat)]
pub struct Middleware {
pub endpoint: Vc<Box<dyn Endpoint>>,
}
#[turbo_tasks::value]
pub struct ProjectContainer {
options_state: State<ProjectOptions>,
versioned_content_map: Vc<VersionedContentMap>,
}
#[turbo_tasks::value_impl]
impl ProjectContainer {
#[turbo_tasks::function]
pub fn new(options: ProjectOptions) -> Vc<Self> {
ProjectContainer {
options_state: State::new(options),
versioned_content_map: VersionedContentMap::new(),
}
.cell()
}
#[turbo_tasks::function]
pub async fn update(self: Vc<Self>, options: ProjectOptions) -> Result<Vc<()>> {
self.await?.options_state.set(options);
Ok(Default::default())
}
#[turbo_tasks::function]
pub async fn project(self: Vc<Self>) -> Result<Vc<Project>> {
let this = self.await?;
let options = this.options_state.get();
let next_config = NextConfig::from_string(Vc::cell(options.next_config.clone()));
let js_config = JsConfig::from_string(Vc::cell(options.js_config.clone()));
let env: Vc<EnvMap> = Vc::cell(options.env.iter().cloned().collect());
Ok(Project {
root_path: options.root_path.clone(),
project_path: options.project_path.clone(),
watch: options.watch,
server_addr: options.server_addr.parse()?,
next_config,
js_config,
env: Vc::upcast(env),
browserslist_query: "last 1 Chrome versions, last 1 Firefox versions, last 1 Safari \
versions, last 1 Edge versions"
.to_string(),
mode: NextMode::Development,
versioned_content_map: this.versioned_content_map,
}
.cell())
}
/// See [Project::entrypoints].
#[turbo_tasks::function]
pub fn entrypoints(self: Vc<Self>) -> Vc<Entrypoints> {
self.project().entrypoints()
}
/// See [Project::hmr_identifiers].
#[turbo_tasks::function]
pub fn hmr_identifiers(self: Vc<Self>) -> Vc<Vec<String>> {
self.project().hmr_identifiers()
}
}
#[turbo_tasks::value]
pub struct Project {
/// A root path from which all files must be nested under. Trying to access
/// a file outside this root will fail. Think of this as a chroot.
root_path: String,
/// A path inside the root_path which contains the app/pages directories.
project_path: String,
/// Whether to watch the filesystem for file changes.
watch: bool,
/// The address of the dev server.
#[turbo_tasks(trace_ignore)]
server_addr: SocketAddr,
/// Next config.
next_config: Vc<NextConfig>,
/// Js/Tsconfig read by load-jsconfig
js_config: Vc<JsConfig>,
/// A map of environment variables to use when compiling code.
env: Vc<Box<dyn ProcessEnv>>,
browserslist_query: String,
mode: NextMode,
versioned_content_map: Vc<VersionedContentMap>,
}
#[turbo_tasks::value_impl]
impl Project {
#[turbo_tasks::function]
async fn app_project(self: Vc<Self>) -> Result<Vc<OptionAppProject>> {
let this = self.await?;
let app_dir = find_app_dir(self.project_path()).await?;
Ok(Vc::cell(if let Some(app_dir) = &*app_dir {
Some(AppProject::new(self, *app_dir, this.mode))
} else {
None
}))
}
#[turbo_tasks::function]
async fn pages_project(self: Vc<Self>) -> Result<Vc<PagesProject>> {
let this = self.await?;
Ok(PagesProject::new(self, this.mode))
}
#[turbo_tasks::function]
async fn project_fs(self: Vc<Self>) -> Result<Vc<Box<dyn FileSystem>>> {
let this = self.await?;
let disk_fs = DiskFileSystem::new(
PROJECT_FILESYSTEM_NAME.to_string(),
this.root_path.to_string(),
);
if this.watch {
disk_fs.await?.start_watching_with_invalidation_reason()?;
}
Ok(Vc::upcast(disk_fs))
}
#[turbo_tasks::function]
async fn client_fs(self: Vc<Self>) -> Result<Vc<Box<dyn FileSystem>>> {
let virtual_fs = VirtualFileSystem::new();
Ok(Vc::upcast(virtual_fs))
}
#[turbo_tasks::function]
async fn node_fs(self: Vc<Self>) -> Result<Vc<Box<dyn FileSystem>>> {
let this = self.await?;
let disk_fs = DiskFileSystem::new("node".to_string(), this.project_path.clone());
disk_fs.await?.start_watching_with_invalidation_reason()?;
Ok(Vc::upcast(disk_fs))
}
#[turbo_tasks::function]
fn server_addr(&self) -> Vc<ServerAddr> {
ServerAddr::new(self.server_addr).cell()
}
#[turbo_tasks::function]
pub(super) fn node_root(self: Vc<Self>) -> Vc<FileSystemPath> {
self.node_fs().root().join(".next".to_string())
}
#[turbo_tasks::function]
pub(super) fn client_root(self: Vc<Self>) -> Vc<FileSystemPath> {
self.client_fs().root()
}
#[turbo_tasks::function]
fn project_root_path(self: Vc<Self>) -> Vc<FileSystemPath> {
self.project_fs().root()
}
#[turbo_tasks::function]
pub(super) fn client_relative_path(self: Vc<Self>) -> Vc<FileSystemPath> {
self.client_root().join("_next".to_string())
}
#[turbo_tasks::function]
pub(super) async fn project_path(self: Vc<Self>) -> Result<Vc<FileSystemPath>> {
let this = self.await?;
let root = self.project_root_path();
let project_relative = this.project_path.strip_prefix(&this.root_path).unwrap();
let project_relative = project_relative
.strip_prefix(MAIN_SEPARATOR)
.unwrap_or(project_relative)
.replace(MAIN_SEPARATOR, "/");
Ok(root.join(project_relative))
}
#[turbo_tasks::function]
pub(super) async fn env(self: Vc<Self>) -> Result<Vc<Box<dyn ProcessEnv>>> {
Ok(self.await?.env)
}
#[turbo_tasks::function]
pub(super) async fn next_config(self: Vc<Self>) -> Result<Vc<NextConfig>> {
Ok(self.await?.next_config)
}
#[turbo_tasks::function]
pub(super) async fn js_config(self: Vc<Self>) -> Result<Vc<JsConfig>> {
Ok(self.await?.js_config)
}
#[turbo_tasks::function]
pub(super) fn execution_context(self: Vc<Self>) -> Vc<ExecutionContext> {
let node_root = self.node_root();
let node_execution_chunking_context = Vc::upcast(
DevChunkingContext::builder(
self.project_path(),
node_root,
node_root.join("chunks".to_string()),
node_root.join("assets".to_string()),
node_build_environment(),
)
.build(),
);
ExecutionContext::new(
self.project_path(),
node_execution_chunking_context,
self.env(),
)
}
#[turbo_tasks::function]
pub(super) fn client_compile_time_info(&self) -> Vc<CompileTimeInfo> {
get_client_compile_time_info(self.mode, self.browserslist_query.clone())
}
#[turbo_tasks::function]
pub(super) async fn server_compile_time_info(self: Vc<Self>) -> Result<Vc<CompileTimeInfo>> {
let this = self.await?;
Ok(get_server_compile_time_info(
this.mode,
self.env(),
self.server_addr(),
))
}
#[turbo_tasks::function]
pub(super) fn edge_compile_time_info(self: Vc<Self>) -> Vc<CompileTimeInfo> {
get_edge_compile_time_info(self.project_path(), self.server_addr())
}
#[turbo_tasks::function]
pub(super) async fn client_chunking_context(
self: Vc<Self>,
) -> Result<Vc<Box<dyn EcmascriptChunkingContext>>> {
let this = self.await?;
Ok(get_client_chunking_context(
self.project_path(),
self.client_root(),
self.client_compile_time_info().environment(),
this.mode,
))
}
#[turbo_tasks::function]
fn server_chunking_context(self: Vc<Self>) -> Vc<BuildChunkingContext> {
get_server_chunking_context(
self.project_path(),
self.node_root(),
self.client_root(),
self.server_compile_time_info().environment(),
)
}
#[turbo_tasks::function]
fn edge_chunking_context(self: Vc<Self>) -> Vc<Box<dyn EcmascriptChunkingContext>> {
get_edge_chunking_context(
self.project_path(),
self.node_root(),
self.client_root(),
self.edge_compile_time_info().environment(),
)
}
/// Emit a telemetry event corresponding to webpack configuration telemetry
/// (https://github.com/vercel/next.js/blob/9da305fe320b89ee2f8c3cfb7ecbf48856368913/packages/next/src/build/webpack-config.ts#L2516)
/// to detect which feature is enabled.
#[turbo_tasks::function]
async fn collect_project_feature_telemetry(self: Vc<Self>) -> Result<Vc<()>> {
let emit_event = |feature_name: &str, enabled: bool| {
NextFeatureTelemetry::new(feature_name.to_string(), enabled)
.cell()
.emit();
};
// First, emit an event for the binary target triple.
// This is different to webpack-config; when this is being called,
// it is always using SWC so we don't check swc here.
emit_event(build::BUILD_TARGET, true);
// Go over jsconfig and report enabled features.
let compiler_options = self.js_config().compiler_options().await?;
let compiler_options = compiler_options.as_object();
let experimental_decorators_enabled = compiler_options
.as_ref()
.and_then(|compiler_options| compiler_options.get("experimentalDecorators"))
.is_some();
let jsx_import_source_enabled = compiler_options
.as_ref()
.and_then(|compiler_options| compiler_options.get("jsxImportSource"))
.is_some();
emit_event("swcExperimentalDecorators", experimental_decorators_enabled);
emit_event("swcImportSource", jsx_import_source_enabled);
// Go over config and report enabled features.
// [TODO]: useSwcLoader is not being reported as it is not directly corresponds (it checks babel config existence)
// need to confirm what we'll do with turbopack.
let config = self.next_config();
emit_event("swcMinify", *config.swc_minify().await?);
emit_event(
"skipMiddlewareUrlNormalize",
*config.skip_middleware_url_normalize().await?,
);
emit_event(
"skipTrailingSlashRedirect",
*config.skip_trailing_slash_redirect().await?,
);
let config = &config.await?;
emit_event("modularizeImports", config.modularize_imports.is_some());
emit_event("transpilePackages", config.transpile_packages.is_some());
emit_event("turbotrace", config.experimental.turbotrace.is_some());
// compiler options
let compiler_options = config.compiler.as_ref();
let swc_relay_enabled = compiler_options.and_then(|c| c.relay.as_ref()).is_some();
let styled_components_enabled = compiler_options
.map(|c| c.styled_components.is_some())
.unwrap_or_default();
let react_remove_properties_enabled = compiler_options
.and_then(|c| c.react_remove_properties)
.unwrap_or_default();
let remove_console_enabled = compiler_options
.map(|c| c.remove_console.is_some())
.unwrap_or_default();
let emotion_enabled = compiler_options
.map(|c| c.emotion.is_some())
.unwrap_or_default();
emit_event("swcRelay", swc_relay_enabled);
emit_event("swcStyledComponents", styled_components_enabled);
emit_event("swcReactRemoveProperties", react_remove_properties_enabled);
emit_event("swcRemoveConsole", remove_console_enabled);
emit_event("swcEmotion", emotion_enabled);
Ok(Default::default())
}
#[turbo_tasks::function]
pub(super) fn ssr_chunking_context(self: Vc<Self>) -> Vc<BuildChunkingContext> {
self.server_chunking_context().with_layer("ssr".to_string())
}
#[turbo_tasks::function]
pub(super) fn edge_ssr_chunking_context(
self: Vc<Self>,
) -> Vc<Box<dyn EcmascriptChunkingContext>> {
self.edge_chunking_context()
.with_layer("edge ssr".to_string())
}
#[turbo_tasks::function]
pub(super) fn ssr_data_chunking_context(self: Vc<Self>) -> Vc<BuildChunkingContext> {
self.server_chunking_context()
.with_layer("ssr data".to_string())
}
#[turbo_tasks::function]
pub(super) fn edge_ssr_data_chunking_context(
self: Vc<Self>,
) -> Vc<Box<dyn EcmascriptChunkingContext>> {
self.edge_chunking_context()
.with_layer("edge ssr data".to_string())
}
#[turbo_tasks::function]
pub(super) fn rsc_chunking_context(self: Vc<Self>) -> Vc<BuildChunkingContext> {
self.server_chunking_context().with_layer("rsc".to_string())
}
#[turbo_tasks::function]
pub(super) fn edge_rsc_chunking_context(
self: Vc<Self>,
) -> Vc<Box<dyn EcmascriptChunkingContext>> {
self.edge_chunking_context()
.with_layer("edge rsc".to_string())
}
#[turbo_tasks::function]
pub(super) fn edge_middleware_chunking_context(
self: Vc<Self>,
) -> Vc<Box<dyn EcmascriptChunkingContext>> {
self.edge_chunking_context()
.with_layer("middleware".to_string())
}
/// Scans the app/pages directories for entry points files (matching the
/// provided page_extensions).
#[turbo_tasks::function]
pub async fn entrypoints(self: Vc<Self>) -> Result<Vc<Entrypoints>> {
self.collect_project_feature_telemetry().await?;
let mut routes = IndexMap::new();
let app_project = self.app_project();
let pages_project = self.pages_project();
if let Some(app_project) = &*app_project.await? {
let app_routes = app_project.routes();
routes.extend(app_routes.await?.iter().map(|(k, v)| (k.clone(), *v)));
}
for (pathname, page_route) in pages_project.routes().await?.iter() {
match routes.entry(pathname.clone()) {
Entry::Occupied(mut entry) => {
*entry.get_mut() = Route::Conflict;
}
Entry::Vacant(entry) => {
entry.insert(*page_route);
}
}
}
let middleware = find_context_file(
self.project_path(),
middleware_files(self.next_config().page_extensions()),
);
let middleware = if let FindContextFileResult::Found(fs_path, _) = *middleware.await? {
let source = Vc::upcast(FileSource::new(fs_path));
Some(Middleware {
endpoint: Vc::upcast(self.middleware_endpoint(source)),
})
} else {
None
};
Ok(Entrypoints {
routes,
middleware,
pages_document_endpoint: self.pages_project().document_endpoint(),
pages_app_endpoint: self.pages_project().app_endpoint(),
pages_error_endpoint: self.pages_project().error_endpoint(),
}
.cell())
}
#[turbo_tasks::function]
fn middleware_context(self: Vc<Self>) -> Vc<Box<dyn AssetContext>> {
Vc::upcast(ModuleAssetContext::new(
Default::default(),
self.edge_compile_time_info(),
get_server_module_options_context(
self.project_path(),
self.execution_context(),
Value::new(ServerContextType::Middleware),
NextMode::Development,
self.next_config(),
),
get_edge_resolve_options_context(
self.project_path(),
Value::new(ServerContextType::Middleware),
NextMode::Development,
self.next_config(),
self.execution_context(),
),
))
}
#[turbo_tasks::function]
fn middleware_endpoint(self: Vc<Self>, source: Vc<Box<dyn Source>>) -> Vc<MiddlewareEndpoint> {
let context = self.middleware_context();
let module = context.process(
source,
Value::new(ReferenceType::Entry(EntryReferenceSubType::Middleware)),
);
MiddlewareEndpoint::new(self, context, module)
}
#[turbo_tasks::function]
pub async fn emit_all_output_assets(
self: Vc<Self>,
output_assets: Vc<OutputAssetsOperation>,
) -> Result<Vc<Completion>> {
let all_output_assets = all_assets_from_entries_operation(output_assets);
self.await?
.versioned_content_map
.insert_output_assets(all_output_assets)
.await?;
Ok(emit_assets(
*all_output_assets.await?,
self.node_root(),
self.client_relative_path(),
self.node_root(),
))
}
#[turbo_tasks::function]
async fn hmr_content(
self: Vc<Self>,
identifier: String,
) -> Result<Vc<Box<dyn VersionedContent>>> {
Ok(self
.await?
.versioned_content_map
.get(self.client_relative_path().join(identifier)))
}
#[turbo_tasks::function]
async fn hmr_content_and_write(
self: Vc<Self>,
identifier: String,
) -> Result<Vc<Box<dyn VersionedContent>>> {
Ok(self.await?.versioned_content_map.get_and_write(
self.client_relative_path().join(identifier),
self.client_relative_path(),
self.node_root(),
))
}
#[turbo_tasks::function]
async fn hmr_version(self: Vc<Self>, identifier: String) -> Result<Vc<Box<dyn Version>>> {
let content = self.hmr_content(identifier);
Ok(content.version())
}
/// 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(
self: Vc<Self>,
identifier: String,
session: TransientInstance<()>,
) -> Result<Vc<VersionState>> {
let version = self.hmr_version(identifier);
// The session argument is important to avoid caching this function between
// sessions.
let _ = session;
// INVALIDATION: This is intentionally untracked to avoid invalidating this
// function completely. We want to initialize the VersionState with the
// first seen version of the session.
VersionState::new(version.into_trait_ref_untracked().await?).await
}
/// 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(
self: Vc<Self>,
identifier: String,
from: Vc<VersionState>,
) -> Result<Vc<Update>> {
let from = from.get();
Ok(self.hmr_content_and_write(identifier).update(from))
}
/// 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<String>>> {
Ok(self
.await?
.versioned_content_map
.keys_in_path(self.client_relative_path()))
}
/// Completion when server side changes are detected in output assets
/// referenced from the roots
#[turbo_tasks::function]
pub fn server_changed(self: Vc<Self>, roots: Vc<OutputAssets>) -> Vc<Completion> {
let path = self.node_root();
any_output_changed(roots, path)
}
/// Completion when client side changes are detected in output assets
/// referenced from the roots
#[turbo_tasks::function]
pub fn client_changed(self: Vc<Self>, roots: Vc<OutputAssets>) -> Vc<Completion> {
let path = self.client_root();
any_output_changed(roots, path)
}
}
#[turbo_tasks::function]
async fn any_output_changed(
roots: Vc<OutputAssets>,
path: Vc<FileSystemPath>,
) -> Result<Vc<Completion>> {
let path = &path.await?;
let completions = AdjacencyMap::new()
.skip_duplicates()
.visit(roots.await?.iter().copied(), get_referenced_output_assets)
.await
.completed()?
.into_inner()
.into_reverse_topological()
.map(|m| async move {
let asset_path = m.ident().path().await?;
if !asset_path.path.ends_with(".map") && asset_path.is_inside_ref(path) {
Ok(Some(content_changed(Vc::upcast(m))))
} else {
Ok(None)
}
})
.try_flat_join()
.await?;
Ok(Vc::<Completions>::cell(completions).completed())
}
async fn get_referenced_output_assets(
parent: Vc<Box<dyn OutputAsset>>,
) -> Result<impl Iterator<Item = Vc<Box<dyn OutputAsset>>> + Send> {
Ok(parent.references().await?.clone_value().into_iter())
}
#[turbo_tasks::function]
async fn all_assets_from_entries_operation_inner(
operation: Vc<OutputAssetsOperation>,
) -> Result<Vc<OutputAssets>> {
let assets = *operation.await?;
Vc::connect(assets);
Ok(all_assets_from_entries(assets))
}
fn all_assets_from_entries_operation(
operation: Vc<OutputAssetsOperation>,
) -> Vc<OutputAssetsOperation> {
Vc::cell(all_assets_from_entries_operation_inner(operation))
}