Skip to content

Commit 26a8652

Browse files
committed
using module-alias programmatically because we want different aliases in dev and prod mode
(in dev mode, we want to directly reference /shared/dist to avoid needing a copy of this directory)
1 parent f6179aa commit 26a8652

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

cloud/functions/package-lock.json

Lines changed: 7 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: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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",
10+
"predeploy": "npm run build && cp -r ../../shared/dist ./lib/shared",
1011
"deploy": "firebase deploy --only functions --project ${FIREBASE_PROJECT_NAME:-voxxrin-v3}",
1112
"logs": "firebase functions:log",
1213
"test": "vitest"
@@ -15,7 +16,7 @@
1516
"engines": {
1617
"node": "20"
1718
},
18-
"main": "lib/index.js",
19+
"main": "lib/cloud-functions/index.js",
1920
"dependencies": {
2021
"@googleapis/youtube": "15.0.0",
2122
"@js-temporal/polyfill": "^0.4.3",
@@ -36,6 +37,7 @@
3637
"zod": "3.22.4"
3738
},
3839
"devDependencies": {
40+
"@types/module-alias": "2.0.4",
3941
"@types/uuid": "9.0.2",
4042
"@typescript-eslint/eslint-plugin": "^5.12.0",
4143
"@typescript-eslint/parser": "^5.12.0",
@@ -49,8 +51,5 @@
4951
"typescript": "5.4.5",
5052
"vitest": "0.31.1"
5153
},
52-
"private": true,
53-
"_moduleAliases": {
54-
"@shared": "../../shared/dist"
55-
}
54+
"private": true
5655
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import moduleAlias from 'module-alias';
2+
3+
// This needs to be done as soon as possible in the loading process...
4+
5+
const isEmulator = !!process.env.FIREBASE_EMULATOR_HUB || !!process.env.FUNCTIONS_EMULATOR;
6+
moduleAlias.addAliases({
7+
// In Emulator (dev mode) it's easier to directly reference shared/dist folder (so that we don't need to copy its content into lib/shared/ folder)
8+
'@shared': isEmulator ? `${__dirname}/../../../../shared/dist`:`${__dirname}/../shared`,
9+
})

cloud/functions/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'module-alias/register';
1+
import './configure-early-module-aliases'
22
import express from 'express';
33
import * as functions from 'firebase-functions';
44
import {declareExpressHttpRoutes} from "./functions/http/api/routes";

cloud/functions/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"noImplicitReturns": true,
55
"noUnusedLocals": false,
66
"rootDir": "./src",
7-
"outDir": "lib",
7+
"outDir": "lib/cloud-functions/",
88
"sourceMap": true,
99
"strict": true,
1010
"target": "es2017",

0 commit comments

Comments
 (0)