@actual-app/sync-server 25.6.0 → 25.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/build/src/app.js +30 -7
  2. package/package.json +2 -2
package/build/src/app.js CHANGED
@@ -1,5 +1,6 @@
1
- import { createRequire } from 'module';
2
1
  import fs, { readFileSync } from 'node:fs';
2
+ import { join, resolve } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
3
4
  import bodyParser from 'body-parser';
4
5
  import cors from 'cors';
5
6
  import express from 'express';
@@ -50,14 +51,36 @@ app.get('/mode', (req, res) => {
50
51
  res.send(config.get('mode'));
51
52
  });
52
53
  app.get('/info', (_req, res) => {
53
- const require = createRequire(import.meta.url);
54
- const packageJsonPath = require.resolve('@actual-app/sync-server/package.json');
55
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
54
+ function findPackageJson(startDir) {
55
+ // find the nearest package.json file while traversing up the directory tree
56
+ let currentPath = startDir;
57
+ let directoriesSearched = 0;
58
+ const pathRoot = resolve(currentPath, '/');
59
+ try {
60
+ while (currentPath !== pathRoot && directoriesSearched < 5) {
61
+ const packageJsonPath = resolve(currentPath, 'package.json');
62
+ if (fs.existsSync(packageJsonPath)) {
63
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
64
+ if (packageJson.name === '@actual-app/sync-server') {
65
+ return packageJson;
66
+ }
67
+ }
68
+ currentPath = resolve(join(currentPath, '..')); // Move up one directory
69
+ directoriesSearched++;
70
+ }
71
+ }
72
+ catch (error) {
73
+ console.error('Error while searching for package.json:', error);
74
+ }
75
+ return null;
76
+ }
77
+ const dirname = resolve(fileURLToPath(import.meta.url), '../');
78
+ const packageJson = findPackageJson(dirname);
56
79
  res.status(200).json({
57
80
  build: {
58
- name: packageJson.name,
59
- description: packageJson.description,
60
- version: packageJson.version,
81
+ name: packageJson?.name,
82
+ description: packageJson?.description,
83
+ version: packageJson?.version,
61
84
  },
62
85
  });
63
86
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@actual-app/sync-server",
3
- "version": "25.6.0",
3
+ "version": "25.6.1",
4
4
  "license": "MIT",
5
5
  "description": "actual syncing server",
6
6
  "bin": {
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@actual-app/crdt": "2.1.0",
31
- "@actual-app/web": "25.6.0",
31
+ "@actual-app/web": "25.6.1",
32
32
  "bcrypt": "^5.1.1",
33
33
  "better-sqlite3": "^11.10.0",
34
34
  "body-parser": "^1.20.3",