Skip to content

Commit 8c79a15

Browse files
committed
Fix: Prevent plugins from being installed to wrong type directory (fixes #235)
1 parent 6ce7ddd commit 8c79a15

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

lib/integration/Plugin.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ export default class Plugin {
335335
*/
336336
async getType () {
337337
if (this._type) return this._type
338+
const pathType = this.getTypeFromProjectPath()
339+
if (pathType) return (this._type = pathType)
338340
const info = await this.getInfo()
339341
if (!info) return null
340342
const foundAttributeType = PLUGIN_TYPES.find(type => info[type])
@@ -347,6 +349,20 @@ export default class Plugin {
347349
return (this._type = foundAttributeType || foundKeywordType || PLUGIN_DEFAULT_TYPE)
348350
}
349351

352+
/**
353+
* Infer plugin type from the installed project path.
354+
* e.g. src/menu/adapt-contrib-boxMenu → 'menu'
355+
* @returns {string|null}
356+
*/
357+
getTypeFromProjectPath () {
358+
if (!this.projectPath) return null
359+
const folderToType = Object.fromEntries(
360+
Object.entries(PLUGIN_TYPE_FOLDERS).map(([type, folder]) => [folder, type])
361+
)
362+
const parentFolder = path.basename(path.dirname(this.projectPath))
363+
return folderToType[parentFolder] || null
364+
}
365+
350366
async getTypeFolder () {
351367
const type = await this.getType()
352368
return PLUGIN_TYPE_FOLDERS[type]

lib/integration/PluginManagement/install.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ async function loadPluginData ({ logger, project, targets }) {
9595
percentage => logger?.logProgress?.(`${chalk.bold.cyan('<info>')} Getting plugin info ${percentage}% complete`)
9696
)
9797
logger?.log(`${chalk.bold.cyan('<info>')} Getting plugin info 100% complete`)
98+
await eachOfLimitProgress(
99+
targets,
100+
target => target.fetchProjectInfo(),
101+
percentage => logger?.logProgress?.(`${chalk.bold.cyan('<info>')} Checking installed plugins ${percentage}% complete`)
102+
)
103+
logger?.log(`${chalk.bold.cyan('<info>')} Checking installed plugins 100% complete`)
98104
await eachOfLimitProgress(
99105
targets,
100106
target => target.findCompatibleVersion(frameworkVersion),

lib/integration/Target.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export default class Target extends Plugin {
122122

123123
markInstallable () {
124124
if (!this.isApplyLatestCompatibleVersion && !(this.isLocalSource && this.latestSourceVersion)) return
125+
if (this.projectVersion === this.matchedVersion) return
125126
this.versionToApply = this.matchedVersion
126127
}
127128

0 commit comments

Comments
 (0)