Permalink
Browse files

packager: Server: remove last declareOpts usage and replace by Flow t…

…ypes

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
  • Loading branch information...
jeanlauliac authored and facebook-github-bot committed May 3, 2017
1 parent 89b3cc1 commit e135bacb48666b5577f5e1a3dfdf2b72a0b02b17
@@ -57,10 +57,12 @@ function attachHMRServer({httpServer, path, packagerServer}: HMROptions) {
resolutionResponse: ResolutionResponse<Module, *>,
}> {
return packagerServer.getDependencies({
platform: platform,
dev: true,
hot: true,
entryFile: bundleEntry,
hot: true,
minify: false,
platform: platform,
recursive: true,
}).then(response => {
/* $FlowFixMe: getModuleId might be null */
const {getModuleId}: {getModuleId: () => number} = response;
@@ -73,10 +75,12 @@ function attachHMRServer({httpServer, path, packagerServer}: HMROptions) {
return Promise.resolve({path: dep.path, deps: []});
}
return packagerServer.getShallowDependencies({
platform: platform,
dev: true,
entryFile: dep.path,
hot: true,
entryFile: dep.path
minify: false,
platform: platform,
recursive: true,
}).then(deps => {
return {
path: dep.path,
@@ -174,10 +178,12 @@ function attachHMRServer({httpServer, path, packagerServer}: HMROptions) {
const promise = type === 'delete'
? Promise.resolve()
: packagerServer.getShallowDependencies({
entryFile: filename,
platform: client.platform,
dev: true,
minify: false,
entryFile: filename,
hot: true,
platform: client.platform,
recursive: true,
}).then(deps => {
if (!client) {
return [];
@@ -193,10 +199,11 @@ function attachHMRServer({httpServer, path, packagerServer}: HMROptions) {
// specific response we can compute a non recursive one which
// is the least we need and improve performance.
return packagerServer.getDependencies({
platform: client.platform,
dev: true,
hot: true,
entryFile: filename,
hot: true,
minify: false,
platform: client.platform,
recursive: true,
}).then(response => {
return packagerServer.getModuleForPath(filename).then(module => {
@@ -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;
@@ -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}) => {
@@ -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,42 +272,39 @@ 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},
);
});
}
getModuleForPath(entryFile: string): Promise<Module> {
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);
});
}

0 comments on commit e135bac

Please sign in to comment.