mirror of https://github.com/status-im/metro.git
packager: remove unused declareOpts module
Summary: That module is not used anymore, remove it and its dependency `joi`. Reviewed By: cpojer Differential Revision: D5028909 fbshipit-source-id: 90b9b156fbfe642cce93a530faf8ce91c5b848f5
This commit is contained in:
parent
3b396ee207
commit
7296c3ec54
|
@ -21,12 +21,11 @@ jest
|
|||
.mock('progress')
|
||||
.mock('../../node-haste/DependencyGraph')
|
||||
.mock('../../JSTransformer')
|
||||
.mock('../../lib/declareOpts')
|
||||
.mock('../../Resolver')
|
||||
.mock('../Bundle')
|
||||
.mock('../HMRBundle')
|
||||
.mock('../../Logger')
|
||||
.mock('../../lib/declareOpts');
|
||||
;
|
||||
|
||||
var Bundler = require('../');
|
||||
var Resolver = require('../../Resolver');
|
||||
|
|
|
@ -22,7 +22,6 @@ jest.mock('../../worker-farm', () => () => () => {})
|
|||
)
|
||||
.mock('../../Bundler')
|
||||
.mock('../../AssetServer')
|
||||
.mock('../../lib/declareOpts')
|
||||
.mock('../../node-haste/DependencyGraph')
|
||||
.mock('../../Logger')
|
||||
.mock('../../lib/GlobalTransformCache');
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
jest.disableAutomock();
|
||||
|
||||
var declareOpts = require('../declareOpts');
|
||||
|
||||
describe('declareOpts', function() {
|
||||
it('should declare and validate simple opts', function() {
|
||||
var validate = declareOpts({
|
||||
name: {
|
||||
required: true,
|
||||
type: 'string',
|
||||
},
|
||||
age: {
|
||||
type: 'number',
|
||||
default: 21,
|
||||
},
|
||||
});
|
||||
var opts = validate({name: 'fooer'});
|
||||
|
||||
expect(opts).toEqual({
|
||||
name: 'fooer',
|
||||
age: 21,
|
||||
});
|
||||
});
|
||||
|
||||
it('should work with complex types', function() {
|
||||
var validate = declareOpts({
|
||||
things: {
|
||||
required: true,
|
||||
type: 'array',
|
||||
},
|
||||
stuff: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
|
||||
var opts = validate({things: [1, 2, 3], stuff: {hai: 1}});
|
||||
expect(opts).toEqual({
|
||||
things: [1, 2, 3],
|
||||
stuff: {hai: 1},
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw when a required option is not present', function() {
|
||||
var validate = declareOpts({
|
||||
foo: {
|
||||
required: true,
|
||||
type: 'number',
|
||||
},
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
validate({});
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('should throw on invalid type', function() {
|
||||
var validate = declareOpts({
|
||||
foo: {
|
||||
required: true,
|
||||
type: 'number',
|
||||
},
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
validate({foo: 'lol'});
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('should throw on extra options', function() {
|
||||
var validate = declareOpts({
|
||||
foo: {
|
||||
required: true,
|
||||
type: 'number',
|
||||
},
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
validate({foo: 1, lol: 1});
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
|
@ -1,75 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* Declares, validates and defaults options.
|
||||
* var validate = declareOpts({
|
||||
* foo: {
|
||||
* type: 'bool',
|
||||
* required: true,
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* var myOptions = validate(someOptions);
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var Joi = require('joi');
|
||||
|
||||
/**
|
||||
* TOut is always more specific than TIn, so it's a subtype.
|
||||
*/
|
||||
module.exports = function<TIn: {}, TOut: TIn>(
|
||||
descriptor: {[name: string]: {
|
||||
type: mixed,
|
||||
required?: boolean,
|
||||
default?: mixed,
|
||||
}},
|
||||
): (untyped: TIn) => TOut {
|
||||
var joiKeys = {};
|
||||
Object.keys(descriptor).forEach(function(prop) {
|
||||
var record = descriptor[prop];
|
||||
if (record.type == null) {
|
||||
throw new Error('Type is required');
|
||||
}
|
||||
|
||||
if (record.type === 'function') {
|
||||
record.type = 'func';
|
||||
}
|
||||
|
||||
var propValidator = Joi[record.type]();
|
||||
|
||||
if (record.required) {
|
||||
propValidator = propValidator.required();
|
||||
}
|
||||
|
||||
if (record.default) {
|
||||
propValidator = propValidator.default(record.default);
|
||||
}
|
||||
|
||||
joiKeys[prop] = propValidator;
|
||||
});
|
||||
|
||||
var schema = Joi.object().keys(joiKeys);
|
||||
|
||||
return function(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var res = Joi.validate(opts, schema, {
|
||||
abortEarly: true,
|
||||
allowUnknown: false,
|
||||
});
|
||||
|
||||
if (res.error) {
|
||||
throw new Error('Error validating module options: ' + res.error.message);
|
||||
}
|
||||
return res.value;
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue