Skip to content

Commit 2e23b05

Browse files
committed
fix bug in algorithm for determining data directory
1 parent 91f80f0 commit 2e23b05

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

src/packages/backend/data.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ import { isEmpty } from "lodash";
3131
import basePath from "@cocalc/backend/base-path";
3232
import port from "@cocalc/backend/port";
3333
import { FALLBACK_ACCOUNT_UUID } from "@cocalc/util/misc";
34+
import { packageDirectorySync } from "package-directory";
3435

35-
function determineRootFromPath(): string {
36-
const cur = __dirname;
37-
const search = "/src/";
38-
const i = cur.lastIndexOf(search);
39-
const root = resolve(cur.slice(0, i + search.length - 1));
36+
function determineRoot(): string {
37+
const pd = packageDirectorySync() ?? '/';
38+
const root = resolve(pd, "..", "..");
4039
process.env.COCALC_ROOT = root;
4140
return root;
4241
}
@@ -170,7 +169,7 @@ export function sslConfigToPsqlEnv(config: SSLConfig): PsqlSSLEnvConfig {
170169
return psqlArgs;
171170
}
172171

173-
export const root: string = process.env.COCALC_ROOT ?? determineRootFromPath();
172+
export const root: string = process.env.COCALC_ROOT ?? determineRoot();
174173
export const data: string = process.env.DATA ?? join(root, "data");
175174
export const pguser: string = process.env.PGUSER ?? "smc";
176175
export const pgdata: string = process.env.PGDATA ?? join(data, "postgres");

src/packages/backend/package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
"./auth/*": "./dist/auth/*.js",
1414
"./auth/tokens/*": "./dist/auth/tokens/*.js"
1515
},
16-
"keywords": ["utilities", "cocalc"],
16+
"keywords": [
17+
"utilities",
18+
"cocalc"
19+
],
1720
"scripts": {
1821
"preinstall": "npx only-allow pnpm",
1922
"clean": "rm -rf dist node_modules",
@@ -31,7 +34,12 @@
3134
"conat-persist": "DEBUG=cocalc:* node ./bin/conat-persist.cjs",
3235
"conat-test-server": "node ./bin/conat-test-server.cjs"
3336
},
34-
"files": ["dist/**", "bin/**", "README.md", "package.json"],
37+
"files": [
38+
"dist/**",
39+
"bin/**",
40+
"README.md",
41+
"package.json"
42+
],
3543
"author": "SageMath, Inc.",
3644
"license": "SEE LICENSE.md",
3745
"dependencies": {
@@ -45,6 +53,7 @@
4553
"fs-extra": "^11.3.1",
4654
"lodash": "^4.17.21",
4755
"lru-cache": "^7.18.3",
56+
"package-directory": "^8.1.0",
4857
"password-hash": "^1.2.2",
4958
"prom-client": "^15.1.3",
5059
"rimraf": "^5.0.5",

src/packages/pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/packages/project-runner/sea/build-tarball.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ cd "$SRC"
3636
cd "$SRC"/packages
3737
rm -rf node_modules && pnpm install --prod --package-import-method=copy
3838

39-
rm -rf cdn frontend
39+
rm -rf cdn frontend static assets
4040
rm -rf static/dist/*.map static/dist/embed-*.js
4141

4242
cd node_modules/.pnpm

0 commit comments

Comments
 (0)