Skip to content

Commit 2648f6a

Browse files
authoredOct 6, 2022
Plugins in project were adding up after every config file reload (#51087)
* Add test where current plugins dont get reset when reloading config file * Reset loaded plugins when reloading configured project and closing project
1 parent c18791c commit 2648f6a

File tree

4 files changed

+244
-2
lines changed

4 files changed

+244
-2
lines changed
 

‎src/server/project.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ namespace ts.server {
143143
private missingFilesMap: ESMap<Path, FileWatcher> | undefined;
144144
private generatedFilesMap: GeneratedFileWatcherMap | undefined;
145145

146-
private plugins: PluginModuleWithName[] = [];
146+
/*@internal*/
147+
protected readonly plugins: PluginModuleWithName[] = [];
147148

148149
/*@internal*/
149150
/**
@@ -845,6 +846,7 @@ namespace ts.server {
845846
this.directoryStructureHost = undefined!;
846847
this.exportMapCache = undefined;
847848
this.projectErrors = undefined;
849+
this.plugins.length = 0;
848850

849851
// Clean up file watchers waiting for missing files
850852
if (this.missingFilesMap) {
@@ -2520,6 +2522,7 @@ namespace ts.server {
25202522

25212523
/*@internal*/
25222524
enablePluginsWithOptions(options: CompilerOptions, pluginConfigOverrides: ESMap<string, any> | undefined): void {
2525+
this.plugins.length = 0;
25232526
if (!options.plugins?.length && !this.projectService.globalPlugins.length) return;
25242527
const host = this.projectService.host;
25252528
if (!host.require && !host.importPlugin) {

‎src/testRunner/unittests/tsserver/plugins.ts

+45
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,50 @@ namespace ts.projectSystem {
100100
};
101101
assert.deepEqual(resp, expectedResp);
102102
});
103+
104+
it("gets external files with config file reload", () => {
105+
const aTs: File = { path: `${tscWatch.projectRoot}/a.ts`, content: `export const x = 10;` };
106+
const tsconfig: File = {
107+
path: `${tscWatch.projectRoot}/tsconfig.json`,
108+
content: JSON.stringify({
109+
compilerOptions: {
110+
plugins: [{ name: "some-plugin" }]
111+
}
112+
})
113+
};
114+
115+
const externalFiles: MapLike<string[]> = {
116+
"some-plugin": ["someFile.txt"],
117+
"some-other-plugin": ["someOtherFile.txt"],
118+
};
119+
120+
const host = createServerHost([aTs, tsconfig, libFile]);
121+
host.require = (_initialPath, moduleName) => {
122+
session.logger.logs.push(`Require:: ${moduleName}`);
123+
return {
124+
module: (): server.PluginModule => {
125+
session.logger.logs.push(`PluginFactory Invoke`);
126+
return {
127+
create: Harness.LanguageService.makeDefaultProxy,
128+
getExternalFiles: () => externalFiles[moduleName]
129+
};
130+
},
131+
error: undefined
132+
};
133+
};
134+
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
135+
openFilesForSession([aTs], session);
136+
session.logger.logs.push(`ExternalFiles:: ${JSON.stringify(session.getProjectService().configuredProjects.get(tsconfig.path)!.getExternalFiles())}`);
137+
138+
host.writeFile(tsconfig.path, JSON.stringify({
139+
compilerOptions: {
140+
plugins: [{ name: "some-other-plugin" }]
141+
}
142+
}));
143+
host.runQueuedTimeoutCallbacks();
144+
session.logger.logs.push(`ExternalFiles:: ${JSON.stringify(session.getProjectService().configuredProjects.get(tsconfig.path)!.getExternalFiles())}`);
145+
146+
baselineTsserverLogs("plugins", "gets external files with config file reload", session);
147+
});
103148
});
104149
}

‎tests/baselines/reference/api/tsserverlibrary.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -10084,7 +10084,6 @@ declare namespace ts.server {
1008410084
private externalFiles;
1008510085
private missingFilesMap;
1008610086
private generatedFilesMap;
10087-
private plugins;
1008810087
protected languageService: LanguageService;
1008910088
languageServiceEnabled: boolean;
1009010089
readonly trace?: (s: string) => void;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
Info 0 [00:00:21.000] Provided types map file "/a/lib/typesMap.json" doesn't exist
2+
Info 1 [00:00:22.000] request:
3+
{
4+
"seq": 0,
5+
"type": "request",
6+
"command": "open",
7+
"arguments": {
8+
"file": "/user/username/projects/myproject/a.ts"
9+
}
10+
}
11+
Before request
12+
//// [/user/username/projects/myproject/a.ts]
13+
export const x = 10;
14+
15+
//// [/user/username/projects/myproject/tsconfig.json]
16+
{"compilerOptions":{"plugins":[{"name":"some-plugin"}]}}
17+
18+
//// [/a/lib/lib.d.ts]
19+
/// <reference no-default-lib="true"/>
20+
interface Boolean {}
21+
interface Function {}
22+
interface CallableFunction {}
23+
interface NewableFunction {}
24+
interface IArguments {}
25+
interface Number { toExponential: any; }
26+
interface Object {}
27+
interface RegExp {}
28+
interface String { charAt: any; }
29+
interface Array<T> { length: number; [n: number]: T; }
30+
31+
32+
PolledWatches::
33+
34+
FsWatches::
35+
36+
FsWatchesRecursive::
37+
38+
Info 2 [00:00:23.000] Search path: /user/username/projects/myproject
39+
Info 3 [00:00:24.000] For info: /user/username/projects/myproject/a.ts :: Config file name: /user/username/projects/myproject/tsconfig.json
40+
Info 4 [00:00:25.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
41+
Info 5 [00:00:26.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 undefined Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
42+
Info 6 [00:00:27.000] Config: /user/username/projects/myproject/tsconfig.json : {
43+
"rootNames": [
44+
"/user/username/projects/myproject/a.ts"
45+
],
46+
"options": {
47+
"plugins": [
48+
{
49+
"name": "some-plugin"
50+
}
51+
],
52+
"configFilePath": "/user/username/projects/myproject/tsconfig.json"
53+
}
54+
}
55+
Info 7 [00:00:28.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 undefined Config: /user/username/projects/myproject/tsconfig.json WatchType: Wild card directory
56+
Info 8 [00:00:29.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 undefined Config: /user/username/projects/myproject/tsconfig.json WatchType: Wild card directory
57+
Info 9 [00:00:30.000] Enabling plugin some-plugin from candidate paths: /a/lib/tsc.js/../../..
58+
Info 10 [00:00:31.000] Loading some-plugin from /a/lib/tsc.js/../../.. (resolved to /a/lib/tsc.js/../../../node_modules)
59+
Require:: some-plugin
60+
PluginFactory Invoke
61+
Info 11 [00:00:32.000] Plugin validation succeeded
62+
Info 12 [00:00:33.000] Starting updateGraphWorker: Project: /user/username/projects/myproject/tsconfig.json
63+
Info 13 [00:00:34.000] FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 500 undefined WatchType: Closed Script info
64+
Info 14 [00:00:35.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/somefile.txt 500 undefined Project: /user/username/projects/myproject/tsconfig.json WatchType: Missing file
65+
Info 15 [00:00:36.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules/@types 1 undefined Project: /user/username/projects/myproject/tsconfig.json WatchType: Type roots
66+
Info 16 [00:00:37.000] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules/@types 1 undefined Project: /user/username/projects/myproject/tsconfig.json WatchType: Type roots
67+
Info 17 [00:00:38.000] Finishing updateGraphWorker: Project: /user/username/projects/myproject/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms
68+
Info 18 [00:00:39.000] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
69+
Info 19 [00:00:40.000] Files (2)
70+
/a/lib/lib.d.ts
71+
/user/username/projects/myproject/a.ts
72+
73+
74+
../../../../a/lib/lib.d.ts
75+
Default library for target 'es3'
76+
a.ts
77+
Matched by default include pattern '**/*'
78+
79+
Info 20 [00:00:41.000] -----------------------------------------------
80+
Info 21 [00:00:42.000] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
81+
Info 21 [00:00:43.000] Files (2)
82+
83+
Info 21 [00:00:44.000] -----------------------------------------------
84+
Info 21 [00:00:45.000] Open files:
85+
Info 21 [00:00:46.000] FileName: /user/username/projects/myproject/a.ts ProjectRootPath: undefined
86+
Info 21 [00:00:47.000] Projects: /user/username/projects/myproject/tsconfig.json
87+
After request
88+
89+
PolledWatches::
90+
/user/username/projects/myproject/somefile.txt:
91+
{"pollingInterval":500}
92+
/user/username/projects/myproject/node_modules/@types:
93+
{"pollingInterval":500}
94+
95+
FsWatches::
96+
/user/username/projects/myproject/tsconfig.json:
97+
{}
98+
/a/lib/lib.d.ts:
99+
{}
100+
101+
FsWatchesRecursive::
102+
/user/username/projects/myproject:
103+
{}
104+
105+
Info 21 [00:00:48.000] response:
106+
{
107+
"responseRequired": false
108+
}
109+
ExternalFiles:: ["someFile.txt"]
110+
Info 22 [00:00:52.000] FileWatcher:: Triggered with /user/username/projects/myproject/tsconfig.json 1:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 undefined Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
111+
Info 23 [00:00:53.000] Scheduled: /user/username/projects/myproject/tsconfig.json
112+
Info 24 [00:00:54.000] Scheduled: *ensureProjectForOpenFiles*
113+
Info 25 [00:00:55.000] Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/tsconfig.json 1:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 undefined Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
114+
Before running timeout callbacks
115+
//// [/user/username/projects/myproject/tsconfig.json]
116+
{"compilerOptions":{"plugins":[{"name":"some-other-plugin"}]}}
117+
118+
119+
PolledWatches::
120+
/user/username/projects/myproject/somefile.txt:
121+
{"pollingInterval":500}
122+
/user/username/projects/myproject/node_modules/@types:
123+
{"pollingInterval":500}
124+
125+
FsWatches::
126+
/user/username/projects/myproject/tsconfig.json:
127+
{}
128+
/a/lib/lib.d.ts:
129+
{}
130+
131+
FsWatchesRecursive::
132+
/user/username/projects/myproject:
133+
{}
134+
135+
Info 26 [00:00:56.000] Running: /user/username/projects/myproject/tsconfig.json
136+
Info 27 [00:00:57.000] Reloading configured project /user/username/projects/myproject/tsconfig.json
137+
Info 28 [00:00:58.000] Config: /user/username/projects/myproject/tsconfig.json : {
138+
"rootNames": [
139+
"/user/username/projects/myproject/a.ts"
140+
],
141+
"options": {
142+
"plugins": [
143+
{
144+
"name": "some-other-plugin"
145+
}
146+
],
147+
"configFilePath": "/user/username/projects/myproject/tsconfig.json"
148+
}
149+
}
150+
Info 29 [00:00:59.000] Enabling plugin some-other-plugin from candidate paths: /a/lib/tsc.js/../../..
151+
Info 30 [00:01:00.000] Loading some-other-plugin from /a/lib/tsc.js/../../.. (resolved to /a/lib/tsc.js/../../../node_modules)
152+
Require:: some-other-plugin
153+
PluginFactory Invoke
154+
Info 31 [00:01:01.000] Plugin validation succeeded
155+
Info 32 [00:01:02.000] Starting updateGraphWorker: Project: /user/username/projects/myproject/tsconfig.json
156+
Info 33 [00:01:03.000] FileWatcher:: Close:: WatchInfo: /user/username/projects/myproject/somefile.txt 500 undefined Project: /user/username/projects/myproject/tsconfig.json WatchType: Missing file
157+
Info 34 [00:01:04.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/someotherfile.txt 500 undefined Project: /user/username/projects/myproject/tsconfig.json WatchType: Missing file
158+
Info 35 [00:01:05.000] Finishing updateGraphWorker: Project: /user/username/projects/myproject/tsconfig.json Version: 2 structureChanged: true structureIsReused:: Not Elapsed:: *ms
159+
Info 36 [00:01:06.000] Different program with same set of files
160+
Info 37 [00:01:07.000] Running: *ensureProjectForOpenFiles*
161+
Info 38 [00:01:08.000] Before ensureProjectForOpenFiles:
162+
Info 39 [00:01:09.000] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
163+
Info 39 [00:01:10.000] Files (2)
164+
165+
Info 39 [00:01:11.000] -----------------------------------------------
166+
Info 39 [00:01:12.000] Open files:
167+
Info 39 [00:01:13.000] FileName: /user/username/projects/myproject/a.ts ProjectRootPath: undefined
168+
Info 39 [00:01:14.000] Projects: /user/username/projects/myproject/tsconfig.json
169+
Info 39 [00:01:15.000] After ensureProjectForOpenFiles:
170+
Info 40 [00:01:16.000] Project '/user/username/projects/myproject/tsconfig.json' (Configured)
171+
Info 40 [00:01:17.000] Files (2)
172+
173+
Info 40 [00:01:18.000] -----------------------------------------------
174+
Info 40 [00:01:19.000] Open files:
175+
Info 40 [00:01:20.000] FileName: /user/username/projects/myproject/a.ts ProjectRootPath: undefined
176+
Info 40 [00:01:21.000] Projects: /user/username/projects/myproject/tsconfig.json
177+
After running timeout callbacks
178+
179+
PolledWatches::
180+
/user/username/projects/myproject/node_modules/@types:
181+
{"pollingInterval":500}
182+
/user/username/projects/myproject/someotherfile.txt:
183+
{"pollingInterval":500}
184+
185+
FsWatches::
186+
/user/username/projects/myproject/tsconfig.json:
187+
{}
188+
/a/lib/lib.d.ts:
189+
{}
190+
191+
FsWatchesRecursive::
192+
/user/username/projects/myproject:
193+
{}
194+
195+
ExternalFiles:: ["someOtherFile.txt"]

0 commit comments

Comments
 (0)
Please sign in to comment.