homey-lib 2.31.0 → 2.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/App/index.js CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
  const { URLSearchParams } = require('url');
7
7
 
8
+ const fs = require('fs');
8
9
  const Ajv = require('ajv');
9
10
  const semver = require('semver');
10
11
  const tinycolor = require('tinycolor2');
@@ -116,6 +117,56 @@ class App {
116
117
  throw new Error('Invalid compatibility');
117
118
  }
118
119
 
120
+ if (appJson.esm === true && semver.lt(semver.coerce(appJson.compatibility), '12.0.1')) {
121
+ throw new Error('ESM apps require a compatibility of at least >=12.0.1');
122
+ }
123
+
124
+ const checkEsm = async (path) => {
125
+ await fs.promises.access(path).then(() => {
126
+ if (semver.lt(semver.coerce(appJson.compatibility), '12.0.1')) {
127
+ throw new Error(`ESM apps require a compatibility of at least >=12.0.1. (${path})`);
128
+ }
129
+ }).catch(err => {
130
+ if (err.code !== 'ENOENT') {
131
+ throw err;
132
+ }
133
+ });
134
+ };
135
+
136
+ const appFilePathMjs = join(this._path, 'app.mjs');
137
+ const appFilePathCjs = join(this._path, 'app.cjs');
138
+ const apiFilePathMjs = join(this._path, 'api.mjs');
139
+ const apiFilePathCjs = join(this._path, 'api.cjs');
140
+
141
+ await checkEsm(appFilePathMjs);
142
+ await checkEsm(appFilePathCjs);
143
+ await checkEsm(apiFilePathMjs);
144
+ await checkEsm(apiFilePathCjs);
145
+
146
+ if (Array.isArray(appJson.drivers)) {
147
+ for (const driver of appJson.drivers) {
148
+ const driverFilePathMjs = join(this._path, 'drivers', driver.id, 'driver.mjs');
149
+ const driverFilePathCjs = join(this._path, 'drivers', driver.id, 'driver.cjs');
150
+ const deviceFilePathMjs = join(this._path, 'drivers', driver.id, 'device.mjs');
151
+ const deviceFilePathCjs = join(this._path, 'drivers', driver.id, 'device.cjs');
152
+
153
+ await checkEsm(driverFilePathMjs);
154
+ await checkEsm(driverFilePathCjs);
155
+ await checkEsm(deviceFilePathMjs);
156
+ await checkEsm(deviceFilePathCjs);
157
+ }
158
+ }
159
+
160
+ if (Array.isArray(appJson.widgets)) {
161
+ for (const widget of appJson.widgets) {
162
+ const apiFilePathMjs = join(this._path, 'widgets', widget.id, 'api.mjs');
163
+ const apiFilePathCjs = join(this._path, 'widgets', widget.id, 'api.cjs');
164
+
165
+ await checkEsm(apiFilePathMjs);
166
+ await checkEsm(apiFilePathCjs);
167
+ }
168
+ }
169
+
119
170
  // validate sdk v3 apps have compatibility of at least >=5.0.0
120
171
  if (appJson.sdk === 3) {
121
172
  // lowest version that satisfies the compatibility
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-lib",
3
- "version": "2.31.0",
3
+ "version": "2.31.1",
4
4
  "description": "Shared Library for Homey",
5
5
  "main": "index.js",
6
6
  "scripts": {