WebThingsIO / gateway

WebThings Gateway - a self-hosted web application for monitoring and controlling a building over the web
http://webthings.io/gateway
Mozilla Public License 2.0
2.62k stars 339 forks source link

Make `exec` member of add-on manifests optional for extensions again #3037

Closed benfrancis closed 1 year ago

benfrancis commented 1 year ago

In the TypeScript re-write for 1.1 a change was made that made the exec member of add-on manifests mandatory.

This means it's no longer possible to create an extension add-on which is just CSS and JavaScript content with no back end executable.

We should consider making exec optional again to allow extension add-ons (e.g the square theme).

benfrancis commented 1 year ago

See also: https://github.com/WebThingsIO/gateway/issues/3036

benfrancis commented 1 year ago

I don't think this change was actually intentional, comments in the code imply that extension add-ons should not require an exec member.

Error reported after manual install of square theme add-on:

022-12-07 08:35:45.430 ERROR  : Failed to load add-on square-theme: Error: Error found in manifest for add-on square-theme: Manifest is missing: gateway_specific_settings.webthings.exec
    at loadManifestJson (/home/pi/webthings/gateway/build/addon-utils.js:219:15)
    at Object.loadManifest (/home/pi/webthings/gateway/build/addon-utils.js:278:16)
    at AddonManager.loadAddon (/home/pi/webthings/gateway/build/addon-manager.js:547:44)
    at fs_1.default.readdir (/home/pi/webthings/gateway/build/addon-manager.js:635:22)
    at FSReqWrap.args [as oncomplete] (fs.js:140:20)
2022-12-07 08:35:45.611 INFO   : Checking for add-on updates...

This error appears to be reported by this line of addon-utils.ts https://github.com/WebThingsIO/gateway/blob/master/src/addon-utils.ts#L69

Assuming this isn't due to manual installation, this may be a bug.

benfrancis commented 1 year ago

This regression may have been caused by https://github.com/WebThingsIO/gateway/pull/2755/files#diff-f39bb9687c1b1ec0a90ab3a5817fc488415f9a94305f1dd32ff76f0df77d2f40R92

It adds the exec member to manifestTemplate, which all manifests are checked against.

The value is set to '' if it doesn't exist, but only if the primary type of the add-on is not "extension", which in this case it is.

benfrancis commented 1 year ago

Note to self: If I revert the added line in the object literal which defines exec: '' I get an error:

src/addon-utils.ts:125:58 - error TS2339: Property 'exec' does not exist on type '{ primary_type: string; }'.

If I comment out line 125:

manifestTemplate.gateway_specific_settings.webthings.exec = '';

then the square theme add-on will install successfully, but presumably that will break validation for add-ons which aren't extensions.