Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symlink-friendly path resolution #277

Merged
merged 3 commits into from
Jul 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,57 @@

var path = require('path');

// True when used as a dependency, false after ejecting
var isInNodeModules = (
'node_modules' ===
path.basename(path.resolve(path.join(__dirname, '..', '..')))
// True after ejecting, false when used as a dependency
var isEjected = (
path.resolve(path.join(__dirname, '..')) ===
path.resolve(process.cwd())
);

// Are we developing create-react-app locally?
var isInCreateReactAppSource = (
process.argv.some(arg => arg.indexOf('--debug-template') > -1)
);

function resolve(relativePath) {
function resolveOwn(relativePath) {
return path.resolve(__dirname, relativePath);
}

function resolveApp(relativePath) {
return path.resolve(relativePath);
}

if (isInCreateReactAppSource) {
// create-react-app development: we're in ./config/
module.exports = {
appBuild: resolve('../build'),
appHtml: resolve('../template/index.html'),
appFavicon: resolve('../template/favicon.ico'),
appPackageJson: resolve('../package.json'),
appSrc: resolve('../template/src'),
appNodeModules: resolve('../node_modules'),
ownNodeModules: resolve('../node_modules')
appBuild: resolveOwn('../build'),
appHtml: resolveOwn('../template/index.html'),
appFavicon: resolveOwn('../template/favicon.ico'),
appPackageJson: resolveOwn('../package.json'),
appSrc: resolveOwn('../template/src'),
appNodeModules: resolveOwn('../node_modules'),
ownNodeModules: resolveOwn('../node_modules')
};
} else if (isInNodeModules) {
} else if (!isEjected) {
// before eject: we're in ./node_modules/react-scripts/config/
module.exports = {
appBuild: resolve('../../../build'),
appHtml: resolve('../../../index.html'),
appFavicon: resolve('../../../favicon.ico'),
appPackageJson: resolve('../../../package.json'),
appSrc: resolve('../../../src'),
appNodeModules: resolve('../..'),
appBuild: resolveApp('build'),
appHtml: resolveApp('index.html'),
appFavicon: resolveApp('favicon.ico'),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
appNodeModules: resolveApp('node_modules'),
// this is empty with npm3 but node resolution searches higher anyway:
ownNodeModules: resolve('../node_modules')
ownNodeModules: resolveOwn('../node_modules')
};
} else {
// after eject: we're in ./config/
module.exports = {
appBuild: resolve('../build'),
appHtml: resolve('../index.html'),
appFavicon: resolve('../favicon.ico'),
appPackageJson: resolve('../package.json'),
appSrc: resolve('../src'),
appNodeModules: resolve('../node_modules'),
ownNodeModules: resolve('../node_modules')
appBuild: resolveApp('build'),
appHtml: resolveApp('index.html'),
appFavicon: resolveApp('favicon.ico'),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
appNodeModules: resolveApp('node_modules'),
ownNodeModules: resolveApp('node_modules')
};
}