Skip to content

Commit 7c802de

Browse files
authored
[react-a11y] Add react-ui/accessibility to bundle build (#16804)
1 parent 901139c commit 7c802de

File tree

9 files changed

+90
-7
lines changed

9 files changed

+90
-7
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
'use strict';
11+
12+
module.exports = require('./src/FocusTable');

packages/react-ui/accessibility/src/ReactFocusTable.js renamed to packages/react-ui/accessibility/src/FocusTable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {ReactScopeMethods} from 'shared/ReactTypes';
1111
import type {KeyboardEvent} from 'react-ui/events/keyboard';
1212

1313
import React from 'react';
14-
import {tabFocusableImpl} from './TabbableScope';
14+
import {tabFocusableImpl} from 'react-ui/accessibility/tabbable-scope';
1515
import {useKeyboard} from 'react-ui/events/keyboard';
1616

1717
type FocusCellProps = {

packages/react-ui/accessibility/src/ReactTabFocus.js renamed to packages/react-ui/accessibility/src/TabFocus.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {ReactScopeMethods} from 'shared/ReactTypes';
1111
import type {KeyboardEvent} from 'react-ui/events/keyboard';
1212

1313
import React from 'react';
14-
import {TabbableScope} from './TabbableScope';
14+
import {TabbableScope} from 'react-ui/accessibility/tabbable-scope';
1515
import {useKeyboard} from 'react-ui/events/keyboard';
1616

1717
type TabFocusControllerProps = {

packages/react-ui/accessibility/src/__tests__/ReactFocusTable-test.internal.js renamed to packages/react-ui/accessibility/src/__tests__/FocusTable-test.internal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('ReactFocusTable', () => {
1919
ReactFeatureFlags = require('shared/ReactFeatureFlags');
2020
ReactFeatureFlags.enableScopeAPI = true;
2121
ReactFeatureFlags.enableFlareAPI = true;
22-
createFocusTable = require('../ReactFocusTable').createFocusTable;
22+
createFocusTable = require('../FocusTable').createFocusTable;
2323
React = require('react');
2424
});
2525

packages/react-ui/accessibility/src/__tests__/TabFocusController-test.internal.js renamed to packages/react-ui/accessibility/src/__tests__/TabFocus-test.internal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('TabFocusController', () => {
2020
ReactFeatureFlags = require('shared/ReactFeatureFlags');
2121
ReactFeatureFlags.enableScopeAPI = true;
2222
ReactFeatureFlags.enableFlareAPI = true;
23-
ReactTabFocus = require('../ReactTabFocus');
23+
ReactTabFocus = require('../TabFocus');
2424
TabFocusController = ReactTabFocus.TabFocusController;
2525
React = require('react');
2626
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
'use strict';
11+
12+
module.exports = require('./src/TabFocus');
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
'use strict';
11+
12+
module.exports = require('./src/TabbableScope');

scripts/rollup/build.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ function getPlugins(
338338
useForks(forks),
339339
// Ensure we don't try to bundle any fbjs modules.
340340
forbidFBJSImports(),
341+
// Replace any externals with their valid internal FB mappings
342+
isFBBundle && replace(Bundles.fbBundleExternalsMap),
341343
// Use Node resolution mechanism.
342344
resolve({
343345
skip: externals,
@@ -452,11 +454,11 @@ async function createBundle(bundle, bundleType) {
452454
const packageName = Packaging.getPackageName(bundle.entry);
453455

454456
let resolvedEntry = require.resolve(bundle.entry);
455-
if (
457+
const isFBBundle =
456458
bundleType === FB_WWW_DEV ||
457459
bundleType === FB_WWW_PROD ||
458-
bundleType === FB_WWW_PROFILING
459-
) {
460+
bundleType === FB_WWW_PROFILING;
461+
if (isFBBundle) {
460462
const resolvedFBEntry = resolvedEntry.replace('.js', '.fb.js');
461463
if (fs.existsSync(resolvedFBEntry)) {
462464
resolvedEntry = resolvedFBEntry;
@@ -473,6 +475,10 @@ async function createBundle(bundle, bundleType) {
473475
const deps = Modules.getDependencies(bundleType, bundle.entry);
474476
externals = externals.concat(deps);
475477
}
478+
if (isFBBundle) {
479+
// Add any mapped fb bundle externals
480+
externals = externals.concat(Object.values(Bundles.fbBundleExternalsMap));
481+
}
476482

477483
const importSideEffects = Modules.getImportSideEffects();
478484
const pureExternalModules = Object.keys(importSideEffects).filter(

scripts/rollup/bundles.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,48 @@ const bundles = [
659659
global: 'ReactEventsTap',
660660
externals: ['react'],
661661
},
662+
663+
// React UI - Accessibility
664+
665+
{
666+
bundleTypes: [NODE_DEV, NODE_PROD, FB_WWW_DEV, FB_WWW_PROD],
667+
moduleType: NON_FIBER_RENDERER,
668+
entry: 'react-ui/accessibility/focus-table',
669+
global: 'ReactFocusTable',
670+
externals: [
671+
'react',
672+
'react-ui/events/keyboard',
673+
'react-ui/accessibility/tabbable-scope',
674+
],
675+
},
676+
677+
{
678+
bundleTypes: [NODE_DEV, NODE_PROD, FB_WWW_DEV, FB_WWW_PROD],
679+
moduleType: NON_FIBER_RENDERER,
680+
entry: 'react-ui/accessibility/tab-focus',
681+
global: 'TabFocus',
682+
externals: [
683+
'react',
684+
'react-ui/events/keyboard',
685+
'react-ui/accessibility/tabbable-scope',
686+
],
687+
},
688+
689+
{
690+
bundleTypes: [NODE_DEV, NODE_PROD, FB_WWW_DEV, FB_WWW_PROD],
691+
moduleType: NON_FIBER_RENDERER,
692+
entry: 'react-ui/accessibility/tabbable-scope',
693+
global: 'ReactTabbableScope',
694+
externals: ['react'],
695+
},
662696
];
663697

698+
const fbBundleExternalsMap = {
699+
'react-ui/events/keyboard': 'ReactEventsKeyboard',
700+
'react-ui/events/tap': 'ReactEventsTap',
701+
'react-ui/accessibility/tabbable-scope': 'ReactTabbableScope',
702+
};
703+
664704
// Based on deep-freeze by substack (public domain)
665705
function deepFreeze(o) {
666706
Object.freeze(o);
@@ -682,6 +722,7 @@ deepFreeze(bundleTypes);
682722
deepFreeze(moduleTypes);
683723

684724
module.exports = {
725+
fbBundleExternalsMap,
685726
bundleTypes,
686727
moduleTypes,
687728
bundles,

0 commit comments

Comments
 (0)