Added indexJson hook which normalizes data.

The official skimdb mirror (which we're supposed to use) contains
older documents which do not match the SemVer specification. In
order to ensure that the documents that we mirror match those
available on registry.npmjs.org, this hook passes them through npm's
`normalize-registry-metadata` package for sanitation.
This commit is contained in:
Michael Krotscheck 2016-04-22 14:28:47 -07:00
parent 553fc71b69
commit ee2e575993
No known key found for this signature in database
GPG Key ID: 20E618D878DE38AB
6 changed files with 4911 additions and 36 deletions

View File

@ -4,6 +4,9 @@ AFS-based NPM mirrors. It is maintained by OpenStack's Infrastructure team.
## Provided Hooks
#### indexJson
The official skimdb mirror (which we're supposed to use) contains older documents which do not match the SemVer specification. In order to ensure that the documents that we mirror match those available on registry.npmjs.org, this hook passes them through npm's `normalize-registry-metadata` package for sanitation.
#### afterAll
After each package is processed, the script will check the overall
synchronization status of the mirror. If it detects that the mirror is up to

View File

@ -34,7 +34,7 @@
/**
* Called before writing a package's main index.json.
*/
indexJson: noop,
indexJson: require('./lib/index_json'),
/**
* Called before writing the index.json for a particular package version.

25
lib/index_json.js Normal file
View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2016 Hewlett Packard Enterprise Development Company, LP
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
(function () {
'use strict';
var clean = require('normalize-registry-metadata');
module.exports = function (data, cb) {
data.json = clean(data.json);
cb(null, true);
};
})();

View File

@ -4,7 +4,9 @@
"version": "1.0.1",
"description": "registry-static procedural hooks for OpenStack's NPM mirror.",
"main": "index.js",
"dependencies": {},
"dependencies": {
"normalize-registry-metadata": "1.1.2"
},
"devDependencies": {
"eslint": "^1.5.0",
"eslint-config-openstack": "^1.2.4",

4828
spec/helpers/shelljs.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -52,9 +52,8 @@
it('should noop on most methods', function () {
var hooks = require('../index');
var methods = ['beforeAll', 'globalIndexJson', 'indexJson',
'versionJson', 'tarball', 'afterTarball', 'startup',
'shasumCheck'];
var methods = ['beforeAll', 'globalIndexJson', 'versionJson', 'tarball',
'afterTarball', 'startup', 'shasumCheck'];
methods.forEach(function (methodName) {
var data = {};
var cb = jasmine.createSpy('spy');
@ -65,40 +64,58 @@
});
});
it('should noop on afterAll if the sequences do not match',
function () {
var hooks = require('../index');
describe('afterAll', function () {
it('should noop on afterAll if the sequences do not match',
function () {
var hooks = require('../index');
var cb = jasmine.createSpy('spy');
var data = {seq: 2, latestSeq: 20};
hooks.afterAll.call(boundScope, data, cb);
expect(procSpy).not.toHaveBeenCalled();
expect(cb).toHaveBeenCalledWith(null, true);
});
it('should not error if sequences are not defined',
function () {
var hooks = require('../index');
var cb = jasmine.createSpy('spy');
var data = {};
hooks.afterAll.call(boundScope, data, cb);
expect(procSpy).not.toHaveBeenCalled();
expect(cb).toHaveBeenCalledWith(null, true);
});
it('should process.exit() if sequences match',
function () {
var hooks = require('../index');
var cb = jasmine.createSpy('spy');
var data = {seq: 20, latestSeq: 20};
hooks.afterAll.call(boundScope, data, cb);
expect(procSpy).toHaveBeenCalledWith(0);
});
});
describe('indexJson', function () {
it('should sanitize versions', function () {
var shellJsData = require('./helpers/shelljs.json');
var oldKeys = Object.keys(shellJsData.json.versions);
var cb = jasmine.createSpy('spy');
var data = {seq: 2, latestSeq: 20};
hooks.afterAll.call(boundScope, data, cb);
expect(oldKeys).toContain('0.0.1alpha1');
expect(procSpy).not.toHaveBeenCalled();
expect(cb).toHaveBeenCalledWith(null, true);
var indexJsonHook = require('../lib/index_json');
indexJsonHook(shellJsData, cb);
var newKeys = Object.keys(shellJsData.json.versions);
expect(newKeys).toContain('0.0.1-alpha1');
expect(newKeys).not.toContain('0.0.1alpha1');
});
it('should not error if sequences are not defined',
function () {
var hooks = require('../index');
var cb = jasmine.createSpy('spy');
var data = {};
hooks.afterAll.call(boundScope, data, cb);
expect(procSpy).not.toHaveBeenCalled();
expect(cb).toHaveBeenCalledWith(null, true);
});
it('should process.exit() if sequences match',
function () {
var hooks = require('../index');
var cb = jasmine.createSpy('spy');
var data = {seq: 20, latestSeq: 20};
hooks.afterAll.call(boundScope, data, cb);
expect(procSpy).toHaveBeenCalledWith(0);
});
});
});
})();