From 2feb90475e12d23e892aef37bb01e2361dac4bc6 Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Fri, 25 Oct 2024 18:57:29 +0200 Subject: [PATCH] Fix module resolution when $CWD != . --- flake.lock | Bin 1497 -> 1497 bytes package-lock.json | Bin 381269 -> 381615 bytes package.json | 1 + scripts/test-non-cwd-exec.sh | 12 ++++++++++++ src/api/start.ts | 3 ++- src/bundle/start.ts | 4 +++- src/cdn/start.ts | 3 ++- src/gateway/start.ts | 3 ++- 8 files changed, 22 insertions(+), 4 deletions(-) create mode 100755 scripts/test-non-cwd-exec.sh diff --git a/flake.lock b/flake.lock index 243467a0d7ef2b06b4ad97c8ec8004fb1efdf9ea..ed36ceded9bb978f0edc85204cdedb69b0419060 100644 GIT binary patch delta 135 zcmV;20C@k|3)u^>DFO#MHa0akF))#k9VV{JoNN?K4!Y)>_0ZAN-lGgdNKMmBga zPjF6GRaQ7zFGfvJM`So!G?SkM8Iv~y5RufACyD?7 delta 135 zcmcb~eUp2GCKJ1biKUU5xy8f@vf7rRAr(OusioN|>Dm!dsUGPS;iegZj+SYj-X6u? z&ME$$p_R!YMU|;x<&)>LNKQ6q7MQ%Ak!^Awv#@?qYMGLif|9A3v2jvzTAD$!nW33c ml4Yt%l4+Wuk(mh)nHd_UTACUpTcjqNPd>n?yqSmjEE51XN+`|% diff --git a/package-lock.json b/package-lock.json index 1978d84491628d8e766d7c7c090c57a76d47fe96..cdfb564dcbc64e607690768e19a384227bfbd3fb 100644 GIT binary patch delta 327 zcmcb*NPPWL@eL;IA}OUgsk(_dnTf?pRtidSMtTN%Ce6z1+m+cF7cJm~%TC|;l2Ls6 zha6_Z=>jVlIj7Hh$t*K{q6L#usHwKQeqe;ZzDt=$RJoafTUJ?;OO?NgS8k4rexAE& zu91FOn0twlX_%j3YHEOSxlxjHes-~8c%pe&X+eo^fUjXlg;z?2Sx}b0xq+XhTe(4A zRKWCyr&y#WE#jZ@f^2h(WdDHV4EM4KuVQCoXR{!)fMDPJ z{QRntvY@a)*D4Fk^jxP9r%1!#0N=#IeAALtCzDb?kARfalHiQVfk#ZIr>|!en?6aO nQEqy}HlWS&8yQ)rn{zNqw;x>32*gZ4%nZaV+Yhd1eWwHfBFjT9 diff --git a/package.json b/package.json index 1e7b2047..42e729f5 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "@types/i18next-node-fs-backend": "^2.1.2", "@types/json-bigint": "^1.0.1", "@types/jsonwebtoken": "^9.0.2", + "@types/module-alias": "^2.0.4", "@types/morgan": "^1.9.4", "@types/multer": "^1.4.7", "@types/murmurhash-js": "^1.0.4", diff --git a/scripts/test-non-cwd-exec.sh b/scripts/test-non-cwd-exec.sh new file mode 100755 index 00000000..7d33c46f --- /dev/null +++ b/scripts/test-non-cwd-exec.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i "bash -x" -p bash jq git nodejs +npm i +npm run setup || exit 1 + +export OWD="$PWD" +export NWD="`mktemp -d`" +echo "Src dir: $OWD" +echo "Exec dir: $NWD" + +#NODE_PATH="$OWD/dist" +node "$OWD/dist/api/start.js" \ No newline at end of file diff --git a/src/api/start.ts b/src/api/start.ts index 088c6f8d..4a3f858e 100644 --- a/src/api/start.ts +++ b/src/api/start.ts @@ -16,7 +16,8 @@ along with this program. If not, see . */ -require("module-alias/register"); +import moduleAlias from "module-alias"; +moduleAlias(__dirname + "../../../package.json"); process.on("uncaughtException", console.error); process.on("unhandledRejection", console.error); diff --git a/src/bundle/start.ts b/src/bundle/start.ts index df50fd4c..fe177cbc 100644 --- a/src/bundle/start.ts +++ b/src/bundle/start.ts @@ -17,7 +17,9 @@ */ // process.env.MONGOMS_DEBUG = "true"; -require("module-alias/register"); +import moduleAlias from "module-alias"; +moduleAlias(__dirname + "../../../package.json"); + import "reflect-metadata"; import cluster, { Worker } from "cluster"; import os from "os"; diff --git a/src/cdn/start.ts b/src/cdn/start.ts index d793077d..21da69e9 100644 --- a/src/cdn/start.ts +++ b/src/cdn/start.ts @@ -16,7 +16,8 @@ along with this program. If not, see . */ -require("module-alias/register"); +import moduleAlias from "module-alias"; +moduleAlias(__dirname + "../../../package.json"); import "dotenv/config"; import { CDNServer } from "./Server"; diff --git a/src/gateway/start.ts b/src/gateway/start.ts index 8af96c13..b04048e1 100644 --- a/src/gateway/start.ts +++ b/src/gateway/start.ts @@ -16,7 +16,8 @@ along with this program. If not, see . */ -require("module-alias/register"); +import moduleAlias from "module-alias"; +moduleAlias(__dirname + "../../../package.json"); process.on("uncaughtException", console.error); process.on("unhandledRejection", console.error);