From 6771a129f53bfaf76ba89fa1365529b0ebd9bdea Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Wed, 27 Aug 2025 22:35:23 +0200 Subject: [PATCH] fixup: remove fix-imports --- .github/workflows/build.yml | 1 - package.json | 3 +- scripts/fix-imports.cjs | 75 ------------------------------------- 3 files changed, 1 insertion(+), 78 deletions(-) delete mode 100644 scripts/fix-imports.cjs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ff9785bd..10fe1c52 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,6 @@ jobs: - run: npm run lint:ci - run: npm run prettier - run: npm run update-translations - - run: npm run fix-imports - name: Fail if there are uncommitted changes run: | if [[ -n "$(git status --porcelain)" ]]; then diff --git a/package.json b/package.json index 65abb6ae..1659e0aa 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,7 @@ "lint:fix": "eslint --fix --ext .ts .", "prettier": "prettier --write .", "update-translations": "cd scripts && node update-translations.cjs", - "fix-imports": "cd scripts && node fix-imports.cjs", - "fix": "npm run update-translations && npm run fix-imports && npm run lint:fix" + "fix": "npm run update-translations && npm run lint:fix" }, "license": "GNU", "type": "module", diff --git a/scripts/fix-imports.cjs b/scripts/fix-imports.cjs deleted file mode 100644 index 7859ba44..00000000 --- a/scripts/fix-imports.cjs +++ /dev/null @@ -1,75 +0,0 @@ -/* eslint-disable */ -const fs = require("fs"); -const path = require("path"); - -const root = path.join(process.cwd(), ".."); - -function listFiles(dir) { - const entries = fs.readdirSync(dir, { withFileTypes: true }); - let results = []; - for (const entry of entries) { - const fullPath = path.join(dir, entry.name); - if (entry.isDirectory()) { - results = results.concat(listFiles(fullPath)); - } else { - results.push(fullPath); - } - } - return results; -} - -const files = listFiles(path.join(root, "src")); - -for (const file of files) { - let content; - try { - content = fs.readFileSync(file, "utf8"); - } catch (e) { - continue; - } - const dir = path.dirname(file); - const fixedContent = content.replaceAll(/from "([^"]+)";/g, (sub, importPath) => { - if (importPath.startsWith("@/") || importPath.startsWith(".")) { - const base = importPath.startsWith("@/") - ? path.join(root, importPath.slice(2)) - : path.resolve(dir, importPath); - let target = base; - - if (fs.existsSync(target)) { - const stat = fs.statSync(target); - if (stat.isDirectory()) { - if (fs.existsSync(path.join(target, "index.ts"))) { - target = path.join(target, "index.ts"); - } else { - return sub; - } - } else { - const ext = path.extname(target); - if (!ext) { - target += ".ts"; - } - } - } else if (fs.existsSync(target + ".ts")) { - target += ".ts"; - } else if (fs.existsSync(path.join(target, "index.ts"))) { - target = path.join(target, "index.ts"); - } else { - return sub; - } - - let relative = path.relative(dir, target).replace(/\\/g, "/"); - if (!path.extname(relative)) { - relative += ".ts"; - } - if (!relative.startsWith(".")) { - relative = "./" + relative; - } - console.log(`${importPath} -> ${relative}`); - return sub.split(importPath).join(relative); - } - return sub; - }); - if (content != fixedContent) { - fs.writeFileSync(file, fixedContent, "utf8"); - } -}