Skip to content

Commit fe3302a

Browse files
committed
Fix node_modules + typescript + ESM issues for real
There were some weird issues with esbuild earlier resolving node_modules in cjs form incorrectly leading to require() statements inside the bundled index.js. Due to production issues, hacks were made to allow a deploy but those have been reverted and now this is an attempt to correctly fix the resolution issues. If this does not work, we should look at things like shimming require() as listed in evanw/esbuild#1921 (comment) and explained in: evanw/esbuild#3637 (comment)
1 parent 63027b6 commit fe3302a

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

functions/package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

functions/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"lint": "eslint --ext .js,.ts .",
66
"build": "run-s build:tsc build:esbuild",
7-
"build:esbuild": "esbuild src/index.ts --bundle --platform=node --outfile=lib/index.js --format=esm --external:./node_modules/* --packages=external",
7+
"build:esbuild": "esbuild src/index.ts --bundle --platform=node --outfile=lib/index.js --format=esm --external:./node_modules/*",
88
"build:tsc": "tsc",
99
"build:watch": "run-p 'build:tsc -- --watch --preserveWatchOutput' 'build:esbuild -- --watch'",
1010
"dev": "run-p build:watch dev:*",
@@ -24,6 +24,7 @@
2424
"@google-cloud/functions-framework": "^3.4.0",
2525
"@google-cloud/pubsub": "^4.4.0",
2626
"@types/node-gzip": "^1.1.3",
27+
"csv-parse": "^5.5.6",
2728
"csv-stringify": "^6.5.0",
2829
"date-fns": "^2.30.0",
2930
"firebase": "^10.12.2",
@@ -33,6 +34,7 @@
3334
"lodash.isequal": "^4.5.0",
3435
"lzma-native": "^8.0.6",
3536
"sentence-splitter": "^5.0.0",
37+
"source-map-support": "^0.5.21",
3638
"youtubei.js": "^9.4.0"
3739
},
3840
"devDependencies": {
@@ -47,7 +49,6 @@
4749
"firebase-functions-test": "^3.1.0",
4850
"jest": "^29.7.0",
4951
"npm-run-all": "^4.1.5",
50-
"source-map-support": "^0.5.21",
5152
"ts-jest": "^29.1.4",
5253
"typescript": "^5.5.2"
5354
},

functions/src/transcript.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as TestingUtils from './utils/testing';
2+
3+
describe('transcript', () => {
4+
it('GET retrieves transcript', async () => {
5+
const response = await TestingUtils.fetchEndpoint(
6+
'transcript',
7+
'GET',
8+
{ category: 'sps-board',
9+
vid: 'MT2zjpRbQJA' });
10+
expect(response.status).toStrictEqual(200);
11+
const responseJson = await response.json();
12+
expect(responseJson.ok).toStrictEqual(true);
13+
});
14+
});

functions/src/video_queue.test.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as TestingUtils from './utils/testing';
2+
import { getCategoryPrivateDb } from './utils/firebase';
3+
import { getAllCategories } from './utils/path';
4+
5+
describe('video_queue', () => {
6+
beforeAll(TestingUtils.beforeAll);
7+
8+
it('Access With auth_code', async () => {
9+
const NEW_VIDS = ['a','b','c'];
10+
const category = getAllCategories()[0];
11+
getCategoryPrivateDb(category, 'new_vids').set(NEW_VIDS);
12+
const response = await TestingUtils.fetchEndpoint(
13+
'video_queue',
14+
'GET',
15+
{ user_id: TestingUtils.FAKE_USER_ID,
16+
auth_code: TestingUtils.FAKE_AUTH_CODE });
17+
expect(response.status).toStrictEqual(200);
18+
const responseJson = await response.json();
19+
expect(responseJson.ok).toStrictEqual(true);
20+
expect(responseJson.data[category]).toEqual(NEW_VIDS);
21+
});
22+
23+
});

functions/tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"typeRoots": ["./node_modules/@types"],
44
"baseUrl": ".",
55
"paths": {
6-
"*": ["./node_modules/*"],
76
"common/*": ["../common/*"],
87
"config/*": ["../config/*"],
98
"utils/*": ["./src/utils/*"]

0 commit comments

Comments
 (0)