1import * as _ from 'lodash-es' 2import { styleText } from 'node:util' 18const warnOrThrowUncommittedChanges = ({pathsA}: {pathsA: string[]}) => { 23 if (uncommittedInCodeTree.length === 0) return 26 assertEmpty(uncommittedInCodeTree, { uncommittedInCodeTree, _maxFrames: 0 }) 28 console.log(styleText('yellow', `WARN: Uncommitted changes in importtree:\n${uncommittedInCodeTree.join('\n')}`)) 32export const epsToAllPaths = async ({epPtPathsA}: {epPtPathsA: string[]}) => { 34 epPtPathsA = _.sortBy(epPtPathsA) 35 madgeDepFilterCtx.enterWith({...madgeDepFilterCtx.getStore(), dependencyFilter: () => true}) 36 const madgeH = await betDurMs(`epsToAllPaths:${epPtPathsA.length}seeds`, () => ptMadge(epPtPathsA) as Promise<Record<string, string[]>>) 37 return _.chain(madgeH).values().flatten().union(epPtPathsA).union(_.keys(madgeH)).uniq().sortBy().value() 40export const getMemoImportTree = async (regEpPath: string) => { 42 const cacheKeyA = [headGitSha, regEpPath, 'memoTree-v1'] 44 const esImportPaths = await epsToAllPaths({epPtPathsA: [regEpPath]}) 46 const serverVirtualPaths = virtualPaths.filter(p => 47 p.includes('/api/') || p.endsWith('runnext.mjs') || p.endsWith('next.config.mjs') 49 const serverVirtualEsImports = serverVirtualPaths.length ? await epsToAllPaths({epPtPathsA: serverVirtualPaths}) : [] 50 return _.uniq([...esImportPaths, ...serverVirtualPaths, ...serverVirtualEsImports]).sort() 54export const getFullEpImportTree = async (regEpPath: string) => { 56 const cacheKeyA = [headGitSha, regEpPath, 'fullTree-v1'] 58 const esImportPaths = await epsToAllPaths({epPtPathsA: [regEpPath]}) 60 const virtualEsImports = virtualPaths.length ? await epsToAllPaths({epPtPathsA: virtualPaths}) : [] 61 return _.uniq([...esImportPaths, ...virtualPaths, ...virtualEsImports]).sort() 65export const epsToAllPathsForDocker = async ({epPtPathsA}: {epPtPathsA: string[]}) => { 67 epPtPathsA = _.sortBy(_.filter(epPtPathsA, dependencyFilter)) 68 madgeDepFilterCtx.enterWith({...madgeDepFilterCtx.getStore(), dependencyFilter}) 69 const madgeH = await ptMadge(epPtPathsA) as Record<string, string[]> 70 const pathsA = _.chain(madgeH).values().flatten().union(epPtPathsA).union(_.keys(madgeH)).uniq().sortBy().value() 71 return {pathsA, madgeH, epPtPathsA} 74export const epsToPathsGitCached = async ({epPtPathsA}: {epPtPathsA: string[]}) => { 76 epPtPathsA = _.sortBy(_.filter(epPtPathsA, dependencyFilter)) 78 const cacheKeyA = [headGitSha, ...epPtPathsA, 'v2'].join() 81 console.log('# computing madge graph..') 83 return await epsToAllPathsForDocker({epPtPathsA}) 84 })) as { pathsA?: string[], madgeH?: Record<string, string[]>, epPtPathsA?: string[] } & string[] 86 const pathsA: string[] = cached.pathsA || cached 87 const madgeH = cached.madgeH 88 const cachedEpPtPathsA = cached.epPtPathsA || epPtPathsA 91 Object.assign(getAppCfg(), {madgeH, madgeEpPtPathsA: cachedEpPtPathsA}) 94 warnOrThrowUncommittedChanges({pathsA}) 96 if (epPtPathsA.length === 1) {