Unverified Commit 6adb9716 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add CompilerAliases Type (#57237)

Ensures all functions in create-compiler-aliases.ts have the same return type. 
parent a65e5c07
...@@ -19,6 +19,10 @@ import { ...@@ -19,6 +19,10 @@ import {
} from './webpack-config' } from './webpack-config'
import { WEBPACK_LAYERS } from '../lib/constants' import { WEBPACK_LAYERS } from '../lib/constants'
interface CompilerAliases {
[alias: string]: string | string[]
}
export function createWebpackAliases({ export function createWebpackAliases({
dev, dev,
pageExtensions, pageExtensions,
...@@ -47,16 +51,9 @@ export function createWebpackAliases({ ...@@ -47,16 +51,9 @@ export function createWebpackAliases({
isNodeServer: boolean isNodeServer: boolean
clientResolveRewrites: string clientResolveRewrites: string
hasRewrites: boolean hasRewrites: boolean
}): }): CompilerAliases {
| { const customAppAliases: CompilerAliases = {}
alias: string | false | string[] const customDocumentAliases: CompilerAliases = {}
name: string
onlyModule?: boolean | undefined
}[]
| { [index: string]: string | false | string[] }
| undefined {
const customAppAliases: { [key: string]: string[] } = {}
const customDocumentAliases: { [key: string]: string[] } = {}
if (dev) { if (dev) {
const nextDistPath = 'next/dist/' + (isEdgeServer ? 'esm/' : '') const nextDistPath = 'next/dist/' + (isEdgeServer ? 'esm/' : '')
...@@ -211,9 +208,9 @@ export function createWebpackAliases({ ...@@ -211,9 +208,9 @@ export function createWebpackAliases({
} }
} }
export function createServerOnlyClientOnlyAliases(isServer: boolean): { export function createServerOnlyClientOnlyAliases(
[aliasPath: string]: string isServer: boolean
} { ): CompilerAliases {
return isServer return isServer
? { ? {
'server-only$': 'next/dist/compiled/server-only/empty', 'server-only$': 'next/dist/compiled/server-only/empty',
...@@ -244,7 +241,7 @@ export function createRSCAliases( ...@@ -244,7 +241,7 @@ export function createRSCAliases(
isEdgeServer: boolean isEdgeServer: boolean
reactProductionProfiling: boolean reactProductionProfiling: boolean
} }
) { ): CompilerAliases {
let alias: Record<string, string> = { let alias: Record<string, string> = {
react$: `next/dist/compiled/react${bundledReactChannel}`, react$: `next/dist/compiled/react${bundledReactChannel}`,
'react-dom$': `next/dist/compiled/react-dom${bundledReactChannel}`, 'react-dom$': `next/dist/compiled/react-dom${bundledReactChannel}`,
...@@ -309,7 +306,7 @@ export function createRSCAliases( ...@@ -309,7 +306,7 @@ export function createRSCAliases(
// Insert aliases for Next.js stubs of fetch, object-assign, and url // Insert aliases for Next.js stubs of fetch, object-assign, and url
// Keep in sync with insert_optimized_module_aliases in import_map.rs // Keep in sync with insert_optimized_module_aliases in import_map.rs
export function getOptimizedModuleAliases(): { [pkg: string]: string } { export function getOptimizedModuleAliases(): CompilerAliases {
return { return {
unfetch: require.resolve('next/dist/build/polyfills/fetch/index.js'), unfetch: require.resolve('next/dist/build/polyfills/fetch/index.js'),
'isomorphic-unfetch': require.resolve( 'isomorphic-unfetch': require.resolve(
...@@ -338,7 +335,7 @@ export function getOptimizedModuleAliases(): { [pkg: string]: string } { ...@@ -338,7 +335,7 @@ export function getOptimizedModuleAliases(): { [pkg: string]: string } {
} }
// Alias these modules to be resolved with "module" if possible. // Alias these modules to be resolved with "module" if possible.
function getBarrelOptimizationAliases(packages: string[]) { function getBarrelOptimizationAliases(packages: string[]): CompilerAliases {
const aliases: { [pkg: string]: string } = {} const aliases: { [pkg: string]: string } = {}
const mainFields = ['module', 'main'] const mainFields = ['module', 'main']
...@@ -361,12 +358,12 @@ function getBarrelOptimizationAliases(packages: string[]) { ...@@ -361,12 +358,12 @@ function getBarrelOptimizationAliases(packages: string[]) {
return aliases return aliases
} }
function getReactProfilingInProduction() { function getReactProfilingInProduction(): CompilerAliases {
return { return {
'react-dom$': 'react-dom/profiling', 'react-dom$': 'react-dom/profiling',
} }
} }
export function createServerComponentsNoopAliases() { export function createServerComponentsNoopAliases(): CompilerAliases {
return { return {
[require.resolve('next/head')]: require.resolve( [require.resolve('next/head')]: require.resolve(
'next/dist/client/components/noop-head' 'next/dist/client/components/noop-head'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment