Skip to content

Commit

Permalink
Bring back programmatic packager API
Browse files Browse the repository at this point in the history
Summary:
Brings back parts of the programmatic API removed in 7762f37. This is used by a few people. Also updates the docs accordingly.

cc akaila

Reviewed By: jeanlauliac

Differential Revision: D4226348

fbshipit-source-id: e5c0794f9c5415f14b54d16c6f35f902eafc3064
  • Loading branch information
davidaurelio authored and Facebook Github Bot committed Nov 23, 2016
1 parent 8016d83 commit f9d80a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
33 changes: 19 additions & 14 deletions packager/README.md
Expand Up @@ -90,10 +90,11 @@ ReactPackager is how you mainly interact with the API.
var ReactPackager = require('./react-packager'); var ReactPackager = require('./react-packager');
``` ```


### ReactPackager.middleware(options) ### ReactPackager.buildBundle(serverOptions, bundleOptions)


Returns a function that can be used in a connect-like Builds a bundle according to the provided options.
middleware. Takes the following options:
#### `serverOptions`


* `projectRoots` array (required): Is the roots where your JavaScript * `projectRoots` array (required): Is the roots where your JavaScript
file will exist file will exist
Expand All @@ -109,21 +110,25 @@ middleware. Takes the following options:
* `nonPersistent` boolean, defaults to false: Whether the server * `nonPersistent` boolean, defaults to false: Whether the server
should be used as a persistent deamon to watch files and update should be used as a persistent deamon to watch files and update
itself itself
* `assetRoots` array: Where should the packager look for assets
* `getTransformOptionsModulePath` string: Path to module that exports a function * `getTransformOptionsModulePath` string: Path to module that exports a function
that acts as a middleware for generating options to pass to the transformer that acts as a middleware for generating options to pass to the transformer
based on the bundle and module being transformed. based on the bundle being built.

### ReactPackager.buildPackageFromUrl(options, url)

Build a package from a url (see the `.bundle` endpoint). `options` is
the same options that is passed to `ReactPackager.middleware`


### ReactPackager.getDependencies(options, main) #### `bundleOptions`


Given an entry point module. Recursively collect all the dependent * `entryFile` string (required): the entry file of the bundle, relative to one
modules and return it as an array. `options` is the same options that of the asset roots.
is passed to `ReactPackager.middleware` * `dev` boolean (defaults to `true`): sets a global `__DEV__` variable
which will effect how the React Native core libraries behave.
* `minify` boolean: Whether to minify code and apply production optimizations.
* `runModule` boolean (defaults to `true`): whether to require your entry
point module.
* `inlineSourceMap` boolean, defaults to false: whether to inline
source maps.
* `platform` string: The target platform for the build
* `generateSourceMaps` boolean: Whether to generate source maps.
* `sourceMapUrl` string: The url of the source map (will be appended to
the bundle).


## Debugging ## Debugging


Expand Down
10 changes: 10 additions & 0 deletions packager/react-packager/index.js
Expand Up @@ -15,6 +15,16 @@ const Logger = require('./src/Logger');


exports.createServer = createServer; exports.createServer = createServer;
exports.Logger = Logger; exports.Logger = Logger;

exports.buildBundle = function(options, bundleOptions) {
var server = createNonPersistentServer(options);
return server.buildBundle(bundleOptions)
.then(p => {
server.end();
return p;
});
};

exports.getOrderedDependencyPaths = function(options, bundleOptions) { exports.getOrderedDependencyPaths = function(options, bundleOptions) {
var server = createNonPersistentServer(options); var server = createNonPersistentServer(options);
return server.getOrderedDependencyPaths(bundleOptions) return server.getOrderedDependencyPaths(bundleOptions)
Expand Down

2 comments on commit f9d80a4

@davidaurelio
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @akaila

@akaila
Copy link

@akaila akaila commented on f9d80a4 Nov 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much David !

Please sign in to comment.