1import * as _ from 'lodash-es' 9const isBuildArtifact = (path: string) => { 11 if (prebuildEnvConfH?.builtWorkerFilename && path.endsWith(`/${prebuildEnvConfH.builtWorkerFilename}`)) return true 12 if (prebuildEnvConfH?.builtSwFilename && path.endsWith(`/${prebuildEnvConfH.builtSwFilename}`)) return true 16const isServerOnlyPath = (path: string) => { 17 if (_.includes(path, '/pages/api/')) return true 18 if (_.endsWith(path, '/route.js') || _.endsWith(path, '/route.ts')) return true 19 if (_.endsWith(path, '/runnext.mjs')) return true 20 if (_.endsWith(path, '/next.config.mjs')) return true 24export const isNextJsRoutePath = (p: string): boolean => 25 p.includes('/pages/') || p.includes('/app/') 27const routeHandlerExtA = ptNextPageExtA 28export const isNextRouteHandlerFile = (p: string): boolean => { 29 if (!p.includes('/app/')) return false 30 for (const ext of routeHandlerExtA) { 31 if (p.endsWith('/route.' + ext)) return true 36export const nextAppPaths = async ({inclClient=true, inclServer, feOnly=false}: {inclClient?: boolean, inclServer?: boolean, feOnly?: boolean}={}) => { 38 let {inclPtPathA=[], appPath, inclServer: ctxInclServer=true} = ctx 39 if (!appPath) return inclPtPathA 40 inclServer = inclServer ?? ctxInclServer 42 // feOnly: frontend-only mode - include pages/app/public but exclude server-only paths 44 const pagesPathsA = _.map(await lsFilePathsRec([ptDir, appPath, 'pages'].join('/')), absPathToPtPath) 45 const appPathsA = _.map(await lsFilePathsRec([ptDir, appPath, 'app'].join('/')), absPathToPtPath) 46 const publicPathsA = _.reject(_.map(await lsFilePathsRec([ptDir, appPath, 'public'].join('/')), absPathToPtPath), isBuildArtifact) 49 ..._.reject([...pagesPathsA, ...appPathsA], isServerOnlyPath), 55 // Legacy behavior for inclServer/inclClient 69 ..._.reject(_.map(await lsFilePathsRec([ptDir, appPath, 'public'].join('/')), absPathToPtPath), isBuildArtifact) 72 inclPtPathA = _.reject(inclPtPathA, path => _.includes(path, '/pages/') && !_.includes(path, '/api/')) 75 const serverAddA = ['runnext.mjs', 'next.config.mjs'] 77 _.each(serverAddA, (filename) => { 78 const ptPath = [appPath, filename].join('/') 79 if (fs.existsSync([ptDir, ptPath].join('/'))) { 80 inclPtPathA.push(ptPath) 84 inclPtPathA = _.reject(inclPtPathA, (path: string) => _.includes(path, '/api/') || _.find(serverAddA, file => _.endsWith(path, `/${file}`))) as string[]