Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(js/openinference-core): Port build process to vite, advertise esm builds #1150

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions js/packages/openinference-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
"version": "0.3.2",
"private": false,
"main": "dist/src/index.js",
"module": "dist/esm/index.js",
"module": "dist/esm/index.mjs",
"esnext": "dist/esnext/index.js",
"types": "dist/src/index.d.ts",
"types": "./dist/src/index.d.ts",
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"import": "./dist/esm/index.mjs",
"require": "./dist/src/index.js",
"default": "./dist/src/index.js"
}
},
"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": "vite build && tsc --emitDeclarationOnly --outDir dist && rimraf dist/test dist/tsconfig.tsbuildinfo",
"type:check": "tsc --noEmit",
"test": "jest"
},
Expand All @@ -34,8 +42,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",
Expand All @@ -45,6 +53,8 @@
"@opentelemetry/semantic-conventions": "^1.19.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.11",
"jest": "^29.7.0"
"glob": "^11.0.0",
"jest": "^29.7.0",
"vite": "^6.0.2"
}
}
2 changes: 1 addition & 1 deletion js/packages/openinference-core/src/trace/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./contextAttributes";
export * from "./types";
export type * from "./types";
export * from "./trace-config";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { TraceConfigOptions } from "./types";
export type { TraceConfigOptions } from "./types";
export {
OPENINFERENCE_BASE64_IMAGE_MAX_LENGTH,
OPENINFERENCE_HIDE_EMBEDDING_VECTORS,
Expand Down
49 changes: 49 additions & 0 deletions js/packages/openinference-core/vite.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import path, { resolve } from "path";
import { defineConfig } from "vite";
import { globSync } from "glob";
import { fileURLToPath } from "url";

export default defineConfig({
build: {
lib: {
// Map every source file as an entry point so that they are not bundled, each file becomes its
// own chunk essentially.
// see https://rollupjs.org/configuration-options/#input
entry: Object.fromEntries(
globSync("src/**/*.ts").map((file) => [
// This remove `src/` as well as the file extension from each
// file, so e.g. src/nested/foo.js becomes nested/foo
path.relative(
"src",
file.slice(0, file.length - path.extname(file).length),
),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.js
fileURLToPath(new URL(file, import.meta.url)),
]),
),
formats: ["es", "cjs"],
},
minify: false,
rollupOptions: {
output: [
{
format: "es",
dir: resolve(__dirname, "dist", "esm"),
},
{
format: "esm",
dir: resolve(__dirname, "dist", "esnext"),
entryFileNames: "[name].js",
},
{
format: "cjs",
dir: resolve(__dirname, "dist", "src"),
},
],
// make sure to externalize deps that shouldn't be bundled
// into your library
external: ["@opentelemetry/api", "@opentelemetry/core"],
Comment on lines +44 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, can this be done via peerDeps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not automatically, no. From what I understand the best we could do is to import package.json and walk the peerDependencies deps, adding them to this config.

vitejs/vite#6780

},
},
});
Loading
Loading