-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Prefer module over main on main fields for app router…
- Loading branch information
Showing
14 changed files
with
99 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
COMPILER_NAMES, | ||
type CompilerNameValues, | ||
} from '../../shared/lib/constants' | ||
|
||
// exports.<conditionName> | ||
export const edgeConditionNames = [ | ||
'edge-light', | ||
'worker', | ||
// inherits the default conditions | ||
'...', | ||
] | ||
|
||
const mainFieldsPerCompiler: Record< | ||
CompilerNameValues | 'app-router-server', | ||
string[] | ||
> = { | ||
// For default case, prefer CJS over ESM on server side. e.g. pages dir SSR | ||
[COMPILER_NAMES.server]: ['main', 'module'], | ||
[COMPILER_NAMES.client]: ['browser', 'module', 'main'], | ||
[COMPILER_NAMES.edgeServer]: edgeConditionNames, | ||
// For app router since everything is bundled, prefer ESM over CJS | ||
'app-router-server': ['module', 'main'], | ||
} | ||
|
||
export function getMainField( | ||
pageType: 'app' | 'pages', | ||
compilerType: CompilerNameValues | ||
) { | ||
if (compilerType === COMPILER_NAMES.edgeServer) { | ||
return edgeConditionNames | ||
} else if (compilerType === COMPILER_NAMES.client) { | ||
return mainFieldsPerCompiler[COMPILER_NAMES.client] | ||
} | ||
|
||
// Prefer module fields over main fields for isomorphic packages on server layer | ||
return pageType === 'app' | ||
? mainFieldsPerCompiler['app-router-server'] | ||
: mainFieldsPerCompiler[COMPILER_NAMES.server] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
test/e2e/app-dir/app-external/node_modules_bak/conditional-exports-optout/react.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react' | ||
|
||
export function getReactVersion() { | ||
return React.version | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
test/e2e/app-dir/app-external/node_modules_bak/conditional-exports/react.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react' | ||
|
||
export function getReactVersion() { | ||
return React.version | ||
} |
1 change: 1 addition & 0 deletions
1
test/e2e/app-dir/app-external/node_modules_bak/server-module-field/index.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports.name = 'server-module-field:main' |
1 change: 1 addition & 0 deletions
1
test/e2e/app-dir/app-external/node_modules_bak/server-module-field/index.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const name = 'server-module-field:module' |
4 changes: 4 additions & 0 deletions
4
test/e2e/app-dir/app-external/node_modules_bak/server-module-field/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"main": "./index.cjs", | ||
"module": "./index.esm.js" | ||
} |