Skip to content

Commit

Permalink
Fix 0.49+ breaking changes (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
krizzu authored and satya164 committed Oct 9, 2017
1 parent 740b6c3 commit a5a8eb6
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 2 deletions.
3 changes: 3 additions & 0 deletions integration_tests/__tests__/start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ test('start command displays "Select platform" message', () => {
writeFiles(TEMP_DIR, {
'webpack.haul.js': '{}',
});
writeFiles(path.resolve(TEMP_DIR, 'node_modules', 'react-native'), {
'package.json': JSON.stringify({ version: '0.47.1' }),
});

const { stdout } = runHaulSync(TEMP_DIR, ['start']);
expect(stripAnsi(stdout).trim()).toMatchSnapshot();
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
"react-deep-force-update": "^2.0.1",
"react-hot-loader": "3.0.0-beta.7",
"resolve": "^1.3.3",
"resolve-cwd": "^2.0.0",
"rxjs": "^5.4.2",
"semver": "^5.4.1",
"source-map": "^0.5.6",
"strip-ansi": "^3.0.1",
"webpack": "^2.3.1",
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/cliEntry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ jest.mock('../commands/bundle', () => {
};
});

jest.mock('../utils/getReactNativeVersion.js', () => {
return () => '0.47.1';
});

beforeEach(() => {
// $FlowFixMe
console.log = jest.fn();
Expand Down
1 change: 1 addition & 0 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function createServer(
stats: 'errors-only',
hot: true,
mimeTypes: { 'application/javascript': ['bundle'] },
headers: { 'Content-Type': 'application/javascript' },
watchOptions: {
aggregateTimeout: 300,
poll: 1000,
Expand Down
27 changes: 27 additions & 0 deletions src/utils/getReactNativeVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright 2017-present, Callstack.
* All rights reserved.
*
* @flow
*/

const resolveCwd = require('resolve-cwd');
const fs = require('fs');
const logger = require('../logger');

/**
* Search top-most node_modules for React Native
* and return it's version
*/

module.exports = (): string => {
let rnVersion = '';
try {
const pckJsonLocation = resolveCwd('react-native/package.json');
rnVersion = JSON.parse(fs.readFileSync(pckJsonLocation, 'utf-8')).version;
} catch (error) {
logger.warn(error.toString());
}

return rnVersion;
};
9 changes: 8 additions & 1 deletion src/utils/makeReactNativeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@ const HappyPack = require('happypack');
const path = require('path');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const semver = require('semver');

const AssetResolver = require('../resolvers/AssetResolver');
const HasteResolver = require('../resolvers/HasteResolver');
const moduleResolve = require('../utils/resolveModule');
const getRNVersion = require('../utils/getReactNativeVersion');

const getBabelConfig = require('./getBabelConfig');

const PLATFORMS = ['ios', 'android'];

// Getting Minor version
const rnVersion = getRNVersion();

type ConfigOptions = {
root: string,
dev: boolean,
Expand Down Expand Up @@ -65,7 +70,9 @@ const getDefaultConfig = ({
devtool: bundle ? 'source-map' : 'eval-source-map',
output: {
path: path.join(root, 'dist'),
filename: `index.${platform}.bundle`,
filename: semver.gte(rnVersion, '0.49.0')
? `index.bundle`
: `index.${platform}.bundle`,
publicPath: `http://localhost:${port}/`,
},
module: {
Expand Down
12 changes: 11 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4070,10 +4070,20 @@ require-uncached@^1.0.3:
caller-path "^0.1.0"
resolve-from "^1.0.0"

resolve-cwd@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a"
dependencies:
resolve-from "^3.0.0"

resolve-from@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"

resolve-from@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748"

resolve@1.1.7:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
Expand Down Expand Up @@ -4165,7 +4175,7 @@ sax@^1.2.1:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"

"semver@2 || 3 || 4 || 5", semver@^5.3.0:
"semver@2 || 3 || 4 || 5", semver@^5.3.0, semver@^5.4.1:
version "5.4.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"

Expand Down

0 comments on commit a5a8eb6

Please sign in to comment.