Skip to content

Commit

Permalink
Add plugin override for watchFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat committed Nov 10, 2022
1 parent 315e59f commit 83a0fa2
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 28 deletions.
7 changes: 6 additions & 1 deletion src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ export function createSystemWatchFunctions({
];
sysLog(`Enabling watchFactory ${isString(options.watchFactory) ? options.watchFactory : JSON.stringify(options.watchFactory)} from candidate paths: ${searchPaths.join(",")}`);
const { resolvedModule, errorLogs, pluginConfigEntry } = resolveModule<UserWatchFactoryModule>(
isString(options.watchFactory) ? { name: options.watchFactory } : options.watchFactory,
getWatchFactoryPlugin(options),
searchPaths,
getSystem(),
sysLog
Expand All @@ -983,6 +983,11 @@ export function createSystemWatchFunctions({
return setUserWatchFactory(options, /*userWatchFactory*/ undefined);
}

function getWatchFactoryPlugin(options: WatchOptions) {
const plugin = isString(options.watchFactory) ? { name: options.watchFactory } : options.watchFactory!;
return options.getHost?.().getPluginWithConfigOverride(plugin) || plugin;
}

function setUserWatchFactory(options: WatchOptions, userWatchFactory: UserWatchFactory | undefined) {
setWatchOptionInternalProperty(options, "getResolvedWatchFactory", userWatchFactory ? () => userWatchFactory : returnUndefined);
return userWatchFactory;
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6790,6 +6790,7 @@ export interface UserWatchFactory {
/**@internal*/
export interface WatchOptionsFactoryHost {
searchPaths: readonly string[];
getPluginWithConfigOverride(plugin: PluginImport): PluginImport;
}
export interface WatchOptions {
watchFile?: WatchFileKind;
Expand Down
17 changes: 15 additions & 2 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ export class ProjectService {
public readonly pluginProbeLocations: readonly string[];
public readonly allowLocalPluginLoads: boolean;
/** @internal */
currentPluginConfigOverrides: Map<string, any> | undefined;
private currentPluginConfigOverrides: Map<string, any> | undefined;

public readonly typesMapLocation: string | undefined;

Expand Down Expand Up @@ -3138,7 +3138,8 @@ export class ProjectService {
/** @internal */
private setWatchOptionsFactoryHost(options: WatchOptions, canonicalConfigFilePath: NormalizedPath | undefined) {
setWatchOptionInternalProperty(options, "getHost", memoize(() => ({
searchPaths: this.getProjectPluginSearchPaths(canonicalConfigFilePath)
searchPaths: this.getProjectPluginSearchPaths(canonicalConfigFilePath),
getPluginWithConfigOverride: plugin => this.getPluginWithConfigOverride(plugin),
})));
}

Expand Down Expand Up @@ -4185,6 +4186,18 @@ export class ProjectService {
return searchPaths;
}

/** @internal */
getPluginWithConfigOverride(pluginConfigEntry: PluginImport) {
const configurationOverride = this.currentPluginConfigOverrides?.get(pluginConfigEntry.name);
if (configurationOverride) {
// Preserve the name property since it's immutable
const pluginName = pluginConfigEntry.name;
pluginConfigEntry = configurationOverride;
pluginConfigEntry.name = pluginName;
}
return pluginConfigEntry;
}

/** @internal */
requestEnablePlugin(project: Project, pluginConfigEntry: PluginImport, searchPaths: string[]) {
if (!this.host.importPlugin && !this.host.require) {
Expand Down
10 changes: 1 addition & 9 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1679,15 +1679,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
*/
endEnablePlugin({ pluginConfigEntry, resolvedModule, errorLogs }: BeginEnablePluginResult) {
if (resolvedModule) {
const configurationOverride = this.projectService.currentPluginConfigOverrides?.get(pluginConfigEntry.name);
if (configurationOverride) {
// Preserve the name property since it's immutable
const pluginName = pluginConfigEntry.name;
pluginConfigEntry = configurationOverride;
pluginConfigEntry.name = pluginName;
}

this.enableProxy(resolvedModule, pluginConfigEntry);
this.enableProxy(resolvedModule, this.projectService.getPluginWithConfigOverride(pluginConfigEntry));
}
else {
forEach(errorLogs, message => this.projectService.logger.info(message));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Info 10 [00:00:33.000] For info: /user/username/projects/myproject/a.ts :: Con
Info 11 [00:00:34.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
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
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Info 13 [00:00:36.000] Config: /user/username/projects/myproject/tsconfig.json : {
"rootNames": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Info 10 [00:00:33.000] For info: /user/username/projects/myproject/a.ts :: Con
Info 11 [00:00:34.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
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
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
Require:: Module myplugin created with config: {"name":"myplugin"} and options: {"watchFactory":"myplugin"}
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":"myplugin"}
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"}
Info 13 [00:00:36.000] Config: /user/username/projects/myproject/tsconfig.json : {
"rootNames": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Info 10 [00:00:33.000] For info: /user/username/projects/myproject/a.ts :: Con
Info 11 [00:00:34.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
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
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Info 13 [00:00:36.000] Config: /user/username/projects/myproject/tsconfig.json : {
"rootNames": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Info 10 [00:00:33.000] For info: /user/username/projects/myproject/a.ts :: Con
Info 11 [00:00:34.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
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
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
Require:: Module myplugin created with config: {"name":"myplugin"} and options: {"watchFactory":"myplugin"}
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":"myplugin"}
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"}
Info 13 [00:00:36.000] Config: /user/username/projects/myproject/tsconfig.json : {
"rootNames": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Info 13 [00:00:36.000] For info: /user/username/projects/myproject/a.ts :: Con
Info 14 [00:00:37.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
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
CustomRequire:: Resolving myplugin2 from /a/pluginprobe1/node_modules
Require:: Module myplugin2 created with config: {"name":"myplugin2","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
Require:: Module myplugin2 created with config: {"init2":"initialConfig2","name":"myplugin2"} and options: {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
Custom myplugin2watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json : {
"rootNames": [
Expand All @@ -239,7 +239,7 @@ Info 17 [00:00:40.000] FileWatcher:: Close:: WatchInfo: /user/username/project
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
Info 19 [00:00:42.000] Local plugin loading enabled; adding /user/username/projects/myproject to search paths
CustomRequire:: Resolving myplugin from /user/username/projects/myproject/node_modules
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
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
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Info 13 [00:00:36.000] For info: /user/username/projects/myproject/a.ts :: Con
Info 14 [00:00:37.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
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
CustomRequire:: Resolving myplugin2 from /a/pluginprobe1/node_modules
Require:: Module myplugin2 created with config: {"name":"myplugin2"} and options: {"watchFactory":"myplugin2"}
Require:: Module myplugin2 created with config: {"init2":"initialConfig2","name":"myplugin2"} and options: {"watchFactory":"myplugin2"}
Custom myplugin2watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin2"}
Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json : {
"rootNames": [
Expand All @@ -233,7 +233,7 @@ Info 17 [00:00:40.000] FileWatcher:: Close:: WatchInfo: /user/username/project
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
Info 19 [00:00:42.000] Local plugin loading enabled; adding /user/username/projects/myproject to search paths
CustomRequire:: Resolving myplugin from /user/username/projects/myproject/node_modules
Require:: Module myplugin created with config: {"name":"myplugin"} and options: {"watchFactory":"myplugin"}
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":"myplugin"}
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"}
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
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":"myplugin"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Info 13 [00:00:36.000] For info: /user/username/projects/myproject/a.ts :: Con
Info 14 [00:00:37.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
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
CustomRequire:: Resolving myplugin2 from /a/pluginprobe1/node_modules
Require:: Module myplugin2 created with config: {"name":"myplugin2","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
Require:: Module myplugin2 created with config: {"init2":"initialConfig2","name":"myplugin2"} and options: {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
Custom myplugin2watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json : {
"rootNames": [
Expand All @@ -238,7 +238,7 @@ Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json
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
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
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
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
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Info 13 [00:00:36.000] For info: /user/username/projects/myproject/a.ts :: Con
Info 14 [00:00:37.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
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
CustomRequire:: Resolving myplugin2 from /a/pluginprobe1/node_modules
Require:: Module myplugin2 created with config: {"name":"myplugin2"} and options: {"watchFactory":"myplugin2"}
Require:: Module myplugin2 created with config: {"init2":"initialConfig2","name":"myplugin2"} and options: {"watchFactory":"myplugin2"}
Custom myplugin2watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin2"}
Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json : {
"rootNames": [
Expand All @@ -232,7 +232,7 @@ Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json
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
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
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
Require:: Module myplugin created with config: {"name":"myplugin"} and options: {"watchFactory":"myplugin"}
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":"myplugin"}
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"}
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
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":"myplugin"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Info 10 [00:00:33.000] FileWatcher:: Close:: WatchInfo: /user/username/project
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
Info 12 [00:00:35.000] Local plugin loading enabled; adding /user/username/projects/myproject to search paths
CustomRequire:: Resolving myplugin from /user/username/projects/myproject/node_modules
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
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
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
Expand Down
Loading

0 comments on commit 83a0fa2

Please sign in to comment.