0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-06 22:40:26 -05:00

fix: don’t make change if time fields match (#1167)

This commit is contained in:
BuffayBu 2019-01-29 11:59:31 +08:00
parent 23b02c01fc
commit e62ef8df99
3 changed files with 27 additions and 6 deletions

View file

@ -185,7 +185,7 @@ class LocalStorage implements IStorage {
}
}
if ('time' in packageInfo) {
if ('time' in packageInfo && !_.isEqual(packageLocalJson.time, packageInfo.time)) {
packageLocalJson.time = packageInfo.time;
change = true;
}

View file

@ -2,6 +2,7 @@
import rimRaf from 'rimraf';
import path from 'path';
import fs from 'fs';
import LocalStorage from '../../../src/lib/local-storage';
import AppConfig from '../../../src/lib/config';
// $FlowFixMe
@ -250,14 +251,16 @@ describe('LocalStorage', () => {
});
describe('LocalStorage::updateVersions', () => {
test('should update versions from external source', async (done) => {
const metadata = JSON.parse(readMetadata('metadata-update-versions-tags'));
const pkgName = 'add-update-versions-test-1';
const version = '1.0.2';
const metadata = JSON.parse(readMetadata('metadata-update-versions-tags'));
const pkgName = 'add-update-versions-test-1';
const version = '1.0.2';
beforeAll(async () => {
await addPackageToStore(pkgName, generatePackageTemplate(pkgName));
await addNewVersion(pkgName, '1.0.1');
await addNewVersion(pkgName, version);
})
test('should update versions from external source', async (done) => {
storage.updateVersions(pkgName, metadata, (err, data) => {
expect(err).toBeNull();
expect(data.versions['1.0.1']).toBeDefined();
@ -274,6 +277,18 @@ describe('LocalStorage', () => {
done();
});
});
test('should not update if the metadata match', done => {
const metadataPath = path.join(configExample.storage, pkgName, 'package.json')
const prevStat = fs.statSync(metadataPath)
storage.updateVersions(pkgName, metadata, (err, data) => {
expect(err).toBeNull()
const nextStat = fs.statSync(metadataPath)
expect(nextStat).toHaveProperty('ctime', prevStat.ctime)
expect(nextStat).toHaveProperty('mtime', prevStat.mtime)
done()
})
})
});
describe('LocalStorage::changePackage', () => {

View file

@ -82,7 +82,13 @@
"beta": "1.0.2",
"next": "1.0.4"
},
"time": {},
"time": {
"modified": "2019-01-29T03:20:04.000Z",
"created": "2019-01-29T03:20:00.000Z",
"1.0.1": "2019-01-29T03:20:01.000Z",
"1.0.2": "2019-01-29T03:20:02.000Z",
"1.0.4": "2019-01-29T03:20:04.000Z"
},
"_distfiles": {},
"_attachments": {},
"_uplinks": {},