Skip to content

Commit

Permalink
Delete hasteImpl, providesModuleNodeModules, and modulePathNameMapper (
Browse files Browse the repository at this point in the history
…facebook#24811)

Summary:
**Depends on facebook#25100

This commit depends on having migrated all of RN away from Haste. With 100% standard path-based requires, the key foundation is set and we no longer need `hasteImpl` and related settings in the Jest configuration.

This commit deletes the `hasteImpl` file and setting as well as `providesModuleNodeModules` and `modulePathNameMapper`, removing most of the dependency graph overriding performed by Jest.

## Changelog

[General] [Changed] - Delete hasteImpl, providesModuleNodeModules, and modulePathNameMapper from Jest config
Pull Request resolved: facebook#24811

Differential Revision: D15659274

Pulled By: cpojer

fbshipit-source-id: 8a4a3b97ddf7e38fbe62c6d3cc9c98248bfca343
  • Loading branch information
ide authored and facebook-github-bot committed Jun 5, 2019
1 parent 995b4d3 commit 7a2463e
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 222 deletions.
8 changes: 0 additions & 8 deletions jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,11 @@

'use strict';

const dir = __dirname;

module.exports = {
haste: {
defaultPlatform: 'ios',
platforms: ['android', 'ios', 'native'],
hasteImplModulePath: require.resolve('./jest/hasteImpl.js'),
providesModuleNodeModules: ['react-native'],
},
moduleNameMapper: {
'^React$': require.resolve('react'),
},
modulePathIgnorePatterns: [`${dir}/Libraries/react-native/`],
transform: {
'^.+\\.(js|ts|tsx)$': 'babel-jest',
'^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve(
Expand Down
38 changes: 0 additions & 38 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ module.exports = {
'./jest/setup.js',
],
'timers': 'fake',
'moduleNameMapper': {
'^React$': '<rootDir>/Libraries/react-native/React.js',
},
'testRegex': '/__tests__/.*-test\\.js$',
'testPathIgnorePatterns': [
'/node_modules/',
Expand All @@ -29,46 +26,11 @@ module.exports = {
],
'haste': {
'defaultPlatform': 'ios',
'hasteImplModulePath': '<rootDir>/jest/hasteImpl.js',
'providesModuleNodeModules': [
'react-native',
],
'platforms': [
'ios',
'android',
],
},
'modulePathIgnorePatterns': [
'/node_modules/(?!react|fbjs|react-native|react-transform-hmr|core-js|promise)/',
'node_modules/react/node_modules/fbjs/',
'node_modules/react/lib/ReactDOM.js',
'node_modules/fbjs/lib/Map.js',
'node_modules/fbjs/lib/Promise.js',
'node_modules/fbjs/lib/fetch.js',
'node_modules/fbjs/lib/ErrorUtils.js',
'node_modules/fbjs/lib/URI.js',
'node_modules/fbjs/lib/Deferred.js',
'node_modules/fbjs/lib/PromiseMap.js',
'node_modules/fbjs/lib/UserAgent.js',
'node_modules/fbjs/lib/areEqual.js',
'node_modules/fbjs/lib/base62.js',
'node_modules/fbjs/lib/crc32.js',
'node_modules/fbjs/lib/everyObject.js',
'node_modules/fbjs/lib/fetchWithRetries.js',
'node_modules/fbjs/lib/filterObject.js',
'node_modules/fbjs/lib/flattenArray.js',
'node_modules/fbjs/lib/forEachObject.js',
'node_modules/fbjs/lib/isEmpty.js',
'node_modules/fbjs/lib/removeFromArray.js',
'node_modules/fbjs/lib/resolveImmediate.js',
'node_modules/fbjs/lib/someObject.js',
'node_modules/fbjs/lib/sprintf.js',
'node_modules/fbjs/lib/xhrSimpleDataSerializer.js',
'node_modules/jest-cli',
'node_modules/react/dist',
'node_modules/fbjs/.*/__mocks__/',
'node_modules/fbjs/node_modules/',
],
'unmockedModulePathPatterns': [
'node_modules/react/',
'Libraries/Renderer',
Expand Down
93 changes: 0 additions & 93 deletions jest/__tests__/hasteImpl-test.js

This file was deleted.

85 changes: 2 additions & 83 deletions jest/hasteImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,93 +5,12 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/

'use strict';

const path = require('path');
const cli = require('@react-native-community/cli');

// Use duck-typing because of Facebook-internal infra that doesn't have the cli package.
const {haste} = (cli.loadConfig && cli.loadConfig()) || {
haste: {
providesModuleNodeModules: [],
platforms: ['ios', 'android'],
},
};

// Detect out-of-tree platforms and add them to the whitelists
const pluginRoots /*: Array<string> */ = haste.providesModuleNodeModules.map(
name => path.resolve(__dirname, '../../', name) + path.sep,
);

const pluginNameReducers /*: Array<[RegExp, string]> */ = haste.platforms.map(
name => [new RegExp(`^(.*)\\.(${name})$`), '$1'],
);

const ROOTS = [path.resolve(__dirname, '..') + path.sep, ...pluginRoots];

const BLACKLISTED_PATTERNS /*: Array<RegExp> */ = [
/.*[\\\/]__(mocks|tests)__[\\\/].*/,
/^Libraries[\\\/]Animated[\\\/]src[\\\/]polyfills[\\\/].*/,
/^Libraries[\\\/]Renderer[\\\/]fb[\\\/].*/,
/DerivedData[\\\/].*/,
];

const WHITELISTED_PREFIXES /*: Array<string> */ = [
'IntegrationTests',
'Libraries',
'ReactAndroid',
'RNTester',
];

const NAME_REDUCERS /*: Array<[RegExp, string]> */ = [
// extract basename
[/^(?:.*[\\\/])?([a-zA-Z0-9$_.-]+)$/, '$1'],
// strip .js/.js.flow suffix
[/^(.*)\.js(\.flow)?$/, '$1'],
// strip native suffix
[/^(.*)\.(native)$/, '$1'],
// strip plugin platform suffixes
...pluginNameReducers,
];

function isHastePath(filePath /*: string */) /*: boolean */ {
if (!filePath.endsWith('.js') && !filePath.endsWith('.js.flow')) {
return false;
}

const root = ROOTS.find(r => filePath.startsWith(r));
if (!root) {
return false;
}

filePath = filePath.substr(root.length);
if (BLACKLISTED_PATTERNS.some(pattern => pattern.test(filePath))) {
return false;
}
return WHITELISTED_PREFIXES.some(prefix => filePath.startsWith(prefix));
}

module.exports = {
/*
* @return {string|void} hasteName for module at filePath; or undefined if
* filePath is not a haste module
*/
getHasteName(
filePath /*: string */,
sourceCode /*: ?string */,
) /*: string | void */ {
if (!isHastePath(filePath)) {
return undefined;
}

const hasteName = NAME_REDUCERS.reduce(
(name, [pattern, replacement]) => name.replace(pattern, replacement),
filePath,
);

return hasteName;
getHasteName() {
return undefined;
},
};

0 comments on commit 7a2463e

Please sign in to comment.