@gfean/react-native-bundle-drop 0.2.1 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gfean/react-native-bundle-drop",
3
- "version": "0.2.1",
3
+ "version": "0.3.2",
4
4
  "description": "react native ota by gFean",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -20,7 +20,12 @@
20
20
  },
21
21
  "scripts": {
22
22
  "clean": "rimraf lib dist",
23
- "build": "tsc -p tsconfig.json && node scripts/make-cli-executable.js",
23
+ "build": "tsc -p tsconfig.build.json && node scripts/make-cli-executable.js",
24
+ "prepare": "husky",
25
+ "test": "jest --runInBand",
26
+ "test:coverage": "jest --runInBand --coverage",
27
+ "coverage:check": "node scripts/check-coverage-thresholds.cjs",
28
+ "coverage:gate": "yarn test:coverage && yarn coverage:check",
24
29
  "prepublishOnly": "yarn clean && yarn build",
25
30
  "build-and-publish": "yarn clean && yarn build && npm publish --access=restricted",
26
31
  "publish:local": "yalc publish --private"
@@ -31,10 +36,16 @@
31
36
  "version": "0.49.6"
32
37
  },
33
38
  "devDependencies": {
39
+ "@types/jest": "^29.5.14",
34
40
  "@types/node": "^24.10.1",
35
41
  "@types/react": "^18.2.66",
36
42
  "@types/react-native": "^0.73.0",
43
+ "husky": "^9.1.7",
44
+ "jest": "^29.7.0",
45
+ "react": "^18.3.1",
46
+ "react-test-renderer": "^18.3.1",
37
47
  "rimraf": "^6.0.1",
48
+ "ts-jest": "^29.4.4",
38
49
  "ts-node": "^10.9.2",
39
50
  "typescript": "^5.8.3"
40
51
  },
@@ -1,10 +0,0 @@
1
- import { UpdatePolicy } from '../types';
2
- export declare function isUpdateFlowActive(): boolean;
3
- export declare function acquireUpdateLock(): boolean;
4
- export declare function releaseUpdateLock(): void;
5
- export declare function initUpdateManager(opts?: {
6
- channelName?: string;
7
- policy?: UpdatePolicy;
8
- onStatusUpdate?: (status: string) => void;
9
- checkOnly?: boolean;
10
- }): Promise<void>;
@@ -1,137 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUpdateFlowActive = isUpdateFlowActive;
4
- exports.acquireUpdateLock = acquireUpdateLock;
5
- exports.releaseUpdateLock = releaseUpdateLock;
6
- exports.initUpdateManager = initUpdateManager;
7
- const downloadAndInstall_1 = require("./downloadAndInstall");
8
- const updateCheck_1 = require("./updateCheck");
9
- const updateState_1 = require("./updateState");
10
- const rollbackState_1 = require("./rollbackState");
11
- const bundleInfo_1 = require("../bundleInfo");
12
- const context_1 = require("../context");
13
- const bundlePointer_1 = require("../fs/bundlePointer");
14
- const bundleDropNative_1 = require("../native/bundleDropNative");
15
- let _updateFlowActive = false;
16
- function isUpdateFlowActive() {
17
- return _updateFlowActive;
18
- }
19
- function acquireUpdateLock() {
20
- if (_updateFlowActive)
21
- return false;
22
- _updateFlowActive = true;
23
- return true;
24
- }
25
- function releaseUpdateLock() {
26
- _updateFlowActive = false;
27
- }
28
- async function initUpdateManager(opts) {
29
- if (!acquireUpdateLock())
30
- return;
31
- try {
32
- await _initUpdateManagerInner(opts);
33
- }
34
- finally {
35
- releaseUpdateLock();
36
- }
37
- }
38
- async function _initUpdateManagerInner(opts) {
39
- const policy = opts?.policy || 'manual';
40
- const channelName = opts?.channelName || context_1.defaultChannel;
41
- const statusCb = opts?.onStatusUpdate;
42
- // Prefetch all startup data in parallel (single bridge round-trip instead of
43
- // 8+ sequential reads across reconcile / rollback / commit / getUpdateState).
44
- const [bundleInfo, bundlePath, currentPointer, rollbackStateData] = await Promise.all([
45
- (0, bundleInfo_1.readBundleInfo)(),
46
- (0, bundleDropNative_1.getDownloadedBundlePathNative)(),
47
- (0, bundlePointer_1.readCurrentBundlePointer)(),
48
- (0, rollbackState_1.readRollbackState)(),
49
- ]);
50
- await (0, updateState_1.reconcileAppliedBundleOnLaunch)({ bundleInfo, bundlePath });
51
- const rollbackPolicy = (0, rollbackState_1.getRollbackPolicy)();
52
- const rollbackResult = await (0, rollbackState_1.rollbackToPreviousIfNeeded)(rollbackPolicy, {
53
- currentPointer,
54
- rollbackState: rollbackStateData,
55
- });
56
- if (rollbackResult.rolledBack) {
57
- statusCb?.('↩️ Rolled back to previous bundle');
58
- (0, bundleDropNative_1.restartReactNativeNative)();
59
- return;
60
- }
61
- await (0, rollbackState_1.commitActiveBundle)({ currentPointer });
62
- // bundlePath hasn't changed; let bundleInfo re-read (reconcile may have updated it).
63
- const pendingState = await (0, updateState_1.getUpdateState)({ bundlePath });
64
- if (pendingState.pendingApply) {
65
- if (policy === 'immediate') {
66
- statusCb?.('♻️ Applying previously downloaded update...');
67
- const applyResult = await (0, updateState_1.applyUpdate)(statusCb);
68
- if (applyResult.status === 'applied')
69
- return;
70
- // 'alreadyApplied' or 'noBundle' — fall through to checkForUpdate
71
- }
72
- if (policy === 'on-next-launch') {
73
- statusCb?.('✅ Update downloaded; will apply on next launch.');
74
- return;
75
- }
76
- }
77
- // Resolve server decision once (covers INSTALL, ROLLBACK, NOOP).
78
- const decision = await (0, updateCheck_1.checkForUpdate)(channelName, statusCb);
79
- if (!decision) {
80
- statusCb?.('⚠️ Unable to check for updates. Try again.');
81
- return;
82
- }
83
- if (decision.action === 'ROLLBACK') {
84
- statusCb?.('↩️ Server requested rollback...');
85
- await (0, rollbackState_1.rollbackToPreviousOrNative)();
86
- (0, bundleDropNative_1.restartReactNativeNative)();
87
- return;
88
- }
89
- if (decision.action === 'NOOP') {
90
- if (decision.incompatible) {
91
- statusCb?.('⛔️ No compatible update for this binary');
92
- return;
93
- }
94
- if (opts?.checkOnly)
95
- statusCb?.('✅ You have the latest version');
96
- return;
97
- }
98
- // INSTALL available
99
- if (policy === 'manual') {
100
- // Check-only mode is already handled by checkForUpdate status updates; no auto download/apply.
101
- return;
102
- }
103
- const resolvedTarget = decision.downloadUrl && decision.hash
104
- ? {
105
- hash: decision.hash,
106
- downloadUrl: decision.downloadUrl,
107
- bundleVersion: decision.bundleVersion,
108
- version: decision.version,
109
- runtimeVersion: decision.runtimeVersion,
110
- }
111
- : undefined;
112
- if (!resolvedTarget) {
113
- statusCb?.('⚠️ Update available but missing download URL');
114
- return;
115
- }
116
- if (policy === 'on-next-launch') {
117
- const res = await (0, downloadAndInstall_1.downloadUpdate)({ channelName, resolvedTarget }, statusCb || (() => { }));
118
- if (res.status === 'staged')
119
- statusCb?.('✅ Update downloaded for next launch');
120
- if (res.status === 'upToDate')
121
- statusCb?.('✅ You have the latest version');
122
- if (res.status === 'incompatible')
123
- statusCb?.('⛔️ No compatible update for this binary');
124
- return;
125
- }
126
- // immediate
127
- const res = await (0, downloadAndInstall_1.downloadUpdate)({ channelName, resolvedTarget }, statusCb || (() => { }));
128
- if (res.status === 'staged') {
129
- await (0, updateState_1.applyUpdate)(statusCb);
130
- return;
131
- }
132
- if (res.status === 'upToDate')
133
- statusCb?.('✅ You have the latest version');
134
- if (res.status === 'incompatible')
135
- statusCb?.('⛔️ No compatible update for this binary');
136
- return;
137
- }