Skip to content

Commit ba9131c

Browse files
authored
fix: correctly discover config file when specified from config flag (#80)
1 parent 3ca3fb9 commit ba9131c

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

rs_lib/src/lib.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use deno_config::workspace::WorkspaceDiscoverOptions;
66
use deno_config::workspace::WorkspaceDiscoverStart;
77
use serde::Serialize;
88
use std::path::PathBuf;
9+
use sys_traits::FsMetadata;
910
use url::Url;
1011
use wasm_bindgen::prelude::*;
1112

@@ -35,10 +36,26 @@ fn inner_resolve_config(
3536
) -> Result<ConfigLookup, anyhow::Error> {
3637
let real_sys = sys_traits::impls::RealSys;
3738
let root_path = resolve_absolute_path(root_path)?;
38-
let root_paths = [root_path.clone()];
39+
40+
// When --config points to a file (not a directory), use ConfigFile
41+
// discovery so non-standard filenames like deno-staging.json work.
42+
let is_config_file = real_sys.fs_is_file(&root_path).unwrap_or(false);
43+
let dir_path = if is_config_file {
44+
root_path.parent().unwrap().to_path_buf()
45+
} else {
46+
root_path.clone()
47+
};
48+
49+
let dir_paths = [dir_path.clone()];
50+
let discover_start = if is_config_file {
51+
WorkspaceDiscoverStart::ConfigFile(&root_path)
52+
} else {
53+
WorkspaceDiscoverStart::Paths(&dir_paths)
54+
};
55+
3956
let workspace_dir = WorkspaceDirectory::discover(
4057
&real_sys,
41-
WorkspaceDiscoverStart::Paths(&root_paths),
58+
discover_start,
4259
&WorkspaceDiscoverOptions {
4360
additional_config_file_names: &[],
4461
deno_json_cache: None,
@@ -49,11 +66,11 @@ fn inner_resolve_config(
4966
},
5067
)?;
5168

52-
let mut pattern = FilePatterns::new_with_base(root_path.clone());
69+
let mut pattern = FilePatterns::new_with_base(dir_path.clone());
5370

5471
if !ignore_paths.is_empty() {
5572
let exclude = PathOrPatternSet::from_exclude_relative_path_or_patterns(
56-
&root_path,
73+
&dir_path,
5774
&ignore_paths,
5875
)?;
5976
pattern
@@ -75,7 +92,7 @@ fn inner_resolve_config(
7592
"workspace_dir.to_deploy_config should have resolved a specifier",
7693
);
7794
let files =
78-
collect_files(&real_sys, root_path, config.files, allow_node_modules);
95+
collect_files(&real_sys, dir_path, config.files, allow_node_modules);
7996
Ok(ConfigLookup {
8097
path: Some(specifier),
8198
files,
@@ -92,8 +109,8 @@ fn inner_resolve_config(
92109
path,
93110
files: collect_files(
94111
&real_sys,
95-
root_path.clone(),
96-
FilePatterns::new_with_base(root_path),
112+
dir_path.clone(),
113+
FilePatterns::new_with_base(dir_path),
97114
allow_node_modules,
98115
),
99116
})

0 commit comments

Comments
 (0)