react-native-store-version 1.4.2 → 2.0.0-beta.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.
Files changed (149) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +514 -43
  3. package/dist/checkVersion.d.ts +73 -0
  4. package/dist/checkVersion.d.ts.map +1 -0
  5. package/dist/checkVersion.js +193 -0
  6. package/dist/cli/check.js +38 -0
  7. package/dist/cli/checks/ids.js +111 -0
  8. package/dist/cli/checks/installed.js +51 -0
  9. package/dist/cli/checks/peers.js +31 -0
  10. package/dist/cli/checks/rollout.js +141 -0
  11. package/dist/cli/checks/store.js +71 -0
  12. package/dist/cli/checks/versions.js +83 -0
  13. package/dist/cli/index.js +43 -0
  14. package/dist/cli/main.js +182 -0
  15. package/dist/cli/output.js +77 -0
  16. package/dist/cli/packages.js +40 -0
  17. package/dist/cli/project/android.js +60 -0
  18. package/dist/cli/project/expo.js +194 -0
  19. package/dist/cli/project/files.js +42 -0
  20. package/dist/cli/project/gradle.js +145 -0
  21. package/dist/cli/project/index.js +10 -0
  22. package/dist/cli/project/ios.js +190 -0
  23. package/dist/cli/project/jsx.js +327 -0
  24. package/dist/cli/project/plist.js +166 -0
  25. package/dist/cli/project/sources.js +86 -0
  26. package/dist/cli/result.js +12 -0
  27. package/dist/compare.d.ts +31 -0
  28. package/dist/compare.d.ts.map +1 -0
  29. package/dist/compare.js +68 -0
  30. package/dist/detect.d.ts +68 -0
  31. package/dist/detect.d.ts.map +1 -0
  32. package/dist/detect.js +103 -0
  33. package/dist/errors.d.ts +33 -0
  34. package/dist/errors.d.ts.map +1 -0
  35. package/dist/errors.js +23 -0
  36. package/dist/fetchers/android.d.ts +53 -0
  37. package/dist/fetchers/android.d.ts.map +1 -0
  38. package/dist/fetchers/android.js +91 -0
  39. package/dist/fetchers/custom.d.ts +29 -0
  40. package/dist/fetchers/custom.d.ts.map +1 -0
  41. package/dist/fetchers/custom.js +41 -0
  42. package/dist/fetchers/ios.d.ts +61 -0
  43. package/dist/fetchers/ios.d.ts.map +1 -0
  44. package/dist/fetchers/ios.js +79 -0
  45. package/dist/index.d.ts +15 -14
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +9 -58
  48. package/dist/openStore.d.ts +29 -0
  49. package/dist/openStore.d.ts.map +1 -0
  50. package/dist/openStore.js +46 -0
  51. package/dist/policy.d.ts +75 -0
  52. package/dist/policy.d.ts.map +1 -0
  53. package/dist/policy.js +128 -0
  54. package/dist/react/DefaultForceModal.d.ts +26 -0
  55. package/dist/react/DefaultForceModal.d.ts.map +1 -0
  56. package/dist/react/DefaultForceModal.js +58 -0
  57. package/dist/react/DefaultWarningSheet.d.ts +26 -0
  58. package/dist/react/DefaultWarningSheet.d.ts.map +1 -0
  59. package/dist/react/DefaultWarningSheet.js +66 -0
  60. package/dist/react/StoreVersionModal.d.ts +52 -0
  61. package/dist/react/StoreVersionModal.d.ts.map +1 -0
  62. package/dist/react/StoreVersionModal.js +250 -0
  63. package/dist/react/StoreVersionProvider.d.ts +51 -0
  64. package/dist/react/StoreVersionProvider.d.ts.map +1 -0
  65. package/dist/react/StoreVersionProvider.js +69 -0
  66. package/dist/react/defaultUi.d.ts +72 -0
  67. package/dist/react/defaultUi.d.ts.map +1 -0
  68. package/dist/react/defaultUi.js +118 -0
  69. package/dist/react/engine.d.ts +146 -0
  70. package/dist/react/engine.d.ts.map +1 -0
  71. package/dist/react/engine.js +541 -0
  72. package/dist/react/texts.d.ts +43 -0
  73. package/dist/react/texts.d.ts.map +1 -0
  74. package/dist/react/texts.js +57 -0
  75. package/dist/react/useIsomorphicLayoutEffect.d.ts +3 -0
  76. package/dist/react/useIsomorphicLayoutEffect.d.ts.map +1 -0
  77. package/dist/react/useIsomorphicLayoutEffect.js +6 -0
  78. package/dist/react/useStoreVersion.d.ts +121 -0
  79. package/dist/react/useStoreVersion.d.ts.map +1 -0
  80. package/dist/react/useStoreVersion.js +23 -0
  81. package/dist/request.d.ts +78 -0
  82. package/dist/request.d.ts.map +1 -0
  83. package/dist/request.js +227 -0
  84. package/dist/resolve.d.ts +98 -0
  85. package/dist/resolve.d.ts.map +1 -0
  86. package/dist/resolve.js +218 -0
  87. package/dist/texts/ja.d.ts +8 -0
  88. package/dist/texts/ja.d.ts.map +1 -0
  89. package/dist/texts/ja.js +18 -0
  90. package/dist/vendor/compare-versions.d.ts +52 -0
  91. package/dist/vendor/compare-versions.d.ts.map +1 -0
  92. package/dist/vendor/compare-versions.js +111 -0
  93. package/package.json +83 -44
  94. package/src/checkVersion.ts +273 -0
  95. package/src/cli/check.ts +59 -0
  96. package/src/cli/checks/ids.ts +163 -0
  97. package/src/cli/checks/installed.ts +75 -0
  98. package/src/cli/checks/peers.ts +34 -0
  99. package/src/cli/checks/rollout.ts +183 -0
  100. package/src/cli/checks/store.ts +105 -0
  101. package/src/cli/checks/versions.ts +108 -0
  102. package/src/cli/index.ts +51 -0
  103. package/src/cli/main.ts +229 -0
  104. package/src/cli/output.ts +122 -0
  105. package/src/cli/packages.ts +43 -0
  106. package/src/cli/project/android.ts +96 -0
  107. package/src/cli/project/expo.ts +232 -0
  108. package/src/cli/project/files.ts +56 -0
  109. package/src/cli/project/gradle.ts +181 -0
  110. package/src/cli/project/index.ts +18 -0
  111. package/src/cli/project/ios.ts +284 -0
  112. package/src/cli/project/jsx.ts +354 -0
  113. package/src/cli/project/plist.ts +179 -0
  114. package/src/cli/project/sources.ts +118 -0
  115. package/src/cli/result.ts +34 -0
  116. package/src/compare.ts +101 -0
  117. package/src/detect.ts +178 -0
  118. package/src/errors.ts +63 -0
  119. package/src/fetchers/android.ts +136 -0
  120. package/src/fetchers/custom.ts +84 -0
  121. package/src/fetchers/ios.ts +160 -0
  122. package/src/index.ts +37 -0
  123. package/src/openStore.ts +74 -0
  124. package/src/policy.ts +223 -0
  125. package/src/react/DefaultForceModal.tsx +100 -0
  126. package/src/react/DefaultWarningSheet.tsx +115 -0
  127. package/src/react/StoreVersionModal.tsx +365 -0
  128. package/src/react/StoreVersionProvider.tsx +149 -0
  129. package/src/react/defaultUi.tsx +205 -0
  130. package/src/react/engine.ts +768 -0
  131. package/src/react/texts.ts +119 -0
  132. package/src/react/useIsomorphicLayoutEffect.ts +8 -0
  133. package/src/react/useStoreVersion.ts +153 -0
  134. package/src/request.ts +328 -0
  135. package/src/resolve.ts +388 -0
  136. package/src/texts/ja.ts +26 -0
  137. package/src/vendor/compare-versions.ts +128 -0
  138. package/texts/ja.d.ts +2 -0
  139. package/texts/ja.js +3 -0
  140. package/.eslintrc.js +0 -51
  141. package/.github/FUNDING.yml +0 -3
  142. package/.github/workflows/pr.yml +0 -48
  143. package/.github/workflows/release.yml +0 -259
  144. package/.prettierrc.js +0 -6
  145. package/babel.config.js +0 -3
  146. package/dist/android.d.ts +0 -1
  147. package/dist/android.js +0 -17
  148. package/dist/ios.d.ts +0 -1
  149. package/dist/ios.js +0 -18
@@ -0,0 +1,218 @@
1
+ // fetcher / custom / policy / compare を束ねて 1 回の判定を行う層。Provider はこれを呼ぶだけにする。
2
+ // React にも react-native にも依存しない(platform は引数で受け取る。Node でも動く)
3
+ import { assertValidVersion, } from './compare.js';
4
+ import { StoreVersionError } from './errors.js';
5
+ import { fetchAndroidVersion, playStoreUrl } from './fetchers/android.js';
6
+ import { callLatestVersion, callMinimumVersion, } from './fetchers/custom.js';
7
+ import { lookupIOS, lookupStoreUrl, storeUrlUnavailable, toStoreUrlResult, } from './fetchers/ios.js';
8
+ import { evaluatePolicy, minimumVersionError, validatePolicy, } from './policy.js';
9
+ import { createAbortError, createScope, raceAbort } from './request.js';
10
+ // 判定を止めたエラーに添える、止めなかったエラーの一覧。エラーのオブジェクト自体には何も足さない
11
+ // (StoreVersionError の形を変えないため)。エラーと一緒に捨てられるので、キャッシュにはならない
12
+ const attached = new WeakMap();
13
+ /**
14
+ * {@link resolve} が reject したエラーに添えた、`onError` に渡すべきほかのエラー(無ければ空)。
15
+ * 例: 最新バージョンと最低バージョンがどちらも比較できないときは、reject の `INVALID_VERSION` に
16
+ * `MINIMUM_VERSION_FAILED` が添えてある(開発者のバグを onError で気づけるように)
17
+ */
18
+ export const attachedErrorsOf = (error) => (typeof error === 'object' && error !== null && attached.get(error)) || [];
19
+ const attach = (error, errors) => {
20
+ if (errors.length > 0 && typeof error === 'object' && error !== null) {
21
+ attached.set(error, errors);
22
+ }
23
+ return error;
24
+ };
25
+ const fetchLatest = ({ platform, appId, country, getLatestVersion }, signal) => {
26
+ if (getLatestVersion) {
27
+ return callLatestVersion(getLatestVersion, { platform, signal }).then((latest) => ({ latest, storeUrl: null }));
28
+ }
29
+ if (platform === 'ios') {
30
+ return lookupIOS({ bundleId: appId }, country, { signal }).then(({ version, storeUrl, releaseNotes }) => releaseNotes === undefined
31
+ ? { latest: version, storeUrl }
32
+ : { latest: version, storeUrl, releaseNotes });
33
+ }
34
+ return fetchAndroidVersion({ packageName: appId }, { signal }).then(({ version }) => ({ latest: version, storeUrl: null }), (error) => {
35
+ // 版を取れない(Varies with device / 比較できない版)でも、最低バージョンが有効で local がそれ未満なら force にする。
36
+ // ここでは止めずに判定に回す
37
+ if (error instanceof StoreVersionError &&
38
+ error.code === 'INVALID_VERSION') {
39
+ return { latest: null, latestError: error, storeUrl: null };
40
+ }
41
+ throw error;
42
+ });
43
+ };
44
+ /** 最低バージョンの取得の結果から、`onError` に渡すべきエラー(getter の失敗 / 比較できない値) */
45
+ const minimumErrorsOf = (minimum) => {
46
+ if (!minimum) {
47
+ return [];
48
+ }
49
+ if (minimum.error) {
50
+ return [minimum.error];
51
+ }
52
+ const invalid = minimumVersionError(minimum.minimum);
53
+ return invalid ? [invalid] : [];
54
+ };
55
+ /**
56
+ * 1 回の判定を行う。latest(ストア / `getLatestVersion`)と minimum(`getMinimumVersion`)は並行に取得し、
57
+ * `evaluatePolicy` で判定する。
58
+ *
59
+ * 判定を止めるエラーは `StoreVersionError` で reject する(`onError` に渡す。UI は出さない):
60
+ * - `POLICY_FAILED`: 値で指定した policy が不正(取得の前に検証する)/ policy の関数が throw・不正な値
61
+ * - `INVALID_VERSION`: local が比較できない(取得の前に検証する)/ 最新が比較できず、最低バージョンでも force にならない
62
+ * - `TIMEOUT`: 最新バージョン(ストア / `getLatestVersion`)が `timeoutMs` までに取れない
63
+ * (最低バージョンだけが間に合わないときは止めず、`MINIMUM_VERSION_FAILED` を `errors` に入れて続ける)
64
+ * - `NETWORK` / `NOT_FOUND` / `PARSE_FAILED`: ストアの取得の失敗
65
+ * - `LATEST_VERSION_FAILED`: `getLatestVersion` の失敗(ストアにはフォールバックしない)
66
+ * - `signal` の abort は `AbortError`
67
+ *
68
+ * reject したエラーに、止めなかったエラー(getMinimumVersion の失敗・比較できない最低バージョン)が添えてあれば
69
+ * {@link attachedErrorsOf} で取れる。latest の取得の失敗(`NETWORK` / `NOT_FOUND` / `PARSE_FAILED` / `TIMEOUT` /
70
+ * `LATEST_VERSION_FAILED`)で止めるときは、その時点で getMinimumVersion が完了していれば添え、完了していなければ添えない
71
+ * (待たない)。呼び出し元の abort(判定の取り消し)で止めるときは何も添えない。
72
+ * 判定を止めないエラーは {@link ResolveResult.errors} に入る。
73
+ */
74
+ export const resolve = async (params) => {
75
+ const { platform, version, appId, country, policy, getLatestVersion, getMinimumVersion, timeoutMs, signal, } = params;
76
+ if (signal?.aborted) {
77
+ throw createAbortError();
78
+ }
79
+ // 取得しても結果が決まっている(必ず error になる)ものは、ストアに問い合わせる前に返す
80
+ validatePolicy(policy);
81
+ assertValidVersion(version, 'local');
82
+ const scope = createScope({ signal, timeoutMs });
83
+ const timeoutError = () => new StoreVersionError('TIMEOUT', `the version check timed out after ${timeoutMs}ms`);
84
+ const ctx = { platform, signal: scope.signal };
85
+ // getLatestVersion を使う iOS は、ストアの URL だけを判定と並行に lookup する(判定はこれを待たない)
86
+ let storeUrlLookup = null;
87
+ const lookedUp = { value: null };
88
+ if (getLatestVersion && platform === 'ios') {
89
+ storeUrlLookup = lookupStoreUrl(appId, country, {
90
+ signal: scope.signal,
91
+ }).then((value) => {
92
+ // タイムアウトで打ち切った lookup の cause は、request の AbortError ではなく TIMEOUT にする
93
+ const result = value.error && scope.timedOut
94
+ ? storeUrlUnavailable(timeoutError())
95
+ : value;
96
+ lookedUp.value = result;
97
+ return result;
98
+ });
99
+ }
100
+ // getMinimumVersion が自分で完了した(タイムアウトや abort で打ち切られる前に値を返した / 失敗した)ときの結果。
101
+ // latest の失敗で判定を止めるときに、その時点で分かっている最低バージョンのエラーを添えるため(待たない)
102
+ const minimumDone = { value: null };
103
+ const minimumCall = getMinimumVersion
104
+ ? callMinimumVersion(getMinimumVersion, ctx)
105
+ : null;
106
+ // `!scope.signal.aborted` は防御のため。minimumDone を読むのはタイムアウトの経路だけ(呼び出し元の abort では読まない)。
107
+ // 今の順序では、タイムアウトの後は latest の catch が 1 tick で minimumDone を読み、このハンドラは 2 tick 以上後に走るので、
108
+ // タイムアウト後の結果がここで書かれても読まれない(このガードを外しても今のテストは通る)。latest 側に await が増えるなど
109
+ // 順序が変わったときに、タイムアウトに応じて getter が投げたエラー(cause が AbortError)を添えないためのもの。その場合、
110
+ // このガードが無ければテスト 'does not attach the rejection of a getMinimumVersion that honors the signal and was aborted by the timeout' が赤になる
111
+ minimumCall?.then((minimum) => {
112
+ if (!scope.signal.aborted) {
113
+ minimumDone.value = { minimum };
114
+ }
115
+ }, (error) => {
116
+ if (!scope.signal.aborted) {
117
+ minimumDone.value = { minimum: null, error };
118
+ }
119
+ });
120
+ // minimum は reject しない形にする(latest の失敗で先に抜けても unhandled rejection にならないように)。
121
+ // getter が signal を見なくても、タイムアウトと呼び出し元の abort で打ち切る
122
+ const minimumTask = minimumCall
123
+ ? raceAbort(minimumCall, scope.signal).then((minimum) => ({ minimum }), (error) => {
124
+ if (scope.timedOut) {
125
+ // latest が時間内に取れていれば、最低バージョンの判定だけを飛ばして続ける
126
+ return {
127
+ minimum: null,
128
+ error: new StoreVersionError('MINIMUM_VERSION_FAILED', `getMinimumVersion timed out after ${timeoutMs}ms`, { cause: timeoutError() }),
129
+ };
130
+ }
131
+ if (scope.signal.aborted) {
132
+ return { minimum: null, aborted: true };
133
+ }
134
+ return { minimum: null, error: error };
135
+ })
136
+ : Promise.resolve({ minimum: null });
137
+ const fail = (error) => {
138
+ // 判定をやめたので、まだ走っている取得(getter / URL の lookup)も止める
139
+ scope.abort();
140
+ throw error;
141
+ };
142
+ let latest;
143
+ try {
144
+ // getter が signal を見なくても、タイムアウトと呼び出し元の abort で打ち切る。latest のタイムアウトは判定全体の TIMEOUT
145
+ latest = await raceAbort(fetchLatest(params, scope.signal), scope.signal);
146
+ }
147
+ catch (error) {
148
+ // その時点で getMinimumVersion が完了していれば、その失敗・比較できない値も添える(完了していなければ待たずに添えない)。
149
+ // 呼び出し元の abort は判定の取り消しなので何も添えない(Provider がアンマウント後に onError を呼ばないように)
150
+ if (!scope.timedOut && scope.signal.aborted) {
151
+ return fail(error);
152
+ }
153
+ return fail(attach(scope.timedOut ? timeoutError() : error, minimumErrorsOf(minimumDone.value)));
154
+ }
155
+ // latest が取れたら、minimum を同じ期限まで待つ(期限を過ぎたら上で MINIMUM_VERSION_FAILED になる)
156
+ const minimum = await minimumTask;
157
+ if (minimum.aborted) {
158
+ return fail(createAbortError());
159
+ }
160
+ const errors = [];
161
+ if (minimum.error) {
162
+ errors.push(minimum.error);
163
+ }
164
+ let evaluation;
165
+ try {
166
+ // 版を取れなかった Play Store(latest が null)は、比較できない remote として判定する
167
+ evaluation = evaluatePolicy({
168
+ local: version,
169
+ remote: latest.latest ?? '',
170
+ minimum: minimum.minimum,
171
+ policy,
172
+ });
173
+ }
174
+ catch (error) {
175
+ // evaluatePolicy は最初の 1 つだけを投げるので、getter の失敗・比較できない最低バージョンもここで拾って添える。
176
+ // latest が null のときに投げられるのは remote の INVALID_VERSION なので、fetcher のエラー(理由が分かる)にする
177
+ return fail(attach(latest.latestError ?? error, minimumErrorsOf(minimum)));
178
+ }
179
+ if (evaluation.minimumError) {
180
+ errors.push(evaluation.minimumError);
181
+ }
182
+ if (evaluation.remoteError) {
183
+ errors.push(latest.latestError ?? evaluation.remoteError);
184
+ }
185
+ let storeUrl;
186
+ let storeUrlResult;
187
+ if (storeUrlLookup) {
188
+ storeUrl = lookedUp.value?.storeUrl ?? null;
189
+ storeUrlResult = storeUrlLookup;
190
+ // URL の lookup が終わるまではタイムアウトと呼び出し元の abort を効かせ続ける(storeUrlLookup は reject しない)
191
+ void storeUrlLookup.then(scope.dispose);
192
+ }
193
+ else {
194
+ scope.dispose();
195
+ // Android の URL は package name から決まる(openStore は market:// を先に試す)
196
+ const known = platform === 'ios'
197
+ ? toStoreUrlResult(latest.storeUrl)
198
+ : { storeUrl: playStoreUrl(appId), error: null };
199
+ storeUrl = known.storeUrl;
200
+ storeUrlResult = Promise.resolve(known);
201
+ }
202
+ const { result, detail, action, diff } = evaluation;
203
+ const resolved = {
204
+ latest: latest.latest,
205
+ minimum: minimum.minimum,
206
+ storeUrl,
207
+ storeUrlResult,
208
+ result,
209
+ detail,
210
+ action,
211
+ diff,
212
+ errors,
213
+ };
214
+ if (latest.releaseNotes !== undefined) {
215
+ resolved.releaseNotes = latest.releaseNotes;
216
+ }
217
+ return resolved;
218
+ };
@@ -0,0 +1,8 @@
1
+ import type { StoreVersionResolvedTexts } from '../react/texts.ts';
2
+ /**
3
+ * 日本語の文言。`<StoreVersionProvider texts={ja}>` で使う。
4
+ * `{remote}`(最新バージョン)/ `{local}`(現在のバージョン)は表示時に置き換わる
5
+ */
6
+ declare const ja: StoreVersionResolvedTexts;
7
+ export default ja;
8
+ //# sourceMappingURL=ja.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ja.d.ts","sourceRoot":"","sources":["../../src/texts/ja.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAEnE;;;GAGG;AACH,QAAA,MAAM,EAAE,EAAE,yBAaT,CAAC;eAEa,EAAE"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 日本語の文言。`<StoreVersionProvider texts={ja}>` で使う。
3
+ * `{remote}`(最新バージョン)/ `{local}`(現在のバージョン)は表示時に置き換わる
4
+ */
5
+ const ja = {
6
+ force: {
7
+ title: 'アップデートが必要です',
8
+ message: '新しいバージョン({remote})が公開されています。引き続きご利用いただくにはアップデートしてください。',
9
+ update: 'アップデート',
10
+ },
11
+ warning: {
12
+ title: '新しいバージョンがあります',
13
+ message: 'バージョン {remote} が利用できます。',
14
+ update: 'アップデート',
15
+ later: 'あとで',
16
+ },
17
+ };
18
+ export default ja;
@@ -0,0 +1,52 @@
1
+ /*!
2
+ * compare-versions 6.1.1 (https://github.com/omichelsen/compare-versions)
3
+ *
4
+ * The MIT License (MIT)
5
+ *
6
+ * Copyright (c) 2015-2021 Ole Michelsen
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ */
26
+ export declare const VENDORED_VERSION = "6.1.1";
27
+ export declare const semver: RegExp;
28
+ export declare const validateAndParse: (version: string) => RegExpMatchArray;
29
+ export declare const compareSegments: (a: string | string[] | RegExpMatchArray, b: string | string[] | RegExpMatchArray) => -1 | 0 | 1;
30
+ /**
31
+ * Compare [semver](https://semver.org/) version strings to find greater, equal or lesser.
32
+ * This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.
33
+ * @param v1 - First version to compare
34
+ * @param v2 - Second version to compare
35
+ * @returns Numeric value compatible with the [Array.sort(fn) interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters).
36
+ */
37
+ export declare const compareVersions: (v1: string, v2: string) => -1 | 0 | 1;
38
+ /**
39
+ * Validate [semver](https://semver.org/) version strings.
40
+ *
41
+ * @param version Version number to validate
42
+ * @returns `true` if the version number is a valid semver version number, `false` otherwise.
43
+ *
44
+ * @example
45
+ * ```
46
+ * validate('1.0.0-rc.1'); // return true
47
+ * validate('1.0-rc.1'); // return false
48
+ * validate('foo'); // return false
49
+ * ```
50
+ */
51
+ export declare const validate: (version: string) => boolean;
52
+ //# sourceMappingURL=compare-versions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare-versions.d.ts","sourceRoot":"","sources":["../../src/vendor/compare-versions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAWH,eAAO,MAAM,gBAAgB,UAAU,CAAC;AAExC,eAAO,MAAM,MAAM,QAC2H,CAAC;AAE/I,eAAO,MAAM,gBAAgB,YAAa,MAAM,qBAY/C,CAAC;AAoBF,eAAO,MAAM,eAAe,MACvB,MAAM,GAAG,MAAM,EAAE,GAAG,gBAAgB,KACpC,MAAM,GAAG,MAAM,EAAE,GAAG,gBAAgB,eAOxC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,OAAQ,MAAM,MAAM,MAAM,eAqBrD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ,YAAa,MAAM,YACuC,CAAC"}
@@ -0,0 +1,111 @@
1
+ /*!
2
+ * compare-versions 6.1.1 (https://github.com/omichelsen/compare-versions)
3
+ *
4
+ * The MIT License (MIT)
5
+ *
6
+ * Copyright (c) 2015-2021 Ole Michelsen
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ */
26
+ // 取り込んだ版: compare-versions 6.1.1(下の VENDORED_VERSION と揃える。差分テストが devDependency の版と照合する)
27
+ // 取り込んだ関数: compareVersions(src/compareVersions.ts)、validateAndParse / compareSegments(src/utils.ts)、
28
+ // validate(src/validate.ts)。`satisfies` / `compare` / `validateStrict` は使わないので取り込まない
29
+ // 本家からの変更点(更新時の差分確認用):
30
+ // 1. 本家の compareVersions.ts / utils.ts / validate.ts を 1 ファイルにまとめた(import の `./utils.js` を削除)
31
+ // 2. 不要な型 `CompareOperator` と `validateStrict` を削除
32
+ // 3. 取り込んだ版を示す定数 VENDORED_VERSION を追加
33
+ // 4. 上記以外のロジック・正規表現・エラーメッセージは本家のまま(Biome の lint / 整形の対象外)
34
+ export const VENDORED_VERSION = '6.1.1';
35
+ export const semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
36
+ export const validateAndParse = (version) => {
37
+ if (typeof version !== 'string') {
38
+ throw new TypeError('Invalid argument expected string');
39
+ }
40
+ const match = version.match(semver);
41
+ if (!match) {
42
+ throw new Error(`Invalid argument not valid semver ('${version}' received)`);
43
+ }
44
+ match.shift();
45
+ return match;
46
+ };
47
+ const isWildcard = (s) => s === '*' || s === 'x' || s === 'X';
48
+ const tryParse = (v) => {
49
+ const n = parseInt(v, 10);
50
+ return isNaN(n) ? v : n;
51
+ };
52
+ const forceType = (a, b) => typeof a !== typeof b ? [String(a), String(b)] : [a, b];
53
+ const compareStrings = (a, b) => {
54
+ if (isWildcard(a) || isWildcard(b))
55
+ return 0;
56
+ const [ap, bp] = forceType(tryParse(a), tryParse(b));
57
+ if (ap > bp)
58
+ return 1;
59
+ if (ap < bp)
60
+ return -1;
61
+ return 0;
62
+ };
63
+ export const compareSegments = (a, b) => {
64
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
65
+ const r = compareStrings(a[i] || '0', b[i] || '0');
66
+ if (r !== 0)
67
+ return r;
68
+ }
69
+ return 0;
70
+ };
71
+ /**
72
+ * Compare [semver](https://semver.org/) version strings to find greater, equal or lesser.
73
+ * This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.
74
+ * @param v1 - First version to compare
75
+ * @param v2 - Second version to compare
76
+ * @returns Numeric value compatible with the [Array.sort(fn) interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters).
77
+ */
78
+ export const compareVersions = (v1, v2) => {
79
+ // validate input and split into segments
80
+ const n1 = validateAndParse(v1);
81
+ const n2 = validateAndParse(v2);
82
+ // pop off the patch
83
+ const p1 = n1.pop();
84
+ const p2 = n2.pop();
85
+ // validate numbers
86
+ const r = compareSegments(n1, n2);
87
+ if (r !== 0)
88
+ return r;
89
+ // validate pre-release
90
+ if (p1 && p2) {
91
+ return compareSegments(p1.split('.'), p2.split('.'));
92
+ }
93
+ else if (p1 || p2) {
94
+ return p1 ? -1 : 1;
95
+ }
96
+ return 0;
97
+ };
98
+ /**
99
+ * Validate [semver](https://semver.org/) version strings.
100
+ *
101
+ * @param version Version number to validate
102
+ * @returns `true` if the version number is a valid semver version number, `false` otherwise.
103
+ *
104
+ * @example
105
+ * ```
106
+ * validate('1.0.0-rc.1'); // return true
107
+ * validate('1.0-rc.1'); // return false
108
+ * validate('foo'); // return false
109
+ * ```
110
+ */
111
+ export const validate = (version) => typeof version === 'string' && /^[v\d]/.test(version) && semver.test(version);
package/package.json CHANGED
@@ -1,13 +1,30 @@
1
1
  {
2
2
  "name": "react-native-store-version",
3
- "version": "1.4.2",
4
- "main": "dist/index.js",
5
- "types": "dist/index.d.ts",
6
- "license": "MIT",
7
- "scripts": {
8
- "build": "tsc --project tsconfig.json",
9
- "test": "jest"
3
+ "version": "2.0.0-beta.1",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./texts/ja": {
13
+ "types": "./dist/texts/ja.d.ts",
14
+ "default": "./dist/texts/ja.js"
15
+ },
16
+ "./package.json": "./package.json"
17
+ },
18
+ "bin": {
19
+ "react-native-store-version": "./dist/cli/index.js"
10
20
  },
21
+ "files": [
22
+ "dist",
23
+ "src",
24
+ "texts",
25
+ "CHANGELOG.md"
26
+ ],
27
+ "license": "MIT",
11
28
  "repository": {
12
29
  "type": "git",
13
30
  "url": "git+https://github.com/watanabeyu/react-native-store-version.git"
@@ -24,53 +41,75 @@
24
41
  "url": "https://github.com/watanabeyu/react-native-store-version/issues"
25
42
  },
26
43
  "homepage": "https://github.com/watanabeyu/react-native-store-version",
27
- "dependencies": {
28
- "compare-versions": "^4.1.3"
44
+ "peerDependencies": {
45
+ "expo-application": "*",
46
+ "react": ">=18",
47
+ "react-native": ">=0.73",
48
+ "react-native-device-info": "*"
49
+ },
50
+ "peerDependenciesMeta": {
51
+ "expo-application": {
52
+ "optional": true
53
+ },
54
+ "react-native-device-info": {
55
+ "optional": true
56
+ }
29
57
  },
30
58
  "devDependencies": {
31
- "@types/jest": "^28.1.6",
32
- "@types/react-native": "^0.69.5",
33
- "@typescript-eslint/eslint-plugin": "^5.32.0",
34
- "@typescript-eslint/parser": "^5.32.0",
35
- "babel-jest": "^28.1.3",
36
- "eslint": "^8.21.0",
37
- "eslint-config-prettier": "^8.5.0",
38
- "eslint-plugin-import": "^2.26.0",
39
- "eslint-plugin-unused-imports": "^2.0.0",
40
- "jest": "^28.1.3",
41
- "metro-react-native-babel-preset": "^0.72.0",
42
- "node-fetch": "^3.2.10",
43
- "prettier": "^2.7.1",
44
- "react-native": "^0.69.3",
45
- "ts-jest": "^28.0.7",
46
- "typescript": "^4.7.4"
59
+ "@babel/core": "^7.28.0",
60
+ "@biomejs/biome": "2.6.5",
61
+ "@react-native/babel-preset": "0.88.1",
62
+ "@react-native/jest-preset": "0.88.1",
63
+ "@testing-library/react-native": "^14.1.0",
64
+ "@types/jest": "^30.0.0",
65
+ "@types/node": "^22.20.5",
66
+ "@types/react": "^19.2.0",
67
+ "babel-jest": "^30.0.0",
68
+ "compare-versions": "6.1.1",
69
+ "jest": "^30.0.0",
70
+ "react": "^19.3.0",
71
+ "react-native": "0.88.1",
72
+ "test-renderer": "^1.0.0",
73
+ "typescript": "^7.0.2"
47
74
  },
48
75
  "jest": {
49
- "preset": "react-native",
50
- "moduleNameMapper": {
51
- "^app(.*)$": "<rootDir>/$1"
52
- },
76
+ "preset": "@react-native/jest-preset",
77
+ "restoreMocks": true,
78
+ "testTimeout": 20000,
79
+ "waitForUnhandledRejections": true,
53
80
  "moduleFileExtensions": [
54
81
  "ts",
55
82
  "tsx",
56
83
  "js"
57
84
  ],
58
- "transform": {
59
- "^.+\\.(ts|tsx)$": "ts-jest"
60
- },
61
- "globals": {
62
- "ts-jest": {
63
- "tsconfig": "tsconfig.json",
64
- "diagnostics": false
65
- }
66
- },
67
85
  "testMatch": [
68
- "**/__tests__/**/*.test.(ts|tsx|js)",
69
- "**/src/**/*.test.(ts|tsx|js)"
86
+ "<rootDir>/__tests__/**/*.test.(ts|tsx)"
87
+ ],
88
+ "setupFilesAfterEnv": [
89
+ "<rootDir>/__tests__/__helpers__/setup.ts"
70
90
  ],
71
91
  "testPathIgnorePatterns": [
72
- "node_modules",
73
- "dist"
74
- ]
92
+ "/node_modules/",
93
+ "/dist/"
94
+ ],
95
+ "transformIgnorePatterns": [
96
+ "node_modules/(?!(\\.pnpm/[^/]+/node_modules/)?((jest-)?react-native|@react-native(-community)?)/)"
97
+ ],
98
+ "collectCoverageFrom": [
99
+ "src/**/*.{ts,tsx}",
100
+ "!src/**/*.d.ts",
101
+ ".github/scripts/release-version.js"
102
+ ],
103
+ "coverageThreshold": {
104
+ "global": {
105
+ "lines": 90
106
+ }
107
+ }
108
+ },
109
+ "scripts": {
110
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json && tsc -p tsconfig.build.cli.json",
111
+ "lint": "biome check",
112
+ "typecheck": "tsc --noEmit && tsc -p tsconfig.build.json --noEmit",
113
+ "test": "jest"
75
114
  }
76
- }
115
+ }