Skip to content

Commit

Permalink
Merge pull request #148 from philikon/packager_projectRoot
Browse files Browse the repository at this point in the history
Ability to override RN packager's projectRoots and assetRoots settings
  • Loading branch information
philikon committed Dec 24, 2015
2 parents 9db59cc + 6cda497 commit 1eb962f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
26 changes: 23 additions & 3 deletions bin/rnws.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@ const packageJson = require('../package.json');
const createBundle = require('../lib/createBundle');
const Server = require('../lib/Server');

function normalizePlatforms(options) {
function normalizeOptions(options) {
options.platforms = [];
if (options.android) {
options.platforms.push('android');
}
if (options.ios) {
options.platforms.push('ios');
}

if (options.projectRoots) {
options.projectRoots = options.projectRoots.split(',')
.map(dir => path.resolve(process.cwd(), dir));
}
if (options.assetRoots) {
options.assetRoots = options.assetRoots.split(',')
.map(dir => path.resolve(process.cwd(), dir));
}

return options;
}

Expand Down Expand Up @@ -88,6 +98,16 @@ function commonOptions(program) {
'iOS entry module name. Has no effect if \'--no-ios\' is passed. [index.ios]',
'index.ios'
)
.option(
'--projectRoots [projectRoots]',
'List of comma-separated paths for the react-native packager to consider as project root directories',
null
)
.option(
'--assetRoots [assetRoots]',
'List of comma-separated paths for the react-native packager to consider as asset root directories',
null
)
.option(
'-r, --resetCache',
'Remove cached react-native packager files [false]',
Expand All @@ -99,7 +119,7 @@ commonOptions(program.command('start'))
.description('Start the webpack server.')
.option('-r, --hot', 'Enable hot module replacement. [false]', false)
.action(function(options) {
const opts = normalizePlatforms(options.opts());
const opts = normalizeOptions(options.opts());
const server = createServer(opts);
server.start();
});
Expand Down Expand Up @@ -127,7 +147,7 @@ commonOptions(program.command('bundle'))
false
)
.action(function(options) {
const opts = normalizePlatforms(options.opts());
const opts = normalizeOptions(options.opts());
const server = createServer(opts);
const bundlePaths = {
android: opts.androidBundlePath,
Expand Down
13 changes: 9 additions & 4 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Server {
ios: options.iosEntry,
};
this.platforms = options.platforms;
this.projectRoots = options.projectRoots;
this.assetRoots = options.assetRoots;
this.resetCache = !!options.resetCache;
this.hot = !!options.hot;
this.webpackConfig = options.webpackConfig;
Expand Down Expand Up @@ -274,9 +276,11 @@ class Server {
'--root', this.entryDir,
'--port', this.packagerPort,
]).concat(
this.resetCache
? '--reset-cache'
: []
this.projectRoots ? ['--projectRoots', this.projectRoots.join(',')] : []
).concat(
this.assetRoots ? ['--assetRoots', this.assetRoots.join(',')] : []
).concat(
this.resetCache ? '--reset-cache' : []
);
const opts = {stdio: 'inherit'};
this.packageServer = spawn(cmd, args, opts);
Expand Down Expand Up @@ -306,7 +310,8 @@ class Server {
const webpackConfig = this.webpackConfig;
const hot = this.hot;
return getReactNativeExternals({
projectRoot: process.cwd(),
projectRoots: this.projectRoots,
assetRoots: this.assetRoots,
platforms: this.platforms,
}).then(reactNativeExternals => {

Expand Down
7 changes: 4 additions & 3 deletions lib/getReactNativeExternals.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const Promise = require('bluebird');
function getReactNativeExternals(options) {
return Promise.all(options.platforms.map(
(platform) => getReactNativeDependencyNames({
projectRoot: options.projectRoot,
projectRoots: options.projectRoots || [process.cwd()],
assetRoots: options.assetRoots || [process.cwd()],
platform: platform,
})
)).then((moduleNamesGroupedByPlatform) => {
Expand Down Expand Up @@ -45,9 +46,9 @@ function getReactNativeDependencyNames(options) {
const rnEntryPoint = require.resolve('react-native');

return ReactPackager.getDependencies({
assetRoots: [options.projectRoot],
blacklistRE: blacklist(false /* don't blacklist any platform */),
projectRoots: [options.projectRoot],
projectRoots: options.projectRoots,
assetRoots: options.assetRoots,
transformModulePath: require.resolve('react-native/packager/transformer'),
}, {
entryFile: rnEntryPoint,
Expand Down

0 comments on commit 1eb962f

Please sign in to comment.