3const fs = require('fs');
4const path = require('path');
5const paths = require('./paths');
6const chalk = require('react-dev-utils/chalk');
9 * Get the baseUrl of a compilerOptions object.
11 * @param {Object} options
13function getAdditionalModulePaths(options = {}) {
14 const baseUrl = options.baseUrl;
16 // We need to explicitly check for null and undefined (and not a falsy value) because
17 // TypeScript treats an empty string as `.`.
18 if (baseUrl == null) {
19 // If there's no baseUrl set we respect NODE_PATH
20 // Note that NODE_PATH is deprecated and will be removed
21 // in the next major release of create-react-app.
23 const nodePath = process.env.NODE_PATH || '';
24 return nodePath.split(path.delimiter).filter(Boolean);
27 const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
29 // We don't need to do anything if `baseUrl` is set to `node_modules`. This is
30 // the default behavior.
31 if (path.relative(paths.appNodeModules, baseUrlResolved) === '') {
35 // Allow the user set the `baseUrl` to `appSrc`.
36 if (path.relative(paths.appSrc, baseUrlResolved) === '') {
37 return [paths.appSrc];
40 // Otherwise, throw an error.
43 "Your project's `baseUrl` can only be set to `src` or `node_modules`." +
44 ' Create React App does not support other values at this time.'
49function getModules() {
50 // Check if TypeScript is setup
51 const hasTsConfig = fs.existsSync(paths.appTsConfig);
52 const hasJsConfig = fs.existsSync(paths.appJsConfig);
54 if (hasTsConfig && hasJsConfig) {
56 'You have both a tsconfig.json and a jsconfig.json. If you are using TypeScript please remove your jsconfig.json file.'
62 // If there's a tsconfig.json we assume it's a
63 // TypeScript project and set up the config
64 // based on tsconfig.json
66 config = require(paths.appTsConfig);
67 // Otherwise we'll check if there is jsconfig.json
68 // for non TS projects.
69 } else if (hasJsConfig) {
70 config = require(paths.appJsConfig);
73 config = config || {};
74 const options = config.compilerOptions || {};
76 const additionalModulePaths = getAdditionalModulePaths(options);
79 additionalModulePaths: additionalModulePaths,
84module.exports = getModules();
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list