mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 04:22:12 +00:00
Add immutability modifiers to types (#11182)
This doesn't change any functionality, and only replaces some mutable types (like `Map`, `Set`, and `Array`) with their immutable versions (like `ReadonlyMap`, `ReadonlySet`, and `ReadonlyArray`). This can help keep functions as pure as possible and improves the readability of some of the involved functions.
This commit is contained in:
2
.changeset/wicked-ligers-rhyme.md
Normal file
2
.changeset/wicked-ligers-rhyme.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
---
|
||||||
@@ -511,7 +511,7 @@ export const build: BuildV2 = async ({
|
|||||||
entryPath,
|
entryPath,
|
||||||
outputDirectory
|
outputDirectory
|
||||||
);
|
);
|
||||||
const omittedPrerenderRoutes = new Set(
|
const omittedPrerenderRoutes: ReadonlySet<string> = new Set(
|
||||||
Object.keys(prerenderManifest.omittedRoutes)
|
Object.keys(prerenderManifest.omittedRoutes)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ export async function serverBuild({
|
|||||||
pagesDir: string;
|
pagesDir: string;
|
||||||
baseDir: string;
|
baseDir: string;
|
||||||
canUsePreviewMode: boolean;
|
canUsePreviewMode: boolean;
|
||||||
omittedPrerenderRoutes: Set<string>;
|
omittedPrerenderRoutes: ReadonlySet<string>;
|
||||||
localePrefixed404: boolean;
|
localePrefixed404: boolean;
|
||||||
staticPages: { [key: string]: FileFsRef };
|
staticPages: { [key: string]: FileFsRef };
|
||||||
lambdaAppPaths: { [key: string]: FileFsRef };
|
lambdaAppPaths: { [key: string]: FileFsRef };
|
||||||
@@ -364,7 +364,7 @@ export async function serverBuild({
|
|||||||
experimentalPPRRoutes.add(route);
|
experimentalPPRRoutes.add(route);
|
||||||
}
|
}
|
||||||
|
|
||||||
const prerenderRoutes = new Set<string>([
|
const prerenderRoutes: ReadonlySet<string> = new Set<string>([
|
||||||
...(canUsePreviewMode ? omittedPrerenderRoutes : []),
|
...(canUsePreviewMode ? omittedPrerenderRoutes : []),
|
||||||
...Object.keys(prerenderManifest.blockingFallbackRoutes),
|
...Object.keys(prerenderManifest.blockingFallbackRoutes),
|
||||||
...Object.keys(prerenderManifest.fallbackRoutes),
|
...Object.keys(prerenderManifest.fallbackRoutes),
|
||||||
@@ -772,7 +772,7 @@ export async function serverBuild({
|
|||||||
.filter(Boolean) as string[];
|
.filter(Boolean) as string[];
|
||||||
|
|
||||||
let traceResult: NodeFileTraceResult | undefined;
|
let traceResult: NodeFileTraceResult | undefined;
|
||||||
let parentFilesMap: Map<string, Set<string>> | undefined;
|
let parentFilesMap: ReadonlyMap<string, Set<string>> | undefined;
|
||||||
|
|
||||||
if (pathsToTrace.length > 0) {
|
if (pathsToTrace.length > 0) {
|
||||||
traceResult = await nodeFileTrace(pathsToTrace, {
|
traceResult = await nodeFileTrace(pathsToTrace, {
|
||||||
|
|||||||
@@ -307,14 +307,14 @@ export async function getRoutesManifest(
|
|||||||
export async function getDynamicRoutes(
|
export async function getDynamicRoutes(
|
||||||
entryPath: string,
|
entryPath: string,
|
||||||
entryDirectory: string,
|
entryDirectory: string,
|
||||||
dynamicPages: string[],
|
dynamicPages: ReadonlyArray<string>,
|
||||||
isDev?: boolean,
|
isDev?: boolean,
|
||||||
routesManifest?: RoutesManifest,
|
routesManifest?: RoutesManifest,
|
||||||
omittedRoutes?: Set<string>,
|
omittedRoutes?: ReadonlySet<string>,
|
||||||
canUsePreviewMode?: boolean,
|
canUsePreviewMode?: boolean,
|
||||||
bypassToken?: string,
|
bypassToken?: string,
|
||||||
isServerMode?: boolean,
|
isServerMode?: boolean,
|
||||||
dynamicMiddlewareRouteMap?: Map<string, RouteWithSrc>,
|
dynamicMiddlewareRouteMap?: ReadonlyMap<string, RouteWithSrc>,
|
||||||
experimentalPPR?: boolean
|
experimentalPPR?: boolean
|
||||||
): Promise<RouteWithSrc[]> {
|
): Promise<RouteWithSrc[]> {
|
||||||
if (routesManifest) {
|
if (routesManifest) {
|
||||||
@@ -442,7 +442,9 @@ export async function getDynamicRoutes(
|
|||||||
let getRouteRegex: ((pageName: string) => { re: RegExp }) | undefined =
|
let getRouteRegex: ((pageName: string) => { re: RegExp }) | undefined =
|
||||||
undefined;
|
undefined;
|
||||||
|
|
||||||
let getSortedRoutes: ((normalizedPages: string[]) => string[]) | undefined;
|
let getSortedRoutes:
|
||||||
|
| ((normalizedPages: ReadonlyArray<string>) => string[])
|
||||||
|
| undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resolved = require_.resolve('next-server/dist/lib/router/utils', {
|
const resolved = require_.resolve('next-server/dist/lib/router/utils', {
|
||||||
@@ -645,10 +647,10 @@ export function filterStaticPages(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getFilesMapFromReasons(
|
export function getFilesMapFromReasons(
|
||||||
fileList: Set<string>,
|
fileList: ReadonlySet<string>,
|
||||||
reasons: NodeFileTraceReasons,
|
reasons: NodeFileTraceReasons,
|
||||||
ignoreFn?: (file: string, parent?: string) => boolean
|
ignoreFn?: (file: string, parent?: string) => boolean
|
||||||
) {
|
): ReadonlyMap<string, Set<string>> {
|
||||||
// this uses the reasons tree to collect files specific to a
|
// this uses the reasons tree to collect files specific to a
|
||||||
// certain parent allowing us to not have to trace each parent
|
// certain parent allowing us to not have to trace each parent
|
||||||
// separately
|
// separately
|
||||||
@@ -1364,7 +1366,7 @@ async function getSourceFilePathFromPage({
|
|||||||
}: {
|
}: {
|
||||||
workPath: string;
|
workPath: string;
|
||||||
page: string;
|
page: string;
|
||||||
pageExtensions?: string[];
|
pageExtensions?: ReadonlyArray<string>;
|
||||||
}) {
|
}) {
|
||||||
const usesSrcDir = await usesSrcDirectory(workPath);
|
const usesSrcDir = await usesSrcDirectory(workPath);
|
||||||
const extensionsToTry = pageExtensions || ['js', 'jsx', 'ts', 'tsx'];
|
const extensionsToTry = pageExtensions || ['js', 'jsx', 'ts', 'tsx'];
|
||||||
@@ -1510,9 +1512,9 @@ export async function getPageLambdaGroups({
|
|||||||
entryPath: string;
|
entryPath: string;
|
||||||
config: Config;
|
config: Config;
|
||||||
functionsConfigManifest?: FunctionsConfigManifestV1;
|
functionsConfigManifest?: FunctionsConfigManifestV1;
|
||||||
pages: string[];
|
pages: ReadonlyArray<string>;
|
||||||
prerenderRoutes: Set<string>;
|
prerenderRoutes: ReadonlySet<string>;
|
||||||
experimentalPPRRoutes: Set<string> | undefined;
|
experimentalPPRRoutes: ReadonlySet<string> | undefined;
|
||||||
pageTraces: {
|
pageTraces: {
|
||||||
[page: string]: {
|
[page: string]: {
|
||||||
[key: string]: FileFsRef;
|
[key: string]: FileFsRef;
|
||||||
@@ -1525,8 +1527,8 @@ export async function getPageLambdaGroups({
|
|||||||
initialPseudoLayer: PseudoLayerResult;
|
initialPseudoLayer: PseudoLayerResult;
|
||||||
initialPseudoLayerUncompressed: number;
|
initialPseudoLayerUncompressed: number;
|
||||||
lambdaCompressedByteLimit: number;
|
lambdaCompressedByteLimit: number;
|
||||||
internalPages: string[];
|
internalPages: ReadonlyArray<string>;
|
||||||
pageExtensions?: string[];
|
pageExtensions?: ReadonlyArray<string>;
|
||||||
inversedAppPathManifest?: Record<string, string>;
|
inversedAppPathManifest?: Record<string, string>;
|
||||||
experimentalAllowBundling?: boolean;
|
experimentalAllowBundling?: boolean;
|
||||||
}) {
|
}) {
|
||||||
@@ -1912,7 +1914,7 @@ type OnPrerenderRouteArgs = {
|
|||||||
isServerMode: boolean;
|
isServerMode: boolean;
|
||||||
canUsePreviewMode: boolean;
|
canUsePreviewMode: boolean;
|
||||||
lambdas: { [key: string]: Lambda };
|
lambdas: { [key: string]: Lambda };
|
||||||
experimentalStreamingLambdaPaths: Map<string, string> | undefined;
|
experimentalStreamingLambdaPaths: ReadonlyMap<string, string> | undefined;
|
||||||
prerenders: { [key: string]: Prerender | File };
|
prerenders: { [key: string]: Prerender | File };
|
||||||
pageLambdaMap: { [key: string]: string };
|
pageLambdaMap: { [key: string]: string };
|
||||||
routesManifest?: RoutesManifest;
|
routesManifest?: RoutesManifest;
|
||||||
@@ -2827,7 +2829,7 @@ export async function getMiddlewareBundle({
|
|||||||
appPathRoutesManifest: Record<string, string>;
|
appPathRoutesManifest: Record<string, string>;
|
||||||
}): Promise<{
|
}): Promise<{
|
||||||
staticRoutes: Route[];
|
staticRoutes: Route[];
|
||||||
dynamicRouteMap: Map<string, RouteWithSrc>;
|
dynamicRouteMap: ReadonlyMap<string, RouteWithSrc>;
|
||||||
edgeFunctions: Record<string, EdgeFunction>;
|
edgeFunctions: Record<string, EdgeFunction>;
|
||||||
}> {
|
}> {
|
||||||
const middlewareManifest = await getMiddlewareManifest(
|
const middlewareManifest = await getMiddlewareManifest(
|
||||||
@@ -3311,7 +3313,7 @@ export async function getServerlessPages(params: {
|
|||||||
glob('**/route.js', appDir),
|
glob('**/route.js', appDir),
|
||||||
glob('**/_not-found.js', appDir),
|
glob('**/_not-found.js', appDir),
|
||||||
]).then(items => Object.assign(...items))
|
]).then(items => Object.assign(...items))
|
||||||
: Promise.resolve({}),
|
: Promise.resolve({} as Record<string, FileFsRef>),
|
||||||
getMiddlewareManifest(params.entryPath, params.outputDirectory),
|
getMiddlewareManifest(params.entryPath, params.outputDirectory),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user