paths.js 2.97 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'),
46
  testsSetup: resolveApp('src/setupTests.js'),
47
  appNodeModules: resolveApp('node_modules'),
48
49
  ownNodeModules: resolveApp('node_modules'),
  nodePaths: nodePaths
50
};
51

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

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

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