mirror of
https://github.com/status-im/react-native.git
synced 2025-01-26 17:30:25 +00:00
03476a225e
Summary: This pull request adds the ability for a platform developer to provide a `"haste"` key under the `"rnpm"` key in their `package.json` which allows the packager to pick up that platform's javascript files. The intent is to remove the need to have custom platforms hardcoded in. This is inspired by the `"jest": { "haste": {} }` key used by jest. For example, React Native Dom would have an entry like: ```json { "rnpm": { "haste": { "providesModuleNodeModules": [ "react-native-dom" ], "platforms": [ "dom" ] } } } ``` Support for more keys (path blacklists perhaps?) could be added in the future. This succeeds #20662, as per a discussion I had with matthargett. I've got an open discussion over here as well: https://github.com/react-native-community/discussions-and-proposals/issues/21 Pull Request resolved: https://github.com/facebook/react-native/pull/20825 Differential Revision: D9596429 Pulled By: hramos fbshipit-source-id: a02f0da0bea8870bdc45d55e23da8ccbc36249f2
94 lines
2.0 KiB
JavaScript
94 lines
2.0 KiB
JavaScript
/**
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @emails oncall+js_foundation
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const path = require('path');
|
|
|
|
const {getHasteName} = require('../hasteImpl');
|
|
|
|
function getPath(...parts) {
|
|
return path.join(__dirname, '..', '..', ...parts);
|
|
}
|
|
|
|
it('returns the correct haste name for a RN library file', () => {
|
|
expect(
|
|
getHasteName(
|
|
getPath(
|
|
'Libraries',
|
|
'Components',
|
|
'AccessibilityInfo',
|
|
'AccessibilityInfo.js',
|
|
),
|
|
),
|
|
).toEqual('AccessibilityInfo');
|
|
});
|
|
|
|
it('returns the correct haste name for a file with a platform suffix', () => {
|
|
for (const platform of ['android', 'ios', 'native']) {
|
|
expect(
|
|
getHasteName(
|
|
getPath(
|
|
'Libraries',
|
|
'Components',
|
|
'AccessibilityInfo',
|
|
`AccessibilityInfo.${platform}.js`,
|
|
),
|
|
),
|
|
).toEqual('AccessibilityInfo');
|
|
}
|
|
});
|
|
|
|
it('returns the correct haste name for a file with a flow suffix', () => {
|
|
expect(
|
|
getHasteName(
|
|
getPath(
|
|
'Libraries',
|
|
'Components',
|
|
'AccessibilityInfo',
|
|
'AccessibilityInfo.ios.js.flow',
|
|
),
|
|
),
|
|
).toEqual('AccessibilityInfo');
|
|
});
|
|
|
|
it('does not calculate the haste name for a file that is not JS', () => {
|
|
expect(
|
|
getHasteName(
|
|
getPath(
|
|
'Libraries',
|
|
'Components',
|
|
'AccessibilityInfo',
|
|
'AccessibilityInfo.txt',
|
|
),
|
|
),
|
|
).toBe(undefined);
|
|
});
|
|
|
|
it('does not calculate the haste name for a file outside of RN', () => {
|
|
expect(
|
|
getHasteName(getPath('..', 'Libraries', 'AccessibilityInfo.txt')),
|
|
).toBe(undefined);
|
|
});
|
|
|
|
it('does not calculate the haste name for a blacklisted file', () => {
|
|
expect(
|
|
getHasteName(
|
|
getPath(
|
|
'Libraries',
|
|
'Components',
|
|
'__mocks__',
|
|
'AccessibilityInfo',
|
|
'AccessibilityInfo.js',
|
|
),
|
|
),
|
|
).toBe(undefined);
|
|
});
|