Allow custom platforms for the RN Packager on a per-project basis

Reviewed By: cpojer

Differential Revision: D4255979

fbshipit-source-id: bf900b67ee30e2f994e96c9a6103ed2e53a87f88
This commit is contained in:
Andrew Imm 2016-12-02 09:41:28 -08:00 committed by Facebook Github Bot
parent 7014885067
commit f4b738ff8e
5 changed files with 35 additions and 1 deletions

View File

@ -267,6 +267,16 @@ describe('Bundler', function() {
); );
}); });
it('allows overriding the platforms array', () => {
expect(bundler._opts.platforms).toEqual(['ios', 'android', 'windows', 'web']);
const b = new Bundler({
projectRoots,
assetServer: assetServer,
platforms: ['android', 'vr'],
});
expect(b._opts.platforms).toEqual(['android', 'vr']);
});
describe('getOrderedDependencyPaths', () => { describe('getOrderedDependencyPaths', () => {
beforeEach(() => { beforeEach(() => {
assetServer.getAssetData.mockImpl(function(relPath) { assetServer.getAssetData.mockImpl(function(relPath) {

View File

@ -25,6 +25,7 @@ const imageSize = require('image-size');
const path = require('path'); const path = require('path');
const version = require('../../../../package.json').version; const version = require('../../../../package.json').version;
const denodeify = require('denodeify'); const denodeify = require('denodeify');
const defaults = require('../../../defaults');
const { const {
sep: pathSeparator, sep: pathSeparator,
@ -91,6 +92,10 @@ const validateOpts = declareOpts({
type: 'array', type: 'array',
default: ['png'], default: ['png'],
}, },
platforms: {
type: 'array',
default: defaults.platforms,
},
watch: { watch: {
type: 'boolean', type: 'boolean',
default: false, default: false,
@ -126,6 +131,7 @@ type Options = {
getTransformOptions?: GetTransformOptions<*>, getTransformOptions?: GetTransformOptions<*>,
extraNodeModules: {}, extraNodeModules: {},
assetExts: Array<string>, assetExts: Array<string>,
platforms: Array<string>,
watch: boolean, watch: boolean,
assetServer: AssetServer, assetServer: AssetServer,
transformTimeoutInterval: ?number, transformTimeoutInterval: ?number,
@ -200,6 +206,7 @@ class Bundler {
watch: opts.watch, watch: opts.watch,
minifyCode: this._transformer.minify, minifyCode: this._transformer.minify,
moduleFormat: opts.moduleFormat, moduleFormat: opts.moduleFormat,
platforms: opts.platforms,
polyfillModuleNames: opts.polyfillModuleNames, polyfillModuleNames: opts.polyfillModuleNames,
projectRoots: opts.projectRoots, projectRoots: opts.projectRoots,
resetCache: opts.resetCache, resetCache: opts.resetCache,

View File

@ -107,6 +107,15 @@ describe('Resolver', function() {
}); });
}); });
it('passes custom platforms to the dependency graph', function() {
new Resolver({ // eslint-disable-line no-new
projectRoot: '/root',
platforms: ['ios', 'windows', 'vr'],
});
const platforms = DependencyGraph.mock.calls[0][0].platforms;
expect(platforms).toEqual(['ios', 'windows', 'vr']);
});
pit('should get dependencies with polyfills', function() { pit('should get dependencies with polyfills', function() {
var module = createModule('index'); var module = createModule('index');
var deps = [module]; var deps = [module];

View File

@ -39,6 +39,10 @@ const validateOpts = declareOpts({
type: 'array', type: 'array',
required: true, required: true,
}, },
platforms: {
type: 'array',
required: true,
},
cache: { cache: {
type: 'object', type: 'object',
required: true, required: true,
@ -94,7 +98,7 @@ class Resolver {
(opts.blacklistRE && opts.blacklistRE.test(filepath)); (opts.blacklistRE && opts.blacklistRE.test(filepath));
}, },
providesModuleNodeModules: defaults.providesModuleNodeModules, providesModuleNodeModules: defaults.providesModuleNodeModules,
platforms: defaults.platforms, platforms: opts.platforms,
preferNativePlatform: true, preferNativePlatform: true,
watch: opts.watch, watch: opts.watch,
cache: opts.cache, cache: opts.cache,

View File

@ -83,6 +83,10 @@ const validateOpts = declareOpts({
type: 'array', type: 'array',
default: defaults.assetExts, default: defaults.assetExts,
}, },
platforms: {
type: 'array',
default: defaults.platforms,
},
transformTimeoutInterval: { transformTimeoutInterval: {
type: 'number', type: 'number',
required: false, required: false,