Skip to content

Commit 7550161

Browse files
committed
flexible dynamic imports - devenv, build, etc...
(hard to see if this works in prod without a manual test)
1 parent f38ec3a commit 7550161

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

packages/db/src/core/navigators/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,25 @@ export abstract class ContentNavigator implements StudyContentSource {
2828
strategyData: ContentNavigationStrategyData
2929
): ContentNavigator {
3030
const implementingClass = strategyData.implementingClass;
31-
const NavigatorImpl = require(`./${implementingClass}.ts`).default;
31+
let NavigatorImpl;
32+
33+
// Try different extension variations
34+
const variations = ['', '.ts', '.js'];
35+
36+
for (const ext of variations) {
37+
try {
38+
NavigatorImpl = require(`./${implementingClass}${ext}`).default;
39+
break; // Break the loop if loading succeeds
40+
} catch (e) {
41+
// Continue to next variation if this one fails
42+
console.log(`Failed to load with extension ${ext}:`, e);
43+
}
44+
}
45+
46+
if (!NavigatorImpl) {
47+
throw new Error(`Could not load navigator implementation for: ${implementingClass}`);
48+
}
49+
3250
return new NavigatorImpl(user, course, strategyData);
3351
}
3452

0 commit comments

Comments
 (0)