Skip to content

Commit 1af9c39

Browse files
authored
Merge pull request #643 from contentstack/feature/workflow
final testing
2 parents 0b33c8d + a3e5d9e commit 1af9c39

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

api/src/services/contentful.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import jsonRTE from "./contentful/jsonRTE.js";
1414
import { getAllLocales, getLogMessage } from "../utils/index.js";
1515
import customLogger from "../utils/custom-logger.utils.js";
1616

17-
18-
1917
const {
2018
DATA,
2119
// DIR

api/src/services/sitecore.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import { getLogMessage } from '../utils/index.js';
1313
import customLogger from '../utils/custom-logger.utils.js';
1414
import { getSafePath } from '../utils/sanitize-path.utils.js';
1515

16-
17-
1816
const append = 'a';
1917
const baseDirName = MIGRATION_DATA_CONFIG.DATA;
2018
const {

api/src/services/wordpress.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getLogMessage } from "../utils/index.js";
1010
import { v4 as uuidv4 } from "uuid";
1111
import { orgService } from "./org.service.js";
1212

13+
1314
const { JSDOM } = jsdom;
1415
const virtualConsole = new jsdom.VirtualConsole();
1516
// Get the current file's path

remove-broken-imports.js

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,59 @@ const fs = require('fs');
22
const path = require('path');
33

44
const exts = ['.js', '.ts', '.tsx'];
5-
const targetDirs = ['api', 'ui', 'upload-api'];
5+
const targetDirs = ['api'];
66

77
function resolveImport(importPath, fileDir) {
8-
// Absolute or relative path
9-
let basePath = path.resolve(fileDir, importPath);
8+
const absPath = path.resolve(fileDir, importPath);
109

11-
// 1. If import has extension, check directly
12-
if (/\.[jt]sx?$/.test(importPath)) {
13-
if (fs.existsSync(basePath) && fs.statSync(basePath).isFile()) {
10+
// 1. Check as-is (could be a file with or without extension)
11+
if (fs.existsSync(absPath) && fs.statSync(absPath).isFile()) {
12+
return true;
13+
}
14+
15+
// 2. If import has extension, check for aliasing (.js <-> .ts, .jsx <-> .tsx)
16+
const extMatch = importPath.match(/\.(js|jsx)$/);
17+
if (extMatch) {
18+
const tsLike = extMatch[1] === 'js'
19+
? importPath.replace(/\.js$/, '.ts')
20+
: importPath.replace(/\.jsx$/, '.tsx');
21+
const tsLikePath = path.resolve(fileDir, tsLike);
22+
if (fs.existsSync(tsLikePath) && fs.statSync(tsLikePath).isFile()) {
1423
return true;
1524
}
16-
} else {
17-
// 2. Try with extensions
25+
}
26+
27+
// 3. Try with extensions
28+
for (const ext of exts) {
29+
const withExt = absPath + ext;
30+
if (fs.existsSync(withExt) && fs.statSync(withExt).isFile()) {
31+
return true;
32+
}
33+
}
34+
35+
// 4. Directory with index file
36+
if (fs.existsSync(absPath) && fs.statSync(absPath).isDirectory()) {
1837
for (const ext of exts) {
19-
if (fs.existsSync(basePath + ext) && fs.statSync(basePath + ext).isFile()) {
38+
const idx = path.join(absPath, 'index' + ext);
39+
if (fs.existsSync(idx) && fs.statSync(idx).isFile()) {
2040
return true;
2141
}
2242
}
23-
// 3. Directory with index file
24-
if (fs.existsSync(basePath) && fs.statSync(basePath).isDirectory()) {
25-
for (const ext of exts) {
26-
const idx = path.join(basePath, 'index' + ext);
27-
if (fs.existsSync(idx) && fs.statSync(idx).isFile()) {
28-
return true;
29-
}
30-
}
31-
}
3243
}
44+
3345
return false;
3446
}
3547

48+
49+
3650
function cleanImportsInFile(filePath) {
3751
let code = fs.readFileSync(filePath, 'utf-8');
3852
const fileDir = path.dirname(filePath);
3953

40-
// Handles both regular and type-only imports
4154
const importRegex = /^import\s+(type\s+)?[\s\S]*?from\s+['"](.*?)['"];?.*$/gm;
4255

4356
let changed = false;
4457
code = code.replace(importRegex, (match, typeKeyword, importPath) => {
45-
// Ignore node_modules and built-in modules
4658
if (!importPath.startsWith('.') && !importPath.startsWith('/')) return match;
4759

4860
if (!resolveImport(importPath, fileDir)) {
@@ -77,7 +89,6 @@ function walkDir(dir, callback) {
7789
});
7890
}
7991

80-
// Only process the specified folders
8192
targetDirs.forEach(folder => {
8293
const absPath = path.join(process.cwd(), folder);
8394
walkDir(absPath, cleanImportsInFile);

0 commit comments

Comments
 (0)