mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-20 22:52:46 -05:00
Merge pull request #1211 from buffaybu/patch-1
fix: don’t update packages that have no uplinks after reading (#1204)
This commit is contained in:
commit
004a407ae7
2 changed files with 28 additions and 5 deletions
|
@ -487,7 +487,9 @@ class Storage implements IStorageHandler {
|
||||||
, null
|
, null
|
||||||
, upLinksErrors );
|
, upLinksErrors );
|
||||||
}
|
}
|
||||||
|
if (upLinks.length === 0) {
|
||||||
|
return callback(null, packageInfo);
|
||||||
|
}
|
||||||
self.localStorage.updateVersions(name, packageInfo, function(err, packageJsonLocal: Package) {
|
self.localStorage.updateVersions(name, packageInfo, function(err, packageJsonLocal: Package) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
import rimraf from 'rimraf';
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
import configExample from '../partials/config/index';
|
import configExample from '../partials/config/index';
|
||||||
import AppConfig from '../../../src/lib/config';
|
import AppConfig from '../../../src/lib/config';
|
||||||
|
@ -16,12 +18,12 @@ import {DOMAIN_SERVERS} from '../../functional/config.functional';
|
||||||
|
|
||||||
setup(configExample.logs);
|
setup(configExample.logs);
|
||||||
|
|
||||||
|
const storagePath = path.join(__dirname, '../partials/store/test-storage-store.spec');
|
||||||
const mockServerPort: number = 55548;
|
const mockServerPort: number = 55548;
|
||||||
const generateStorage = async function(port = mockServerPort, configDefault = configExample) {
|
const generateStorage = async function(port = mockServerPort, configDefault = configExample) {
|
||||||
const storageConfig = _.clone(configDefault);
|
const storageConfig = _.clone(configDefault);
|
||||||
const storage = path.join(__dirname, '../partials/store/test-storage-store.spec');
|
|
||||||
storageConfig.self_path = __dirname;
|
storageConfig.self_path = __dirname;
|
||||||
storageConfig.storage = storage;
|
storageConfig.storage = storagePath;
|
||||||
storageConfig.uplinks = {
|
storageConfig.uplinks = {
|
||||||
npmjs: {
|
npmjs: {
|
||||||
url: `http://${DOMAIN_SERVERS}:${port}`
|
url: `http://${DOMAIN_SERVERS}:${port}`
|
||||||
|
@ -37,8 +39,11 @@ const generateStorage = async function(port = mockServerPort, configDefault = co
|
||||||
describe('StorageTest', () => {
|
describe('StorageTest', () => {
|
||||||
let mockRegistry;
|
let mockRegistry;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(done => {
|
||||||
|
rimraf(storagePath, async () => {
|
||||||
mockRegistry = await mockServer(mockServerPort).init();
|
mockRegistry = await mockServer(mockServerPort).init();
|
||||||
|
done()
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(function(done) {
|
afterAll(function(done) {
|
||||||
|
@ -90,5 +95,21 @@ describe('StorageTest', () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should not touch if the package exists and has no uplinks', async (done) => {
|
||||||
|
const storage: IStorageHandler = await generateStorage();
|
||||||
|
const metadataSource = path.join(__dirname, '../partials/metadata');
|
||||||
|
const metadataPath = path.join(storagePath, 'npm_test/package.json');
|
||||||
|
fs.mkdirSync(path.join(storagePath, 'npm_test'));
|
||||||
|
fs.writeFileSync(metadataPath, fs.readFileSync(metadataSource));
|
||||||
|
const metadata = JSON.parse(fs.readFileSync(metadataPath).toString());
|
||||||
|
// $FlowFixMe
|
||||||
|
storage.localStorage.updateVersions = jest.fn(storage.localStorage.updateVersions);
|
||||||
|
storage._syncUplinksMetadata('npm_test', metadata, {}, (err) => {
|
||||||
|
expect(err).toBeNull();
|
||||||
|
expect(storage.localStorage.updateVersions).not.toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue