add --dev flag to the packager's dependencies command

Summary:
The packager dependencies CLI command always operates on --dev=true today. This means any tooling that needs to get the production dependencies (--dev=false) will always get the dev-mode list instead. For instance:

```
if (__DEV__) {
  require('Foobar');
}
```

Previously, `Foobar.js` will always be listed in the CLI output. With this change, setting `--dev false` option will correctly skip `Foobar.js` in the output.

Reviewed By: cpojer

Differential Revision: D5163184

fbshipit-source-id: 203221ee5d6ecb7df575442f12f6c4c489bfbd46
This commit is contained in:
Kevin Gozali 2017-06-01 13:51:58 -07:00 committed by Facebook Github Bot
parent 220ff2321a
commit d41c9d94fd
4 changed files with 16 additions and 2 deletions

View File

@ -47,6 +47,9 @@ function dependencies(argv, config, args, packagerInstance) {
const options = {
platform: args.platform,
entryFile: relativePath,
dev: args.dev,
minify: !args.dev,
generateSourceMaps: !args.dev,
};
const writeToFile = args.output;
@ -94,6 +97,11 @@ module.exports = {
}, {
command: '--transformer [path]',
description: 'Specify a custom transformer to be used'
}, {
command: '--dev [boolean]',
description: 'If false, skip all dev-only code path',
parse: (val) => val === 'false' ? false : true,
default: true,
}, {
command: '--verbose',
description: 'Enables logging',

View File

@ -596,12 +596,14 @@ class Bundler {
return response;
}
getOrderedDependencyPaths({entryFile, dev, platform}: {
getOrderedDependencyPaths({entryFile, dev, platform, minify, generateSourceMaps}: {
+entryFile: string,
+dev: boolean,
+platform: string,
+minify: boolean,
+generateSourceMaps: boolean,
}) {
return this.getDependencies({entryFile, dev, platform}).then(
return this.getDependencies({entryFile, dev, platform, minify, generateSourceMaps}).then(
({dependencies}) => {
const ret = [];
const promises = [];

View File

@ -319,6 +319,8 @@ class Server {
+entryFile: string,
+dev: boolean,
+platform: string,
+minify: boolean,
+generateSourceMaps: boolean,
}): Promise<mixed> {
return Promise.resolve().then(() => {
return this._bundler.getOrderedDependencyPaths(options);

View File

@ -92,6 +92,8 @@ exports.getOrderedDependencyPaths = function(options: Options, depOptions: {
+entryFile: string,
+dev: boolean,
+platform: string,
+minify: boolean,
+generateSourceMaps: boolean,
}) {
var server = createNonPersistentServer(options);
return server.getOrderedDependencyPaths(depOptions)