Skip to content

Commit e20ee2c

Browse files
committed
improve robustness of asset lookup...
1 parent 5fce075 commit e20ee2c

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

packages/express/src/design-docs.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,42 @@ function emit(key?: unknown, value?: unknown): [unknown, unknown] {
1515
const __filename = fileURLToPath(import.meta.url);
1616
const __dirname = dirname(__filename);
1717

18-
// Load design documents with absolute paths
18+
// Dual resolution strategy for assets
19+
function getAssetPath(assetName: string): string {
20+
// Strategy 1: Development mode - assets in parent directory
21+
const devModePath = join(__dirname, '..', 'assets', assetName);
22+
if (fileSystem.existsSync(devModePath)) {
23+
return devModePath;
24+
}
25+
26+
// Strategy 2: Built module mode - assets in same directory
27+
const moduleModePath = join(__dirname, 'assets', assetName);
28+
if (fileSystem.existsSync(moduleModePath)) {
29+
return moduleModePath;
30+
}
31+
32+
// Fallback error with helpful context
33+
throw new Error(
34+
`Asset '${assetName}' not found. Tried:\n` +
35+
` Dev mode: ${devModePath}\n` +
36+
` Module mode: ${moduleModePath}\n` +
37+
` Current __dirname: ${__dirname}`
38+
);
39+
}
40+
41+
// Load design documents with dual resolution
1942
export const classroomDbDesignDoc = fileSystem.readFileSync(
20-
join(__dirname, 'assets', 'classroomDesignDoc.js'),
43+
getAssetPath('classroomDesignDoc.js'),
2144
'utf-8'
2245
);
2346

2447
export const courseDBDesignDoc = fileSystem.readFileSync(
25-
join(__dirname, 'assets', 'get-tagsDesignDoc.json'),
48+
getAssetPath('get-tagsDesignDoc.json'),
2649
'utf-8'
2750
);
2851

2952
export const courseValidateDocUpdate = fileSystem.readFileSync(
30-
join(__dirname, 'assets', 'courseValidateDocUpdate.js'),
53+
getAssetPath('courseValidateDocUpdate.js'),
3154
'utf-8'
3255
);
3356

0 commit comments

Comments
 (0)