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:
Jean Lauliac 2017-05-10 05:22:45 -07:00 committed by Facebook Github Bot
parent f1a220b3cf
commit 9b06205f82
5 changed files with 1 additions and 171 deletions

View File

@ -171,7 +171,6 @@
"image-size": "^0.3.5", "image-size": "^0.3.5",
"inquirer": "^0.12.0", "inquirer": "^0.12.0",
"jest-haste-map": "19.0.0", "jest-haste-map": "19.0.0",
"joi": "^6.6.1",
"json-stable-stringify": "^1.0.1", "json-stable-stringify": "^1.0.1",
"json5": "^0.4.0", "json5": "^0.4.0",
"left-pad": "^1.1.3", "left-pad": "^1.1.3",

View File

@ -21,12 +21,11 @@ jest
.mock('progress') .mock('progress')
.mock('../../node-haste/DependencyGraph') .mock('../../node-haste/DependencyGraph')
.mock('../../JSTransformer') .mock('../../JSTransformer')
.mock('../../lib/declareOpts')
.mock('../../Resolver') .mock('../../Resolver')
.mock('../Bundle') .mock('../Bundle')
.mock('../HMRBundle') .mock('../HMRBundle')
.mock('../../Logger') .mock('../../Logger')
.mock('../../lib/declareOpts'); ;
var Bundler = require('../'); var Bundler = require('../');
var Resolver = require('../../Resolver'); var Resolver = require('../../Resolver');

View File

@ -22,7 +22,6 @@ jest.mock('../../worker-farm', () => () => () => {})
) )
.mock('../../Bundler') .mock('../../Bundler')
.mock('../../AssetServer') .mock('../../AssetServer')
.mock('../../lib/declareOpts')
.mock('../../node-haste/DependencyGraph') .mock('../../node-haste/DependencyGraph')
.mock('../../Logger') .mock('../../Logger')
.mock('../../lib/GlobalTransformCache'); .mock('../../lib/GlobalTransformCache');

View File

@ -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();
});
});

View File

@ -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;
};
};