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 { toolRegistry } from './registry'
|
||||
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 {
|
||||
id: string
|
||||
@@ -504,12 +513,13 @@ function getNodeRenderSpec(node: SimplifiedNode, isCenter: boolean): NodeRenderS
|
||||
return { text: wrapped, fontSize, width, height }
|
||||
}
|
||||
|
||||
function computeNodeLayoutForRankdir(
|
||||
async function computeNodeLayoutForRankdir(
|
||||
nodes: SimplifiedNode[],
|
||||
edges: SimplifiedEdge[],
|
||||
rankdir: 'LR' | 'TB',
|
||||
renderSpecs: Map<string, NodeRenderSpec>,
|
||||
): Map<string, NodeLayoutBox> {
|
||||
): Promise<Map<string, NodeLayoutBox>> {
|
||||
const dagre = await getDagre()
|
||||
const graph = new dagre.graphlib.Graph()
|
||||
graph.setGraph({
|
||||
rankdir,
|
||||
@@ -738,11 +748,11 @@ async function computeNodeLayout(
|
||||
const firstRankdir: 'LR' | 'TB' = (diagramType === 'org-chart') ? '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 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 tbBounds = getLayoutBounds(tbLayout)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user