Skip to content

Commit 43a3958

Browse files
committed
Add plugin override for watchFactory
1 parent e10491c commit 43a3958

16 files changed

+39
-28
lines changed

src/compiler/sys.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ export function createSystemWatchFunctions({
965965
];
966966
sysLog(`Enabling watchFactory ${isString(options.watchFactory) ? options.watchFactory : JSON.stringify(options.watchFactory)} from candidate paths: ${searchPaths.join(",")}`);
967967
const { resolvedModule, errorLogs, pluginConfigEntry } = resolveModule<UserWatchFactoryModule>(
968-
isString(options.watchFactory) ? { name: options.watchFactory } : options.watchFactory,
968+
getWatchFactoryPlugin(options),
969969
searchPaths,
970970
getSystem(),
971971
sysLog
@@ -983,6 +983,11 @@ export function createSystemWatchFunctions({
983983
return setUserWatchFactory(options, /*userWatchFactory*/ undefined);
984984
}
985985

986+
function getWatchFactoryPlugin(options: WatchOptions) {
987+
const plugin = isString(options.watchFactory) ? { name: options.watchFactory } : options.watchFactory!;
988+
return options.getHost?.().getPluginWithConfigOverride(plugin) || plugin;
989+
}
990+
986991
function setUserWatchFactory(options: WatchOptions, userWatchFactory: UserWatchFactory | undefined) {
987992
setWatchOptionInternalProperty(options, "getResolvedWatchFactory", userWatchFactory ? () => userWatchFactory : returnUndefined);
988993
return userWatchFactory;

src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6790,6 +6790,7 @@ export interface UserWatchFactory {
67906790
/**@internal*/
67916791
export interface WatchOptionsFactoryHost {
67926792
searchPaths: readonly string[];
6793+
getPluginWithConfigOverride(plugin: PluginImport): PluginImport;
67936794
}
67946795
export interface WatchOptions {
67956796
watchFile?: WatchFileKind;

src/server/editorServices.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ export class ProjectService {
827827
public readonly pluginProbeLocations: readonly string[];
828828
public readonly allowLocalPluginLoads: boolean;
829829
/** @internal */
830-
currentPluginConfigOverrides: Map<string, any> | undefined;
830+
private currentPluginConfigOverrides: Map<string, any> | undefined;
831831

832832
public readonly typesMapLocation: string | undefined;
833833

@@ -3138,7 +3138,8 @@ export class ProjectService {
31383138
/** @internal */
31393139
private setWatchOptionsFactoryHost(options: WatchOptions, canonicalConfigFilePath: NormalizedPath | undefined) {
31403140
setWatchOptionInternalProperty(options, "getHost", memoize(() => ({
3141-
searchPaths: this.getProjectPluginSearchPaths(canonicalConfigFilePath)
3141+
searchPaths: this.getProjectPluginSearchPaths(canonicalConfigFilePath),
3142+
getPluginWithConfigOverride: plugin => this.getPluginWithConfigOverride(plugin),
31423143
})));
31433144
}
31443145

@@ -4185,6 +4186,18 @@ export class ProjectService {
41854186
return searchPaths;
41864187
}
41874188

4189+
/** @internal */
4190+
getPluginWithConfigOverride(pluginConfigEntry: PluginImport) {
4191+
const configurationOverride = this.currentPluginConfigOverrides?.get(pluginConfigEntry.name);
4192+
if (configurationOverride) {
4193+
// Preserve the name property since it's immutable
4194+
const pluginName = pluginConfigEntry.name;
4195+
pluginConfigEntry = configurationOverride;
4196+
pluginConfigEntry.name = pluginName;
4197+
}
4198+
return pluginConfigEntry;
4199+
}
4200+
41884201
/** @internal */
41894202
requestEnablePlugin(project: Project, pluginConfigEntry: PluginImport, searchPaths: string[]) {
41904203
if (!this.host.importPlugin && !this.host.require) {

src/server/project.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -1679,15 +1679,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
16791679
*/
16801680
endEnablePlugin({ pluginConfigEntry, resolvedModule, errorLogs }: BeginEnablePluginResult) {
16811681
if (resolvedModule) {
1682-
const configurationOverride = this.projectService.currentPluginConfigOverrides?.get(pluginConfigEntry.name);
1683-
if (configurationOverride) {
1684-
// Preserve the name property since it's immutable
1685-
const pluginName = pluginConfigEntry.name;
1686-
pluginConfigEntry = configurationOverride;
1687-
pluginConfigEntry.name = pluginName;
1688-
}
1689-
1690-
this.enableProxy(resolvedModule, pluginConfigEntry);
1682+
this.enableProxy(resolvedModule, this.projectService.getPluginWithConfigOverride(pluginConfigEntry));
16911683
}
16921684
else {
16931685
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-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-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.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-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-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.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)