6import * as _ from 'lodash-es' 13const findCopyToDockerDirs = (basePath: string) => { 14 const results: string[] = [] 16 if (!fs.existsSync(absBasePath)) return results 18 const walk = (dir: string) => { 20 const entries = fs.readdirSync(dir, {withFileTypes: true}) 21 for (const entry of entries) { 22 if (!entry.isDirectory()) continue 23 const fullPath = path.join(dir, entry.name) 24 if (entry.name === 'copyToDocker') { 25 results.push(fullPath) 26 } else if (!entry.name.startsWith('.') && entry.name !== 'node_modules') { 36export const getVirtualImportsForDeployScript = async (regEpPath: string) => { 38 const cacheKeyA = [headGitSha, regEpPath, 'virtualImports-v1'] 42 const epTypeRuntimeDirsH: Record<string, string[]> = { 43 eptNextjsApp: ['pages', 'app', 'public', 'server'], 44 eptEnsStaticSite: ['public'], 45 eptEnsGallerySite: ['public'], 47 const dirsToScan = (epType && epTypeRuntimeDirsH[epType]) || [] 48 const virtualImportsA: string[] = [] 50 if (appPath && dirsToScan.length) { 51 for (const subdir of dirsToScan) { 52 const dirPath = [ptDir, appPath, subdir].join('/') 54 if (!fs.existsSync(dirPath)) continue 56 const monorPathsA = _.map(filesA, absPathToPtPath) 57 virtualImportsA.push(...monorPathsA) 58 } catch { /* dir may not exist or be readable */ } 61 if (epType === 'eptNextjsApp') { 62 const serverFilesA = ['runnext.mjs', 'next.config.mjs', 'tsconfig.json'] 63 for (const filename of serverFilesA) { 64 const filePath = [appPath, filename].join('/') 65 const absPath = [ptDir, filePath].join('/') 66 if (fs.existsSync(absPath)) { 67 virtualImportsA.push(filePath) 74 const copyToDockerDirs = findCopyToDockerDirs(appPath) 75 for (const copyDir of copyToDockerDirs) { 77 virtualImportsA.push(...filesA.map(absPathToPtPath)) 81 const importTreePaths = _.uniq([regEpPath, ..._.keys(madgeH), ..._.flatten(_.values(madgeH))]) 82 const dirsInTree = _.uniq(importTreePaths.map(p => path.dirname(p))) 83 for (const dir of dirsInTree) { 85 if (fs.existsSync(copyToDockerPath)) { 87 virtualImportsA.push(...filesA.map(absPathToPtPath)) 92 return virtualImportsA 96export const getDeployScriptsIncludingFile = async (filePath: string) => { 98 const resultA: string[] = [] 99 for (const { regEpPath } of registry) { 100 const virtualImports = await getVirtualImportsForDeployScript(regEpPath) 101 if (virtualImports.includes(filePath)) { 102 resultA.push(regEpPath)