Skip to content

Commit

Permalink
fix: ignore fix invalid version (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Jun 7, 2023
1 parent cb5117a commit f5607c0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/core/entity/PaddingSemVer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class PaddingSemVer {

// 版本信息中为纯数字, JS 中支持的最大整型为 16 位
// 因此填充成 16 位对齐,如果版本号超过 16 位,则抛出异常
static paddingVersion(v) {
static paddingVersion(v: number) {
const t = String(v);
if (t.length <= 16) {
const padding = new Array(16 - t.length).fill(0)
Expand Down
3 changes: 3 additions & 0 deletions app/core/service/FixNoPaddingVersionService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SingletonProto, AccessLevel, Inject } from '@eggjs/tegg';
import { EggLogger } from 'egg';
import pMap from 'p-map';
import semver from 'semver';
import { PackageVersionRepository } from '../../repository/PackageVersionRepository';
import { PaddingSemVer } from '../entity/PaddingSemVer';

Expand All @@ -25,6 +26,8 @@ export class FixNoPaddingVersionService {
this.logger.info('[FixNoPaddingVersionService] fix padding version ids %j', packageVersions.map(t => t.id));

await pMap(packageVersions, async packageVersion => {
// ignore invalid version, e.g.: '1000000000000000000.0.0' on https://registry.npmjs.com/latentflip-test
if (!semver.valid(packageVersion.version)) return;
const paddingSemver = new PaddingSemVer(packageVersion.version);
await this.packageVersionRepository.fixPaddingVersion(packageVersion.packageVersionId, paddingSemver);
}, { concurrency: 30 });
Expand Down
2 changes: 1 addition & 1 deletion sql/3.28.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ ALTER TABLE
ADD
COLUMN padding_version varchar(255) DEFAULT NULL COMMENT 'token name',
ADD
COLUMN `is_pre_release` tinyint(4) DEFAULT NULL COMMENT '是否是先行版本',
COLUMN `is_pre_release` tinyint(4) DEFAULT NULL COMMENT 'pre release version or not',
ADD
KEY `idx_pkg_id_is_pre_release_padding_version` (`package_id`, `padding_version`, `is_pre_release`, `version`);

0 comments on commit f5607c0

Please sign in to comment.