Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CompilerAliases Type #57237

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading