From 3c9fb1b722d9b052d82381609358427bcbcf8d04 Mon Sep 17 00:00:00 2001 From: Wojciech Kozyra Date: Mon, 30 Sep 2024 17:57:16 +0200 Subject: [PATCH] ESM + CJS --- .github/workflows/ts_sdk_check.yml | 2 +- ts/.eslintrc.base.json | 12 ++ .../browser-render/package.json | 9 - ts/@live-compositor/core/.eslintignore | 3 +- ts/@live-compositor/core/.gitignore | 3 + ts/@live-compositor/core/package.json | 21 ++- ts/@live-compositor/core/src/api.ts | 2 +- ts/@live-compositor/core/src/api/input.ts | 2 +- ts/@live-compositor/core/src/api/renderer.ts | 2 +- ts/@live-compositor/core/src/compositor.ts | 14 +- .../core/src/compositorManager.ts | 2 +- ts/@live-compositor/core/src/index.ts | 6 +- ts/@live-compositor/core/src/output.ts | 8 +- ts/@live-compositor/core/src/renderer.ts | 4 +- ts/@live-compositor/core/tsconfig.cjs.json | 9 + ts/@live-compositor/core/tsconfig.json | 2 +- ts/live-compositor/.eslintignore | 3 +- ts/live-compositor/.gitignore | 3 +- ts/live-compositor/package.json | 21 ++- ts/live-compositor/src/api.ts | 2 +- ts/live-compositor/src/component.ts | 2 +- ts/live-compositor/src/components/Image.ts | 4 +- .../src/components/InputStream.ts | 10 +- ts/live-compositor/src/components/Rescaler.ts | 6 +- ts/live-compositor/src/components/Shader.ts | 4 +- ts/live-compositor/src/components/Text.ts | 6 +- ts/live-compositor/src/components/Tiles.ts | 6 +- ts/live-compositor/src/components/View.ts | 6 +- ts/live-compositor/src/components/WebView.ts | 4 +- ts/live-compositor/src/components/common.ts | 2 +- ts/live-compositor/src/context/index.ts | 4 +- .../src/context/instanceContextStore.ts | 2 +- .../src/context/outputContext.ts | 2 +- ts/live-compositor/src/hooks.ts | 6 +- ts/live-compositor/src/index.ts | 36 ++-- ts/live-compositor/src/internal.ts | 4 +- ts/live-compositor/src/types/registerInput.ts | 2 +- .../src/types/registerOutput.ts | 2 +- .../src/types/registerRenderer.ts | 2 +- ts/live-compositor/tsconfig.cjs.json | 9 + ts/live-compositor/tsconfig.json | 2 +- ts/package-lock.json | 156 ++++++++++++++++++ ts/package.json | 5 +- 43 files changed, 310 insertions(+), 102 deletions(-) create mode 100644 ts/@live-compositor/core/.gitignore create mode 100644 ts/@live-compositor/core/tsconfig.cjs.json create mode 100644 ts/live-compositor/tsconfig.cjs.json diff --git a/.github/workflows/ts_sdk_check.yml b/.github/workflows/ts_sdk_check.yml index ad3091269..f784491db 100644 --- a/.github/workflows/ts_sdk_check.yml +++ b/.github/workflows/ts_sdk_check.yml @@ -42,7 +42,7 @@ jobs: - name: Build working-directory: ./ts - run: npm run build + run: npm run build:all - name: Lint code working-directory: ./ts diff --git a/ts/.eslintrc.base.json b/ts/.eslintrc.base.json index 917923284..693c84045 100644 --- a/ts/.eslintrc.base.json +++ b/ts/.eslintrc.base.json @@ -8,6 +8,7 @@ "prettier" ], "plugins": [ + "import", "prettier" ], "parser": "@typescript-eslint/parser", @@ -16,6 +17,17 @@ "tsconfig.json" ] }, + "settings": { + "import/parsers": { + "@typescript-eslint/parser": [".ts", ".tsx"] + }, + "import/resolver": { + "typescript": { + "alwaysTryTypes": true, + "project": "**/tsconfig.json" + } + } + }, "rules": { "prettier/prettier": ["error"], "@typescript-eslint/no-explicit-any": [0, {}], diff --git a/ts/@live-compositor/browser-render/package.json b/ts/@live-compositor/browser-render/package.json index 150b9a9f1..fd1932dd8 100644 --- a/ts/@live-compositor/browser-render/package.json +++ b/ts/@live-compositor/browser-render/package.json @@ -23,14 +23,5 @@ }, "peerDependencies": { "live-compositor": "^0.1.0" - }, - "nx": { - "targets": { - "build": { - "dependsOn": [ - "build-wasm" - ] - } - } } } diff --git a/ts/@live-compositor/core/.eslintignore b/ts/@live-compositor/core/.eslintignore index 1521c8b76..55294f895 100644 --- a/ts/@live-compositor/core/.eslintignore +++ b/ts/@live-compositor/core/.eslintignore @@ -1 +1,2 @@ -dist +esm +cjs diff --git a/ts/@live-compositor/core/.gitignore b/ts/@live-compositor/core/.gitignore new file mode 100644 index 000000000..26300b6f8 --- /dev/null +++ b/ts/@live-compositor/core/.gitignore @@ -0,0 +1,3 @@ +node_modules +cjs +esm diff --git a/ts/@live-compositor/core/package.json b/ts/@live-compositor/core/package.json index 271599306..498568ecd 100644 --- a/ts/@live-compositor/core/package.json +++ b/ts/@live-compositor/core/package.json @@ -2,19 +2,30 @@ "name": "@live-compositor/core", "version": "0.1.0", "description": "", - "main": "dist/index.js", + "type": "module", + "main": "cjs/index.js", + "exports": { + "import": "./esm/index.js", + "require": "./cjs/index.js", + "types": "./esm/index.d.ts" + }, "scripts": { "lint": "eslint .", "typecheck": "tsc --noEmit", - "watch": "tsc --watch --preserveWatchOutput", - "build": "tsc", - "clean": "rimraf dist", + "watch": "concurrently \"npm run watch:esm\" \"npm run watch:cjs\"", + "watch:esm": "tsc --watch --preserveWatchOutput", + "watch:cjs": "tsc --watch --preserveWatchOutput -p ./tsconfig.cjs.json", + "build": "npm run build:esm && npm run build:cjs", + "build:esm": "tsc && echo '{\"type\": \"module\"}' > esm/package.json", + "build:cjs": "tsc -p ./tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > cjs/package.json", + "clean": "rimraf esm cjs", "prepublishOnly": "npm run clean && npm run build" }, "author": "", "license": "MIT", "files": [ - "/dist" + "/esm", + "/cjs" ], "devDependencies": { "@types/react-reconciler": "0.28.8" diff --git a/ts/@live-compositor/core/src/api.ts b/ts/@live-compositor/core/src/api.ts index fa517323a..8340d8fc6 100644 --- a/ts/@live-compositor/core/src/api.ts +++ b/ts/@live-compositor/core/src/api.ts @@ -1,5 +1,5 @@ import { Api } from 'live-compositor'; -import { CompositorManager } from './compositorManager'; +import { CompositorManager } from './compositorManager.js'; export { Api }; diff --git a/ts/@live-compositor/core/src/api/input.ts b/ts/@live-compositor/core/src/api/input.ts index 57e697f90..8d74a208f 100644 --- a/ts/@live-compositor/core/src/api/input.ts +++ b/ts/@live-compositor/core/src/api/input.ts @@ -1,4 +1,4 @@ -import { Api } from '../api'; +import { Api } from '../api.js'; import { RegisterInput, Inputs } from 'live-compositor'; export function intoRegisterInput(input: RegisterInput): Api.RegisterInput { diff --git a/ts/@live-compositor/core/src/api/renderer.ts b/ts/@live-compositor/core/src/api/renderer.ts index d8b3ad361..f75dff1e9 100644 --- a/ts/@live-compositor/core/src/api/renderer.ts +++ b/ts/@live-compositor/core/src/api/renderer.ts @@ -1,4 +1,4 @@ -import { Api } from '../api'; +import { Api } from '../api.js'; import { Renderers } from 'live-compositor'; export function intoRegisterImage(image: Renderers.RegisterImage): Api.ImageSpec { diff --git a/ts/@live-compositor/core/src/compositor.ts b/ts/@live-compositor/core/src/compositor.ts index 66ba74a71..b4f9ee9b4 100644 --- a/ts/@live-compositor/core/src/compositor.ts +++ b/ts/@live-compositor/core/src/compositor.ts @@ -4,13 +4,13 @@ import { RegisterOutput, Renderers, } from 'live-compositor'; -import { ApiClient } from './api'; -import Output from './output'; -import { CompositorManager } from './compositorManager'; -import { intoRegisterOutput } from './api/output'; -import { intoRegisterInput } from './api/input'; -import { onCompositorEvent } from './event'; -import { intoRegisterImage, intoRegisterWebRenderer } from './api/renderer'; +import { ApiClient } from './api.js'; +import Output from './output.js'; +import { CompositorManager } from './compositorManager.js'; +import { intoRegisterOutput } from './api/output.js'; +import { intoRegisterInput } from './api/input.js'; +import { onCompositorEvent } from './event.js'; +import { intoRegisterImage, intoRegisterWebRenderer } from './api/renderer.js'; export class LiveCompositor { private manager: CompositorManager; diff --git a/ts/@live-compositor/core/src/compositorManager.ts b/ts/@live-compositor/core/src/compositorManager.ts index 8ba4db1ac..6af287159 100644 --- a/ts/@live-compositor/core/src/compositorManager.ts +++ b/ts/@live-compositor/core/src/compositorManager.ts @@ -1,4 +1,4 @@ -import { ApiRequest } from './api'; +import { ApiRequest } from './api.js'; export interface CompositorManager { setupInstance(): Promise; diff --git a/ts/@live-compositor/core/src/index.ts b/ts/@live-compositor/core/src/index.ts index 4d82a0b65..0c2f6703d 100644 --- a/ts/@live-compositor/core/src/index.ts +++ b/ts/@live-compositor/core/src/index.ts @@ -1,3 +1,3 @@ -export { ApiClient, ApiRequest } from './api'; -export { LiveCompositor } from './compositor'; -export { CompositorManager } from './compositorManager'; +export { ApiClient, ApiRequest } from './api.js'; +export { LiveCompositor } from './compositor.js'; +export { CompositorManager } from './compositorManager.js'; diff --git a/ts/@live-compositor/core/src/output.ts b/ts/@live-compositor/core/src/output.ts index e6f6f060a..bad2aa7b6 100644 --- a/ts/@live-compositor/core/src/output.ts +++ b/ts/@live-compositor/core/src/output.ts @@ -1,9 +1,9 @@ import { _liveCompositorInternals, RegisterOutput, View, Outputs } from 'live-compositor'; import React, { useSyncExternalStore } from 'react'; -import { ApiClient, Api } from './api'; -import Renderer from './renderer'; -import { intoAudioInputsConfiguration } from './api/output'; -import { throttle } from './utils'; +import { ApiClient, Api } from './api.js'; +import Renderer from './renderer.js'; +import { intoAudioInputsConfiguration } from './api/output.js'; +import { throttle } from './utils.js'; type OutputContext = _liveCompositorInternals.OutputContext; type InstanceContextStore = _liveCompositorInternals.InstanceContextStore; diff --git a/ts/@live-compositor/core/src/renderer.ts b/ts/@live-compositor/core/src/renderer.ts index a9e33c057..c4b500e92 100644 --- a/ts/@live-compositor/core/src/renderer.ts +++ b/ts/@live-compositor/core/src/renderer.ts @@ -1,6 +1,6 @@ import Reconciler from 'react-reconciler'; -import { DefaultEventPriority, LegacyRoot } from 'react-reconciler/constants'; -import { Api } from './api'; +import { DefaultEventPriority, LegacyRoot } from 'react-reconciler/constants.js'; +import { Api } from './api.js'; import { _liveCompositorInternals } from 'live-compositor'; import React from 'react'; diff --git a/ts/@live-compositor/core/tsconfig.cjs.json b/ts/@live-compositor/core/tsconfig.cjs.json new file mode 100644 index 000000000..9513b5819 --- /dev/null +++ b/ts/@live-compositor/core/tsconfig.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "cjs", + "module": "commonjs", + "moduleResolution": "node", + "esModuleInterop": true + } +} diff --git a/ts/@live-compositor/core/tsconfig.json b/ts/@live-compositor/core/tsconfig.json index 4e94ea868..738a96a32 100644 --- a/ts/@live-compositor/core/tsconfig.json +++ b/ts/@live-compositor/core/tsconfig.json @@ -1,6 +1,6 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "outDir": "dist" + "outDir": "esm" } } diff --git a/ts/live-compositor/.eslintignore b/ts/live-compositor/.eslintignore index 1521c8b76..55294f895 100644 --- a/ts/live-compositor/.eslintignore +++ b/ts/live-compositor/.eslintignore @@ -1 +1,2 @@ -dist +esm +cjs diff --git a/ts/live-compositor/.gitignore b/ts/live-compositor/.gitignore index f06235c46..1a57bdc18 100644 --- a/ts/live-compositor/.gitignore +++ b/ts/live-compositor/.gitignore @@ -1,2 +1,3 @@ node_modules -dist +esm +cjs diff --git a/ts/live-compositor/package.json b/ts/live-compositor/package.json index f4d32fe9c..cd1ae012d 100644 --- a/ts/live-compositor/package.json +++ b/ts/live-compositor/package.json @@ -2,13 +2,23 @@ "name": "live-compositor", "version": "0.1.0", "description": "", - "main": "dist/index.js", + "type": "module", + "main": "cjs/index.js", + "exports": { + "import": "./esm/index.js", + "require": "./cjs/index.js", + "types": "./esm/index.d.ts" + }, "scripts": { "lint": "eslint .", "typecheck": "tsc --noEmit", - "watch": "tsc --watch --preserveWatchOutput", - "build": "tsc", - "clean": "rimraf dist", + "watch": "concurrently \"npm run watch:esm\" \"npm run watch:cjs\"", + "watch:esm": "tsc --watch --preserveWatchOutput", + "watch:cjs": "tsc --watch --preserveWatchOutput -p ./tsconfig.cjs.json", + "build": "npm run build:esm && npm run build:cjs", + "build:esm": "tsc && echo '{\"type\": \"module\"}' > esm/package.json", + "build:cjs": "tsc -p ./tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > cjs/package.json", + "clean": "rimraf esm cjs", "prepublishOnly": "npm run clean && npm run build" }, "author": "", @@ -18,7 +28,8 @@ }, "homepage": "https://github.com/software-mansion/live-compositor", "files": [ - "/dist" + "/esm", + "/cjs" ], "devDependencies": { "@types/react": "^18.3.3" diff --git a/ts/live-compositor/src/api.ts b/ts/live-compositor/src/api.ts index 6bb6559ad..efddd886f 100644 --- a/ts/live-compositor/src/api.ts +++ b/ts/live-compositor/src/api.ts @@ -1 +1 @@ -export * from './api.generated'; +export * from './api.generated.js'; diff --git a/ts/live-compositor/src/component.ts b/ts/live-compositor/src/component.ts index 82f7c9167..abd075010 100644 --- a/ts/live-compositor/src/component.ts +++ b/ts/live-compositor/src/component.ts @@ -1,5 +1,5 @@ import React, { useId } from 'react'; -import * as Api from './api'; +import * as Api from './api.js'; type ComponentProps

= { children?: React.ReactNode; id?: Api.ComponentId } & P; diff --git a/ts/live-compositor/src/components/Image.ts b/ts/live-compositor/src/components/Image.ts index 74b359a4a..4d8fa7483 100644 --- a/ts/live-compositor/src/components/Image.ts +++ b/ts/live-compositor/src/components/Image.ts @@ -1,5 +1,5 @@ -import * as Api from '../api'; -import { createCompositorComponent, SceneComponent } from '../component'; +import * as Api from '../api.js'; +import { createCompositorComponent, SceneComponent } from '../component.js'; export type ImageProps = { children?: undefined; diff --git a/ts/live-compositor/src/components/InputStream.ts b/ts/live-compositor/src/components/InputStream.ts index 7018a90e8..27ef54016 100644 --- a/ts/live-compositor/src/components/InputStream.ts +++ b/ts/live-compositor/src/components/InputStream.ts @@ -1,7 +1,7 @@ -import React from 'react'; -import * as Api from '../api'; -import { createCompositorComponent, SceneComponent } from '../component'; -import { useAudioInput } from '../hooks'; +import { createElement } from 'react'; +import * as Api from '../api.js'; +import { createCompositorComponent, SceneComponent } from '../component.js'; +import { useAudioInput } from '../hooks.js'; export type InputStreamProps = { children?: undefined; @@ -34,7 +34,7 @@ function InputStream(props: InputStreamProps) { useAudioInput(props.inputId, { volume: mute ? 0 : (volume ?? 1), }); - return React.createElement(InnerInputStream, otherProps); + return createElement(InnerInputStream, otherProps); } function sceneBuilder(props: InputStreamProps, _children: SceneComponent[]): Api.Component { diff --git a/ts/live-compositor/src/components/Rescaler.ts b/ts/live-compositor/src/components/Rescaler.ts index 472eafc04..a1080ed47 100644 --- a/ts/live-compositor/src/components/Rescaler.ts +++ b/ts/live-compositor/src/components/Rescaler.ts @@ -1,7 +1,7 @@ import React from 'react'; -import * as Api from '../api'; -import { intoApiTransition, Transition } from './common'; -import { createCompositorComponent, SceneComponent, sceneComponentIntoApi } from '../component'; +import * as Api from '../api.js'; +import { intoApiTransition, Transition } from './common.js'; +import { createCompositorComponent, SceneComponent, sceneComponentIntoApi } from '../component.js'; export type RescalerProps = { children: React.ReactElement | string | number; diff --git a/ts/live-compositor/src/components/Shader.ts b/ts/live-compositor/src/components/Shader.ts index f97c882bd..73809d5db 100644 --- a/ts/live-compositor/src/components/Shader.ts +++ b/ts/live-compositor/src/components/Shader.ts @@ -1,5 +1,5 @@ -import * as Api from '../api'; -import { createCompositorComponent, SceneComponent, sceneComponentIntoApi } from '../component'; +import * as Api from '../api.js'; +import { createCompositorComponent, SceneComponent, sceneComponentIntoApi } from '../component.js'; export type ShaderProps = { /** diff --git a/ts/live-compositor/src/components/Text.ts b/ts/live-compositor/src/components/Text.ts index 4dfe6015b..a5d5b9959 100644 --- a/ts/live-compositor/src/components/Text.ts +++ b/ts/live-compositor/src/components/Text.ts @@ -1,6 +1,6 @@ -import * as Api from '../api'; -import { createCompositorComponent, SceneComponent } from '../component'; -import { intoApiRgbaColor } from './common'; +import * as Api from '../api.js'; +import { createCompositorComponent, SceneComponent } from '../component.js'; +import { intoApiRgbaColor } from './common.js'; export type TextProps = { children?: (string | number)[] | string | number; diff --git a/ts/live-compositor/src/components/Tiles.ts b/ts/live-compositor/src/components/Tiles.ts index c462bff12..b900f95ca 100644 --- a/ts/live-compositor/src/components/Tiles.ts +++ b/ts/live-compositor/src/components/Tiles.ts @@ -1,6 +1,6 @@ -import * as Api from '../api'; -import { intoApiRgbaColor, intoApiTransition, Transition } from './common'; -import { createCompositorComponent, SceneComponent, sceneComponentIntoApi } from '../component'; +import * as Api from '../api.js'; +import { intoApiRgbaColor, intoApiTransition, Transition } from './common.js'; +import { createCompositorComponent, SceneComponent, sceneComponentIntoApi } from '../component.js'; export type TilesProps = { /** diff --git a/ts/live-compositor/src/components/View.ts b/ts/live-compositor/src/components/View.ts index d29575a24..5a7e3a8c9 100644 --- a/ts/live-compositor/src/components/View.ts +++ b/ts/live-compositor/src/components/View.ts @@ -1,6 +1,6 @@ -import * as Api from '../api'; -import { createCompositorComponent, SceneComponent, sceneComponentIntoApi } from '../component'; -import { intoApiRgbaColor, intoApiTransition, Transition } from './common'; +import * as Api from '../api.js'; +import { createCompositorComponent, SceneComponent, sceneComponentIntoApi } from '../component.js'; +import { intoApiRgbaColor, intoApiTransition, Transition } from './common.js'; export type ViewProps = { /** diff --git a/ts/live-compositor/src/components/WebView.ts b/ts/live-compositor/src/components/WebView.ts index 0d4bc6ea3..d781c66a0 100644 --- a/ts/live-compositor/src/components/WebView.ts +++ b/ts/live-compositor/src/components/WebView.ts @@ -1,5 +1,5 @@ -import * as Api from '../api'; -import { createCompositorComponent, SceneComponent, sceneComponentIntoApi } from '../component'; +import * as Api from '../api.js'; +import { createCompositorComponent, SceneComponent, sceneComponentIntoApi } from '../component.js'; export type WebViewProps = { /** diff --git a/ts/live-compositor/src/components/common.ts b/ts/live-compositor/src/components/common.ts index a911102c9..4678627a7 100644 --- a/ts/live-compositor/src/components/common.ts +++ b/ts/live-compositor/src/components/common.ts @@ -1,4 +1,4 @@ -import * as Api from '../api'; +import * as Api from '../api.js'; export interface Transition { /** diff --git a/ts/live-compositor/src/context/index.ts b/ts/live-compositor/src/context/index.ts index 39a85e471..da77c93c8 100644 --- a/ts/live-compositor/src/context/index.ts +++ b/ts/live-compositor/src/context/index.ts @@ -1,6 +1,6 @@ import { createContext } from 'react'; -import { InstanceContextStore } from './instanceContextStore'; -import { OutputContext } from './outputContext'; +import { InstanceContextStore } from './instanceContextStore.js'; +import { OutputContext } from './outputContext.js'; type CompositorOutputContext = { // global store for the entire LiveCompositor instance diff --git a/ts/live-compositor/src/context/instanceContextStore.ts b/ts/live-compositor/src/context/instanceContextStore.ts index 61dd619a3..1b24ab5b2 100644 --- a/ts/live-compositor/src/context/instanceContextStore.ts +++ b/ts/live-compositor/src/context/instanceContextStore.ts @@ -1,4 +1,4 @@ -import * as Api from '../api'; +import * as Api from '../api.js'; export type StreamState = 'ready' | 'playing' | 'finished'; diff --git a/ts/live-compositor/src/context/outputContext.ts b/ts/live-compositor/src/context/outputContext.ts index d8fa56ff0..7aedb18bd 100644 --- a/ts/live-compositor/src/context/outputContext.ts +++ b/ts/live-compositor/src/context/outputContext.ts @@ -1,4 +1,4 @@ -import { AudioInputsConfiguration } from '../types/registerOutput'; +import { AudioInputsConfiguration } from '../types/registerOutput.js'; export type ContextAudioOptions = { volume: number; diff --git a/ts/live-compositor/src/hooks.ts b/ts/live-compositor/src/hooks.ts index 90f51991d..370fa7226 100644 --- a/ts/live-compositor/src/hooks.ts +++ b/ts/live-compositor/src/hooks.ts @@ -1,8 +1,8 @@ import { useContext, useEffect, useSyncExternalStore } from 'react'; -import * as Api from './api'; -import { LiveCompositorContext } from './context'; -import { InputStreamInfo } from './context/instanceContextStore'; +import * as Api from './api.js'; +import { LiveCompositorContext } from './context/index.js'; +import { InputStreamInfo } from './context/instanceContextStore.js'; export function useInputStreams(): Record { const ctx = useContext(LiveCompositorContext); diff --git a/ts/live-compositor/src/index.ts b/ts/live-compositor/src/index.ts index 2b8e2d4be..15bd4cbfc 100644 --- a/ts/live-compositor/src/index.ts +++ b/ts/live-compositor/src/index.ts @@ -1,23 +1,23 @@ -import View, { ViewProps } from './components/View'; -import Image, { ImageProps } from './components/Image'; -import Text, { TextProps } from './components/Text'; -import InputStream, { InputStreamProps } from './components/InputStream'; -import Rescaler, { RescalerProps } from './components/Rescaler'; -import WebView, { WebViewProps } from './components/WebView'; -import Shader, { ShaderParam, ShaderParamStructField, ShaderProps } from './components/Shader'; -import Tiles, { TilesProps } from './components/Tiles'; -import { EasingFunction, Transition } from './components/common'; -import { useAudioInput, useInputStreams } from './hooks'; -import { CompositorEvent, CompositorEventType } from './types/events'; +import View, { ViewProps } from './components/View.js'; +import Image, { ImageProps } from './components/Image.js'; +import Text, { TextProps } from './components/Text.js'; +import InputStream, { InputStreamProps } from './components/InputStream.js'; +import Rescaler, { RescalerProps } from './components/Rescaler.js'; +import WebView, { WebViewProps } from './components/WebView.js'; +import Shader, { ShaderParam, ShaderParamStructField, ShaderProps } from './components/Shader.js'; +import Tiles, { TilesProps } from './components/Tiles.js'; +import { EasingFunction, Transition } from './components/common.js'; +import { useAudioInput, useInputStreams } from './hooks.js'; +import { CompositorEvent, CompositorEventType } from './types/events.js'; -export { RegisterInput } from './types/registerInput'; -export { RegisterOutput } from './types/registerOutput'; +export { RegisterInput } from './types/registerInput.js'; +export { RegisterOutput } from './types/registerOutput.js'; -export * as Inputs from './types/registerInput'; -export * as Outputs from './types/registerOutput'; -export * as Renderers from './types/registerRenderer'; -export * as Api from './api'; -export * as _liveCompositorInternals from './internal'; +export * as Inputs from './types/registerInput.js'; +export * as Outputs from './types/registerOutput.js'; +export * as Renderers from './types/registerRenderer.js'; +export * as Api from './api.js'; +export * as _liveCompositorInternals from './internal.js'; export { View, diff --git a/ts/live-compositor/src/internal.ts b/ts/live-compositor/src/internal.ts index 8af1b8f67..3edf6c708 100644 --- a/ts/live-compositor/src/internal.ts +++ b/ts/live-compositor/src/internal.ts @@ -1,4 +1,4 @@ // Internal logic used by `@live-compositor/core`, do not use directly -export { InstanceContextStore, OutputContext, LiveCompositorContext } from './context'; -export { SceneBuilder, SceneComponent } from './component'; +export { InstanceContextStore, OutputContext, LiveCompositorContext } from './context/index.js'; +export { SceneBuilder, SceneComponent } from './component.js'; diff --git a/ts/live-compositor/src/types/registerInput.ts b/ts/live-compositor/src/types/registerInput.ts index 88b2cf0b6..e0d0b38bb 100644 --- a/ts/live-compositor/src/types/registerInput.ts +++ b/ts/live-compositor/src/types/registerInput.ts @@ -1,4 +1,4 @@ -import * as Api from '../api'; +import * as Api from '../api.js'; export type RegisterInput = | ({ type: 'rtp_stream' } & RegisterRtpInput) diff --git a/ts/live-compositor/src/types/registerOutput.ts b/ts/live-compositor/src/types/registerOutput.ts index 9aa4311fa..620c9428e 100644 --- a/ts/live-compositor/src/types/registerOutput.ts +++ b/ts/live-compositor/src/types/registerOutput.ts @@ -1,5 +1,5 @@ import React from 'react'; -import * as Api from '../api'; +import * as Api from '../api.js'; export type RegisterOutput = | ({ type: 'rtp_stream' } & RegisterRtpOutput) diff --git a/ts/live-compositor/src/types/registerRenderer.ts b/ts/live-compositor/src/types/registerRenderer.ts index 1e4ebbcc2..72b5ed030 100644 --- a/ts/live-compositor/src/types/registerRenderer.ts +++ b/ts/live-compositor/src/types/registerRenderer.ts @@ -1,4 +1,4 @@ -import * as Api from '../api'; +import * as Api from '../api.js'; export type RegisterShader = Api.ShaderSpec; diff --git a/ts/live-compositor/tsconfig.cjs.json b/ts/live-compositor/tsconfig.cjs.json new file mode 100644 index 000000000..6812a1212 --- /dev/null +++ b/ts/live-compositor/tsconfig.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "cjs", + "module": "commonjs", + "moduleResolution": "node", + "target": "es2015" + } +} diff --git a/ts/live-compositor/tsconfig.json b/ts/live-compositor/tsconfig.json index 9f48d7e4c..27edaeb17 100644 --- a/ts/live-compositor/tsconfig.json +++ b/ts/live-compositor/tsconfig.json @@ -1,6 +1,6 @@ { "extends": "../tsconfig.base.json", "compilerOptions": { - "outDir": "dist" + "outDir": "esm" } } diff --git a/ts/package-lock.json b/ts/package-lock.json index 01c79e495..ed4c82c97 100644 --- a/ts/package-lock.json +++ b/ts/package-lock.json @@ -21,8 +21,10 @@ "devDependencies": { "@typescript-eslint/eslint-plugin": "^7.16.0", "@typescript-eslint/parser": "^7.18.0", + "concurrently": "^9.0.1", "eslint": "^8.57.0", "eslint-config-prettier": "^9.1.0", + "eslint-import-resolver-typescript": "^3.6.3", "eslint-plugin-import": "^2.29.1", "eslint-plugin-prettier": "^5.1.3", "json-schema-to-typescript": "^15.0.1", @@ -1701,6 +1703,15 @@ "node": ">= 8" } }, + "node_modules/@nolyfill/is-core-module": { + "version": "1.0.39", + "resolved": "https://registry.npmjs.org/@nolyfill/is-core-module/-/is-core-module-1.0.39.tgz", + "integrity": "sha512-nn5ozdjYQpUCZlWGuxcJY/KpxkWQs4DcbMCmKojjyrYDEAGy4Ce19NN4v5MduafTwJlbKc99UA8YhSVqq9yPZA==", + "dev": true, + "engines": { + "node": ">=12.4.0" + } + }, "node_modules/@npmcli/agent": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/@npmcli/agent/-/agent-2.2.2.tgz", @@ -4760,6 +4771,46 @@ "typedarray": "^0.0.6" } }, + "node_modules/concurrently": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-9.0.1.tgz", + "integrity": "sha512-wYKvCd/f54sTXJMSfV6Ln/B8UrfLBKOYa+lzc6CHay3Qek+LorVSBdMVfyewFhRbH0Rbabsk4D+3PL/VjQ5gzg==", + "dev": true, + "dependencies": { + "chalk": "^4.1.2", + "lodash": "^4.17.21", + "rxjs": "^7.8.1", + "shell-quote": "^1.8.1", + "supports-color": "^8.1.1", + "tree-kill": "^1.2.2", + "yargs": "^17.7.2" + }, + "bin": { + "conc": "dist/bin/concurrently.js", + "concurrently": "dist/bin/concurrently.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/open-cli-tools/concurrently?sponsor=1" + } + }, + "node_modules/concurrently/node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, "node_modules/console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", @@ -5484,6 +5535,19 @@ "once": "^1.4.0" } }, + "node_modules/enhanced-resolve": { + "version": "5.17.1", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.17.1.tgz", + "integrity": "sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.4", + "tapable": "^2.2.0" + }, + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/enquirer": { "version": "2.3.6", "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", @@ -5833,6 +5897,41 @@ "ms": "^2.1.1" } }, + "node_modules/eslint-import-resolver-typescript": { + "version": "3.6.3", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-3.6.3.tgz", + "integrity": "sha512-ud9aw4szY9cCT1EWWdGv1L1XR6hh2PaRWif0j2QjQ0pgTY/69iw+W0Z4qZv5wHahOl8isEr+k/JnyAqNQkLkIA==", + "dev": true, + "dependencies": { + "@nolyfill/is-core-module": "1.0.39", + "debug": "^4.3.5", + "enhanced-resolve": "^5.15.0", + "eslint-module-utils": "^2.8.1", + "fast-glob": "^3.3.2", + "get-tsconfig": "^4.7.5", + "is-bun-module": "^1.0.2", + "is-glob": "^4.0.3" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts/projects/eslint-import-resolver-ts" + }, + "peerDependencies": { + "eslint": "*", + "eslint-plugin-import": "*", + "eslint-plugin-import-x": "*" + }, + "peerDependenciesMeta": { + "eslint-plugin-import": { + "optional": true + }, + "eslint-plugin-import-x": { + "optional": true + } + } + }, "node_modules/eslint-module-utils": { "version": "2.11.0", "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.11.0.tgz", @@ -7073,6 +7172,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-tsconfig": { + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.8.1.tgz", + "integrity": "sha512-k9PN+cFBmaLWtVz29SkUoqU5O0slLuHJXt/2P+tMVFT+phsSGXGkp9t3rQIqdz0e+06EHNGs3oM6ZX1s2zHxRg==", + "dev": true, + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, "node_modules/git-raw-commits": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/git-raw-commits/-/git-raw-commits-3.0.0.tgz", @@ -7858,6 +7969,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-bun-module": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-bun-module/-/is-bun-module-1.2.1.tgz", + "integrity": "sha512-AmidtEM6D6NmUiLOvvU7+IePxjEjOzra2h0pSrsfSAcXwl/83zLLXDByafUJy9k/rKK0pvXMLdwKwGHlX2Ke6Q==", + "dev": true, + "dependencies": { + "semver": "^7.6.3" + } + }, "node_modules/is-callable": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", @@ -11526,6 +11646,15 @@ "node": ">=4" } }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, "node_modules/restore-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", @@ -12064,6 +12193,15 @@ "node": ">=8" } }, + "node_modules/shell-quote": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz", + "integrity": "sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/side-channel": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", @@ -12546,6 +12684,15 @@ "url": "https://opencollective.com/unts" } }, + "node_modules/tapable": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", + "integrity": "sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/tar": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.1.tgz", @@ -12814,6 +12961,15 @@ "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", "license": "MIT" }, + "node_modules/tree-kill": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", + "integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==", + "dev": true, + "bin": { + "tree-kill": "cli.js" + } + }, "node_modules/treeverse": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/treeverse/-/treeverse-3.0.0.tgz", diff --git a/ts/package.json b/ts/package.json index bcadbc6d5..6051808d9 100644 --- a/ts/package.json +++ b/ts/package.json @@ -6,7 +6,8 @@ "lint": "lerna run lint", "lint:fix": "lerna run lint -- --fix", "build": "lerna run build --concurrency=1", - "build-sdk": "lerna run build --concurrency 1 --scope @live-compositor/core --scope @live-compositor/node --scope live-compositor", + "build:sdk": "lerna run build --concurrency 1 --scope @live-compositor/core --scope @live-compositor/node --scope live-compositor", + "build:all": "npm run -w @live-compositor/browser-render build-wasm && npm run build", "typecheck": "lerna run typecheck", "clean": "lerna run clean", "watch": "lerna run --parallel --stream watch --private", @@ -26,8 +27,10 @@ "devDependencies": { "@typescript-eslint/eslint-plugin": "^7.16.0", "@typescript-eslint/parser": "^7.18.0", + "concurrently": "^9.0.1", "eslint": "^8.57.0", "eslint-config-prettier": "^9.1.0", + "eslint-import-resolver-typescript": "^3.6.3", "eslint-plugin-import": "^2.29.1", "eslint-plugin-prettier": "^5.1.3", "json-schema-to-typescript": "^15.0.1",