Skip to content

Commit

Permalink
feat: use isEqual instead of json diff
Browse files Browse the repository at this point in the history
  • Loading branch information
elrrrrrrr committed Aug 4, 2023
1 parent 2ed3df7 commit af1e06b
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions app/core/service/PackageSyncerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Pointcut } from '@eggjs/tegg/aop';
import { EggHttpClient } from 'egg';
import { setTimeout } from 'timers/promises';
import { rm } from 'fs/promises';
import { isEqual } from 'lodash';
import { isEqual, isEmpty } from 'lodash';
import semver from 'semver';
import semverRcompare from 'semver/functions/rcompare';
import semverPrerelease from 'semver/functions/prerelease';
Expand Down Expand Up @@ -608,7 +608,7 @@ export class PackageSyncerService extends AbstractService {
// fix _npmUser field since https://github.com/cnpm/cnpmcore/issues/553
const metaDataKeys = [ 'peerDependenciesMeta', 'os', 'cpu', 'libc', 'workspaces', 'hasInstallScript', 'deprecated', '_npmUser' ];
const ignoreInAbbreviated = ['_npmUser'];

Check failure on line 610 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (16, ubuntu-latest)

A space is required after '['

Check failure on line 610 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (16, ubuntu-latest)

A space is required before ']'

Check failure on line 610 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (18, ubuntu-latest)

A space is required after '['

Check failure on line 610 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (18, ubuntu-latest)

A space is required before ']'

Check failure on line 610 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (20, ubuntu-latest)

A space is required after '['

Check failure on line 610 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (20, ubuntu-latest)

A space is required before ']'

Check failure on line 610 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (16, ubuntu-latest)

A space is required after '['

Check failure on line 610 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (16, ubuntu-latest)

A space is required before ']'

Check failure on line 610 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (18, ubuntu-latest)

A space is required after '['

Check failure on line 610 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (18, ubuntu-latest)

A space is required before ']'

Check failure on line 610 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (20, ubuntu-latest)

A space is required after '['

Check failure on line 610 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (20, ubuntu-latest)

A space is required before ']'
let diffMeta: Partial<PackageJSONType>;
let diffMeta: Partial<PackageJSONType> = {};

Check failure on line 611 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (16, ubuntu-latest)

'diffMeta' is never reassigned. Use 'const' instead

Check failure on line 611 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (18, ubuntu-latest)

'diffMeta' is never reassigned. Use 'const' instead

Check failure on line 611 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (20, ubuntu-latest)

'diffMeta' is never reassigned. Use 'const' instead

Check failure on line 611 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (16, ubuntu-latest)

'diffMeta' is never reassigned. Use 'const' instead

Check failure on line 611 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (18, ubuntu-latest)

'diffMeta' is never reassigned. Use 'const' instead

Check failure on line 611 in app/core/service/PackageSyncerService.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (20, ubuntu-latest)

'diffMeta' is never reassigned. Use 'const' instead
for (const key of metaDataKeys) {
let remoteItemValue = item[key];
// make sure hasInstallScript exists
Expand All @@ -617,22 +617,18 @@ export class PackageSyncerService extends AbstractService {
remoteItemValue = true;
}
}
const remoteItemDiffValue = JSON.stringify(remoteItemValue);
if (remoteItemDiffValue !== JSON.stringify(existsItem[key])) {
if (!diffMeta) diffMeta = {};
if (!isEqual(remoteItemValue, existsItem[key])) {
diffMeta[key] = remoteItemValue;
} else if (!ignoreInAbbreviated.includes(key) && existsAbbreviatedItem && remoteItemDiffValue !== JSON.stringify(existsAbbreviatedItem[key])) {
} else if (!ignoreInAbbreviated.includes(key) && existsAbbreviatedItem && !isEqual(remoteItemValue, existsAbbreviatedItem[key])) {
// should diff exists abbreviated item too
if (!diffMeta) diffMeta = {};
diffMeta[key] = remoteItemValue;
}
}
// should delete readme
if (shouldDeleteReadme) {
if (!diffMeta) diffMeta = {};
diffMeta.readme = undefined;
}
if (diffMeta) {
if (!isEmpty(diffMeta)) {
differentMetas.push([ existsItem, diffMeta ]);
}
continue;
Expand Down

0 comments on commit af1e06b

Please sign in to comment.