Skip to content

Commit

Permalink
Exclude react-dom/unstable_testing entry point from stable releases (f…
Browse files Browse the repository at this point in the history
…acebook#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
  • Loading branch information
sebmarkbage authored and zhengjitf committed Apr 15, 2022
1 parent a9ed957 commit dd5fcba
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/react-dom/npm/unstable_testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion scripts/rollup/forks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 14 additions & 1 deletion scripts/rollup/packaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions scripts/shared/inlinedHostConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit dd5fcba

Please sign in to comment.