Skip to content

Commit 63027b6

Browse files
committed
Revert "Use js-extensions for everything"
This reverts commit 4395ccc.
1 parent 6a18c2f commit 63027b6

18 files changed

+115
-105
lines changed

common/paths.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Constants from "../config/constants.js";
1+
import * as Constants from "config/constants";
22

33
export function makePublicPath(...parts) {
44
return [Constants.APP_SCOPE, "public", ...parts].join("/");

common/transcript.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { DiarizedTranscript } from './transcript.js';
1+
import { DiarizedTranscript } from 'common/transcript';
22
import * as fs from 'node:fs/promises';
33

4-
import type { StorageAccessor } from './storage.js';
4+
import type { StorageAccessor } from 'common/storage';
55

66
// Work around JSDOM missing TextDecoder.
77
import { TextEncoder, TextDecoder } from 'util';

common/transcript.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import * as Constants from '../config/constants.js';
1+
import * as Constants from 'config/constants';
22
import langs from 'langs';
3-
import { getArchivedWhisperXTranscript } from './whisperx.js';
3+
import { getArchivedWhisperXTranscript } from 'common/whisperx';
44
import { parse } from 'csv-parse/sync';
55
import { stringify } from 'csv-stringify/sync';
6-
import { makePublicPath } from './paths.js';
6+
import { makePublicPath } from 'common/paths';
77
import { split, SentenceSplitterSyntax } from 'sentence-splitter';
88

9-
import type { CategoryId, Iso6393Code, SegmentId, SpeakerId, VideoId } from './params.js';
10-
import type { StorageAccessor } from './storage.js';
11-
import type { WhisperXTranscript } from './whisperx.js';
9+
import type { CategoryId, Iso6393Code, SegmentId, SpeakerId, VideoId } from 'common/params';
10+
import type { StorageAccessor } from 'common/storage';
11+
import type { WhisperXTranscript } from 'common/whisperx';
1212

1313
///////////////////
1414
/// Types

common/whisperx.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
// for this kind of archival. However different libraries work better/worse
1111
// in the node.js and browser envrionment.
1212

13-
import * as Constants from "../config/constants.js";
13+
import * as Constants from "config/constants";
1414
import langs from 'langs';
15-
import { makePublicPath } from "./paths.js";
15+
import { makePublicPath } from "common/paths";
1616

17-
import type { StorageAccessor } from './storage.js';
18-
import type { CategoryId, Iso6393Code, VideoId } from "./params.js";
17+
import type { StorageAccessor } from 'common/storage';
18+
import type { CategoryId, Iso6393Code, VideoId } from "common/params";
1919

2020
// Top level WhipserX trannscript ytpe.
2121
export type WhisperXTranscript = {

functions/jest.config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* https://jestjs.io/docs/configuration
44
*/
55

6+
import { pathsToModuleNameMapper } from 'ts-jest';
7+
import { compilerOptions } from './tsconfig.json';
68
import type { Config } from 'jest';
79

810
const config: Config = {
@@ -92,6 +94,7 @@ const config: Config = {
9294
// ],
9395

9496
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
97+
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
9598

9699
extensionsToTreatAsEsm: ['.ts'],
97100

functions/package-lock.json

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

functions/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"type": "module",
44
"scripts": {
55
"lint": "eslint --ext .js,.ts .",
6-
"build": "run-s build:tsc",
6+
"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",
78
"build:tsc": "tsc",
8-
"build:watch": "tsc --watch",
9+
"build:watch": "run-p 'build:tsc -- --watch --preserveWatchOutput' 'build:esbuild -- --watch'",
910
"dev": "run-p build:watch dev:*",
1011
"dev:emulators": "firebase emulators:start --only functions,storage,database",
1112
"serve": "npm run build && firebase emulators:start --only functions,storage,database",
@@ -18,7 +19,7 @@
1819
"test:watch": "run-p build:watch test:jest:watch",
1920
"logs": "firebase functions:log"
2021
},
21-
"main": "lib/functions/src/index.js",
22+
"main": "lib/index.js",
2223
"dependencies": {
2324
"@google-cloud/functions-framework": "^3.4.0",
2425
"@google-cloud/pubsub": "^4.4.0",

functions/src/endpoint_auth.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as TestingUtils from './utils/testing.js';
1+
import * as TestingUtils from 'utils/testing';
22

33
// List of endpoints that should be guarded by user_id/auth_code params.
44
const AUTH_CODE_ENDPOINTS = [

functions/src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import 'source-map-support/register.js';
22

3-
export { speakerinfo } from "./speakerinfo.js";
4-
export { transcript } from "./transcript.js";
5-
export { video_queue, vast } from "./video_queue.js";
3+
export { speakerinfo } from "./speakerinfo";
4+
export { transcript } from "./transcript";
5+
export { video_queue, vast } from "./video_queue";
66

7-
import { initializeFirebase } from "./utils/firebase.js";
7+
import { initializeFirebase } from "./utils/firebase";
88

99
initializeFirebase();

functions/src/migrations/2024-06-15-sentence-tables.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
// /transcripts/public/[category]/diarized/[vid].json
99
// /transcripts/public/[category]/sentences/[vid].eng.json
1010

11-
import * as Constants from '../../../config/constants.js';
12-
import { FirebaseAdminStorageAccessor } from '../utils/storage.js';
13-
import { DiarizedTranscript, makeSentenceTablePath, makeTranscriptDataPath } from '../../../common/transcript.js';
11+
import * as Constants from 'config/constants';
12+
import { FirebaseAdminStorageAccessor } from 'utils/storage';
13+
import { DiarizedTranscript, makeSentenceTablePath, makeTranscriptDataPath } from 'common/transcript';
1414
import { basename } from 'node:path';
15-
import { makePublicPath } from '../../../common/paths.js';
15+
import { makePublicPath } from 'common/paths';
1616

17-
import type { Iso6393Code, VideoId } from "../../../common/params.js";
17+
import type { Iso6393Code, VideoId } from "common/params";
1818

1919
const accessor = new FirebaseAdminStorageAccessor();
2020

functions/src/speakerinfo.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import isEqual from "lodash.isequal";
2-
import { getCategoryPublicDb, getCategoryPrivateDb, getUser, jsonOnRequest } from "./utils/firebase.js";
3-
import { makeResponseJson } from "./utils/response.js";
2+
import { getCategoryPublicDb, getCategoryPrivateDb, getUser, jsonOnRequest } from "./utils/firebase";
3+
import { makeResponseJson } from "./utils/response";
44

55
// POST to speaker info with JSON body of type:
66
// {

functions/src/transcript.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import langs from 'langs';
2-
import { DiarizedTranscript } from '../../common/transcript.js';
3-
import { getCategoryPublicDb, getAuthCode, jsonOnRequest } from './utils/firebase.js';
4-
import { getStorageAccessor } from './utils/storage.js';
5-
import { makeResponseJson } from './utils/response.js';
2+
import { DiarizedTranscript } from 'common/transcript';
3+
import { getCategoryPublicDb, getAuthCode, jsonOnRequest } from './utils/firebase';
4+
import { getStorageAccessor } from './utils/storage';
5+
import { makeResponseJson } from './utils/response';
66

7-
import type { WhisperXTranscript } from '../../common/whisperx.js';
8-
import type { Iso6393Code, VideoId } from '../../common/params.js';
7+
import type { WhisperXTranscript } from 'common/whisperx';
8+
import type { Iso6393Code, VideoId } from 'common/params';
99

1010
const LANGUAGES = new Set<Iso6393Code>(["eng"]);
1111

functions/src/utils/firebase.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { getDatabase } from "firebase-admin/database";
66
import { getAuth } from "firebase-admin/auth";
77
import { onRequest } from "firebase-functions/v2/https";
88

9-
import { makeResponseJson } from "./response.js";
10-
import { makePublicPath, makePrivatePath } from "../../../common/paths.js";
9+
import { makeResponseJson } from "./response";
10+
import { makePublicPath, makePrivatePath } from "common/paths";
1111

1212
import type { AppOptions } from "firebase-admin/app";
1313

functions/src/utils/storage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createGzip, createGunzip } from 'zlib';
55
import { getStorage } from 'firebase-admin/storage';
66
import { pipeline } from 'node:stream/promises';
77

8-
import type { StorageAccessor } from "../../../common/storage.js";
8+
import type { StorageAccessor } from "common/storage";
99

1010
// Implements the StorageAccessor API using the Firebase Admin SDK
1111
// and Google Cloud Storage API. Unlike the client API, the Firebase

functions/src/utils/testing.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fetch from 'node-fetch';
2-
import * as FirebaseUtils from './firebase.js';
2+
import * as FirebaseUtils from 'utils/firebase';
33
import sourceMapSupport from 'source-map-support'
44

55
// First set up unique project id for these tests, so that any other test files run in parallel

functions/src/video_queue.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { getCategoryPublicDb, getCategoryPrivateDb, getPubSubClient, jsonOnRequest, getAuthCode, getUser, UserRecord } from "./utils/firebase.js";
1+
import { getCategoryPublicDb, getCategoryPrivateDb, getPubSubClient, jsonOnRequest, getAuthCode, getUser, UserRecord } from "./utils/firebase";
22
import { getVideosForCategory } from "./youtube.js";
3-
import { getAllCategories, sanitizeCategory } from "./utils/path.js";
4-
import { makeResponseJson } from "./utils/response.js";
3+
import { getAllCategories, sanitizeCategory } from "./utils/path";
4+
import { makeResponseJson } from "./utils/response";
55

66
async function getVideoQueue(req, res) {
77
if (!req.query.user_id) {

functions/src/youtube.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Constants from '../../config/constants.js';
1+
import * as Constants from 'config/constants';
22
import { Innertube, YTNodes } from 'youtubei.js';
33

44
let global_youtube : Innertube | null;

functions/tsconfig.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
"typeRoots": ["./node_modules/@types"],
44
"baseUrl": ".",
55
"paths": {
6-
"*": ["./node_modules/*"]
6+
"*": ["./node_modules/*"],
7+
"common/*": ["../common/*"],
8+
"config/*": ["../config/*"],
9+
"utils/*": ["./src/utils/*"]
710
},
811
"allowJs": true,
912
"noImplicitReturns": true,
1013
"noUnusedLocals": true,
1114
"esModuleInterop": true,
1215
"skipLibCheck": true,
13-
"module": "nodenext",
14-
"moduleResolution": "nodenext",
16+
"module": "ESNext",
17+
"moduleResolution": "Bundler",
18+
"moduleDetection": "force",
1519
"resolveJsonModule": true,
1620
"isolatedModules": true,
1721
"outDir": "lib",

0 commit comments

Comments
 (0)