Skip to content

Commit

Permalink
Add CompilerAliases Type (#57237)
Browse files Browse the repository at this point in the history
Ensures all functions in create-compiler-aliases.ts have the same return type.
  • Loading branch information
timneutkens authored Oct 23, 2023
1 parent a65e5c0 commit 6adb971
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions packages/next/src/build/create-compiler-aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import {
} from './webpack-config'
import { WEBPACK_LAYERS } from '../lib/constants'

interface CompilerAliases {
[alias: string]: string | string[]
}

export function createWebpackAliases({
dev,
pageExtensions,
Expand Down Expand Up @@ -47,16 +51,9 @@ export function createWebpackAliases({
isNodeServer: boolean
clientResolveRewrites: string
hasRewrites: boolean
}):
| {
alias: string | false | string[]
name: string
onlyModule?: boolean | undefined
}[]
| { [index: string]: string | false | string[] }
| undefined {
const customAppAliases: { [key: string]: string[] } = {}
const customDocumentAliases: { [key: string]: string[] } = {}
}): CompilerAliases {
const customAppAliases: CompilerAliases = {}
const customDocumentAliases: CompilerAliases = {}

if (dev) {
const nextDistPath = 'next/dist/' + (isEdgeServer ? 'esm/' : '')
Expand Down Expand Up @@ -211,9 +208,9 @@ export function createWebpackAliases({
}
}

export function createServerOnlyClientOnlyAliases(isServer: boolean): {
[aliasPath: string]: string
} {
export function createServerOnlyClientOnlyAliases(
isServer: boolean
): CompilerAliases {
return isServer
? {
'server-only$': 'next/dist/compiled/server-only/empty',
Expand Down Expand Up @@ -244,7 +241,7 @@ export function createRSCAliases(
isEdgeServer: boolean
reactProductionProfiling: boolean
}
) {
): CompilerAliases {
let alias: Record<string, string> = {
react$: `next/dist/compiled/react${bundledReactChannel}`,
'react-dom$': `next/dist/compiled/react-dom${bundledReactChannel}`,
Expand Down Expand Up @@ -309,7 +306,7 @@ export function createRSCAliases(

// Insert aliases for Next.js stubs of fetch, object-assign, and url
// Keep in sync with insert_optimized_module_aliases in import_map.rs
export function getOptimizedModuleAliases(): { [pkg: string]: string } {
export function getOptimizedModuleAliases(): CompilerAliases {
return {
unfetch: require.resolve('next/dist/build/polyfills/fetch/index.js'),
'isomorphic-unfetch': require.resolve(
Expand Down Expand Up @@ -338,7 +335,7 @@ export function getOptimizedModuleAliases(): { [pkg: string]: string } {
}

// 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 mainFields = ['module', 'main']

Expand All @@ -361,12 +358,12 @@ function getBarrelOptimizationAliases(packages: string[]) {

return aliases
}
function getReactProfilingInProduction() {
function getReactProfilingInProduction(): CompilerAliases {
return {
'react-dom$': 'react-dom/profiling',
}
}
export function createServerComponentsNoopAliases() {
export function createServerComponentsNoopAliases(): CompilerAliases {
return {
[require.resolve('next/head')]: require.resolve(
'next/dist/client/components/noop-head'
Expand Down

0 comments on commit 6adb971

Please sign in to comment.