From 16a2a105404e555699e3812d85664baeedd3151d Mon Sep 17 00:00:00 2001 From: lukasIO Date: Thu, 28 Nov 2024 14:21:21 +0100 Subject: [PATCH] Enable verbatimModuleSyntax and isolatedModules (#341) * Enable verbatimModuleSyntax and isolatedModules * Create silver-rocks-listen.md * include lib check --- .changeset/silver-rocks-listen.md | 6 +++++ packages/livekit-rtc/src/ffi_client.ts | 8 +++---- packages/livekit-rtc/src/index.ts | 22 ++++++++++++------- packages/livekit-rtc/src/napi/native.d.ts | 10 ++++----- packages/livekit-rtc/tsconfig.json | 13 ++--------- .../livekit-server-sdk/src/AccessToken.ts | 4 +++- packages/livekit-server-sdk/src/TwirpRPC.ts | 2 +- tsconfig.json | 7 +++++- 8 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 .changeset/silver-rocks-listen.md diff --git a/.changeset/silver-rocks-listen.md b/.changeset/silver-rocks-listen.md new file mode 100644 index 00000000..cb43acf8 --- /dev/null +++ b/.changeset/silver-rocks-listen.md @@ -0,0 +1,6 @@ +--- +"@livekit/rtc-node": patch +"livekit-server-sdk": patch +--- + +Enable verbatimModuleSyntax and isolatedModules diff --git a/packages/livekit-rtc/src/ffi_client.ts b/packages/livekit-rtc/src/ffi_client.ts index 9b19f415..562cbeda 100644 --- a/packages/livekit-rtc/src/ffi_client.ts +++ b/packages/livekit-rtc/src/ffi_client.ts @@ -14,16 +14,16 @@ import { livekitRetrievePtr, } from './napi/native.js'; import { - FfiEvent, + type FfiEvent, FfiEventSchema, - FfiRequest, + type FfiRequest, FfiRequestSchema, - FfiResponse, + type FfiResponse, FfiResponseSchema, } from './proto/ffi_pb.js'; import { SDK_VERSION } from './version.js'; -export { FfiHandle, FfiEvent, FfiResponse, FfiRequest, livekitDispose as dispose }; +export { FfiHandle, type FfiEvent, type FfiResponse, type FfiRequest, livekitDispose as dispose }; export type FfiClientCallbacks = { ffi_event: (event: FfiEvent) => void; diff --git a/packages/livekit-rtc/src/index.ts b/packages/livekit-rtc/src/index.ts index f831e108..dba1821c 100644 --- a/packages/livekit-rtc/src/index.ts +++ b/packages/livekit-rtc/src/index.ts @@ -14,24 +14,24 @@ import { import { TrackSource } from './proto/track_pb.js'; import { VideoCodec } from './proto/video_frame_pb.js'; -export { Room, RoomEvent, ConnectError, RoomOptions, RtcConfiguration } from './room.js'; +export { Room, RoomEvent, ConnectError, type RoomOptions, type RtcConfiguration } from './room.js'; export { Participant, RemoteParticipant, LocalParticipant } from './participant.js'; export { Track, - LocalTrack, - RemoteTrack, - VideoTrack, + type LocalTrack, + type RemoteTrack, + type VideoTrack, LocalAudioTrack, LocalVideoTrack, RemoteAudioTrack, RemoteVideoTrack, - AudioTrack, + type AudioTrack, } from './track.js'; export { VideoFrame } from './video_frame.js'; export { AudioFrame, combineAudioFrames } from './audio_frame.js'; export { AudioStream } from './audio_stream.js'; export { AudioResampler, AudioResamplerQuality } from './audio_resampler.js'; -export { VideoStream, VideoFrameEvent } from './video_stream.js'; +export { VideoStream, type VideoFrameEvent } from './video_stream.js'; export { AudioSource } from './audio_source.js'; export { VideoSource } from './video_source.js'; export { @@ -39,8 +39,14 @@ export { RemoteTrackPublication, LocalTrackPublication, } from './track_publication.js'; -export { Transcription, TranscriptionSegment } from './transcription.js'; -export { E2EEManager, E2EEOptions, KeyProviderOptions, KeyProvider, FrameCryptor } from './e2ee.js'; +export { type Transcription, type TranscriptionSegment } from './transcription.js'; +export { + E2EEManager, + type E2EEOptions, + type KeyProviderOptions, + KeyProvider, + FrameCryptor, +} from './e2ee.js'; export { ConnectionQuality, diff --git a/packages/livekit-rtc/src/napi/native.d.ts b/packages/livekit-rtc/src/napi/native.d.ts index 983654dc..2483dafa 100644 --- a/packages/livekit-rtc/src/napi/native.d.ts +++ b/packages/livekit-rtc/src/napi/native.d.ts @@ -3,15 +3,15 @@ /* auto-generated by NAPI-RS */ -export function livekitInitialize( +export declare function livekitInitialize( callback: (data: Uint8Array) => void, captureLogs: boolean, sdkVersion: string, ): void; -export function livekitFfiRequest(data: Uint8Array): Uint8Array; -export function livekitRetrievePtr(handle: Uint8Array): bigint; -export function livekitCopyBuffer(ptr: bigint, len: number): Uint8Array; -export function livekitDispose(): Promise; +export declare function livekitFfiRequest(data: Uint8Array): Uint8Array; +export declare function livekitRetrievePtr(handle: Uint8Array): bigint; +export declare function livekitCopyBuffer(ptr: bigint, len: number): Uint8Array; +export declare function livekitDispose(): Promise; export declare class FfiHandle { constructor(handle: bigint); dispose(): void; diff --git a/packages/livekit-rtc/tsconfig.json b/packages/livekit-rtc/tsconfig.json index fe1dca3d..21aeb92d 100644 --- a/packages/livekit-rtc/tsconfig.json +++ b/packages/livekit-rtc/tsconfig.json @@ -1,17 +1,8 @@ { + "extends": "../../tsconfig.json", "compilerOptions": { - "module": "ES2015", - "esModuleInterop": true, - "allowJs": true, - "declaration": true, - "declarationMap": true, - "target": "es2015", - "lib": ["es2015"], - "moduleResolution": "node", - "sourceMap": true, "outDir": "dist", - "strict": true, - "noUncheckedIndexedAccess": true + "declarationDir": "dist" }, "include": ["src/**/*.ts"], "exclude": ["src/**/*.test.ts", "vite.config.ts"] diff --git a/packages/livekit-server-sdk/src/AccessToken.ts b/packages/livekit-server-sdk/src/AccessToken.ts index 3dab9f9d..b9591837 100644 --- a/packages/livekit-server-sdk/src/AccessToken.ts +++ b/packages/livekit-server-sdk/src/AccessToken.ts @@ -63,7 +63,9 @@ export class AccessToken { } if (!apiKey || !apiSecret) { throw Error('api-key and api-secret must be set'); - } else if (typeof document !== 'undefined') { + } + // @ts-expect-error we're not including dom lib for the server sdk so document is not defined + else if (typeof document !== 'undefined') { // check against document rather than window because deno provides window console.error( 'You should not include your API secret in your web client bundle.\n\n' + diff --git a/packages/livekit-server-sdk/src/TwirpRPC.ts b/packages/livekit-server-sdk/src/TwirpRPC.ts index d7db2bc5..aa14c0ef 100644 --- a/packages/livekit-server-sdk/src/TwirpRPC.ts +++ b/packages/livekit-server-sdk/src/TwirpRPC.ts @@ -49,7 +49,7 @@ export class TwirpRpc { if (!response.ok) { throw new Error(`Request failed with status ${response.status}: ${response.statusText}`); } - const parsedResp = await response.json(); + const parsedResp = (await response.json()) as Record; const camelcaseKeys = await import('camelcase-keys').then((mod) => mod.default); return camelcaseKeys(parsedResp, { deep: true }); } diff --git a/tsconfig.json b/tsconfig.json index 64e5e421..2ad4c3d2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,13 +1,18 @@ { "compilerOptions": { + "lib": ["es2015"], "target": "es2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, "module": "node16" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, "declaration": true, "declarationMap": true, "sourceMap": true, + "moduleResolution": "node16", "strict": true /* Enable all strict type-checking options. */, "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, - "skipLibCheck": true /* Skip type checking of declaration files. */, + "skipLibCheck": false /* Skip type checking of declaration files. */, "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, + "verbatimModuleSyntax": true, + "isolatedModules": true, + "noUncheckedIndexedAccess": true } }