ctb_formats_javascript/javascript.rs
1// SPDX-License-Identifier: AGPL-3.0-or-later
2/*
3This file is part of Collective Toolbox, a database and document workspace and utilities.
4Copyright (C) 2026 Collective Toolbox Developers
5Contact: info@collectivetoolbox.com
6
7This program is free software: you can redistribute it and/or modify it under
8the terms of the GNU Affero General Public License as published by the Free
9Software Foundation, either version 3 of the License, or (at your option) any
10later version.
11
12This program is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
15
16You should have received a copy of the GNU Affero General Public License along
17with this program. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20//! JavaScript and TypeScript toolchain, parsing, and linting runtime.
21
22#[allow(
23 unused_imports,
24 clippy::wildcard_imports,
25 reason = "Standard workspace crate prelude"
26)]
27pub(crate) use ctb_utilities::*;
28
29pub mod deno_config;
30pub mod diagnostics;
31pub mod js_lint;
32pub mod js_test;
33pub mod jsdoc;
34pub mod lint;
35pub mod project_files_resolver;
36pub mod string;
37pub mod ts_check;
38pub mod tsconfig;
39pub mod typescript;
40
41#[cfg(test)]
42pub fn get_js_data(key: &str) -> Option<Vec<u8>> {
43 ctb_utilities::load_manifest_fixture(env!("CARGO_MANIFEST_DIR"), key)
44}
45
46#[cfg(test)]
47#[allow(
48 clippy::panic,
49 clippy::expect_used,
50 clippy::unwrap_used,
51 clippy::unwrap_in_result,
52 clippy::panic_in_result_fn,
53 clippy::indexing_slicing,
54 clippy::arithmetic_side_effects,
55 reason = "Standard repository test boilerplate"
56)]
57mod tests {
58 #[crate::ctb_test]
59 fn test_get_bootstrapped_compiler() {
60 // let repo_path = super::typescript::get_default_ts_repo_path();
61 // if let Some(parent) = repo_path.parent() {
62 // let cached_tar = parent.join("TypeScript-built.tar");
63 // if cached_tar.exists() {
64 // println!("Skipping test_bootstrap_typescript because vendor/TypeScript-built.tar exists.");
65 // return;
66 // }
67 // }
68 // assert!(repo_path.exists(), "TypeScript repo path does not exist: {}", repo_path.display());
69 // let tarball = super::typescript::get_bootstrapped_compiler(&repo_path).unwrap();
70 let tarball = super::typescript::get_bootstrapped_compiler().unwrap();
71 assert!(!tarball.is_empty(), "Bootstrapped tarball is empty!");
72
73 let mut archive = tar::Archive::new(&tarball[..]);
74 let entries = archive.entries().unwrap();
75 let mut found_tsc = false;
76 let mut found_ts = false;
77 let mut found_lib = false;
78 for entry in entries {
79 let entry: tar::Entry<'_, &[u8]> = entry.unwrap();
80 let path = entry
81 .path()
82 .unwrap()
83 .to_string_lossy()
84 .into_owned()
85 .replace('\\', "/");
86 if path == "tsc/tsc.js" {
87 found_tsc = true;
88 }
89 if path == "typescript/typescript.js" {
90 found_ts = true;
91 }
92 if path == "tsc/lib.es5.d.ts" {
93 found_lib = true;
94 }
95 }
96 assert!(found_tsc, "tsc/tsc.js not found in tarball");
97 assert!(found_ts, "typescript/typescript.js not found in tarball");
98 assert!(found_lib, "tsc/lib.es5.d.ts not found in tarball");
99 }
100}