From 64322ed0abaa226cbaf146b4b7d7fc716604da33 Mon Sep 17 00:00:00 2001 From: Johannah Sprinz Date: Sun, 20 Mar 2022 14:18:20 +0100 Subject: [PATCH] allow specifying compatible_installer per os resolves #2509 --- package-lock.json | 291 +++++++++++++++++++----------------------- package.json | 1 + src/core/core.js | 23 ++++ src/core/core.spec.js | 85 +++++++++++- src/lib/mainEvent.js | 11 ++ 5 files changed, 252 insertions(+), 159 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6d415fb5..a862479d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,6 +23,7 @@ "progressive-downloader": "^1.0.7", "promise-android-tools": "^4.0.8", "ps-tree": "^1.2.0", + "semver": "^7.3.5", "sudo-prompt": "^9.2.1", "svelte-markdown": "^0.2.2", "systeminformation": "^5.11.8", @@ -118,6 +119,15 @@ "url": "https://opencollective.com/babel" } }, + "node_modules/@babel/core/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/@babel/generator": { "version": "7.17.7", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.17.7.tgz", @@ -159,6 +169,15 @@ "@babel/core": "^7.0.0" } }, + "node_modules/@babel/helper-compilation-targets/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/@babel/helper-environment-visitor": { "version": "7.16.7", "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.16.7.tgz", @@ -722,6 +741,15 @@ "graceful-fs": "^4.1.6" } }, + "node_modules/@electron/get/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/@electron/get/node_modules/universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", @@ -1828,21 +1856,6 @@ "node": ">=14.0.0" } }, - "node_modules/app-builder-lib/node_modules/semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -3134,20 +3147,6 @@ "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" }, - "node_modules/conf/node_modules/semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/config-chain": { "version": "1.1.13", "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.13.tgz", @@ -3909,21 +3908,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/electron-packager/node_modules/semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/electron-publish": { "version": "22.14.13", "resolved": "https://registry.npmjs.org/electron-publish/-/electron-publish-22.14.13.tgz", @@ -4740,22 +4724,6 @@ "node": ">=10.0" } }, - "node_modules/global-agent/node_modules/semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "optional": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/global-dirs": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-3.0.0.tgz", @@ -5544,6 +5512,15 @@ "node": ">=8" } }, + "node_modules/istanbul-lib-instrument/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/istanbul-lib-report": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz", @@ -6232,21 +6209,6 @@ "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" } }, - "node_modules/jest-snapshot/node_modules/semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/jest-util": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-27.5.1.tgz", @@ -6831,6 +6793,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/make-dir/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/makeerror": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.12.tgz", @@ -7501,6 +7472,15 @@ "node": ">=8" } }, + "node_modules/package-json/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/parse-author": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/parse-author/-/parse-author-2.0.0.tgz", @@ -8680,12 +8660,17 @@ } }, "node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "dev": true, + "version": "7.3.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "dependencies": { + "lru-cache": "^6.0.0" + }, "bin": { "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" } }, "node_modules/semver-compare": { @@ -8707,6 +8692,15 @@ "node": ">=8" } }, + "node_modules/semver-diff/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/serialize-error": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-7.0.1.tgz", @@ -10063,21 +10057,6 @@ "is-ci": "bin.js" } }, - "node_modules/update-notifier/node_modules/semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -10587,6 +10566,14 @@ "gensync": "^1.0.0-beta.2", "json5": "^2.1.2", "semver": "^6.3.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "@babel/generator": { @@ -10618,6 +10605,14 @@ "@babel/helper-validator-option": "^7.16.7", "browserslist": "^4.17.5", "semver": "^6.3.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "@babel/helper-environment-visitor": { @@ -11047,6 +11042,12 @@ "graceful-fs": "^4.1.6" } }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + }, "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", @@ -11972,17 +11973,6 @@ "sanitize-filename": "^1.6.3", "semver": "^7.3.5", "temp-file": "^3.4.0" - }, - "dependencies": { - "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } - } } }, "argparse": { @@ -12971,14 +12961,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" - }, - "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "requires": { - "lru-cache": "^6.0.0" - } } } }, @@ -13573,15 +13555,6 @@ "requires": { "pump": "^3.0.0" } - }, - "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } } } }, @@ -14225,18 +14198,6 @@ "roarr": "^2.15.3", "semver": "^7.3.2", "serialize-error": "^7.0.1" - }, - "dependencies": { - "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "optional": true, - "requires": { - "lru-cache": "^6.0.0" - } - } } }, "global-dirs": { @@ -14821,6 +14782,14 @@ "@istanbuljs/schema": "^0.1.2", "istanbul-lib-coverage": "^3.2.0", "semver": "^6.3.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "istanbul-lib-report": { @@ -15363,17 +15332,6 @@ "natural-compare": "^1.4.0", "pretty-format": "^27.5.1", "semver": "^7.3.2" - }, - "dependencies": { - "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } - } } }, "jest-util": { @@ -15835,6 +15793,14 @@ "dev": true, "requires": { "semver": "^6.0.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "makeerror": { @@ -16362,6 +16328,14 @@ "registry-auth-token": "^4.0.0", "registry-url": "^5.0.0", "semver": "^6.2.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "parse-author": { @@ -17281,10 +17255,12 @@ } }, "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "dev": true + "version": "7.3.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "requires": { + "lru-cache": "^6.0.0" + } }, "semver-compare": { "version": "1.0.0", @@ -17300,6 +17276,14 @@ "dev": true, "requires": { "semver": "^6.3.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "serialize-error": { @@ -18377,15 +18361,6 @@ "requires": { "ci-info": "^2.0.0" } - }, - "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } } } }, diff --git a/package.json b/package.json index cb894b09..2f1ed5f7 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "progressive-downloader": "^1.0.7", "promise-android-tools": "^4.0.8", "ps-tree": "^1.2.0", + "semver": "^7.3.5", "sudo-prompt": "^9.2.1", "svelte-markdown": "^0.2.2", "systeminformation": "^5.11.8", diff --git a/src/core/core.js b/src/core/core.js index dc0e4a27..14d2ead1 100644 --- a/src/core/core.js +++ b/src/core/core.js @@ -28,6 +28,8 @@ const errors = require("../lib/errors.js"); const window = require("../lib/window.js"); const api = require("./helpers/api.js"); const PluginIndex = require("./plugins/index.js"); +const packageInfo = require("../../package.json"); +const semver = require("semver"); /** * properties @@ -198,6 +200,7 @@ class Core { `Installing ${this.props.os.name} on your ${this.props.config.name} (${this.props.config.codename})` ) ) + .then(() => this.installer_version()) .then(() => this.prerequisites()) .then(() => this.eula()) .then(() => this.configure()) @@ -207,6 +210,26 @@ class Core { ); } + /** + * ensure the required installer version is fulfilled + * @returns {Promise} + */ + installer_version() { + return new Promise((resolve, reject) => + semver.satisfies( + packageInfo.version, + this.props.os.compatible_installer || "*", + { includePrerelease: true } + ) + ? resolve() + : mainEvent.emit( + "user:installer_version", + this.props.os.compatible_installer, + resolve + ) + ); + } + /** * ensure prerequisites are fulfilled * @returns {Promise} diff --git a/src/core/core.spec.js b/src/core/core.spec.js index d43d2a9c..468aa57c 100644 --- a/src/core/core.spec.js +++ b/src/core/core.spec.js @@ -26,7 +26,16 @@ const user_actions = {}; const handlers = { fastboot_lock: {} }; -core.props.config = { user_actions, handlers }; +const operating_systems = [ + { + name: "Ubuntu Touch", + compatible_installer: ">=9.9.9", + steps: [{}] + } +]; +core.props.config = { user_actions, handlers, operating_systems }; + +beforeEach(() => jest.restoreAllMocks()); describe("Core module", () => { describe("prepare()", () => { @@ -187,6 +196,15 @@ describe("Core module", () => { core.prepare("a"); }); }); + + describe("reset()", () => { + it.todo("should reset props"); + }); + + describe("prepare()", () => { + it.todo("should run preparations"); + }); + describe("kill()", () => { it("should kill", () => { jest.spyOn(core, "reset").mockReturnValue(); @@ -199,6 +217,7 @@ describe("Core module", () => { }); }); }); + describe("setConfig()", () => { it("should set config", () => { const old = core.props.config; @@ -208,6 +227,7 @@ describe("Core module", () => { }); }); }); + describe("setDevice()", () => { it("should set Device", () => { jest.spyOn(mainEvent, "emit").mockReturnValue(); @@ -239,6 +259,69 @@ describe("Core module", () => { }); }); }); + + describe("readConfigFile()", () => { + it.todo("should read config file"); + }); + + describe("selectOs()", () => { + it.todo("should propmpt os selection"); + }); + + describe("unlock()", () => { + it.todo("should run unlock steps"); + }); + + describe("install()", () => { + it("should start installation", () => { + core.props.config = { user_actions, handlers, operating_systems }; + jest.spyOn(core, "installer_version").mockResolvedValueOnce(); + jest.spyOn(core, "prerequisites").mockResolvedValueOnce(); + jest.spyOn(core, "eula").mockResolvedValueOnce(); + jest.spyOn(core, "configure").mockRejectedValueOnce(); + jest.spyOn(core, "handle").mockResolvedValueOnce(); + jest.spyOn(core, "run").mockResolvedValueOnce(); + return core.install(0).then(() => { + expect(core.prerequisites).toHaveBeenCalledTimes(1); + expect(core.eula).toHaveBeenCalledTimes(1); + expect(core.configure).toHaveBeenCalledTimes(1); + expect(core.run).toHaveBeenCalledTimes(1); + }); + }); + }); + + describe("installer_version()", () => { + it("should pass if not specified", () => { + core.props.os.compatible_installer = null; + return core.installer_version(); + }); + it("should ensure installer version", done => { + core.props.os.compatible_installer = ">=9.9.9"; + jest.spyOn(mainEvent, "emit").mockImplementation(m => { + expect(m).toEqual("user:installer_version"); + mainEvent.emit.mockRestore(); + done(); + }); + core.installer_version(); + }); + }); + + describe("prerequisites()", () => { + it.todo("should ensure prerequisites"); + }); + + describe("eula()", () => { + it.todo("should ensure eula"); + }); + + describe("configure()", () => { + it.todo("should configure install"); + }); + + describe("setRemoteValues()", () => { + it.todo("should set remote values"); + }); + describe("run", () => { const steps = [ { actions: [{ "a:x": null }, { "b:y": null }] }, diff --git a/src/lib/mainEvent.js b/src/lib/mainEvent.js index 70a85516..f0a792dd 100644 --- a/src/lib/mainEvent.js +++ b/src/lib/mainEvent.js @@ -147,6 +147,17 @@ mainEvent.on("user:unlock", (fields, resolve) => { }).then(resolve); }); +// installer_version +mainEvent.on("user:installer_version", (version, resolve) => { + log.warn(`Incompatible UBports Installer version! Required: ${version}`); + prompt({ + title: "Incompatible installer version", + dismissable: false, + description: `This installation procedure requires UBports Installer \`${version}\`. You are running \`${packageInfo.version}\`. Please use a [compatible installer](https://github.com/ubports/ubports-installer/releases). You might also ignore this warning, but there is no guarantee the installer will work as expected.`, + confirm: "I know what I'm doing, ignore warning and continue" + }).then(() => resolve(log.warn("Installer version constraint ignored"))); +}); + // prerequisites mainEvent.on("user:prerequisites", (fields, resolve) => { prompt({