Skip to main content

rigspark_cli/
retirement.rs

1const BROWSER_SCRIPTS: &[&str] = &[
2    "crates/rigspark-gui/static/calculator-runtime.js",
3    "crates/rigspark-gui/static/calculator-template.js",
4    "crates/rigspark-gui/static/chat.js",
5    "crates/rigspark-gui/static/generate.js",
6    "crates/rigspark-gui/static/markdown.js",
7    "crates/rigspark-gui/static/run-reducer.js",
8    "crates/rigspark-gui/static/sse.js",
9    "crates/rigspark-gui/static/telemetry.js",
10    "crates/rigspark-gui/static/workspace.js",
11    "site/main.js",
12    // Generated, inert catalog data (`cargo catalog-site`); `--check` keeps it reproducible.
13    "site/data/latest.js",
14    "apps/desktop/src-tauri/src/dialog-smoke.js",
15    "crates/rigspark-gui/vendor/dompurify.min.js",
16    "crates/rigspark-gui/vendor/katex/contrib/auto-render.min.js",
17    "crates/rigspark-gui/vendor/katex/katex.min.js",
18    "crates/rigspark-gui/vendor/marked.min.js",
19];
20
21// Minified vendors use `node:` as an object key, so only module-loading forms count.
22fn imports_node_api(text: &str) -> bool {
23    let compact: String = text
24        .chars()
25        .filter(|character| !character.is_whitespace())
26        .collect();
27    ["from", "require(", "import("].iter().any(|loader| {
28        ["\"node:", "'node:", "`node:"]
29            .iter()
30            .any(|quote| compact.contains(&format!("{loader}{quote}")))
31    })
32}
33
34pub fn check_file(path: &str, text: &str) -> Vec<&'static str> {
35    let name = path.rsplit('/').next().unwrap_or(path);
36    let extension = name.rsplit('.').next().unwrap_or("");
37    let mut failures = Vec::new();
38    if path.starts_with("src/") {
39        failures.push("root src directory must be empty after native migration");
40    }
41    let browser = BROWSER_SCRIPTS.contains(&path);
42    if ["ts", "tsx", "jsx", "mjs", "cjs"].contains(&extension) || (extension == "js" && !browser) {
43        failures.push("Node/TypeScript source or unreviewed JavaScript remains");
44    }
45    if [
46        "package.json",
47        "package-lock.json",
48        "npm-shrinkwrap.json",
49        "pnpm-lock.yaml",
50        "pnpm-workspace.yaml",
51        "yarn.lock",
52        "bun.lock",
53        "bun.lockb",
54        ".npmrc",
55        ".yarnrc",
56        ".yarnrc.yml",
57        ".nvmrc",
58        ".node-version",
59    ]
60    .contains(&name)
61        || (name.starts_with("tsconfig") && name.ends_with(".json"))
62    {
63        failures.push("Node package or toolchain configuration remains");
64    }
65    if browser
66        && (imports_node_api(text)
67            || text
68                .lines()
69                .next()
70                .is_some_and(|line| line.starts_with("#!") && line.contains("node")))
71    {
72        failures.push("browser asset invokes a Node runtime or imports Node APIs");
73    }
74    let executable_config = path.starts_with(".github/workflows/")
75        || ["sh", "ps1", "py", "cmd", "bat"].contains(&extension)
76        || ["Makefile", "justfile"].contains(&name)
77        || path == "apps/desktop/src-tauri/tauri.conf.json";
78    if executable_config {
79        let lower = text.to_ascii_lowercase();
80        if path.starts_with(".github/workflows/")
81            && [
82                "actions/checkout@",
83                "actions/configure-pages@",
84                "actions/upload-pages-artifact@",
85                "actions/deploy-pages@",
86                "actions/add-to-project@",
87                "actions/upload-artifact@",
88                "actions/download-artifact@",
89                "actions/cache@",
90                "actions/github-script@",
91                "softprops/action-gh-release@",
92            ]
93            .iter()
94            .any(|action| lower.contains(action))
95        {
96            failures.push("workflow still references a Node-backed action");
97        }
98        let has_command = lower
99            .split(|character: char| {
100                !character.is_ascii_alphanumeric() && character != '-' && character != '_'
101            })
102            .any(|word| {
103                [
104                    "node",
105                    "nodejs",
106                    "npm",
107                    "npx",
108                    "pnpm",
109                    "yarn",
110                    "bun",
111                    "setup-node",
112                    "electron",
113                ]
114                .contains(&word)
115            });
116        if has_command {
117            failures.push("executable configuration still references the Node toolchain");
118        }
119    }
120    failures
121}