File tree Expand file tree Collapse file tree 2 files changed +27
-12
lines changed Expand file tree Collapse file tree 2 files changed +27
-12
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
2
* Utility to detect if the fb directory exists
3
- * This checks for the existence of the exists marker file in the fb directory
3
+ * This checks for the existence of the internal_utils file in the fb directory
4
4
*/
5
5
6
6
export const checkFbDirectoryExists = async ( ) : Promise < boolean > => {
7
7
try {
8
- // Try to fetch the exists marker file in the fb directory
9
- const response = await fetch ( '/fb/exists' , { method : 'HEAD' } ) ;
10
- return response . ok ;
8
+ // Try to fetch the actual internal_utils file in the fb directory
9
+ const response = await fetch ( './fb/internal_utils.ts' , { method : 'HEAD' } ) ;
10
+
11
+ // Check if we got a successful response AND it's not HTML content
12
+ // Vite dev server returns 200 + HTML (index.html) for missing files as SPA fallback
13
+ const contentType = response . headers . get ( 'content-type' ) || '' ;
14
+ const isHtmlFallback = contentType . includes ( 'text/html' ) ;
15
+
16
+ // Only consider it successful if we get 200 AND it's not HTML fallback
17
+ return response . ok && ! isHtmlFallback ;
11
18
} catch ( error ) {
12
19
// If the request fails, the directory likely doesn't exist
13
20
return false ;
14
21
}
15
- } ;
22
+ } ;
Original file line number Diff line number Diff line change 1
1
/**
2
2
* Safe dynamic import utility that handles missing modules gracefully
3
- * This avoids build-time module resolution issues
3
+ * This avoids build-time module resolution issues for OSS/internal builds
4
4
*/
5
5
6
6
/**
7
7
* Safely imports a module by path, returning null if it doesn't exist
8
- * Uses Function constructor to avoid static analysis
8
+ * Uses string concatenation to bypass static analysis while maintaining proper path resolution
9
9
*/
10
10
export async function safeImport ( modulePath : string ) : Promise < any | null > {
11
11
try {
12
- // Use Function constructor to create dynamic import
13
- // This completely bypasses static analysis
14
- const dynamicImport = new Function ( 'path' , 'return import(path)' ) ;
15
- const module = await dynamicImport ( modulePath ) ;
12
+ // Adjust path to account for safeImport.ts being in the utils directory
13
+ // When called from App.tsx with './utils/fb/internal_utils',
14
+ // we need to convert it to './fb/internal_utils' since we're already in utils/
15
+ let adjustedPath = modulePath ;
16
+ if ( modulePath . startsWith ( './utils/' ) ) {
17
+ adjustedPath = './' + modulePath . substring ( './utils/' . length ) ;
18
+ }
19
+
20
+ // Use string concatenation to create dynamic import path
21
+ // This bypasses static analysis while maintaining proper module resolution
22
+ const dynamicPath = '' + adjustedPath ;
23
+ const module = await import ( /* @vite -ignore */ dynamicPath ) ;
16
24
return module ;
17
25
} catch ( error ) {
18
26
console . warn ( `Module ${ modulePath } not available:` , error ) ;
19
27
return null ;
20
28
}
21
- }
29
+ }
You can’t perform that action at this time.
0 commit comments