mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-17 12:19:32 -05:00
--moduleResolution bundler: Require ESM for module and remove node from hard-coded conditions (#52940)
This commit is contained in:
@@ -70,6 +70,7 @@ import {
|
||||
ModuleResolutionHost,
|
||||
ModuleResolutionKind,
|
||||
moduleResolutionOptionDeclarations,
|
||||
moduleResolutionSupportsPackageJsonExportsAndImports,
|
||||
noop,
|
||||
noopPush,
|
||||
normalizePath,
|
||||
@@ -705,11 +706,14 @@ export function getConditions(options: CompilerOptions, esmMode?: boolean) {
|
||||
// conditions are only used by the node16/nodenext/bundler resolvers - there's no priority order in the list,
|
||||
// it's essentially a set (priority is determined by object insertion order in the object we look at).
|
||||
const conditions = esmMode || getEmitModuleResolutionKind(options) === ModuleResolutionKind.Bundler
|
||||
? ["node", "import"]
|
||||
: ["node", "require"];
|
||||
? ["import"]
|
||||
: ["require"];
|
||||
if (!options.noDtsResolution) {
|
||||
conditions.push("types");
|
||||
}
|
||||
if (getEmitModuleResolutionKind(options) !== ModuleResolutionKind.Bundler) {
|
||||
conditions.push("node");
|
||||
}
|
||||
return concatenate(conditions, options.customConditions);
|
||||
}
|
||||
|
||||
@@ -1701,7 +1705,7 @@ function nodeModuleNameResolverWorker(features: NodeResolutionFeatures, moduleNa
|
||||
candidateIsFromPackageJsonField: false,
|
||||
};
|
||||
|
||||
if (traceEnabled && getEmitModuleResolutionKind(compilerOptions) >= ModuleResolutionKind.Node16 && getEmitModuleResolutionKind(compilerOptions) <= ModuleResolutionKind.NodeNext) {
|
||||
if (traceEnabled && moduleResolutionSupportsPackageJsonExportsAndImports(getEmitModuleResolutionKind(compilerOptions))) {
|
||||
trace(host, Diagnostics.Resolving_in_0_mode_with_conditions_1, features & NodeResolutionFeatures.EsmMode ? "ESM" : "CJS", conditions.map(c => `'${c}'`).join(", "));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user