@@ -6,7 +6,7 @@ mod specifier;
66
77use std:: { convert:: Infallible , sync:: Arc } ;
88
9- use config:: { ResolvedTaskConfig , UserRunConfig } ;
9+ use config:: { ResolvedGlobalCacheConfig , ResolvedTaskConfig , UserRunConfig } ;
1010use petgraph:: graph:: { DefaultIx , DiGraph , EdgeIndex , IndexType , NodeIndex } ;
1111use rustc_hash:: { FxBuildHasher , FxHashMap } ;
1212use serde:: Serialize ;
@@ -47,6 +47,15 @@ pub(crate) struct TaskId {
4747 pub task_name : Str ,
4848}
4949
50+ /// Whether a task originates from the `tasks` map or from a package.json script.
51+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Serialize ) ]
52+ pub enum TaskSource {
53+ /// Defined in the `tasks` map in the workspace config.
54+ TaskConfig ,
55+ /// Pure package.json script (not in the tasks map).
56+ PackageJsonScript ,
57+ }
58+
5059/// A node in the task graph, representing a task with its resolved configuration.
5160#[ derive( Debug , Serialize ) ]
5261pub struct TaskNode {
@@ -60,6 +69,9 @@ pub struct TaskNode {
6069 ///
6170 /// However, it does not contain external factors like additional args from cli and env vars.
6271 pub resolved_config : ResolvedTaskConfig ,
72+
73+ /// Whether this task comes from the tasks map or a package.json script.
74+ pub source : TaskSource ,
6375}
6476
6577impl vite_graph_ser:: GetKey for TaskNode {
@@ -166,6 +178,9 @@ pub struct IndexedTaskGraph {
166178
167179 /// task indices by task id for quick lookup
168180 pub ( crate ) node_indices_by_task_id : FxHashMap < TaskId , TaskNodeIndex > ,
181+
182+ /// Global cache configuration resolved from the workspace root config.
183+ resolved_global_cache : ResolvedGlobalCacheConfig ,
169184}
170185
171186pub type TaskGraph = DiGraph < TaskNode , TaskDependencyType , TaskIx > ;
@@ -234,11 +249,9 @@ impl IndexedTaskGraph {
234249 package_configs. push ( ( package_index, package_dir, user_config) ) ;
235250 }
236251
237- let resolved_cache = config:: ResolvedGlobalCacheConfig :: resolve_from ( root_cache. as_ref ( ) ) ;
238- let cache_scripts = resolved_cache. scripts ;
239- let cache_tasks = resolved_cache. tasks ;
252+ let resolved_global_cache = ResolvedGlobalCacheConfig :: resolve_from ( root_cache. as_ref ( ) ) ;
240253
241- // Second pass: create task nodes using resolved cache config
254+ // Second pass: create task nodes (cache is NOT applied here; it's applied at plan time)
242255 for ( package_index, package_dir, user_config) in package_configs {
243256 let package = & package_graph[ package_index] ;
244257
@@ -250,19 +263,15 @@ impl IndexedTaskGraph {
250263 . map ( |( name, value) | ( name. as_str ( ) , value. as_str ( ) ) )
251264 . collect ( ) ;
252265
253- for ( task_name, mut task_user_config) in user_config. tasks . unwrap_or_default ( ) {
254- // Apply cache.tasks kill switch: when false, override all tasks to disable caching
255- if !cache_tasks {
256- task_user_config. options . cache_config = config:: UserCacheConfig :: disabled ( ) ;
257- }
258- // For each task defined in vite.config.*, look up the corresponding package.json script (if any)
266+ for ( task_name, task_user_config) in user_config. tasks . unwrap_or_default ( ) {
267+ // For each task defined in the config, look up the corresponding package.json script (if any)
259268 let package_json_script = package_json_scripts. remove ( task_name. as_str ( ) ) ;
260269
261270 let task_id = TaskId { task_name : task_name. clone ( ) , package_index } ;
262271
263272 let dependency_specifiers = task_user_config. options . depends_on . clone ( ) ;
264273
265- // Resolve the task configuration combining vite. config.* and package.json script
274+ // Resolve the task configuration combining config and package.json script
266275 let resolved_config = ResolvedTaskConfig :: resolve (
267276 task_user_config,
268277 & package_dir,
@@ -284,20 +293,20 @@ impl IndexedTaskGraph {
284293 package_path : Arc :: clone ( & package_dir) ,
285294 } ,
286295 resolved_config,
296+ source : TaskSource :: TaskConfig ,
287297 } ;
288298
289299 let node_index = task_graph. add_node ( task_node) ;
290300 task_ids_with_dependency_specifiers. push ( ( task_id. clone ( ) , dependency_specifiers) ) ;
291301 node_indices_by_task_id. insert ( task_id, node_index) ;
292302 }
293303
294- // For remaining package.json scripts not defined in vite.config.* , create tasks with default config
304+ // For remaining package.json scripts not in the tasks map , create tasks with default config
295305 for ( script_name, package_json_script) in package_json_scripts {
296306 let task_id = TaskId { task_name : Str :: from ( script_name) , package_index } ;
297307 let resolved_config = ResolvedTaskConfig :: resolve_package_json_script (
298308 & package_dir,
299309 package_json_script,
300- cache_scripts,
301310 ) ;
302311 let node_index = task_graph. add_node ( TaskNode {
303312 task_display : TaskDisplay {
@@ -306,6 +315,7 @@ impl IndexedTaskGraph {
306315 package_path : Arc :: clone ( & package_dir) ,
307316 } ,
308317 resolved_config,
318+ source : TaskSource :: PackageJsonScript ,
309319 } ) ;
310320 node_indices_by_task_id. insert ( task_id, node_index) ;
311321 }
@@ -316,6 +326,7 @@ impl IndexedTaskGraph {
316326 task_graph,
317327 indexed_package_graph : IndexedPackageGraph :: index ( package_graph) ,
318328 node_indices_by_task_id,
329+ resolved_global_cache,
319330 } ;
320331
321332 // Add explicit dependencies
@@ -420,4 +431,9 @@ impl IndexedTaskGraph {
420431 let index = self . indexed_package_graph . get_package_index_from_cwd ( cwd) ?;
421432 Some ( self . get_package_path ( index) )
422433 }
434+
435+ #[ must_use]
436+ pub const fn global_cache_config ( & self ) -> & ResolvedGlobalCacheConfig {
437+ & self . resolved_global_cache
438+ }
423439}
0 commit comments