Skip to content

Commit d5ad9fa

Browse files
committed
lets test on workflow
1 parent 3b5da01 commit d5ad9fa

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

remove-broken-imports.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,44 @@ const exts = ['.js', '.ts', '.tsx'];
55
const targetDirs = ['api', 'ui', 'upload-api'];
66

77
function resolveImport(importPath, fileDir) {
8+
// Absolute or relative path
89
let basePath = path.resolve(fileDir, importPath);
910

10-
// 1. Direct file with extension
11-
if (fs.existsSync(basePath) && fs.statSync(basePath).isFile()) {
12-
return true;
13-
}
14-
15-
// 2. Try with extensions
16-
for (const ext of exts) {
17-
if (fs.existsSync(basePath + ext)) {
11+
// 1. If import has extension, check directly
12+
if (/\.[jt]sx?$/.test(importPath)) {
13+
if (fs.existsSync(basePath) && fs.statSync(basePath).isFile()) {
1814
return true;
1915
}
20-
}
21-
22-
// 3. Directory with index file
23-
if (fs.existsSync(basePath) && fs.statSync(basePath).isDirectory()) {
16+
} else {
17+
// 2. Try with extensions
2418
for (const ext of exts) {
25-
if (fs.existsSync(path.join(basePath, 'index' + ext))) {
19+
if (fs.existsSync(basePath + ext) && fs.statSync(basePath + ext).isFile()) {
2620
return true;
2721
}
2822
}
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+
}
2932
}
30-
3133
return false;
3234
}
3335

3436
function cleanImportsInFile(filePath) {
3537
let code = fs.readFileSync(filePath, 'utf-8');
3638
const fileDir = path.dirname(filePath);
3739

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

4043
let changed = false;
4144
code = code.replace(importRegex, (match, typeKeyword, importPath) => {
45+
// Ignore node_modules and built-in modules
4246
if (!importPath.startsWith('.') && !importPath.startsWith('/')) return match;
4347

4448
if (!resolveImport(importPath, fileDir)) {

upload-api/migration-wordpress/libs/contenttypemapper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { writeFile, writeFileAsync } = require('../utils/helper');
88
const restrictedUid = require('../utils');
99

1010

11+
1112
const { contentTypes: contentTypesConfig } = config.modules;
1213
const contentTypesFile = path.join(
1314
process.cwd(),

0 commit comments

Comments
 (0)