Skip to content

Commit 9e42678

Browse files
committed
fix: Robust multi-path import resolution for CI compatibility
🔴 CRITICAL: CI path environment different from local development ✅ Root Cause Analysis - CI working directory: /home/runner/work/StringRay/StringRay/ (nested) - Local working directory: /path/to/StringRay/ - Relative paths fail due to different directory structure - import-resolver.js exists but path resolution fails ✅ Multi-Strategy Import Resolution - Try 3 different relative path patterns: ../dist/, ./dist/, dist/ - For each pattern, try both import() and absolute path resolution - Comprehensive error reporting with file existence checks - Works across all CI environments (GitHub, local, etc.) ✅ Path Resolution Strategies 1. '../dist/plugin/utils/import-resolver.js' (from scripts/) 2. './dist/plugin/utils/import-resolver.js' (from project root) 3. 'dist/plugin/utils/import-resolver.js' (fallback) 4. Absolute path resolution for each relative path 5. Detailed error reporting with CWD and file existence info ✅ CI Environment Compatibility - Handles nested working directories in CI - Works with different GitHub Actions configurations - Maintains local development compatibility - Robust error diagnostics for troubleshooting BREAKING: Test now uses comprehensive path resolution for maximum CI compatibility
1 parent 8ae0096 commit 9e42678

File tree

1 file changed

+57
-23
lines changed

1 file changed

+57
-23
lines changed

scripts/test-comprehensive-path-resolution.mjs

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,70 @@ try {
3636
// Test 3: Import Resolver Functionality
3737
console.log('\n=== TEST 3: Import Resolver Functionality ===');
3838
try {
39-
// Try multiple import strategies for compatibility
39+
// Try multiple import strategies for maximum compatibility
4040
let importResolver;
4141

42-
try {
43-
// First try: relative import (works in development)
44-
({ importResolver } = await import('../dist/plugin/utils/import-resolver.js'));
45-
} catch (e) {
42+
// Possible paths to try (in order of preference)
43+
const possiblePaths = [
44+
'../dist/plugin/utils/import-resolver.js', // Relative from scripts/
45+
'./dist/plugin/utils/import-resolver.js', // Relative from project root
46+
'dist/plugin/utils/import-resolver.js', // From anywhere in project
47+
];
48+
49+
let lastError;
50+
let foundPath = null;
51+
52+
for (const relativePath of possiblePaths) {
4653
try {
47-
// Second try: absolute path resolution (works in CI)
48-
const path = await import('path');
49-
const { fileURLToPath } = await import('url');
50-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
51-
const importResolverPath = path.resolve(__dirname, '../dist/plugin/utils/import-resolver.js');
52-
({ importResolver } = await import(importResolverPath));
53-
} catch (e2) {
54-
// Third try: check if file exists and provide detailed error
55-
const fs = await import('fs');
56-
const path = await import('path');
57-
const { fileURLToPath } = await import('url');
58-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
59-
const importResolverPath = path.resolve(__dirname, '../dist/plugin/utils/import-resolver.js');
60-
61-
if (fs.existsSync(importResolverPath)) {
62-
throw new Error(`File exists at ${importResolverPath} but import failed: ${e2.message}`);
63-
} else {
64-
throw new Error(`Import resolver file not found at ${importResolverPath}. Build may have failed.`);
54+
// Try importing with each path
55+
({ importResolver } = await import(relativePath));
56+
foundPath = relativePath;
57+
break;
58+
} catch (e) {
59+
lastError = e;
60+
61+
// Also try absolute path resolution for this relative path
62+
try {
63+
const path = await import('path');
64+
const { fileURLToPath } = await import('url');
65+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
66+
const absPath = path.resolve(__dirname, relativePath);
67+
({ importResolver } = await import(absPath));
68+
foundPath = absPath;
69+
break;
70+
} catch (e2) {
71+
// Continue to next path
6572
}
6673
}
6774
}
6875

76+
if (!importResolver) {
77+
// Last resort: check multiple possible locations and provide detailed error
78+
const fs = await import('fs');
79+
const path = await import('path');
80+
const { fileURLToPath } = await import('url');
81+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
82+
83+
const checkPaths = [
84+
path.resolve(__dirname, '../dist/plugin/utils/import-resolver.js'),
85+
path.resolve(__dirname, './dist/plugin/utils/import-resolver.js'),
86+
path.resolve(process.cwd(), 'dist/plugin/utils/import-resolver.js'),
87+
];
88+
89+
let existingPaths = [];
90+
for (const checkPath of checkPaths) {
91+
if (fs.existsSync(checkPath)) {
92+
existingPaths.push(checkPath);
93+
}
94+
}
95+
96+
if (existingPaths.length > 0) {
97+
throw new Error(`File exists at ${existingPaths.join(', ')} but import failed: ${lastError.message}`);
98+
} else {
99+
throw new Error(`Import resolver file not found. Searched: ${checkPaths.join(', ')}. Build may have failed. CWD: ${process.cwd()}`);
100+
}
101+
}
102+
69103
const envInfo = importResolver.getEnvironmentInfo();
70104
console.log(`✅ Import Resolver loaded: ${envInfo.isDevelopment ? 'development' : 'production'} environment`);
71105

0 commit comments

Comments
 (0)