@@ -4,9 +4,11 @@ import { pathToFileURL } from 'url';
44import globalDirs from 'global-dirs' ;
55import chalk from 'chalk' ;
66import { createRequire } from 'module' ;
7+ import semver from 'semver' ;
78import { loadConfig } from './config.js' ;
89
910const require = createRequire ( import . meta. url ) ;
11+ const TOOL_VERSION = require ( '../package.json' ) . version ;
1012
1113function expandHomeDirectory ( pluginRef ) {
1214 if ( pluginRef . startsWith ( '~/' ) || pluginRef . startsWith ( '~\\' ) ) {
@@ -114,13 +116,17 @@ export class PluginLoader {
114116 const mageConfigPath = path . join ( pluginRoot , 'mage-remote-run.json' ) ;
115117 const pkgPath = path . join ( pluginRoot , 'package.json' ) ;
116118
119+ // Always read package.json to check peer dependencies and static config
120+ let pluginPkg = null ;
121+ if ( await fs . promises . access ( pkgPath ) . then ( ( ) => true ) . catch ( ( ) => false ) ) {
122+ pluginPkg = JSON . parse ( await fs . promises . readFile ( pkgPath , 'utf8' ) ) ;
123+ this . _checkPeerDependency ( pluginName , pluginPkg ) ;
124+ }
125+
117126 if ( await fs . promises . access ( mageConfigPath ) . then ( ( ) => true ) . catch ( ( ) => false ) ) {
118127 staticConfig = JSON . parse ( await fs . promises . readFile ( mageConfigPath , 'utf8' ) ) ;
119- } else if ( await fs . promises . access ( pkgPath ) . then ( ( ) => true ) . catch ( ( ) => false ) ) {
120- const pkg = JSON . parse ( await fs . promises . readFile ( pkgPath , 'utf8' ) ) ;
121- if ( pkg [ 'mage-remote-run' ] ) {
122- staticConfig = pkg [ 'mage-remote-run' ] ;
123- }
128+ } else if ( pluginPkg ?. [ 'mage-remote-run' ] ) {
129+ staticConfig = pluginPkg [ 'mage-remote-run' ] ;
124130 }
125131
126132 if ( staticConfig ) {
@@ -171,4 +177,16 @@ export class PluginLoader {
171177 console . warn ( chalk . yellow ( `Plugin ${ pluginName } could not be loaded because it has no default export and no static config.` ) ) ;
172178 }
173179 }
180+
181+ _checkPeerDependency ( pluginName , pkg ) {
182+ const requiredRange = pkg . peerDependencies ?. [ 'mage-remote-run' ] ;
183+ if ( ! requiredRange ) return ;
184+
185+ if ( ! semver . satisfies ( TOOL_VERSION , requiredRange ) ) {
186+ console . warn ( chalk . yellow (
187+ `Plugin "${ pluginName } " requires mage-remote-run "${ requiredRange } " but the running version is ${ TOOL_VERSION } . ` +
188+ `The plugin may not work correctly.`
189+ ) ) ;
190+ }
191+ }
174192}
0 commit comments