Skip to content

Commit f6179aa

Browse files
committed
considered shared as a cloud/function project reference and @shared path mapping (I had to introduce module-alias to translate @shared/* imports into relative paths
1 parent 012fe13 commit f6179aa

File tree

6 files changed

+53
-9
lines changed

6 files changed

+53
-9
lines changed

cloud/functions/package-lock.json

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

cloud/functions/package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "functions",
33
"scripts": {
44
"lint": "eslint --ext .js,.ts .",
5-
"build": "tsc",
6-
"build:watch": "tsc --watch",
5+
"build": "tsc --build",
6+
"build:watch": "tsc --build --watch",
77
"serve": "npm run build && env-cmd -f ./.env.local firebase emulators:start --import data --export-on-exit --inspect-functions --project ${FIREBASE_PROJECT_NAME:-voxxrin-v3}",
88
"shell": "npm run build && firebase functions:shell",
99
"start": "npm run shell",
@@ -15,7 +15,7 @@
1515
"engines": {
1616
"node": "20"
1717
},
18-
"main": "lib/cloud/functions/src/index.js",
18+
"main": "lib/index.js",
1919
"dependencies": {
2020
"@googleapis/youtube": "15.0.0",
2121
"@js-temporal/polyfill": "^0.4.3",
@@ -28,6 +28,7 @@
2828
"isomorphic-dompurify": "2.14.0",
2929
"lodash": "^4.17.21",
3030
"marked": "13.0.2",
31+
"module-alias": "2.2.3",
3132
"string-similarity-js": "2.1.4",
3233
"ts-pattern": "5.1.1",
3334
"uuid": "9.0.0",
@@ -48,5 +49,8 @@
4849
"typescript": "5.4.5",
4950
"vitest": "0.31.1"
5051
},
51-
"private": true
52+
"private": true,
53+
"_moduleAliases": {
54+
"@shared": "../../shared/dist"
55+
}
5256
}

cloud/functions/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import * as express from 'express';
1+
import 'module-alias/register';
2+
import express from 'express';
23
import * as functions from 'firebase-functions';
34
import {declareExpressHttpRoutes} from "./functions/http/api/routes";
45

56
const app = express()
67
app.use(express.json());
7-
app.use((req, res, next) => {
8+
app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
89
if (req.headers['x-forwarded-host'] && req.headers['x-forwarded-host'].toString().endsWith("voxxr.in") && req.originalUrl.startsWith('/api')) {
910
req.url = req.originalUrl.substring("/api".length);
1011
}

cloud/functions/tsconfig.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,25 @@
33
"module": "commonjs",
44
"noImplicitReturns": true,
55
"noUnusedLocals": false,
6+
"rootDir": "./src",
67
"outDir": "lib",
78
"sourceMap": true,
89
"strict": true,
910
"target": "es2017",
10-
"allowSyntheticDefaultImports": true
11+
"allowSyntheticDefaultImports": true,
12+
"esModuleInterop": true,
13+
"skipLibCheck": true,
14+
"forceConsistentCasingInFileNames": true,
15+
"paths": {
16+
"@shared/*": ["../../shared/dist/*"]
17+
}
1118
},
19+
"references": [{
20+
"path": "../../shared"
21+
}],
1222
"compileOnSave": true,
1323
"include": [
14-
"../../shared/**/*.ts",
1524
"src/**/*.ts"
16-
]
25+
],
26+
"exclude": ["node_modules", "lib", "src/**/*.spec.ts"]
1727
}

shared/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

shared/tsconfig.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"declarationMap": true,
5+
"outDir": "dist",
6+
"rootDir": ".",
7+
"composite": true,
8+
"module": "commonjs",
9+
"target": "ES2017",
10+
"strict": true,
11+
"esModuleInterop": true,
12+
"forceConsistentCasingInFileNames": true,
13+
"skipLibCheck": true
14+
},
15+
"include": [
16+
"**/*.ts"
17+
],
18+
"exclude": [
19+
"dist",
20+
"node_modules"
21+
]
22+
}

0 commit comments

Comments
 (0)