From 993347bb8aadeb5157807bfc24a16b190996f6ba Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Mon, 8 May 2017 23:35:11 -0700 Subject: [PATCH] [CS2] Un-prefer global (#4543) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Don’t prefer global installation; the `coffee` or `cake` commands should try to run the locally-installed module if it exists, or the global version otherwise * Style --- bin/cake | 15 +++++++++++++-- bin/coffee | 15 +++++++++++++-- package.json | 1 - 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/bin/cake b/bin/cake index 70b9aa0d..5694676a 100755 --- a/bin/cake +++ b/bin/cake @@ -2,6 +2,17 @@ var path = require('path'); var fs = require('fs'); -var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib'); -require(lib + '/coffeescript/cake').run(); +var potentialPaths = [ + path.join(process.cwd(), 'node_modules/coffeescript/lib/coffeescript'), + path.join(process.cwd(), 'node_modules/coffeescript/lib/coffee-script'), + path.join(process.cwd(), 'node_modules/coffee-script/lib/coffee-script'), + path.join(__dirname, '../lib/coffeescript') +]; + +for (var i = 0, len = potentialPaths.length; i < len; i++) { + if (fs.existsSync(potentialPaths[i])) { + require(potentialPaths[i] + '/cake').run(); + break; + } +} diff --git a/bin/coffee b/bin/coffee index c84782ac..9d8468bc 100755 --- a/bin/coffee +++ b/bin/coffee @@ -2,6 +2,17 @@ var path = require('path'); var fs = require('fs'); -var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib'); -require(lib + '/coffeescript/command').run(); +var potentialPaths = [ + path.join(process.cwd(), 'node_modules/coffeescript/lib/coffeescript'), + path.join(process.cwd(), 'node_modules/coffeescript/lib/coffee-script'), + path.join(process.cwd(), 'node_modules/coffee-script/lib/coffee-script'), + path.join(__dirname, '../lib/coffeescript') +]; + +for (var i = 0, len = potentialPaths.length; i < len; i++) { + if (fs.existsSync(potentialPaths[i])) { + require(potentialPaths[i] + '/command').run(); + break; + } +} diff --git a/package.json b/package.json index d52205f4..79f0aa3a 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "register.js", "repl.js" ], - "preferGlobal": true, "scripts": { "test": "node ./bin/cake test", "test-harmony": "node --harmony ./bin/cake test"