diff --git a/ContainerShip/Dockerfile.android b/ContainerShip/Dockerfile.android index 63bfd8a46e563f..605bb33104d0d1 100644 --- a/ContainerShip/Dockerfile.android +++ b/ContainerShip/Dockerfile.android @@ -3,7 +3,6 @@ FROM containership/android-base:latest # set default environment variables ENV GRADLE_OPTS="-Dorg.gradle.jvmargs=\"-Xmx512m -XX:+HeapDumpOnOutOfMemoryError\"" ENV JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF8" -ENV REACT_NATIVE_MAX_WORKERS=1 # add ReactAndroid directory ADD .buckconfig /app/.buckconfig diff --git a/ContainerShip/scripts/run-ci-e2e-tests.sh b/ContainerShip/scripts/run-ci-e2e-tests.sh index 28a341957392b7..e19fa5868d3cd2 100755 --- a/ContainerShip/scripts/run-ci-e2e-tests.sh +++ b/ContainerShip/scripts/run-ci-e2e-tests.sh @@ -17,7 +17,6 @@ AVD_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1) ANDROID_NPM_DEPS="appium@1.5.1 mocha@2.4.5 wd@0.3.11 colors@1.0.3 pretty-data2@0.40.1" CLI_PACKAGE=$ROOT/react-native-cli/react-native-cli-*.tgz PACKAGE=$ROOT/react-native-*.tgz -REACT_NATIVE_MAX_WORKERS=1 # solve issue with max user watches limit echo 65536 | tee -a /proc/sys/fs/inotify/max_user_watches @@ -231,13 +230,13 @@ function e2e_suite() { # js tests if [ $RUN_JS -ne 0 ]; then # Check the packager produces a bundle (doesn't throw an error) - REACT_NATIVE_MAX_WORKERS=1 react-native bundle --platform android --dev true --entry-file index.android.js --bundle-output android-bundle.js + react-native bundle --max-workers 1 --platform android --dev true --entry-file index.android.js --bundle-output android-bundle.js if [ $? -ne 0 ]; then echo "Could not build android bundle" return 1 fi - REACT_NATIVE_MAX_WORKERS=1 react-native bundle --platform ios --dev true --entry-file index.ios.js --bundle-output ios-bundle.js + react-native bundle --max-workers 1 --platform ios --dev true --entry-file index.ios.js --bundle-output ios-bundle.js if [ $? -ne 0 ]; then echo "Could not build iOS bundle" return 1 diff --git a/circle.yml b/circle.yml index ade3772f92bcf6..6b36c93d5d224b 100644 --- a/circle.yml +++ b/circle.yml @@ -69,7 +69,7 @@ test: # integration tests # build JS bundle for instrumentation tests - - REACT_NATIVE_MAX_WORKERS=1 node local-cli/cli.js bundle --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js + - node local-cli/cli.js bundle --max-workers 1 --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js # build test APK - buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=1 # run installed apk with tests diff --git a/local-cli/bundle/buildBundle.js b/local-cli/bundle/buildBundle.js index bb3e7b05b0fad1..ebab913ee7c006 100644 --- a/local-cli/bundle/buildBundle.js +++ b/local-cli/bundle/buildBundle.js @@ -13,7 +13,7 @@ const log = require('../util/log').out('bundle'); const Server = require('metro-bundler/build/Server'); -const Terminal = require('metro-bundler/build/lib/TerminalClass'); +const Terminal = require('metro-bundler/build/lib/Terminal'); const TerminalReporter = require('metro-bundler/build/lib/TerminalReporter'); const TransformCaching = require('metro-bundler/build/lib/TransformCaching'); @@ -38,6 +38,7 @@ function buildBundle( args: OutputOptions & { assetsDest: mixed, entryFile: string, + maxWorkers: number, resetCache: boolean, transformer: string, }, @@ -89,6 +90,7 @@ function buildBundle( getTransformOptions: config.getTransformOptions, globalTransformCache: null, hasteImpl: config.hasteImpl, + maxWorkers: args.maxWorkers, platforms: defaultPlatforms.concat(platforms), postMinifyProcess: config.postMinifyProcess, postProcessModules: config.postProcessModules, diff --git a/local-cli/bundle/bundleCommandLineArgs.js b/local-cli/bundle/bundleCommandLineArgs.js index 15d47de6de28ef..d3dc3cf34a4def 100644 --- a/local-cli/bundle/bundleCommandLineArgs.js +++ b/local-cli/bundle/bundleCommandLineArgs.js @@ -31,6 +31,12 @@ module.exports = [ command: '--bundle-encoding [string]', description: 'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).', default: 'utf8', + }, { + command: '--max-workers [number]', + description: 'Specifies the maximum number of workers the worker-pool ' + + 'will spawn for transforming files. This defaults to the number of the ' + + 'cores available on your machine.', + parse: (workers: string) => Number(workers), }, { command: '--sourcemap-output [string]', description: 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map', diff --git a/local-cli/dependencies/dependencies.js b/local-cli/dependencies/dependencies.js index 5c47721f2d2008..c11c04f9e13551 100644 --- a/local-cli/dependencies/dependencies.js +++ b/local-cli/dependencies/dependencies.js @@ -96,6 +96,12 @@ module.exports = { }, { command: '--transformer [path]', description: 'Specify a custom transformer to be used' + }, { + command: '--max-workers [number]', + description: 'Specifies the maximum number of workers the worker-pool ' + + 'will spawn for transforming files. This defaults to the number of the ' + + 'cores available on your machine.', + parse: (workers: string) => Number(workers), }, { command: '--dev [boolean]', description: 'If false, skip all dev-only code path', diff --git a/local-cli/server/runServer.js b/local-cli/server/runServer.js index 323219bda665eb..ba2e7cbec2d47a 100644 --- a/local-cli/server/runServer.js +++ b/local-cli/server/runServer.js @@ -15,7 +15,7 @@ require('../../setupBabel')(); const InspectorProxy = require('./util/inspectorProxy.js'); const ReactPackager = require('metro-bundler'); -const Terminal = require('metro-bundler/build/lib/TerminalClass'); +const Terminal = require('metro-bundler/build/lib/Terminal'); const attachHMRServer = require('./util/attachHMRServer'); const connect = require('connect'); @@ -46,6 +46,7 @@ import type {Reporter} from 'metro-bundler/build/lib/reporting'; export type Args = {| +assetExts: $ReadOnlyArray, +host: string, + +maxWorkers: number, +nonPersistent: boolean, +platforms: $ReadOnlyArray, +port: number, @@ -160,10 +161,11 @@ function getPackagerServer(args, config) { extraNodeModules: config.extraNodeModules, getTransformOptions: config.getTransformOptions, hasteImpl: config.hasteImpl, + maxWorkers: args.maxWorkers, platforms: defaultPlatforms.concat(args.platforms), polyfillModuleNames: config.getPolyfillModuleNames(), - postProcessModules: config.postProcessModules, postMinifyProcess: config.postMinifyProcess, + postProcessModules: config.postProcessModules, projectRoots: args.projectRoots, providesModuleNodeModules: providesModuleNodeModules, reporter: new LogReporter(terminal), diff --git a/local-cli/server/server.js b/local-cli/server/server.js index b7a4c02dd054dc..0a839c0738cd24 100644 --- a/local-cli/server/server.js +++ b/local-cli/server/server.js @@ -103,6 +103,12 @@ module.exports = { } return null; }, + }, { + command: '--max-workers [number]', + description: 'Specifies the maximum number of workers the worker-pool ' + + 'will spawn for transforming files. This defaults to the number of the ' + + 'cores available on your machine.', + parse: (workers: string) => Number(workers), }, { command: '--skipflow', description: 'Disable flow checks' diff --git a/local-cli/util/Config.js b/local-cli/util/Config.js index 3ead4ff14a1521..5d9564c4fd84f5 100644 --- a/local-cli/util/Config.js +++ b/local-cli/util/Config.js @@ -10,9 +10,8 @@ */ 'use strict'; -const findSymlinksPaths = require('./findSymlinksPaths'); - const blacklist = require('metro-bundler/build/blacklist'); +const findSymlinksPaths = require('./findSymlinksPaths'); const fs = require('fs'); const invariant = require('fbjs/lib/invariant'); const path = require('path'); diff --git a/package.json b/package.json index d6502fce51e370..22f7fce304c764 100644 --- a/package.json +++ b/package.json @@ -182,7 +182,7 @@ "left-pad": "^1.1.3", "lodash": "^4.16.6", "merge-stream": "^1.0.1", - "metro-bundler": "^0.7.4", + "metro-bundler": "^0.8.1", "mime": "^1.3.4", "mime-types": "2.1.11", "minimist": "^1.2.0", diff --git a/scripts/run-ci-e2e-tests.js b/scripts/run-ci-e2e-tests.js index b9b5a9abdb8472..b1e093c13822c0 100644 --- a/scripts/run-ci-e2e-tests.js +++ b/scripts/run-ci-e2e-tests.js @@ -125,12 +125,9 @@ try { } echo(`Starting packager server, ${SERVER_PID}`); - const packagerEnv = Object.create(process.env); - packagerEnv.REACT_NATIVE_MAX_WORKERS = 1; // shelljs exec('', {async: true}) does not emit stdout events, so we rely on good old spawn - const packagerProcess = spawn('npm', ['start'], { - // stdio: 'inherit', - env: packagerEnv + const packagerProcess = spawn('npm', ['start', '--', '--max-workers 1'], { + env: process.env }); SERVER_PID = packagerProcess.pid; // wait a bit to allow packager to startup @@ -193,12 +190,12 @@ try { if (argv.js) { // Check the packager produces a bundle (doesn't throw an error) - if (exec('REACT_NATIVE_MAX_WORKERS=1 react-native bundle --platform android --dev true --entry-file index.android.js --bundle-output android-bundle.js').code) { + if (exec('react-native bundle --max-workers 1 --platform android --dev true --entry-file index.android.js --bundle-output android-bundle.js').code) { echo('Could not build Android bundle'); exitCode = 1; throw Error(exitCode); } - if (exec('REACT_NATIVE_MAX_WORKERS=1 react-native bundle --platform ios --dev true --entry-file index.ios.js --bundle-output ios-bundle.js').code) { + if (exec('react-native --max-workers 1 bundle --platform ios --dev true --entry-file index.ios.js --bundle-output ios-bundle.js').code) { echo('Could not build iOS bundle'); exitCode = 1; throw Error(exitCode);