utils.d.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /// <reference types="node" />
  2. import type { NextConfigComplete } from '../server/config-shared';
  3. import '../server/node-polyfill-fetch';
  4. import { CustomRoutes } from '../lib/load-custom-routes';
  5. import { GetStaticPaths, ServerRuntime } from 'next/types';
  6. import { BuildManifest } from '../server/get-page-files';
  7. import { UnwrapPromise } from '../lib/coalesced-function';
  8. import { MiddlewareManifest } from './webpack/plugins/middleware-plugin';
  9. import { AppBuildManifest } from './webpack/plugins/app-build-manifest-plugin';
  10. export declare type ROUTER_TYPE = 'pages' | 'app';
  11. export declare function unique<T>(main: ReadonlyArray<T>, sub: ReadonlyArray<T>): T[];
  12. export declare function difference<T>(main: ReadonlyArray<T> | ReadonlySet<T>, sub: ReadonlyArray<T> | ReadonlySet<T>): T[];
  13. declare type ComputeFilesGroup = {
  14. files: ReadonlyArray<string>;
  15. size: {
  16. total: number;
  17. };
  18. };
  19. declare type ComputeFilesManifest = {
  20. unique: ComputeFilesGroup;
  21. common: ComputeFilesGroup;
  22. };
  23. declare type ComputeFilesManifestResult = {
  24. router: {
  25. pages: ComputeFilesManifest;
  26. app?: ComputeFilesManifest;
  27. };
  28. sizes: Map<string, number>;
  29. };
  30. export declare function computeFromManifest(manifests: {
  31. build: BuildManifest;
  32. app?: AppBuildManifest;
  33. }, distPath: string, gzipSize?: boolean, pageInfos?: Map<string, PageInfo>): Promise<ComputeFilesManifestResult>;
  34. export declare function isMiddlewareFilename(file?: string): boolean;
  35. export interface PageInfo {
  36. isHybridAmp?: boolean;
  37. size: number;
  38. totalSize: number;
  39. static: boolean;
  40. isSsg: boolean;
  41. ssgPageRoutes: string[] | null;
  42. initialRevalidateSeconds: number | false;
  43. pageDuration: number | undefined;
  44. ssgPageDurations: number[] | undefined;
  45. runtime: ServerRuntime;
  46. }
  47. export declare function printTreeView(lists: {
  48. pages: ReadonlyArray<string>;
  49. app?: ReadonlyArray<string>;
  50. }, pageInfos: Map<string, PageInfo>, serverless: boolean, { distPath, buildId, pagesDir, pageExtensions, buildManifest, appBuildManifest, middlewareManifest, useStatic404, gzipSize, }: {
  51. distPath: string;
  52. buildId: string;
  53. pagesDir?: string;
  54. pageExtensions: string[];
  55. buildManifest: BuildManifest;
  56. appBuildManifest?: AppBuildManifest;
  57. middlewareManifest: MiddlewareManifest;
  58. useStatic404: boolean;
  59. gzipSize?: boolean;
  60. }): Promise<void>;
  61. export declare function printCustomRoutes({ redirects, rewrites, headers, }: CustomRoutes): void;
  62. export declare function getJsPageSizeInKb(routerType: ROUTER_TYPE, page: string, distPath: string, buildManifest: BuildManifest, appBuildManifest?: AppBuildManifest, gzipSize?: boolean, cachedStats?: ComputeFilesManifestResult): Promise<[number, number]>;
  63. export declare function buildStaticPaths({ page, getStaticPaths, staticPathsResult, configFileName, locales, defaultLocale, }: {
  64. page: string;
  65. getStaticPaths?: GetStaticPaths;
  66. staticPathsResult?: UnwrapPromise<ReturnType<GetStaticPaths>>;
  67. configFileName: string;
  68. locales?: string[];
  69. defaultLocale?: string;
  70. }): Promise<Omit<UnwrapPromise<ReturnType<GetStaticPaths>>, 'paths'> & {
  71. paths: string[];
  72. encodedPaths: string[];
  73. }>;
  74. export declare type AppConfig = {
  75. revalidate?: number | false;
  76. dynamicParams?: true | false;
  77. dynamic?: 'auto' | 'error' | 'force-static';
  78. fetchCache?: 'force-cache' | 'only-cache';
  79. preferredRegion?: string;
  80. };
  81. declare type GenerateParams = Array<{
  82. config: AppConfig;
  83. segmentPath: string;
  84. getStaticPaths?: GetStaticPaths;
  85. generateStaticParams?: any;
  86. isLayout?: boolean;
  87. }>;
  88. export declare const collectGenerateParams: (segment: any, parentSegments?: string[], generateParams?: GenerateParams) => GenerateParams;
  89. export declare function buildAppStaticPaths({ page, configFileName, generateParams, }: {
  90. page: string;
  91. configFileName: string;
  92. generateParams: GenerateParams;
  93. }): Promise<(Omit<import("next/types").GetStaticPathsResult<import("querystring").ParsedUrlQuery>, "paths"> & {
  94. paths: string[];
  95. encodedPaths: string[];
  96. }) | {
  97. paths: undefined;
  98. fallback: undefined;
  99. encodedPaths: undefined;
  100. }>;
  101. export declare function isPageStatic({ page, distDir, serverless, configFileName, runtimeEnvConfig, httpAgentOptions, locales, defaultLocale, parentId, pageRuntime, edgeInfo, pageType, hasServerComponents, originalAppPath, }: {
  102. page: string;
  103. distDir: string;
  104. serverless: boolean;
  105. configFileName: string;
  106. runtimeEnvConfig: any;
  107. httpAgentOptions: NextConfigComplete['httpAgentOptions'];
  108. locales?: string[];
  109. defaultLocale?: string;
  110. parentId?: any;
  111. edgeInfo?: any;
  112. pageType?: 'pages' | 'app';
  113. pageRuntime: ServerRuntime;
  114. hasServerComponents?: boolean;
  115. originalAppPath?: string;
  116. }): Promise<{
  117. isStatic?: boolean;
  118. isAmpOnly?: boolean;
  119. isHybridAmp?: boolean;
  120. hasServerProps?: boolean;
  121. hasStaticProps?: boolean;
  122. prerenderRoutes?: string[];
  123. encodedPrerenderRoutes?: string[];
  124. prerenderFallback?: boolean | 'blocking';
  125. isNextImageImported?: boolean;
  126. traceIncludes?: string[];
  127. traceExcludes?: string[];
  128. appConfig?: AppConfig;
  129. }>;
  130. export declare function hasCustomGetInitialProps(page: string, distDir: string, isLikeServerless: boolean, runtimeEnvConfig: any, checkingApp: boolean): Promise<boolean>;
  131. export declare function getNamedExports(page: string, distDir: string, isLikeServerless: boolean, runtimeEnvConfig: any): Promise<Array<string>>;
  132. export declare function detectConflictingPaths(combinedPages: string[], ssgPages: Set<string>, additionalSsgPaths: Map<string, string[]>): void;
  133. export declare function copyTracedFiles(dir: string, distDir: string, pageKeys: ReadonlyArray<string>, tracingRoot: string, serverConfig: {
  134. [key: string]: any;
  135. }, middlewareManifest: MiddlewareManifest): Promise<void>;
  136. export declare function isReservedPage(page: string): boolean;
  137. export declare function isCustomErrorPage(page: string): boolean;
  138. export declare function isMiddlewareFile(file: string): boolean;
  139. export declare function getPossibleMiddlewareFilenames(folder: string, extensions: string[]): string[];
  140. export declare class MiddlewareInServerlessTargetError extends Error {
  141. constructor();
  142. }
  143. export declare class NestedMiddlewareError extends Error {
  144. constructor(nestedFileNames: string[], mainDir: string, pagesDir: string);
  145. }
  146. export {};