Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions api/src/services/contentful.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions api/src/services/sitecore.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions api/src/services/wordpress.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 32 additions & 21 deletions remove-broken-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down
Loading