use std::path::Path;
use std::sync::Arc;
use skif_config::Config;
use skif_core::FileSystem;
use skif_js::{DependencyTrace, InputSource, JsAnalysis, JsProvider, PluginSource, UsageReport};
use skif_workspace::Workspace;
pub(crate) fn provider(config: &Config, fs: Arc<dyn FileSystem>) -> JsProvider {
JsProvider::new(fs).with_input_source(Arc::new(
PluginSource::new(config.js.plugins.clone())
.with_workspaces(&config.js.workspaces)
.with_root_tsconfig(config.js.tsconfig.as_deref())
.with_overrides(&config.overrides),
))
}
#[must_use]
pub fn explain_usage(
config: &Config,
fs: &Arc<dyn FileSystem>,
workspace: &Workspace,
file: &Path,
export: Option<&str>,
) -> UsageReport {
let source: Arc<dyn InputSource> = Arc::new(
PluginSource::new(config.js.plugins.clone())
.with_workspaces(&config.js.workspaces)
.with_root_tsconfig(config.js.tsconfig.as_deref())
.with_overrides(&config.overrides),
);
JsAnalysis::build(workspace, config, fs, &[source], false).explain_usage(file, export)
}
#[must_use]
pub fn trace_dependency(
config: &Config,
fs: &Arc<dyn FileSystem>,
workspace: &Workspace,
name: &str,
) -> DependencyTrace {
let source: Arc<dyn InputSource> = Arc::new(
PluginSource::new(config.js.plugins.clone())
.with_workspaces(&config.js.workspaces)
.with_root_tsconfig(config.js.tsconfig.as_deref())
.with_overrides(&config.overrides),
);
JsAnalysis::build(workspace, config, fs, &[source], false).trace_dependency(name)
}