From 6ee7bf6df5f06b61a8970ee9a095d2f0b6afda0c Mon Sep 17 00:00:00 2001 From: Christina Date: Mon, 6 Feb 2017 13:30:56 -0500 Subject: [PATCH] checks if babel is installed globally and displays correct cli message (#5258) * checks if babel is installed globally and displays correct cli message - fixes #5228 * recommend local installation and fix lint errors * uses babel-cli vs babel * switch back to babel * use process.cwd() to determine if globally executed * checks for /node_module/.bin/babel * compare execPath and module execution path to determine global or local installation * Move the babel/cli.js into a 'src' so the 'const's are compiled Node < 6. --- packages/babel/package.json | 6 +++--- packages/babel/{ => src}/cli.js | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) rename packages/babel/{ => src}/cli.js (58%) diff --git a/packages/babel/package.json b/packages/babel/package.json index a4440b5718..4c03e3eb51 100644 --- a/packages/babel/package.json +++ b/packages/babel/package.json @@ -7,8 +7,8 @@ "license": "MIT", "repository": "https://github.com/babel/babel/tree/master/packages/babel", "bin": { - "babel": "./cli.js", - "babel-node": "./cli.js", - "babel-external-helpers": "./cli.js" + "babel": "./lib/cli.js", + "babel-node": "./lib/cli.js", + "babel-external-helpers": "./lib/cli.js" } } diff --git a/packages/babel/cli.js b/packages/babel/src/cli.js similarity index 58% rename from packages/babel/cli.js rename to packages/babel/src/cli.js index 92c1235cd0..0a6c889d7d 100755 --- a/packages/babel/cli.js +++ b/packages/babel/src/cli.js @@ -1,10 +1,13 @@ #!/usr/bin/env node +import path from "path"; + +const globalMessage = path.dirname(process.execPath) === path.dirname(process.env._ || "") ? " -g" : ""; console.error("You have mistakenly installed the `babel` package, which is a no-op in Babel 6.\n" + "Babel's CLI commands have been moved from the `babel` package to the `babel-cli` package.\n" + "\n" + - " npm uninstall babel\n" + - " npm install babel-cli\n" + + " npm uninstall" + globalMessage + " babel\n" + + " npm install --save-dev babel-cli\n" + "\n" + "See http://babeljs.io/docs/usage/cli/ for setup instructions."); process.exit(1);