Skip to content

Commit

Permalink
Move remaining things to named exports (#18165)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
sebmarkbage committed Feb 28, 2020
1 parent 739f20b commit 549e418
Show file tree
Hide file tree
Showing 40 changed files with 113 additions and 200 deletions.
4 changes: 1 addition & 3 deletions packages/eslint-plugin-react-hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
* LICENSE file in the root directory of this source tree.
*/

'use strict';

module.exports = require('./src/index');
export * from './src/index';
6 changes: 1 addition & 5 deletions packages/react-art/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
* @flow
*/

'use strict';

const Circle = require('./npm/Circle');

module.exports = Circle;
export {default} from './npm/Circle';
6 changes: 1 addition & 5 deletions packages/react-art/Rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
* @flow
*/

'use strict';

const Rectangle = require('./npm/Rectangle');

module.exports = Rectangle;
export {default} from './npm/Rectangle';
6 changes: 1 addition & 5 deletions packages/react-art/Wedge.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
* @flow
*/

'use strict';

const Wedge = require('./npm/Wedge');

module.exports = Wedge;
export {default} from './npm/Wedge';
6 changes: 1 addition & 5 deletions packages/react-art/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
* @flow
*/

'use strict';

const ReactART = require('./src/ReactART');

module.exports = ReactART;
export * from './src/ReactART';
23 changes: 13 additions & 10 deletions packages/react-art/src/__tests__/ReactART-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,26 @@

'use strict';

const React = require('react');
import * as React from 'react';

import * as ReactART from 'react-art';
import ARTSVGMode from 'art/modes/svg';
import ARTCurrentMode from 'art/modes/current';
// Since these are default exports, we need to import them using ESM.
// Since they must be on top, we need to import this before ReactDOM.
import Circle from 'react-art/Circle';
import Rectangle from 'react-art/Rectangle';
import Wedge from 'react-art/Wedge';

// Isolate DOM renderer.
jest.resetModules();
const ReactDOM = require('react-dom');
const ReactTestUtils = require('react-dom/test-utils');

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

// Isolate ART renderer.
jest.resetModules();
const ReactART = require('react-art');
const ARTSVGMode = require('art/modes/svg');
const ARTCurrentMode = require('art/modes/current');
const Circle = require('react-art/Circle');
const Rectangle = require('react-art/Rectangle');
const Wedge = require('react-art/Wedge');

// Isolate the noop renderer
jest.resetModules();
const ReactNoop = require('react-noop-renderer');
Expand Down
7 changes: 1 addition & 6 deletions packages/react-debug-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const ReactDebugTools = require('./src/ReactDebugTools');

// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactDebugTools.default || ReactDebugTools;
export * from './src/ReactDebugTools';
8 changes: 1 addition & 7 deletions packages/react-flight-dom-webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@
* @flow
*/

'use strict';

const ReactFlightDOMClient = require('./src/ReactFlightDOMClient');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest
module.exports = ReactFlightDOMClient.default || ReactFlightDOMClient;
export * from './src/ReactFlightDOMClient';
9 changes: 1 addition & 8 deletions packages/react-flight-dom-webpack/server.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,4 @@
* @flow
*/

'use strict';

const ReactFlightDOMServerBrowser = require('./src/ReactFlightDOMServerBrowser');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest
module.exports =
ReactFlightDOMServerBrowser.default || ReactFlightDOMServerBrowser;
export * from './src/ReactFlightDOMServerBrowser';
4 changes: 1 addition & 3 deletions packages/react-flight-dom-webpack/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
* @flow
*/

'use strict';

module.exports = require('./server.node');
export * from './server.node';
8 changes: 1 addition & 7 deletions packages/react-flight-dom-webpack/server.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@
* @flow
*/

'use strict';

const ReactFlightDOMServerNode = require('./src/ReactFlightDOMServerNode');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest
module.exports = ReactFlightDOMServerNode.default || ReactFlightDOMServerNode;
export * from './src/ReactFlightDOMServerNode';
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,4 @@ function readFromXHR<T>(request: XMLHttpRequest): ReactModelRoot<T> {
return getModelRoot(response);
}

export default {
readFromXHR,
readFromFetch,
readFromReadableStream,
};
export {readFromXHR, readFromFetch, readFromReadableStream};
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ function renderToReadableStream(model: ReactModel): ReadableStream {
});
}

export default {
renderToReadableStream,
};
export {renderToReadableStream};
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,4 @@ function pipeToNodeWritable(model: ReactModel, destination: Writable): void {
startWork(request);
}

export default {
pipeToNodeWritable,
};
export {pipeToNodeWritable};
8 changes: 1 addition & 7 deletions packages/react-flight/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,4 @@
// `react-server/inline-typed` (which *is*) for the current renderer.
// On CI, we run Flow checks for each renderer separately.

'use strict';

const ReactFlightClient = require('./src/ReactFlightClient');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactFlightClient.default || ReactFlightClient;
export * from './src/ReactFlightClient';
4 changes: 1 addition & 3 deletions packages/react-interactions/events/context-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
* @flow
*/

'use strict';

module.exports = require('./src/dom/ContextMenu');
export * from './src/dom/ContextMenu';
4 changes: 1 addition & 3 deletions packages/react-interactions/events/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
* @flow
*/

'use strict';

module.exports = require('./src/dom/Focus');
export * from './src/dom/Focus';
4 changes: 1 addition & 3 deletions packages/react-interactions/events/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
* @flow
*/

'use strict';

module.exports = require('./src/dom/Hover');
export * from './src/dom/Hover';
4 changes: 1 addition & 3 deletions packages/react-interactions/events/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
* @flow
*/

'use strict';

module.exports = require('./src/dom/Input');
export * from './src/dom/Input';
4 changes: 1 addition & 3 deletions packages/react-interactions/events/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
* @flow
*/

'use strict';

module.exports = require('./src/dom/Keyboard');
export * from './src/dom/Keyboard';
4 changes: 1 addition & 3 deletions packages/react-interactions/events/press-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
* @flow
*/

'use strict';

module.exports = require('./src/dom/PressLegacy');
export * from './src/dom/PressLegacy';
4 changes: 1 addition & 3 deletions packages/react-interactions/events/press.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
* @flow
*/

'use strict';

module.exports = require('./src/dom/Press');
export * from './src/dom/Press';
4 changes: 1 addition & 3 deletions packages/react-interactions/events/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
* @flow
*/

'use strict';

module.exports = require('./src/dom/Tap');
export * from './src/dom/Tap';
8 changes: 1 addition & 7 deletions packages/react-noop-renderer/flight-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@
* @flow
*/

'use strict';

const ReactNoopFlightClient = require('./src/ReactNoopFlightClient');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactNoopFlightClient.default || ReactNoopFlightClient;
export * from './src/ReactNoopFlightClient';
8 changes: 1 addition & 7 deletions packages/react-noop-renderer/flight-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@
* @flow
*/

'use strict';

const ReactNoopFlightServer = require('./src/ReactNoopFlightServer');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactNoopFlightServer.default || ReactNoopFlightServer;
export * from './src/ReactNoopFlightServer';
8 changes: 1 addition & 7 deletions packages/react-noop-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@
* @flow
*/

'use strict';

const ReactNoop = require('./src/ReactNoop');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactNoop.default || ReactNoop;
export * from './src/ReactNoop';
8 changes: 1 addition & 7 deletions packages/react-noop-renderer/persistent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@
* @flow
*/

'use strict';

const ReactNoopPersistent = require('./src/ReactNoopPersistent');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactNoopPersistent.default || ReactNoopPersistent;
export * from './src/ReactNoopPersistent';
8 changes: 1 addition & 7 deletions packages/react-noop-renderer/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@
* @flow
*/

'use strict';

const ReactNoopServer = require('./src/ReactNoopServer');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactNoopServer.default || ReactNoopServer;
export * from './src/ReactNoopServer';
33 changes: 30 additions & 3 deletions packages/react-noop-renderer/src/ReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,36 @@
import ReactFiberReconciler from 'react-reconciler';
import createReactNoop from './createReactNoop';

const ReactNoop = createReactNoop(
export const {
_Scheduler,
getChildren,
getPendingChildren,
getOrCreateRootContainer,
createRoot,
createBlockingRoot,
getChildrenAsJSX,
getPendingChildrenAsJSX,
createPortal,
render,
renderLegacySyncRoot,
renderToRootWithID,
unmountRootWithID,
findInstance,
flushNextYield,
flushWithHostCounters,
expire,
flushExpired,
batchedUpdates,
deferredUpdates,
unbatchedUpdates,
discreteUpdates,
flushDiscreteUpdates,
flushSync,
flushPassiveEffects,
act,
dumpTree,
getRoot,
} = createReactNoop(
ReactFiberReconciler, // reconciler
true, // useMutation
);

export default ReactNoop;
4 changes: 1 addition & 3 deletions packages/react-noop-renderer/src/ReactNoopFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,4 @@ function read<T>(source: Source): ReactModelRoot<T> {
return getModelRoot(response);
}

export default {
read,
};
export {read};
4 changes: 1 addition & 3 deletions packages/react-noop-renderer/src/ReactNoopFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,4 @@ function render(model: ReactModel): Destination {
return destination;
}

export default {
render,
};
export {render};
33 changes: 30 additions & 3 deletions packages/react-noop-renderer/src/ReactNoopPersistent.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,36 @@
import ReactFiberPersistentReconciler from 'react-reconciler/persistent';
import createReactNoop from './createReactNoop';

const ReactNoopPersistent = createReactNoop(
export const {
_Scheduler,
getChildren,
getPendingChildren,
getOrCreateRootContainer,
createRoot,
createBlockingRoot,
getChildrenAsJSX,
getPendingChildrenAsJSX,
createPortal,
render,
renderLegacySyncRoot,
renderToRootWithID,
unmountRootWithID,
findInstance,
flushNextYield,
flushWithHostCounters,
expire,
flushExpired,
batchedUpdates,
deferredUpdates,
unbatchedUpdates,
discreteUpdates,
flushDiscreteUpdates,
flushSync,
flushPassiveEffects,
act,
dumpTree,
getRoot,
} = createReactNoop(
ReactFiberPersistentReconciler, // reconciler
false, // useMutation
);

export default ReactNoopPersistent;
Loading

0 comments on commit 549e418

Please sign in to comment.