@@ -18,10 +18,10 @@ import * as ReactDOM from 'react-dom';
18
18
import * as ReactRedux from 'react-redux' ;
19
19
import * as ReactRouter from 'react-router-dom' ;
20
20
import * as Recharts from 'recharts' ;
21
- import semver from 'semver' ;
22
21
import * as CommonComponents from '../components/common' ;
23
22
import helpers from '../helpers' ;
24
23
import * as K8s from '../lib/k8s' ;
24
+ import { checkCompatibleVersion , getPluginPaths , getPlugins } from '../lib/k8s/api/v2/plugins' ;
25
25
import * as ApiProxy from '../lib/k8s/apiProxy' ;
26
26
import * as Crd from '../lib/k8s/crd' ;
27
27
import * as Notification from '../lib/notification' ;
@@ -125,10 +125,6 @@ export async function initializePlugins() {
125
125
* @param sources array of source to execute. Has the same order as packageInfos.
126
126
* @param packageInfos array of package.json contents
127
127
* @param appMode if we are in app mode
128
- * @param compatibleVersion headlamp-plugin version this build is compatible with.
129
- * If the plugin engine version is not compatible, the plugin will not be loaded.
130
- * Can be set to a semver range, e.g. '>= 0.6.0' or '0.6.0 - 0.7.0'.
131
- * If set to an empty string, all plugin versions will be loaded.
132
128
* @param settingsPackages the packages from settings
133
129
*
134
130
* @returns the sources to execute and incompatible PackageInfos
@@ -138,8 +134,8 @@ export function filterSources(
138
134
sources : string [ ] ,
139
135
packageInfos : PluginInfo [ ] ,
140
136
appMode : boolean ,
141
- compatibleVersion : string ,
142
- settingsPackages ?: PluginInfo [ ]
137
+ settingsPackages ?: PluginInfo [ ] ,
138
+ disableCompatibilityCheck ?: boolean
143
139
) {
144
140
const incompatiblePlugins : Record < string , PluginInfo > = { } ;
145
141
@@ -167,11 +163,11 @@ export function filterSources(
167
163
return enabledInSettings ;
168
164
} ) ;
169
165
166
+ const checkAllVersion = disableCompatibilityCheck ;
167
+
170
168
const compatible = enabledSourcesAndPackageInfos . filter ( ( { packageInfo } ) => {
171
- const isCompatible = semver . satisfies (
172
- semver . coerce ( packageInfo . devDependencies ?. [ '@kinvolk/headlamp-plugin' ] ) || '' ,
173
- compatibleVersion
174
- ) ;
169
+ const isCompatible = checkCompatibleVersion ( packageInfo , checkAllVersion ) ;
170
+
175
171
if ( ! isCompatible ) {
176
172
incompatiblePlugins [ packageInfo . name ] = packageInfo ;
177
173
return false ;
@@ -199,17 +195,21 @@ export function filterSources(
199
195
*/
200
196
export function updateSettingsPackages (
201
197
backendPlugins : PluginInfo [ ] ,
202
- settingsPlugins : PluginInfo [ ]
198
+ settingsPlugins : { name : string ; isEnabled : boolean } [ ]
203
199
) : PluginInfo [ ] {
204
200
if ( backendPlugins . length === 0 ) return [ ] ;
205
201
206
202
const pluginsChanged =
207
203
backendPlugins . length !== settingsPlugins . length ||
208
- backendPlugins . map ( p => p . name + p . version ) . join ( '' ) !==
209
- settingsPlugins . map ( p => p . name + p . version ) . join ( '' ) ;
204
+ JSON . stringify ( backendPlugins . map ( p => p . name ) . sort ( ) ) !==
205
+ JSON . stringify ( settingsPlugins . map ( p => p . name ) . sort ( ) ) ;
210
206
211
207
if ( ! pluginsChanged ) {
212
- return settingsPlugins ;
208
+ const updatedPlugins = backendPlugins . filter ( plugin =>
209
+ settingsPlugins . some ( setting => setting . name === plugin . name )
210
+ ) ;
211
+
212
+ return updatedPlugins ;
213
213
}
214
214
215
215
return backendPlugins . map ( plugin => {
@@ -241,46 +241,19 @@ export function updateSettingsPackages(
241
241
*
242
242
*/
243
243
export async function fetchAndExecutePlugins (
244
- settingsPackages : PluginInfo [ ] ,
244
+ settingsPackages : { name : string ; isEnabled : boolean } [ ] ,
245
245
onSettingsChange : ( plugins : PluginInfo [ ] ) => void ,
246
246
onIncompatible : ( plugins : Record < string , PluginInfo > ) => void
247
247
) {
248
- const pluginPaths = ( await fetch ( `${ helpers . getAppUrl ( ) } plugins` ) . then ( resp =>
249
- resp . json ( )
250
- ) ) as string [ ] ;
248
+ const pluginPaths = await getPluginPaths ( ) ;
251
249
252
250
const sourcesPromise = Promise . all (
253
251
pluginPaths . map ( path =>
254
252
fetch ( `${ helpers . getAppUrl ( ) } ${ path } /main.js` ) . then ( resp => resp . text ( ) )
255
253
)
256
254
) ;
257
255
258
- const packageInfosPromise = await Promise . all < PluginInfo > (
259
- pluginPaths . map ( path =>
260
- fetch ( `${ helpers . getAppUrl ( ) } ${ path } /package.json` ) . then ( resp => {
261
- if ( ! resp . ok ) {
262
- if ( resp . status !== 404 ) {
263
- return Promise . reject ( resp ) ;
264
- }
265
- {
266
- console . warn (
267
- 'Missing package.json. ' +
268
- `Please upgrade the plugin ${ path } ` +
269
- ' by running "headlamp-plugin extract" again.' +
270
- ' Please use headlamp-plugin >= 0.8.0'
271
- ) ;
272
- return {
273
- name : path . split ( '/' ) . slice ( - 1 ) [ 0 ] ,
274
- version : '0.0.0' ,
275
- author : 'unknown' ,
276
- description : '' ,
277
- } ;
278
- }
279
- }
280
- return resp . json ( ) ;
281
- } )
282
- )
283
- ) ;
256
+ const packageInfosPromise = await getPlugins ( settingsPackages ) ;
284
257
285
258
const sources = await sourcesPromise ;
286
259
const packageInfos = await packageInfosPromise ;
@@ -291,15 +264,10 @@ export async function fetchAndExecutePlugins(
291
264
onSettingsChange ( updatedSettingsPackages ) ;
292
265
}
293
266
294
- // Can set this to a semver version range like '>=0.8.0-alpha.3'.
295
- // '' means all versions.
296
- const compatibleHeadlampPluginVersion = '>=0.8.0-alpha.3' ;
297
-
298
267
const { sourcesToExecute, incompatiblePlugins } = filterSources (
299
268
sources ,
300
269
packageInfos ,
301
270
helpers . isElectron ( ) ,
302
- compatibleHeadlampPluginVersion ,
303
271
updatedSettingsPackages
304
272
) ;
305
273
0 commit comments