Skip to content

Commit 6ea43b5

Browse files
committed
fix: path detection for version.ts
1 parent 8a3461c commit 6ea43b5

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

packages/apps-engine/src/definition/version.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
* without relying on filesystem path traversal.
55
*
66
* Uses require() instead of a static import so TypeScript does not resolve the path
7-
* at compile time. The compiled output lands at definition/version.js, so
8-
* '../package.json' correctly points to the package root at runtime.
7+
* at compile time.
8+
*
9+
* When running for tests, using ts-node, package.json is located two levels above the current file.
10+
* When running in production, package.json is located one level above the compiled version of this file.
911
*/
10-
// eslint-disable-next-line @typescript-eslint/no-require-imports
11-
export const ENGINE_VERSION: string = (require('../package.json') as { version: string }).version;
12+
const runningFromSource = __dirname.endsWith('src/definition');
13+
const requirePath = runningFromSource ? '../../package.json' : '../package.json';
14+
15+
export const ENGINE_VERSION: string = require(requirePath).version;

0 commit comments

Comments
 (0)