paths.js 3.22 KB
Newer Older
1
// @remove-on-eject-begin
2
3
4
5
6
7
8
9
/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */
10
// @remove-on-eject-end
11
12

var path = require('path');
13
14
15
16
17
18
19
20
var fs = require('fs');

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebookincubator/create-react-app/issues/637
var appDirectory = fs.realpathSync(process.cwd());
function resolveApp(relativePath) {
  return path.resolve(appDirectory, relativePath);
}
21

Dan Abramov's avatar
Dan Abramov committed
22
// We support resolving modules according to `NODE_PATH`.
23
24
// This lets you use absolute paths in imports inside large monorepos:
// https://github.com/facebookincubator/create-react-app/issues/253.
Dan Abramov's avatar
Dan Abramov committed
25
26

// It works similar to `NODE_PATH` in Node itself:
27
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
Dan Abramov's avatar
Dan Abramov committed
28

29
// We will export `nodePaths` as an array of absolute paths.
Dan Abramov's avatar
Dan Abramov committed
30
31
32
// It will then be used by Webpack configs.
// Jest doesn’t need this because it already handles `NODE_PATH` out of the box.

33
34
35
var nodePaths = (process.env.NODE_PATH || '')
  .split(process.platform === 'win32' ? ';' : ':')
  .filter(Boolean)
36
  .map(resolveApp);
37

38
39
40
// config after eject: we're in ./config/
module.exports = {
  appBuild: resolveApp('build'),
41
42
  appPublic: resolveApp('public'),
  appHtml: resolveApp('public/index.html'),
43
  appIndexJs: resolveApp('src/index.js'),
44
45
  appPackageJson: resolveApp('package.json'),
  appSrc: resolveApp('src'),
Ville Immonen's avatar
Ville Immonen committed
46
  yarnLockFile: resolveApp('yarn.lock'),
47
  testsSetup: resolveApp('src/setupTests.js'),
48
  appNodeModules: resolveApp('node_modules'),
49
50
  ownNodeModules: resolveApp('node_modules'),
  nodePaths: nodePaths
51
};
52

53
// @remove-on-eject-begin
54
function resolveOwn(relativePath) {
55
56
  return path.resolve(__dirname, relativePath);
}
57

58
59
60
// config before eject: we're in ./node_modules/react-scripts/config/
module.exports = {
  appBuild: resolveApp('build'),
61
62
  appPublic: resolveApp('public'),
  appHtml: resolveApp('public/index.html'),
63
  appIndexJs: resolveApp('src/index.js'),
64
65
  appPackageJson: resolveApp('package.json'),
  appSrc: resolveApp('src'),
Ville Immonen's avatar
Ville Immonen committed
66
  yarnLockFile: resolveApp('yarn.lock'),
67
  testsSetup: resolveApp('src/setupTests.js'),
68
69
  appNodeModules: resolveApp('node_modules'),
  // this is empty with npm3 but node resolution searches higher anyway:
70
71
  ownNodeModules: resolveOwn('../node_modules'),
  nodePaths: nodePaths
72
73
};
// @remove-on-eject-end
74

75
76
77
78
79
80
81
82
83
// config before publish: we're in ./packages/react-scripts/config/
if (__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
  module.exports = {
    appBuild: resolveOwn('../../../build'),
    appPublic: resolveOwn('../template/public'),
    appHtml: resolveOwn('../template/public/index.html'),
    appIndexJs: resolveOwn('../template/src/index.js'),
    appPackageJson: resolveOwn('../package.json'),
    appSrc: resolveOwn('../template/src'),
Ville Immonen's avatar
Ville Immonen committed
84
    yarnLockFile: resolveOwn('../template/yarn.lock'),
85
86
87
88
89
90
    testsSetup: resolveOwn('../template/src/setupTests.js'),
    appNodeModules: resolveOwn('../node_modules'),
    ownNodeModules: resolveOwn('../node_modules'),
    nodePaths: nodePaths
  };
}