From 58124aeb8a662cc53a201124a67b57a5c3aebda4 Mon Sep 17 00:00:00 2001 From: Andreas Engberg Date: Mon, 15 Jun 2026 11:57:07 +0200 Subject: [PATCH 1/4] correctly create csj and esm build --- package.json | 36 ++++++++++++++++++------------------ tsconfig.esm.json | 9 +++++++++ tsconfig.json | 4 ++-- tsconfig.rollup.json | 3 ++- 4 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 tsconfig.esm.json diff --git a/package.json b/package.json index 87fc9e1..3aaa548 100644 --- a/package.json +++ b/package.json @@ -2,33 +2,33 @@ "name": "openspace-api-js", "version": "1.0.0", "description": "OpenSpace Socket/Websocket API bindings for JavaScript", - "main": "./dist/node.js", + "main": "./dist/cjs/node.js", "browser": { - "./dist/node.js": "./dist/browser.js" + "./dist/cjs/node.js": "./dist/cjs/browser.js" }, - "types": "./dist/node.d.ts", + "types": "./dist/cjs/node.d.ts", "exports": { ".": { - "types": "./dist/node.d.ts", - "import": "./dist/node.js", - "require": "./dist/node.js", - "browser": "./dist/browser.js", - "default": "./dist/node.js" + "browser": "./dist/esm/browser.js", + "import": "./dist/esm/node.js", + "require": "./dist/cjs/node.js", + "types": "./dist/cjs/node.d.ts", + "default": "./dist/cjs/node.js" }, "./api": { - "types": "./dist/api.d.ts", - "import": "./dist/api.js", - "require": "./dist/api.js" + "import": "./dist/esm/api.js", + "require": "./dist/cjs/api.js", + "types": "./dist/cjs/api.d.ts" }, "./types": { - "types": "./dist/types/index.d.ts", - "import": "./dist/types/index.js", - "require": "./dist/types/index.js" + "import": "./dist/esm/types/index.js", + "require": "./dist/cjs/types/index.js", + "types": "./dist/cjs/types/index.d.ts" }, "./topics": { - "types": "./dist/topic.d.ts", - "import": "./dist/topic.js", - "require": "./dist/topic.js" + "import": "./dist/esm/topic.js", + "require": "./dist/cjs/topic.js", + "types": "./dist/cjs/topic.d.ts" } }, "files": [ @@ -36,7 +36,7 @@ "README.md" ], "scripts": { - "build": "rimraf dist && tsc --project tsconfig.json && rollup --config rollup.config.ts --configPlugin typescript", + "build": "rimraf dist && tsc --project tsconfig.json && tsc --project tsconfig.esm.json && rollup --config rollup.config.ts --configPlugin typescript", "typecheck": "tsc --noEmit", "generate-lua-library": "pip install -r script/requirements.txt && python script/generatetypescriptfile.py", "generate-topic-types": "node script/generatetopictypes.mjs", diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..733a2e5 --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "esnext", + "moduleResolution": "bundler", + "outDir": "./dist/esm", + "declarationDir": "./dist/esm" + } +} diff --git a/tsconfig.json b/tsconfig.json index bb0303a..ffcc7f2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,10 +3,10 @@ "target": "es2022", "module": "commonjs", "lib": ["ES2023", "DOM"], - "outDir": "./dist", + "outDir": "./dist/cjs", "rootDir": "./src", "declaration": true, - "declarationDir": "./dist", + "declarationDir": "./dist/cjs", "strict": true, "esModuleInterop": true, "skipLibCheck": true, diff --git a/tsconfig.rollup.json b/tsconfig.rollup.json index ea5b7c7..b418856 100644 --- a/tsconfig.rollup.json +++ b/tsconfig.rollup.json @@ -2,6 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "module": "esnext", - "moduleResolution": "bundler" + "moduleResolution": "bundler", + "outDir": "./dist" } } From 22587759bbe32ef4441be8dec1494f389a109b40 Mon Sep 17 00:00:00 2001 From: Andreas Engberg Date: Mon, 15 Jun 2026 11:59:09 +0200 Subject: [PATCH 2/4] Update API to version 1.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3aaa548..a5183ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openspace-api-js", - "version": "1.0.0", + "version": "1.0.2", "description": "OpenSpace Socket/Websocket API bindings for JavaScript", "main": "./dist/cjs/node.js", "browser": { From d8bb9c98e6d40e43d6ac0c76647d669bc42aa186 Mon Sep 17 00:00:00 2001 From: Andreas Engberg Date: Mon, 15 Jun 2026 12:33:02 +0200 Subject: [PATCH 3/4] split config for esm and cjs --- package.json | 2 +- tsconfig.cjs.json | 10 ++++++++++ tsconfig.esm.json | 1 + tsconfig.json | 4 ---- 4 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 tsconfig.cjs.json diff --git a/package.json b/package.json index a5183ab..f81d6ad 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "README.md" ], "scripts": { - "build": "rimraf dist && tsc --project tsconfig.json && tsc --project tsconfig.esm.json && rollup --config rollup.config.ts --configPlugin typescript", + "build": "rimraf dist && tsc --project tsconfig.cjs.json && tsc --project tsconfig.esm.json && rollup --config rollup.config.ts --configPlugin typescript", "typecheck": "tsc --noEmit", "generate-lua-library": "pip install -r script/requirements.txt && python script/generatetypescriptfile.py", "generate-topic-types": "node script/generatetopictypes.mjs", diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..26bdc1a --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "node16", + "moduleResolution": "node16", + "declaration": true, + "outDir": "./dist/cjs", + "declarationDir": "./dist/cjs" + } +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json index 733a2e5..83a235d 100644 --- a/tsconfig.esm.json +++ b/tsconfig.esm.json @@ -3,6 +3,7 @@ "compilerOptions": { "module": "esnext", "moduleResolution": "bundler", + "declaration": true, "outDir": "./dist/esm", "declarationDir": "./dist/esm" } diff --git a/tsconfig.json b/tsconfig.json index ffcc7f2..1ad07cf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,8 @@ { "compilerOptions": { "target": "es2022", - "module": "commonjs", "lib": ["ES2023", "DOM"], - "outDir": "./dist/cjs", "rootDir": "./src", - "declaration": true, - "declarationDir": "./dist/cjs", "strict": true, "esModuleInterop": true, "skipLibCheck": true, From 294c7fc901e195e8eff12724123c2e38db373f1d Mon Sep 17 00:00:00 2001 From: Andreas Engberg Date: Mon, 15 Jun 2026 12:33:37 +0200 Subject: [PATCH 4/4] update examples --- examples/example.js | 4 ++-- examples/example.ts | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/example.js b/examples/example.js index 2e8bacb..d8c3e67 100644 --- a/examples/example.js +++ b/examples/example.js @@ -1,5 +1,5 @@ -const { OpenSpaceApi } = require('../dist/api.js'); -const { Socket } = require('../dist/socket.js'); +const { OpenSpaceApi } = require('../dist/cjs/api.js'); +const { Socket } = require('../dist/cjs/socket.js'); const password = ''; diff --git a/examples/example.ts b/examples/example.ts index 7acf957..7a636dd 100644 --- a/examples/example.ts +++ b/examples/example.ts @@ -43,8 +43,8 @@ async function main() { for (let i = 0; i < 5; i++) { setTimeout(() => { - addSceneGraphNode(); - }, 2000); + addSceneGraphNode(i); + }, i * 2000); } setTimeout(() => { @@ -103,8 +103,7 @@ async function getScaleUpdates() { await loop(); } -let nodeIndex = 0; -async function addSceneGraphNode() { +async function addSceneGraphNode(nodeIndex: number) { const identifier = `TestNode${nodeIndex}`; const name = `Test Node ${nodeIndex}`; try { @@ -130,7 +129,6 @@ async function addSceneGraphNode() { console.log('Failed to add scene graph node. Error: \n ', e); } - nodeIndex++; console.log(`Added ${name}`); openspace?.setPropertyValue('NavigationHandler.OrbitalNavigator.Anchor', identifier);