Skip to content

Commit 549e418

Browse files
authored
Move remaining things to named exports (#18165)
* Move remaining things to named exports The interesting case here is the noop renderers. The wrappers around the reconciler now changed to use a local export that gets mutated. ReactNoop and ReactNoopPersistent now have to destructure the object to list out the names it's going to export. We should probably refactor ReactNoop away from createReactNoop. Especially since it's also not Flow typed. * Switch interactions to star exports This will have esModule compatibility flag on them. They should ideally export default instead.
1 parent 739f20b commit 549e418

40 files changed

+113
-200
lines changed

packages/eslint-plugin-react-hooks/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
'use strict';
9-
10-
module.exports = require('./src/index');
8+
export * from './src/index';

packages/react-art/Circle.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
const Circle = require('./npm/Circle');
13-
14-
module.exports = Circle;
10+
export {default} from './npm/Circle';

packages/react-art/Rectangle.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
const Rectangle = require('./npm/Rectangle');
13-
14-
module.exports = Rectangle;
10+
export {default} from './npm/Rectangle';

packages/react-art/Wedge.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
const Wedge = require('./npm/Wedge');
13-
14-
module.exports = Wedge;
10+
export {default} from './npm/Wedge';

packages/react-art/index.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
const ReactART = require('./src/ReactART');
13-
14-
module.exports = ReactART;
10+
export * from './src/ReactART';

packages/react-art/src/__tests__/ReactART-test.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,26 @@
1111

1212
'use strict';
1313

14-
const React = require('react');
14+
import * as React from 'react';
15+
16+
import * as ReactART from 'react-art';
17+
import ARTSVGMode from 'art/modes/svg';
18+
import ARTCurrentMode from 'art/modes/current';
19+
// Since these are default exports, we need to import them using ESM.
20+
// Since they must be on top, we need to import this before ReactDOM.
21+
import Circle from 'react-art/Circle';
22+
import Rectangle from 'react-art/Rectangle';
23+
import Wedge from 'react-art/Wedge';
24+
25+
// Isolate DOM renderer.
26+
jest.resetModules();
1527
const ReactDOM = require('react-dom');
1628
const ReactTestUtils = require('react-dom/test-utils');
1729

1830
// Isolate test renderer.
1931
jest.resetModules();
2032
const ReactTestRenderer = require('react-test-renderer');
2133

22-
// Isolate ART renderer.
23-
jest.resetModules();
24-
const ReactART = require('react-art');
25-
const ARTSVGMode = require('art/modes/svg');
26-
const ARTCurrentMode = require('art/modes/current');
27-
const Circle = require('react-art/Circle');
28-
const Rectangle = require('react-art/Rectangle');
29-
const Wedge = require('react-art/Wedge');
30-
3134
// Isolate the noop renderer
3235
jest.resetModules();
3336
const ReactNoop = require('react-noop-renderer');

packages/react-debug-tools/index.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,4 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
'use strict';
9-
10-
const ReactDebugTools = require('./src/ReactDebugTools');
11-
12-
// This is hacky but makes it work with both Rollup and Jest.
13-
module.exports = ReactDebugTools.default || ReactDebugTools;
8+
export * from './src/ReactDebugTools';

packages/react-flight-dom-webpack/index.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
const ReactFlightDOMClient = require('./src/ReactFlightDOMClient');
13-
14-
// TODO: decide on the top-level export form.
15-
// This is hacky but makes it work with both Rollup and Jest
16-
module.exports = ReactFlightDOMClient.default || ReactFlightDOMClient;
10+
export * from './src/ReactFlightDOMClient';

packages/react-flight-dom-webpack/server.browser.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
const ReactFlightDOMServerBrowser = require('./src/ReactFlightDOMServerBrowser');
13-
14-
// TODO: decide on the top-level export form.
15-
// This is hacky but makes it work with both Rollup and Jest
16-
module.exports =
17-
ReactFlightDOMServerBrowser.default || ReactFlightDOMServerBrowser;
10+
export * from './src/ReactFlightDOMServerBrowser';

packages/react-flight-dom-webpack/server.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
module.exports = require('./server.node');
10+
export * from './server.node';

packages/react-flight-dom-webpack/server.node.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
const ReactFlightDOMServerNode = require('./src/ReactFlightDOMServerNode');
13-
14-
// TODO: decide on the top-level export form.
15-
// This is hacky but makes it work with both Rollup and Jest
16-
module.exports = ReactFlightDOMServerNode.default || ReactFlightDOMServerNode;
10+
export * from './src/ReactFlightDOMServerNode';

packages/react-flight-dom-webpack/src/ReactFlightDOMClient.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,4 @@ function readFromXHR<T>(request: XMLHttpRequest): ReactModelRoot<T> {
7979
return getModelRoot(response);
8080
}
8181

82-
export default {
83-
readFromXHR,
84-
readFromFetch,
85-
readFromReadableStream,
86-
};
82+
export {readFromXHR, readFromFetch, readFromReadableStream};

packages/react-flight-dom-webpack/src/ReactFlightDOMServerBrowser.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,4 @@ function renderToReadableStream(model: ReactModel): ReadableStream {
2929
});
3030
}
3131

32-
export default {
33-
renderToReadableStream,
34-
};
32+
export {renderToReadableStream};

packages/react-flight-dom-webpack/src/ReactFlightDOMServerNode.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,4 @@ function pipeToNodeWritable(model: ReactModel, destination: Writable): void {
2626
startWork(request);
2727
}
2828

29-
export default {
30-
pipeToNodeWritable,
31-
};
29+
export {pipeToNodeWritable};

packages/react-flight/index.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,4 @@
1717
// `react-server/inline-typed` (which *is*) for the current renderer.
1818
// On CI, we run Flow checks for each renderer separately.
1919

20-
'use strict';
21-
22-
const ReactFlightClient = require('./src/ReactFlightClient');
23-
24-
// TODO: decide on the top-level export form.
25-
// This is hacky but makes it work with both Rollup and Jest.
26-
module.exports = ReactFlightClient.default || ReactFlightClient;
20+
export * from './src/ReactFlightClient';

packages/react-interactions/events/context-menu.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
module.exports = require('./src/dom/ContextMenu');
10+
export * from './src/dom/ContextMenu';

packages/react-interactions/events/focus.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
module.exports = require('./src/dom/Focus');
10+
export * from './src/dom/Focus';

packages/react-interactions/events/hover.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
module.exports = require('./src/dom/Hover');
10+
export * from './src/dom/Hover';

packages/react-interactions/events/input.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
module.exports = require('./src/dom/Input');
10+
export * from './src/dom/Input';

packages/react-interactions/events/keyboard.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
module.exports = require('./src/dom/Keyboard');
10+
export * from './src/dom/Keyboard';

packages/react-interactions/events/press-legacy.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
module.exports = require('./src/dom/PressLegacy');
10+
export * from './src/dom/PressLegacy';

packages/react-interactions/events/press.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
module.exports = require('./src/dom/Press');
10+
export * from './src/dom/Press';

packages/react-interactions/events/tap.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
module.exports = require('./src/dom/Tap');
10+
export * from './src/dom/Tap';

packages/react-noop-renderer/flight-client.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
const ReactNoopFlightClient = require('./src/ReactNoopFlightClient');
13-
14-
// TODO: decide on the top-level export form.
15-
// This is hacky but makes it work with both Rollup and Jest.
16-
module.exports = ReactNoopFlightClient.default || ReactNoopFlightClient;
10+
export * from './src/ReactNoopFlightClient';

packages/react-noop-renderer/flight-server.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
const ReactNoopFlightServer = require('./src/ReactNoopFlightServer');
13-
14-
// TODO: decide on the top-level export form.
15-
// This is hacky but makes it work with both Rollup and Jest.
16-
module.exports = ReactNoopFlightServer.default || ReactNoopFlightServer;
10+
export * from './src/ReactNoopFlightServer';

packages/react-noop-renderer/index.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
const ReactNoop = require('./src/ReactNoop');
13-
14-
// TODO: decide on the top-level export form.
15-
// This is hacky but makes it work with both Rollup and Jest.
16-
module.exports = ReactNoop.default || ReactNoop;
10+
export * from './src/ReactNoop';

packages/react-noop-renderer/persistent.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
const ReactNoopPersistent = require('./src/ReactNoopPersistent');
13-
14-
// TODO: decide on the top-level export form.
15-
// This is hacky but makes it work with both Rollup and Jest.
16-
module.exports = ReactNoopPersistent.default || ReactNoopPersistent;
10+
export * from './src/ReactNoopPersistent';

packages/react-noop-renderer/server.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
const ReactNoopServer = require('./src/ReactNoopServer');
13-
14-
// TODO: decide on the top-level export form.
15-
// This is hacky but makes it work with both Rollup and Jest.
16-
module.exports = ReactNoopServer.default || ReactNoopServer;
10+
export * from './src/ReactNoopServer';

packages/react-noop-renderer/src/ReactNoop.js

+30-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,36 @@
1717
import ReactFiberReconciler from 'react-reconciler';
1818
import createReactNoop from './createReactNoop';
1919

20-
const ReactNoop = createReactNoop(
20+
export const {
21+
_Scheduler,
22+
getChildren,
23+
getPendingChildren,
24+
getOrCreateRootContainer,
25+
createRoot,
26+
createBlockingRoot,
27+
getChildrenAsJSX,
28+
getPendingChildrenAsJSX,
29+
createPortal,
30+
render,
31+
renderLegacySyncRoot,
32+
renderToRootWithID,
33+
unmountRootWithID,
34+
findInstance,
35+
flushNextYield,
36+
flushWithHostCounters,
37+
expire,
38+
flushExpired,
39+
batchedUpdates,
40+
deferredUpdates,
41+
unbatchedUpdates,
42+
discreteUpdates,
43+
flushDiscreteUpdates,
44+
flushSync,
45+
flushPassiveEffects,
46+
act,
47+
dumpTree,
48+
getRoot,
49+
} = createReactNoop(
2150
ReactFiberReconciler, // reconciler
2251
true, // useMutation
2352
);
24-
25-
export default ReactNoop;

packages/react-noop-renderer/src/ReactNoopFlightClient.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,4 @@ function read<T>(source: Source): ReactModelRoot<T> {
3838
return getModelRoot(response);
3939
}
4040

41-
export default {
42-
read,
43-
};
41+
export {read};

packages/react-noop-renderer/src/ReactNoopFlightServer.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,4 @@ function render(model: ReactModel): Destination {
5252
return destination;
5353
}
5454

55-
export default {
56-
render,
57-
};
55+
export {render};

packages/react-noop-renderer/src/ReactNoopPersistent.js

+30-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,36 @@
1717
import ReactFiberPersistentReconciler from 'react-reconciler/persistent';
1818
import createReactNoop from './createReactNoop';
1919

20-
const ReactNoopPersistent = createReactNoop(
20+
export const {
21+
_Scheduler,
22+
getChildren,
23+
getPendingChildren,
24+
getOrCreateRootContainer,
25+
createRoot,
26+
createBlockingRoot,
27+
getChildrenAsJSX,
28+
getPendingChildrenAsJSX,
29+
createPortal,
30+
render,
31+
renderLegacySyncRoot,
32+
renderToRootWithID,
33+
unmountRootWithID,
34+
findInstance,
35+
flushNextYield,
36+
flushWithHostCounters,
37+
expire,
38+
flushExpired,
39+
batchedUpdates,
40+
deferredUpdates,
41+
unbatchedUpdates,
42+
discreteUpdates,
43+
flushDiscreteUpdates,
44+
flushSync,
45+
flushPassiveEffects,
46+
act,
47+
dumpTree,
48+
getRoot,
49+
} = createReactNoop(
2150
ReactFiberPersistentReconciler, // reconciler
2251
false, // useMutation
2352
);
24-
25-
export default ReactNoopPersistent;

0 commit comments

Comments
 (0)