fix: import type + lazy singleton pour dagre et pptxgenjs (Turbopack build)
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 23s
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 23s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,7 +4,16 @@ import { tool } from 'ai'
|
|||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import { toolRegistry } from './registry'
|
import { toolRegistry } from './registry'
|
||||||
import { prisma } from '@/lib/prisma'
|
import { prisma } from '@/lib/prisma'
|
||||||
import dagre from 'dagre'
|
// import type is erased at build time — Turbopack won't try to resolve the module
|
||||||
|
import type dagreType from 'dagre'
|
||||||
|
let _dagre: typeof dagreType | null = null
|
||||||
|
async function getDagre(): Promise<typeof dagreType> {
|
||||||
|
if (!_dagre) {
|
||||||
|
const mod = await import('dagre')
|
||||||
|
_dagre = (mod.default ?? mod) as typeof dagreType
|
||||||
|
}
|
||||||
|
return _dagre
|
||||||
|
}
|
||||||
|
|
||||||
interface SimplifiedNode {
|
interface SimplifiedNode {
|
||||||
id: string
|
id: string
|
||||||
@@ -504,12 +513,13 @@ function getNodeRenderSpec(node: SimplifiedNode, isCenter: boolean): NodeRenderS
|
|||||||
return { text: wrapped, fontSize, width, height }
|
return { text: wrapped, fontSize, width, height }
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeNodeLayoutForRankdir(
|
async function computeNodeLayoutForRankdir(
|
||||||
nodes: SimplifiedNode[],
|
nodes: SimplifiedNode[],
|
||||||
edges: SimplifiedEdge[],
|
edges: SimplifiedEdge[],
|
||||||
rankdir: 'LR' | 'TB',
|
rankdir: 'LR' | 'TB',
|
||||||
renderSpecs: Map<string, NodeRenderSpec>,
|
renderSpecs: Map<string, NodeRenderSpec>,
|
||||||
): Map<string, NodeLayoutBox> {
|
): Promise<Map<string, NodeLayoutBox>> {
|
||||||
|
const dagre = await getDagre()
|
||||||
const graph = new dagre.graphlib.Graph()
|
const graph = new dagre.graphlib.Graph()
|
||||||
graph.setGraph({
|
graph.setGraph({
|
||||||
rankdir,
|
rankdir,
|
||||||
@@ -738,11 +748,11 @@ async function computeNodeLayout(
|
|||||||
const firstRankdir: 'LR' | 'TB' = (diagramType === 'org-chart') ? 'TB' : 'LR'
|
const firstRankdir: 'LR' | 'TB' = (diagramType === 'org-chart') ? 'TB' : 'LR'
|
||||||
const secondRankdir: 'LR' | 'TB' = firstRankdir === 'LR' ? 'TB' : 'LR'
|
const secondRankdir: 'LR' | 'TB' = firstRankdir === 'LR' ? 'TB' : 'LR'
|
||||||
|
|
||||||
const lrLayout = computeNodeLayoutForRankdir(nodes, edges, firstRankdir, renderSpecs)
|
const lrLayout = await computeNodeLayoutForRankdir(nodes, edges, firstRankdir, renderSpecs)
|
||||||
const lrQuality = computeLayoutQuality(nodes, edges, lrLayout)
|
const lrQuality = computeLayoutQuality(nodes, edges, lrLayout)
|
||||||
const lrBounds = getLayoutBounds(lrLayout)
|
const lrBounds = getLayoutBounds(lrLayout)
|
||||||
|
|
||||||
const tbLayout = computeNodeLayoutForRankdir(nodes, edges, secondRankdir, renderSpecs)
|
const tbLayout = await computeNodeLayoutForRankdir(nodes, edges, secondRankdir, renderSpecs)
|
||||||
const tbQuality = computeLayoutQuality(nodes, edges, tbLayout)
|
const tbQuality = computeLayoutQuality(nodes, edges, tbLayout)
|
||||||
const tbBounds = getLayoutBounds(tbLayout)
|
const tbBounds = getLayoutBounds(tbLayout)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
'use server'
|
'use server'
|
||||||
|
|
||||||
import PptxGenJS from 'pptxgenjs'
|
// import type is erased at build time — Turbopack won't try to resolve the module
|
||||||
|
import type PptxGenJSModule from 'pptxgenjs'
|
||||||
|
// Lazy singleton — actual module loaded at runtime only
|
||||||
|
let _PptxGenJS: (new () => PptxGenJSModule) | null = null
|
||||||
|
async function getPptxGenClass(): Promise<new () => PptxGenJSModule> {
|
||||||
|
if (!_PptxGenJS) {
|
||||||
|
const mod = await import('pptxgenjs')
|
||||||
|
_PptxGenJS = (mod.default ?? mod) as unknown as new () => PptxGenJSModule
|
||||||
|
}
|
||||||
|
return _PptxGenJS
|
||||||
|
}
|
||||||
import { tool } from 'ai'
|
import { tool } from 'ai'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import { toolRegistry } from './registry'
|
import { toolRegistry } from './registry'
|
||||||
@@ -960,10 +970,11 @@ function addClosingSlide(pres: PptxGenJS, spec: PresentationSpec, t: Theme, styl
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildPresentation(spec: PresentationSpec): PptxGenJS {
|
async function buildPresentation(spec: PresentationSpec): Promise<PptxGenJSModule> {
|
||||||
const { theme } = resolveTheme(spec)
|
const { theme } = resolveTheme(spec)
|
||||||
const style = STYLES[spec.style || 'soft'] || STYLES.soft!
|
const style = STYLES[spec.style || 'soft'] || STYLES.soft!
|
||||||
|
|
||||||
|
const PptxGenJS = await getPptxGenClass()
|
||||||
const pres = new PptxGenJS()
|
const pres = new PptxGenJS()
|
||||||
pres.title = spec.title
|
pres.title = spec.title
|
||||||
pres.author = 'Momento'
|
pres.author = 'Momento'
|
||||||
@@ -1131,7 +1142,7 @@ RULES:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const pptx = buildPresentation(spec)
|
const pptx = await buildPresentation(spec)
|
||||||
const base64 = await pptx.write({ outputType: 'base64' }) as string
|
const base64 = await pptx.write({ outputType: 'base64' }) as string
|
||||||
|
|
||||||
const canvas = await prisma.canvas.create({
|
const canvas = await prisma.canvas.create({
|
||||||
|
|||||||
Reference in New Issue
Block a user