Skip to content

Commit 497b8d9

Browse files
authored
Fix reading server package version (#124)
1 parent 26c9b0f commit 497b8d9

File tree

1 file changed

+2
-16
lines changed
  • packages/open-collaboration-server/src

1 file changed

+2
-16
lines changed

packages/open-collaboration-server/src/app.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,18 @@
66

77
import 'reflect-metadata';
88
import * as crypto from 'node:crypto';
9-
import * as fs from 'node:fs';
10-
import * as path from 'node:path';
11-
import * as url from 'node:url';
129
import { program } from 'commander';
1310
import serverModule from './inversify-module.js';
1411
import { Container } from 'inversify';
1512
import { initializeProtocol } from 'open-collaboration-protocol';
1613
import { CollaborationServer } from './collaboration-server.js';
1714
import { ConfigurationFile } from './utils/configuration.js';
15+
import pck from '../package.json' with { type: 'json' };
1816

1917
initializeProtocol({
2018
cryptoModule: crypto.webcrypto
2119
});
2220

23-
// This is a replacement for `__dirname`
24-
function getDirname(): string {
25-
return url.fileURLToPath(new URL('.', import.meta.url));
26-
}
27-
28-
function getVersion(): string {
29-
const ownPackagePath = path.resolve(getDirname(), '..', 'package.json');
30-
const packString = fs.readFileSync(ownPackagePath, { encoding: 'utf-8' });
31-
const pack = JSON.parse(packString);
32-
return pack.version;
33-
}
34-
3521
function startServer(options: { port: number, hostname: string, config: string }) {
3622
const container = new Container();
3723
container.bind(ConfigurationFile).toConstantValue(options.config);
@@ -45,7 +31,7 @@ process.on('unhandledRejection', (reason, promise) => {
4531
});
4632

4733
program
48-
.version(getVersion())
34+
.version(pck.version)
4935
.option('-p, --port <number>', 'Port to listen on', parseInt, 8100)
5036
.option('-h, --hostname <string>', 'Hostname to bind to', 'localhost')
5137
.option('-c, --config <string>', 'Path to the configuration file')

0 commit comments

Comments
 (0)