Skip to content

Commit 5b37c3e

Browse files
andrewimmMartin Konicek
authored and
Martin Konicek
committed
Allow custom platforms for the RN Packager on a per-project basis
Reviewed By: cpojer Differential Revision: D4255979 fbshipit-source-id: bf900b67ee30e2f994e96c9a6103ed2e53a87f88
1 parent cd8cfc3 commit 5b37c3e

File tree

8 files changed

+51
-1
lines changed

8 files changed

+51
-1
lines changed

local-cli/default.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ var config = {
3434
return [];
3535
},
3636

37+
/**
38+
* Specify any additional platforms to be used by the packager.
39+
* For example, if you want to add a "custom" platform, and use modules
40+
* ending in .custom.js, you would return ['custom'] here.
41+
*/
42+
getPlatforms() {
43+
return [];
44+
},
45+
3746
/**
3847
* Returns a regular expression for modules that should be ignored by the
3948
* packager on a given platform.

local-cli/server/runServer.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const connect = require('connect');
1616
const copyToClipBoardMiddleware = require('./middleware/copyToClipBoardMiddleware');
1717
const cpuProfilerMiddleware = require('./middleware/cpuProfilerMiddleware');
1818
const defaultAssetExts = require('../../packager/defaults').assetExts;
19+
const defaultPlatforms = require('../../packager/defaults').platforms;
1920
const getDevToolsMiddleware = require('./middleware/getDevToolsMiddleware');
2021
const heapCaptureMiddleware = require('./middleware/heapCaptureMiddleware.js');
2122
const http = require('http');
@@ -91,6 +92,7 @@ function getPackagerServer(args, config) {
9192
cacheVersion: '3',
9293
extraNodeModules: config.extraNodeModules,
9394
getTransformOptions: config.getTransformOptions,
95+
platforms: defaultPlatforms.concat(args.platforms),
9496
projectRoots: args.projectRoots,
9597
resetCache: args.resetCache,
9698
transformModulePath: transformModulePath,

local-cli/server/server.js

+5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ module.exports = {
9696
description: 'Specify any additional asset extentions to be used by the packager',
9797
parse: (val) => val.split(','),
9898
default: (config) => config.getAssetExts(),
99+
}, {
100+
command: '--platforms [list]',
101+
description: 'Specify any additional platforms to be used by the packager',
102+
parse: (val) => val.split(','),
103+
default: (config) => config.getPlatforms(),
99104
}, {
100105
command: '--skipflow',
101106
description: 'Disable flow checks'

packager/react-packager/src/Bundler/__tests__/Bundler-test.js

+10
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,16 @@ describe('Bundler', function() {
267267
);
268268
});
269269

270+
it('allows overriding the platforms array', () => {
271+
expect(bundler._opts.platforms).toEqual(['ios', 'android', 'windows', 'web']);
272+
const b = new Bundler({
273+
projectRoots,
274+
assetServer: assetServer,
275+
platforms: ['android', 'vr'],
276+
});
277+
expect(b._opts.platforms).toEqual(['android', 'vr']);
278+
});
279+
270280
describe('getOrderedDependencyPaths', () => {
271281
beforeEach(() => {
272282
assetServer.getAssetData.mockImpl(function(relPath) {

packager/react-packager/src/Bundler/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const imageSize = require('image-size');
2525
const path = require('path');
2626
const version = require('../../../../package.json').version;
2727
const denodeify = require('denodeify');
28+
const defaults = require('../../../defaults');
2829

2930
const {
3031
sep: pathSeparator,
@@ -91,6 +92,10 @@ const validateOpts = declareOpts({
9192
type: 'array',
9293
default: ['png'],
9394
},
95+
platforms: {
96+
type: 'array',
97+
default: defaults.platforms,
98+
},
9499
watch: {
95100
type: 'boolean',
96101
default: false,
@@ -126,6 +131,7 @@ type Options = {
126131
getTransformOptions?: GetTransformOptions<*>,
127132
extraNodeModules: {},
128133
assetExts: Array<string>,
134+
platforms: Array<string>,
129135
watch: boolean,
130136
assetServer: AssetServer,
131137
transformTimeoutInterval: ?number,
@@ -200,6 +206,7 @@ class Bundler {
200206
watch: opts.watch,
201207
minifyCode: this._transformer.minify,
202208
moduleFormat: opts.moduleFormat,
209+
platforms: opts.platforms,
203210
polyfillModuleNames: opts.polyfillModuleNames,
204211
projectRoots: opts.projectRoots,
205212
resetCache: opts.resetCache,

packager/react-packager/src/Resolver/__tests__/Resolver-test.js

+9
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ describe('Resolver', function() {
107107
});
108108
});
109109

110+
it('passes custom platforms to the dependency graph', function() {
111+
new Resolver({ // eslint-disable-line no-new
112+
projectRoot: '/root',
113+
platforms: ['ios', 'windows', 'vr'],
114+
});
115+
const platforms = DependencyGraph.mock.calls[0][0].platforms;
116+
expect(platforms).toEqual(['ios', 'windows', 'vr']);
117+
});
118+
110119
pit('should get dependencies with polyfills', function() {
111120
var module = createModule('index');
112121
var deps = [module];

packager/react-packager/src/Resolver/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ const validateOpts = declareOpts({
3939
type: 'array',
4040
required: true,
4141
},
42+
platforms: {
43+
type: 'array',
44+
required: true,
45+
},
4246
cache: {
4347
type: 'object',
4448
required: true,
@@ -94,7 +98,7 @@ class Resolver {
9498
(opts.blacklistRE && opts.blacklistRE.test(filepath));
9599
},
96100
providesModuleNodeModules: defaults.providesModuleNodeModules,
97-
platforms: defaults.platforms,
101+
platforms: opts.platforms,
98102
preferNativePlatform: true,
99103
watch: opts.watch,
100104
cache: opts.cache,

packager/react-packager/src/Server/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ const validateOpts = declareOpts({
8383
type: 'array',
8484
default: defaults.assetExts,
8585
},
86+
platforms: {
87+
type: 'array',
88+
default: defaults.platforms,
89+
},
8690
transformTimeoutInterval: {
8791
type: 'number',
8892
required: false,

0 commit comments

Comments
 (0)