supermemory/packages/memory-graph/scripts/swap-exports.ts
Mahesh Sanikommu 4fdfbe4516
Some checks failed
Publish Memory Graph / publish (push) Has been cancelled
feat(memory-graph): fetchMemoryGraph server helper and endpoint prop (0.3.0) (#1919)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Ishaan Gupta <ishaankone@gmail.com>
2026-11-24 22:27:42 +00:00

58 lines
1.7 KiB
TypeScript

/**
* 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",
},
"./server": {
types: "./dist/server.d.ts",
import: "./dist/server.js",
require: "./dist/server.cjs",
},
"./package.json": "./package.json",
}
pkg.typesVersions = { "*": { server: ["./dist/server.d.ts"] } }
} 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",
"./server": "./src/server.ts",
"./package.json": "./package.json",
}
delete pkg.typesVersions
} 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`)