diff --git a/Libraries/vendor/core/ErrorUtils.js b/Libraries/vendor/core/ErrorUtils.js index 2d60c4fc37..8fedfc7376 100644 --- a/Libraries/vendor/core/ErrorUtils.js +++ b/Libraries/vendor/core/ErrorUtils.js @@ -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 diff --git a/jest-preset.js b/jest-preset.js index 5a3051ff38..b5554b8f5f 100644 --- a/jest-preset.js +++ b/jest-preset.js @@ -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', diff --git a/jest.config.js b/jest.config.js index d27b605c73..6a99e3ae10 100644 --- a/jest.config.js +++ b/jest.config.js @@ -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)$': '/jest/assetFileTransformer.js', - '.*': './jest/preprocessor.js', - }, - 'setupFiles': [ - './jest/setup.js', - ], - 'timers': 'fake', - 'testRegex': '/__tests__/.*-test\\.js$', - 'testPathIgnorePatterns': [ - '/node_modules/', - '/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/', - '/Libraries/react-native/', - ], + transform: { + '^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': + '/jest/assetFileTransformer.js', + '.*': './jest/preprocessor.js', + }, + setupFiles: ['./jest/setup.js'], + timers: 'fake', + testRegex: '/__tests__/.*-test\\.js$', + testPathIgnorePatterns: [ + '/node_modules/', + '/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/', + '/Libraries/react-native/', + ], }; diff --git a/jest/setup.js b/jest/setup.js index d834e52a99..bc27b00e23 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -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; diff --git a/package.json b/package.json index 268a9e6bc5..8b4a62a4e6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/polyfills/.npmignore b/packages/polyfills/.npmignore new file mode 100644 index 0000000000..9b166b095d --- /dev/null +++ b/packages/polyfills/.npmignore @@ -0,0 +1,3 @@ +**/__mocks__/** +**/__tests__/** +BUCK diff --git a/packages/polyfills/BUCK b/packages/polyfills/BUCK new file mode 100644 index 0000000000..2d48cbf752 --- /dev/null +++ b/packages/polyfills/BUCK @@ -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"], +) diff --git a/Libraries/polyfills/Object.es7.js b/packages/polyfills/Object.es7.js similarity index 100% rename from Libraries/polyfills/Object.es7.js rename to packages/polyfills/Object.es7.js diff --git a/Libraries/polyfills/__tests__/Object.es7-test.js b/packages/polyfills/__tests__/Object.es7-test.js similarity index 100% rename from Libraries/polyfills/__tests__/Object.es7-test.js rename to packages/polyfills/__tests__/Object.es7-test.js diff --git a/Libraries/polyfills/console.js b/packages/polyfills/console.js similarity index 100% rename from Libraries/polyfills/console.js rename to packages/polyfills/console.js diff --git a/Libraries/polyfills/error-guard.js b/packages/polyfills/error-guard.js similarity index 100% rename from Libraries/polyfills/error-guard.js rename to packages/polyfills/error-guard.js diff --git a/packages/polyfills/index.js b/packages/polyfills/index.js new file mode 100644 index 0000000000..b4dd4b63c6 --- /dev/null +++ b/packages/polyfills/index.js @@ -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'), +]; diff --git a/packages/polyfills/package.json b/packages/polyfills/package.json new file mode 100644 index 0000000000..ed96b9f671 --- /dev/null +++ b/packages/polyfills/package.json @@ -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" +} diff --git a/rn-get-polyfills.js b/rn-get-polyfills.js index a0041d6ef1..0bd50234ae 100644 --- a/rn-get-polyfills.js +++ b/rn-get-polyfills.js @@ -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'); diff --git a/scripts/run-ci-e2e-tests.js b/scripts/run-ci-e2e-tests.js index 46fc0cf0c6..ecbaea2409 100644 --- a/scripts/run-ci-e2e-tests.js +++ b/scripts/run-ci-e2e-tests.js @@ -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, '.'); diff --git a/yarn.lock b/yarn.lock index 5f855736ea..0a849b2118 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"