From 16a3815d55fb9e5542c550c1da70d4a616ff5c66 Mon Sep 17 00:00:00 2001 From: Anthony Powell Date: Thu, 12 Dec 2024 11:16:44 -0500 Subject: [PATCH] feat(js): Fix ESM builds (#1163) Co-authored-by: Mikyo King --- js/.changeset/smart-donuts-attack.md | 15 ++++ js/package.json | 1 + js/packages/openinference-core/package.json | 13 +++- js/packages/openinference-core/src/index.ts | 1 + .../package.json | 11 ++- .../package.json | 11 ++- .../package.json | 9 ++- js/packages/openinference-vercel/package.json | 9 ++- js/pnpm-lock.yaml | 74 +++++++++++++++++++ js/tsconfig.base.esm.json | 11 ++- 10 files changed, 143 insertions(+), 12 deletions(-) create mode 100644 js/.changeset/smart-donuts-attack.md diff --git a/js/.changeset/smart-donuts-attack.md b/js/.changeset/smart-donuts-attack.md new file mode 100644 index 000000000..78c6dd70d --- /dev/null +++ b/js/.changeset/smart-donuts-attack.md @@ -0,0 +1,15 @@ +--- +"@arizeai/openinference-instrumentation-langchain": major +"@arizeai/openinference-instrumentation-openai": major +"@arizeai/openinference-semantic-conventions": major +"@arizeai/openinference-vercel": major +"@arizeai/openinference-core": major +--- + +ESM support + +Packages are now shipped as "Dual Package" meaning that ESM and CJS module resolution +should be supported for each package. + +Support is described as "experimental" because opentelemetry describes support for autoinstrumenting +ESM projects as "ongoing". See https://github.com/open-telemetry/opentelemetry-js/blob/61d5a0e291db26c2af638274947081b29db3f0ca/doc/esm-support.md diff --git a/js/package.json b/js/package.json index e690c1d80..02bfc6f2c 100644 --- a/js/package.json +++ b/js/package.json @@ -31,6 +31,7 @@ "prettier": "^3.3.3", "rimraf": "^5.0.9", "ts-jest": "^29.2.2", + "tsc-alias": "^1.8.10", "typescript": "^5.5.4" }, "engines": { diff --git a/js/packages/openinference-core/package.json b/js/packages/openinference-core/package.json index 33d762c73..9ea126fd8 100644 --- a/js/packages/openinference-core/package.json +++ b/js/packages/openinference-core/package.json @@ -9,10 +9,17 @@ "description": "OpenInference Core provides utilities shared by all OpenInference SDK packages.", "scripts": { "prebuild": "rimraf dist", - "build": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", + "build": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json && tsc-alias -p tsconfig.esm.json", + "postbuild": "echo '{\"type\": \"module\"}' > ./dist/esm/package.json; rimraf dist/test", "type:check": "tsc --noEmit", "test": "jest" }, + "exports": { + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/src/index.js" + } + }, "files": [ "dist", "src" @@ -34,8 +41,8 @@ }, "dependencies": { "@arizeai/openinference-semantic-conventions": "workspace:*", - "@opentelemetry/core": "^1.25.1", - "@opentelemetry/api": "^1.9.0" + "@opentelemetry/api": "^1.9.0", + "@opentelemetry/core": "^1.25.1" }, "devDependencies": { "@opentelemetry/context-async-hooks": "^1.25.1", diff --git a/js/packages/openinference-core/src/index.ts b/js/packages/openinference-core/src/index.ts index 54b635613..df3026d2d 100644 --- a/js/packages/openinference-core/src/index.ts +++ b/js/packages/openinference-core/src/index.ts @@ -1,2 +1,3 @@ export * from "./trace"; export * from "./utils"; +export type * from "./utils/types"; diff --git a/js/packages/openinference-instrumentation-langchain/package.json b/js/packages/openinference-instrumentation-langchain/package.json index 9c26f4034..7ac39bdf9 100644 --- a/js/packages/openinference-instrumentation-langchain/package.json +++ b/js/packages/openinference-instrumentation-langchain/package.json @@ -12,12 +12,19 @@ "url": "https://github.com/Arize-ai/openinference.git" }, "scripts": { - "prebuild": "rimraf dist & pnpm run version:update", - "build": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", + "prebuild": "rimraf dist && pnpm run version:update", + "build": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json && tsc-alias -p tsconfig.esm.json", + "postbuild": "echo '{\"type\": \"module\"}' > ./dist/esm/package.json && rimraf dist/test", "version:update": "../../scripts/version-update.js", "type:check": "tsc --noEmit", "test": "jest" }, + "exports": { + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/src/index.js" + } + }, "keywords": [], "files": [ "dist", diff --git a/js/packages/openinference-instrumentation-openai/package.json b/js/packages/openinference-instrumentation-openai/package.json index a3f29c917..41f23b6e8 100644 --- a/js/packages/openinference-instrumentation-openai/package.json +++ b/js/packages/openinference-instrumentation-openai/package.json @@ -12,12 +12,19 @@ "url": "https://github.com/Arize-ai/openinference.git" }, "scripts": { - "prebuild": "rimraf dist & pnpm run version:update", - "build": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", + "prebuild": "rimraf dist && pnpm run version:update", + "build": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json && tsc-alias -p tsconfig.esm.json", + "postbuild": "echo '{\"type\": \"module\"}' > ./dist/esm/package.json && rimraf dist/test", "version:update": "../../scripts/version-update.js", "type:check": "tsc --noEmit", "test": "jest ." }, + "exports": { + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/src/index.js" + } + }, "dependencies": { "@arizeai/openinference-core": "workspace:*", "@arizeai/openinference-semantic-conventions": "workspace:*", diff --git a/js/packages/openinference-semantic-conventions/package.json b/js/packages/openinference-semantic-conventions/package.json index 9da1a6dba..18ad5328e 100644 --- a/js/packages/openinference-semantic-conventions/package.json +++ b/js/packages/openinference-semantic-conventions/package.json @@ -9,10 +9,17 @@ "description": "This package provides OpenInference semantic conventions for tracing of LLM Applications.", "scripts": { "prebuild": "rimraf dist", - "build": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", + "build": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json && tsc-alias -p tsconfig.esm.json", + "postbuild": "echo '{\"type\": \"module\"}' > ./dist/esm/package.json && rimraf dist/test", "type:check": "tsc --noEmit", "test": "echo \"NOOP: semantic conventions has no tests\" && exit 0" }, + "exports": { + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/src/index.js" + } + }, "files": [ "dist", "src" diff --git a/js/packages/openinference-vercel/package.json b/js/packages/openinference-vercel/package.json index 84c13c63a..c2f65a3a7 100644 --- a/js/packages/openinference-vercel/package.json +++ b/js/packages/openinference-vercel/package.json @@ -9,10 +9,17 @@ "description": "OpenInference utilities for ingesting Vercel AI SDK spans", "scripts": { "prebuild": "rimraf dist", - "build": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", + "build": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json && tsc-alias -p tsconfig.esm.json", + "postbuild": "echo '{\"type\": \"module\"}' > ./dist/esm/package.json && rimraf dist/test", "type:check": "tsc --noEmit", "test": "jest" }, + "exports": { + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/src/index.js" + } + }, "files": [ "dist", "src" diff --git a/js/pnpm-lock.yaml b/js/pnpm-lock.yaml index 7e922b99f..a59651be9 100644 --- a/js/pnpm-lock.yaml +++ b/js/pnpm-lock.yaml @@ -39,6 +39,9 @@ importers: ts-jest: specifier: ^29.2.2 version: 29.2.4(@babel/core@7.24.9)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.24.9))(jest@29.7.0)(typescript@5.5.4) + tsc-alias: + specifier: ^1.8.10 + version: 1.8.10 typescript: specifier: ^5.5.4 version: 5.5.4 @@ -1404,6 +1407,10 @@ packages: charenc@0.0.2: resolution: {integrity: sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==} + chokidar@3.6.0: + resolution: {integrity: sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==} + engines: {node: '>= 8.10.0'} + ci-info@3.9.0: resolution: {integrity: sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==} engines: {node: '>=8'} @@ -1443,6 +1450,10 @@ packages: resolution: {integrity: sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==} engines: {node: '>=14'} + commander@9.5.0: + resolution: {integrity: sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==} + engines: {node: ^12.20.0 || >=14} + concat-map@0.0.1: resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} @@ -1832,6 +1843,10 @@ packages: is-arrayish@0.2.1: resolution: {integrity: sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==} + is-binary-path@2.1.0: + resolution: {integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==} + engines: {node: '>=8'} + is-buffer@1.1.6: resolution: {integrity: sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==} @@ -2636,6 +2651,10 @@ packages: resolution: {integrity: sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==} hasBin: true + mylas@2.1.13: + resolution: {integrity: sha512-+MrqnJRtxdF+xngFfUUkIMQrUUL0KsxbADUkn23Z/4ibGg192Q+z+CQyiYwvWTsYjJygmMR8+w3ZDa98Zh6ESg==} + engines: {node: '>=12.0.0'} + natural-compare@1.4.0: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} @@ -2806,6 +2825,10 @@ packages: resolution: {integrity: sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==} engines: {node: '>=8'} + plimit-lit@1.6.1: + resolution: {integrity: sha512-B7+VDyb8Tl6oMJT9oSO2CW8XC/T4UcJGrwOVoNGwOQsQYhlpfajmrMj5xeejqaASq3V/EqThyOeATEOMuSEXiA==} + engines: {node: '>=12'} + preferred-pm@3.1.4: resolution: {integrity: sha512-lEHd+yEm22jXdCphDrkvIJQU66EuLojPPtvZkpKIkiD+l0DMThF/niqZKJSoU8Vl7iuvtmzyMhir9LdVy5WMnA==} engines: {node: '>=10'} @@ -2846,6 +2869,10 @@ packages: pure-rand@6.1.0: resolution: {integrity: sha512-bVWawvoZoBYpp6yIoQtQXHZjmz35RSVHnUOTefl8Vcjr8snTPY1wnpSPMWekcFwbxI6gtmT7rSYPFvz71ldiOA==} + queue-lit@1.5.2: + resolution: {integrity: sha512-tLc36IOPeMAubu8BkW8YDBV+WyIgKlYU7zUNs0J5Vk9skSZ4JfGlPOqplP0aHdfv7HL0B2Pg6nwiq60Qc6M2Hw==} + engines: {node: '>=12'} + queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} @@ -2856,6 +2883,10 @@ packages: resolution: {integrity: sha512-VIMnQi/Z4HT2Fxuwg5KrY174U1VdUIASQVWXXyqtNRtxSr9IYkn1rsI6Tb6HsrHCmB7gVpNwX6JxPTHcH6IoTA==} engines: {node: '>=6'} + readdirp@3.6.0: + resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} + engines: {node: '>=8.10.0'} + regenerator-runtime@0.14.1: resolution: {integrity: sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==} @@ -3080,6 +3111,10 @@ packages: esbuild: optional: true + tsc-alias@1.8.10: + resolution: {integrity: sha512-Ibv4KAWfFkFdKJxnWfVtdOmB0Zi1RJVxcbPGiCDsFpCQSsmpWyuzHG3rQyI5YkobWwxFPEyQfu1hdo4qLG2zPw==} + hasBin: true + type-check@0.4.0: resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==} engines: {node: '>= 0.8.0'} @@ -4527,6 +4562,18 @@ snapshots: charenc@0.0.2: {} + chokidar@3.6.0: + dependencies: + anymatch: 3.1.3 + braces: 3.0.3 + glob-parent: 5.1.2 + is-binary-path: 2.1.0 + is-glob: 4.0.3 + normalize-path: 3.0.0 + readdirp: 3.6.0 + optionalDependencies: + fsevents: 2.3.3 + ci-info@3.9.0: {} cjs-module-lexer@1.3.1: {} @@ -4559,6 +4606,8 @@ snapshots: commander@10.0.1: {} + commander@9.5.0: {} + concat-map@0.0.1: {} convert-source-map@2.0.0: {} @@ -4967,6 +5016,10 @@ snapshots: is-arrayish@0.2.1: {} + is-binary-path@2.1.0: + dependencies: + binary-extensions: 2.3.0 + is-buffer@1.1.6: {} is-core-module@2.15.0: @@ -5709,6 +5762,8 @@ snapshots: mustache@4.2.0: {} + mylas@2.1.13: {} + natural-compare@1.4.0: {} node-domexception@1.0.0: {} @@ -5860,6 +5915,10 @@ snapshots: dependencies: find-up: 4.1.0 + plimit-lit@1.6.1: + dependencies: + queue-lit: 1.5.2 + preferred-pm@3.1.4: dependencies: find-up: 5.0.0 @@ -5905,6 +5964,8 @@ snapshots: pure-rand@6.1.0: {} + queue-lit@1.5.2: {} + queue-microtask@1.2.3: {} react-is@18.3.1: {} @@ -5916,6 +5977,10 @@ snapshots: pify: 4.0.1 strip-bom: 3.0.0 + readdirp@3.6.0: + dependencies: + picomatch: 2.3.1 + regenerator-runtime@0.14.1: {} require-directory@2.1.1: {} @@ -6100,6 +6165,15 @@ snapshots: '@jest/types': 29.6.3 babel-jest: 29.7.0(@babel/core@7.24.9) + tsc-alias@1.8.10: + dependencies: + chokidar: 3.6.0 + commander: 9.5.0 + globby: 11.1.0 + mylas: 2.1.13 + normalize-path: 3.0.0 + plimit-lit: 1.6.1 + type-check@0.4.0: dependencies: prelude-ls: 1.2.1 diff --git a/js/tsconfig.base.esm.json b/js/tsconfig.base.esm.json index d63786958..5b21f356a 100644 --- a/js/tsconfig.base.esm.json +++ b/js/tsconfig.base.esm.json @@ -1,7 +1,12 @@ { - "extends": "./tsconfig.base.es5.json", + "extends": "./tsconfig.base.esnext.json", "compilerOptions": { - "module": "ES6", - "moduleResolution": "node" + "target": "ES2020", + "moduleResolution": "node10", + "module": "ES2020" + }, + "tsc-alias": { + "verbose": false, + "resolveFullPaths": true } }