UNPKG

27.4 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../export/worker.ts"],"names":["envConfig","require","global","__NEXT_DATA__","nextExport","exportPage","parentSpanId","path","pathMap","distDir","outDir","pagesDataDir","renderOpts","buildExport","serverRuntimeConfig","subFolders","serverless","optimizeFonts","optimizeImages","optimizeCss","disableOptimizedLoading","exportPageSpan","traceAsyncFn","results","ampValidations","query","originalQuery","page","filePath","isDynamic","ampPath","renderAmpPath","params","updatedPath","__nextSsgPath","locale","__nextLocale","localePathResult","locales","detectedLocale","pathname","defaultLocale","hasOrigQueryValues","Object","keys","length","queryWithAutoExportWarn","Error","nonLocalizedPath","undefined","headerMocks","headers","getHeader","setHeader","hasHeader","removeHeader","getHeaderNames","req","url","res","statusCode","trailingSlash","endsWith","setConfig","publicRuntimeConfig","runtimeConfig","htmlFilename","sep","pageExt","pathExt","baseDir","htmlFilepath","promises","mkdir","recursive","html","curRenderOpts","renderMethod","renderToHTML","inAmpMode","hybridAmp","renderedDuringBuild","getStaticProps","curUrl","parse","format","Component","mod","getServerSideProps","pageConfig","ampState","ampFirst","amp","hasQuery","Boolean","hybrid","SERVER_PROPS_EXPORT_ERROR","renderReqToHTML","result","fontManifest","isNotFound","components","process","env","__NEXT_OPTIMIZE_FONTS","JSON","stringify","__NEXT_OPTIMIZE_IMAGES","__NEXT_OPTIMIZE_CSS","ssgNotFound","validateAmp","rawAmpHtml","ampPageName","validatorPath","validator","AmpHtmlValidator","getInstance","validateString","errors","filter","e","severity","warnings","push","ampSkipValidation","ampValidatorPath","ampHtmlFilename","ampBaseDir","ampHtmlFilepath","access","_","ampHtml","includes","writeFile","pageData","dataFile","replace","fromBuildExportRevalidate","revalidate","error","console","stack"],"mappings":"gEAAA,gDACA,0BACA,oDACA,sBACA,8FACA,qEACA,qEACA,2EACA,uEACA,4EACA,2CACA,4DAIA,sDAEA,kFACA,yCACA,2C,mFAEA,KAAMA,CAAAA,SAAS,CAAGC,OAAO,CAAC,mCAAD,CAAzB,CAE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CAAN,CACA,KAAMF,cAAS6D,SAAT,CAAmBL,eAAnB,CAAoCG,OAApC,CAA6C,MAA7C,CAAN,CACD,CACF,CAED,GAAKvD,aAAD,CAAuB0D,QAA3B,CAAqC,CACnC,KAAMC,CAAAA,QAAQ,CAAG,eACf5H,YADe,CAEfuD,YAAY,CAACsE,OAAb,CAAqB,SAArB,CAAgC,OAAhC,CAFe,CAAjB,CAKA,KAAMhE,cAASC,KAAT,CAAe,kBAAQ8D,QAAR,CAAf,CAAkC,CAAE7D,SAAS,CAAE,IAAb,CAAlC,CAAN,CACA,KAAMF,cAAS6D,SAAT,CACJE,QADI,CAEJ9B,IAAI,CAACC,SAAL,CAAgB9B,aAAD,CAAuB0D,QAAtC,CAFI,CAGJ,MAHI,CAAN,CAMA,GAAItD,SAAJ,CAAe,CACb,KAAMR,cAAS6D,SAAT,CACJE,QAAQ,CAACC,OAAT,CAAiB,SAAjB,CAA4B,WAA5B,CADI,CAEJ/B,IAAI,CAACC,SAAL,CAAgB9B,aAAD,CAAuB0D,QAAtC,CAFI,CAGJ,MAHI,CAAN,CAKD,CACF,CACD/G,OAAO,CAACkH,yBAAR,CAAqC7D,aAAD,CAAuB8D,UAA3D,CAEA,GAAInH,OAAO,CAACsF,WAAZ,CAAyB,CACvB;AACA,MAAOtF,CAAAA,OAAP,CACD,CACD,KAAMiD,cAAS6D,SAAT,CAAmB9D,YAAnB,CAAiCI,IAAjC,CAAuC,MAAvC,CAAN,CACA,MAAOpD,CAAAA,OAAP,CACD,CAAC,MAAOoH,KAAP,CAAc,CACdC,OAAO,CAACD,KAAR,CACG,uCAAsCpI,IAAK,kEAA5C,CACEoI,KAAK,CAACE,KAFV,EAIA,MAAO,CAAE,GAAGtH,OAAL,CAAcoH,KAAK,CAAE,IAArB,CAAP,CACD,CACF,CAvXM,CAAP,CAwXD","sourcesContent":["import url from 'url'\nimport { extname, join, dirname, sep } from 'path'\nimport { renderToHTML } from '../next-server/server/render'\nimport { promises } from 'fs'\nimport AmpHtmlValidator from 'next/dist/compiled/amphtml-validator'\nimport { loadComponents } from '../next-server/server/load-components'\nimport { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic'\nimport { getRouteMatcher } from '../next-server/lib/router/utils/route-matcher'\nimport { getRouteRegex } from '../next-server/lib/router/utils/route-regex'\nimport { normalizePagePath } from '../next-server/server/normalize-page-path'\nimport { SERVER_PROPS_EXPORT_ERROR } from '../lib/constants'\nimport 'next/dist/next-server/server/node-polyfill-fetch'\nimport { IncomingMessage, ServerResponse } from 'http'\nimport { ComponentType } from 'react'\nimport { GetStaticProps } from '../types'\nimport { requireFontManifest } from '../next-server/server/require'\nimport { FontManifest } from '../next-server/server/font-utils'\nimport { normalizeLocalePath } from '../next-server/lib/i18n/normalize-locale-path'\nimport { trace } from '../telemetry/trace'\nimport { isInAmpMode } from '../next-server/lib/amp'\n\nconst envConfig = require('../next-server/lib/runtime-config')\n\n;(global as any).__NEXT_DATA__ = {\n nextExport: true,\n}\n\ninterface AmpValidation {\n page: string\n result: {\n errors: AmpHtmlValidator.ValidationError[]\n warnings: AmpHtmlValidator.ValidationError[]\n }\n}\n\ninterface PathMap {\n page: string\n query?: { [key: string]: string | string[] }\n}\n\ninterface ExportPageInput {\n path: string\n pathMap: PathMap\n distDir: string\n outDir: string\n pagesDataDir: string\n renderOpts: RenderOpts\n buildExport?: boolean\n serverRuntimeConfig: string\n subFolders?: boolean\n serverless: boolean\n optimizeFonts: boolean\n optimizeImages?: boolean\n optimizeCss: any\n disableOptimizedLoading: any\n parentSpanId: any\n}\n\ninterface ExportPageResults {\n ampValidations: AmpValidation[]\n fromBuildExportRevalidate?: number\n error?: boolean\n ssgNotFound?: boolean\n}\n\ninterface RenderOpts {\n runtimeConfig?: { [key: string]: any }\n params?: { [key: string]: string | string[] }\n ampPath?: string\n ampValidatorPath?: string\n ampSkipValidation?: boolean\n optimizeFonts?: boolean\n optimizeImages?: boolean\n disableOptimizedLoading?: boolean\n optimizeCss?: any\n fontManifest?: FontManifest\n locales?: string[]\n locale?: string\n defaultLocale?: string\n trailingSlash?: boolean\n}\n\ntype ComponentModule = ComponentType<{}> & {\n renderReqToHTML: typeof renderToHTML\n getStaticProps?: GetStaticProps\n}\n\nexport default async function exportPage({\n parentSpanId,\n path,\n pathMap,\n distDir,\n outDir,\n pagesDataDir,\n renderOpts,\n buildExport,\n serverRuntimeConfig,\n subFolders,\n serverless,\n optimizeFonts,\n optimizeImages,\n optimizeCss,\n disableOptimizedLoading,\n}: ExportPageInput): Promise<ExportPageResults> {\n const exportPageSpan = trace('export-page-worker', parentSpanId)\n\n return exportPageSpan.traceAsyncFn(async () => {\n let results: ExportPageResults = {\n ampValidations: [],\n }\n\n try {\n const { query: originalQuery = {} } = pathMap\n const { page } = pathMap\n const filePath = normalizePagePath(path)\n const isDynamic = isDynamicRoute(page)\n const ampPath = `${filePath}.amp`\n let renderAmpPath = ampPath\n let query = { ...originalQuery }\n let params: { [key: string]: string | string[] } | undefined\n\n let updatedPath = (query.__nextSsgPath as string) || path\n let locale = query.__nextLocale || renderOpts.locale\n delete query.__nextLocale\n delete query.__nextSsgPath\n\n if (renderOpts.locale) {\n const localePathResult = normalizeLocalePath(path, renderOpts.locales)\n\n if (localePathResult.detectedLocale) {\n updatedPath = localePathResult.pathname\n locale = localePathResult.detectedLocale\n\n if (locale === renderOpts.defaultLocale) {\n renderAmpPath = `${normalizePagePath(updatedPath)}.amp`\n }\n }\n }\n\n // We need to show a warning if they try to provide query values\n // for an auto-exported page since they won't be available\n const hasOrigQueryValues = Object.keys(originalQuery).length > 0\n const queryWithAutoExportWarn = () => {\n if (hasOrigQueryValues) {\n throw new Error(\n `\\nError: you provided query values for ${path} which is an auto-exported page. These can not be applied since the page can no longer be re-rendered on the server. To disable auto-export for this page add \\`getInitialProps\\`\\n`\n )\n }\n }\n\n // Check if the page is a specified dynamic route\n const nonLocalizedPath = normalizeLocalePath(path, renderOpts.locales)\n .pathname\n\n if (isDynamic && page !== nonLocalizedPath) {\n params = getRouteMatcher(getRouteRegex(page))(updatedPath) || undefined\n if (params) {\n // we have to pass these separately for serverless\n if (!serverless) {\n query = {\n ...query,\n ...params,\n }\n }\n } else {\n throw new Error(\n `The provided export path '${updatedPath}' doesn't match the '${page}' page.\\nRead more: https://nextjs.org/docs/messages/export-path-mismatch`\n )\n }\n }\n\n const headerMocks = {\n headers: {},\n getHeader: () => ({}),\n setHeader: () => {},\n hasHeader: () => false,\n removeHeader: () => {},\n getHeaderNames: () => [],\n }\n\n const req = ({\n url: updatedPath,\n ...headerMocks,\n } as unknown) as IncomingMessage\n const res = ({\n ...headerMocks,\n } as unknown) as ServerResponse\n\n if (path === '/500' && page === '/_error') {\n res.statusCode = 500\n }\n\n if (renderOpts.trailingSlash && !req.url?.endsWith('/')) {\n req.url += '/'\n }\n\n envConfig.setConfig({\n serverRuntimeConfig,\n publicRuntimeConfig: renderOpts.runtimeConfig,\n })\n\n let htmlFilename = `${filePath}${sep}index.html`\n if (!subFolders) htmlFilename = `${filePath}.html`\n\n const pageExt = extname(page)\n const pathExt = extname(path)\n // Make sure page isn't a folder with a dot in the name e.g. `v1.2`\n if (pageExt !== pathExt && pathExt !== '') {\n // If the path has an extension, use that as the filename instead\n htmlFilename = path\n } else if (path === '/') {\n // If the path is the root, just use index.html\n htmlFilename = 'index.html'\n }\n\n const baseDir = join(outDir, dirname(htmlFilename))\n let htmlFilepath = join(outDir, htmlFilename)\n\n await promises.mkdir(baseDir, { recursive: true })\n let html\n let curRenderOpts: RenderOpts = {}\n let renderMethod = renderToHTML\n let inAmpMode = false,\n hybridAmp = false\n\n const renderedDuringBuild = (getStaticProps: any) => {\n return !buildExport && getStaticProps && !isDynamicRoute(path)\n }\n\n if (serverless) {\n const curUrl = url.parse(req.url!, true)\n req.url = url.format({\n ...curUrl,\n query: {\n ...curUrl.query,\n ...query,\n },\n })\n const {\n Component: mod,\n getServerSideProps,\n pageConfig,\n } = await loadComponents(distDir, page, serverless)\n const ampState = {\n ampFirst: pageConfig?.amp === true,\n hasQuery: Boolean(query.amp),\n hybrid: pageConfig?.amp === 'hybrid',\n }\n inAmpMode = isInAmpMode(ampState)\n hybridAmp = ampState.hybrid\n\n if (getServerSideProps) {\n throw new Error(\n `Error for page ${page}: ${SERVER_PROPS_EXPORT_ERROR}`\n )\n }\n\n // if it was auto-exported the HTML is loaded here\n if (typeof mod === 'string') {\n html = mod\n queryWithAutoExportWarn()\n } else {\n // for non-dynamic SSG pages we should have already\n // prerendered the file\n if (renderedDuringBuild((mod as ComponentModule).getStaticProps))\n return results\n\n if (\n (mod as ComponentModule).getStaticProps &&\n !htmlFilepath.endsWith('.html')\n ) {\n // make sure it ends with .html if the name contains a dot\n htmlFilename += '.html'\n htmlFilepath += '.html'\n }\n\n renderMethod = (mod as ComponentModule).renderReqToHTML\n const result = await renderMethod(\n req,\n res,\n 'export',\n {\n ampPath: renderAmpPath,\n /// @ts-ignore\n optimizeFonts,\n /// @ts-ignore\n optimizeImages,\n /// @ts-ignore\n optimizeCss,\n disableOptimizedLoading,\n distDir,\n fontManifest: optimizeFonts\n ? requireFontManifest(distDir, serverless)\n : null,\n locale: locale!,\n locales: renderOpts.locales!,\n },\n // @ts-ignore\n params\n )\n curRenderOpts = (result as any).renderOpts || {}\n html = (result as any).html\n }\n\n if (!html && !(curRenderOpts as any).isNotFound) {\n throw new Error(`Failed to render serverless page`)\n }\n } else {\n const components = await loadComponents(distDir, page, serverless)\n const ampState = {\n ampFirst: components.pageConfig?.amp === true,\n hasQuery: Boolean(query.amp),\n hybrid: components.pageConfig?.amp === 'hybrid',\n }\n inAmpMode = isInAmpMode(ampState)\n hybridAmp = ampState.hybrid\n\n if (components.getServerSideProps) {\n throw new Error(\n `Error for page ${page}: ${SERVER_PROPS_EXPORT_ERROR}`\n )\n }\n\n // for non-dynamic SSG pages we should have already\n // prerendered the file\n if (renderedDuringBuild(components.getStaticProps)) {\n return results\n }\n\n // TODO: de-dupe the logic here between serverless and server mode\n if (components.getStaticProps && !htmlFilepath.endsWith('.html')) {\n // make sure it ends with .html if the name contains a dot\n htmlFilepath += '.html'\n htmlFilename += '.html'\n }\n\n if (typeof components.Component === 'string') {\n html = components.Component\n queryWithAutoExportWarn()\n } else {\n /**\n * This sets environment variable to be used at the time of static export by head.tsx.\n * Using this from process.env allows targeting both serverless and SSR by calling\n * `process.env.__NEXT_OPTIMIZE_FONTS`.\n * TODO(prateekbh@): Remove this when experimental.optimizeFonts are being cleaned up.\n */\n if (optimizeFonts) {\n process.env.__NEXT_OPTIMIZE_FONTS = JSON.stringify(true)\n }\n if (optimizeImages) {\n process.env.__NEXT_OPTIMIZE_IMAGES = JSON.stringify(true)\n }\n if (optimizeCss) {\n process.env.__NEXT_OPTIMIZE_CSS = JSON.stringify(true)\n }\n curRenderOpts = {\n ...components,\n ...renderOpts,\n ampPath: renderAmpPath,\n params,\n optimizeFonts,\n optimizeImages,\n optimizeCss,\n disableOptimizedLoading,\n fontManifest: optimizeFonts\n ? requireFontManifest(distDir, serverless)\n : null,\n locale: locale as string,\n }\n // @ts-ignore\n html = await renderMethod(req, res, page, query, curRenderOpts)\n }\n }\n results.ssgNotFound = (curRenderOpts as any).isNotFound\n\n const validateAmp = async (\n rawAmpHtml: string,\n ampPageName: string,\n validatorPath?: string\n ) => {\n const validator = await AmpHtmlValidator.getInstance(validatorPath)\n const result = validator.validateString(rawAmpHtml)\n const errors = result.errors.filter((e) => e.severity === 'ERROR')\n const warnings = result.errors.filter((e) => e.severity !== 'ERROR')\n\n if (warnings.length || errors.length) {\n results.ampValidations.push({\n page: ampPageName,\n result: {\n errors,\n warnings,\n },\n })\n }\n }\n\n if (inAmpMode && !curRenderOpts.ampSkipValidation) {\n if (!results.ssgNotFound) {\n await validateAmp(html, path, curRenderOpts.ampValidatorPath)\n }\n } else if (hybridAmp) {\n // we need to render the AMP version\n let ampHtmlFilename = `${ampPath}${sep}index.html`\n if (!subFolders) {\n ampHtmlFilename = `${ampPath}.html`\n }\n const ampBaseDir = join(outDir, dirname(ampHtmlFilename))\n const ampHtmlFilepath = join(outDir, ampHtmlFilename)\n\n try {\n await promises.access(ampHtmlFilepath)\n } catch (_) {\n // make sure it doesn't exist from manual mapping\n let ampHtml\n if (serverless) {\n req.url += (req.url!.includes('?') ? '&' : '?') + 'amp=1'\n // @ts-ignore\n ampHtml = (\n await (renderMethod as any)(\n req,\n res,\n 'export',\n curRenderOpts,\n params\n )\n ).html\n } else {\n ampHtml = await renderMethod(\n req,\n res,\n page,\n // @ts-ignore\n { ...query, amp: '1' },\n curRenderOpts as any\n )\n }\n\n if (!curRenderOpts.ampSkipValidation) {\n await validateAmp(ampHtml, page + '?amp=1')\n }\n await promises.mkdir(ampBaseDir, { recursive: true })\n await promises.writeFile(ampHtmlFilepath, ampHtml, 'utf8')\n }\n }\n\n if ((curRenderOpts as any).pageData) {\n const dataFile = join(\n pagesDataDir,\n htmlFilename.replace(/\\.html$/, '.json')\n )\n\n await promises.mkdir(dirname(dataFile), { recursive: true })\n await promises.writeFile(\n dataFile,\n JSON.stringify((curRenderOpts as any).pageData),\n 'utf8'\n )\n\n if (hybridAmp) {\n await promises.writeFile(\n dataFile.replace(/\\.json$/, '.amp.json'),\n JSON.stringify((curRenderOpts as any).pageData),\n 'utf8'\n )\n }\n }\n results.fromBuildExportRevalidate = (curRenderOpts as any).revalidate\n\n if (results.ssgNotFound) {\n // don't attempt writing to disk if getStaticProps returned not found\n return results\n }\n await promises.writeFile(htmlFilepath, html, 'utf8')\n return results\n } catch (error) {\n console.error(\n `\\nError occurred prerendering page \"${path}\". Read more: https://nextjs.org/docs/messages/prerender-error\\n` +\n error.stack\n )\n return { ...results, error: true }\n }\n })\n}\n"]}
\No newline at end of file