Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe3b9ee

Browse files
committed
refactor(linter/plugins): addregisterPlugin function
1 parentbe36e36 commitbe3b9ee

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

‎apps/oxlint/src-js/plugins/load.ts‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,33 +108,30 @@ interface PluginDetails {
108108
*/
109109
exportasyncfunctionloadPlugin(url:string,packageName:string|null):Promise<string>{
110110
try{
111-
constres=awaitloadPluginImpl(url,packageName);
111+
if(DEBUG){
112+
if(registeredPluginUrls.has(url))thrownewError("This plugin has already been registered");
113+
registeredPluginUrls.add(url);
114+
}
115+
116+
constplugin=(awaitimport(url)).defaultasPlugin;
117+
constres=registerPlugin(plugin,packageName);
112118
returnJSON.stringify({Success:res});
113119
}catch(err){
114120
returnJSON.stringify({Failure:getErrorMessage(err)});
115121
}
116122
}
117123

118124
/**
119-
*Load a plugin.
125+
*Register a plugin.
120126
*
121-
*@paramurl -Absolute path of plugin file as a `file://...` URL
127+
*@paramplugin -Plugin
122128
*@param packageName - Optional package name from `package.json` (fallback if `plugin.meta.name` is not defined)
123129
*@returns - Plugin details
124-
*@throws {*} If plugin throws during import
125130
*@throws {Error} If `plugin.meta.name` is `null` / `undefined` and `packageName` not provided
126131
*@throws {TypeError} If one of plugin's rules is malformed, or its `createOnce` method returns invalid visitor
127132
*@throws {TypeError} If `plugin.meta.name` is not a string
128-
*@throws {Error} In debug build if plugin has already been registered
129133
*/
130-
asyncfunctionloadPluginImpl(url:string,packageName:string|null):Promise<PluginDetails>{
131-
if(DEBUG){
132-
if(registeredPluginUrls.has(url))thrownewError("This plugin has already been registered");
133-
registeredPluginUrls.add(url);
134-
}
135-
136-
const{default:plugin}=(awaitimport(url))as{default:Plugin};
137-
134+
functionregisterPlugin(plugin:Plugin,packageName:string|null):PluginDetails{
138135
// TODO: Use a validation library to assert the shape of the plugin, and of rules
139136

140137
constpluginName=getPluginName(plugin,packageName);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp