From 9b06205f82b75638ee109bf9f17a3f2de2ac56fc Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Wed, 10 May 2017 05:22:45 -0700 Subject: [PATCH] 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 --- package.json | 1 - .../src/Bundler/__tests__/Bundler-test.js | 3 +- packager/src/Server/__tests__/Server-test.js | 1 - .../src/lib/__tests__/declareOpts-test.js | 92 ------------------- packager/src/lib/declareOpts.js | 75 --------------- 5 files changed, 1 insertion(+), 171 deletions(-) delete mode 100644 packager/src/lib/__tests__/declareOpts-test.js delete mode 100644 packager/src/lib/declareOpts.js diff --git a/package.json b/package.json index efa2cb99c..4ee90b6b3 100644 --- a/package.json +++ b/package.json @@ -171,7 +171,6 @@ "image-size": "^0.3.5", "inquirer": "^0.12.0", "jest-haste-map": "19.0.0", - "joi": "^6.6.1", "json-stable-stringify": "^1.0.1", "json5": "^0.4.0", "left-pad": "^1.1.3", diff --git a/packager/src/Bundler/__tests__/Bundler-test.js b/packager/src/Bundler/__tests__/Bundler-test.js index a8924a4fe..5a171a806 100644 --- a/packager/src/Bundler/__tests__/Bundler-test.js +++ b/packager/src/Bundler/__tests__/Bundler-test.js @@ -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'); diff --git a/packager/src/Server/__tests__/Server-test.js b/packager/src/Server/__tests__/Server-test.js index d98072883..2dfa6d3d1 100644 --- a/packager/src/Server/__tests__/Server-test.js +++ b/packager/src/Server/__tests__/Server-test.js @@ -22,7 +22,6 @@ jest.mock('../../worker-farm', () => () => () => {}) ) .mock('../../Bundler') .mock('../../AssetServer') - .mock('../../lib/declareOpts') .mock('../../node-haste/DependencyGraph') .mock('../../Logger') .mock('../../lib/GlobalTransformCache'); diff --git a/packager/src/lib/__tests__/declareOpts-test.js b/packager/src/lib/__tests__/declareOpts-test.js deleted file mode 100644 index fec70f9d2..000000000 --- a/packager/src/lib/__tests__/declareOpts-test.js +++ /dev/null @@ -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(); - }); -}); diff --git a/packager/src/lib/declareOpts.js b/packager/src/lib/declareOpts.js deleted file mode 100644 index 719da9411..000000000 --- a/packager/src/lib/declareOpts.js +++ /dev/null @@ -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( - 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; - }; -};