Skip to content

Commit

Permalink
Create @react-native/polyfills package.
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal]

Reviewed By: GijsWeterings

Differential Revision: D22625944

fbshipit-source-id: 1d97550c92115eb637da57e8f38c28e8139f3a8b
  • Loading branch information
cpojer authored and facebook-github-bot committed Jul 22, 2020
1 parent bbb7bef commit a77f2c4
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Libraries/vendor/core/ErrorUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @flow strict
*/

import type {ErrorUtilsT} from '../../polyfills/error-guard';
import type {ErrorUtilsT} from '@react-native/polyfills/error-guard';

/**
* The particular require runtime that we are using looks for a global
Expand Down
2 changes: 1 addition & 1 deletion jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
),
},
transformIgnorePatterns: [
'node_modules/(?!(jest-)?react-native|@react-native-community)',
'node_modules/(?!((jest-)?react-native|@react-native(-community)?)/)',
],
setupFiles: [require.resolve('./jest/setup.js')],
testEnvironment: 'node',
Expand Down
77 changes: 37 additions & 40 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,46 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

'use strict';

module.exports = {
'transform': {
'^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': '<rootDir>/jest/assetFileTransformer.js',
'.*': './jest/preprocessor.js',
},
'setupFiles': [
'./jest/setup.js',
],
'timers': 'fake',
'testRegex': '/__tests__/.*-test\\.js$',
'testPathIgnorePatterns': [
'/node_modules/',
'<rootDir>/template',
'Libraries/Renderer',
'RNTester/e2e',
],
'haste': {
'defaultPlatform': 'ios',
'platforms': [
'ios',
'android',
],
},
'unmockedModulePathPatterns': [
'node_modules/react/',
'Libraries/Renderer',
'promise',
'source-map',
'fastpath',
'denodeify',
'fbjs',
],
'testEnvironment': 'node',
'collectCoverageFrom': [
'Libraries/**/*.js',
],
'coveragePathIgnorePatterns': [
'/__tests__/',
'/vendor/',
'<rootDir>/Libraries/react-native/',
],
transform: {
'^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$':
'<rootDir>/jest/assetFileTransformer.js',
'.*': './jest/preprocessor.js',
},
setupFiles: ['./jest/setup.js'],
timers: 'fake',
testRegex: '/__tests__/.*-test\\.js$',
testPathIgnorePatterns: [
'/node_modules/',
'<rootDir>/template',
'Libraries/Renderer',
'RNTester/e2e',
],
transformIgnorePatterns: ['node_modules/(?!@react-native/)'],
haste: {
defaultPlatform: 'ios',
platforms: ['ios', 'android'],
},
unmockedModulePathPatterns: [
'node_modules/react/',
'Libraries/Renderer',
'promise',
'source-map',
'fastpath',
'denodeify',
'fbjs',
],
testEnvironment: 'node',
collectCoverageFrom: ['Libraries/**/*.js'],
coveragePathIgnorePatterns: [
'/__tests__/',
'/vendor/',
'<rootDir>/Libraries/react-native/',
],
};
4 changes: 2 additions & 2 deletions jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
const MockNativeMethods = jest.requireActual('./MockNativeMethods');
const mockComponent = jest.requireActual('./mockComponent');

jest.requireActual('../Libraries/polyfills/Object.es7.js');
jest.requireActual('../Libraries/polyfills/error-guard');
jest.requireActual('@react-native/polyfills/Object.es7');
jest.requireActual('@react-native/polyfills/error-guard');

global.__DEV__ = true;

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@
"react": "0.0.0-experimental-aae83a4b9"
},
"dependencies": {
"@react-native-community/cli": "^4.10.0",
"@react-native-community/cli-platform-android": "^4.10.0",
"@react-native-community/cli-platform-ios": "^4.10.0",
"@react-native-community/cli": "^4.10.0",
"@react-native/polyfills": "1.0.0",
"abort-controller": "^3.0.0",
"anser": "^1.4.9",
"base64-js": "^1.1.2",
Expand Down
3 changes: 3 additions & 0 deletions packages/polyfills/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/__mocks__/**
**/__tests__/**
BUCK
20 changes: 20 additions & 0 deletions packages/polyfills/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("@fbsource//tools/build_defs/third_party:yarn_defs.bzl", "yarn_workspace")

yarn_workspace(
name = "yarn-workspace",
srcs = glob(
[
"**/*.js",
"**/*.json",
],
exclude = [
"**/__fixtures__/**",
"**/__flowtests__/**",
"**/__mocks__/**",
"**/__tests__/**",
"**/node_modules/**",
"**/node_modules/.bin/**",
],
),
visibility = ["PUBLIC"],
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions packages/polyfills/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

'use strict';

module.exports = () => [
require.resolve('./console.js'),
require.resolve('./error-guard.js'),
require.resolve('./Object.es7.js'),
];
10 changes: 10 additions & 0 deletions packages/polyfills/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@react-native/polyfills",
"version": "1.0.0",
"description": "Polyfills for React Native.",
"repository": {
"type": "git",
"url": "git@github.com:facebook/react-native.git"
},
"license": "MIT"
}
6 changes: 1 addition & 5 deletions rn-get-polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@

'use strict';

module.exports = () => [
require.resolve('./Libraries/polyfills/console.js'),
require.resolve('./Libraries/polyfills/error-guard.js'),
require.resolve('./Libraries/polyfills/Object.es7.js'),
];
module.exports = require('@react-native/polyfills');
2 changes: 1 addition & 1 deletion scripts/run-ci-e2e-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ try {

const METRO_CONFIG = path.join(ROOT, 'metro.config.js');
const RN_GET_POLYFILLS = path.join(ROOT, 'rn-get-polyfills.js');
const RN_POLYFILLS_PATH = 'Libraries/polyfills/';
const RN_POLYFILLS_PATH = 'packages/polyfills/';
exec(`mkdir -p ${RN_POLYFILLS_PATH}`);

cp(METRO_CONFIG, '.');
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,11 @@
"@react-native-community/eslint-plugin@file:packages/eslint-plugin-react-native-community":
version "1.1.0"

"@react-native/polyfills@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@react-native/polyfills/-/polyfills-1.0.0.tgz#05bb0031533598f9458cf65a502b8df0eecae780"
integrity sha512-0jbp4RxjYopTsIdLl+/Fy2TiwVYHy4mgeu07DG4b/LyM0OS/+lPP5c9sbnt/AMlnF6qz2JRZpPpGw1eMNS6A4w==

"@reactions/component@^2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@reactions/component/-/component-2.0.2.tgz#40f8c1c2c37baabe57a0c944edb9310dc1ec6642"
Expand Down

0 comments on commit a77f2c4

Please sign in to comment.