1use std::path::{Path, PathBuf};
9
10use fallow_config::{
11 AutoImportRule, EntryPointRole, JsxImportSourceRule, PackageJson, UsedClassMemberRule,
12};
13use fallow_types::semantic::SemanticFrameworkContract;
14use regex::Regex;
15
16const TEST_ENTRY_POINT_PLUGINS: &[&str] = &[
17 "ava",
18 "bun",
19 "deno",
20 "cucumber",
21 "cypress",
22 "jasmine",
23 "jest",
24 "k6",
25 "mocha",
26 "playwright",
27 "rstest",
28 "tap",
29 "tsd",
30 "vitest",
31 "webdriverio",
32];
33
34const RUNTIME_ENTRY_POINT_PLUGINS: &[&str] = &[
35 "adonis",
36 "angular",
37 "astro",
38 "browser-extension",
39 "convex",
40 "docusaurus",
41 "egg",
42 "electron",
43 "ember",
44 "eve",
45 "expo",
46 "expo-router",
47 "flue",
48 "gatsby",
49 "hardhat",
50 "kibana",
51 "module-federation",
52 "nestjs",
53 "next-intl",
54 "nextjs",
55 "nitro",
56 "nuxt",
57 "obsidian",
58 "parcel",
59 "qwik",
60 "react-native",
61 "react-router",
62 "redwoodsdk",
63 "remix",
64 "rolldown",
65 "rollup",
66 "rsbuild",
67 "rspack",
68 "sanity",
69 "supabase",
70 "sveltekit",
71 "tanstack-router",
72 "tsdown",
73 "tsup",
74 "vercel",
75 "vite",
76 "vite-plus",
77 "vitepress",
78 "waku",
79 "webpack",
80 "wrangler",
81 "wxt",
82];
83
84#[cfg(test)]
87fn entry_rules_match(result: &PluginResult, path: &str) -> bool {
88 result
89 .entry_patterns
90 .iter()
91 .filter_map(|rule| CompiledPathRule::for_entry_rule(rule, "entry pattern"))
92 .any(|rule| rule.matches(path))
93}
94
95#[cfg(test)]
96const SUPPORT_ENTRY_POINT_PLUGINS: &[&str] = &[
97 "alchemy",
98 "content-collections",
99 "contentlayer",
100 "danger",
101 "drizzle",
102 "fumadocs",
103 "i18next",
104 "knex",
105 "kysely",
106 "mintlify",
107 "msw",
108 "opencode",
109 "prisma",
110 "storybook",
111 "stryker",
112 "typeorm",
113 "velite",
114];
115
116#[derive(Debug, Clone, Copy, PartialEq, Eq)]
118pub enum PluginConfigEffect {
119 Unreadable,
122 NotModeled,
125}
126
127#[derive(Debug, Clone, PartialEq, Eq)]
138pub struct PluginConfigDiagnostic {
139 pub config_path: PathBuf,
141 pub plugin: String,
145 pub key: String,
148 pub reason: String,
150 pub effect: PluginConfigEffect,
152}
153
154impl PluginConfigDiagnostic {
155 pub(super) fn unreadable(
157 config_path: &Path,
158 plugin: &str,
159 key: &str,
160 reason: &'static str,
161 ) -> Self {
162 Self {
163 config_path: config_path.to_path_buf(),
164 plugin: plugin.to_owned(),
165 key: key.to_owned(),
166 reason: reason.to_owned(),
167 effect: PluginConfigEffect::Unreadable,
168 }
169 }
170
171 pub(crate) fn not_modeled(
173 config_path: &Path,
174 plugin: &str,
175 key: &str,
176 reason: &'static str,
177 ) -> Self {
178 Self {
179 config_path: config_path.to_path_buf(),
180 plugin: plugin.to_owned(),
181 key: key.to_owned(),
182 reason: reason.to_owned(),
183 effect: PluginConfigEffect::NotModeled,
184 }
185 }
186
187 #[must_use]
190 pub fn into_workspace_diagnostic(self, root: &Path) -> fallow_config::WorkspaceDiagnostic {
191 let Self {
192 config_path,
193 plugin,
194 key,
195 reason,
196 effect,
197 } = self;
198 let kind = match effect {
199 PluginConfigEffect::Unreadable => {
200 fallow_config::WorkspaceDiagnosticKind::PluginConfigUnreadable {
201 plugin,
202 key,
203 reason,
204 }
205 }
206 PluginConfigEffect::NotModeled => {
207 fallow_config::WorkspaceDiagnosticKind::PluginEffectNotModeled {
208 plugin,
209 key,
210 reason,
211 }
212 }
213 };
214 fallow_config::WorkspaceDiagnostic::new(root, config_path, kind)
215 }
216}
217
218#[derive(Debug, Default)]
220pub struct PluginResult {
221 entry_patterns: Vec<PathRule>,
223 replace_entry_patterns: bool,
228 accumulate_config_entry_patterns: bool,
232 replace_used_export_rules: bool,
235 used_exports: Vec<UsedExportRule>,
237 entry_export_credits: Vec<UsedExportRule>,
242 used_class_members: Vec<UsedClassMemberRule>,
247 referenced_dependencies: Vec<String>,
249 package_referenced_dependencies: Vec<(PathBuf, String)>,
252 required_dependencies: Vec<RequiredDependency>,
254 always_used_files: Vec<String>,
256 path_aliases: Vec<(String, String)>,
258 setup_files: Vec<PathBuf>,
260 fixture_patterns: Vec<String>,
262 scss_include_paths: Vec<PathBuf>,
270 static_dir_mappings: Vec<(PathBuf, String)>,
273 framework_static_dir_mappings: Vec<(PathBuf, String)>,
274 provided_dependencies: Vec<ProvidedDependencyRule>,
277 config_diagnostics: Vec<PluginConfigDiagnostic>,
281 federation_sources: Vec<FederationSource>,
284 jsx_import_sources: Vec<JsxImportSourceRule>,
288 jsx_package_credits: Vec<JsxImportSourceRule>,
293 tsconfig_jsx_dirs: Vec<PathBuf>,
298}
299
300#[derive(Debug, Clone, PartialEq, Eq)]
302pub struct FederationSource {
303 pub target: FederationSourceTarget,
305 pub config_path: PathBuf,
307 pub plugin: String,
309 pub key: &'static str,
311}
312
313#[derive(Debug, Clone, PartialEq, Eq)]
315pub enum FederationSourceTarget {
316 Exposed(PathRule),
318 Remote(String),
320}
321
322impl FederationSource {
323 #[must_use]
324 fn prefixed(&self, ws_prefix: &str) -> Self {
325 let target = match &self.target {
326 FederationSourceTarget::Exposed(rule) => {
327 FederationSourceTarget::Exposed(rule.prefixed(ws_prefix))
328 }
329 FederationSourceTarget::Remote(alias) => FederationSourceTarget::Remote(alias.clone()),
330 };
331 Self {
332 target,
333 config_path: self.config_path.clone(),
334 plugin: self.plugin.clone(),
335 key: self.key,
336 }
337 }
338}
339
340#[must_use]
348pub fn federation_trace_provenance(
349 root: &Path,
350 files: &[crate::discover::DiscoveredFile],
351 sources: &[FederationSource],
352 modules: &[crate::extract::ModuleInfo],
353) -> fallow_types::trace::TraceProvenance {
354 let mut provenance = fallow_types::trace::TraceProvenance::default();
355 push_runtime_remote_sources(&mut provenance, root, files, modules);
356 if sources.is_empty() {
357 return provenance;
358 }
359 let mut exposed = Vec::new();
360 for source in sources {
361 let config = source
362 .config_path
363 .strip_prefix(root)
364 .unwrap_or(&source.config_path)
365 .to_path_buf();
366 let trace_source = fallow_types::trace::TraceSource {
367 kind: "module-federation".to_owned(),
368 plugin: source.plugin.clone(),
369 config,
370 key: source.key.to_owned(),
371 };
372 match &source.target {
373 FederationSourceTarget::Exposed(rule) => {
374 if let Some(compiled) =
375 CompiledPathRule::for_entry_rule(rule, "Module Federation exposes target")
376 {
377 exposed.push((compiled, trace_source));
378 }
379 }
380 FederationSourceTarget::Remote(alias) => {
381 provenance.push_dependency(alias.clone(), trace_source);
382 }
383 }
384 }
385 if exposed.is_empty() {
386 return provenance;
387 }
388 for file in files {
389 let Ok(relative) = file.path.strip_prefix(root) else {
390 continue;
391 };
392 let relative_str = relative.to_string_lossy().replace('\\', "/");
393 for (rule, source) in &exposed {
394 if rule.matches(&relative_str) {
395 provenance.push_file(relative.to_path_buf(), source.clone());
396 }
397 }
398 }
399 provenance
400}
401
402pub const CONFIG_ONLY_EXPORT_NAMES: &[&str] = &[
411 "dynamic",
412 "dynamicParams",
413 "revalidate",
414 "fetchCache",
415 "runtime",
416 "preferredRegion",
417 "maxDuration",
418 "prerender",
419 "config",
420 "metadata",
421 "viewport",
422];
423
424pub fn push_tooling_trace_credits(
428 provenance: &mut fallow_types::trace::TraceProvenance,
429 root: &Path,
430 workspaces: &[fallow_config::WorkspaceInfo],
431 plugin_result: &AggregatedPluginResult,
432) {
433 for entry in &plugin_result.plugin_tooling {
434 let Some(evidence) = entry.evidence(&plugin_result.script_used_packages) else {
435 continue;
436 };
437 let credit = match evidence {
438 PluginToolingEvidence::OwnConfig(config) => fallow_types::trace::ToolingCredit {
439 reason: "plugin-config".to_owned(),
440 plugin: Some(entry.plugin.clone()),
441 config: Some(config.strip_prefix(root).unwrap_or(config).to_path_buf()),
442 reference: None,
443 },
444 PluginToolingEvidence::Reference(name) => fallow_types::trace::ToolingCredit {
445 reason: "plugin-reference".to_owned(),
446 plugin: Some(entry.plugin.clone()),
447 config: None,
448 reference: Some(name.to_owned()),
449 },
450 };
451 for dependency in &entry.dependencies {
452 provenance.push_tooling_credit(dependency.clone(), credit.clone());
453 }
454 }
455 push_types_trace_credits(provenance, plugin_result);
456 push_catalogue_trace_credits(provenance, root, workspaces, plugin_result);
457}
458
459fn push_catalogue_trace_credits(
469 provenance: &mut fallow_types::trace::TraceProvenance,
470 root: &Path,
471 workspaces: &[fallow_config::WorkspaceInfo],
472 plugin_result: &AggregatedPluginResult,
473) {
474 let manifests = read_trace_manifests(root, workspaces);
475 let mut names: Vec<&String> = plugin_result.dev_dependency_names.iter().collect();
476 names.sort_unstable();
477 for name in names {
478 let declaring: Vec<&(PathBuf, serde_json::Value)> = manifests
479 .iter()
480 .filter(|(_, manifest)| manifest_lists(manifest, "devDependencies", name))
481 .collect();
482 if let Some(credit) = catalogue_credit(name, root, &declaring) {
483 provenance.push_tooling_credit(name.clone(), credit);
484 }
485 if let Some((path, _)) = declaring
486 .iter()
487 .find(|(_, manifest)| manifest_lists(manifest, "peerDependencies", name))
488 {
489 provenance.push_tooling_credit(
490 name.clone(),
491 fallow_types::trace::ToolingCredit {
492 reason: "own-peer".to_owned(),
493 plugin: None,
494 config: Some(path.strip_prefix(root).unwrap_or(path).to_path_buf()),
495 reference: None,
496 },
497 );
498 }
499 }
500}
501
502fn read_trace_manifests(
504 root: &Path,
505 workspaces: &[fallow_config::WorkspaceInfo],
506) -> Vec<(PathBuf, serde_json::Value)> {
507 std::iter::once(root)
508 .chain(
509 workspaces
510 .iter()
511 .map(|ws| ws.root.as_path())
512 .filter(|ws_root| *ws_root != root),
513 )
514 .filter_map(|package_root| {
515 let path = package_root.join("package.json");
516 let content = std::fs::read_to_string(&path).ok()?;
517 serde_json::from_str(&content)
518 .ok()
519 .map(|value| (path, value))
520 })
521 .collect()
522}
523
524fn manifest_lists(manifest: &serde_json::Value, section: &str, name: &str) -> bool {
525 manifest
526 .get(section)
527 .and_then(serde_json::Value::as_object)
528 .is_some_and(|deps| deps.contains_key(name))
529}
530
531fn catalogue_credit(
534 name: &str,
535 root: &Path,
536 declaring: &[&(PathBuf, serde_json::Value)],
537) -> Option<fallow_types::trace::ToolingCredit> {
538 if is_ambient_types_package(name) || types_package_target(name).is_some() {
539 return None;
540 }
541 let Some(patterns) = cli_tooling_config_patterns(name) else {
542 return is_known_tooling_dependency(name).then(|| fallow_types::trace::ToolingCredit {
543 reason: "known-tooling".to_owned(),
544 plugin: None,
545 config: None,
546 reference: None,
547 });
548 };
549 let config = declaring.iter().find_map(|(path, manifest)| {
550 crate::analyze::cli_tool_own_config(name, patterns, root, path, Some(manifest))
551 })?;
552 Some(fallow_types::trace::ToolingCredit {
553 reason: "known-tooling-config".to_owned(),
554 plugin: None,
555 config: Some(config.strip_prefix(root).unwrap_or(&config).to_path_buf()),
556 reference: None,
557 })
558}
559
560fn push_types_trace_credits(
565 provenance: &mut fallow_types::trace::TraceProvenance,
566 plugin_result: &AggregatedPluginResult,
567) {
568 let declared = plugin_result.dependency_binaries.declared_packages();
569 let mut names: Vec<&String> = plugin_result.dev_dependency_names.iter().collect();
570 names.sort_unstable();
571 for name in names {
572 let credit = if is_ambient_types_package(name) {
573 fallow_types::trace::ToolingCredit {
574 reason: "ambient-types".to_owned(),
575 plugin: None,
576 config: None,
577 reference: None,
578 }
579 } else if let Some(target) = types_package_target(name) {
580 if declared.contains(&target) {
581 fallow_types::trace::ToolingCredit {
582 reason: "types-target".to_owned(),
583 plugin: None,
584 config: None,
585 reference: Some(target),
586 }
587 } else if plugin_result.referenced_dependencies.contains(name) {
588 fallow_types::trace::ToolingCredit {
589 reason: "types-config".to_owned(),
590 plugin: None,
591 config: None,
592 reference: None,
593 }
594 } else {
595 continue;
596 }
597 } else {
598 continue;
599 };
600 provenance.push_tooling_credit(name.clone(), credit);
601 }
602}
603
604fn push_runtime_remote_sources(
606 provenance: &mut fallow_types::trace::TraceProvenance,
607 root: &Path,
608 files: &[crate::discover::DiscoveredFile],
609 modules: &[crate::extract::ModuleInfo],
610) {
611 for module in modules {
612 let mut file = None;
613 for fact in module.semantic_facts.iter() {
614 let fallow_types::extract::SemanticFact::FederationRuntimeRemote(fact) = fact else {
615 continue;
616 };
617 let Some(remote) = &fact.remote else {
618 continue;
619 };
620 let Some(path) = file.get_or_insert_with(|| {
621 files.get(module.file_id.0 as usize).map(|file| {
622 file.path
623 .strip_prefix(root)
624 .unwrap_or(&file.path)
625 .to_path_buf()
626 })
627 }) else {
628 break;
629 };
630 provenance.push_dependency(
631 remote.clone(),
632 fallow_types::trace::TraceSource {
633 kind: "module-federation".to_owned(),
634 plugin: "module-federation".to_owned(),
635 config: path.clone(),
636 key: fact.call.name().to_owned(),
637 },
638 );
639 }
640 }
641}
642
643impl PluginResult {
644 fn extend_config_dir_entry_patterns(
649 &mut self,
650 values: Vec<String>,
651 config_path: &Path,
652 root: &Path,
653 ) {
654 let (negated, positive): (Vec<String>, Vec<String>) =
655 values.into_iter().partition(|value| value.starts_with('!'));
656 let excluded: Vec<String> = negated
657 .iter()
658 .filter_map(|value| value.strip_prefix('!'))
659 .filter_map(|value| config_parser::normalize_config_path(value, config_path, root))
660 .collect();
661 self.entry_patterns.extend(
662 positive
663 .iter()
664 .filter_map(|value| config_parser::normalize_config_path(value, config_path, root))
665 .map(|pattern| {
666 PathRule::new(pattern).with_excluded_globs(excluded.iter().cloned())
667 }),
668 );
669 }
670
671 fn push_parent_relative_entry_pattern(&mut self, pattern: String) {
674 let mut rule = PathRule::new(pattern);
675 rule.parent_relative = true;
676 self.entry_patterns.push(rule);
677 }
678
679 fn push_entry_pattern(&mut self, pattern: impl Into<String>) {
680 self.entry_patterns
681 .push(PathRule::new(normalize_entry_pattern(pattern.into())));
682 }
683
684 fn extend_entry_patterns<I, S>(&mut self, patterns: I)
685 where
686 I: IntoIterator<Item = S>,
687 S: Into<String>,
688 {
689 self.entry_patterns.extend(
690 patterns
691 .into_iter()
692 .map(|pat| PathRule::new(normalize_entry_pattern(pat.into()))),
693 );
694 }
695
696 fn extend_entry_patterns_or_dependencies<I, S>(
711 &mut self,
712 values: I,
713 resolve_path: impl Fn(String) -> String,
714 ) where
715 I: IntoIterator<Item = S>,
716 S: Into<String>,
717 {
718 for value in values {
719 let value = value.into();
720 if let Some(request) = module_request(&value) {
721 self.referenced_dependencies
722 .push(crate::resolve::extract_package_name(request));
723 continue;
724 }
725 self.push_entry_path(resolve_path(value));
726 }
727 }
728
729 fn extend_entry_patterns_and_dependencies<I, S>(&mut self, values: I, root: &Path)
741 where
742 I: IntoIterator<Item = S>,
743 S: Into<String>,
744 {
745 for value in values {
746 let value = value.into();
747 if let Some(request) = module_request(&value)
748 && !names_project_file(root, request)
749 {
750 self.referenced_dependencies
751 .push(crate::resolve::extract_package_name(request));
752 }
753 self.push_entry_path(value);
754 }
755 }
756
757 fn extend_entry_paths<I, S>(&mut self, values: I)
759 where
760 I: IntoIterator<Item = S>,
761 S: Into<String>,
762 {
763 for value in values {
764 self.push_entry_path(value.into());
765 }
766 }
767
768 fn push_entry_path(&mut self, value: String) {
776 if has_glob_syntax(&value) || has_source_extension(&value) {
777 self.push_entry_pattern(value);
778 return;
779 }
780 let base = value.trim_end_matches('/').to_owned();
781 self.push_entry_pattern(value);
782 self.push_entry_pattern(format!("{base}.{REQUEST_EXTENSIONS}"));
783 self.push_entry_pattern(format!("{base}/index.{REQUEST_EXTENSIONS}"));
784 }
785
786 #[must_use]
793 const fn is_empty(&self) -> bool {
794 self.config_diagnostics.is_empty()
795 && self.entry_patterns.is_empty()
796 && self.used_exports.is_empty()
797 && self.entry_export_credits.is_empty()
798 && self.used_class_members.is_empty()
799 && self.referenced_dependencies.is_empty()
800 && self.package_referenced_dependencies.is_empty()
801 && self.required_dependencies.is_empty()
802 && self.always_used_files.is_empty()
803 && self.path_aliases.is_empty()
804 && self.setup_files.is_empty()
805 && self.fixture_patterns.is_empty()
806 && self.scss_include_paths.is_empty()
807 && self.static_dir_mappings.is_empty()
808 && self.framework_static_dir_mappings.is_empty()
809 && self.provided_dependencies.is_empty()
810 && self.federation_sources.is_empty()
811 && self.jsx_import_sources.is_empty()
812 && self.jsx_package_credits.is_empty()
813 && self.tsconfig_jsx_dirs.is_empty()
814 }
815}
816
817fn names_project_file(root: &Path, value: &str) -> bool {
821 let base = root.join(value);
822 base.is_file()
823 || crate::discover::SOURCE_EXTENSIONS.iter().any(|extension| {
824 let mut candidate = base.clone().into_os_string();
825 candidate.push(".");
826 candidate.push(extension);
827 Path::new(&candidate).is_file() || base.join(format!("index.{extension}")).is_file()
828 })
829}
830
831const REQUEST_EXTENSIONS: &str = "{ts,tsx,mts,cts,gts,js,jsx,mjs,cjs,gjs,vue,svelte,astro,mdx}";
835
836fn normalize_entry_pattern(pattern: String) -> String {
837 pattern
838 .strip_prefix("./")
839 .map(str::to_owned)
840 .unwrap_or(pattern)
841}
842
843fn module_request(value: &str) -> Option<&str> {
854 let request = strip_resource_query(value);
855 (config_parser::is_package_specifier(request)
856 && !has_glob_syntax(request)
857 && !has_source_extension(request))
858 .then_some(request)
859}
860
861fn strip_resource_query(value: &str) -> &str {
869 match value.split_once('?') {
870 Some((request, query)) if is_resource_query(query) => request,
871 _ => value,
872 }
873}
874
875fn is_resource_query(query: &str) -> bool {
878 !query.is_empty()
879 && query.split('&').all(|pair| {
880 let key = pair.split_once('=').map_or(pair, |(key, _)| key);
881 key.starts_with(|first: char| first.is_ascii_alphanumeric() || first == '_')
882 && key
883 .chars()
884 .all(|char| char.is_ascii_alphanumeric() || matches!(char, '_' | '-' | '.'))
885 })
886}
887
888fn has_glob_syntax(value: &str) -> bool {
891 value.contains('*') || value.contains('?') || value.contains('[') || value.contains('{')
892}
893
894fn has_source_extension(value: &str) -> bool {
898 Path::new(value)
899 .extension()
900 .and_then(|ext| ext.to_str())
901 .is_some_and(|ext| {
902 crate::discover::SOURCE_EXTENSIONS.contains(&ext.to_ascii_lowercase().as_str())
903 })
904}
905
906#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
912pub struct PathRule {
913 pub pattern: String,
914 pub exclude_globs: Vec<String>,
915 pub exclude_regexes: Vec<String>,
916 pub exclude_segment_regexes: Vec<String>,
920 pub parent_relative: bool,
927}
928
929impl PathRule {
930 #[must_use]
931 pub(crate) fn new(pattern: impl Into<String>) -> Self {
932 Self {
933 pattern: pattern.into(),
934 exclude_globs: Vec::new(),
935 exclude_regexes: Vec::new(),
936 exclude_segment_regexes: Vec::new(),
937 parent_relative: false,
938 }
939 }
940
941 #[must_use]
942 fn from_static(pattern: &'static str) -> Self {
943 Self::new(pattern)
944 }
945
946 #[must_use]
950 fn from_extglob(pattern: &str) -> Self {
951 let rewritten = fallow_config::extglob::rewrite_include(pattern);
952 Self::new(rewritten.include).with_excluded_globs(rewritten.excludes)
953 }
954
955 #[must_use]
959 fn with_excluded_extglobs<I, S>(self, patterns: I) -> Self
960 where
961 I: IntoIterator<Item = S>,
962 S: AsRef<str>,
963 {
964 let excluded: Vec<String> = patterns
965 .into_iter()
966 .filter_map(|pattern| fallow_config::extglob::rewrite_exclude(pattern.as_ref()))
967 .collect();
968 self.with_excluded_globs(excluded)
969 }
970
971 #[must_use]
972 pub(crate) fn with_excluded_globs<I, S>(mut self, patterns: I) -> Self
973 where
974 I: IntoIterator<Item = S>,
975 S: Into<String>,
976 {
977 self.exclude_globs
978 .extend(patterns.into_iter().map(Into::into));
979 self
980 }
981
982 #[must_use]
983 fn with_excluded_regexes<I, S>(mut self, patterns: I) -> Self
984 where
985 I: IntoIterator<Item = S>,
986 S: Into<String>,
987 {
988 self.exclude_regexes
989 .extend(patterns.into_iter().map(Into::into));
990 self
991 }
992
993 #[must_use]
994 fn with_excluded_segment_regexes<I, S>(mut self, patterns: I) -> Self
995 where
996 I: IntoIterator<Item = S>,
997 S: Into<String>,
998 {
999 self.exclude_segment_regexes
1000 .extend(patterns.into_iter().map(Into::into));
1001 self
1002 }
1003
1004 #[must_use]
1005 fn prefixed(&self, ws_prefix: &str) -> Self {
1006 let prefix = |pattern: &str| {
1007 if self.parent_relative && pattern.starts_with("../") {
1008 resolve_parent_relative_pattern(pattern, ws_prefix)
1009 } else {
1010 prefix_workspace_pattern(pattern, ws_prefix)
1011 }
1012 };
1013 Self {
1014 pattern: prefix(&self.pattern),
1015 exclude_globs: self
1016 .exclude_globs
1017 .iter()
1018 .map(|pattern| prefix(pattern))
1019 .collect(),
1020 exclude_regexes: self
1021 .exclude_regexes
1022 .iter()
1023 .map(|pattern| prefix_workspace_regex(pattern, ws_prefix))
1024 .collect(),
1025 exclude_segment_regexes: self.exclude_segment_regexes.clone(),
1026 parent_relative: false,
1027 }
1028 }
1029}
1030
1031#[derive(Debug, Clone, Default, PartialEq, Eq)]
1033pub struct ProvidedDependencyRule {
1034 pub(crate) path: PathRule,
1035 exact_specifiers: Vec<String>,
1036 specifier_prefixes: Vec<String>,
1037}
1038
1039impl ProvidedDependencyRule {
1040 #[must_use]
1041 fn new(
1042 pattern: impl Into<String>,
1043 exact_specifiers: impl IntoIterator<Item = impl Into<String>>,
1044 specifier_prefixes: impl IntoIterator<Item = impl Into<String>>,
1045 ) -> Self {
1046 Self {
1047 path: PathRule::new(pattern),
1048 exact_specifiers: exact_specifiers.into_iter().map(Into::into).collect(),
1049 specifier_prefixes: specifier_prefixes.into_iter().map(Into::into).collect(),
1050 }
1051 }
1052
1053 #[must_use]
1054 fn prefixed(&self, ws_prefix: &str) -> Self {
1055 Self {
1056 path: self.path.prefixed(ws_prefix),
1057 exact_specifiers: self.exact_specifiers.clone(),
1058 specifier_prefixes: self.specifier_prefixes.clone(),
1059 }
1060 }
1061
1062 #[must_use]
1063 pub(crate) fn may_cover_package(&self, package_name: &str) -> bool {
1064 self.exact_specifiers
1065 .iter()
1066 .chain(self.specifier_prefixes.iter())
1067 .any(|specifier| crate::resolve::extract_package_name(specifier) == package_name)
1068 }
1069
1070 #[must_use]
1071 pub(crate) fn covers_specifier(&self, specifier: &str) -> bool {
1072 self.exact_specifiers
1073 .iter()
1074 .any(|allowed| allowed == specifier)
1075 || self
1076 .specifier_prefixes
1077 .iter()
1078 .any(|prefix| specifier.starts_with(prefix))
1079 }
1080}
1081
1082pub(crate) fn entry_rule_glob(pattern: &str) -> Result<globset::Glob, globset::Error> {
1086 globset::GlobBuilder::new(pattern)
1087 .literal_separator(true)
1088 .empty_alternates(true)
1089 .build()
1090}
1091
1092#[derive(Debug, Clone)]
1097pub(crate) struct CompiledPathRule {
1098 include: globset::GlobMatcher,
1099 exclude_globs: Vec<globset::GlobMatcher>,
1100 exclude_regexes: Vec<Regex>,
1101 exclude_segment_regexes: Vec<Regex>,
1102}
1103
1104impl CompiledPathRule {
1105 pub(crate) fn for_entry_rule(rule: &PathRule, rule_kind: &str) -> Option<Self> {
1106 let include = match entry_rule_glob(&rule.pattern) {
1107 Ok(glob) => glob.compile_matcher(),
1108 Err(err) => {
1109 tracing::warn!("invalid {rule_kind} '{}': {err}", rule.pattern);
1110 return None;
1111 }
1112 };
1113 Some(Self {
1114 include,
1115 exclude_globs: compile_excluded_globs(&rule.exclude_globs, rule_kind, &rule.pattern),
1116 exclude_regexes: compile_excluded_regexes(
1117 &rule.exclude_regexes,
1118 rule_kind,
1119 &rule.pattern,
1120 ),
1121 exclude_segment_regexes: compile_excluded_segment_regexes(
1122 &rule.exclude_segment_regexes,
1123 rule_kind,
1124 &rule.pattern,
1125 ),
1126 })
1127 }
1128
1129 pub(crate) fn for_used_export_rule(rule: &PathRule, rule_kind: &str) -> Option<Self> {
1130 Self::for_entry_rule(rule, rule_kind)
1131 }
1132
1133 #[must_use]
1134 pub(crate) fn matches(&self, path: &str) -> bool {
1135 self.include.is_match(path)
1136 && !self.exclude_globs.iter().any(|glob| glob.is_match(path))
1137 && !self
1138 .exclude_regexes
1139 .iter()
1140 .any(|regex| regex.is_match(path))
1141 && !matches_segment_regex(path, &self.exclude_segment_regexes)
1142 }
1143}
1144
1145fn prefix_workspace_pattern(pattern: &str, ws_prefix: &str) -> String {
1146 if pattern.starts_with(ws_prefix) || pattern.starts_with('/') {
1147 pattern.to_string()
1148 } else {
1149 format!("{ws_prefix}/{pattern}")
1150 }
1151}
1152
1153fn resolve_parent_relative_pattern(pattern: &str, ws_prefix: &str) -> String {
1159 if ws_prefix.starts_with('/') || Path::new(ws_prefix).is_absolute() {
1160 return pattern.to_string();
1161 }
1162 let mut base: Vec<&str> = ws_prefix
1165 .split(['/', '\\'])
1166 .filter(|segment| !segment.is_empty())
1167 .collect();
1168 let mut rest = pattern;
1169 while let Some(stripped) = rest.strip_prefix("../") {
1170 if base.pop().is_none() {
1171 return pattern.to_string();
1172 }
1173 rest = stripped;
1174 }
1175 if base.is_empty() {
1176 rest.to_string()
1177 } else {
1178 format!("{}/{rest}", base.join("/"))
1179 }
1180}
1181
1182fn prefix_workspace_regex(pattern: &str, ws_prefix: &str) -> String {
1183 if let Some(pattern) = pattern.strip_prefix('^') {
1184 format!("^{}/{}", regex::escape(ws_prefix), pattern)
1185 } else {
1186 format!("^{}/(?:{})", regex::escape(ws_prefix), pattern)
1187 }
1188}
1189
1190fn compile_excluded_globs(
1191 patterns: &[String],
1192 rule_kind: &str,
1193 rule_pattern: &str,
1194) -> Vec<globset::GlobMatcher> {
1195 patterns
1196 .iter()
1197 .filter_map(|pattern| {
1198 match globset::GlobBuilder::new(pattern)
1199 .literal_separator(true)
1200 .empty_alternates(true)
1201 .build()
1202 {
1203 Ok(glob) => Some(glob.compile_matcher()),
1204 Err(err) => {
1205 tracing::warn!(
1206 "skipping invalid excluded glob '{}' for {} '{}': {err}",
1207 pattern,
1208 rule_kind,
1209 rule_pattern
1210 );
1211 None
1212 }
1213 }
1214 })
1215 .collect()
1216}
1217
1218fn compile_excluded_regexes(
1219 patterns: &[String],
1220 rule_kind: &str,
1221 rule_pattern: &str,
1222) -> Vec<Regex> {
1223 patterns
1224 .iter()
1225 .filter_map(|pattern| match Regex::new(pattern) {
1226 Ok(regex) => Some(regex),
1227 Err(err) => {
1228 tracing::warn!(
1229 "skipping invalid excluded regex '{}' for {} '{}': {err}",
1230 pattern,
1231 rule_kind,
1232 rule_pattern
1233 );
1234 None
1235 }
1236 })
1237 .collect()
1238}
1239
1240fn compile_excluded_segment_regexes(
1241 patterns: &[String],
1242 rule_kind: &str,
1243 rule_pattern: &str,
1244) -> Vec<Regex> {
1245 patterns
1246 .iter()
1247 .filter_map(|pattern| match Regex::new(pattern) {
1248 Ok(regex) => Some(regex),
1249 Err(err) => {
1250 tracing::warn!(
1251 "skipping invalid excluded segment regex '{}' for {} '{}': {err}",
1252 pattern,
1253 rule_kind,
1254 rule_pattern
1255 );
1256 None
1257 }
1258 })
1259 .collect()
1260}
1261
1262fn matches_segment_regex(path: &str, regexes: &[Regex]) -> bool {
1265 path.split(std::path::is_separator)
1266 .any(|segment| regexes.iter().any(|regex| regex.is_match(segment)))
1267}
1268
1269impl From<String> for PathRule {
1270 fn from(pattern: String) -> Self {
1271 Self::new(pattern)
1272 }
1273}
1274
1275impl From<&str> for PathRule {
1276 fn from(pattern: &str) -> Self {
1277 Self::new(pattern)
1278 }
1279}
1280
1281impl std::ops::Deref for PathRule {
1282 type Target = str;
1283
1284 fn deref(&self) -> &Self::Target {
1285 &self.pattern
1286 }
1287}
1288
1289impl PartialEq<&str> for PathRule {
1290 fn eq(&self, other: &&str) -> bool {
1291 self.pattern == *other
1292 }
1293}
1294
1295impl PartialEq<str> for PathRule {
1296 fn eq(&self, other: &str) -> bool {
1297 self.pattern == other
1298 }
1299}
1300
1301impl PartialEq<String> for PathRule {
1302 fn eq(&self, other: &String) -> bool {
1303 &self.pattern == other
1304 }
1305}
1306
1307pub trait Plugin: Send + Sync {
1309 fn name(&self) -> &'static str;
1311
1312 fn enablers(&self) -> &'static [&'static str] {
1315 &[]
1316 }
1317
1318 fn is_enabled(&self, pkg: &PackageJson, root: &Path) -> bool {
1320 let deps = pkg.all_dependency_names();
1321 self.is_enabled_with_deps(&deps, root)
1322 }
1323
1324 fn is_enabled_with_deps(&self, deps: &[String], _root: &Path) -> bool {
1327 let enablers = self.enablers();
1328 if enablers.is_empty() {
1329 return false;
1330 }
1331 enablers.iter().any(|enabler| {
1332 if enabler.ends_with('/') {
1333 deps.iter().any(|d| d.starts_with(enabler))
1335 } else {
1336 deps.iter().any(|d| d == enabler)
1337 }
1338 })
1339 }
1340
1341 fn is_enabled_with_files(
1354 &self,
1355 deps: &[String],
1356 root: &Path,
1357 _discovered_files: &[PathBuf],
1358 _candidate_index: Option<®istry::ConfigCandidateIndex>,
1359 ) -> bool {
1360 self.is_enabled_with_deps(deps, root)
1361 }
1362
1363 fn script_enablers(&self) -> &'static [&'static str] {
1365 &[]
1366 }
1367
1368 fn is_enabled_with_scripts(
1370 &self,
1371 script_packages: &rustc_hash::FxHashSet<String>,
1372 _root: &Path,
1373 ) -> bool {
1374 let enablers = self.script_enablers();
1375 if enablers.is_empty() {
1376 return false;
1377 }
1378 enablers.iter().any(|enabler| {
1379 if enabler.ends_with('/') {
1380 script_packages
1381 .iter()
1382 .any(|package| package.starts_with(enabler))
1383 } else {
1384 script_packages.contains(*enabler)
1385 }
1386 })
1387 }
1388
1389 fn entry_patterns(&self) -> &'static [&'static str] {
1391 &[]
1392 }
1393
1394 fn entry_pattern_rules(&self) -> Vec<PathRule> {
1396 self.entry_patterns()
1397 .iter()
1398 .map(|pattern| PathRule::from_static(pattern))
1399 .collect()
1400 }
1401
1402 fn entry_point_role(&self) -> EntryPointRole {
1407 builtin_entry_point_role(self.name())
1408 }
1409
1410 fn config_patterns(&self) -> &'static [&'static str] {
1412 &[]
1413 }
1414
1415 fn config_default_export_opt_out(&self) -> &'static [&'static str] {
1424 &[]
1425 }
1426
1427 fn config_file_exports(&self) -> &'static [(&'static str, &'static [&'static str])] {
1436 &[]
1437 }
1438
1439 fn always_used(&self) -> &'static [&'static str] {
1441 &[]
1442 }
1443
1444 fn used_exports(&self) -> Vec<(&'static str, &'static [&'static str])> {
1446 vec![]
1447 }
1448
1449 fn used_export_rules(&self) -> Vec<UsedExportRule> {
1451 self.used_exports()
1452 .into_iter()
1453 .map(|(pattern, exports)| UsedExportRule::from_static(pattern, exports))
1454 .collect()
1455 }
1456
1457 fn used_class_members(&self) -> &'static [&'static str] {
1462 &[]
1463 }
1464
1465 fn used_class_member_rules(&self) -> Vec<UsedClassMemberRule> {
1473 Vec::new()
1474 }
1475
1476 fn framework_class_member_contracts(&self) -> Vec<SemanticFrameworkContract> {
1479 Vec::new()
1480 }
1481
1482 fn fixture_glob_patterns(&self) -> &'static [&'static str] {
1487 &[]
1488 }
1489
1490 fn discovery_hidden_dirs(&self) -> &'static [&'static str] {
1495 &[]
1496 }
1497
1498 fn tooling_dependencies(&self) -> &'static [&'static str] {
1501 &[]
1502 }
1503
1504 fn virtual_module_prefixes(&self) -> &'static [&'static str] {
1509 &[]
1510 }
1511
1512 fn virtual_package_suffixes(&self) -> &'static [&'static str] {
1518 &[]
1519 }
1520
1521 fn generated_import_patterns(&self) -> &'static [&'static str] {
1527 &[]
1528 }
1529
1530 fn generated_type_import_prefixes(&self) -> &'static [&'static str] {
1535 &[]
1536 }
1537
1538 fn path_aliases(&self, _root: &Path) -> Vec<(&'static str, String)> {
1548 vec![]
1549 }
1550
1551 fn static_dir_mappings(&self, _root: &Path) -> Vec<(std::path::PathBuf, String)> {
1563 vec![]
1564 }
1565
1566 fn auto_imports(&self, _root: &Path) -> Vec<AutoImportRule> {
1584 Vec::new()
1585 }
1586
1587 fn provided_dependencies(&self) -> Vec<ProvidedDependencyRule> {
1589 Vec::new()
1590 }
1591
1592 fn is_enabled_with_package_json(&self, _pkg: &PackageJson, _root: &Path) -> bool {
1594 false
1595 }
1596
1597 fn resolve_package_json(&self, _pkg: &PackageJson, _root: &Path) -> PluginResult {
1599 PluginResult::default()
1600 }
1601
1602 fn package_json_referenced_dependencies(
1607 &self,
1608 _pkg: &PackageJson,
1609 _root: &Path,
1610 ) -> Vec<String> {
1611 Vec::new()
1612 }
1613
1614 fn resolve_config(&self, _config_path: &Path, _source: &str, _root: &Path) -> PluginResult {
1619 PluginResult::default()
1620 }
1621
1622 fn resolve_config_in_project(
1631 &self,
1632 config_path: &Path,
1633 source: &str,
1634 root: &Path,
1635 _project_root: &Path,
1636 ) -> PluginResult {
1637 self.resolve_config(config_path, source, root)
1638 }
1639
1640 fn resolve_script_config(
1644 &self,
1645 config_path: &Path,
1646 source: &str,
1647 root: &Path,
1648 project_root: &Path,
1649 ) -> PluginResult {
1650 self.resolve_config_in_project(config_path, source, root, project_root)
1651 }
1652
1653 fn script_config_binaries(&self) -> &'static [&'static str] {
1661 &[]
1662 }
1663
1664 fn package_json_config_key(&self) -> Option<&'static str> {
1669 None
1670 }
1671}
1672
1673fn builtin_entry_point_role(name: &str) -> EntryPointRole {
1674 if TEST_ENTRY_POINT_PLUGINS.contains(&name) {
1675 EntryPointRole::Test
1676 } else if RUNTIME_ENTRY_POINT_PLUGINS.contains(&name) {
1677 EntryPointRole::Runtime
1678 } else {
1679 EntryPointRole::Support
1680 }
1681}
1682
1683macro_rules! define_plugin {
1744 (
1745 struct $name:ident => $display:expr,
1746 enablers: $enablers:expr
1747 $(, entry_patterns: $entry:expr)?
1748 $(, config_patterns: $config:expr)?
1749 $(, config_default_export_opt_out: $config_opt_out:expr)?
1750 $(, config_file_exports: $config_exports:expr)?
1751 $(, always_used: $always:expr)?
1752 $(, tooling_dependencies: $tooling:expr)?
1753 $(, fixture_glob_patterns: $fixtures:expr)?
1754 $(, discovery_hidden_dirs: $hidden_dirs:expr)?
1755 $(, virtual_module_prefixes: $virtual:expr)?
1756 $(, virtual_package_suffixes: $virtual_suffixes:expr)?
1757 $(, generated_type_import_prefixes: $generated_type_prefixes:expr)?
1758 $(, provided_dependencies: $provided_dependencies:expr)?
1759 $(, used_exports: [$( ($pat:expr, $exports:expr) ),* $(,)?])?
1760 , resolve_config: imports_only
1761 $(,)?
1762 ) => {
1763 pub struct $name;
1764
1765 impl Plugin for $name {
1766 fn name(&self) -> &'static str {
1767 $display
1768 }
1769
1770 fn enablers(&self) -> &'static [&'static str] {
1771 $enablers
1772 }
1773
1774 $( fn entry_patterns(&self) -> &'static [&'static str] { $entry } )?
1775 $( fn config_patterns(&self) -> &'static [&'static str] { $config } )?
1776 $( fn config_default_export_opt_out(&self) -> &'static [&'static str] { $config_opt_out } )?
1777 $( fn config_file_exports(&self) -> &'static [(&'static str, &'static [&'static str])] { $config_exports } )?
1778 $( fn always_used(&self) -> &'static [&'static str] { $always } )?
1779 $( fn tooling_dependencies(&self) -> &'static [&'static str] { $tooling } )?
1780 $( fn fixture_glob_patterns(&self) -> &'static [&'static str] { $fixtures } )?
1781 $( fn discovery_hidden_dirs(&self) -> &'static [&'static str] { $hidden_dirs } )?
1782 $( fn virtual_module_prefixes(&self) -> &'static [&'static str] { $virtual } )?
1783 $( fn virtual_package_suffixes(&self) -> &'static [&'static str] { $virtual_suffixes } )?
1784 $( fn generated_type_import_prefixes(&self) -> &'static [&'static str] { $generated_type_prefixes } )?
1785 $( fn provided_dependencies(&self) -> Vec<ProvidedDependencyRule> { $provided_dependencies } )?
1786
1787 $(
1788 fn used_exports(&self) -> Vec<(&'static str, &'static [&'static str])> {
1789 vec![$( ($pat, $exports) ),*]
1790 }
1791 )?
1792
1793 fn resolve_config(
1794 &self,
1795 config_path: &std::path::Path,
1796 source: &str,
1797 _root: &std::path::Path,
1798 ) -> PluginResult {
1799 let mut result = PluginResult::default();
1800 crate::plugins::add_import_referenced_dependencies(
1801 &mut result,
1802 source,
1803 config_path,
1804 );
1805 result
1806 }
1807 }
1808 };
1809
1810 (
1811 struct $name:ident => $display:expr,
1812 enablers: $enablers:expr
1813 $(, entry_patterns: $entry:expr)?
1814 $(, config_patterns: $config:expr)?
1815 $(, config_default_export_opt_out: $config_opt_out:expr)?
1816 $(, config_file_exports: $config_exports:expr)?
1817 $(, always_used: $always:expr)?
1818 $(, tooling_dependencies: $tooling:expr)?
1819 $(, fixture_glob_patterns: $fixtures:expr)?
1820 $(, discovery_hidden_dirs: $hidden_dirs:expr)?
1821 $(, virtual_module_prefixes: $virtual:expr)?
1822 $(, virtual_package_suffixes: $virtual_suffixes:expr)?
1823 $(, generated_type_import_prefixes: $generated_type_prefixes:expr)?
1824 $(, provided_dependencies: $provided_dependencies:expr)?
1825 $(, package_json_config_key: $pkg_key:expr)?
1826 $(, script_config_binaries: $script_binaries:expr)?
1827 $(, used_exports: [$( ($pat:expr, $exports:expr) ),* $(,)?])?
1828 , resolve_config($cp:ident, $src:ident, $root:ident) $body:block
1829 $(, resolve_config_in_project($pcp:ident, $psrc:ident, $proot:ident, $pproj:ident) $pbody:block)?
1830 $(,)?
1831 ) => {
1832 pub struct $name;
1833
1834 impl Plugin for $name {
1835 fn name(&self) -> &'static str {
1836 $display
1837 }
1838
1839 fn enablers(&self) -> &'static [&'static str] {
1840 $enablers
1841 }
1842
1843 $( fn entry_patterns(&self) -> &'static [&'static str] { $entry } )?
1844 $( fn config_patterns(&self) -> &'static [&'static str] { $config } )?
1845 $( fn config_default_export_opt_out(&self) -> &'static [&'static str] { $config_opt_out } )?
1846 $( fn config_file_exports(&self) -> &'static [(&'static str, &'static [&'static str])] { $config_exports } )?
1847 $( fn always_used(&self) -> &'static [&'static str] { $always } )?
1848 $( fn tooling_dependencies(&self) -> &'static [&'static str] { $tooling } )?
1849 $( fn fixture_glob_patterns(&self) -> &'static [&'static str] { $fixtures } )?
1850 $( fn discovery_hidden_dirs(&self) -> &'static [&'static str] { $hidden_dirs } )?
1851 $( fn virtual_module_prefixes(&self) -> &'static [&'static str] { $virtual } )?
1852 $( fn virtual_package_suffixes(&self) -> &'static [&'static str] { $virtual_suffixes } )?
1853 $( fn generated_type_import_prefixes(&self) -> &'static [&'static str] { $generated_type_prefixes } )?
1854 $( fn provided_dependencies(&self) -> Vec<ProvidedDependencyRule> { $provided_dependencies } )?
1855
1856 $(
1857 fn package_json_config_key(&self) -> Option<&'static str> {
1858 Some($pkg_key)
1859 }
1860 )?
1861
1862 $(
1863 fn used_exports(&self) -> Vec<(&'static str, &'static [&'static str])> {
1864 vec![$( ($pat, $exports) ),*]
1865 }
1866 )?
1867
1868 $( fn script_config_binaries(&self) -> &'static [&'static str] { $script_binaries } )?
1869
1870 fn resolve_config(
1871 &self,
1872 $cp: &std::path::Path,
1873 $src: &str,
1874 $root: &std::path::Path,
1875 ) -> PluginResult
1876 $body
1877
1878 $(
1879 fn resolve_config_in_project(
1880 &self,
1881 $pcp: &std::path::Path,
1882 $psrc: &str,
1883 $proot: &std::path::Path,
1884 $pproj: &std::path::Path,
1885 ) -> PluginResult
1886 $pbody
1887 )?
1888 }
1889 };
1890
1891 (
1892 struct $name:ident => $display:expr,
1893 enablers: $enablers:expr
1894 $(, entry_patterns: $entry:expr)?
1895 $(, config_patterns: $config:expr)?
1896 $(, config_default_export_opt_out: $config_opt_out:expr)?
1897 $(, config_file_exports: $config_exports:expr)?
1898 $(, always_used: $always:expr)?
1899 $(, tooling_dependencies: $tooling:expr)?
1900 $(, fixture_glob_patterns: $fixtures:expr)?
1901 $(, discovery_hidden_dirs: $hidden_dirs:expr)?
1902 $(, virtual_module_prefixes: $virtual:expr)?
1903 $(, virtual_package_suffixes: $virtual_suffixes:expr)?
1904 $(, generated_type_import_prefixes: $generated_type_prefixes:expr)?
1905 $(, provided_dependencies: $provided_dependencies:expr)?
1906 $(, package_json_config_key: $pkg_key:expr)?
1907 $(, used_exports: [$( ($pat:expr, $exports:expr) ),* $(,)?])?
1908 $(,)?
1909 ) => {
1910 pub struct $name;
1911
1912 impl Plugin for $name {
1913 fn name(&self) -> &'static str {
1914 $display
1915 }
1916
1917 fn enablers(&self) -> &'static [&'static str] {
1918 $enablers
1919 }
1920
1921 $( fn entry_patterns(&self) -> &'static [&'static str] { $entry } )?
1922 $( fn config_patterns(&self) -> &'static [&'static str] { $config } )?
1923 $( fn config_default_export_opt_out(&self) -> &'static [&'static str] { $config_opt_out } )?
1924 $( fn config_file_exports(&self) -> &'static [(&'static str, &'static [&'static str])] { $config_exports } )?
1925 $( fn always_used(&self) -> &'static [&'static str] { $always } )?
1926 $( fn tooling_dependencies(&self) -> &'static [&'static str] { $tooling } )?
1927 $( fn fixture_glob_patterns(&self) -> &'static [&'static str] { $fixtures } )?
1928 $( fn discovery_hidden_dirs(&self) -> &'static [&'static str] { $hidden_dirs } )?
1929 $( fn virtual_module_prefixes(&self) -> &'static [&'static str] { $virtual } )?
1930 $( fn virtual_package_suffixes(&self) -> &'static [&'static str] { $virtual_suffixes } )?
1931 $( fn generated_type_import_prefixes(&self) -> &'static [&'static str] { $generated_type_prefixes } )?
1932 $( fn provided_dependencies(&self) -> Vec<ProvidedDependencyRule> { $provided_dependencies } )?
1933
1934 $(
1935 fn package_json_config_key(&self) -> Option<&'static str> {
1936 Some($pkg_key)
1937 }
1938 )?
1939
1940 $(
1941 fn used_exports(&self) -> Vec<(&'static str, &'static [&'static str])> {
1942 vec![$( ($pat, $exports) ),*]
1943 }
1944 )?
1945 }
1946 };
1947}
1948
1949mod config_dependencies;
1950pub mod config_parser;
1951mod config_value_credits;
1952mod flue;
1953mod jasmine;
1954mod manifest;
1955pub mod manifest_entries;
1956mod mise;
1957mod osls;
1958mod project_glob;
1959mod railway;
1960pub mod registry;
1961mod rstest;
1962mod serverless_framework;
1963mod textlint;
1964mod tooling;
1965mod trace_provenance;
1966mod used_export_names;
1967mod used_export_rule;
1968
1969pub use config_dependencies::RequiredDependency;
1970use config_dependencies::add_import_referenced_dependencies;
1971pub(crate) use module_federation::runtime_remotes;
1972pub use registry::{
1973 AggregatedPluginResult, PluginRegistry, PluginToolingDependencies, PluginToolingEvidence,
1974};
1975pub use tooling::types_package_target;
1976pub(crate) use tooling::{
1977 cli_tooling_config_patterns, is_ambient_types_package, is_known_tooling_dependency,
1978};
1979pub use trace_provenance::{ExportCredits, build_trace_provenance};
1980pub use used_export_names::UsedExportNames;
1981pub(crate) use used_export_rule::{ConfigExportCredit, is_export_ignored};
1982pub use used_export_rule::{PluginUsedExportRule, UsedExportRule};
1983
1984fn credit_environment_optional_peers(environment: &str, result: &mut PluginResult) {
1996 credit_config_value(
1997 config_value_credits::CreditSurface::TestEnvironmentOptionalPeer,
1998 canonical_test_environment(environment),
1999 result,
2000 );
2001}
2002
2003fn credit_config_value(
2008 surface: config_value_credits::CreditSurface,
2009 value: &str,
2010 result: &mut PluginResult,
2011) -> bool {
2012 let Some(packages) = config_value_credits::credited_packages(surface, value) else {
2013 return false;
2014 };
2015 result
2016 .referenced_dependencies
2017 .extend(packages.iter().cloned());
2018 true
2019}
2020
2021fn canonical_test_environment(environment: &str) -> &str {
2028 environment
2029 .strip_prefix("jest-environment-")
2030 .or_else(|| environment.strip_prefix("vitest-environment-"))
2031 .unwrap_or(environment)
2032}
2033
2034mod adonis;
2035mod ag_ui;
2036mod alchemy;
2037mod alias_replacement;
2038mod angular;
2039mod astro;
2040mod ava;
2041mod babel;
2042mod biome;
2043mod browser_extension;
2044mod bun;
2045mod c8;
2046mod capacitor;
2047mod changesets;
2048mod commit_and_tag_version;
2049mod commitizen;
2050mod commitlint;
2051mod content_collections;
2052mod contentlayer;
2053mod convex;
2054mod cspell;
2055mod cucumber;
2056mod cypress;
2057mod danger;
2058mod deno;
2059mod dependency_cruiser;
2060mod docusaurus;
2061mod dotenv;
2062mod drizzle;
2063mod egg;
2064mod electron;
2065mod ember;
2066mod eslint;
2067mod eve;
2068mod expo;
2069mod expo_router;
2070mod firebase;
2071mod fumadocs;
2072mod gatsby;
2073mod github_action;
2074mod graphql_codegen;
2075mod graphql_config;
2076mod hardhat;
2077mod husky;
2078mod i18next;
2079mod ionic;
2080mod jest;
2081mod k6;
2082mod karma;
2083mod kibana;
2084mod knex;
2085mod kysely;
2086mod lefthook;
2087mod lexical;
2088mod lint_staged;
2089mod lit;
2090mod markdownlint;
2091mod mintlify;
2092mod mocha;
2093mod module_federation;
2094mod msw;
2095mod napi_rs;
2096mod nest_commander;
2097mod nestjs;
2098mod nestjs_trpc;
2099mod next_intl;
2100mod nextjs;
2101mod nitro;
2102mod nodemon;
2103pub(crate) mod nuxt;
2104mod nx;
2105mod nyc;
2106mod obsidian;
2107mod openapi_ts;
2108mod opencode;
2109mod opennext_cloudflare;
2110mod opentelemetry;
2111mod oxfmt;
2112mod oxlint;
2113mod pandacss;
2114mod parcel;
2115mod pinia;
2116mod pkg_utils;
2117mod playwright;
2118mod plop;
2119mod pm2;
2120mod pnpm;
2121mod postcss;
2122mod prettier;
2123mod prisma;
2124mod qwik;
2125mod react_compiler;
2126mod react_native;
2127mod react_router;
2128mod redwoodsdk;
2129mod relay;
2130mod release_it;
2131mod remark;
2132mod remix;
2133mod rolldown;
2134mod rollup;
2135mod rsbuild;
2136mod rspack;
2137mod rspress;
2138mod sanity;
2139mod semantic_release;
2140mod sentry;
2141mod simple_git_hooks;
2142mod size_limit;
2143mod storybook;
2144mod stryker;
2145mod stylelint;
2146mod supabase;
2147mod sveltekit;
2148mod svgo;
2149mod svgr;
2150mod swc;
2151mod syncpack;
2152mod tailwind;
2153mod tanstack_router;
2154mod tap;
2155mod test_alias;
2156#[cfg(test)]
2157mod tests;
2158mod tsd;
2159mod tsdown;
2160mod tsup;
2161mod turborepo;
2162mod typedoc;
2163mod typeorm;
2164mod typescript;
2165mod typescript_content_mapper;
2166mod unocss;
2167mod varlock;
2168mod velite;
2169mod vercel;
2170mod vite;
2171pub(crate) mod vite_plus;
2172mod vitepress;
2173mod vitest;
2174mod vscode;
2175mod waku;
2176mod webdriverio;
2177mod webpack;
2178mod wrangler;
2179mod wuchale;
2180mod wxt;