paths.js 2.83 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
41
// config after eject: we're in ./config/
module.exports = {
  appBuild: resolveApp('build'),
  appHtml: resolveApp('index.html'),
42
  appIndexJs: resolveApp('src/index.js'),
43
44
  appPackageJson: resolveApp('package.json'),
  appSrc: resolveApp('src'),
45
  testsSetup: resolveApp('src/setupTests.js'),
46
  appNodeModules: resolveApp('node_modules'),
47
48
  ownNodeModules: resolveApp('node_modules'),
  nodePaths: nodePaths
49
};
50

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

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

71
72
73
74
// @remove-on-publish-begin
module.exports = {
  appBuild: resolveOwn('../build'),
  appHtml: resolveOwn('../template/index.html'),
75
  appIndexJs: resolveOwn('../template/src/index.js'),
76
77
  appPackageJson: resolveOwn('../package.json'),
  appSrc: resolveOwn('../template/src'),
78
  testsSetup: resolveOwn('../template/src/setupTests.js'),
79
  appNodeModules: resolveOwn('../node_modules'),
80
81
  ownNodeModules: resolveOwn('../node_modules'),
  nodePaths: nodePaths
82
83
};
// @remove-on-publish-end