Skip to content

Commit d49a285

Browse files
authored
Use custom conditions in path completions (microsoft#54332)
1 parent b03926e commit d49a285

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

src/services/stringCompletions.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
flatten,
4545
forEachAncestorDirectory,
4646
getBaseFileName,
47+
getConditions,
4748
getContextualTypeFromParent,
4849
getDirectoryPath,
4950
getEffectiveTypeRoots,
@@ -924,7 +925,7 @@ function getCompletionEntriesForNonRelativeModules(
924925
}
925926
const keys = getOwnKeys(exports);
926927
const fragmentSubpath = components.join("/") + (components.length && hasTrailingDirectorySeparator(fragment) ? "/" : "");
927-
const conditions = mode === ModuleKind.ESNext ? ["node", "import", "types"] : ["node", "require", "types"];
928+
const conditions = getConditions(compilerOptions, mode === ModuleKind.ESNext);
928929
addCompletionEntriesFromPathsOrExports(
929930
result,
930931
fragmentSubpath,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @moduleResolution: bundler
4+
5+
// @Filename: /node_modules/foo/package.json
6+
//// {
7+
//// "name": "foo",
8+
//// "exports": {
9+
//// "./only-for-node": {
10+
//// "node": "./something.js"
11+
//// },
12+
//// "./for-everywhere": "./other.js",
13+
//// }
14+
//// }
15+
16+
// @Filename: /node_modules/foo/something.d.ts
17+
//// export const index = 0;
18+
19+
// @Filename: /node_modules/foo/other.d.ts
20+
//// export const index = 0;
21+
22+
// @Filename: /index.ts
23+
//// import { } from "foo//**/";
24+
25+
verify.completions({
26+
marker: "",
27+
isNewIdentifierLocation: true,
28+
exact: [
29+
{ name: "for-everywhere", kind: "script", kindModifiers: "" },
30+
]
31+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @module: nodenext
4+
// @customConditions: custom-condition
5+
6+
// @Filename: /node_modules/foo/package.json
7+
//// {
8+
//// "name": "foo",
9+
//// "exports": {
10+
//// "./only-with-custom-conditions": {
11+
//// "custom-condition": "./something.js"
12+
//// },
13+
//// }
14+
//// }
15+
16+
// @Filename: /node_modules/foo/something.d.ts
17+
//// export const index = 0;
18+
19+
// @Filename: /index.ts
20+
//// import { } from "foo//**/";
21+
22+
verify.completions({
23+
marker: "",
24+
isNewIdentifierLocation: true,
25+
exact: [
26+
{ name: "only-with-custom-conditions", kind: "script", kindModifiers: "" },
27+
]
28+
});

0 commit comments

Comments
 (0)