Skip to content

Commit 4806908

Browse files
committed
Centralize access to the 'current' ts namespace object
1 parent 08285ab commit 4806908

File tree

8 files changed

+36
-1
lines changed

8 files changed

+36
-1
lines changed

src/compiler/_namespaces/ts.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* Generated file to emulate the ts namespace. */
22

33
export * from "../corePublic";
4+
export * from "../pluginUtilities";
45
export * from "../core";
56
export * from "../debug";
67
export * from "../semver";

src/compiler/pluginUtilities.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** @internal */
2+
export type Entrypoint = "tsc" | "typescript" | "tsserver" | "tsserverlibrary" | "testRunner";
3+
4+
let currentEntrypoint: Entrypoint | undefined;
5+
let currentTsNamespace: any;
6+
7+
/** @internal */
8+
export function setTypeScriptNamespace(entrypoint: Entrypoint, ts: any) {
9+
if (currentEntrypoint !== undefined) throw new Error("ts namespace already set");
10+
currentEntrypoint = entrypoint;
11+
currentTsNamespace = ts;
12+
}
13+
14+
/** @internal */
15+
export function getTypeScriptNamespace(): any {
16+
if (currentTsNamespace === undefined) throw new Error("ts namespace unset");
17+
return currentTsNamespace;
18+
}

src/server/project.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import {
6161
getNormalizedAbsolutePath,
6262
getOrUpdate,
6363
getStringComparer,
64+
getTypeScriptNamespace,
6465
HasInvalidatedLibResolutions,
6566
HasInvalidatedResolutions,
6667
HostCancellationToken,
@@ -2000,7 +2001,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
20002001
session: this.projectService.session
20012002
};
20022003

2003-
const pluginModule = pluginModuleFactory({ typescript: ts });
2004+
const pluginModule = pluginModuleFactory({ typescript: getTypeScriptNamespace() });
20042005
const newLS = pluginModule.create(info);
20052006
for (const k of Object.keys(this.languageService)) {
20062007
// eslint-disable-next-line local/no-in-operator

src/testRunner/_namespaces/ts.ts

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ export * from "../../harness/_namespaces/ts";
1111
export * from "../../loggedIO/_namespaces/ts";
1212
import * as server from "./ts.server";
1313
export { server };
14+
15+
import * as ts from "./ts";
16+
ts.setTypeScriptNamespace("testRunner", ts);

src/tsc/_namespaces/ts.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
export * from "../../compiler/_namespaces/ts";
44
export * from "../../executeCommandLine/_namespaces/ts";
5+
6+
import * as ts from "./ts";
7+
ts.setTypeScriptNamespace("tsc", ts);

src/tsserver/_namespaces/ts.ts

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ export * from "../../jsTyping/_namespaces/ts";
66
export * from "../../server/_namespaces/ts";
77
import * as server from "./ts.server";
88
export { server };
9+
10+
import * as ts from "./ts";
11+
ts.setTypeScriptNamespace("tsserver", ts);

src/tsserverlibrary/_namespaces/ts.ts

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ export * from "../../services/_namespaces/ts";
66
export * from "../../server/_namespaces/ts";
77
import * as server from "./ts.server";
88
export { server };
9+
10+
import * as ts from "./ts";
11+
ts.setTypeScriptNamespace("tsserverlibrary", ts);

src/typescript/_namespaces/ts.ts

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ export * from "../../compiler/_namespaces/ts";
44
export * from "../../jsTyping/_namespaces/ts";
55
export * from "../../services/_namespaces/ts";
66
export * from "../../deprecatedCompat/_namespaces/ts";
7+
8+
import * as ts from "./ts";
9+
ts.setTypeScriptNamespace("typescript", ts);

0 commit comments

Comments
 (0)