@ai-wendao/ant 0.5.2 → 0.5.3
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/client.js +29 -8
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -183,19 +183,40 @@ window.__ModuleLoader__.load({
|
|
|
183
183
|
return normalized ? new URL('/console', normalized).toString() : null
|
|
184
184
|
}
|
|
185
185
|
const versionParts = (value) => {
|
|
186
|
-
if (typeof value !== 'string'
|
|
187
|
-
|
|
186
|
+
if (typeof value !== 'string') return null
|
|
187
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-((?:0|[1-9]\d*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u.exec(value)
|
|
188
|
+
if (!match) return null
|
|
189
|
+
return { core: match.slice(1, 4), prerelease: match[4]?.split('.') ?? null }
|
|
190
|
+
}
|
|
191
|
+
const compareNumericVersionIdentifiers = (left, right) => {
|
|
192
|
+
const normalizedLeft = left.replace(/^0+(?=\d)/u, '')
|
|
193
|
+
const normalizedRight = right.replace(/^0+(?=\d)/u, '')
|
|
194
|
+
if (normalizedLeft.length !== normalizedRight.length) return normalizedLeft.length < normalizedRight.length ? -1 : 1
|
|
195
|
+
return normalizedLeft === normalizedRight ? 0 : normalizedLeft < normalizedRight ? -1 : 1
|
|
188
196
|
}
|
|
189
197
|
const newerVersion = (candidate, current) => {
|
|
190
198
|
const next = versionParts(candidate)
|
|
191
199
|
const installed = versionParts(current)
|
|
192
200
|
if (!next || !installed) return false
|
|
193
|
-
for (let index = 0; index < next.length; index += 1) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
201
|
+
for (let index = 0; index < next.core.length; index += 1) {
|
|
202
|
+
const order = compareNumericVersionIdentifiers(next.core[index], installed.core[index])
|
|
203
|
+
if (order !== 0) return order > 0
|
|
204
|
+
}
|
|
205
|
+
if (!next.prerelease) return Boolean(installed.prerelease)
|
|
206
|
+
if (!installed.prerelease) return false
|
|
207
|
+
for (let index = 0; index < Math.max(next.prerelease.length, installed.prerelease.length); index += 1) {
|
|
208
|
+
const nextIdentifier = next.prerelease[index]
|
|
209
|
+
const installedIdentifier = installed.prerelease[index]
|
|
210
|
+
if (nextIdentifier === undefined) return false
|
|
211
|
+
if (installedIdentifier === undefined) return true
|
|
212
|
+
if (nextIdentifier === installedIdentifier) continue
|
|
213
|
+
const nextIsNumeric = /^\d+$/u.test(nextIdentifier)
|
|
214
|
+
const installedIsNumeric = /^\d+$/u.test(installedIdentifier)
|
|
215
|
+
if (nextIsNumeric && installedIsNumeric) {
|
|
216
|
+
return compareNumericVersionIdentifiers(nextIdentifier, installedIdentifier) > 0
|
|
217
|
+
}
|
|
218
|
+
if (nextIsNumeric !== installedIsNumeric) return !nextIsNumeric
|
|
219
|
+
return nextIdentifier > installedIdentifier
|
|
199
220
|
}
|
|
200
221
|
return false
|
|
201
222
|
}
|