diff --git a/apps/web/next.config.ts b/apps/web/next.config.ts index e53a5c2f..c4992e71 100644 --- a/apps/web/next.config.ts +++ b/apps/web/next.config.ts @@ -6,6 +6,7 @@ const nextConfig: NextConfig = { ignoreBuildErrors: true, }, transpilePackages: [ + "@supermemory/memory-graph", "@tiptap/core", "@tiptap/react", "@tiptap/pm", diff --git a/packages/memory-graph/package.json b/packages/memory-graph/package.json index fcf06d91..c4a5dd96 100644 --- a/packages/memory-graph/package.json +++ b/packages/memory-graph/package.json @@ -3,26 +3,12 @@ "version": "0.2.0", "description": "Interactive graph visualization component for Supermemory - visualize and explore your memory connections", "type": "module", - "main": "./dist/memory-graph.cjs", - "module": "./dist/memory-graph.js", - "types": "./dist/index.d.ts", + "main": "./src/index.tsx", + "module": "./src/index.tsx", + "types": "./src/index.tsx", "exports": { - ".": { - "import": { - "types": "./dist/index.d.ts", - "default": "./dist/memory-graph.js" - }, - "require": { - "types": "./dist/index.d.ts", - "default": "./dist/memory-graph.cjs" - } - }, - "./mock-data": { - "import": { - "types": "./dist/mock-data.d.ts", - "default": "./dist/mock-data.js" - } - }, + ".": "./src/index.tsx", + "./mock-data": "./src/mock-data.ts", "./package.json": "./package.json" }, "files": [ @@ -33,7 +19,8 @@ "dev": "vite build --watch", "build": "vite build && tsc --emitDeclarationOnly", "check-types": "tsc --noEmit", - "prepublishOnly": "bun run build", + "prepublishOnly": "bun run build && bun run scripts/swap-exports.ts pack", + "postpublish": "bun run scripts/swap-exports.ts unpack", "test": "vitest run" }, "keywords": [ @@ -73,4 +60,4 @@ "vite": "^7.2.1", "vitest": "^3.2.4" } -} \ No newline at end of file +} diff --git a/packages/memory-graph/scripts/swap-exports.ts b/packages/memory-graph/scripts/swap-exports.ts new file mode 100644 index 00000000..1049ca43 --- /dev/null +++ b/packages/memory-graph/scripts/swap-exports.ts @@ -0,0 +1,50 @@ +/** + * Swaps package.json exports between source (for workspace/monorepo use) + * and dist (for npm publishing). + * + * Usage: + * bun run scripts/swap-exports.ts pack # switch to dist exports + * bun run scripts/swap-exports.ts unpack # switch back to source exports + */ +import { readFileSync, writeFileSync } from "node:fs" +import { join } from "node:path" + +const pkgPath = join(import.meta.dirname, "..", "package.json") +const pkg = JSON.parse(readFileSync(pkgPath, "utf-8")) + +const mode = process.argv[2] + +if (mode === "pack") { + // Switch to dist exports for npm publishing + pkg.main = "./dist/memory-graph.cjs" + pkg.module = "./dist/memory-graph.js" + pkg.types = "./dist/index.d.ts" + pkg.exports = { + ".": { + types: "./dist/index.d.ts", + import: "./dist/memory-graph.js", + require: "./dist/memory-graph.cjs", + }, + "./mock-data": { + types: "./dist/mock-data.d.ts", + import: "./dist/mock-data.js", + }, + "./package.json": "./package.json", + } +} else if (mode === "unpack") { + // Switch back to source exports for workspace use + pkg.main = "./src/index.tsx" + pkg.module = "./src/index.tsx" + pkg.types = "./src/index.tsx" + pkg.exports = { + ".": "./src/index.tsx", + "./mock-data": "./src/mock-data.ts", + "./package.json": "./package.json", + } +} else { + console.error("Usage: bun run scripts/swap-exports.ts [pack|unpack]") + process.exit(1) +} + +writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`) +console.log(`Exports swapped to ${mode === "pack" ? "dist" : "source"} mode`)