Skip to content

Commit 2e5534d

Browse files
committed
Add plugin override for watchFactory
1 parent 83822a3 commit 2e5534d

16 files changed

+39
-28
lines changed

src/compiler/sys.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ namespace ts {
953953
];
954954
sysLog(`Enabling watchFactory ${isString(options.watchFactory) ? options.watchFactory : JSON.stringify(options.watchFactory)} from candidate paths: ${searchPaths.join(",")}`);
955955
const { resolvedModule, errorLogs, pluginConfigEntry } = resolveModule<UserWatchFactoryModule>(
956-
isString(options.watchFactory) ? { name: options.watchFactory } : options.watchFactory,
956+
getWatchFactoryPlugin(options),
957957
searchPaths,
958958
getSystem(),
959959
sysLog
@@ -971,6 +971,11 @@ namespace ts {
971971
return setUserWatchFactory(options, /*userWatchFactory*/ undefined);
972972
}
973973

974+
function getWatchFactoryPlugin(options: WatchOptions) {
975+
const plugin = isString(options.watchFactory) ? { name: options.watchFactory } : options.watchFactory!;
976+
return options.getHost?.().getPluginWithConfigOverride(plugin) || plugin;
977+
}
978+
974979
function setUserWatchFactory(options: WatchOptions, userWatchFactory: UserWatchFactory | undefined) {
975980
setWatchOptionInternalProperty(options, "getResolvedWatchFactory", userWatchFactory ? () => userWatchFactory : returnUndefined);
976981
return userWatchFactory;

src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6682,6 +6682,7 @@ namespace ts {
66826682
/*@internal*/
66836683
export interface WatchOptionsFactoryHost {
66846684
searchPaths: readonly string[];
6685+
getPluginWithConfigOverride(plugin: PluginImport): PluginImport;
66856686
}
66866687
export interface WatchOptions {
66876688
watchFile?: WatchFileKind;

src/server/editorServices.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ namespace ts.server {
779779
public readonly pluginProbeLocations: readonly string[];
780780
public readonly allowLocalPluginLoads: boolean;
781781
/*@internal*/
782-
currentPluginConfigOverrides: ESMap<string, any> | undefined;
782+
private currentPluginConfigOverrides: ESMap<string, any> | undefined;
783783

784784
public readonly typesMapLocation: string | undefined;
785785

@@ -3082,7 +3082,8 @@ namespace ts.server {
30823082
/*@internal*/
30833083
private setWatchOptionsFactoryHost(options: WatchOptions, canonicalConfigFilePath: NormalizedPath | undefined) {
30843084
setWatchOptionInternalProperty(options, "getHost", memoize(() => ({
3085-
searchPaths: this.getProjectPluginSearchPaths(canonicalConfigFilePath)
3085+
searchPaths: this.getProjectPluginSearchPaths(canonicalConfigFilePath),
3086+
getPluginWithConfigOverride: plugin => this.getPluginWithConfigOverride(plugin),
30863087
})));
30873088
}
30883089

@@ -4129,6 +4130,18 @@ namespace ts.server {
41294130
return searchPaths;
41304131
}
41314132

4133+
/*@internal*/
4134+
getPluginWithConfigOverride(pluginConfigEntry: PluginImport) {
4135+
const configurationOverride = this.currentPluginConfigOverrides?.get(pluginConfigEntry.name);
4136+
if (configurationOverride) {
4137+
// Preserve the name property since it's immutable
4138+
const pluginName = pluginConfigEntry.name;
4139+
pluginConfigEntry = configurationOverride;
4140+
pluginConfigEntry.name = pluginName;
4141+
}
4142+
return pluginConfigEntry;
4143+
}
4144+
41324145
/*@internal*/
41334146
requestEnablePlugin(project: Project, pluginConfigEntry: PluginImport, searchPaths: string[]) {
41344147
if (!this.host.importPlugin && !this.host.require) {

src/server/project.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -1639,15 +1639,7 @@ namespace ts.server {
16391639
/*@internal*/
16401640
endEnablePlugin({ pluginConfigEntry, resolvedModule, errorLogs }: BeginEnablePluginResult) {
16411641
if (resolvedModule) {
1642-
const configurationOverride = this.projectService.currentPluginConfigOverrides?.get(pluginConfigEntry.name);
1643-
if (configurationOverride) {
1644-
// Preserve the name property since it's immutable
1645-
const pluginName = pluginConfigEntry.name;
1646-
pluginConfigEntry = configurationOverride;
1647-
pluginConfigEntry.name = pluginName;
1648-
}
1649-
1650-
this.enableProxy(resolvedModule, pluginConfigEntry);
1642+
this.enableProxy(resolvedModule, this.projectService.getPluginWithConfigOverride(pluginConfigEntry));
16511643
}
16521644
else {
16531645
forEach(errorLogs, message => this.projectService.logger.info(message));

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-as-configuration-of-host-with-pluginOverride-allowLocalPluginLoads-object.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Info 10 [00:00:33.000] For info: /user/username/projects/myproject/a.ts :: Con
139139
Info 11 [00:00:34.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
140140
Info 12 [00:00:35.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
141141
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
142-
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
142+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
143143
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
144144
Info 13 [00:00:36.000] Config: /user/username/projects/myproject/tsconfig.json : {
145145
"rootNames": [

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-as-configuration-of-host-with-pluginOverride-object.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Info 10 [00:00:33.000] For info: /user/username/projects/myproject/a.ts :: Con
139139
Info 11 [00:00:34.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
140140
Info 12 [00:00:35.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
141141
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
142-
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
142+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
143143
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
144144
Info 13 [00:00:36.000] Config: /user/username/projects/myproject/tsconfig.json : {
145145
"rootNames": [

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-as-configuration-of-host-with-pluginoverride-allowLocalPluginLoads.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Info 10 [00:00:33.000] For info: /user/username/projects/myproject/a.ts :: Con
136136
Info 11 [00:00:34.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
137137
Info 12 [00:00:35.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
138138
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
139-
Require:: Module myplugin created with config: {"name":"myplugin"} and options: {"watchFactory":"myplugin"}
139+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":"myplugin"}
140140
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"}
141141
Info 13 [00:00:36.000] Config: /user/username/projects/myproject/tsconfig.json : {
142142
"rootNames": [

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-as-configuration-of-host-with-pluginoverride.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Info 10 [00:00:33.000] For info: /user/username/projects/myproject/a.ts :: Con
136136
Info 11 [00:00:34.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
137137
Info 12 [00:00:35.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
138138
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
139-
Require:: Module myplugin created with config: {"name":"myplugin"} and options: {"watchFactory":"myplugin"}
139+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":"myplugin"}
140140
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"}
141141
Info 13 [00:00:36.000] Config: /user/username/projects/myproject/tsconfig.json : {
142142
"rootNames": [

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-in-config-as-well-as-configuration-of-host-with-pluginOverride-allowLocalPluginLoads-object.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Info 13 [00:00:36.000] For info: /user/username/projects/myproject/a.ts :: Con
218218
Info 14 [00:00:37.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
219219
Info 15 [00:00:38.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
220220
CustomRequire:: Resolving myplugin2 from /a/pluginprobe1/node_modules
221-
Require:: Module myplugin2 created with config: {"name":"myplugin2","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
221+
Require:: Module myplugin2 created with config: {"init2":"initialConfig2","name":"myplugin2"} and options: {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
222222
Custom myplugin2watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
223223
Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json : {
224224
"rootNames": [
@@ -239,7 +239,7 @@ Info 17 [00:00:40.000] FileWatcher:: Close:: WatchInfo: /user/username/project
239239
Info 18 [00:00:41.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
240240
Info 19 [00:00:42.000] Local plugin loading enabled; adding /user/username/projects/myproject to search paths
241241
CustomRequire:: Resolving myplugin from /user/username/projects/myproject/node_modules
242-
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
242+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
243243
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
244244
Info 20 [00:00:43.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Config: /user/username/projects/myproject/tsconfig.json WatchType: Wild card directory
245245
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-in-config-as-well-as-configuration-of-host-with-pluginOverride-object.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Info 13 [00:00:36.000] For info: /user/username/projects/myproject/a.ts :: Con
218218
Info 14 [00:00:37.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
219219
Info 15 [00:00:38.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
220220
CustomRequire:: Resolving myplugin2 from /a/pluginprobe1/node_modules
221-
Require:: Module myplugin2 created with config: {"name":"myplugin2","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
221+
Require:: Module myplugin2 created with config: {"init2":"initialConfig2","name":"myplugin2"} and options: {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
222222
Custom myplugin2watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
223223
Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json : {
224224
"rootNames": [
@@ -238,7 +238,7 @@ Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json
238238
Info 17 [00:00:40.000] FileWatcher:: Close:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
239239
Info 18 [00:00:41.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
240240
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
241-
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
241+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
242242
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
243243
Info 19 [00:00:42.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Config: /user/username/projects/myproject/tsconfig.json WatchType: Wild card directory
244244
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-in-config-as-well-as-configuration-of-host-with-pluginoverride-allowLocalPluginLoads.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Info 13 [00:00:36.000] For info: /user/username/projects/myproject/a.ts :: Con
215215
Info 14 [00:00:37.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
216216
Info 15 [00:00:38.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin2"} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
217217
CustomRequire:: Resolving myplugin2 from /a/pluginprobe1/node_modules
218-
Require:: Module myplugin2 created with config: {"name":"myplugin2"} and options: {"watchFactory":"myplugin2"}
218+
Require:: Module myplugin2 created with config: {"init2":"initialConfig2","name":"myplugin2"} and options: {"watchFactory":"myplugin2"}
219219
Custom myplugin2watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin2"}
220220
Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json : {
221221
"rootNames": [
@@ -233,7 +233,7 @@ Info 17 [00:00:40.000] FileWatcher:: Close:: WatchInfo: /user/username/project
233233
Info 18 [00:00:41.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
234234
Info 19 [00:00:42.000] Local plugin loading enabled; adding /user/username/projects/myproject to search paths
235235
CustomRequire:: Resolving myplugin from /user/username/projects/myproject/node_modules
236-
Require:: Module myplugin created with config: {"name":"myplugin"} and options: {"watchFactory":"myplugin"}
236+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":"myplugin"}
237237
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"}
238238
Info 20 [00:00:43.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 {"watchFactory":"myplugin"} Config: /user/username/projects/myproject/tsconfig.json WatchType: Wild card directory
239239
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":"myplugin"}

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-in-config-as-well-as-configuration-of-host-with-pluginoverride.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Info 13 [00:00:36.000] For info: /user/username/projects/myproject/a.ts :: Con
215215
Info 14 [00:00:37.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
216216
Info 15 [00:00:38.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin2"} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
217217
CustomRequire:: Resolving myplugin2 from /a/pluginprobe1/node_modules
218-
Require:: Module myplugin2 created with config: {"name":"myplugin2"} and options: {"watchFactory":"myplugin2"}
218+
Require:: Module myplugin2 created with config: {"init2":"initialConfig2","name":"myplugin2"} and options: {"watchFactory":"myplugin2"}
219219
Custom myplugin2watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin2"}
220220
Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json : {
221221
"rootNames": [
@@ -232,7 +232,7 @@ Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json
232232
Info 17 [00:00:40.000] FileWatcher:: Close:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin2"} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
233233
Info 18 [00:00:41.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
234234
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
235-
Require:: Module myplugin created with config: {"name":"myplugin"} and options: {"watchFactory":"myplugin"}
235+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":"myplugin"}
236236
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"}
237237
Info 19 [00:00:42.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 {"watchFactory":"myplugin"} Config: /user/username/projects/myproject/tsconfig.json WatchType: Wild card directory
238238
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":"myplugin"}

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-in-config-file-with-pluginOverride-allowLocalPluginLoads-object.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Info 10 [00:00:33.000] FileWatcher:: Close:: WatchInfo: /user/username/project
110110
Info 11 [00:00:34.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
111111
Info 12 [00:00:35.000] Local plugin loading enabled; adding /user/username/projects/myproject to search paths
112112
CustomRequire:: Resolving myplugin from /user/username/projects/myproject/node_modules
113-
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
113+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
114114
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
115115
Info 13 [00:00:36.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Config: /user/username/projects/myproject/tsconfig.json WatchType: Wild card directory
116116
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}

0 commit comments

Comments
 (0)