-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-paths.js
More file actions
50 lines (40 loc) · 1.49 KB
/
Copy pathdebug-paths.js
File metadata and controls
50 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Debug script to test Next.js path normalization
*/
import { join } from 'path';
function normalizePath(filePath, targetDir) {
// Remove leading ./ or /
let normalized = filePath.replace(/^\.?\//, '');
// Extract the last part of targetDir (e.g., "web" from "./generated/web")
const targetDirParts = targetDir.replace(/^\.?\//, '').split('/');
// Try to find and remove common prefixes
// Check for patterns like: "generated/web/src/App.jsx" when targetDir is "./generated/web"
for (let i = targetDirParts.length; i > 0; i--) {
const prefix = targetDirParts.slice(-i).join('/') + '/';
if (normalized.startsWith(prefix)) {
normalized = normalized.substring(prefix.length);
break;
}
}
return normalized;
}
// Simulate Next.js scenario
const targetDir = './generated/web';
const testCases = [
'generated/web/app/page.tsx',
'generated/web/app/layout.tsx',
'generated/web/package.json',
'app/page.tsx',
'./generated/web/app/page.tsx',
'/generated/web/components/Button.tsx',
];
console.log('Target Directory:', targetDir);
console.log('='.repeat(80));
for (const filePath of testCases) {
const normalized = normalizePath(filePath, targetDir);
const final = join(targetDir, normalized);
console.log('\nOriginal path:', filePath);
console.log('Normalized:', normalized);
console.log('Final path:', final);
console.log('Has nested?:', final.includes('generated/web/generated/web'));
}