Skip to content

Commit cb6c4cc

Browse files
committed
Merge pull request #95 from skevy/rn-0.18-compat
RN 0.18 Compatibility changes
2 parents 86f3318 + 7b58cbe commit cb6c4cc

File tree

9 files changed

+106
-16
lines changed

9 files changed

+106
-16
lines changed

gulpfile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ var runSequence = require('run-sequence');
99

1010
var babelPluginDEV = require('fbjs-scripts/babel/dev-expression');
1111
var babelDefaultOptions = require('fbjs-scripts/babel/default-options');
12-
var gulpModuleMap = require('fbjs-scripts/gulp/module-map.js');
12+
var gulpModuleMap = require('fbjs-scripts/gulp/module-map');
13+
var gulpStripProvidesModule = require('fbjs-scripts/gulp/strip-provides-module');
1314

1415
var paths = {
1516
lib: {
@@ -50,6 +51,7 @@ gulp.task('lib', function() {
5051
var libTask = gulp
5152
.src(paths.lib.src)
5253
.pipe(gulpModuleMap(moduleMapOpts))
54+
.pipe(gulpStripProvidesModule())
5355
.pipe(babel(babelOpts))
5456
.pipe(flatten())
5557
.pipe(gulp.dest(paths.lib.dest));

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363
"dependencies": {
6464
"core-js": "^1.0.0",
6565
"loose-envify": "^1.0.0",
66+
"isomorphic-fetch": "^2.1.1",
6667
"promise": "^7.0.3",
67-
"ua-parser-js": "^0.7.9",
68-
"whatwg-fetch": "^0.9.0"
68+
"ua-parser-js": "^0.7.9"
6969
},
7070
"devEngines": {
7171
"node": ">=3",

scripts/babel/default-options.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ module.exports = {
4343
plugins: plugins,
4444
_moduleMap: {
4545
'core-js/library/es6/map': 'core-js/library/es6/map',
46+
'isomorphic-fetch': 'isomorphic-fetch',
4647
'promise': 'promise',
48+
'promise/setimmediate/done': 'promise/setimmediate/done',
49+
'promise/setimmediate/es6-extensions': 'promise/setimmediate/es6-extensions',
4750
'ua-parser-js': 'ua-parser-js',
48-
'whatwg-fetch': 'whatwg-fetch',
4951
},
5052
};

scripts/gulp/module-map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var through = require('through2');
1414
var fs = require('fs');
1515
var path = require('path');
1616

17-
var PM_REGEXP = /\r?\n \* \@providesModule (\S+)\r?\n/;
17+
var PM_REGEXP = require('./shared/provides-module').regexp;
1818

1919
var PLUGIN_NAME = 'module-map';
2020

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright 2013-2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
'use strict';
11+
12+
module.exports = {
13+
regexp: /\r?\n \* \@providesModule (\S+)(?=\r?\n)/,
14+
};

scripts/gulp/strip-provides-module.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2013-2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
'use strict';
11+
12+
var gutil = require('gulp-util');
13+
var through = require('through2');
14+
var PM_REGEXP = require('./shared/provides-module').regexp;
15+
16+
module.exports = function(opts) {
17+
function transform(file, enc, cb) {
18+
if (file.isNull()) {
19+
cb(null, file);
20+
return;
21+
}
22+
23+
if (file.isStream()) {
24+
cb(new gutil.PluginError('module-map', 'Streaming not supported'));
25+
return;
26+
}
27+
28+
// Get the @providesModule piece out of the file and save that.
29+
var contents = file.contents.toString().replace(PM_REGEXP, '');
30+
file.contents = new Buffer(contents);
31+
this.push(file);
32+
cb();
33+
}
34+
35+
return through.obj(transform);
36+
};

src/__forks__/Promise.native.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
*
3+
* Copyright 2013-2016 Facebook, Inc.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* This module wraps and augments the minimally ES6-compliant Promise
10+
* implementation provided by the promise npm package.
11+
*
12+
*/
13+
14+
'use strict';
15+
16+
var Promise = require('promise/setimmediate/es6-extensions');
17+
require('promise/setimmediate/done');
18+
19+
/**
20+
* Handle either fulfillment or rejection with the same callback.
21+
*/
22+
Promise.prototype.finally = function(onSettled) {
23+
return this.then(onSettled, onSettled);
24+
};
25+
26+
module.exports = Promise;

src/__forks__/fetch.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,11 @@
1111

1212
'use strict';
1313

14-
require('whatwg-fetch');
15-
module.exports = self.fetch.bind(self);
14+
// This hopefully supports the React Native case, which is already bringing along
15+
// its own fetch polyfill. That should exist on `global`. If that doesn't exist
16+
// then we'll try to polyfill, which might not work correctly in all environments.
17+
if (global.fetch) {
18+
module.exports = global.fetch.bind(global);
19+
} else {
20+
module.exports = require('isomorphic-fetch');
21+
}

src/stubs/ErrorUtils.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111

1212
/* jslint unused:false */
1313

14-
var ErrorUtils = {
15-
applyWithGuard(callback, context, args, onError, name) {
16-
return callback.apply(context, args);
17-
},
18-
guard(callback, name) {
19-
return callback;
20-
},
21-
};
14+
if (global.ErrorUtils) {
15+
module.exports = global.ErrorUtils;
16+
} else {
17+
var ErrorUtils = {
18+
applyWithGuard(callback, context, args, onError, name) {
19+
return callback.apply(context, args);
20+
},
21+
guard(callback, name) {
22+
return callback;
23+
},
24+
};
2225

23-
module.exports = ErrorUtils;
26+
module.exports = ErrorUtils;
27+
}

0 commit comments

Comments
 (0)