🌳
pt0/deployF/dockerF/dfFromMadgeF.mts
1import * as _ from 'lodash-es'
2import { styleText } from 'node:util'
18const warnOrThrowUncommittedChanges = ({pathsA}: {pathsA: string[]}) => {
19 const action = getAction()
20 if (!action) return
22 const uncommittedInCodeTree = getUncommittedInPathSet(pathsA)
23 if (uncommittedInCodeTree.length === 0) return
25 if (isDeployAction(action)) {
26 assertEmpty(uncommittedInCodeTree, { uncommittedInCodeTree, _maxFrames: 0 })
27 } else {
28 console.log(styleText('yellow', `WARN: Uncommitted changes in importtree:\n${uncommittedInCodeTree.join('\n')}`))
29 }
32export const epsToAllPaths = async ({epPtPathsA}: {epPtPathsA: string[]}) => {
33 assertDefined(epPtPathsA)
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) => {
41 const headGitSha = await getHeadGitSha()
42 const cacheKeyA = [headGitSha, regEpPath, 'memoTree-v1']
43 return await runMemoTempfile({cacheKeyA}, async () => {
44 const esImportPaths = await epsToAllPaths({epPtPathsA: [regEpPath]})
45 const virtualPaths = await getVirtualImportsForDeployScript(regEpPath) as string[]
46 const serverVirtualPaths = virtualPaths.filter(p =>
47 p.includes('/api/') || p.endsWith('runnext.mjs') || p.endsWith('next.config.mjs')
48 )
49 const serverVirtualEsImports = serverVirtualPaths.length ? await epsToAllPaths({epPtPathsA: serverVirtualPaths}) : []
50 return _.uniq([...esImportPaths, ...serverVirtualPaths, ...serverVirtualEsImports]).sort()
51 })
54export const getFullEpImportTree = async (regEpPath: string) => {
55 const headGitSha = await getHeadGitSha()
56 const cacheKeyA = [headGitSha, regEpPath, 'fullTree-v1']
57 return await runMemoTempfile({cacheKeyA}, async () => betDurMs('getFullEpImportTree:calc', async () => {
58 const esImportPaths = await epsToAllPaths({epPtPathsA: [regEpPath]})
59 const virtualPaths = await getVirtualImportsForDeployScript(regEpPath) as string[]
60 const virtualEsImports = virtualPaths.length ? await epsToAllPaths({epPtPathsA: virtualPaths}) : []
61 return _.uniq([...esImportPaths, ...virtualPaths, ...virtualEsImports]).sort()
62 }))
65export const epsToAllPathsForDocker = async ({epPtPathsA}: {epPtPathsA: string[]}) => {
66 assertDefined(epPtPathsA)
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[]}) => {
75 const headGitSha = await getHeadGitSha()
76 epPtPathsA = _.sortBy(_.filter(epPtPathsA, dependencyFilter))
78 const cacheKeyA = [headGitSha, ...epPtPathsA, 'v2'].join()
79 const cached = await runMemoTempfile({cacheKeyA}, async () => betDurMs('epsToPathsGitCached:calc', async () => {
80 if (isVeryVerbose) {
81 console.log('# computing madge graph..')
82 }
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
90 if (madgeH) {
91 Object.assign(getAppCfg(), {madgeH, madgeEpPtPathsA: cachedEpPtPathsA})
92 }
94 warnOrThrowUncommittedChanges({pathsA})
96 if (epPtPathsA.length === 1) {
97 const action = getAction()
98 if (isDeployAction(action)) await warnOrThrowStaleHostnames({regEpPath: epPtPathsA[0], action})
99 }
101 return pathsA