mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Dont use baseURL relative absolute paths in declaration emit, use absolute paths in bundle emit (#26341)
This commit is contained in:
@@ -3900,8 +3900,6 @@ namespace ts {
|
||||
compilerOptions,
|
||||
contextFile,
|
||||
context.tracker.moduleResolverHost,
|
||||
context.tracker.moduleResolverHost.getSourceFiles!(), // TODO: GH#18217
|
||||
{ importModuleSpecifierPreference: "non-relative" },
|
||||
host.redirectTargetsMap,
|
||||
);
|
||||
links.specifierCache = links.specifierCache || createMap();
|
||||
|
||||
@@ -27,11 +27,21 @@ namespace ts.moduleSpecifiers {
|
||||
compilerOptions: CompilerOptions,
|
||||
importingSourceFile: SourceFile,
|
||||
host: ModuleSpecifierResolutionHost,
|
||||
files: ReadonlyArray<SourceFile>,
|
||||
preferences: ModuleSpecifierPreferences,
|
||||
redirectTargetsMap: RedirectTargetsMap,
|
||||
): string {
|
||||
return first(first(getModuleSpecifiers(moduleSymbol, compilerOptions, importingSourceFile, host, files, preferences, redirectTargetsMap)));
|
||||
const isBundle = (compilerOptions.out || compilerOptions.outFile);
|
||||
if (isBundle && host.getCommonSourceDirectory) {
|
||||
// For declaration bundles, we need to generate absolute paths relative to the common source dir for imports,
|
||||
// just like how the declaration emitter does for the ambient module declarations - we can easily accomplish this
|
||||
// using the `baseUrl` compiler option (which we would otherwise never use in declaration emit) and a non-relative
|
||||
// specifier preference
|
||||
compilerOptions = {
|
||||
...compilerOptions,
|
||||
baseUrl: host.getCommonSourceDirectory(),
|
||||
};
|
||||
}
|
||||
const preferences: ModuleSpecifierPreferences = { importModuleSpecifierPreference: isBundle ? "non-relative" : "relative" };
|
||||
return first(first(getModuleSpecifiers(moduleSymbol, compilerOptions, importingSourceFile, host, host.getSourceFiles ? host.getSourceFiles() : [importingSourceFile], preferences, redirectTargetsMap)));
|
||||
}
|
||||
|
||||
// For each symlink/original for a module, returns a list of ways to import that file.
|
||||
|
||||
@@ -5336,6 +5336,7 @@ namespace ts {
|
||||
fileExists?(path: string): boolean;
|
||||
readFile?(path: string): string | undefined;
|
||||
getSourceFiles?(): ReadonlyArray<SourceFile>; // Used for cached resolutions to find symlinks without traversing the fs (again)
|
||||
getCommonSourceDirectory?(): string;
|
||||
}
|
||||
|
||||
// Note: this used to be deprecated in our public API, but is still used internally
|
||||
|
||||
Reference in New Issue
Block a user