diff --git a/api/src/services/contentful.service.ts b/api/src/services/contentful.service.ts index 3e8bc410e..fb220820b 100644 --- a/api/src/services/contentful.service.ts +++ b/api/src/services/contentful.service.ts @@ -14,8 +14,6 @@ import jsonRTE from "./contentful/jsonRTE.js"; import { getAllLocales, getLogMessage } from "../utils/index.js"; import customLogger from "../utils/custom-logger.utils.js"; - - const { DATA, // DIR diff --git a/api/src/services/sitecore.service.ts b/api/src/services/sitecore.service.ts index 40f8a0e9e..539291442 100644 --- a/api/src/services/sitecore.service.ts +++ b/api/src/services/sitecore.service.ts @@ -13,8 +13,6 @@ import { getLogMessage } from '../utils/index.js'; import customLogger from '../utils/custom-logger.utils.js'; import { getSafePath } from '../utils/sanitize-path.utils.js'; - - const append = 'a'; const baseDirName = MIGRATION_DATA_CONFIG.DATA; const { diff --git a/api/src/services/wordpress.service.ts b/api/src/services/wordpress.service.ts index 72b517c6e..efaff7778 100644 --- a/api/src/services/wordpress.service.ts +++ b/api/src/services/wordpress.service.ts @@ -10,6 +10,7 @@ import { getLogMessage } from "../utils/index.js"; import { v4 as uuidv4 } from "uuid"; import { orgService } from "./org.service.js"; + const { JSDOM } = jsdom; const virtualConsole = new jsdom.VirtualConsole(); // Get the current file's path diff --git a/remove-broken-imports.js b/remove-broken-imports.js index 1c872d412..f60702305 100644 --- a/remove-broken-imports.js +++ b/remove-broken-imports.js @@ -2,47 +2,59 @@ const fs = require('fs'); const path = require('path'); const exts = ['.js', '.ts', '.tsx']; -const targetDirs = ['api', 'ui', 'upload-api']; +const targetDirs = ['api']; function resolveImport(importPath, fileDir) { - // Absolute or relative path - let basePath = path.resolve(fileDir, importPath); + const absPath = path.resolve(fileDir, importPath); - // 1. If import has extension, check directly - if (/\.[jt]sx?$/.test(importPath)) { - if (fs.existsSync(basePath) && fs.statSync(basePath).isFile()) { + // 1. Check as-is (could be a file with or without extension) + if (fs.existsSync(absPath) && fs.statSync(absPath).isFile()) { + return true; + } + + // 2. If import has extension, check for aliasing (.js <-> .ts, .jsx <-> .tsx) + const extMatch = importPath.match(/\.(js|jsx)$/); + if (extMatch) { + const tsLike = extMatch[1] === 'js' + ? importPath.replace(/\.js$/, '.ts') + : importPath.replace(/\.jsx$/, '.tsx'); + const tsLikePath = path.resolve(fileDir, tsLike); + if (fs.existsSync(tsLikePath) && fs.statSync(tsLikePath).isFile()) { return true; } - } else { - // 2. Try with extensions + } + + // 3. Try with extensions + for (const ext of exts) { + const withExt = absPath + ext; + if (fs.existsSync(withExt) && fs.statSync(withExt).isFile()) { + return true; + } + } + + // 4. Directory with index file + if (fs.existsSync(absPath) && fs.statSync(absPath).isDirectory()) { for (const ext of exts) { - if (fs.existsSync(basePath + ext) && fs.statSync(basePath + ext).isFile()) { + const idx = path.join(absPath, 'index' + ext); + if (fs.existsSync(idx) && fs.statSync(idx).isFile()) { return true; } } - // 3. Directory with index file - if (fs.existsSync(basePath) && fs.statSync(basePath).isDirectory()) { - for (const ext of exts) { - const idx = path.join(basePath, 'index' + ext); - if (fs.existsSync(idx) && fs.statSync(idx).isFile()) { - return true; - } - } - } } + return false; } + + function cleanImportsInFile(filePath) { let code = fs.readFileSync(filePath, 'utf-8'); const fileDir = path.dirname(filePath); - // Handles both regular and type-only imports const importRegex = /^import\s+(type\s+)?[\s\S]*?from\s+['"](.*?)['"];?.*$/gm; let changed = false; code = code.replace(importRegex, (match, typeKeyword, importPath) => { - // Ignore node_modules and built-in modules if (!importPath.startsWith('.') && !importPath.startsWith('/')) return match; if (!resolveImport(importPath, fileDir)) { @@ -77,7 +89,6 @@ function walkDir(dir, callback) { }); } -// Only process the specified folders targetDirs.forEach(folder => { const absPath = path.join(process.cwd(), folder); walkDir(absPath, cleanImportsInFile);