mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-07 08:26:15 +00:00
Fix Cloudflare Workers build: use source exports for workspace, dist for npm publish
- Package exports now point to source files (./src/index.tsx) for workspace consumers, allowing Next.js/Turbopack to resolve without pre-building - Added publishConfig swap script that switches exports to dist/ during npm publish (prepublishOnly) and back to source after (postpublish) - Added @supermemory/memory-graph to transpilePackages in web app next.config.ts so Next.js transpiles the source files correctly
This commit is contained in:
parent
3eab287959
commit
96b7f16175
3 changed files with 59 additions and 21 deletions
|
|
@ -6,6 +6,7 @@ const nextConfig: NextConfig = {
|
|||
ignoreBuildErrors: true,
|
||||
},
|
||||
transpilePackages: [
|
||||
"@supermemory/memory-graph",
|
||||
"@tiptap/core",
|
||||
"@tiptap/react",
|
||||
"@tiptap/pm",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
50
packages/memory-graph/scripts/swap-exports.ts
Normal file
50
packages/memory-graph/scripts/swap-exports.ts
Normal file
|
|
@ -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`)
|
||||
Loading…
Add table
Reference in a new issue