1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

refactor: update to deno_config 0.25 (#24645)

- Gets rid of WorkspaceMemberContext. It's now `Workspace` and
`WorkspaceDirectory`
- Uses the workspace cache in the lsp

* https://github.com/denoland/deno_config/pull/95
* https://github.com/denoland/deno_config/pull/96
This commit is contained in:
David Sherret 2024-07-19 15:56:07 -04:00 committed by GitHub
parent a4c76add56
commit afcae364be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 360 additions and 332 deletions

4
Cargo.lock generated
View file

@ -1312,9 +1312,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_config" name = "deno_config"
version = "0.24.0" version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6b72d6f849f5640ed80dc458b529aec74a79bdabdebe291448d345f865faa99" checksum = "64e7a65603a3aa52216021a0abd401770ac6ed284e5b885dadf40ce35b2a0d9e"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"deno_semver", "deno_semver",

View file

@ -101,7 +101,7 @@ console_static_text = "=0.8.1"
data-encoding = "2.3.3" data-encoding = "2.3.3"
data-url = "=0.3.0" data-url = "=0.3.0"
deno_cache_dir = "=0.10.0" deno_cache_dir = "=0.10.0"
deno_config = { version = "=0.24.0", default-features = false } deno_config = { version = "=0.25.0", default-features = false }
dlopen2 = "0.6.1" dlopen2 = "0.6.1"
ecb = "=0.1.2" ecb = "=0.1.2"
elliptic-curve = { version = "0.13.4", features = ["alloc", "arithmetic", "ecdh", "std", "pem"] } elliptic-curve = { version = "0.13.4", features = ["alloc", "arithmetic", "ecdh", "std", "pem"] }

View file

@ -8,7 +8,7 @@ use deno_semver::jsr::JsrPackageReqReference;
use deno_semver::npm::NpmPackageReqReference; use deno_semver::npm::NpmPackageReqReference;
pub fn deno_json_deps( pub fn deno_json_deps(
config: &deno_config::ConfigFile, config: &deno_config::deno_json::ConfigFile,
) -> HashSet<JsrDepPackageReq> { ) -> HashSet<JsrDepPackageReq> {
let values = imports_values(config.json.imports.as_ref()) let values = imports_values(config.json.imports.as_ref())
.into_iter() .into_iter()

View file

@ -11,7 +11,6 @@ use clap::Command;
use clap::ValueHint; use clap::ValueHint;
use deno_config::glob::FilePatterns; use deno_config::glob::FilePatterns;
use deno_config::glob::PathOrPatternSet; use deno_config::glob::PathOrPatternSet;
use deno_config::ConfigFlag;
use deno_core::anyhow::bail; use deno_core::anyhow::bail;
use deno_core::anyhow::Context; use deno_core::anyhow::Context;
use deno_core::error::AnyError; use deno_core::error::AnyError;
@ -42,6 +41,14 @@ use crate::util::fs::canonicalize_path;
use super::flags_net; use super::flags_net;
use super::DENO_FUTURE; use super::DENO_FUTURE;
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub enum ConfigFlag {
#[default]
Discover,
Path(String),
Disabled,
}
#[derive(Clone, Debug, Default, Eq, PartialEq)] #[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct FileFlags { pub struct FileFlags {
pub ignore: Vec<String>, pub ignore: Vec<String>,

View file

@ -12,12 +12,12 @@ use deno_config::workspace::CreateResolverOptions;
use deno_config::workspace::PackageJsonDepResolution; use deno_config::workspace::PackageJsonDepResolution;
use deno_config::workspace::VendorEnablement; use deno_config::workspace::VendorEnablement;
use deno_config::workspace::Workspace; use deno_config::workspace::Workspace;
use deno_config::workspace::WorkspaceDirectory;
use deno_config::workspace::WorkspaceDirectoryEmptyOptions;
use deno_config::workspace::WorkspaceDiscoverOptions; use deno_config::workspace::WorkspaceDiscoverOptions;
use deno_config::workspace::WorkspaceDiscoverStart; use deno_config::workspace::WorkspaceDiscoverStart;
use deno_config::workspace::WorkspaceEmptyOptions; use deno_config::workspace::WorkspaceLintConfig;
use deno_config::workspace::WorkspaceMemberContext;
use deno_config::workspace::WorkspaceResolver; use deno_config::workspace::WorkspaceResolver;
use deno_config::WorkspaceLintConfig;
use deno_core::normalize_path; use deno_core::normalize_path;
use deno_core::resolve_url_or_path; use deno_core::resolve_url_or_path;
use deno_graph::GraphKind; use deno_graph::GraphKind;
@ -32,17 +32,17 @@ use deno_runtime::deno_tls::RootCertStoreProvider;
use deno_semver::npm::NpmPackageReqReference; use deno_semver::npm::NpmPackageReqReference;
use import_map::resolve_import_map_value_from_specifier; use import_map::resolve_import_map_value_from_specifier;
pub use deno_config::deno_json::BenchConfig;
pub use deno_config::deno_json::ConfigFile;
pub use deno_config::deno_json::FmtOptionsConfig;
pub use deno_config::deno_json::JsxImportSourceConfig;
pub use deno_config::deno_json::LintRulesConfig;
pub use deno_config::deno_json::ProseWrap;
pub use deno_config::deno_json::TsConfig;
pub use deno_config::deno_json::TsConfigForEmit;
pub use deno_config::deno_json::TsConfigType;
pub use deno_config::deno_json::TsTypeLib;
pub use deno_config::glob::FilePatterns; pub use deno_config::glob::FilePatterns;
pub use deno_config::BenchConfig;
pub use deno_config::ConfigFile;
pub use deno_config::FmtOptionsConfig;
pub use deno_config::JsxImportSourceConfig;
pub use deno_config::LintRulesConfig;
pub use deno_config::ProseWrap;
pub use deno_config::TsConfig;
pub use deno_config::TsConfigForEmit;
pub use deno_config::TsConfigType;
pub use deno_config::TsTypeLib;
pub use flags::*; pub use flags::*;
pub use lockfile::CliLockfile; pub use lockfile::CliLockfile;
pub use package_json::PackageJsonInstallDepsProvider; pub use package_json::PackageJsonInstallDepsProvider;
@ -83,9 +83,9 @@ use crate::file_fetcher::FileFetcher;
use crate::util::fs::canonicalize_path_maybe_not_exists; use crate::util::fs::canonicalize_path_maybe_not_exists;
use crate::version; use crate::version;
use deno_config::FmtConfig; use deno_config::deno_json::FmtConfig;
use deno_config::LintConfig; use deno_config::deno_json::LintConfig;
use deno_config::TestConfig; use deno_config::deno_json::TestConfig;
pub fn npm_registry_url() -> &'static Url { pub fn npm_registry_url() -> &'static Url {
static NPM_REGISTRY_DEFAULT_URL: Lazy<Url> = Lazy::new(|| { static NPM_REGISTRY_DEFAULT_URL: Lazy<Url> = Lazy::new(|| {
@ -159,9 +159,9 @@ pub fn jsr_api_url() -> &'static Url {
} }
pub fn ts_config_to_transpile_and_emit_options( pub fn ts_config_to_transpile_and_emit_options(
config: deno_config::TsConfig, config: deno_config::deno_json::TsConfig,
) -> Result<(deno_ast::TranspileOptions, deno_ast::EmitOptions), AnyError> { ) -> Result<(deno_ast::TranspileOptions, deno_ast::EmitOptions), AnyError> {
let options: deno_config::EmitConfigOptions = let options: deno_config::deno_json::EmitConfigOptions =
serde_json::from_value(config.0) serde_json::from_value(config.0)
.context("Failed to parse compilerOptions")?; .context("Failed to parse compilerOptions")?;
let imports_not_used_as_values = let imports_not_used_as_values =
@ -503,7 +503,7 @@ fn resolve_lint_rules_options(
pub fn discover_npmrc_from_workspace( pub fn discover_npmrc_from_workspace(
workspace: &Workspace, workspace: &Workspace,
) -> Result<(Arc<ResolvedNpmRc>, Option<PathBuf>), AnyError> { ) -> Result<(Arc<ResolvedNpmRc>, Option<PathBuf>), AnyError> {
let root_folder = workspace.root_folder().1; let root_folder = workspace.root_folder_configs();
discover_npmrc( discover_npmrc(
root_folder.pkg_json.as_ref().map(|p| p.path.clone()), root_folder.pkg_json.as_ref().map(|p| p.path.clone()),
root_folder.deno_json.as_ref().and_then(|cf| { root_folder.deno_json.as_ref().and_then(|cf| {
@ -769,7 +769,7 @@ pub struct CliOptions {
npmrc: Arc<ResolvedNpmRc>, npmrc: Arc<ResolvedNpmRc>,
maybe_lockfile: Option<Arc<CliLockfile>>, maybe_lockfile: Option<Arc<CliLockfile>>,
overrides: CliOptionOverrides, overrides: CliOptionOverrides,
pub workspace: Arc<Workspace>, pub start_dir: Arc<WorkspaceDirectory>,
pub disable_deprecated_api_warning: bool, pub disable_deprecated_api_warning: bool,
pub verbose_deprecated_api_warning: bool, pub verbose_deprecated_api_warning: bool,
} }
@ -780,7 +780,7 @@ impl CliOptions {
initial_cwd: PathBuf, initial_cwd: PathBuf,
maybe_lockfile: Option<Arc<CliLockfile>>, maybe_lockfile: Option<Arc<CliLockfile>>,
npmrc: Arc<ResolvedNpmRc>, npmrc: Arc<ResolvedNpmRc>,
workspace: Arc<Workspace>, start_dir: Arc<WorkspaceDirectory>,
force_global_cache: bool, force_global_cache: bool,
) -> Result<Self, AnyError> { ) -> Result<Self, AnyError> {
if let Some(insecure_allowlist) = if let Some(insecure_allowlist) =
@ -801,7 +801,7 @@ impl CliOptions {
} }
let maybe_lockfile = maybe_lockfile.filter(|_| !force_global_cache); let maybe_lockfile = maybe_lockfile.filter(|_| !force_global_cache);
let root_folder = workspace.root_folder().1; let root_folder = start_dir.workspace.root_folder_configs();
let maybe_node_modules_folder = resolve_node_modules_folder( let maybe_node_modules_folder = resolve_node_modules_folder(
&initial_cwd, &initial_cwd,
&flags, &flags,
@ -826,7 +826,7 @@ impl CliOptions {
npmrc, npmrc,
maybe_node_modules_folder, maybe_node_modules_folder,
overrides: Default::default(), overrides: Default::default(),
workspace, start_dir,
disable_deprecated_api_warning, disable_deprecated_api_warning,
verbose_deprecated_api_warning, verbose_deprecated_api_warning,
}) })
@ -847,14 +847,13 @@ impl CliOptions {
} else { } else {
&[] &[]
}; };
let config_parse_options = deno_config::ConfigParseOptions { let config_parse_options = deno_config::deno_json::ConfigParseOptions {
include_task_comments: matches!( include_task_comments: matches!(
flags.subcommand, flags.subcommand,
DenoSubcommand::Task(..) DenoSubcommand::Task(..)
), ),
}; };
let discover_pkg_json = flags.config_flag let discover_pkg_json = flags.config_flag != ConfigFlag::Disabled
!= deno_config::ConfigFlag::Disabled
&& !flags.no_npm && !flags.no_npm
&& !has_flag_env_var("DENO_NO_PACKAGE_JSON"); && !has_flag_env_var("DENO_NO_PACKAGE_JSON");
if !discover_pkg_json { if !discover_pkg_json {
@ -866,13 +865,14 @@ impl CliOptions {
pkg_json_cache: Some( pkg_json_cache: Some(
&deno_runtime::deno_node::PackageJsonThreadLocalCache, &deno_runtime::deno_node::PackageJsonThreadLocalCache,
), ),
workspace_cache: None,
config_parse_options, config_parse_options,
additional_config_file_names, additional_config_file_names,
discover_pkg_json, discover_pkg_json,
maybe_vendor_override, maybe_vendor_override,
} }
}; };
let resolve_empty_options = || WorkspaceEmptyOptions { let resolve_empty_options = || WorkspaceDirectoryEmptyOptions {
root_dir: Arc::new( root_dir: Arc::new(
ModuleSpecifier::from_directory_path(&initial_cwd).unwrap(), ModuleSpecifier::from_directory_path(&initial_cwd).unwrap(),
), ),
@ -880,36 +880,36 @@ impl CliOptions {
.unwrap_or(VendorEnablement::Disable), .unwrap_or(VendorEnablement::Disable),
}; };
let workspace = match &flags.config_flag { let start_dir = match &flags.config_flag {
deno_config::ConfigFlag::Discover => { ConfigFlag::Discover => {
if let Some(start_paths) = flags.config_path_args(&initial_cwd) { if let Some(start_paths) = flags.config_path_args(&initial_cwd) {
Workspace::discover( WorkspaceDirectory::discover(
WorkspaceDiscoverStart::Paths(&start_paths), WorkspaceDiscoverStart::Paths(&start_paths),
&resolve_workspace_discover_options(), &resolve_workspace_discover_options(),
)? )?
} else { } else {
Workspace::empty(resolve_empty_options()) WorkspaceDirectory::empty(resolve_empty_options())
} }
} }
deno_config::ConfigFlag::Path(path) => { ConfigFlag::Path(path) => {
let config_path = normalize_path(initial_cwd.join(path)); let config_path = normalize_path(initial_cwd.join(path));
Workspace::discover( WorkspaceDirectory::discover(
WorkspaceDiscoverStart::ConfigFile(&config_path), WorkspaceDiscoverStart::ConfigFile(&config_path),
&resolve_workspace_discover_options(), &resolve_workspace_discover_options(),
)? )?
} }
deno_config::ConfigFlag::Disabled => { ConfigFlag::Disabled => {
Workspace::empty(resolve_empty_options()) WorkspaceDirectory::empty(resolve_empty_options())
} }
}; };
for diagnostic in workspace.diagnostics() { for diagnostic in start_dir.workspace.diagnostics() {
log::warn!("{} {}", colors::yellow("Warning"), diagnostic); log::warn!("{} {}", colors::yellow("Warning"), diagnostic);
} }
let (npmrc, _) = discover_npmrc_from_workspace(&workspace)?; let (npmrc, _) = discover_npmrc_from_workspace(&start_dir.workspace)?;
let maybe_lock_file = CliLockfile::discover(&flags, &workspace)?; let maybe_lock_file = CliLockfile::discover(&flags, &start_dir.workspace)?;
log::debug!("Finished config loading."); log::debug!("Finished config loading.");
@ -918,7 +918,7 @@ impl CliOptions {
initial_cwd, initial_cwd,
maybe_lock_file.map(Arc::new), maybe_lock_file.map(Arc::new),
npmrc, npmrc,
Arc::new(workspace), Arc::new(start_dir),
false, false,
) )
} }
@ -928,6 +928,11 @@ impl CliOptions {
&self.initial_cwd &self.initial_cwd
} }
#[inline(always)]
pub fn workspace(&self) -> &Arc<Workspace> {
&self.start_dir.workspace
}
pub fn graph_kind(&self) -> GraphKind { pub fn graph_kind(&self) -> GraphKind {
match self.sub_command() { match self.sub_command() {
DenoSubcommand::Cache(_) => GraphKind::All, DenoSubcommand::Cache(_) => GraphKind::All,
@ -1013,7 +1018,7 @@ impl CliOptions {
Some(maybe_url) => Ok(maybe_url), Some(maybe_url) => Ok(maybe_url),
None => resolve_import_map_specifier( None => resolve_import_map_specifier(
self.flags.import_map_path.as_deref(), self.flags.import_map_path.as_deref(),
self.workspace.root_folder().1.deno_json.as_deref(), self.workspace().root_deno_json().map(|c| c.as_ref()),
&self.initial_cwd, &self.initial_cwd,
), ),
} }
@ -1033,12 +1038,7 @@ impl CliOptions {
let cli_arg_specified_import_map = if overrode_no_import_map { let cli_arg_specified_import_map = if overrode_no_import_map {
// use a fake empty import map // use a fake empty import map
Some(deno_config::workspace::SpecifiedImportMap { Some(deno_config::workspace::SpecifiedImportMap {
base_url: self base_url: self.workspace().root_dir().join("import_map.json").unwrap(),
.workspace
.root_folder()
.0
.join("import_map.json")
.unwrap(),
value: serde_json::Value::Object(Default::default()), value: serde_json::Value::Object(Default::default()),
}) })
} else { } else {
@ -1062,7 +1062,7 @@ impl CliOptions {
}; };
Ok( Ok(
self self
.workspace .start_dir
.create_resolver( .create_resolver(
CreateResolverOptions { CreateResolverOptions {
pkg_json_dep_resolution, pkg_json_dep_resolution,
@ -1226,7 +1226,7 @@ impl CliOptions {
maybe_node_modules_folder: Some(path), maybe_node_modules_folder: Some(path),
npmrc: self.npmrc.clone(), npmrc: self.npmrc.clone(),
maybe_lockfile: self.maybe_lockfile.clone(), maybe_lockfile: self.maybe_lockfile.clone(),
workspace: self.workspace.clone(), start_dir: self.start_dir.clone(),
overrides: self.overrides.clone(), overrides: self.overrides.clone(),
disable_deprecated_api_warning: self.disable_deprecated_api_warning, disable_deprecated_api_warning: self.disable_deprecated_api_warning,
verbose_deprecated_api_warning: self.verbose_deprecated_api_warning, verbose_deprecated_api_warning: self.verbose_deprecated_api_warning,
@ -1237,11 +1237,11 @@ impl CliOptions {
self self
.flags .flags
.node_modules_dir .node_modules_dir
.or_else(|| self.workspace.node_modules_dir()) .or_else(|| self.workspace().node_modules_dir())
} }
pub fn vendor_dir_path(&self) -> Option<&PathBuf> { pub fn vendor_dir_path(&self) -> Option<&PathBuf> {
self.workspace.vendor_dir_path() self.workspace().vendor_dir_path()
} }
pub fn resolve_root_cert_store_provider( pub fn resolve_root_cert_store_provider(
@ -1258,7 +1258,7 @@ impl CliOptions {
&self, &self,
config_type: TsConfigType, config_type: TsConfigType,
) -> Result<TsConfigForEmit, AnyError> { ) -> Result<TsConfigForEmit, AnyError> {
let result = self.workspace.resolve_ts_config_for_emit(config_type); let result = self.workspace().resolve_ts_config_for_emit(config_type);
match result { match result {
Ok(mut ts_config_for_emit) => { Ok(mut ts_config_for_emit) => {
@ -1301,7 +1301,7 @@ impl CliOptions {
&self, &self,
) -> Result<Vec<deno_graph::ReferrerImports>, AnyError> { ) -> Result<Vec<deno_graph::ReferrerImports>, AnyError> {
self self
.workspace .workspace()
.to_compiler_option_types() .to_compiler_option_types()
.map(|maybe_imports| { .map(|maybe_imports| {
maybe_imports maybe_imports
@ -1321,11 +1321,11 @@ impl CliOptions {
pub fn resolve_fmt_options_for_members( pub fn resolve_fmt_options_for_members(
&self, &self,
fmt_flags: &FmtFlags, fmt_flags: &FmtFlags,
) -> Result<Vec<(WorkspaceMemberContext, FmtOptions)>, AnyError> { ) -> Result<Vec<(WorkspaceDirectory, FmtOptions)>, AnyError> {
let cli_arg_patterns = let cli_arg_patterns =
fmt_flags.files.as_file_patterns(self.initial_cwd())?; fmt_flags.files.as_file_patterns(self.initial_cwd())?;
let member_configs = self let member_configs = self
.workspace .workspace()
.resolve_fmt_config_for_members(&cli_arg_patterns)?; .resolve_fmt_config_for_members(&cli_arg_patterns)?;
let mut result = Vec::with_capacity(member_configs.len()); let mut result = Vec::with_capacity(member_configs.len());
for (ctx, config) in member_configs { for (ctx, config) in member_configs {
@ -1339,18 +1339,18 @@ impl CliOptions {
&self, &self,
lint_flags: &LintFlags, lint_flags: &LintFlags,
) -> Result<WorkspaceLintOptions, AnyError> { ) -> Result<WorkspaceLintOptions, AnyError> {
let lint_config = self.workspace.to_lint_config()?; let lint_config = self.workspace().to_lint_config()?;
WorkspaceLintOptions::resolve(&lint_config, lint_flags) WorkspaceLintOptions::resolve(&lint_config, lint_flags)
} }
pub fn resolve_lint_options_for_members( pub fn resolve_lint_options_for_members(
&self, &self,
lint_flags: &LintFlags, lint_flags: &LintFlags,
) -> Result<Vec<(WorkspaceMemberContext, LintOptions)>, AnyError> { ) -> Result<Vec<(WorkspaceDirectory, LintOptions)>, AnyError> {
let cli_arg_patterns = let cli_arg_patterns =
lint_flags.files.as_file_patterns(self.initial_cwd())?; lint_flags.files.as_file_patterns(self.initial_cwd())?;
let member_configs = self let member_configs = self
.workspace .workspace()
.resolve_lint_config_for_members(&cli_arg_patterns)?; .resolve_lint_config_for_members(&cli_arg_patterns)?;
let mut result = Vec::with_capacity(member_configs.len()); let mut result = Vec::with_capacity(member_configs.len());
for (ctx, config) in member_configs { for (ctx, config) in member_configs {
@ -1391,16 +1391,16 @@ impl CliOptions {
pub fn resolve_test_options_for_members( pub fn resolve_test_options_for_members(
&self, &self,
test_flags: &TestFlags, test_flags: &TestFlags,
) -> Result<Vec<(WorkspaceMemberContext, TestOptions)>, AnyError> { ) -> Result<Vec<(WorkspaceDirectory, TestOptions)>, AnyError> {
let cli_arg_patterns = let cli_arg_patterns =
test_flags.files.as_file_patterns(self.initial_cwd())?; test_flags.files.as_file_patterns(self.initial_cwd())?;
let member_ctxs = self let workspace_dir_configs = self
.workspace .workspace()
.resolve_test_config_for_members(&cli_arg_patterns)?; .resolve_test_config_for_members(&cli_arg_patterns)?;
let mut result = Vec::with_capacity(member_ctxs.len()); let mut result = Vec::with_capacity(workspace_dir_configs.len());
for (member_ctx, config) in member_ctxs { for (member_dir, config) in workspace_dir_configs {
let options = TestOptions::resolve(config, test_flags); let options = TestOptions::resolve(config, test_flags);
result.push((member_ctx, options)); result.push((member_dir, options));
} }
Ok(result) Ok(result)
} }
@ -1415,16 +1415,16 @@ impl CliOptions {
pub fn resolve_bench_options_for_members( pub fn resolve_bench_options_for_members(
&self, &self,
bench_flags: &BenchFlags, bench_flags: &BenchFlags,
) -> Result<Vec<(WorkspaceMemberContext, BenchOptions)>, AnyError> { ) -> Result<Vec<(WorkspaceDirectory, BenchOptions)>, AnyError> {
let cli_arg_patterns = let cli_arg_patterns =
bench_flags.files.as_file_patterns(self.initial_cwd())?; bench_flags.files.as_file_patterns(self.initial_cwd())?;
let member_ctxs = self let workspace_dir_configs = self
.workspace .workspace()
.resolve_bench_config_for_members(&cli_arg_patterns)?; .resolve_bench_config_for_members(&cli_arg_patterns)?;
let mut result = Vec::with_capacity(member_ctxs.len()); let mut result = Vec::with_capacity(workspace_dir_configs.len());
for (member_ctx, config) in member_ctxs { for (member_dir, config) in workspace_dir_configs {
let options = BenchOptions::resolve(config, bench_flags); let options = BenchOptions::resolve(config, bench_flags);
result.push((member_ctx, options)); result.push((member_dir, options));
} }
Ok(result) Ok(result)
} }
@ -1433,7 +1433,7 @@ impl CliOptions {
&self, &self,
) -> Result<Vec<deno_graph::WorkspaceMember>, AnyError> { ) -> Result<Vec<deno_graph::WorkspaceMember>, AnyError> {
self self
.workspace .workspace()
.jsr_packages() .jsr_packages()
.into_iter() .into_iter()
.map(|pkg| config_to_deno_graph_workspace_member(&pkg.config_file)) .map(|pkg| config_to_deno_graph_workspace_member(&pkg.config_file))
@ -1454,7 +1454,7 @@ impl CliOptions {
} }
pub fn check_js(&self) -> bool { pub fn check_js(&self) -> bool {
self.workspace.check_js() self.workspace().check_js()
} }
pub fn coverage_dir(&self) -> Option<String> { pub fn coverage_dir(&self) -> Option<String> {
@ -1541,7 +1541,7 @@ impl CliOptions {
} }
pub fn no_config(&self) -> bool { pub fn no_config(&self) -> bool {
self.flags.config_flag == deno_config::ConfigFlag::Disabled self.flags.config_flag == ConfigFlag::Disabled
} }
pub fn permission_flags(&self) -> &PermissionFlags { pub fn permission_flags(&self) -> &PermissionFlags {
@ -1601,14 +1601,14 @@ impl CliOptions {
pub fn unstable_bare_node_builtins(&self) -> bool { pub fn unstable_bare_node_builtins(&self) -> bool {
self.flags.unstable_config.bare_node_builtins self.flags.unstable_config.bare_node_builtins
|| self.workspace.has_unstable("bare-node-builtins") || self.workspace().has_unstable("bare-node-builtins")
} }
pub fn use_byonm(&self) -> bool { pub fn use_byonm(&self) -> bool {
if self.enable_future_features() if self.enable_future_features()
&& self.node_modules_dir_enablement().is_none() && self.node_modules_dir_enablement().is_none()
&& self && self
.workspace .workspace()
.config_folders() .config_folders()
.values() .values()
.any(|f| f.pkg_json.is_some()) .any(|f| f.pkg_json.is_some())
@ -1622,16 +1622,16 @@ impl CliOptions {
.as_ref() .as_ref()
.map(|s| matches!(s.kind, NpmProcessStateKind::Byonm)) .map(|s| matches!(s.kind, NpmProcessStateKind::Byonm))
.unwrap_or(false) .unwrap_or(false)
|| self.workspace.has_unstable("byonm") || self.workspace().has_unstable("byonm")
} }
pub fn unstable_sloppy_imports(&self) -> bool { pub fn unstable_sloppy_imports(&self) -> bool {
self.flags.unstable_config.sloppy_imports self.flags.unstable_config.sloppy_imports
|| self.workspace.has_unstable("sloppy-imports") || self.workspace().has_unstable("sloppy-imports")
} }
pub fn unstable_features(&self) -> Vec<String> { pub fn unstable_features(&self) -> Vec<String> {
let mut from_config_file = self.workspace.unstable_features().to_vec(); let mut from_config_file = self.workspace().unstable_features().to_vec();
self self
.flags .flags
@ -1713,7 +1713,7 @@ impl CliOptions {
full_paths.push(import_map_path); full_paths.push(import_map_path);
} }
for (_, folder) in self.workspace.config_folders() { for (_, folder) in self.workspace().config_folders() {
if let Some(deno_json) = &folder.deno_json { if let Some(deno_json) = &folder.deno_json {
if deno_json.specifier.scheme() == "file" { if deno_json.specifier.scheme() == "file" {
if let Ok(path) = deno_json.specifier.to_file_path() { if let Ok(path) = deno_json.specifier.to_file_path() {
@ -1815,8 +1815,7 @@ impl StorageKeyResolver {
// otherwise we will use the path to the config file or None to // otherwise we will use the path to the config file or None to
// fall back to using the main module's path // fall back to using the main module's path
options options
.workspace .start_dir
.resolve_start_ctx()
.maybe_deno_json() .maybe_deno_json()
.map(|config_file| Some(config_file.specifier.to_string())) .map(|config_file| Some(config_file.specifier.to_string()))
}) })
@ -1912,7 +1911,7 @@ mod test {
let config_file = ConfigFile::new( let config_file = ConfigFile::new(
config_text, config_text,
config_specifier, config_specifier,
&deno_config::ConfigParseOptions::default(), &deno_config::deno_json::ConfigParseOptions::default(),
) )
.unwrap(); .unwrap();
let actual = resolve_import_map_specifier( let actual = resolve_import_map_specifier(
@ -1936,7 +1935,7 @@ mod test {
let config_file = ConfigFile::new( let config_file = ConfigFile::new(
config_text, config_text,
config_specifier, config_specifier,
&deno_config::ConfigParseOptions::default(), &deno_config::deno_json::ConfigParseOptions::default(),
) )
.unwrap(); .unwrap();
let actual = resolve_import_map_specifier( let actual = resolve_import_map_specifier(

View file

@ -54,10 +54,10 @@ use crate::worker::CliMainWorkerOptions;
use std::collections::BTreeSet; use std::collections::BTreeSet;
use std::path::PathBuf; use std::path::PathBuf;
use deno_config::deno_json::ConfigFile;
use deno_config::package_json::PackageJsonDepValue; use deno_config::package_json::PackageJsonDepValue;
use deno_config::workspace::PackageJsonDepResolution; use deno_config::workspace::PackageJsonDepResolution;
use deno_config::workspace::WorkspaceResolver; use deno_config::workspace::WorkspaceResolver;
use deno_config::ConfigFile;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::futures::FutureExt; use deno_core::futures::FutureExt;
use deno_core::FeatureChecker; use deno_core::FeatureChecker;
@ -341,7 +341,8 @@ impl CliFactory {
// initialize the lockfile with the workspace's configuration // initialize the lockfile with the workspace's configuration
if let Some(lockfile) = &maybe_lockfile { if let Some(lockfile) = &maybe_lockfile {
let (root_url, root_folder) = self.options.workspace.root_folder(); let root_url = self.options.workspace().root_dir();
let root_folder = self.options.workspace().root_folder_configs();
let config = deno_lockfile::WorkspaceConfig { let config = deno_lockfile::WorkspaceConfig {
root: WorkspaceMemberConfig { root: WorkspaceMemberConfig {
package_json_deps: pkg_json_deps(root_folder.pkg_json.as_deref()), package_json_deps: pkg_json_deps(root_folder.pkg_json.as_deref()),
@ -349,7 +350,7 @@ impl CliFactory {
}, },
members: self members: self
.options .options
.workspace .workspace()
.config_folders() .config_folders()
.iter() .iter()
.filter(|(folder_url, _)| *folder_url != root_url) .filter(|(folder_url, _)| *folder_url != root_url)
@ -440,7 +441,7 @@ impl CliFactory {
text_only_progress_bar: self.text_only_progress_bar().clone(), text_only_progress_bar: self.text_only_progress_bar().clone(),
maybe_node_modules_path: self.options.node_modules_dir_path().cloned(), maybe_node_modules_path: self.options.node_modules_dir_path().cloned(),
package_json_deps_provider: Arc::new(PackageJsonInstallDepsProvider::from_workspace( package_json_deps_provider: Arc::new(PackageJsonInstallDepsProvider::from_workspace(
&self.options.workspace, self.options.workspace(),
)), )),
npm_system_info: self.options.npm_system_info(), npm_system_info: self.options.npm_system_info(),
npmrc: self.options.npmrc().clone(), npmrc: self.options.npmrc().clone(),
@ -510,7 +511,7 @@ impl CliFactory {
.unstable_bare_node_builtins(), .unstable_bare_node_builtins(),
maybe_jsx_import_source_config: self maybe_jsx_import_source_config: self
.options .options
.workspace .workspace()
.to_maybe_jsx_import_source_config()?, .to_maybe_jsx_import_source_config()?,
maybe_vendor_dir: self.options.vendor_dir_path(), maybe_vendor_dir: self.options.vendor_dir_path(),
}))) })))

View file

@ -98,7 +98,7 @@ impl MainModuleGraphContainer {
&self, &self,
files: &[String], files: &[String],
) -> Result<Vec<ModuleSpecifier>, AnyError> { ) -> Result<Vec<ModuleSpecifier>, AnyError> {
let excludes = self.cli_options.workspace.resolve_config_excludes()?; let excludes = self.cli_options.workspace().resolve_config_excludes()?;
Ok( Ok(
files files
.iter() .iter()

View file

@ -1,6 +1,12 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use deno_ast::MediaType; use deno_ast::MediaType;
use deno_config::deno_json::DenoJsonCache;
use deno_config::deno_json::FmtConfig;
use deno_config::deno_json::FmtOptionsConfig;
use deno_config::deno_json::LintConfig;
use deno_config::deno_json::TestConfig;
use deno_config::deno_json::TsConfig;
use deno_config::fs::DenoConfigFs; use deno_config::fs::DenoConfigFs;
use deno_config::fs::RealDenoConfigFs; use deno_config::fs::RealDenoConfigFs;
use deno_config::glob::FilePatterns; use deno_config::glob::FilePatterns;
@ -11,14 +17,11 @@ use deno_config::workspace::PackageJsonDepResolution;
use deno_config::workspace::SpecifiedImportMap; use deno_config::workspace::SpecifiedImportMap;
use deno_config::workspace::VendorEnablement; use deno_config::workspace::VendorEnablement;
use deno_config::workspace::Workspace; use deno_config::workspace::Workspace;
use deno_config::workspace::WorkspaceCache;
use deno_config::workspace::WorkspaceDirectory;
use deno_config::workspace::WorkspaceDirectoryEmptyOptions;
use deno_config::workspace::WorkspaceDiscoverOptions; use deno_config::workspace::WorkspaceDiscoverOptions;
use deno_config::workspace::WorkspaceEmptyOptions;
use deno_config::workspace::WorkspaceMemberContext;
use deno_config::workspace::WorkspaceResolver; use deno_config::workspace::WorkspaceResolver;
use deno_config::DenoJsonCache;
use deno_config::FmtConfig;
use deno_config::FmtOptionsConfig;
use deno_config::TsConfig;
use deno_core::anyhow::anyhow; use deno_core::anyhow::anyhow;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::parking_lot::Mutex; use deno_core::parking_lot::Mutex;
@ -29,6 +32,7 @@ use deno_core::serde_json;
use deno_core::serde_json::json; use deno_core::serde_json::json;
use deno_core::serde_json::Value; use deno_core::serde_json::Value;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_lint::linter::LintConfig as DenoLintConfig;
use deno_npm::npm_rc::ResolvedNpmRc; use deno_npm::npm_rc::ResolvedNpmRc;
use deno_runtime::deno_node::PackageJson; use deno_runtime::deno_node::PackageJson;
use deno_runtime::deno_permissions::PermissionsContainer; use deno_runtime::deno_permissions::PermissionsContainer;
@ -1107,13 +1111,12 @@ pub enum ConfigWatchedFileType {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ConfigData { pub struct ConfigData {
pub scope: Arc<ModuleSpecifier>, pub scope: Arc<ModuleSpecifier>,
pub workspace: Arc<Workspace>, pub member_dir: Arc<WorkspaceDirectory>,
pub member_ctx: Arc<WorkspaceMemberContext>, pub fmt_config: Arc<FmtConfig>,
pub fmt_config: Arc<deno_config::FmtConfig>, pub lint_config: Arc<LintConfig>,
pub lint_config: Arc<deno_config::LintConfig>, pub test_config: Arc<TestConfig>,
pub test_config: Arc<deno_config::TestConfig>,
pub exclude_files: Arc<PathOrPatternSet>, pub exclude_files: Arc<PathOrPatternSet>,
pub deno_lint_config: deno_lint::linter::LintConfig, pub deno_lint_config: DenoLintConfig,
pub lint_rules: Arc<ConfiguredRules>, pub lint_rules: Arc<ConfiguredRules>,
pub ts_config: Arc<LspTsConfig>, pub ts_config: Arc<LspTsConfig>,
pub byonm: bool, pub byonm: bool,
@ -1127,6 +1130,7 @@ pub struct ConfigData {
} }
impl ConfigData { impl ConfigData {
#[allow(clippy::too_many_arguments)]
async fn load( async fn load(
specified_config: Option<&Path>, specified_config: Option<&Path>,
scope: &ModuleSpecifier, scope: &ModuleSpecifier,
@ -1136,12 +1140,13 @@ impl ConfigData {
cached_deno_config_fs: &(dyn DenoConfigFs + Sync), cached_deno_config_fs: &(dyn DenoConfigFs + Sync),
deno_json_cache: &(dyn DenoJsonCache + Sync), deno_json_cache: &(dyn DenoJsonCache + Sync),
pkg_json_cache: &(dyn PackageJsonCache + Sync), pkg_json_cache: &(dyn PackageJsonCache + Sync),
workspace_cache: &(dyn WorkspaceCache + Sync),
) -> Self { ) -> Self {
let scope = Arc::new(scope.clone()); let scope = Arc::new(scope.clone());
let discover_result = match scope.to_file_path() { let discover_result = match scope.to_file_path() {
Ok(scope_dir_path) => { Ok(scope_dir_path) => {
let paths = [scope_dir_path]; let paths = [scope_dir_path];
Workspace::discover( WorkspaceDirectory::discover(
match specified_config { match specified_config {
Some(config_path) => { Some(config_path) => {
deno_config::workspace::WorkspaceDiscoverStart::ConfigFile( deno_config::workspace::WorkspaceDiscoverStart::ConfigFile(
@ -1157,6 +1162,7 @@ impl ConfigData {
additional_config_file_names: &[], additional_config_file_names: &[],
deno_json_cache: Some(deno_json_cache), deno_json_cache: Some(deno_json_cache),
pkg_json_cache: Some(pkg_json_cache), pkg_json_cache: Some(pkg_json_cache),
workspace_cache: Some(workspace_cache),
discover_pkg_json: !has_flag_env_var("DENO_NO_PACKAGE_JSON"), discover_pkg_json: !has_flag_env_var("DENO_NO_PACKAGE_JSON"),
config_parse_options: Default::default(), config_parse_options: Default::default(),
maybe_vendor_override: None, maybe_vendor_override: None,
@ -1168,17 +1174,18 @@ impl ConfigData {
Err(()) => Err(anyhow!("Scope '{}' was not a directory path.", scope)), Err(()) => Err(anyhow!("Scope '{}' was not a directory path.", scope)),
}; };
match discover_result { match discover_result {
Ok(workspace) => { Ok(member_dir) => {
Self::load_inner(workspace, scope, settings, Some(file_fetcher)).await Self::load_inner(member_dir, scope, settings, Some(file_fetcher)).await
} }
Err(err) => { Err(err) => {
lsp_warn!(" Couldn't open workspace \"{}\": {}", scope.as_str(), err); lsp_warn!(" Couldn't open workspace \"{}\": {}", scope.as_str(), err);
let workspace = Arc::new(Workspace::empty(WorkspaceEmptyOptions { let member_dir =
root_dir: scope.clone(), Arc::new(WorkspaceDirectory::empty(WorkspaceDirectoryEmptyOptions {
use_vendor_dir: VendorEnablement::Disable, root_dir: scope.clone(),
})); use_vendor_dir: VendorEnablement::Disable,
}));
let mut data = Self::load_inner( let mut data = Self::load_inner(
workspace, member_dir,
scope.clone(), scope.clone(),
settings, settings,
Some(file_fetcher), Some(file_fetcher),
@ -1220,7 +1227,7 @@ impl ConfigData {
} }
async fn load_inner( async fn load_inner(
workspace: Arc<Workspace>, member_dir: Arc<WorkspaceDirectory>,
scope: Arc<ModuleSpecifier>, scope: Arc<ModuleSpecifier>,
settings: &Settings, settings: &Settings,
file_fetcher: Option<&Arc<FileFetcher>>, file_fetcher: Option<&Arc<FileFetcher>>,
@ -1242,9 +1249,7 @@ impl ConfigData {
watched_files.entry(specifier).or_insert(file_type); watched_files.entry(specifier).or_insert(file_type);
}; };
let member_ctx = workspace.resolve_start_ctx(); if let Some(deno_json) = member_dir.maybe_deno_json() {
if let Some(deno_json) = member_ctx.maybe_deno_json() {
lsp_log!( lsp_log!(
" Resolved Deno configuration file: \"{}\"", " Resolved Deno configuration file: \"{}\"",
deno_json.specifier deno_json.specifier
@ -1256,7 +1261,7 @@ impl ConfigData {
); );
} }
if let Some(pkg_json) = member_ctx.maybe_pkg_json() { if let Some(pkg_json) = member_dir.maybe_pkg_json() {
lsp_log!(" Resolved package.json: \"{}\"", pkg_json.specifier()); lsp_log!(" Resolved package.json: \"{}\"", pkg_json.specifier());
add_watched_file( add_watched_file(
@ -1266,7 +1271,7 @@ impl ConfigData {
} }
// todo(dsherret): cache this so we don't load this so many times // todo(dsherret): cache this so we don't load this so many times
let npmrc = discover_npmrc_from_workspace(&workspace) let npmrc = discover_npmrc_from_workspace(&member_dir.workspace)
.inspect(|(_, path)| { .inspect(|(_, path)| {
if let Some(path) = path { if let Some(path) = path {
lsp_log!(" Resolved .npmrc: \"{}\"", path.display()); lsp_log!(" Resolved .npmrc: \"{}\"", path.display());
@ -1281,51 +1286,48 @@ impl ConfigData {
}) })
.map(|(r, _)| r) .map(|(r, _)| r)
.ok(); .ok();
let default_file_patterns = scope let default_file_pattern_base =
.to_file_path() scope.to_file_path().unwrap_or_else(|_| PathBuf::from("/"));
.map(FilePatterns::new_with_base)
.unwrap_or_else(|_| FilePatterns::new_with_base(PathBuf::from("/")));
let fmt_config = Arc::new( let fmt_config = Arc::new(
member_ctx member_dir
.to_fmt_config(FilePatterns::new_with_base(member_ctx.dir_path())) .to_fmt_config(FilePatterns::new_with_base(member_dir.dir_path()))
.inspect_err(|err| { .inspect_err(|err| {
lsp_warn!(" Couldn't read formatter configuration: {}", err) lsp_warn!(" Couldn't read formatter configuration: {}", err)
}) })
.ok() .ok()
.unwrap_or_else(|| deno_config::FmtConfig { .unwrap_or_else(|| {
options: Default::default(), FmtConfig::new_with_base(default_file_pattern_base.clone())
files: default_file_patterns.clone(),
}), }),
); );
let lint_config = Arc::new( let lint_config = Arc::new(
member_ctx member_dir
.to_lint_config(FilePatterns::new_with_base(member_ctx.dir_path())) .to_lint_config(FilePatterns::new_with_base(member_dir.dir_path()))
.inspect_err(|err| { .inspect_err(|err| {
lsp_warn!(" Couldn't read lint configuration: {}", err) lsp_warn!(" Couldn't read lint configuration: {}", err)
}) })
.ok() .ok()
.unwrap_or_else(|| deno_config::LintConfig { .unwrap_or_else(|| {
options: Default::default(), LintConfig::new_with_base(default_file_pattern_base.clone())
files: default_file_patterns.clone(),
}), }),
); );
let lint_rules = Arc::new(get_configured_rules( let lint_rules = Arc::new(get_configured_rules(
lint_config.options.rules.clone(), lint_config.options.rules.clone(),
member_ctx.maybe_deno_json().map(|c| c.as_ref()), member_dir.maybe_deno_json().map(|c| c.as_ref()),
)); ));
let test_config = Arc::new( let test_config = Arc::new(
member_ctx member_dir
.to_test_config(FilePatterns::new_with_base(member_ctx.dir_path())) .to_test_config(FilePatterns::new_with_base(member_dir.dir_path()))
.inspect_err(|err| { .inspect_err(|err| {
lsp_warn!(" Couldn't read test configuration: {}", err) lsp_warn!(" Couldn't read test configuration: {}", err)
}) })
.ok() .ok()
.unwrap_or_else(|| deno_config::TestConfig { .unwrap_or_else(|| {
files: default_file_patterns.clone(), TestConfig::new_with_base(default_file_pattern_base.clone())
}), }),
); );
let exclude_files = Arc::new( let exclude_files = Arc::new(
workspace member_dir
.workspace
.resolve_config_excludes() .resolve_config_excludes()
.inspect_err(|err| { .inspect_err(|err| {
lsp_warn!(" Couldn't read config excludes: {}", err) lsp_warn!(" Couldn't read config excludes: {}", err)
@ -1334,8 +1336,9 @@ impl ConfigData {
.unwrap_or_default(), .unwrap_or_default(),
); );
let ts_config = let ts_config = LspTsConfig::new(
LspTsConfig::new(workspace.root_deno_json().map(|c| c.as_ref())); member_dir.workspace.root_deno_json().map(|c| c.as_ref()),
);
let deno_lint_config = let deno_lint_config =
if ts_config.inner.0.get("jsx").and_then(|v| v.as_str()) == Some("react") if ts_config.inner.0.get("jsx").and_then(|v| v.as_str()) == Some("react")
@ -1347,21 +1350,21 @@ impl ConfigData {
.0 .0
.get("jsxFragmentFactory") .get("jsxFragmentFactory")
.and_then(|v| v.as_str()); .and_then(|v| v.as_str());
deno_lint::linter::LintConfig { DenoLintConfig {
default_jsx_factory: default_jsx_factory.map(String::from), default_jsx_factory: default_jsx_factory.map(String::from),
default_jsx_fragment_factory: default_jsx_fragment_factory default_jsx_fragment_factory: default_jsx_fragment_factory
.map(String::from), .map(String::from),
} }
} else { } else {
deno_lint::linter::LintConfig { DenoLintConfig {
default_jsx_factory: None, default_jsx_factory: None,
default_jsx_fragment_factory: None, default_jsx_fragment_factory: None,
} }
}; };
let vendor_dir = workspace.vendor_dir_path().cloned(); let vendor_dir = member_dir.workspace.vendor_dir_path().cloned();
// todo(dsherret): add caching so we don't load this so many times // todo(dsherret): add caching so we don't load this so many times
let lockfile = resolve_lockfile_from_workspace(&workspace).map(Arc::new); let lockfile = resolve_lockfile_from_workspace(&member_dir).map(Arc::new);
if let Some(lockfile) = &lockfile { if let Some(lockfile) = &lockfile {
if let Ok(specifier) = ModuleSpecifier::from_file_path(&lockfile.filename) if let Ok(specifier) = ModuleSpecifier::from_file_path(&lockfile.filename)
{ {
@ -1370,18 +1373,22 @@ impl ConfigData {
} }
let byonm = std::env::var("DENO_UNSTABLE_BYONM").is_ok() let byonm = std::env::var("DENO_UNSTABLE_BYONM").is_ok()
|| workspace.has_unstable("byonm") || member_dir.workspace.has_unstable("byonm")
|| (*DENO_FUTURE || (*DENO_FUTURE
&& workspace.package_jsons().next().is_some() && member_dir.workspace.package_jsons().next().is_some()
&& workspace.node_modules_dir().is_none()); && member_dir.workspace.node_modules_dir().is_none());
if byonm { if byonm {
lsp_log!(" Enabled 'bring your own node_modules'."); lsp_log!(" Enabled 'bring your own node_modules'.");
} }
let node_modules_dir = resolve_node_modules_dir(&workspace, byonm); let node_modules_dir =
resolve_node_modules_dir(&member_dir.workspace, byonm);
// Mark the import map as a watched file // Mark the import map as a watched file
if let Some(import_map_specifier) = if let Some(import_map_specifier) = member_dir
workspace.to_import_map_specifier().ok().flatten() .workspace
.to_import_map_specifier()
.ok()
.flatten()
{ {
add_watched_file( add_watched_file(
import_map_specifier.clone(), import_map_specifier.clone(),
@ -1396,11 +1403,12 @@ impl ConfigData {
PackageJsonDepResolution::Enabled PackageJsonDepResolution::Enabled
}; };
let mut import_map_from_settings = { let mut import_map_from_settings = {
let is_config_import_map = member_ctx let is_config_import_map = member_dir
.maybe_deno_json() .maybe_deno_json()
.map(|c| c.is_an_import_map() || c.json.import_map.is_some()) .map(|c| c.is_an_import_map() || c.json.import_map.is_some())
.or_else(|| { .or_else(|| {
workspace member_dir
.workspace
.root_deno_json() .root_deno_json()
.map(|c| c.is_an_import_map() || c.json.import_map.is_some()) .map(|c| c.is_an_import_map() || c.json.import_map.is_some())
}) })
@ -1417,11 +1425,12 @@ impl ConfigData {
}; };
let specified_import_map = { let specified_import_map = {
let is_config_import_map = member_ctx let is_config_import_map = member_dir
.maybe_deno_json() .maybe_deno_json()
.map(|c| c.is_an_import_map() || c.json.import_map.is_some()) .map(|c| c.is_an_import_map() || c.json.import_map.is_some())
.or_else(|| { .or_else(|| {
workspace member_dir
.workspace
.root_deno_json() .root_deno_json()
.map(|c| c.is_an_import_map() || c.json.import_map.is_some()) .map(|c| c.is_an_import_map() || c.json.import_map.is_some())
}) })
@ -1470,7 +1479,7 @@ impl ConfigData {
} }
}; };
let resolver = deno_core::unsync::spawn({ let resolver = deno_core::unsync::spawn({
let workspace = workspace.clone(); let workspace = member_dir.clone();
let file_fetcher = file_fetcher.cloned(); let file_fetcher = file_fetcher.cloned();
async move { async move {
workspace workspace
@ -1508,7 +1517,7 @@ impl ConfigData {
WorkspaceResolver::new_raw( WorkspaceResolver::new_raw(
scope.clone(), scope.clone(),
None, None,
workspace.package_jsons().cloned().collect(), member_dir.workspace.package_jsons().cloned().collect(),
pkg_json_dep_resolution, pkg_json_dep_resolution,
) )
}); });
@ -1526,8 +1535,7 @@ impl ConfigData {
ConfigData { ConfigData {
scope, scope,
workspace, member_dir,
member_ctx: Arc::new(member_ctx),
resolver: Arc::new(resolver), resolver: Arc::new(resolver),
fmt_config, fmt_config,
lint_config, lint_config,
@ -1546,14 +1554,16 @@ impl ConfigData {
} }
} }
pub fn maybe_deno_json(&self) -> Option<&Arc<deno_config::ConfigFile>> { pub fn maybe_deno_json(
self.member_ctx.maybe_deno_json() &self,
) -> Option<&Arc<deno_config::deno_json::ConfigFile>> {
self.member_dir.maybe_deno_json()
} }
pub fn maybe_pkg_json( pub fn maybe_pkg_json(
&self, &self,
) -> Option<&Arc<deno_config::package_json::PackageJson>> { ) -> Option<&Arc<deno_config::package_json::PackageJson>> {
self.member_ctx.maybe_pkg_json() self.member_dir.maybe_pkg_json()
} }
} }
@ -1588,11 +1598,13 @@ impl ConfigTree {
&self.scopes &self.scopes
} }
pub fn workspace_member_ctx_for_specifier( pub fn workspace_dir_for_specifier(
&self, &self,
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
) -> Option<&Arc<WorkspaceMemberContext>> { ) -> Option<&WorkspaceDirectory> {
self.data_for_specifier(specifier).map(|d| &d.member_ctx) self
.data_for_specifier(specifier)
.map(|d| d.member_dir.as_ref())
} }
pub fn config_files(&self) -> Vec<&Arc<ConfigFile>> { pub fn config_files(&self) -> Vec<&Arc<ConfigFile>> {
@ -1618,12 +1630,7 @@ impl ConfigTree {
self self
.data_for_specifier(specifier) .data_for_specifier(specifier)
.map(|d| d.fmt_config.clone()) .map(|d| d.fmt_config.clone())
.unwrap_or_else(|| { .unwrap_or_else(|| Arc::new(FmtConfig::new_with_base(PathBuf::from("/"))))
Arc::new(FmtConfig {
options: Default::default(),
files: FilePatterns::new_with_base(PathBuf::from("/")),
})
})
} }
/// Returns (scope_uri, type). /// Returns (scope_uri, type).
@ -1665,6 +1672,7 @@ impl ConfigTree {
let cached_fs = CachedDenoConfigFs::default(); let cached_fs = CachedDenoConfigFs::default();
let deno_json_cache = DenoJsonMemCache::default(); let deno_json_cache = DenoJsonMemCache::default();
let pkg_json_cache = PackageJsonMemCache::default(); let pkg_json_cache = PackageJsonMemCache::default();
let workspace_cache = WorkspaceMemCache::default();
let mut scopes = BTreeMap::new(); let mut scopes = BTreeMap::new();
for (folder_uri, ws_settings) in &settings.by_workspace_folder { for (folder_uri, ws_settings) in &settings.by_workspace_folder {
let mut ws_settings = ws_settings.as_ref(); let mut ws_settings = ws_settings.as_ref();
@ -1686,6 +1694,7 @@ impl ConfigTree {
&cached_fs, &cached_fs,
&deno_json_cache, &deno_json_cache,
&pkg_json_cache, &pkg_json_cache,
&workspace_cache,
) )
.await, .await,
), ),
@ -1718,11 +1727,12 @@ impl ConfigTree {
&cached_fs, &cached_fs,
&deno_json_cache, &deno_json_cache,
&pkg_json_cache, &pkg_json_cache,
&workspace_cache,
) )
.await, .await,
); );
scopes.insert(scope, data.clone()); scopes.insert(scope, data.clone());
for (member_scope, _) in data.workspace.config_folders() { for (member_scope, _) in data.member_dir.workspace.config_folders() {
if scopes.contains_key(member_scope) { if scopes.contains_key(member_scope) {
continue; continue;
} }
@ -1734,6 +1744,7 @@ impl ConfigTree {
&cached_fs, &cached_fs,
&deno_json_cache, &deno_json_cache,
&pkg_json_cache, &pkg_json_cache,
&workspace_cache,
) )
.await; .await;
scopes.insert(member_scope.as_ref().clone(), Arc::new(member_data)); scopes.insert(member_scope.as_ref().clone(), Arc::new(member_data));
@ -1756,6 +1767,7 @@ impl ConfigTree {
&cached_fs, &cached_fs,
&deno_json_cache, &deno_json_cache,
&pkg_json_cache, &pkg_json_cache,
&workspace_cache,
) )
.await, .await,
), ),
@ -1775,8 +1787,8 @@ impl ConfigTree {
config_path.to_string_lossy().to_string(), config_path.to_string_lossy().to_string(),
json_text, json_text,
)]); )]);
let workspace = Arc::new( let workspace_dir = Arc::new(
Workspace::discover( WorkspaceDirectory::discover(
deno_config::workspace::WorkspaceDiscoverStart::ConfigFile( deno_config::workspace::WorkspaceDiscoverStart::ConfigFile(
&config_path, &config_path,
), ),
@ -1789,7 +1801,7 @@ impl ConfigTree {
); );
let data = Arc::new( let data = Arc::new(
ConfigData::load_inner( ConfigData::load_inner(
workspace, workspace_dir,
Arc::new(scope.clone()), Arc::new(scope.clone()),
&Default::default(), &Default::default(),
None, None,
@ -1802,9 +1814,9 @@ impl ConfigTree {
} }
fn resolve_lockfile_from_workspace( fn resolve_lockfile_from_workspace(
workspace: &Workspace, workspace: &WorkspaceDirectory,
) -> Option<CliLockfile> { ) -> Option<CliLockfile> {
let lockfile_path = match workspace.resolve_lockfile_path() { let lockfile_path = match workspace.workspace.resolve_lockfile_path() {
Ok(Some(value)) => value, Ok(Some(value)) => value,
Ok(None) => return None, Ok(None) => return None,
Err(err) => { Err(err) => {
@ -1834,8 +1846,7 @@ fn resolve_node_modules_dir(
return None; return None;
} }
let node_modules_dir = workspace let node_modules_dir = workspace
.root_folder() .root_dir()
.0
.to_file_path() .to_file_path()
.ok()? .ok()?
.join("node_modules"); .join("node_modules");
@ -1864,7 +1875,7 @@ fn resolve_lockfile_from_path(lockfile_path: PathBuf) -> Option<CliLockfile> {
#[derive(Default)] #[derive(Default)]
struct DenoJsonMemCache(Mutex<HashMap<PathBuf, Arc<ConfigFile>>>); struct DenoJsonMemCache(Mutex<HashMap<PathBuf, Arc<ConfigFile>>>);
impl deno_config::DenoJsonCache for DenoJsonMemCache { impl deno_config::deno_json::DenoJsonCache for DenoJsonMemCache {
fn get(&self, path: &Path) -> Option<Arc<ConfigFile>> { fn get(&self, path: &Path) -> Option<Arc<ConfigFile>> {
self.0.lock().get(path).cloned() self.0.lock().get(path).cloned()
} }
@ -1887,6 +1898,19 @@ impl deno_config::package_json::PackageJsonCache for PackageJsonMemCache {
} }
} }
#[derive(Default)]
struct WorkspaceMemCache(Mutex<HashMap<PathBuf, Arc<Workspace>>>);
impl deno_config::workspace::WorkspaceCache for WorkspaceMemCache {
fn get(&self, dir_path: &Path) -> Option<Arc<Workspace>> {
self.0.lock().get(dir_path).cloned()
}
fn set(&self, dir_path: PathBuf, workspace: Arc<Workspace>) {
self.0.lock().insert(dir_path, workspace);
}
}
#[derive(Default)] #[derive(Default)]
struct CachedFsItems<T: Clone> { struct CachedFsItems<T: Clone> {
items: HashMap<PathBuf, Result<T, std::io::Error>>, items: HashMap<PathBuf, Result<T, std::io::Error>>,
@ -1920,7 +1944,6 @@ impl<T: Clone> CachedFsItems<T> {
struct InnerData { struct InnerData {
stat_calls: CachedFsItems<deno_config::fs::FsMetadata>, stat_calls: CachedFsItems<deno_config::fs::FsMetadata>,
read_to_string_calls: CachedFsItems<String>, read_to_string_calls: CachedFsItems<String>,
read_dir_calls: CachedFsItems<Vec<deno_config::fs::FsDirEntry>>,
} }
#[derive(Default)] #[derive(Default)]
@ -1953,22 +1976,23 @@ impl DenoConfigFs for CachedDenoConfigFs {
&self, &self,
path: &Path, path: &Path,
) -> Result<Vec<deno_config::fs::FsDirEntry>, std::io::Error> { ) -> Result<Vec<deno_config::fs::FsDirEntry>, std::io::Error> {
self // no need to cache these because the workspace cache will ensure
.0 // we only do read_dir calls once (read_dirs are only used for
.lock() // npm workspace resolution)
.read_dir_calls RealDenoConfigFs.read_dir(path)
.get(path, |path| RealDenoConfigFs.read_dir(path))
} }
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use deno_config::deno_json::ConfigParseOptions;
use deno_core::resolve_url; use deno_core::resolve_url;
use deno_core::serde_json; use deno_core::serde_json;
use deno_core::serde_json::json; use deno_core::serde_json::json;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use super::*;
#[test] #[test]
fn test_config_specifier_enabled() { fn test_config_specifier_enabled() {
let root_uri = resolve_url("file:///").unwrap(); let root_uri = resolve_url("file:///").unwrap();
@ -2234,7 +2258,7 @@ mod tests {
ConfigFile::new( ConfigFile::new(
"{}", "{}",
root_uri.join("deno.json").unwrap(), root_uri.join("deno.json").unwrap(),
&deno_config::ConfigParseOptions::default(), &ConfigParseOptions::default(),
) )
.unwrap(), .unwrap(),
) )
@ -2292,7 +2316,7 @@ mod tests {
}) })
.to_string(), .to_string(),
root_uri.join("deno.json").unwrap(), root_uri.join("deno.json").unwrap(),
&deno_config::ConfigParseOptions::default(), &ConfigParseOptions::default(),
) )
.unwrap(), .unwrap(),
) )
@ -2318,7 +2342,7 @@ mod tests {
}) })
.to_string(), .to_string(),
root_uri.join("deno.json").unwrap(), root_uri.join("deno.json").unwrap(),
&deno_config::ConfigParseOptions::default(), &ConfigParseOptions::default(),
) )
.unwrap(), .unwrap(),
) )
@ -2336,7 +2360,7 @@ mod tests {
}) })
.to_string(), .to_string(),
root_uri.join("deno.json").unwrap(), root_uri.join("deno.json").unwrap(),
&deno_config::ConfigParseOptions::default(), &ConfigParseOptions::default(),
) )
.unwrap(), .unwrap(),
) )

View file

@ -23,7 +23,7 @@ use crate::resolver::SloppyImportsResolver;
use crate::util::path::to_percent_decoded_str; use crate::util::path::to_percent_decoded_str;
use deno_ast::MediaType; use deno_ast::MediaType;
use deno_config::glob::FilePatterns; use deno_config::deno_json::LintConfig;
use deno_core::anyhow::anyhow; use deno_core::anyhow::anyhow;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::parking_lot::RwLock; use deno_core::parking_lot::RwLock;
@ -39,6 +39,7 @@ use deno_graph::source::ResolutionMode;
use deno_graph::Resolution; use deno_graph::Resolution;
use deno_graph::ResolutionError; use deno_graph::ResolutionError;
use deno_graph::SpecifierError; use deno_graph::SpecifierError;
use deno_lint::linter::LintConfig as DenoLintConfig;
use deno_lint::rules::LintRule; use deno_lint::rules::LintRule;
use deno_runtime::deno_fs; use deno_runtime::deno_fs;
use deno_runtime::deno_node; use deno_runtime::deno_node;
@ -827,11 +828,8 @@ fn generate_lint_diagnostics(
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
( (
Arc::new(deno_config::LintConfig { Arc::new(LintConfig::new_with_base(PathBuf::from("/"))),
options: Default::default(), DenoLintConfig {
files: FilePatterns::new_with_base(PathBuf::from("/")),
}),
deno_lint::linter::LintConfig {
default_jsx_factory: None, default_jsx_factory: None,
default_jsx_fragment_factory: None, default_jsx_fragment_factory: None,
}, },
@ -856,8 +854,8 @@ fn generate_lint_diagnostics(
fn generate_document_lint_diagnostics( fn generate_document_lint_diagnostics(
document: &Document, document: &Document,
lint_config: &deno_config::LintConfig, lint_config: &LintConfig,
deno_lint_config: deno_lint::linter::LintConfig, deno_lint_config: DenoLintConfig,
lint_rules: Vec<&'static dyn LintRule>, lint_rules: Vec<&'static dyn LintRule>,
) -> Vec<lsp::Diagnostic> { ) -> Vec<lsp::Diagnostic> {
if !lint_config.files.matches_specifier(document.specifier()) { if !lint_config.files.matches_specifier(document.specifier()) {
@ -1611,7 +1609,6 @@ fn generate_deno_diagnostics(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::lsp::cache::LspCache; use crate::lsp::cache::LspCache;
use crate::lsp::config::Config; use crate::lsp::config::Config;
@ -1621,7 +1618,8 @@ mod tests {
use crate::lsp::documents::LanguageId; use crate::lsp::documents::LanguageId;
use crate::lsp::language_server::StateSnapshot; use crate::lsp::language_server::StateSnapshot;
use crate::lsp::resolver::LspResolver; use crate::lsp::resolver::LspResolver;
use deno_config::ConfigFile;
use deno_config::deno_json::ConfigFile;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use std::sync::Arc; use std::sync::Arc;
use test_util::TempDir; use test_util::TempDir;
@ -1661,7 +1659,7 @@ mod tests {
let config_file = ConfigFile::new( let config_file = ConfigFile::new(
json_string, json_string,
base_url, base_url,
&deno_config::ConfigParseOptions::default(), &deno_config::deno_json::ConfigParseOptions::default(),
) )
.unwrap(); .unwrap();
config.tree.inject_config_file(config_file).await; config.tree.inject_config_file(config_file).await;

View file

@ -1597,7 +1597,9 @@ fn analyze_module(
mod tests { mod tests {
use super::*; use super::*;
use crate::lsp::cache::LspCache; use crate::lsp::cache::LspCache;
use deno_config::ConfigFile;
use deno_config::deno_json::ConfigFile;
use deno_config::deno_json::ConfigParseOptions;
use deno_core::serde_json; use deno_core::serde_json;
use deno_core::serde_json::json; use deno_core::serde_json::json;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
@ -1751,7 +1753,7 @@ console.log(b, "hello deno");
}) })
.to_string(), .to_string(),
config.root_uri().unwrap().join("deno.json").unwrap(), config.root_uri().unwrap().join("deno.json").unwrap(),
&deno_config::ConfigParseOptions::default(), &ConfigParseOptions::default(),
) )
.unwrap(), .unwrap(),
) )
@ -1795,7 +1797,7 @@ console.log(b, "hello deno");
}) })
.to_string(), .to_string(),
config.root_uri().unwrap().join("deno.json").unwrap(), config.root_uri().unwrap().join("deno.json").unwrap(),
&deno_config::ConfigParseOptions::default(), &ConfigParseOptions::default(),
) )
.unwrap(), .unwrap(),
) )

View file

@ -49,7 +49,7 @@ impl JsrCacheResolver {
let info_by_name = DashMap::new(); let info_by_name = DashMap::new();
let mut workspace_scope_by_name = HashMap::new(); let mut workspace_scope_by_name = HashMap::new();
if let Some(config_data) = config_data { if let Some(config_data) = config_data {
for jsr_pkg_config in config_data.workspace.jsr_packages() { for jsr_pkg_config in config_data.member_dir.workspace.jsr_packages() {
let Some(exports) = &jsr_pkg_config.config_file.json.exports else { let Some(exports) = &jsr_pkg_config.config_file.json.exports else {
continue; continue;
}; };

View file

@ -2,7 +2,7 @@
use base64::Engine; use base64::Engine;
use deno_ast::MediaType; use deno_ast::MediaType;
use deno_config::workspace::Workspace; use deno_config::workspace::WorkspaceDirectory;
use deno_config::workspace::WorkspaceDiscoverOptions; use deno_config::workspace::WorkspaceDiscoverOptions;
use deno_core::anyhow::anyhow; use deno_core::anyhow::anyhow;
use deno_core::error::AnyError; use deno_core::error::AnyError;
@ -3556,27 +3556,30 @@ impl Inner {
let initial_cwd = config_data let initial_cwd = config_data
.and_then(|d| d.scope.to_file_path().ok()) .and_then(|d| d.scope.to_file_path().ok())
.unwrap_or_else(|| self.initial_cwd.clone()); .unwrap_or_else(|| self.initial_cwd.clone());
// todo: we need a way to convert config data to a Workspace let workspace = match config_data {
let workspace = Arc::new(Workspace::discover( Some(d) => d.member_dir.clone(),
deno_config::workspace::WorkspaceDiscoverStart::Paths(&[ None => Arc::new(WorkspaceDirectory::discover(
initial_cwd.clone() deno_config::workspace::WorkspaceDiscoverStart::Paths(&[
]), initial_cwd.clone()
&WorkspaceDiscoverOptions { ]),
fs: &DenoConfigFsAdapter::new(&deno_runtime::deno_fs::RealFs), &WorkspaceDiscoverOptions {
deno_json_cache: None, fs: &DenoConfigFsAdapter::new(&deno_runtime::deno_fs::RealFs),
pkg_json_cache: None, deno_json_cache: None,
config_parse_options: deno_config::ConfigParseOptions { pkg_json_cache: None,
include_task_comments: false, workspace_cache: None,
config_parse_options: deno_config::deno_json::ConfigParseOptions {
include_task_comments: false,
},
additional_config_file_names: &[],
discover_pkg_json: !has_flag_env_var("DENO_NO_PACKAGE_JSON"),
maybe_vendor_override: if force_global_cache {
Some(deno_config::workspace::VendorEnablement::Disable)
} else {
None
},
}, },
additional_config_file_names: &[], )?),
discover_pkg_json: !has_flag_env_var("DENO_NO_PACKAGE_JSON"), };
maybe_vendor_override: if force_global_cache {
Some(deno_config::workspace::VendorEnablement::Disable)
} else {
None
},
},
)?);
let cli_options = CliOptions::new( let cli_options = CliOptions::new(
Flags { Flags {
cache_path: Some(self.cache.deno_dir().root.clone()), cache_path: Some(self.cache.deno_dir().root.clone()),

View file

@ -115,7 +115,7 @@ impl LspScopeResolver {
))); )));
let npm_graph_resolver = graph_resolver.create_graph_npm_resolver(); let npm_graph_resolver = graph_resolver.create_graph_npm_resolver();
let graph_imports = config_data let graph_imports = config_data
.and_then(|d| d.workspace.to_compiler_option_types().ok()) .and_then(|d| d.member_dir.workspace.to_compiler_option_types().ok())
.map(|imports| { .map(|imports| {
Arc::new( Arc::new(
imports imports
@ -513,9 +513,9 @@ fn create_graph_resolver(
npm_resolver: Option<&Arc<dyn CliNpmResolver>>, npm_resolver: Option<&Arc<dyn CliNpmResolver>>,
node_resolver: Option<&Arc<CliNodeResolver>>, node_resolver: Option<&Arc<CliNodeResolver>>,
) -> Arc<CliGraphResolver> { ) -> Arc<CliGraphResolver> {
let workspace = config_data.map(|d| &d.workspace); let workspace = config_data.map(|d| &d.member_dir.workspace);
let unstable_sloppy_imports = let unstable_sloppy_imports =
workspace.is_some_and(|w| w.has_unstable("sloppy-imports")); workspace.is_some_and(|dir| dir.has_unstable("sloppy-imports"));
Arc::new(CliGraphResolver::new(CliGraphResolverOptions { Arc::new(CliGraphResolver::new(CliGraphResolverOptions {
node_resolver: node_resolver.cloned(), node_resolver: node_resolver.cloned(),
npm_resolver: npm_resolver.cloned(), npm_resolver: npm_resolver.cloned(),
@ -530,11 +530,12 @@ fn create_graph_resolver(
)) ))
}, },
), ),
maybe_jsx_import_source_config: workspace maybe_jsx_import_source_config: workspace.and_then(|workspace| {
.and_then(|cf| cf.to_maybe_jsx_import_source_config().ok().flatten()), workspace.to_maybe_jsx_import_source_config().ok().flatten()
}),
maybe_vendor_dir: config_data.and_then(|d| d.vendor_dir.as_ref()), maybe_vendor_dir: config_data.and_then(|d| d.vendor_dir.as_ref()),
bare_node_builtins_enabled: workspace bare_node_builtins_enabled: workspace
.is_some_and(|cf| cf.has_unstable("bare-node-builtins")), .is_some_and(|workspace| workspace.has_unstable("bare-node-builtins")),
sloppy_imports_resolver: unstable_sloppy_imports.then(|| { sloppy_imports_resolver: unstable_sloppy_imports.then(|| {
SloppyImportsResolver::new_without_stat_cache(Arc::new(deno_fs::RealFs)) SloppyImportsResolver::new_without_stat_cache(Arc::new(deno_fs::RealFs))
}), }),

View file

@ -5012,7 +5012,7 @@ impl UserPreferences {
// Only use workspace settings for quote style if there's no `deno.json`. // Only use workspace settings for quote style if there's no `deno.json`.
quote_preference: if config quote_preference: if config
.tree .tree
.workspace_member_ctx_for_specifier(specifier) .workspace_dir_for_specifier(specifier)
.is_some_and(|ctx| ctx.maybe_deno_json().is_some()) .is_some_and(|ctx| ctx.maybe_deno_json().is_some())
{ {
base_preferences.quote_preference base_preferences.quote_preference
@ -5407,13 +5407,13 @@ mod tests {
config config
.tree .tree
.inject_config_file( .inject_config_file(
deno_config::ConfigFile::new( deno_config::deno_json::ConfigFile::new(
&json!({ &json!({
"compilerOptions": ts_config, "compilerOptions": ts_config,
}) })
.to_string(), .to_string(),
temp_dir.uri().join("deno.json").unwrap(), temp_dir.uri().join("deno.json").unwrap(),
&deno_config::ConfigParseOptions::default(), &Default::default(),
) )
.unwrap(), .unwrap(),
) )

View file

@ -733,18 +733,13 @@ impl<'a> DenoCompileBinaryWriter<'a> {
InnerCliNpmResolverRef::Byonm(_) => { InnerCliNpmResolverRef::Byonm(_) => {
maybe_warn_different_system(&self.npm_system_info); maybe_warn_different_system(&self.npm_system_info);
let mut builder = VfsBuilder::new(root_path.to_path_buf())?; let mut builder = VfsBuilder::new(root_path.to_path_buf())?;
for pkg_json in cli_options.workspace.package_jsons() { for pkg_json in cli_options.workspace().package_jsons() {
builder.add_file_at_path(&pkg_json.path)?; builder.add_file_at_path(&pkg_json.path)?;
} }
// traverse and add all the node_modules directories in the workspace // traverse and add all the node_modules directories in the workspace
let mut pending_dirs = VecDeque::new(); let mut pending_dirs = VecDeque::new();
pending_dirs.push_back( pending_dirs.push_back(
cli_options cli_options.workspace().root_dir().to_file_path().unwrap(),
.workspace
.root_folder()
.0
.to_file_path()
.unwrap(),
); );
while let Some(pending_dir) = pending_dirs.pop_front() { while let Some(pending_dir) = pending_dirs.pop_front() {
let entries = fs::read_dir(&pending_dir).with_context(|| { let entries = fs::read_dir(&pending_dir).with_context(|| {

View file

@ -77,15 +77,15 @@ pub async fn compile(
graph graph
}; };
let ts_config_for_emit = let ts_config_for_emit = cli_options
cli_options.resolve_ts_config_for_emit(deno_config::TsConfigType::Emit)?; .resolve_ts_config_for_emit(deno_config::deno_json::TsConfigType::Emit)?;
let (transpile_options, emit_options) = let (transpile_options, emit_options) =
crate::args::ts_config_to_transpile_and_emit_options( crate::args::ts_config_to_transpile_and_emit_options(
ts_config_for_emit.ts_config, ts_config_for_emit.ts_config,
)?; )?;
let parser = parsed_source_cache.as_capturing_parser(); let parser = parsed_source_cache.as_capturing_parser();
let root_dir_url = resolve_root_dir_from_specifiers( let root_dir_url = resolve_root_dir_from_specifiers(
cli_options.workspace.root_folder().0, cli_options.workspace().root_dir(),
graph.specifiers().map(|(s, _)| s).chain( graph.specifiers().map(|(s, _)| s).chain(
cli_options cli_options
.node_modules_dir_path() .node_modules_dir_path()

View file

@ -187,32 +187,31 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
Default::default() Default::default()
}; };
let rewrite_map = if let Some(config_file) = let rewrite_map =
cli_options.workspace.resolve_start_ctx().maybe_deno_json() if let Some(config_file) = cli_options.start_dir.maybe_deno_json() {
{ let config = config_file.to_exports_config()?;
let config = config_file.to_exports_config()?;
let rewrite_map = config let rewrite_map = config
.clone() .clone()
.into_map() .into_map()
.into_keys() .into_keys()
.map(|key| { .map(|key| {
Ok(( Ok((
config.get_resolved(&key)?.unwrap(), config.get_resolved(&key)?.unwrap(),
key key
.strip_prefix('.') .strip_prefix('.')
.unwrap_or(&key) .unwrap_or(&key)
.strip_prefix('/') .strip_prefix('/')
.unwrap_or(&key) .unwrap_or(&key)
.to_owned(), .to_owned(),
)) ))
}) })
.collect::<Result<IndexMap<_, _>, AnyError>>()?; .collect::<Result<IndexMap<_, _>, AnyError>>()?;
Some(rewrite_map) Some(rewrite_map)
} else { } else {
None None
}; };
generate_docs_directory( generate_docs_directory(
doc_nodes_by_url, doc_nodes_by_url,

View file

@ -52,9 +52,9 @@ use crate::cache::IncrementalCache;
pub async fn format(flags: Flags, fmt_flags: FmtFlags) -> Result<(), AnyError> { pub async fn format(flags: Flags, fmt_flags: FmtFlags) -> Result<(), AnyError> {
if fmt_flags.is_stdin() { if fmt_flags.is_stdin() {
let cli_options = CliOptions::from_flags(flags)?; let cli_options = CliOptions::from_flags(flags)?;
let start_ctx = cli_options.workspace.resolve_start_ctx(); let start_dir = &cli_options.start_dir;
let fmt_config = start_ctx let fmt_config = start_dir
.to_fmt_config(FilePatterns::new_with_base(start_ctx.dir_path()))?; .to_fmt_config(FilePatterns::new_with_base(start_dir.dir_path()))?;
let fmt_options = FmtOptions::resolve(fmt_config, &fmt_flags); let fmt_options = FmtOptions::resolve(fmt_config, &fmt_flags);
return format_stdin( return format_stdin(
&fmt_flags, &fmt_flags,

View file

@ -3,6 +3,7 @@
use crate::args::resolve_no_prompt; use crate::args::resolve_no_prompt;
use crate::args::AddFlags; use crate::args::AddFlags;
use crate::args::CaData; use crate::args::CaData;
use crate::args::ConfigFlag;
use crate::args::Flags; use crate::args::Flags;
use crate::args::InstallFlags; use crate::args::InstallFlags;
use crate::args::InstallFlagsGlobal; use crate::args::InstallFlagsGlobal;
@ -14,7 +15,6 @@ use crate::factory::CliFactory;
use crate::http_util::HttpClientProvider; use crate::http_util::HttpClientProvider;
use crate::util::fs::canonicalize_path_maybe_not_exists; use crate::util::fs::canonicalize_path_maybe_not_exists;
use deno_config::ConfigFlag;
use deno_core::anyhow::Context; use deno_core::anyhow::Context;
use deno_core::error::generic_error; use deno_core::error::generic_error;
use deno_core::error::AnyError; use deno_core::error::AnyError;
@ -571,11 +571,11 @@ fn is_in_path(dir: &Path) -> bool {
mod tests { mod tests {
use super::*; use super::*;
use crate::args::ConfigFlag;
use crate::args::PermissionFlags; use crate::args::PermissionFlags;
use crate::args::UninstallFlagsGlobal; use crate::args::UninstallFlagsGlobal;
use crate::args::UnstableConfig; use crate::args::UnstableConfig;
use crate::util::fs::canonicalize_path; use crate::util::fs::canonicalize_path;
use deno_config::ConfigFlag;
use std::process::Command; use std::process::Command;
use test_util::testdata_path; use test_util::testdata_path;
use test_util::TempDir; use test_util::TempDir;

View file

@ -8,10 +8,10 @@ use deno_ast::ModuleSpecifier;
use deno_ast::ParsedSource; use deno_ast::ParsedSource;
use deno_ast::SourceRange; use deno_ast::SourceRange;
use deno_ast::SourceTextInfo; use deno_ast::SourceTextInfo;
use deno_config::deno_json::ConfigFile;
use deno_config::glob::FileCollector; use deno_config::glob::FileCollector;
use deno_config::glob::FilePatterns; use deno_config::glob::FilePatterns;
use deno_config::workspace::Workspace; use deno_config::workspace::WorkspaceDirectory;
use deno_config::workspace::WorkspaceMemberContext;
use deno_core::anyhow::anyhow; use deno_core::anyhow::anyhow;
use deno_core::anyhow::bail; use deno_core::anyhow::bail;
use deno_core::anyhow::Context; use deno_core::anyhow::Context;
@ -118,7 +118,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
let mut linter = WorkspaceLinter::new( let mut linter = WorkspaceLinter::new(
factory.caches()?.clone(), factory.caches()?.clone(),
factory.module_graph_creator().await?.clone(), factory.module_graph_creator().await?.clone(),
cli_options.workspace.clone(), cli_options.start_dir.clone(),
&cli_options.resolve_workspace_lint_options(&lint_flags)?, &cli_options.resolve_workspace_lint_options(&lint_flags)?,
); );
for paths_with_options in paths_with_options_batches { for paths_with_options in paths_with_options_batches {
@ -126,7 +126,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
.lint_files( .lint_files(
paths_with_options.options, paths_with_options.options,
lint_config.clone(), lint_config.clone(),
paths_with_options.ctx, paths_with_options.dir,
paths_with_options.paths, paths_with_options.paths,
) )
.await?; .await?;
@ -147,16 +147,16 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
let workspace_lint_options = let workspace_lint_options =
cli_options.resolve_workspace_lint_options(&lint_flags)?; cli_options.resolve_workspace_lint_options(&lint_flags)?;
let success = if is_stdin { let success = if is_stdin {
let start_ctx = cli_options.workspace.resolve_start_ctx(); let start_dir = &cli_options.start_dir;
let reporter_lock = Arc::new(Mutex::new(create_reporter( let reporter_lock = Arc::new(Mutex::new(create_reporter(
workspace_lint_options.reporter_kind, workspace_lint_options.reporter_kind,
))); )));
let lint_config = start_ctx let lint_config = start_dir
.to_lint_config(FilePatterns::new_with_base(start_ctx.dir_path()))?; .to_lint_config(FilePatterns::new_with_base(start_dir.dir_path()))?;
let lint_options = LintOptions::resolve(lint_config, &lint_flags); let lint_options = LintOptions::resolve(lint_config, &lint_flags);
let lint_rules = get_config_rules_err_empty( let lint_rules = get_config_rules_err_empty(
lint_options.rules, lint_options.rules,
start_ctx.maybe_deno_json().map(|c| c.as_ref()), start_dir.maybe_deno_json().map(|c| c.as_ref()),
)?; )?;
let file_path = cli_options.initial_cwd().join(STDIN_FILE_NAME); let file_path = cli_options.initial_cwd().join(STDIN_FILE_NAME);
let r = lint_stdin(&file_path, lint_rules.rules, deno_lint_config); let r = lint_stdin(&file_path, lint_rules.rules, deno_lint_config);
@ -171,7 +171,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
let mut linter = WorkspaceLinter::new( let mut linter = WorkspaceLinter::new(
factory.caches()?.clone(), factory.caches()?.clone(),
factory.module_graph_creator().await?.clone(), factory.module_graph_creator().await?.clone(),
cli_options.workspace.clone(), cli_options.start_dir.clone(),
&workspace_lint_options, &workspace_lint_options,
); );
let paths_with_options_batches = let paths_with_options_batches =
@ -181,7 +181,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
.lint_files( .lint_files(
paths_with_options.options, paths_with_options.options,
deno_lint_config.clone(), deno_lint_config.clone(),
paths_with_options.ctx, paths_with_options.dir,
paths_with_options.paths, paths_with_options.paths,
) )
.await?; .await?;
@ -197,7 +197,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
} }
struct PathsWithOptions { struct PathsWithOptions {
ctx: WorkspaceMemberContext, dir: WorkspaceDirectory,
paths: Vec<PathBuf>, paths: Vec<PathBuf>,
options: LintOptions, options: LintOptions,
} }
@ -210,11 +210,11 @@ fn resolve_paths_with_options_batches(
cli_options.resolve_lint_options_for_members(lint_flags)?; cli_options.resolve_lint_options_for_members(lint_flags)?;
let mut paths_with_options_batches = let mut paths_with_options_batches =
Vec::with_capacity(members_lint_options.len()); Vec::with_capacity(members_lint_options.len());
for (ctx, lint_options) in members_lint_options { for (dir, lint_options) in members_lint_options {
let files = collect_lint_files(cli_options, lint_options.files.clone())?; let files = collect_lint_files(cli_options, lint_options.files.clone())?;
if !files.is_empty() { if !files.is_empty() {
paths_with_options_batches.push(PathsWithOptions { paths_with_options_batches.push(PathsWithOptions {
ctx, dir,
paths: files, paths: files,
options: lint_options, options: lint_options,
}); });
@ -232,7 +232,7 @@ type WorkspaceModuleGraphFuture =
struct WorkspaceLinter { struct WorkspaceLinter {
caches: Arc<Caches>, caches: Arc<Caches>,
module_graph_creator: Arc<ModuleGraphCreator>, module_graph_creator: Arc<ModuleGraphCreator>,
workspace: Arc<Workspace>, workspace_dir: Arc<WorkspaceDirectory>,
reporter_lock: Arc<Mutex<Box<dyn LintReporter + Send>>>, reporter_lock: Arc<Mutex<Box<dyn LintReporter + Send>>>,
workspace_module_graph: Option<WorkspaceModuleGraphFuture>, workspace_module_graph: Option<WorkspaceModuleGraphFuture>,
has_error: Arc<AtomicFlag>, has_error: Arc<AtomicFlag>,
@ -243,7 +243,7 @@ impl WorkspaceLinter {
pub fn new( pub fn new(
caches: Arc<Caches>, caches: Arc<Caches>,
module_graph_creator: Arc<ModuleGraphCreator>, module_graph_creator: Arc<ModuleGraphCreator>,
workspace: Arc<Workspace>, workspace_dir: Arc<WorkspaceDirectory>,
workspace_options: &WorkspaceLintOptions, workspace_options: &WorkspaceLintOptions,
) -> Self { ) -> Self {
let reporter_lock = let reporter_lock =
@ -251,7 +251,7 @@ impl WorkspaceLinter {
Self { Self {
caches, caches,
module_graph_creator, module_graph_creator,
workspace, workspace_dir,
reporter_lock, reporter_lock,
workspace_module_graph: None, workspace_module_graph: None,
has_error: Default::default(), has_error: Default::default(),
@ -263,14 +263,14 @@ impl WorkspaceLinter {
&mut self, &mut self,
lint_options: LintOptions, lint_options: LintOptions,
lint_config: LintConfig, lint_config: LintConfig,
member_ctx: WorkspaceMemberContext, member_dir: WorkspaceDirectory,
paths: Vec<PathBuf>, paths: Vec<PathBuf>,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
self.file_count += paths.len(); self.file_count += paths.len();
let lint_rules = get_config_rules_err_empty( let lint_rules = get_config_rules_err_empty(
lint_options.rules, lint_options.rules,
member_ctx.maybe_deno_json().map(|c| c.as_ref()), member_dir.maybe_deno_json().map(|c| c.as_ref()),
)?; )?;
let incremental_cache = Arc::new(IncrementalCache::new( let incremental_cache = Arc::new(IncrementalCache::new(
self.caches.lint_incremental_cache_db(), self.caches.lint_incremental_cache_db(),
@ -282,7 +282,7 @@ impl WorkspaceLinter {
if lint_rules.no_slow_types { if lint_rules.no_slow_types {
if self.workspace_module_graph.is_none() { if self.workspace_module_graph.is_none() {
let module_graph_creator = self.module_graph_creator.clone(); let module_graph_creator = self.module_graph_creator.clone();
let packages = self.workspace.jsr_packages_for_publish(); let packages = self.workspace_dir.jsr_packages_for_publish();
self.workspace_module_graph = Some( self.workspace_module_graph = Some(
async move { async move {
module_graph_creator module_graph_creator
@ -297,7 +297,7 @@ impl WorkspaceLinter {
} }
let workspace_module_graph_future = let workspace_module_graph_future =
self.workspace_module_graph.as_ref().unwrap().clone(); self.workspace_module_graph.as_ref().unwrap().clone();
let publish_config = member_ctx.maybe_package_config(); let publish_config = member_dir.maybe_package_config();
if let Some(publish_config) = publish_config { if let Some(publish_config) = publish_config {
let has_error = self.has_error.clone(); let has_error = self.has_error.clone();
let reporter_lock = self.reporter_lock.clone(); let reporter_lock = self.reporter_lock.clone();
@ -989,7 +989,7 @@ fn sort_diagnostics(diagnostics: &mut [JsonLintDiagnostic]) {
fn get_config_rules_err_empty( fn get_config_rules_err_empty(
rules: LintRulesConfig, rules: LintRulesConfig,
maybe_config_file: Option<&deno_config::ConfigFile>, maybe_config_file: Option<&ConfigFile>,
) -> Result<ConfiguredRules, AnyError> { ) -> Result<ConfiguredRules, AnyError> {
let lint_rules = get_configured_rules(rules, maybe_config_file); let lint_rules = get_configured_rules(rules, maybe_config_file);
if lint_rules.rules.is_empty() { if lint_rules.rules.is_empty() {
@ -1026,7 +1026,7 @@ impl ConfiguredRules {
pub fn get_configured_rules( pub fn get_configured_rules(
rules: LintRulesConfig, rules: LintRulesConfig,
maybe_config_file: Option<&deno_config::ConfigFile>, maybe_config_file: Option<&ConfigFile>,
) -> ConfiguredRules { ) -> ConfiguredRules {
const NO_SLOW_TYPES_NAME: &str = "no-slow-types"; const NO_SLOW_TYPES_NAME: &str = "no-slow-types";
let implicit_no_slow_types = let implicit_no_slow_types =
@ -1060,9 +1060,7 @@ pub fn get_configured_rules(
} }
} }
fn get_default_tags( fn get_default_tags(maybe_config_file: Option<&ConfigFile>) -> Vec<String> {
maybe_config_file: Option<&deno_config::ConfigFile>,
) -> Vec<String> {
let mut tags = Vec::with_capacity(2); let mut tags = Vec::with_capacity(2);
tags.push("recommended".to_string()); tags.push("recommended".to_string());
if maybe_config_file.map(|c| c.is_package()).unwrap_or(false) { if maybe_config_file.map(|c| c.is_package()).unwrap_or(false) {

View file

@ -82,9 +82,9 @@ pub async fn publish(
let directory_path = cli_factory.cli_options().initial_cwd(); let directory_path = cli_factory.cli_options().initial_cwd();
let cli_options = cli_factory.cli_options(); let cli_options = cli_factory.cli_options();
let publish_configs = cli_options.workspace.jsr_packages_for_publish(); let publish_configs = cli_options.start_dir.jsr_packages_for_publish();
if publish_configs.is_empty() { if publish_configs.is_empty() {
match cli_options.workspace.resolve_start_ctx().maybe_deno_json() { match cli_options.start_dir.maybe_deno_json() {
Some(deno_json) => { Some(deno_json) => {
debug_assert!(!deno_json.is_package()); debug_assert!(!deno_json.is_package());
bail!( bail!(
@ -437,7 +437,7 @@ impl PublishPreparer {
let Some((scope, name_no_scope)) = name_no_at.split_once('/') else { let Some((scope, name_no_scope)) = name_no_at.split_once('/') else {
bail!("Invalid package name, use '@<scope_name>/<package_name> format"); bail!("Invalid package name, use '@<scope_name>/<package_name> format");
}; };
let file_patterns = package.member_ctx.to_publish_config()?.files; let file_patterns = package.member_dir.to_publish_config()?.files;
let tarball = deno_core::unsync::spawn_blocking({ let tarball = deno_core::unsync::spawn_blocking({
let diagnostics_collector = diagnostics_collector.clone(); let diagnostics_collector = diagnostics_collector.clone();

View file

@ -5,7 +5,7 @@ use std::path::PathBuf;
use std::sync::Arc; use std::sync::Arc;
use deno_ast::TextChange; use deno_ast::TextChange;
use deno_config::FmtOptionsConfig; use deno_config::deno_json::FmtOptionsConfig;
use deno_core::anyhow::anyhow; use deno_core::anyhow::anyhow;
use deno_core::anyhow::bail; use deno_core::anyhow::bail;
use deno_core::anyhow::Context; use deno_core::anyhow::Context;
@ -49,7 +49,7 @@ impl DenoConfigFormat {
} }
enum DenoOrPackageJson { enum DenoOrPackageJson {
Deno(Arc<deno_config::ConfigFile>, DenoConfigFormat), Deno(Arc<deno_config::deno_json::ConfigFile>, DenoConfigFormat),
Npm(Arc<deno_node::PackageJson>, Option<FmtOptionsConfig>), Npm(Arc<deno_node::PackageJson>, Option<FmtOptionsConfig>),
} }
@ -122,9 +122,9 @@ impl DenoOrPackageJson {
fn from_flags(flags: Flags) -> Result<(Self, CliFactory), AnyError> { fn from_flags(flags: Flags) -> Result<(Self, CliFactory), AnyError> {
let factory = CliFactory::from_flags(flags.clone())?; let factory = CliFactory::from_flags(flags.clone())?;
let options = factory.cli_options(); let options = factory.cli_options();
let start_ctx = options.workspace.resolve_start_ctx(); let start_dir = &options.start_dir;
match (start_ctx.maybe_deno_json(), start_ctx.maybe_pkg_json()) { match (start_dir.maybe_deno_json(), start_dir.maybe_pkg_json()) {
// when both are present, for now, // when both are present, for now,
// default to deno.json // default to deno.json
(Some(deno), Some(_) | None) => Ok(( (Some(deno), Some(_) | None) => Ok((
@ -140,13 +140,14 @@ impl DenoOrPackageJson {
(None, Some(_) | None) => { (None, Some(_) | None) => {
std::fs::write(options.initial_cwd().join("deno.json"), "{}\n") std::fs::write(options.initial_cwd().join("deno.json"), "{}\n")
.context("Failed to create deno.json file")?; .context("Failed to create deno.json file")?;
drop(factory); // drop to prevent use
log::info!("Created deno.json configuration file."); log::info!("Created deno.json configuration file.");
let factory = CliFactory::from_flags(flags.clone())?; let factory = CliFactory::from_flags(flags.clone())?;
let options = factory.cli_options().clone(); let options = factory.cli_options().clone();
let start_ctx = options.workspace.resolve_start_ctx(); let start_dir = &options.start_dir;
Ok(( Ok((
DenoOrPackageJson::Deno( DenoOrPackageJson::Deno(
start_ctx.maybe_deno_json().cloned().ok_or_else(|| { start_dir.maybe_deno_json().cloned().ok_or_else(|| {
anyhow!("config not found, but it was just created") anyhow!("config not found, but it was just created")
})?, })?,
DenoConfigFormat::Json, DenoConfigFormat::Json,

View file

@ -254,7 +254,7 @@ impl ReplSession {
)) ))
})?; })?;
let ts_config_for_emit = cli_options let ts_config_for_emit = cli_options
.resolve_ts_config_for_emit(deno_config::TsConfigType::Emit)?; .resolve_ts_config_for_emit(deno_config::deno_json::TsConfigType::Emit)?;
let (transpile_options, _) = let (transpile_options, _) =
crate::args::ts_config_to_transpile_and_emit_options( crate::args::ts_config_to_transpile_and_emit_options(
ts_config_for_emit.ts_config, ts_config_for_emit.ts_config,

View file

@ -8,8 +8,9 @@ use crate::factory::CliFactory;
use crate::npm::CliNpmResolver; use crate::npm::CliNpmResolver;
use crate::task_runner; use crate::task_runner;
use crate::util::fs::canonicalize_path; use crate::util::fs::canonicalize_path;
use deno_config::deno_json::Task;
use deno_config::workspace::TaskOrScript; use deno_config::workspace::TaskOrScript;
use deno_config::workspace::Workspace; use deno_config::workspace::WorkspaceDirectory;
use deno_config::workspace::WorkspaceTasksConfig; use deno_config::workspace::WorkspaceTasksConfig;
use deno_core::anyhow::bail; use deno_core::anyhow::bail;
use deno_core::anyhow::Context; use deno_core::anyhow::Context;
@ -30,8 +31,8 @@ pub async fn execute_script(
) -> Result<i32, AnyError> { ) -> Result<i32, AnyError> {
let factory = CliFactory::from_flags(flags)?; let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let start_ctx = cli_options.workspace.resolve_start_ctx(); let start_dir = &cli_options.start_dir;
if !start_ctx.has_deno_or_pkg_json() { if !start_dir.has_deno_or_pkg_json() {
bail!("deno task couldn't find deno.json(c). See https://deno.land/manual@v{}/getting_started/configuration_file", env!("CARGO_PKG_VERSION")) bail!("deno task couldn't find deno.json(c). See https://deno.land/manual@v{}/getting_started/configuration_file", env!("CARGO_PKG_VERSION"))
} }
let force_use_pkg_json = let force_use_pkg_json =
@ -44,7 +45,7 @@ pub async fn execute_script(
v == "1" v == "1"
}) })
.unwrap_or(false); .unwrap_or(false);
let tasks_config = start_ctx.to_tasks_config()?; let tasks_config = start_dir.to_tasks_config()?;
let tasks_config = if force_use_pkg_json { let tasks_config = if force_use_pkg_json {
tasks_config.with_only_pkg_json() tasks_config.with_only_pkg_json()
} else { } else {
@ -56,7 +57,7 @@ pub async fn execute_script(
None => { None => {
print_available_tasks( print_available_tasks(
&mut std::io::stdout(), &mut std::io::stdout(),
&cli_options.workspace, &cli_options.start_dir,
&tasks_config, &tasks_config,
)?; )?;
return Ok(1); return Ok(1);
@ -143,7 +144,7 @@ pub async fn execute_script(
if log::log_enabled!(log::Level::Error) { if log::log_enabled!(log::Level::Error) {
print_available_tasks( print_available_tasks(
&mut std::io::stderr(), &mut std::io::stderr(),
&cli_options.workspace, &cli_options.start_dir,
&tasks_config, &tasks_config,
)?; )?;
} }
@ -204,7 +205,7 @@ fn output_task(task_name: &str, script: &str) {
fn print_available_tasks( fn print_available_tasks(
writer: &mut dyn std::io::Write, writer: &mut dyn std::io::Write,
workspace: &Arc<Workspace>, workspace_dir: &Arc<WorkspaceDirectory>,
tasks_config: &WorkspaceTasksConfig, tasks_config: &WorkspaceTasksConfig,
) -> Result<(), std::io::Error> { ) -> Result<(), std::io::Error> {
writeln!(writer, "{}", colors::green("Available tasks:"))?; writeln!(writer, "{}", colors::green("Available tasks:"))?;
@ -228,7 +229,8 @@ fn print_available_tasks(
.as_ref() .as_ref()
.map(|config| { .map(|config| {
let is_root = !is_cwd_root_dir let is_root = !is_cwd_root_dir
&& config.folder_url == *workspace.root_folder().0.as_ref(); && config.folder_url
== *workspace_dir.workspace.root_dir().as_ref();
config config
.tasks .tasks
.iter() .iter()
@ -242,13 +244,10 @@ fn print_available_tasks(
.as_ref() .as_ref()
.map(|config| { .map(|config| {
let is_root = !is_cwd_root_dir let is_root = !is_cwd_root_dir
&& config.folder_url == *workspace.root_folder().0.as_ref(); && config.folder_url
== *workspace_dir.workspace.root_dir().as_ref();
config.tasks.iter().map(move |(k, v)| { config.tasks.iter().map(move |(k, v)| {
( (is_root, false, (k, Cow::Owned(Task::Definition(v.clone()))))
is_root,
false,
(k, Cow::Owned(deno_config::Task::Definition(v.clone()))),
)
}) })
}) })
.into_iter() .into_iter()
@ -275,10 +274,10 @@ fn print_available_tasks(
} }
)?; )?;
let definition = match task.as_ref() { let definition = match task.as_ref() {
deno_config::Task::Definition(definition) => definition, Task::Definition(definition) => definition,
deno_config::Task::Commented { definition, .. } => definition, Task::Commented { definition, .. } => definition,
}; };
if let deno_config::Task::Commented { comments, .. } = task.as_ref() { if let Task::Commented { comments, .. } = task.as_ref() {
let slash_slash = colors::italic_gray("//"); let slash_slash = colors::italic_gray("//");
for comment in comments { for comment in comments {
writeln!( writeln!(

View file

@ -53,16 +53,17 @@ pub async fn vendor(
validate_options(&mut cli_options, &output_dir)?; validate_options(&mut cli_options, &output_dir)?;
let factory = CliFactory::from_cli_options(Arc::new(cli_options)); let factory = CliFactory::from_cli_options(Arc::new(cli_options));
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
if cli_options.workspace.config_folders().len() > 1 { if cli_options.workspace().config_folders().len() > 1 {
bail!("deno vendor is not supported in a workspace. Set `\"vendor\": true` in the workspace deno.json file instead"); bail!("deno vendor is not supported in a workspace. Set `\"vendor\": true` in the workspace deno.json file instead");
} }
let entry_points = let entry_points =
resolve_entry_points(&vendor_flags, cli_options.initial_cwd())?; resolve_entry_points(&vendor_flags, cli_options.initial_cwd())?;
let jsx_import_source = let jsx_import_source = cli_options
cli_options.workspace.to_maybe_jsx_import_source_config()?; .workspace()
.to_maybe_jsx_import_source_config()?;
let module_graph_creator = factory.module_graph_creator().await?.clone(); let module_graph_creator = factory.module_graph_creator().await?.clone();
let workspace_resolver = factory.workspace_resolver().await?; let workspace_resolver = factory.workspace_resolver().await?;
let root_folder = cli_options.workspace.root_folder().1; let root_folder = cli_options.workspace().root_folder_configs();
let maybe_config_file = root_folder.deno_json.as_ref(); let maybe_config_file = root_folder.deno_json.as_ref();
let output = build::build(build::BuildInput { let output = build::build(build::BuildInput {
entry_points, entry_points,
@ -189,7 +190,7 @@ fn validate_options(
let import_map_specifier = options let import_map_specifier = options
.resolve_specified_import_map_specifier()? .resolve_specified_import_map_specifier()?
.or_else(|| { .or_else(|| {
let config_file = options.workspace.root_folder().1.deno_json.as_ref()?; let config_file = options.workspace().root_deno_json()?;
config_file config_file
.to_import_map_specifier() .to_import_map_specifier()
.ok() .ok()