Skip to content

Commit 6a5527e

Browse files
authored
Properly compare path prefixes when generating module paths (#40885)
2 parents 477e4b1 + e9465c5 commit 6a5527e

File tree

5 files changed

+150
-2
lines changed

5 files changed

+150
-2
lines changed

src/compiler/moduleSpecifiers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,15 @@ namespace ts.moduleSpecifiers {
235235
: discoverProbableSymlinks(host.getSourceFiles(), getCanonicalFileName, cwd);
236236

237237
const symlinkedDirectories = links.getSymlinkedDirectories();
238-
const compareStrings = (!host.useCaseSensitiveFileNames || host.useCaseSensitiveFileNames()) ? compareStringsCaseSensitive : compareStringsCaseInsensitive;
238+
const useCaseSensitiveFileNames = !host.useCaseSensitiveFileNames || host.useCaseSensitiveFileNames();
239239
const result = symlinkedDirectories && forEachEntry(symlinkedDirectories, (resolved, path) => {
240240
if (resolved === false) return undefined;
241241
if (startsWithDirectory(importingFileName, resolved.realPath, getCanonicalFileName)) {
242242
return undefined; // Don't want to a package to globally import from itself
243243
}
244244

245245
return forEach(targets, target => {
246-
if (compareStrings(target.slice(0, resolved.real.length), resolved.real) !== Comparison.EqualTo) {
246+
if (!containsPath(resolved.real, target, !useCaseSensitiveFileNames)) {
247247
return;
248248
}
249249

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//// [tests/cases/compiler/declarationEmitSymlinkPaths.ts] ////
2+
3+
//// [package.json]
4+
{
5+
"name": "search",
6+
"version": "0.0.1",
7+
"main": "lib/index.js",
8+
"types": "lib/index.d.ts",
9+
"sideEffects": false
10+
}
11+
//// [index.d.ts]
12+
export declare function test<T> (a: () => T): () => T;
13+
//// [NotificationAPIUtils.ts]
14+
export type NotificationRequest = {};
15+
export type NotificationResponse = {};
16+
export function getNotification(): NotificationResponse {
17+
return {};
18+
}
19+
//// [NotificationStore.ts]
20+
import { test } from "search/lib/index";
21+
import { getNotification } from "../API/NotificationAPIUtils";
22+
23+
export const NotificationScenario = test(
24+
getNotification
25+
);
26+
27+
//// [NotificationAPIUtils.js]
28+
"use strict";
29+
Object.defineProperty(exports, "__esModule", { value: true });
30+
exports.getNotification = void 0;
31+
function getNotification() {
32+
return {};
33+
}
34+
exports.getNotification = getNotification;
35+
//// [NotificationStore.js]
36+
"use strict";
37+
Object.defineProperty(exports, "__esModule", { value: true });
38+
exports.NotificationScenario = void 0;
39+
var index_1 = require("search/lib/index");
40+
var NotificationAPIUtils_1 = require("../API/NotificationAPIUtils");
41+
exports.NotificationScenario = index_1.test(NotificationAPIUtils_1.getNotification);
42+
43+
44+
//// [NotificationAPIUtils.d.ts]
45+
export declare type NotificationRequest = {};
46+
export declare type NotificationResponse = {};
47+
export declare function getNotification(): NotificationResponse;
48+
//// [NotificationStore.d.ts]
49+
export declare const NotificationScenario: () => import("../API/NotificationAPIUtils").NotificationResponse;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
=== /packages/search/lib/index.d.ts ===
2+
export declare function test<T> (a: () => T): () => T;
3+
>test : Symbol(test, Decl(index.d.ts, 0, 0))
4+
>T : Symbol(T, Decl(index.d.ts, 0, 29))
5+
>a : Symbol(a, Decl(index.d.ts, 0, 33))
6+
>T : Symbol(T, Decl(index.d.ts, 0, 29))
7+
>T : Symbol(T, Decl(index.d.ts, 0, 29))
8+
9+
=== /packages/search-prefix/src/API/NotificationAPIUtils.ts ===
10+
export type NotificationRequest = {};
11+
>NotificationRequest : Symbol(NotificationRequest, Decl(NotificationAPIUtils.ts, 0, 0))
12+
13+
export type NotificationResponse = {};
14+
>NotificationResponse : Symbol(NotificationResponse, Decl(NotificationAPIUtils.ts, 0, 37))
15+
16+
export function getNotification(): NotificationResponse {
17+
>getNotification : Symbol(getNotification, Decl(NotificationAPIUtils.ts, 1, 38))
18+
>NotificationResponse : Symbol(NotificationResponse, Decl(NotificationAPIUtils.ts, 0, 37))
19+
20+
return {};
21+
}
22+
=== /packages/search-prefix/src/Store/NotificationStore.ts ===
23+
import { test } from "search/lib/index";
24+
>test : Symbol(test, Decl(NotificationStore.ts, 0, 8))
25+
26+
import { getNotification } from "../API/NotificationAPIUtils";
27+
>getNotification : Symbol(getNotification, Decl(NotificationStore.ts, 1, 8))
28+
29+
export const NotificationScenario = test(
30+
>NotificationScenario : Symbol(NotificationScenario, Decl(NotificationStore.ts, 3, 12))
31+
>test : Symbol(test, Decl(NotificationStore.ts, 0, 8))
32+
33+
getNotification
34+
>getNotification : Symbol(getNotification, Decl(NotificationStore.ts, 1, 8))
35+
36+
);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
=== /packages/search/lib/index.d.ts ===
2+
export declare function test<T> (a: () => T): () => T;
3+
>test : <T>(a: () => T) => () => T
4+
>a : () => T
5+
6+
=== /packages/search-prefix/src/API/NotificationAPIUtils.ts ===
7+
export type NotificationRequest = {};
8+
>NotificationRequest : NotificationRequest
9+
10+
export type NotificationResponse = {};
11+
>NotificationResponse : NotificationResponse
12+
13+
export function getNotification(): NotificationResponse {
14+
>getNotification : () => NotificationResponse
15+
16+
return {};
17+
>{} : {}
18+
}
19+
=== /packages/search-prefix/src/Store/NotificationStore.ts ===
20+
import { test } from "search/lib/index";
21+
>test : <T>(a: () => T) => () => T
22+
23+
import { getNotification } from "../API/NotificationAPIUtils";
24+
>getNotification : () => import("/packages/search-prefix/src/API/NotificationAPIUtils").NotificationResponse
25+
26+
export const NotificationScenario = test(
27+
>NotificationScenario : () => import("/packages/search-prefix/src/API/NotificationAPIUtils").NotificationResponse
28+
>test( getNotification) : () => import("/packages/search-prefix/src/API/NotificationAPIUtils").NotificationResponse
29+
>test : <T>(a: () => T) => () => T
30+
31+
getNotification
32+
>getNotification : () => import("/packages/search-prefix/src/API/NotificationAPIUtils").NotificationResponse
33+
34+
);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// @declaration: true
2+
// @outDir: /packages/search-prefix/lib
3+
// @rootDir: /packages/search-prefix/src
4+
// @target: es5
5+
// @filename: /packages/search/package.json
6+
{
7+
"name": "search",
8+
"version": "0.0.1",
9+
"main": "lib/index.js",
10+
"types": "lib/index.d.ts",
11+
"sideEffects": false
12+
}
13+
// @filename: /packages/search/lib/index.d.ts
14+
export declare function test<T> (a: () => T): () => T;
15+
// @filename: /packages/search-prefix/src/API/NotificationAPIUtils.ts
16+
export type NotificationRequest = {};
17+
export type NotificationResponse = {};
18+
export function getNotification(): NotificationResponse {
19+
return {};
20+
}
21+
// @filename: /packages/search-prefix/src/Store/NotificationStore.ts
22+
import { test } from "search/lib/index";
23+
import { getNotification } from "../API/NotificationAPIUtils";
24+
25+
export const NotificationScenario = test(
26+
getNotification
27+
);
28+
// @link: /packages/search -> /node_modules/search
29+
// @link: /packages/search-prefix -> /node_modules/search-prefix

0 commit comments

Comments
 (0)