Skip to content

Commit

Permalink
Reformat source code with Prettier 1.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Jun 28, 2017
1 parent 29c8733 commit a171d93
Show file tree
Hide file tree
Showing 49 changed files with 420 additions and 270 deletions.
46 changes: 33 additions & 13 deletions packages/create-react-app/createReactApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ const program = new commander.Command(packageJson.name)
);
console.log(` - a specific npm version: ${chalk.green('0.8.2')}`);
console.log(
` - a custom fork published on npm: ${chalk.green('my-react-scripts')}`
` - a custom fork published on npm: ${chalk.green(
'my-react-scripts'
)}`
);
console.log(
` - a .tgz archive: ${chalk.green('https://mysite.com/my-react-scripts-0.8.2.tgz')}`
` - a .tgz archive: ${chalk.green(
'https://mysite.com/my-react-scripts-0.8.2.tgz'
)}`
);
console.log(
` It is not needed unless you specifically want to use a fork.`
Expand All @@ -87,7 +91,9 @@ const program = new commander.Command(packageJson.name)
` If you have any problems, do not hesitate to file an issue:`
);
console.log(
` ${chalk.cyan('https://github.com/facebookincubator/create-react-app/issues/new')}`
` ${chalk.cyan(
'https://github.com/facebookincubator/create-react-app/issues/new'
)}`
);
console.log();
})
Expand Down Expand Up @@ -258,15 +264,19 @@ function run(

console.log('Installing packages. This might take a couple of minutes.');
getPackageName(packageToInstall)
.then(packageName => checkIfOnline(useYarn).then(isOnline => ({
isOnline: isOnline,
packageName: packageName,
})))
.then(packageName =>
checkIfOnline(useYarn).then(isOnline => ({
isOnline: isOnline,
packageName: packageName,
}))
)
.then(info => {
const isOnline = info.isOnline;
const packageName = info.packageName;
console.log(
`Installing ${chalk.cyan('react')}, ${chalk.cyan('react-dom')}, and ${chalk.cyan(packageName)}...`
`Installing ${chalk.cyan('react')}, ${chalk.cyan(
'react-dom'
)}, and ${chalk.cyan(packageName)}...`
);
console.log();

Expand Down Expand Up @@ -334,7 +344,9 @@ function run(
if (!remainingFiles.length) {
// Delete target folder if empty
console.log(
`Deleting ${chalk.cyan(`${appName} /`)} from ${chalk.cyan(path.resolve(root, '..'))}`
`Deleting ${chalk.cyan(`${appName} /`)} from ${chalk.cyan(
path.resolve(root, '..')
)}`
);
process.chdir(path.resolve(root, '..'));
fs.removeSync(path.join(root));
Expand Down Expand Up @@ -422,7 +434,9 @@ function getPackageName(installPackage) {
/^.+\/(.+?)(?:-\d+.+)?\.tgz$/
)[1];
console.log(
`Based on the filename, assuming it is "${chalk.cyan(assumedProjectName)}"`
`Based on the filename, assuming it is "${chalk.cyan(
assumedProjectName
)}"`
);
return Promise.resolve(assumedProjectName);
});
Expand Down Expand Up @@ -485,7 +499,9 @@ function checkAppName(appName) {
const validationResult = validateProjectName(appName);
if (!validationResult.validForNewPackages) {
console.error(
`Could not create a project called ${chalk.red(`"${appName}"`)} because of npm naming restrictions:`
`Could not create a project called ${chalk.red(
`"${appName}"`
)} because of npm naming restrictions:`
);
printValidationResults(validationResult.errors);
printValidationResults(validationResult.warnings);
Expand All @@ -497,7 +513,9 @@ function checkAppName(appName) {
if (dependencies.indexOf(appName) >= 0) {
console.error(
chalk.red(
`We cannot create a project called ${chalk.green(appName)} because a dependency with the same name exists.\n` +
`We cannot create a project called ${chalk.green(
appName
)} because a dependency with the same name exists.\n` +
`Due to the way npm works, the following names are not allowed:\n\n`
) +
chalk.cyan(dependencies.map(depName => ` ${depName}`).join('\n')) +
Expand All @@ -519,7 +537,9 @@ function makeCaretRange(dependencies, name) {

if (!semver.validRange(patchedVersion)) {
console.error(
`Unable to patch ${name} dependency version because version ${chalk.red(version)} will become invalid ${chalk.red(patchedVersion)}`
`Unable to patch ${name} dependency version because version ${chalk.red(
version
)} will become invalid ${chalk.red(patchedVersion)}`
);
patchedVersion = version;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-config-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ module.exports = {
{
object: 'System',
property: 'import',
message: 'Please use import() instead. More info: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting',
message:
'Please use import() instead. More info: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting',
},
],

Expand Down
15 changes: 6 additions & 9 deletions packages/react-dev-utils/FileSizeReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,12 @@ function measureFileSizesBeforeBuild(buildFolder) {
if (!err && fileNames) {
sizes = fileNames
.filter(fileName => /\.(js|css)$/.test(fileName))
.reduce(
(memo, fileName) => {
var contents = fs.readFileSync(fileName);
var key = removeFileNameHash(buildFolder, fileName);
memo[key] = gzipSize(contents);
return memo;
},
{}
);
.reduce((memo, fileName) => {
var contents = fs.readFileSync(fileName);
var key = removeFileNameHash(buildFolder, fileName);
memo[key] = gzipSize(contents);
return memo;
}, {});
}
resolve({
root: buildFolder,
Expand Down
21 changes: 14 additions & 7 deletions packages/react-dev-utils/ModuleScopePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ class ModuleScopePlugin {
// Maybe an indexOf === 0 would be better?
const relative = path.relative(appSrc, request.context.issuer);
// If it's not in src/ or a subdirectory, not our request!
if (
relative.startsWith('../') ||
relative.startsWith('..\\')
) {
if (relative.startsWith('../') || relative.startsWith('..\\')) {
return callback();
}
// Find path from src to the requested file
Expand All @@ -58,9 +55,19 @@ class ModuleScopePlugin {
) {
callback(
new Error(
`You attempted to import ${chalk.cyan(request.__innerRequest_request)} which falls outside of the project ${chalk.cyan('src/')} directory. ` +
`Relative imports outside of ${chalk.cyan('src/')} are not supported. ` +
`You can either move it inside ${chalk.cyan('src/')}, or add a symlink to it from project's ${chalk.cyan('node_modules/')}.`
`You attempted to import ${chalk.cyan(
request.__innerRequest_request
)} which falls outside of the project ${chalk.cyan(
'src/'
)} directory. ` +
`Relative imports outside of ${chalk.cyan(
'src/'
)} are not supported. ` +
`You can either move it inside ${chalk.cyan(
'src/'
)}, or add a symlink to it from project's ${chalk.cyan(
'node_modules/'
)}.`
),
request
);
Expand Down
99 changes: 52 additions & 47 deletions packages/react-dev-utils/WebpackDevServerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,20 @@ if (isSmokeTest) {
}

function prepareUrls(protocol, host, port) {
const formatUrl = hostname => url.format({
protocol,
hostname,
port,
pathname: '/',
});
const prettyPrintUrl = hostname => url.format({
protocol,
hostname,
port: chalk.bold(port),
pathname: '/',
});
const formatUrl = hostname =>
url.format({
protocol,
hostname,
port,
pathname: '/',
});
const prettyPrintUrl = hostname =>
url.format({
protocol,
hostname,
port: chalk.bold(port),
pathname: '/',
});

const isUnspecifiedHost = host === '0.0.0.0' || host === '::';
let prettyHost, lanUrlForConfig, lanUrlForTerminal;
Expand Down Expand Up @@ -317,9 +319,11 @@ function prepareProxy(proxy, appPublicFolder) {
// However API calls like `fetch()` won’t generally accept text/html.
// If this heuristic doesn’t work well for you, use a custom `proxy` object.
context: function(pathname, req) {
return mayProxy(pathname) &&
return (
mayProxy(pathname) &&
req.headers.accept &&
req.headers.accept.indexOf('text/html') === -1;
req.headers.accept.indexOf('text/html') === -1
);
},
onProxyReq: proxyReq => {
// Browers may send Origin headers even with same-origin
Expand Down Expand Up @@ -375,39 +379,40 @@ function prepareProxy(proxy, appPublicFolder) {

function choosePort(host, defaultPort) {
return detect(defaultPort, host).then(
port => new Promise(resolve => {
if (port === defaultPort) {
return resolve(port);
}
const message = process.platform !== 'win32' &&
defaultPort < 1024 &&
!isRoot()
? `Admin permissions are required to run a server on a port below 1024.`
: `Something is already running on port ${defaultPort}.`;
if (isInteractive) {
clearConsole();
const existingProcess = getProcessForPort(defaultPort);
const question = {
type: 'confirm',
name: 'shouldChangePort',
message: chalk.yellow(
message +
`${existingProcess ? ` Probably:\n ${existingProcess}` : ''}`
) + '\n\nWould you like to run the app on another port instead?',
default: true,
};
inquirer.prompt(question).then(answer => {
if (answer.shouldChangePort) {
resolve(port);
} else {
resolve(null);
}
});
} else {
console.log(chalk.red(message));
resolve(null);
}
}),
port =>
new Promise(resolve => {
if (port === defaultPort) {
return resolve(port);
}
const message =
process.platform !== 'win32' && defaultPort < 1024 && !isRoot()
? `Admin permissions are required to run a server on a port below 1024.`
: `Something is already running on port ${defaultPort}.`;
if (isInteractive) {
clearConsole();
const existingProcess = getProcessForPort(defaultPort);
const question = {
type: 'confirm',
name: 'shouldChangePort',
message:
chalk.yellow(
message +
`${existingProcess ? ` Probably:\n ${existingProcess}` : ''}`
) + '\n\nWould you like to run the app on another port instead?',
default: true,
};
inquirer.prompt(question).then(answer => {
if (answer.shouldChangePort) {
resolve(port);
} else {
resolve(null);
}
});
} else {
console.log(chalk.red(message));
resolve(null);
}
}),
err => {
throw new Error(
chalk.red(`Could not find an open port at ${chalk.bold(host)}.`) +
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dev-utils/ansiHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function ansiHTML(txt) {
var open = false;
for (var index = 0; index < arr.length; ++index) {
var c = arr[index];
var content = c.content, fg = c.fg;
var content = c.content,
fg = c.fg;

var contentParts = content.split('\n');
for (var _index = 0; _index < contentParts.length; ++_index) {
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dev-utils/eslintFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ function formatter(results) {
// it here because we always show at most one error, and
// we can only be sure it's an ESLint error before exiting
// this function.
output += 'Search for the ' +
output +=
'Search for the ' +
chalk.underline(chalk.red('keywords')) +
' to learn more about each error.';
}
Expand Down
9 changes: 6 additions & 3 deletions packages/react-dev-utils/launchEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ function isTerminalEditor(editor) {
// of the app every time
const COMMON_EDITORS_OSX = {
'/Applications/Atom.app/Contents/MacOS/Atom': 'atom',
'/Applications/Atom Beta.app/Contents/MacOS/Atom Beta': '/Applications/Atom Beta.app/Contents/MacOS/Atom Beta',
'/Applications/Atom Beta.app/Contents/MacOS/Atom Beta':
'/Applications/Atom Beta.app/Contents/MacOS/Atom Beta',
'/Applications/Brackets.app/Contents/MacOS/Brackets': 'brackets',
'/Applications/Sublime Text.app/Contents/MacOS/Sublime Text': '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl',
'/Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2': '/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl',
'/Applications/Sublime Text.app/Contents/MacOS/Sublime Text':
'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl',
'/Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2':
'/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl',
'/Applications/Visual Studio Code.app/Contents/MacOS/Electron': 'code',
};

Expand Down
3 changes: 2 additions & 1 deletion packages/react-dev-utils/openBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ function startBrowserProcess(browser, url) {
// requested a different browser, we can try opening
// Chrome with AppleScript. This lets us reuse an
// existing tab when possible instead of creating a new one.
const shouldTryOpenChromeWithAppleScript = process.platform === 'darwin' &&
const shouldTryOpenChromeWithAppleScript =
process.platform === 'darwin' &&
(typeof browser !== 'string' || browser === OSX_CHROME);

if (shouldTryOpenChromeWithAppleScript) {
Expand Down
Loading

0 comments on commit a171d93

Please sign in to comment.