Skip to content

Commit 5ab8cce

Browse files
committed
refactor: derive project root in config.ts from __dirname
Replace the hardcoded `../../package.json` lookup with a layout-aware project-root resolution that works for both the source tree (modules/) and the compiled output (dist/modules/). The new helper detects the `dist/modules/` shape and walks up one extra level; otherwise it falls back to the parent of __dirname, which matches the previous behaviour for source. No behavioural change under the current tsconfig (rootDir: "." with outDir: "./dist" produces dist/modules/config.js, where both the old and new expressions resolve to the same path). The refactor future-proofs the lookup against a `rootDir: "modules"` change that would otherwise break version reads from the compiled bundle.
1 parent cb7ff3c commit 5ab8cce

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

modules/config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ function hasOwn(key: string): boolean {
3434
return hasProcess() && Object.prototype.hasOwnProperty.call(process.env, key);
3535
}
3636

37+
// Resolve project root — works from source (modules/) and dist (dist/modules/).
38+
const _MODULE_DIR$ = path.dirname(__dirname);
39+
const _PROJECT_ROOT$ = path.basename(__dirname) === 'modules' && path.basename(_MODULE_DIR$) === 'dist'
40+
? path.dirname(_MODULE_DIR$)
41+
: _MODULE_DIR$;
42+
3743
const Config: {
3844
// ── Bot identity ────────────────────────────────────────────────
3945
BOT_NAME: string | undefined;
@@ -102,7 +108,7 @@ const Config: {
102108
BOT_NAME: str('BOT_NAME'),
103109
PREFERRED_ACCOUNT: str('PREFERRED_ACCOUNT'),
104110
LIVE_BOT_NAME: str('LIVE_BOT_NAME'),
105-
VERSION: hasProcess() ? require(path.join(__dirname, '..', '..', 'package.json')).version : '0.0.0',
111+
VERSION: hasProcess() ? require(path.join(_PROJECT_ROOT$, 'package.json')).version : '0.0.0',
106112

107113
// ── Feature flags ───────────────────────────────────────────────
108114
DEXBOT_SKIP_PROFILE_VALIDATION: bool('DEXBOT_SKIP_PROFILE_VALIDATION'),

0 commit comments

Comments
 (0)