Skip to content

Commit bdb5d73

Browse files
d-gubertclaude
andcommitted
feat(apps-engine): export ENGINE_VERSION from definition layer
Adds `src/definition/version.ts` which reads the package version via `resolveJsonModule` and exports it as `ENGINE_VERSION`. Replaces `AppPackageParser.getEngineVersion()` — which resolved the version by traversing the filesystem relative to `__dirname` — with a direct import of `ENGINE_VERSION`. This removes the assumption that `package.json` lives at a predictable relative path, which will break when `AppPackageParser` moves to a different package during the apps-engine split. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f621848 commit bdb5d73

3 files changed

Lines changed: 11 additions & 22 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { version } from '../../package.json';
2+
3+
/**
4+
* The version of the Apps-Engine package.
5+
* Consumed by host-side code (e.g. AppPackageParser) to validate app compatibility
6+
* without relying on filesystem path traversal.
7+
*/
8+
export const ENGINE_VERSION: string = version;

packages/apps-engine/src/server/compiler/AppPackageParser.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as fs from 'fs';
21
import * as path from 'path';
32

43
import * as AdmZip from 'adm-zip';
@@ -7,6 +6,7 @@ import { v4 as uuidv4 } from 'uuid';
76

87
import { AppImplements } from '.';
98
import type { IAppInfo } from '../../definition/metadata/IAppInfo';
9+
import { ENGINE_VERSION } from '../../definition/version';
1010
import { RequiredApiVersionError } from '../errors';
1111
import type { IParseAppPackageResult } from './IParseAppPackageResult';
1212

@@ -15,11 +15,7 @@ export class AppPackageParser {
1515

1616
private allowedIconExts: Array<string> = ['.png', '.jpg', '.jpeg', '.gif'];
1717

18-
private appsEngineVersion: string;
19-
20-
constructor() {
21-
this.appsEngineVersion = this.getEngineVersion();
22-
}
18+
private appsEngineVersion: string = ENGINE_VERSION;
2319

2420
public async unpackageApp(appPackage: Buffer): Promise<IParseAppPackageResult> {
2521
const zip = new AdmZip(appPackage);
@@ -144,20 +140,4 @@ export class AppPackageParser {
144140
return `data:image/${ext.replace('.', '')};base64,${base64}`;
145141
}
146142

147-
private getEngineVersion(): string {
148-
const devLocation = path.join(__dirname, '../../../package.json');
149-
const prodLocation = path.join(__dirname, '../../package.json');
150-
151-
let info: { version: string };
152-
153-
if (fs.existsSync(devLocation)) {
154-
info = JSON.parse(fs.readFileSync(devLocation, 'utf8'));
155-
} else if (fs.existsSync(prodLocation)) {
156-
info = JSON.parse(fs.readFileSync(prodLocation, 'utf8'));
157-
} else {
158-
throw new Error('Could not find the Apps TypeScript Definition Package Version!');
159-
}
160-
161-
return info.version.replace(/^[^0-9]/, '').split('-')[0];
162-
}
163143
}

packages/apps-engine/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"emitDecoratorMetadata": true,
1111
"experimentalDecorators": true,
1212
"moduleResolution": "node",
13+
"resolveJsonModule": true,
1314
"types": ["node"],
1415
"lib": ["es2017", "dom"],
1516
"rootDir": "./src",

0 commit comments

Comments
 (0)