1. 'use strict';
    
  2. 
    
  3. const {readdirSync, statSync} = require('fs');
    
  4. const {join} = require('path');
    
  5. const baseConfig = require('./config.base');
    
  6. 
    
  7. process.env.IS_BUILD = true;
    
  8. 
    
  9. const NODE_MODULES_DIR =
    
  10.   process.env.RELEASE_CHANNEL === 'stable' ? 'oss-stable' : 'oss-experimental';
    
  11. 
    
  12. // Find all folders in packages/* with package.json
    
  13. const packagesRoot = join(__dirname, '..', '..', 'packages');
    
  14. const packages = readdirSync(packagesRoot).filter(dir => {
    
  15.   if (dir === 'internal-test-utils') {
    
  16.     // This is an internal package used only for testing. It's OK to read
    
  17.     // from source.
    
  18.     // TODO: Maybe let's have some convention for this?
    
  19.     return false;
    
  20.   }
    
  21.   if (dir.charAt(0) === '.') {
    
  22.     return false;
    
  23.   }
    
  24.   const packagePath = join(packagesRoot, dir, 'package.json');
    
  25.   let stat;
    
  26.   try {
    
  27.     stat = statSync(packagePath);
    
  28.   } catch (err) {
    
  29.     return false;
    
  30.   }
    
  31.   return stat.isFile();
    
  32. });
    
  33. 
    
  34. // Create a module map to point React packages to the build output
    
  35. const moduleNameMapper = {};
    
  36. 
    
  37. // Allow bundle tests to read (but not write!) default feature flags.
    
  38. // This lets us determine whether we're running in different modes
    
  39. // without making relevant tests internal-only.
    
  40. moduleNameMapper[
    
  41.   '^shared/ReactFeatureFlags'
    
  42. ] = `<rootDir>/packages/shared/forks/ReactFeatureFlags.readonly`;
    
  43. 
    
  44. // Map packages to bundles
    
  45. packages.forEach(name => {
    
  46.   // Root entry point
    
  47.   moduleNameMapper[`^${name}$`] = `<rootDir>/build/${NODE_MODULES_DIR}/${name}`;
    
  48.   // Named entry points
    
  49.   moduleNameMapper[
    
  50.     `^${name}\/([^\/]+)$`
    
  51.   ] = `<rootDir>/build/${NODE_MODULES_DIR}/${name}/$1`;
    
  52. });
    
  53. 
    
  54. moduleNameMapper[
    
  55.   'use-sync-external-store/shim/with-selector'
    
  56. ] = `<rootDir>/build/${NODE_MODULES_DIR}/use-sync-external-store/shim/with-selector`;
    
  57. moduleNameMapper[
    
  58.   'use-sync-external-store/shim/index.native'
    
  59. ] = `<rootDir>/build/${NODE_MODULES_DIR}/use-sync-external-store/shim/index.native`;
    
  60. 
    
  61. module.exports = Object.assign({}, baseConfig, {
    
  62.   // Redirect imports to the compiled bundles
    
  63.   moduleNameMapper,
    
  64.   modulePathIgnorePatterns: [
    
  65.     ...baseConfig.modulePathIgnorePatterns,
    
  66.     'packages/react-devtools-extensions',
    
  67.     'packages/react-devtools-shared',
    
  68.   ],
    
  69.   // Don't run bundle tests on -test.internal.* files
    
  70.   testPathIgnorePatterns: ['/node_modules/', '-test.internal.js$'],
    
  71.   // Exclude the build output from transforms
    
  72.   transformIgnorePatterns: ['/node_modules/', '<rootDir>/build/'],
    
  73.   setupFiles: [
    
  74.     ...baseConfig.setupFiles,
    
  75.     require.resolve('./setupTests.build.js'),
    
  76.   ],
    
  77. });