native-update 4.4.0 → 4.4.2
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/README.md +13 -4
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +3 -11
- package/android/src/main/java/com/aoneahsan/nativeupdate/VersionOrder.kt +60 -0
- package/cli/commands/ota-tag-core.js +127 -0
- package/cli/commands/ota-tag.js +103 -0
- package/cli/commands/remote.js +36 -2
- package/cli/index.js +26 -0
- package/dist/esm/app-update/app-update-checker.js +2 -11
- package/dist/esm/background-update/background-scheduler.js +2 -11
- package/dist/esm/core/update-check.d.ts +1 -1
- package/dist/esm/core/update-check.js +1 -1
- package/dist/esm/core/version-order.d.ts +21 -0
- package/dist/esm/core/version-order.js +83 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/live-update/rollout-checker.js +2 -13
- package/dist/esm/live-update/version-manager.js +2 -30
- package/dist/esm/plugin.js +2 -11
- package/dist/esm/security/validator.js +2 -11
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.esm.js +1 -1
- package/dist/plugin.js +2 -2
- package/docs/CHANGELOG.md +41 -0
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ are available as an HTTP API for CI and coding agents.
|
|
|
28
28
|
|
|
29
29
|
| | |
|
|
30
30
|
|---|---|
|
|
31
|
-
| **Version** | `4.4.
|
|
31
|
+
| **Version** | `4.4.2` |
|
|
32
32
|
| **License** | Proprietary — free to use in your apps ([LICENSE](./LICENSE)) |
|
|
33
33
|
| **Node** | `>=24.16.0` (install + CLI toolchain) |
|
|
34
34
|
| **Platforms** | iOS 14+ · Android 8.0+ (API 26) · Web |
|
|
@@ -383,6 +383,14 @@ npx native-update deploy ./dist --app com.example.app --version 1.2.0 --wait
|
|
|
383
383
|
| `--channel <name>` | `production` | release channel |
|
|
384
384
|
| `--rollout <percent>` | — | release to a percentage of devices |
|
|
385
385
|
| `--wait` | `false` | block until the queued upload finishes — **use this in CI** |
|
|
386
|
+
| `--ota-tag <prefix>` | — | publish as `<version>-<prefix><N>`, e.g. `1.16.1-nu2`; N restarts at 1 when the version changes |
|
|
387
|
+
| `--min-native <version>` | `versionName` in `android/app/build.gradle` with `--ota-tag` | lowest binary that may receive the bundle |
|
|
388
|
+
| `--dry-run` | `false` | print the version, channel and minimum native version; upload nothing |
|
|
389
|
+
|
|
390
|
+
A tag sorts below its own version (`1.16.1-nu3` < `1.16.1`), so the store release of that version supersedes it,
|
|
391
|
+
so the tag's version must be above the `versionName` your devices run. With `--ota-tag` and no `--version`, a
|
|
392
|
+
`package.json` version that is not above it moves to that `versionName`'s next patch; an explicit `--version` is
|
|
393
|
+
refused instead.
|
|
386
394
|
|
|
387
395
|
Full reference: [CLI docs](https://nativeupdate-docs.aoneahsan.com/reference/cli/overview).
|
|
388
396
|
|
|
@@ -513,9 +521,10 @@ indexed at [`/raw/manifest.json`](https://nativeupdate-docs.aoneahsan.com/raw/ma
|
|
|
513
521
|
<a id="changelog"></a>
|
|
514
522
|
## 🔄 Changelog [#](#changelog)
|
|
515
523
|
|
|
516
|
-
Latest release: **`4.4.
|
|
517
|
-
|
|
518
|
-
|
|
524
|
+
Latest release: **`4.4.2`**. `deploy --ota-tag` now picks the tag's version by itself when `package.json` is not
|
|
525
|
+
above the native `versionName` (native 1.3.0 → `1.3.1-nu1`). **`4.4.1`** added OTA version tags (`1.16.1-nu1`,
|
|
526
|
+
`-nu2` …) and ordered `-nu10` after `-nu9` everywhere. Before that, **`4.4.0`** added Dart
|
|
527
|
+
code patches for Flutter apps (`bundle flutter-patch`, `deploy --payload-type dart_aot`).
|
|
519
528
|
|
|
520
529
|
Full history ships inside the package at `docs/CHANGELOG.md`, so it always matches the version you
|
|
521
530
|
installed. It is also published as the
|
|
@@ -61,7 +61,7 @@ class LiveUpdatePlugin(
|
|
|
61
61
|
|
|
62
62
|
companion object {
|
|
63
63
|
/** This plugin's version, sent as X-Sdk-Version. Kept equal to package.json by tests/sdk-version.test.ts. */
|
|
64
|
-
const val SDK_VERSION = "4.4.
|
|
64
|
+
const val SDK_VERSION = "4.4.2"
|
|
65
65
|
|
|
66
66
|
// SharedPreferences keys. Kept as constants so A2 (boot-time
|
|
67
67
|
// re-verification) and A3 (crash-loop auto-rollback) stay in sync
|
|
@@ -1031,16 +1031,8 @@ class LiveUpdatePlugin(
|
|
|
1031
1031
|
}
|
|
1032
1032
|
}
|
|
1033
1033
|
|
|
1034
|
-
/**
|
|
1035
|
-
private fun compareVersions(left: String, right: String): Int
|
|
1036
|
-
val a = left.substringBefore('-').substringBefore('+').split('.').map { it.toIntOrNull() ?: 0 }
|
|
1037
|
-
val b = right.substringBefore('-').substringBefore('+').split('.').map { it.toIntOrNull() ?: 0 }
|
|
1038
|
-
for (index in 0 until maxOf(a.size, b.size)) {
|
|
1039
|
-
val difference = (a.getOrNull(index) ?: 0) - (b.getOrNull(index) ?: 0)
|
|
1040
|
-
if (difference != 0) return difference
|
|
1041
|
-
}
|
|
1042
|
-
return 0
|
|
1043
|
-
}
|
|
1034
|
+
/** The shared version order: OTA tags such as 1.16.1-nu10 sort after 1.16.1-nu9 ([VersionOrder]). */
|
|
1035
|
+
private fun compareVersions(left: String, right: String): Int = VersionOrder.compare(left, right)
|
|
1044
1036
|
|
|
1045
1037
|
fun cleanup() {
|
|
1046
1038
|
// Clean up any resources
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
package com.aoneahsan.nativeupdate
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The plugin's one version order, identical to the TypeScript `compareVersions` and the server's PHP
|
|
5
|
+
* `version_compare` for the shapes we ship.
|
|
6
|
+
*
|
|
7
|
+
* Semver precedence, plus one refinement: a pre-release identifier ending in digits compares those digits as a
|
|
8
|
+
* number, so the OTA tag `1.16.1-nu10` is newer than `1.16.1-nu9`. An OTA tag sorts below its own base
|
|
9
|
+
* (`1.16.1-nu3` < `1.16.1`), so a store release of that base supersedes it. Build metadata (`+…`) is ignored.
|
|
10
|
+
*/
|
|
11
|
+
object VersionOrder {
|
|
12
|
+
private val numeric = Regex("^\\d+$")
|
|
13
|
+
private val lettersThenDigits = Regex("^(.*?)(\\d+)$")
|
|
14
|
+
|
|
15
|
+
/** Negative when [left] is older, zero when equal, positive when [left] is newer. */
|
|
16
|
+
fun compare(left: String, right: String): Int {
|
|
17
|
+
val a = parse(left)
|
|
18
|
+
val b = parse(right)
|
|
19
|
+
for (index in 0 until maxOf(a.first.size, b.first.size, 3)) {
|
|
20
|
+
val difference = (a.first.getOrNull(index) ?: 0L).compareTo(b.first.getOrNull(index) ?: 0L)
|
|
21
|
+
if (difference != 0) return difference
|
|
22
|
+
}
|
|
23
|
+
val preA = a.second
|
|
24
|
+
val preB = b.second
|
|
25
|
+
if (preA.isEmpty() && preB.isEmpty()) return 0
|
|
26
|
+
if (preA.isEmpty()) return 1
|
|
27
|
+
if (preB.isEmpty()) return -1
|
|
28
|
+
for (index in 0 until maxOf(preA.size, preB.size)) {
|
|
29
|
+
val leftId = preA.getOrNull(index) ?: return -1
|
|
30
|
+
val rightId = preB.getOrNull(index) ?: return 1
|
|
31
|
+
val result = compareIdentifier(leftId, rightId)
|
|
32
|
+
if (result != 0) return result
|
|
33
|
+
}
|
|
34
|
+
return 0
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private fun parse(version: String): Pair<List<Long>, List<String>> {
|
|
38
|
+
val withoutBuild = version.trim().removePrefix("v").removePrefix("V").substringBefore('+')
|
|
39
|
+
val core = withoutBuild.substringBefore('-')
|
|
40
|
+
val pre = if (withoutBuild.contains('-')) withoutBuild.substringAfter('-') else ""
|
|
41
|
+
return Pair(
|
|
42
|
+
core.split('.').map { it.toLongOrNull() ?: 0L },
|
|
43
|
+
if (pre.isEmpty()) emptyList() else pre.split('.'),
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private fun compareIdentifier(left: String, right: String): Int {
|
|
48
|
+
val leftNumeric = numeric.matches(left)
|
|
49
|
+
val rightNumeric = numeric.matches(right)
|
|
50
|
+
if (leftNumeric && rightNumeric) return left.toBigInteger().compareTo(right.toBigInteger())
|
|
51
|
+
if (leftNumeric) return -1
|
|
52
|
+
if (rightNumeric) return 1
|
|
53
|
+
val leftTail = lettersThenDigits.find(left)
|
|
54
|
+
val rightTail = lettersThenDigits.find(right)
|
|
55
|
+
if (leftTail != null && rightTail != null && leftTail.groupValues[1] == rightTail.groupValues[1]) {
|
|
56
|
+
return leftTail.groupValues[2].toBigInteger().compareTo(rightTail.groupValues[2].toBigInteger())
|
|
57
|
+
}
|
|
58
|
+
return left.compareTo(right).coerceIn(-1, 1)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OTA version tags: `<base>-<prefix><N>`, e.g. `1.16.1-nu2`.
|
|
3
|
+
*
|
|
4
|
+
* `base` is the app's own version (package.json). `N` counts the OTA builds already published on that base in
|
|
5
|
+
* the channel, and starts again at 1 when the base changes. The tag sorts below its own base, so the store
|
|
6
|
+
* release of that base supersedes every OTA build of it — which is why the base must be ABOVE the native
|
|
7
|
+
* versionName the devices run: a tag on the same base as the installed binary is never offered to it.
|
|
8
|
+
*
|
|
9
|
+
* Pure functions only, so they can be unit-tested without a network or a file system.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const PREFIX_PATTERN = /^[a-z]+$/;
|
|
13
|
+
const BASE_PATTERN = /^\d+\.\d+\.\d+$/;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Validate the tag prefix (letters only, so the counter is the identifier's numeric tail).
|
|
17
|
+
*
|
|
18
|
+
* @param {string} prefix
|
|
19
|
+
* @returns {string} the prefix, lower-cased
|
|
20
|
+
*/
|
|
21
|
+
export function normalizePrefix(prefix) {
|
|
22
|
+
const value = String(prefix ?? '').trim().toLowerCase();
|
|
23
|
+
if (!PREFIX_PATTERN.test(value)) {
|
|
24
|
+
throw new Error(`--ota-tag needs a letters-only prefix such as "nu", not "${prefix}"`);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The base an OTA tag hangs from: a plain `major.minor.patch`.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} version e.g. "1.16.1" (a pre-release or build part is refused)
|
|
33
|
+
* @returns {string}
|
|
34
|
+
*/
|
|
35
|
+
export function normalizeBase(version) {
|
|
36
|
+
const value = String(version ?? '').trim().replace(/^v/i, '');
|
|
37
|
+
if (!BASE_PATTERN.test(value)) {
|
|
38
|
+
throw new Error(`OTA base version must be plain major.minor.patch, not "${version}"`);
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Compare two plain `major.minor.patch` versions.
|
|
45
|
+
*
|
|
46
|
+
* @returns {number} negative when `left` is older, 0 when equal, positive when newer
|
|
47
|
+
*/
|
|
48
|
+
export function compareBase(left, right) {
|
|
49
|
+
const a = left.split('.').map(Number);
|
|
50
|
+
const b = right.split('.').map(Number);
|
|
51
|
+
for (let index = 0; index < 3; index++) {
|
|
52
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
53
|
+
if (difference !== 0) return difference;
|
|
54
|
+
}
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The next OTA tag for `base`, given every version already published in the channel (any status: the server
|
|
60
|
+
* refuses a duplicate version even when the earlier build failed).
|
|
61
|
+
*
|
|
62
|
+
* @param {object} input
|
|
63
|
+
* @param {string} input.base app version, e.g. "1.16.1"
|
|
64
|
+
* @param {string} input.prefix tag prefix, e.g. "nu"
|
|
65
|
+
* @param {string[]} input.existingVersions versions already in the channel
|
|
66
|
+
* @returns {string} e.g. "1.16.1-nu3"
|
|
67
|
+
*/
|
|
68
|
+
export function nextOtaTag({ base, prefix, existingVersions }) {
|
|
69
|
+
const cleanBase = normalizeBase(base);
|
|
70
|
+
const cleanPrefix = normalizePrefix(prefix);
|
|
71
|
+
const pattern = new RegExp(`^${cleanBase.replace(/\./g, '\\.')}-${cleanPrefix}(\\d+)$`);
|
|
72
|
+
let highest = 0;
|
|
73
|
+
for (const version of existingVersions ?? []) {
|
|
74
|
+
const match = pattern.exec(String(version).trim());
|
|
75
|
+
if (match) highest = Math.max(highest, Number(match[1]));
|
|
76
|
+
}
|
|
77
|
+
return `${cleanBase}-${cleanPrefix}${highest + 1}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Refuse a base that devices on `nativeVersion` would never be offered.
|
|
82
|
+
*
|
|
83
|
+
* @param {string} base app version
|
|
84
|
+
* @param {string|null} nativeVersion the versionName of the native build in this tree, when known
|
|
85
|
+
* @returns {string|null} an error message, or null when the base is fine
|
|
86
|
+
*/
|
|
87
|
+
export function baseProblem(base, nativeVersion) {
|
|
88
|
+
if (!nativeVersion) return null;
|
|
89
|
+
const native = String(nativeVersion).trim().split(/[-+]/)[0];
|
|
90
|
+
if (!BASE_PATTERN.test(native)) return null;
|
|
91
|
+
if (compareBase(normalizeBase(base), native) > 0) return null;
|
|
92
|
+
return (
|
|
93
|
+
`Base ${base} is not above the native versionName ${native}: devices running ${native} would never be ` +
|
|
94
|
+
`offered ${base}-<tag>. Bump the patch first (yarn version --new-version patch --no-git-tag-version), ` +
|
|
95
|
+
'rebuild, and deploy again.'
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The version an OTA tag hangs from.
|
|
101
|
+
*
|
|
102
|
+
* The app's own version when it is above the native `versionName`; otherwise the native version's next patch
|
|
103
|
+
* (native 1.3.0 → 1.3.1), which is the version the next store release must carry. So an app that keeps its web
|
|
104
|
+
* version apart from its binary version still gets a tag every installed phone is offered.
|
|
105
|
+
*
|
|
106
|
+
* @param {string} appVersion package.json version
|
|
107
|
+
* @param {string|null} nativeVersion the versionName of the native build in this tree, when known
|
|
108
|
+
* @returns {string}
|
|
109
|
+
*/
|
|
110
|
+
export function otaBase(appVersion, nativeVersion) {
|
|
111
|
+
const app = normalizeBase(appVersion);
|
|
112
|
+
const native = nativeVersion ? String(nativeVersion).trim().split(/[-+]/)[0] : '';
|
|
113
|
+
if (!BASE_PATTERN.test(native) || compareBase(app, native) > 0) return app;
|
|
114
|
+
const [major, minor, patch] = native.split('.').map(Number);
|
|
115
|
+
return `${major}.${minor}.${patch + 1}`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Read `versionName` from an Android module's build.gradle (Groovy or Kotlin DSL).
|
|
120
|
+
*
|
|
121
|
+
* @param {string} gradleText the file's contents
|
|
122
|
+
* @returns {string|null}
|
|
123
|
+
*/
|
|
124
|
+
export function versionNameFromGradle(gradleText) {
|
|
125
|
+
const match = /versionName\s*=?\s*["']([^"']+)["']/.exec(gradleText ?? '');
|
|
126
|
+
return match ? match[1] : null;
|
|
127
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
import { baseProblem, nextOtaTag, otaBase, versionNameFromGradle } from './ota-tag-core.js';
|
|
5
|
+
import { apiClient } from './remote-shared.js';
|
|
6
|
+
|
|
7
|
+
/** Pages of 50 to read when looking for earlier tags on the same base (newest first). */
|
|
8
|
+
const MAX_PAGES = 10;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Every version already published in a channel, newest first, read through the management API.
|
|
12
|
+
*
|
|
13
|
+
* @param {ReturnType<import('./remote-shared.js').apiClient>} client
|
|
14
|
+
* @param {string} app app id or numeric id
|
|
15
|
+
* @param {string} channel
|
|
16
|
+
* @returns {Promise<string[]>}
|
|
17
|
+
*/
|
|
18
|
+
async function channelVersions(client, app, channel) {
|
|
19
|
+
const versions = [];
|
|
20
|
+
for (let page = 1; page <= MAX_PAGES; page++) {
|
|
21
|
+
const body = await client.get(`/apps/${app}/builds?channel=${encodeURIComponent(channel)}&per_page=50&page=${page}`);
|
|
22
|
+
for (const build of body.data ?? []) versions.push(String(build.version));
|
|
23
|
+
if (!body.meta || body.meta.current_page >= body.meta.last_page) break;
|
|
24
|
+
}
|
|
25
|
+
return versions;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The native versionName of the Android build in this tree, or null when there is none.
|
|
30
|
+
*
|
|
31
|
+
* @param {string|undefined} explicit `--native-version`
|
|
32
|
+
* @returns {Promise<string|null>}
|
|
33
|
+
*/
|
|
34
|
+
export async function nativeVersionName(explicit) {
|
|
35
|
+
if (explicit) return explicit;
|
|
36
|
+
for (const file of ['android/app/build.gradle', 'android/app/build.gradle.kts']) {
|
|
37
|
+
try {
|
|
38
|
+
const found = versionNameFromGradle(await fs.readFile(path.join(process.cwd(), file), 'utf-8'));
|
|
39
|
+
if (found) return found;
|
|
40
|
+
} catch {
|
|
41
|
+
// No Android module here; the caller decides whether that matters.
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Work out the OTA tag for this release.
|
|
49
|
+
*
|
|
50
|
+
* @param {object} input
|
|
51
|
+
* @param {ReturnType<import('./remote-shared.js').apiClient>} input.client
|
|
52
|
+
* @param {string} input.app
|
|
53
|
+
* @param {string} input.channel
|
|
54
|
+
* @param {string} input.base app version the tag hangs from
|
|
55
|
+
* @param {boolean} [input.explicit] true when the caller passed --version (checked, never moved)
|
|
56
|
+
* @param {string} input.prefix e.g. "nu"
|
|
57
|
+
* @param {string|undefined} input.nativeVersion `--native-version`
|
|
58
|
+
* @returns {Promise<{ tag: string, nativeVersion: string|null }>}
|
|
59
|
+
*/
|
|
60
|
+
export async function resolveOtaTag({ client, app, channel, base, explicit = false, prefix, nativeVersion }) {
|
|
61
|
+
const native = await nativeVersionName(nativeVersion);
|
|
62
|
+
// An explicit --version is the caller's choice and is only checked; the package.json default moves above the
|
|
63
|
+
// native versionName on its own.
|
|
64
|
+
let tagBase = base;
|
|
65
|
+
if (explicit) {
|
|
66
|
+
const problem = baseProblem(base, native);
|
|
67
|
+
if (problem) throw new Error(problem);
|
|
68
|
+
} else {
|
|
69
|
+
tagBase = otaBase(base, native);
|
|
70
|
+
}
|
|
71
|
+
const tag = nextOtaTag({ base: tagBase, prefix, existingVersions: await channelVersions(client, app, channel) });
|
|
72
|
+
return { tag, nativeVersion: native };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* `native-update ota-tag --app <id> --ota-tag nu` — print only the next tag, so a script that signs its bundle
|
|
77
|
+
* locally can stamp the same version into `bundle create` before `deploy`.
|
|
78
|
+
*
|
|
79
|
+
* @param {object} options commander options
|
|
80
|
+
*/
|
|
81
|
+
export async function otaTagCommand(options) {
|
|
82
|
+
const base = options.version ?? (await packageVersion());
|
|
83
|
+
if (!base) throw new Error('no --version, and no version found in ./package.json');
|
|
84
|
+
const { tag } = await resolveOtaTag({
|
|
85
|
+
client: apiClient(options),
|
|
86
|
+
app: options.app,
|
|
87
|
+
channel: options.channel,
|
|
88
|
+
base,
|
|
89
|
+
explicit: options.version !== undefined,
|
|
90
|
+
prefix: options.otaTag,
|
|
91
|
+
nativeVersion: options.nativeVersion,
|
|
92
|
+
});
|
|
93
|
+
process.stdout.write(`${tag}\n`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The version in ./package.json, or null. */
|
|
97
|
+
export async function packageVersion() {
|
|
98
|
+
try {
|
|
99
|
+
return JSON.parse(await fs.readFile(path.join(process.cwd(), 'package.json'), 'utf-8')).version ?? null;
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
package/cli/commands/remote.js
CHANGED
|
@@ -75,12 +75,45 @@ export async function buildsList(app, options) {
|
|
|
75
75
|
export async function deploy(target, options) {
|
|
76
76
|
const client = apiClient(options);
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
let version = options.version ?? (await versionFromPackageJson());
|
|
79
79
|
if (!version) {
|
|
80
80
|
console.error(chalk.red('Error: no --version, and no version found in ./package.json.'));
|
|
81
81
|
process.exit(1);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
// --ota-tag nu: publish as <version>-nu<N>, N counting this base's OTA builds in the channel. The minimum
|
|
85
|
+
// native version defaults to the native build in this tree, so the bundle never reaches an older binary
|
|
86
|
+
// that lacks the plugins this web build calls.
|
|
87
|
+
let minNative = options.minNative;
|
|
88
|
+
if (options.otaTag) {
|
|
89
|
+
try {
|
|
90
|
+
const { resolveOtaTag } = await import('./ota-tag.js');
|
|
91
|
+
const resolved = await resolveOtaTag({
|
|
92
|
+
client,
|
|
93
|
+
app: options.app,
|
|
94
|
+
channel: options.channel,
|
|
95
|
+
base: version,
|
|
96
|
+
explicit: options.version !== undefined,
|
|
97
|
+
prefix: options.otaTag,
|
|
98
|
+
nativeVersion: options.nativeVersion,
|
|
99
|
+
});
|
|
100
|
+
version = resolved.tag;
|
|
101
|
+
minNative = minNative ?? resolved.nativeVersion ?? undefined;
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.error(chalk.red(`Error: ${error.message}`));
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (options.dryRun) {
|
|
109
|
+
console.log(chalk.bold('\nDry run — nothing uploaded'));
|
|
110
|
+
console.log(chalk.gray(` App: ${options.app}`));
|
|
111
|
+
console.log(chalk.gray(` Version: ${version}`));
|
|
112
|
+
console.log(chalk.gray(` Channel: ${options.channel}`));
|
|
113
|
+
console.log(chalk.gray(` Min native: ${minNative ?? '(none)'}`));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
84
117
|
const bundle = await resolveBundle(target);
|
|
85
118
|
|
|
86
119
|
try {
|
|
@@ -89,6 +122,7 @@ export async function deploy(target, options) {
|
|
|
89
122
|
console.log(chalk.gray(` App: ${options.app}`));
|
|
90
123
|
console.log(chalk.gray(` Version: ${version}`));
|
|
91
124
|
console.log(chalk.gray(` Channel: ${options.channel}`));
|
|
125
|
+
if (minNative) console.log(chalk.gray(` Min native: ${minNative}`));
|
|
92
126
|
console.log(chalk.gray(` Bundle: ${(stat.size / 1024 / 1024).toFixed(2)} MB`));
|
|
93
127
|
|
|
94
128
|
// A detached signature from `native-update bundle sign`, if the consumer
|
|
@@ -124,7 +158,7 @@ export async function deploy(target, options) {
|
|
|
124
158
|
channel: options.channel,
|
|
125
159
|
release_notes: options.notes,
|
|
126
160
|
rollout_percentage: options.rollout,
|
|
127
|
-
min_native_version:
|
|
161
|
+
min_native_version: minNative,
|
|
128
162
|
signature: signature?.value,
|
|
129
163
|
});
|
|
130
164
|
|
package/cli/index.js
CHANGED
|
@@ -245,6 +245,9 @@ ${chalk.bold('Examples:')}
|
|
|
245
245
|
${chalk.gray('# Block until the release is actually live (recommended in CI)')}
|
|
246
246
|
${chalk.green('npx native-update deploy ./dist --app com.example.app --wait')}
|
|
247
247
|
|
|
248
|
+
${chalk.gray('# OTA tag: 1.16.1 → 1.16.1-nu1, then -nu2 … until the version changes')}
|
|
249
|
+
${chalk.green('npx native-update deploy ./dist --app com.example.app --ota-tag nu --wait')}
|
|
250
|
+
|
|
248
251
|
${chalk.gray('# Staged rollout with release notes')}
|
|
249
252
|
${chalk.green('npx native-update deploy ./bundle.zip --app 12 --version 1.2.0 --rollout 10 --notes "Bug fixes"')}`)
|
|
250
253
|
.requiredOption('-a, --app <appIdOrNumericId>', 'App to deploy to (app_id like com.example.app, or numeric id)')
|
|
@@ -261,11 +264,34 @@ ${chalk.bold('Examples:')}
|
|
|
261
264
|
.option('--runtime-keys <keys>', 'dart_aot only: comma-separated engine keys (auto-read from a sibling .runtime-keys)')
|
|
262
265
|
.option('--signature <file>', 'Detached signature from `bundle sign` (auto-detects a sibling .sig)')
|
|
263
266
|
.option('-w, --wait', 'Wait for processing to finish (exit non-zero if it fails)', false)
|
|
267
|
+
.option('--ota-tag <prefix>', 'Publish as <version>-<prefix><N> (e.g. nu → 1.16.1-nu2); N restarts at 1 when the version changes')
|
|
268
|
+
.option('--native-version <version>', 'Native versionName the devices run (default: android/app/build.gradle)')
|
|
269
|
+
.option('--dry-run', 'Print the version, channel and minimum native version, upload nothing', false)
|
|
264
270
|
).action(async (target, options) => {
|
|
265
271
|
const { deploy } = await import('./commands/remote.js');
|
|
266
272
|
await deploy(target, options);
|
|
267
273
|
});
|
|
268
274
|
|
|
275
|
+
// ota-tag — print the next OTA tag only (for scripts that sign the bundle locally)
|
|
276
|
+
remoteAuthOptions(
|
|
277
|
+
program
|
|
278
|
+
.command('ota-tag')
|
|
279
|
+
.description('Print the next OTA tag for this app and channel, e.g. 1.16.1-nu3')
|
|
280
|
+
.requiredOption('-a, --app <appIdOrNumericId>', 'App (app_id like com.example.app, or numeric id)')
|
|
281
|
+
.option('-v, --version <version>', 'Base version (defaults to ./package.json version)')
|
|
282
|
+
.option('-c, --channel <channel>', 'Release channel', 'production')
|
|
283
|
+
.option('--ota-tag <prefix>', 'Tag prefix', 'nu')
|
|
284
|
+
.option('--native-version <version>', 'Native versionName the devices run (default: android/app/build.gradle)')
|
|
285
|
+
).action(async (options) => {
|
|
286
|
+
const { otaTagCommand } = await import('./commands/ota-tag.js');
|
|
287
|
+
try {
|
|
288
|
+
await otaTagCommand(options);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
console.error(chalk.red(`Error: ${error.message}`));
|
|
291
|
+
process.exit(1);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
269
295
|
// apps
|
|
270
296
|
const appsCmd = program
|
|
271
297
|
.command('apps')
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Logger } from '../core/logger';
|
|
2
|
+
import { compareVersions as compareVersionOrder } from '../core/version-order';
|
|
2
3
|
export class AppUpdateChecker {
|
|
3
4
|
constructor(config) {
|
|
4
5
|
this.cachedAppInfo = null;
|
|
@@ -63,17 +64,7 @@ export class AppUpdateChecker {
|
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
compareVersions(version1, version2) {
|
|
66
|
-
|
|
67
|
-
const v2Parts = version2.split('.').map(Number);
|
|
68
|
-
for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
|
|
69
|
-
const v1Part = v1Parts[i] || 0;
|
|
70
|
-
const v2Part = v2Parts[i] || 0;
|
|
71
|
-
if (v1Part > v2Part)
|
|
72
|
-
return 1;
|
|
73
|
-
if (v1Part < v2Part)
|
|
74
|
-
return -1;
|
|
75
|
-
}
|
|
76
|
-
return 0;
|
|
67
|
+
return compareVersionOrder(version1, version2);
|
|
77
68
|
}
|
|
78
69
|
isUpdateRequired(currentVersion, availableVersion, minimumVersion) {
|
|
79
70
|
// Check if current version is less than available
|
|
@@ -2,6 +2,7 @@ import { BackgroundUpdateType, UpdateErrorCode } from '../definitions';
|
|
|
2
2
|
import { Logger } from '../core/logger';
|
|
3
3
|
import { ConfigManager } from '../core/config';
|
|
4
4
|
import { checkForUpdate } from '../core/update-check';
|
|
5
|
+
import { compareVersions as compareVersionOrder } from '../core/version-order';
|
|
5
6
|
export class BackgroundScheduler {
|
|
6
7
|
constructor() {
|
|
7
8
|
this.config = null;
|
|
@@ -317,16 +318,6 @@ export class BackgroundScheduler {
|
|
|
317
318
|
return true;
|
|
318
319
|
}
|
|
319
320
|
compareVersions(version1, version2) {
|
|
320
|
-
|
|
321
|
-
const v2Parts = version2.split('.').map(Number);
|
|
322
|
-
for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
|
|
323
|
-
const v1Part = v1Parts[i] || 0;
|
|
324
|
-
const v2Part = v2Parts[i] || 0;
|
|
325
|
-
if (v1Part > v2Part)
|
|
326
|
-
return 1;
|
|
327
|
-
if (v1Part < v2Part)
|
|
328
|
-
return -1;
|
|
329
|
-
}
|
|
330
|
-
return 0;
|
|
321
|
+
return compareVersionOrder(version1, version2);
|
|
331
322
|
}
|
|
332
323
|
}
|
|
@@ -60,7 +60,7 @@ import type { AppIdentity } from '../types/app-identity';
|
|
|
60
60
|
* This plugin's version, sent as `X-Sdk-Version`. Kept equal to package.json (and to the Kotlin and Swift
|
|
61
61
|
* constants) by tests/sdk-version.test.ts.
|
|
62
62
|
*/
|
|
63
|
-
export declare const SDK_VERSION = "4.4.
|
|
63
|
+
export declare const SDK_VERSION = "4.4.2";
|
|
64
64
|
/** Request inputs for a single backend update check. */
|
|
65
65
|
export interface UpdateCheckRequest {
|
|
66
66
|
/** API key issued by the dashboard; sent as `X-API-Key`. Required. */
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
* This plugin's version, sent as `X-Sdk-Version`. Kept equal to package.json (and to the Kotlin and Swift
|
|
60
60
|
* constants) by tests/sdk-version.test.ts.
|
|
61
61
|
*/
|
|
62
|
-
export const SDK_VERSION = '4.4.
|
|
62
|
+
export const SDK_VERSION = '4.4.2';
|
|
63
63
|
/**
|
|
64
64
|
* Perform one update check against the Native Update backend.
|
|
65
65
|
*
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one version order every part of the plugin uses.
|
|
3
|
+
*
|
|
4
|
+
* Semver precedence (2.0.0 §11), with one deliberate refinement: an
|
|
5
|
+
* alphanumeric pre-release identifier that ends in digits compares its letters
|
|
6
|
+
* first and then its digits as a NUMBER. Strict semver compares `nu10` and
|
|
7
|
+
* `nu9` as plain ASCII, so the tenth OTA of a day would sort below the ninth.
|
|
8
|
+
*
|
|
9
|
+
* OTA tags look like `1.16.1-nu2`: base `1.16.1`, the second over-the-air
|
|
10
|
+
* build on that base. They sort below `1.16.1` itself, so a store release of
|
|
11
|
+
* the same base always supersedes its OTA builds. The server's PHP
|
|
12
|
+
* `version_compare` orders these the same way.
|
|
13
|
+
*
|
|
14
|
+
* Build metadata (`+…`) is ignored, as semver requires.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Compare two versions.
|
|
18
|
+
*
|
|
19
|
+
* @returns -1 when `left` is older, 0 when equal, 1 when `left` is newer.
|
|
20
|
+
*/
|
|
21
|
+
export declare function compareVersions(left: string, right: string): number;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one version order every part of the plugin uses.
|
|
3
|
+
*
|
|
4
|
+
* Semver precedence (2.0.0 §11), with one deliberate refinement: an
|
|
5
|
+
* alphanumeric pre-release identifier that ends in digits compares its letters
|
|
6
|
+
* first and then its digits as a NUMBER. Strict semver compares `nu10` and
|
|
7
|
+
* `nu9` as plain ASCII, so the tenth OTA of a day would sort below the ninth.
|
|
8
|
+
*
|
|
9
|
+
* OTA tags look like `1.16.1-nu2`: base `1.16.1`, the second over-the-air
|
|
10
|
+
* build on that base. They sort below `1.16.1` itself, so a store release of
|
|
11
|
+
* the same base always supersedes its OTA builds. The server's PHP
|
|
12
|
+
* `version_compare` orders these the same way.
|
|
13
|
+
*
|
|
14
|
+
* Build metadata (`+…`) is ignored, as semver requires.
|
|
15
|
+
*/
|
|
16
|
+
function parse(version) {
|
|
17
|
+
const withoutBuild = version.trim().replace(/^v/i, '').split('+')[0];
|
|
18
|
+
const dash = withoutBuild.indexOf('-');
|
|
19
|
+
const coreText = dash === -1 ? withoutBuild : withoutBuild.slice(0, dash);
|
|
20
|
+
const preText = dash === -1 ? '' : withoutBuild.slice(dash + 1);
|
|
21
|
+
const core = coreText.split('.').map((part) => {
|
|
22
|
+
const value = Number.parseInt(part, 10);
|
|
23
|
+
return Number.isFinite(value) ? value : 0;
|
|
24
|
+
});
|
|
25
|
+
return { core, pre: preText === '' ? [] : preText.split('.') };
|
|
26
|
+
}
|
|
27
|
+
const NUMERIC = /^\d+$/;
|
|
28
|
+
const LETTERS_THEN_DIGITS = /^(.*?)(\d+)$/;
|
|
29
|
+
function compareIdentifier(left, right) {
|
|
30
|
+
const leftNumeric = NUMERIC.test(left);
|
|
31
|
+
const rightNumeric = NUMERIC.test(right);
|
|
32
|
+
if (leftNumeric && rightNumeric)
|
|
33
|
+
return Math.sign(Number(left) - Number(right));
|
|
34
|
+
// Semver: numeric identifiers always rank below alphanumeric ones.
|
|
35
|
+
if (leftNumeric)
|
|
36
|
+
return -1;
|
|
37
|
+
if (rightNumeric)
|
|
38
|
+
return 1;
|
|
39
|
+
const leftTail = LETTERS_THEN_DIGITS.exec(left);
|
|
40
|
+
const rightTail = LETTERS_THEN_DIGITS.exec(right);
|
|
41
|
+
if (leftTail && rightTail && leftTail[1] === rightTail[1]) {
|
|
42
|
+
return Math.sign(Number(leftTail[2]) - Number(rightTail[2]));
|
|
43
|
+
}
|
|
44
|
+
if (left === right)
|
|
45
|
+
return 0;
|
|
46
|
+
return left < right ? -1 : 1;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Compare two versions.
|
|
50
|
+
*
|
|
51
|
+
* @returns -1 when `left` is older, 0 when equal, 1 when `left` is newer.
|
|
52
|
+
*/
|
|
53
|
+
export function compareVersions(left, right) {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
const a = parse(left);
|
|
56
|
+
const b = parse(right);
|
|
57
|
+
const length = Math.max(a.core.length, b.core.length, 3);
|
|
58
|
+
for (let index = 0; index < length; index++) {
|
|
59
|
+
const difference = ((_a = a.core[index]) !== null && _a !== void 0 ? _a : 0) - ((_b = b.core[index]) !== null && _b !== void 0 ? _b : 0);
|
|
60
|
+
if (difference !== 0)
|
|
61
|
+
return Math.sign(difference);
|
|
62
|
+
}
|
|
63
|
+
// A version without a pre-release ranks above the same version with one.
|
|
64
|
+
if (a.pre.length === 0 && b.pre.length === 0)
|
|
65
|
+
return 0;
|
|
66
|
+
if (a.pre.length === 0)
|
|
67
|
+
return 1;
|
|
68
|
+
if (b.pre.length === 0)
|
|
69
|
+
return -1;
|
|
70
|
+
const identifiers = Math.max(a.pre.length, b.pre.length);
|
|
71
|
+
for (let index = 0; index < identifiers; index++) {
|
|
72
|
+
const leftId = a.pre[index];
|
|
73
|
+
const rightId = b.pre[index];
|
|
74
|
+
if (leftId === undefined)
|
|
75
|
+
return -1;
|
|
76
|
+
if (rightId === undefined)
|
|
77
|
+
return 1;
|
|
78
|
+
const result = compareIdentifier(leftId, rightId);
|
|
79
|
+
if (result !== 0)
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export { CacheManager } from './core/cache-manager';
|
|
|
11
11
|
export { BundleManager } from './live-update/bundle-manager';
|
|
12
12
|
export { DownloadManager } from './live-update/download-manager';
|
|
13
13
|
export { VersionManager } from './live-update/version-manager';
|
|
14
|
+
export { compareVersions } from './core/version-order';
|
|
14
15
|
export { UpdateManager } from './live-update/update-manager';
|
package/dist/esm/index.js
CHANGED
|
@@ -15,4 +15,5 @@ export { CacheManager } from './core/cache-manager';
|
|
|
15
15
|
export { BundleManager } from './live-update/bundle-manager';
|
|
16
16
|
export { DownloadManager } from './live-update/download-manager';
|
|
17
17
|
export { VersionManager } from './live-update/version-manager';
|
|
18
|
+
export { compareVersions } from './core/version-order';
|
|
18
19
|
export { UpdateManager } from './live-update/update-manager';
|