( dir: string, options: Readonly<ExportAppOptions>, span: Span, staticWorker?: StaticWorker )
| 189 | } |
| 190 | |
| 191 | async function exportAppImpl( |
| 192 | dir: string, |
| 193 | options: Readonly<ExportAppOptions>, |
| 194 | span: Span, |
| 195 | staticWorker?: StaticWorker |
| 196 | ): Promise<ExportAppResult | null> { |
| 197 | dir = resolve(dir) |
| 198 | |
| 199 | // attempt to load global env values so they are available in next.config.js |
| 200 | span.traceChild('load-dotenv').traceFn(() => loadEnvConfig(dir, false, Log)) |
| 201 | |
| 202 | const { enabledDirectories } = options |
| 203 | |
| 204 | const nextConfig = |
| 205 | options.nextConfig || |
| 206 | (await span.traceChild('load-next-config').traceAsyncFn(() => |
| 207 | loadConfig(PHASE_EXPORT, dir, { |
| 208 | debugPrerender: options.debugPrerender, |
| 209 | }) |
| 210 | )) |
| 211 | |
| 212 | const distDir = join(dir, nextConfig.distDir) |
| 213 | const telemetry = options.buildExport ? null : new Telemetry({ distDir }) |
| 214 | |
| 215 | if (telemetry) { |
| 216 | telemetry.record( |
| 217 | eventCliSession(nextConfig, { |
| 218 | webpackVersion: null, |
| 219 | cliCommand: 'export', |
| 220 | isSrcDir: null, |
| 221 | hasNowJson: !!(await findUp('now.json', { cwd: dir })), |
| 222 | isCustomServer: null, |
| 223 | turboFlag: false, |
| 224 | pagesDir: null, |
| 225 | appDir: null, |
| 226 | }) |
| 227 | ) |
| 228 | } |
| 229 | |
| 230 | const subFolders = nextConfig.trailingSlash && !options.buildExport |
| 231 | |
| 232 | if (!options.silent && !options.buildExport) { |
| 233 | Log.info(`using build directory: ${distDir}`) |
| 234 | } |
| 235 | |
| 236 | const buildIdFile = join(distDir, BUILD_ID_FILE) |
| 237 | |
| 238 | if (!existsSync(buildIdFile)) { |
| 239 | throw new ExportError( |
| 240 | `Could not find a production build in the '${distDir}' directory. Try building your app with 'next build' before starting the static export. https://nextjs.org/docs/messages/next-export-no-build-id` |
| 241 | ) |
| 242 | } |
| 243 | |
| 244 | const customRoutes = (['rewrites', 'redirects', 'headers'] as const).filter( |
| 245 | (config) => typeof nextConfig[config] === 'function' |
| 246 | ) |
| 247 | |
| 248 | if (!hasNextSupport && !options.buildExport && customRoutes.length > 0) { |
no test coverage detected