Skip to content

Commit 9d1b450

Browse files
committed
Use correct baseUrl for the module specifier
1 parent 63b4076 commit 9d1b450

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

src/compiler/moduleSpecifiers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,13 @@ namespace ts.moduleSpecifiers {
181181
function getLocalModuleSpecifier(moduleFileName: string, info: Info, compilerOptions: CompilerOptions, host: ModuleSpecifierResolutionHost, { ending, relativePreference }: Preferences): string {
182182
const { baseUrl, paths, rootDirs } = compilerOptions;
183183
const { sourceDirectory, getCanonicalFileName } = info;
184-
185184
const relativePath = rootDirs && tryGetModuleNameFromRootDirs(rootDirs, moduleFileName, sourceDirectory, getCanonicalFileName, ending, compilerOptions) ||
186185
removeExtensionAndIndexPostFix(ensurePathIsNonModuleName(getRelativePathFromDirectory(sourceDirectory, moduleFileName, getCanonicalFileName)), ending, compilerOptions);
187186
if (!baseUrl && !paths || relativePreference === RelativePreference.Relative) {
188187
return relativePath;
189188
}
190189

191-
const baseDirectory = getPathsBasePath(compilerOptions, host) || baseUrl!;
190+
const baseDirectory = getNormalizedAbsolutePath(getPathsBasePath(compilerOptions, host) || baseUrl!, host.getCurrentDirectory());
192191
const relativeToBaseUrl = getRelativePathIfInDirectory(moduleFileName, baseDirectory, getCanonicalFileName);
193192
if (!relativeToBaseUrl) {
194193
return relativePath;

src/compiler/transformers/declarations.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,7 @@ namespace ts {
372372

373373
if (declFileName) {
374374
const specifier = moduleSpecifiers.getModuleSpecifier(
375-
// We pathify the baseUrl since we pathify the other paths here, so we can still easily check if the other paths are within the baseUrl
376-
// TODO: Should we _always_ be pathifying the baseUrl as we read it in?
377-
{ ...options, baseUrl: options.baseUrl && toPath(options.baseUrl, host.getCurrentDirectory(), host.getCanonicalFileName) },
375+
options,
378376
currentSourceFile,
379377
toPath(outputFilePath, host.getCurrentDirectory(), host.getCanonicalFileName),
380378
toPath(declFileName, host.getCurrentDirectory(), host.getCanonicalFileName),

tests/baselines/reference/declarationEmitPathMappingMonorepo2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ exports["default"] = (0, utils_1.createSvgIcon)("Hello", "ArrowLeft");
3737

3838

3939
//// [index.d.ts]
40-
declare const _default: import("../../core/src/SvgIcon").SomeInterface;
40+
declare const _default: import("@ts-bug/core/SvgIcon").SomeInterface;
4141
export default _default;

0 commit comments

Comments
 (0)