From a3bde7974c48cfa749b18531700f895c86cbad91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Tue, 8 Feb 2022 23:12:31 -0500 Subject: [PATCH] Exclude react-dom/unstable_testing entry point from stable releases (#23258) * Use consistent naming for unstable_testing entry point * Exclude the testing build from non-experimental builds except at FB * FB builds shouldn't contribute to whether we include the npm files * Exclude exports fields if we delete the files entry * Move test to no longer be internal so we can test against the build * Update the bundle artifact names since they've now changed * Gate import since it doesn't exist --- packages/react-dom/npm/unstable_testing.js | 4 +-- ...ernal.js => ReactDOMTestSelectors-test.js} | 30 ++++++++++--------- ...c.fb.js => unstable_testing.classic.fb.js} | 0 ...al.js => unstable_testing.experimental.js} | 0 .../{testing.js => unstable_testing.js} | 0 ...rn.fb.js => unstable_testing.modern.fb.js} | 0 ...g.stable.js => unstable_testing.stable.js} | 0 scripts/rollup/bundles.js | 7 +++-- scripts/rollup/forks.js | 2 +- scripts/rollup/packaging.js | 15 +++++++++- scripts/shared/inlinedHostConfigs.js | 6 ++-- 11 files changed, 40 insertions(+), 24 deletions(-) rename packages/react-dom/src/__tests__/{ReactDOMTestSelectors-test.internal.js => ReactDOMTestSelectors-test.js} (98%) rename packages/react-dom/{testing.classic.fb.js => unstable_testing.classic.fb.js} (100%) rename packages/react-dom/{testing.experimental.js => unstable_testing.experimental.js} (100%) rename packages/react-dom/{testing.js => unstable_testing.js} (100%) rename packages/react-dom/{testing.modern.fb.js => unstable_testing.modern.fb.js} (100%) rename packages/react-dom/{testing.stable.js => unstable_testing.stable.js} (100%) diff --git a/packages/react-dom/npm/unstable_testing.js b/packages/react-dom/npm/unstable_testing.js index 0cb587bf9a9dc..bb0dfdfa8865f 100644 --- a/packages/react-dom/npm/unstable_testing.js +++ b/packages/react-dom/npm/unstable_testing.js @@ -32,7 +32,7 @@ if (process.env.NODE_ENV === 'production') { // DCE check should happen before ReactDOM bundle executes so that // DevTools can report bad minification during injection. checkDCE(); - module.exports = require('./cjs/react-dom-testing.production.min.js'); + module.exports = require('./cjs/react-dom-unstable_testing.production.min.js'); } else { - module.exports = require('./cjs/react-dom-testing.development.js'); + module.exports = require('./cjs/react-dom-unstable_testing.development.js'); } diff --git a/packages/react-dom/src/__tests__/ReactDOMTestSelectors-test.internal.js b/packages/react-dom/src/__tests__/ReactDOMTestSelectors-test.js similarity index 98% rename from packages/react-dom/src/__tests__/ReactDOMTestSelectors-test.internal.js rename to packages/react-dom/src/__tests__/ReactDOMTestSelectors-test.js index 29cf7a9870ec1..ceb1ea598601b 100644 --- a/packages/react-dom/src/__tests__/ReactDOMTestSelectors-test.internal.js +++ b/packages/react-dom/src/__tests__/ReactDOMTestSelectors-test.js @@ -31,21 +31,23 @@ describe('ReactDOMTestSelectors', () => { jest.resetModules(); React = require('react'); - - const ReactDOM = require('react-dom/testing'); act = React.unstable_act; - createComponentSelector = ReactDOM.createComponentSelector; - createHasPseudoClassSelector = ReactDOM.createHasPseudoClassSelector; - createRoleSelector = ReactDOM.createRoleSelector; - createTextSelector = ReactDOM.createTextSelector; - createTestNameSelector = ReactDOM.createTestNameSelector; - findAllNodes = ReactDOM.findAllNodes; - findBoundingRects = ReactDOM.findBoundingRects; - focusWithin = ReactDOM.focusWithin; - getFindAllNodesFailureDescription = - ReactDOM.getFindAllNodesFailureDescription; - observeVisibleRects = ReactDOM.observeVisibleRects; - render = ReactDOM.render; + + if (__EXPERIMENTAL__ || global.__WWW__) { + const ReactDOM = require('react-dom/unstable_testing'); + createComponentSelector = ReactDOM.createComponentSelector; + createHasPseudoClassSelector = ReactDOM.createHasPseudoClassSelector; + createRoleSelector = ReactDOM.createRoleSelector; + createTextSelector = ReactDOM.createTextSelector; + createTestNameSelector = ReactDOM.createTestNameSelector; + findAllNodes = ReactDOM.findAllNodes; + findBoundingRects = ReactDOM.findBoundingRects; + focusWithin = ReactDOM.focusWithin; + getFindAllNodesFailureDescription = + ReactDOM.getFindAllNodesFailureDescription; + observeVisibleRects = ReactDOM.observeVisibleRects; + render = ReactDOM.render; + } container = document.createElement('div'); document.body.appendChild(container); diff --git a/packages/react-dom/testing.classic.fb.js b/packages/react-dom/unstable_testing.classic.fb.js similarity index 100% rename from packages/react-dom/testing.classic.fb.js rename to packages/react-dom/unstable_testing.classic.fb.js diff --git a/packages/react-dom/testing.experimental.js b/packages/react-dom/unstable_testing.experimental.js similarity index 100% rename from packages/react-dom/testing.experimental.js rename to packages/react-dom/unstable_testing.experimental.js diff --git a/packages/react-dom/testing.js b/packages/react-dom/unstable_testing.js similarity index 100% rename from packages/react-dom/testing.js rename to packages/react-dom/unstable_testing.js diff --git a/packages/react-dom/testing.modern.fb.js b/packages/react-dom/unstable_testing.modern.fb.js similarity index 100% rename from packages/react-dom/testing.modern.fb.js rename to packages/react-dom/unstable_testing.modern.fb.js diff --git a/packages/react-dom/testing.stable.js b/packages/react-dom/unstable_testing.stable.js similarity index 100% rename from packages/react-dom/testing.stable.js rename to packages/react-dom/unstable_testing.stable.js diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index 4ac846e78a9a2..5381ffe933544 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -245,12 +245,13 @@ const bundles = [ externals: ['react', 'react-dom'], }, - // TODO: We don't use this bundle anymore /******* React DOM - www - Testing *******/ { moduleType: RENDERER, - bundleTypes: [FB_WWW_DEV, FB_WWW_PROD, NODE_DEV, NODE_PROD], - entry: 'react-dom/testing', + bundleTypes: __EXPERIMENTAL__ + ? [FB_WWW_DEV, FB_WWW_PROD, NODE_DEV, NODE_PROD] + : [FB_WWW_DEV, FB_WWW_PROD], + entry: 'react-dom/unstable_testing', global: 'ReactDOMTesting', minifyWithProdErrorCodes: true, wrapWithModuleBoundaries: false, diff --git a/scripts/rollup/forks.js b/scripts/rollup/forks.js index b2234fa42a010..9cab6e5be3904 100644 --- a/scripts/rollup/forks.js +++ b/scripts/rollup/forks.js @@ -129,7 +129,7 @@ const forks = Object.freeze({ return 'shared/forks/ReactFeatureFlags.test-renderer.www.js'; } return 'shared/forks/ReactFeatureFlags.test-renderer.js'; - case 'react-dom/testing': + case 'react-dom/unstable_testing': switch (bundleType) { case FB_WWW_DEV: case FB_WWW_PROD: diff --git a/scripts/rollup/packaging.js b/scripts/rollup/packaging.js index 793ba1a2da9ac..87675ae9f73c0 100644 --- a/scripts/rollup/packaging.js +++ b/scripts/rollup/packaging.js @@ -139,7 +139,11 @@ let entryPointsToHasBundle = new Map(); for (const bundle of Bundles.bundles) { let hasBundle = entryPointsToHasBundle.get(bundle.entry); if (!hasBundle) { - entryPointsToHasBundle.set(bundle.entry, bundle.bundleTypes.length > 0); + const hasNonFBBundleTypes = bundle.bundleTypes.some( + type => + type !== FB_WWW_DEV && type !== FB_WWW_PROD && type !== FB_WWW_PROFILING + ); + entryPointsToHasBundle.set(bundle.entry, hasNonFBBundleTypes); } } @@ -176,6 +180,15 @@ function filterOutEntrypoints(name) { i--; unlinkSync(`build/node_modules/${name}/${filename}`); changed = true; + // Remove it from the exports field too if it exists. + const exportsJSON = packageJSON.exports; + if (exportsJSON) { + if (filename === 'index.js') { + delete exportsJSON['.']; + } else { + delete exportsJSON['./' + filename.replace(/\.js$/, '')]; + } + } } } if (changed) { diff --git a/scripts/shared/inlinedHostConfigs.js b/scripts/shared/inlinedHostConfigs.js index f6d349502f6ba..5b4520d8b2f11 100644 --- a/scripts/shared/inlinedHostConfigs.js +++ b/scripts/shared/inlinedHostConfigs.js @@ -11,7 +11,7 @@ module.exports = [ shortName: 'dom', entryPoints: [ 'react-dom', - 'react-dom/testing', + 'react-dom/unstable_testing', 'react-dom/src/server/ReactDOMFizzServerNode', 'react-server-dom-webpack/writer.node.server', 'react-server-dom-webpack', @@ -33,14 +33,14 @@ module.exports = [ shortName: 'dom-browser', entryPoints: [ 'react-dom', - 'react-dom/testing', + 'react-dom/unstable_testing', 'react-dom/src/server/ReactDOMFizzServerBrowser', 'react-server-dom-webpack/writer.browser.server', 'react-server-dom-webpack', ], paths: [ 'react-dom', - 'react-dom/testing', + 'react-dom/unstable_testing', 'react-dom/src/server/ReactDOMFizzServerBrowser.js', // react-dom/server.browser 'react-server-dom-webpack', 'react-server-dom-webpack/writer.browser.server',