@@ -237,16 +237,17 @@ export const getProcessPluginName = (nameOrPath: string, logger: ILogger | Conso
237
237
* 4. /absolutePath/.../picgo-plugin-xxx -> picgo-plugin-xxx
238
238
* 5. an exception: [package.json's name] !== [folder name]
239
239
* then use [package.json's name], usually match the scope package.
240
+ * 6. if plugin name has version: picgo-plugin-xxx@x.x.x then remove the version
240
241
* @param nameOrPath
241
242
*/
242
243
export const getNormalPluginName = ( nameOrPath : string , logger : ILogger | Console = console ) : string => {
243
244
const pluginNameType = getPluginNameType ( nameOrPath )
244
245
switch ( pluginNameType ) {
245
246
case 'normal' :
246
247
case 'scope' :
247
- return nameOrPath
248
+ return removePluginVersion ( nameOrPath )
248
249
case 'simple' :
249
- return handleCompletePluginName ( nameOrPath )
250
+ return removePluginVersion ( handleCompletePluginName ( nameOrPath ) )
250
251
default : {
251
252
// now, the nameOrPath must be path
252
253
// the nameOrPath here will be ensured with unix style
@@ -282,3 +283,22 @@ export const handleUnixStylePath = (pathStr: string): string => {
282
283
const pathArr = pathStr . split ( path . sep )
283
284
return pathArr . join ( '/' )
284
285
}
286
+
287
+ /**
288
+ * remove plugin version when register plugin name
289
+ * 1. picgo-plugin-xxx@1.0.0 -> picgo-plugin-xxx
290
+ * @param nameOrPath
291
+ */
292
+ export const removePluginVersion = ( nameOrPath : string ) : string => {
293
+ if ( ! nameOrPath . includes ( '@' ) ) {
294
+ return nameOrPath
295
+ } else {
296
+ const matchArr = nameOrPath . match ( / ( .+ \/ ) ? ( p i c g o - p l u g i n - \w + ) ( @ .+ ) * / )
297
+ if ( ! matchArr ) {
298
+ console . warn ( 'can not remove plugin version' )
299
+ return nameOrPath
300
+ } else {
301
+ return matchArr [ 2 ]
302
+ }
303
+ }
304
+ }
0 commit comments