Skip to content

Commit

Permalink
Merge pull request #443 from athombv/develop
Browse files Browse the repository at this point in the history
mdim
  • Loading branch information
jeroenwienk authored Aug 14, 2024
2 parents b123b52 + 4d808b8 commit 8450803
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions lib/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

const { URLSearchParams } = require('url');

const fs = require('fs');
const Ajv = require('ajv');
const semver = require('semver');
const tinycolor = require('tinycolor2');
Expand Down Expand Up @@ -116,6 +117,56 @@ class App {
throw new Error('Invalid compatibility');
}

if (appJson.esm === true && semver.lt(semver.coerce(appJson.compatibility), '12.0.1')) {
throw new Error('ESM apps require a compatibility of at least >=12.0.1');
}

const checkEsm = async (path) => {
await fs.promises.access(path).then(() => {
if (semver.lt(semver.coerce(appJson.compatibility), '12.0.1')) {
throw new Error(`ESM apps require a compatibility of at least >=12.0.1. (${path})`);
}
}).catch(err => {
if (err.code !== 'ENOENT') {
throw err;
}
});
};

const appFilePathMjs = join(this._path, 'app.mjs');
const appFilePathCjs = join(this._path, 'app.cjs');
const apiFilePathMjs = join(this._path, 'api.mjs');
const apiFilePathCjs = join(this._path, 'api.cjs');

await checkEsm(appFilePathMjs);
await checkEsm(appFilePathCjs);
await checkEsm(apiFilePathMjs);
await checkEsm(apiFilePathCjs);

if (Array.isArray(appJson.drivers)) {
for (const driver of appJson.drivers) {
const driverFilePathMjs = join(this._path, 'drivers', driver.id, 'driver.mjs');
const driverFilePathCjs = join(this._path, 'drivers', driver.id, 'driver.cjs');
const deviceFilePathMjs = join(this._path, 'drivers', driver.id, 'device.mjs');
const deviceFilePathCjs = join(this._path, 'drivers', driver.id, 'device.cjs');

await checkEsm(driverFilePathMjs);
await checkEsm(driverFilePathCjs);
await checkEsm(deviceFilePathMjs);
await checkEsm(deviceFilePathCjs);
}
}

if (Array.isArray(appJson.widgets)) {
for (const widget of appJson.widgets) {
const apiFilePathMjs = join(this._path, 'widgets', widget.id, 'api.mjs');
const apiFilePathCjs = join(this._path, 'widgets', widget.id, 'api.cjs');

await checkEsm(apiFilePathMjs);
await checkEsm(apiFilePathCjs);
}
}

// validate sdk v3 apps have compatibility of at least >=5.0.0
if (appJson.sdk === 3) {
// lowest version that satisfies the compatibility
Expand Down

0 comments on commit 8450803

Please sign in to comment.