packager: Server: remove last declareOpts usage and replace by Flow types

Summary:
`declareOpts` prevents strong Flow typing, and promotes default values, that may be different from a function to another (my goal is to remove defaults from the whole codebase except perhaps the public API). This changeset replaces it by Flow types and fixes callsites to be explicit on values.

This is the last callsite of `declareOpts` so I'll remove it, in a separate diff.

Reviewed By: cpojer

Differential Revision: D4970650

fbshipit-source-id: e5ea2e06febde892d28c9dc59dc2920d4033bb01
This commit is contained in:
Jean Lauliac 2017-05-03 03:26:52 -07:00 committed by Facebook Github Bot
parent ce06a303ed
commit 58f3046450
3 changed files with 37 additions and 55 deletions

View File

@ -79,9 +79,13 @@ exports.buildBundle = function(options: Options, bundleOptions: PublicBundleOpti
});
};
exports.getOrderedDependencyPaths = function(options: Options, bundleOptions: {}) {
exports.getOrderedDependencyPaths = function(options: Options, depOptions: {
+entryFile: string,
+dev: boolean,
+platform: string,
}) {
var server = createNonPersistentServer(options);
return server.getOrderedDependencyPaths(bundleOptions)
return server.getOrderedDependencyPaths(depOptions)
.then(function(paths) {
server.end();
return paths;

View File

@ -584,9 +584,9 @@ class Bundler {
}
getOrderedDependencyPaths({entryFile, dev, platform}: {
entryFile: string,
dev: boolean,
platform: string,
+entryFile: string,
+dev: boolean,
+platform: string,
}) {
return this.getDependencies({entryFile, dev, platform}).then(
({dependencies}) => {

View File

@ -16,7 +16,6 @@ const getPlatformExtension = require('../node-haste').getPlatformExtension;
const Bundler = require('../Bundler');
const MultipartResponse = require('./MultipartResponse');
const declareOpts = require('../lib/declareOpts');
const defaults = require('../../defaults');
const mime = require('mime-types');
const path = require('path');
@ -98,32 +97,14 @@ export type BundleOptions = {
unbundle: boolean,
};
const dependencyOpts = declareOpts({
platform: {
type: 'string',
required: true,
},
dev: {
type: 'boolean',
default: true,
},
entryFile: {
type: 'string',
required: true,
},
recursive: {
type: 'boolean',
default: true,
},
hot: {
type: 'boolean',
default: false,
},
minify: {
type: 'boolean',
default: undefined,
},
});
type DependencyOptions = {|
+dev: boolean,
+entryFile: string,
+hot: boolean,
+minify: boolean,
+platform: ?string,
+recursive: boolean,
|};
const bundleDeps = new WeakMap();
const NODE_MODULES = `${path.sep}node_modules${path.sep}`;
@ -291,17 +272,14 @@ class Server {
return this._bundler.hmrBundle(options, host, port);
}
getShallowDependencies(options: {
entryFile: string,
platform?: string,
}): Promise<Array<Module>> {
getShallowDependencies(options: DependencyOptions): Promise<Array<Module>> {
return Promise.resolve().then(() => {
if (!options.platform) {
options.platform = getPlatformExtension(options.entryFile);
}
const opts = dependencyOpts(options);
return this._bundler.getShallowDependencies(opts);
const platform = options.platform != null
? options.platform : getPlatformExtension(options.entryFile);
const {entryFile, dev, minify, hot} = options;
return this._bundler.getShallowDependencies(
{entryFile, platform, dev, minify, hot, generateSourceMaps: false},
);
});
}
@ -309,24 +287,24 @@ class Server {
return this._bundler.getModuleForPath(entryFile);
}
getDependencies(options: {
entryFile: string,
platform: ?string,
}): Promise<ResolutionResponse<Module, *>> {
getDependencies(options: DependencyOptions): Promise<ResolutionResponse<Module, *>> {
return Promise.resolve().then(() => {
if (!options.platform) {
options.platform = getPlatformExtension(options.entryFile);
}
const opts = dependencyOpts(options);
return this._bundler.getDependencies(opts);
const platform = options.platform != null
? options.platform : getPlatformExtension(options.entryFile);
const {entryFile, dev, minify, hot} = options;
return this._bundler.getDependencies(
{entryFile, platform, dev, minify, hot, generateSourceMaps: false},
);
});
}
getOrderedDependencyPaths(options: {}): Promise<mixed> {
getOrderedDependencyPaths(options: {
+entryFile: string,
+dev: boolean,
+platform: string,
}): Promise<mixed> {
return Promise.resolve().then(() => {
const opts = dependencyOpts(options);
return this._bundler.getOrderedDependencyPaths(opts);
return this._bundler.getOrderedDependencyPaths(options);
});
}