From da89bcb447b8fd1b11a06b2a618a954d49e6918b Mon Sep 17 00:00:00 2001 From: aoife cassidy Date: Wed, 13 Nov 2024 23:47:46 +0200 Subject: [PATCH] chore: support CJS this PR changes the CI to run two protobuf generators, one for each, plus another for dts. currently untested. --- packages/javascript/package.json | 19 ++++++++---- packages/javascript/src/gen/version.d.ts | 1 - packages/javascript/src/index.d.ts | 21 ++++++------- packages/javascript/src/index.js | 39 ++++++++++++++++-------- packages/javascript/src/index.mjs | 13 ++++++++ 5 files changed, 63 insertions(+), 30 deletions(-) delete mode 100644 packages/javascript/src/gen/version.d.ts create mode 100644 packages/javascript/src/index.mjs diff --git a/packages/javascript/package.json b/packages/javascript/package.json index 2f56411d..8098810b 100644 --- a/packages/javascript/package.json +++ b/packages/javascript/package.json @@ -2,8 +2,8 @@ "name": "@livekit/protocol", "version": "1.27.1", "description": "", - "type": "module", "main": "src/index.js", + "module": "src/index.mjs", "types": "src/index.d.ts", "files": [ "src" @@ -11,16 +11,23 @@ "exports": { ".": { "types": "./src/index.d.ts", - "default": "./src/index.js" + "import": "./src/index.mjs", + "require": "./src/index.js" }, "./*": { - "types": "./src/gen/livekit_*_pb.d.ts", - "default": "./src/gen/livekit_*_pb.js" + "types": "./src/gen/dts/livekit_*_pb.d.ts", + "import": "./src/gen/esm/livekit_*_pb.js", + "require": "./src/gen/cjs/livekit_*_pb.js" } }, "scripts": { - "generate:version": "genversion --esm --semi src/gen/version.js", - "generate:proto": "protoc --es_out src/gen --es_opt target=js+dts -I=../../protobufs ../../protobufs/livekit_*.proto", + "generate:version:esm": "genversion --esm --semi src/gen/esm/version.js", + "generate:version:cjs": "genversion --semi src/gen/cjs/version.js", + "generate:version": "pnpm generate:version:esm && pnpm generate:version:cjs", + "generate:proto:esm": "protoc --es_out src/gen/esm --es_opt target=js -I=../../protobufs ../../protobufs/livekit_*.proto", + "generate:proto:cjs": "protoc --es_out src/gen/cjs --es_opt target=js,js_import_style=legacy_commonjs -I=../../protobufs ../../protobufs/livekit_*.proto", + "generate:proto:dts": "mkdir -p src/gen/dts && protoc --es_out src/gen/dts --es_opt target=dts -I=../../protobufs ../../protobufs/livekit_*.proto", + "generate:proto": "pnpm generate:proto:esm && pnpm generate:proto:cjs && pnpm generate:proto:dts", "build": "pnpm generate:version && pnpm generate:proto" }, "keywords": [], diff --git a/packages/javascript/src/gen/version.d.ts b/packages/javascript/src/gen/version.d.ts deleted file mode 100644 index baaee2fd..00000000 --- a/packages/javascript/src/gen/version.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const version: string; diff --git a/packages/javascript/src/index.d.ts b/packages/javascript/src/index.d.ts index 094183bb..a8371776 100644 --- a/packages/javascript/src/index.d.ts +++ b/packages/javascript/src/index.d.ts @@ -1,12 +1,11 @@ export { protoInt64 } from "@bufbuild/protobuf"; -export * from "./gen/livekit_agent_dispatch_pb.js"; -export * from "./gen/livekit_agent_pb.js"; -export * from "./gen/livekit_egress_pb.js"; -export * from "./gen/livekit_ingress_pb.js"; -export * from "./gen/livekit_metrics_pb.js"; -export * from "./gen/livekit_models_pb.js"; -export * from "./gen/livekit_room_pb.js"; -export * from "./gen/livekit_rtc_pb.js"; -export * from "./gen/livekit_sip_pb.js"; -export * from "./gen/livekit_webhook_pb.js"; -export * from "./gen/version.js"; +export type * from "./gen/dts/livekit_agent_dispatch_pb.d.ts"; +export type * from "./gen/dts/livekit_agent_pb.d.ts"; +export type * from "./gen/dts/livekit_egress_pb.d.ts"; +export type * from "./gen/dts/livekit_ingress_pb.d.ts"; +export type * from "./gen/dts/livekit_metrics_pb.d.ts"; +export type * from "./gen/dts/livekit_models_pb.d.ts"; +export type * from "./gen/dts/livekit_room_pb.d.ts"; +export type * from "./gen/dts/livekit_rtc_pb.d.ts"; +export type * from "./gen/dts/livekit_sip_pb.d.ts"; +export type * from "./gen/dts/livekit_webhook_pb.d.ts"; diff --git a/packages/javascript/src/index.js b/packages/javascript/src/index.js index 4c20c141..f7557618 100644 --- a/packages/javascript/src/index.js +++ b/packages/javascript/src/index.js @@ -1,13 +1,28 @@ // @ts-check -export { protoInt64 } from "@bufbuild/protobuf"; -export * from "./gen/livekit_agent_dispatch_pb.js"; -export * from "./gen/livekit_agent_pb.js"; -export * from "./gen/livekit_egress_pb.js"; -export * from "./gen/livekit_ingress_pb.js"; -export * from "./gen/livekit_metrics_pb.js"; -export * from "./gen/livekit_models_pb.js"; -export * from "./gen/livekit_room_pb.js"; -export * from "./gen/livekit_rtc_pb.js"; -export * from "./gen/livekit_sip_pb.js"; -export * from "./gen/livekit_webhook_pb.js"; -export * from "./gen/version.js"; +const { protoInt64 } = require("@bufbuild/protobuf"); +const agentDispatch = require("./gen/esm/livekit_agent_dispatch_pb.js"); +const agent = require("./gen/esm/livekit_agent_pb.js"); +const egress = require("./gen/esm/livekit_egress_pb.js"); +const ingress = require("./gen/esm/livekit_ingress_pb.js"); +const metrics = require("./gen/esm/livekit_metrics_pb.js"); +const models = require("./gen/esm/livekit_models_pb.js"); +const room = require("./gen/esm/livekit_room_pb.js"); +const rtc = require("./gen/esm/livekit_rtc_pb.js"); +const sip = require("./gen/esm/livekit_sip_pb.js"); +const webhook = require("./gen/esm/livekit_webhook_pb.js"); +const version = require("./gen/esm/version.js"); + +module.exports = { + protoInt64, + ...agentDispatch, + ...agent, + ...egress, + ...ingress, + ...metrics, + ...models, + ...room, + ...rtc, + ...sip, + ...webhook, + ...version, +} diff --git a/packages/javascript/src/index.mjs b/packages/javascript/src/index.mjs new file mode 100644 index 00000000..d377cabe --- /dev/null +++ b/packages/javascript/src/index.mjs @@ -0,0 +1,13 @@ +// @ts-check +export { protoInt64 } from "@bufbuild/protobuf"; +export * from "./gen/esm/livekit_agent_dispatch_pb.js"; +export * from "./gen/esm/livekit_agent_pb.js"; +export * from "./gen/esm/livekit_egress_pb.js"; +export * from "./gen/esm/livekit_ingress_pb.js"; +export * from "./gen/esm/livekit_metrics_pb.js"; +export * from "./gen/esm/livekit_models_pb.js"; +export * from "./gen/esm/livekit_room_pb.js"; +export * from "./gen/esm/livekit_rtc_pb.js"; +export * from "./gen/esm/livekit_sip_pb.js"; +export * from "./gen/esm/livekit_webhook_pb.js"; +export * from "./gen/esm/version.js";