ctb_formats_javascript/tsconfig.rs
1// SPDX-License-Identifier: AGPL-3.0-or-later AND MIT
2// SPDX-License-Identifier for parts derived from dlint: MIT
3/*
4This file is part of Collective Toolbox, a database and document workspace and utilities.
5Copyright (C) 2026 Collective Toolbox Developers
6Contact: info@collectivetoolbox.com
7
8This program is free software: you can redistribute it and/or modify it under
9the terms of the GNU Affero General Public License as published by the Free
10Software Foundation, either version 3 of the License, or (at your option) any
11later version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
16
17You should have received a copy of the GNU Affero General Public License along
18with this program. If not, see <https://www.gnu.org/licenses/>.
19*/
20
21// Derived from Deno's dlint (https://github.com/denoland/deno_lint).
22// For parts derived from dlint:
23// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
24
25// See additional licensing details at end of file.
26
27//! TypeScript configuration (`tsconfig.json`) parser and resolver.
28
29#[allow(
30 unused_imports,
31 clippy::wildcard_imports,
32 reason = "Standard workspace crate prelude"
33)]
34pub(crate) use ctb_utilities::*;
35
36use std::path::{Path, PathBuf};
37
38pub fn find_tsconfig(start_dir: &Path) -> Option<PathBuf> {
39 let mut dir = start_dir.to_path_buf();
40 loop {
41 let path = dir.join("tsconfig.json");
42 if path.exists() {
43 return Some(path);
44 }
45 if !dir.pop() {
46 break;
47 }
48 }
49 None
50}
51
52#[cfg(test)]
53#[allow(
54 clippy::panic,
55 clippy::expect_used,
56 clippy::unwrap_used,
57 clippy::unwrap_in_result,
58 clippy::panic_in_result_fn,
59 clippy::indexing_slicing,
60 clippy::arithmetic_side_effects,
61 reason = "Standard repository test boilerplate"
62)]
63mod tests {}
64
65/*
66Code from dlint is used under the following license:
67======
68
69MIT License
70
71Copyright (c) 2018-2024 the Deno authors
72
73Permission is hereby granted, free of charge, to any person obtaining a copy
74of this software and associated documentation files (the "Software"), to deal
75in the Software without restriction, including without limitation the rights
76to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
77copies of the Software, and to permit persons to whom the Software is
78furnished to do so, subject to the following conditions:
79
80The above copyright notice and this permission notice shall be included in all
81copies or substantial portions of the Software.
82
83THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
84IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
85FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
86AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
87LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
88OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
89SOFTWARE.
90*/