| 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['^shared/ReactFeatureFlags'] = |
| 41 | `<rootDir>/packages/shared/forks/ReactFeatureFlags.readonly`; |
| 42 | |
| 43 | // Map packages to bundles |
| 44 | packages.forEach(name => { |
| 45 | // Root entry point |
| 46 | moduleNameMapper[`^${name}$`] = `<rootDir>/build/${NODE_MODULES_DIR}/${name}`; |
| 47 | // Named entry points |
| 48 | moduleNameMapper[`^${name}\/([^\/]+)$`] = |
| 49 | `<rootDir>/build/${NODE_MODULES_DIR}/${name}/$1`; |
| 50 | }); |
| 51 | |
| 52 | moduleNameMapper['use-sync-external-store/shim/with-selector'] = |
| 53 | `<rootDir>/build/${NODE_MODULES_DIR}/use-sync-external-store/shim/with-selector`; |
| 54 | moduleNameMapper['use-sync-external-store/shim/index.native'] = |
| 55 | `<rootDir>/build/${NODE_MODULES_DIR}/use-sync-external-store/shim/index.native`; |
| 56 | |
| 57 | module.exports = Object.assign({}, baseConfig, { |
| 58 | // Redirect imports to the compiled bundles |
| 59 | moduleNameMapper, |
| 60 | modulePathIgnorePatterns: [ |
| 61 | ...baseConfig.modulePathIgnorePatterns, |
| 62 | 'packages/react-devtools-extensions', |
| 63 | 'packages/react-devtools-facade', |
| 64 | 'packages/react-devtools-shared', |
| 65 | 'packages/react-devtools-cdt-mcp', |
| 66 | ], |
| 67 | // Don't run bundle tests on -test.internal.* files |
| 68 | testPathIgnorePatterns: ['/node_modules/', '-test.internal.js$'], |
| 69 | // Exclude the build output from transforms |
| 70 | transformIgnorePatterns: ['/node_modules/', '<rootDir>/build/'], |
| 71 | setupFiles: [ |
| 72 | ...baseConfig.setupFiles, |
| 73 | require.resolve('./setupTests.build.js'), |
| 74 | ], |
| 75 | }); |