Skip to content

Commit 35e15b0

Browse files
committed
✨ Feature: supporting install specific version of plugin
1 parent 36ad778 commit 35e15b0

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/utils/common.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,17 @@ export const getProcessPluginName = (nameOrPath: string, logger: ILogger | Conso
237237
* 4. /absolutePath/.../picgo-plugin-xxx -> picgo-plugin-xxx
238238
* 5. an exception: [package.json's name] !== [folder name]
239239
* 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
240241
* @param nameOrPath
241242
*/
242243
export const getNormalPluginName = (nameOrPath: string, logger: ILogger | Console = console): string => {
243244
const pluginNameType = getPluginNameType(nameOrPath)
244245
switch (pluginNameType) {
245246
case 'normal':
246247
case 'scope':
247-
return nameOrPath
248+
return removePluginVersion(nameOrPath)
248249
case 'simple':
249-
return handleCompletePluginName(nameOrPath)
250+
return removePluginVersion(handleCompletePluginName(nameOrPath))
250251
default: {
251252
// now, the nameOrPath must be path
252253
// the nameOrPath here will be ensured with unix style
@@ -282,3 +283,22 @@ export const handleUnixStylePath = (pathStr: string): string => {
282283
const pathArr = pathStr.split(path.sep)
283284
return pathArr.join('/')
284285
}
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(/(.+\/)?(picgo-plugin-\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

Comments
 (0)