diff --git a/README.md b/README.md index c8a589d..0c2a591 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ rewire [![](https://img.shields.io/npm/v/rewire.svg)](https://www.npmjs.com/package/rewire) [![](https://img.shields.io/npm/dm/rewire.svg)](https://www.npmjs.com/package/rewire) [![Dependency Status](https://david-dm.org/jhnns/rewire.svg)](https://david-dm.org/jhnns/rewire) -[![Build Status](https://travis-ci.org/jhnns/rewire.svg?branch=master)](https://travis-ci.org/rewire/jhnns) +[![Build Status](https://travis-ci.org/jhnns/rewire.svg?branch=master)](https://travis-ci.org/jhnns/rewire) [![Coverage Status](https://img.shields.io/coveralls/jhnns/rewire.svg)](https://coveralls.io/r/jhnns/rewire?branch=master) rewire adds a special setter and getter to modules so you can modify their behaviour for better unit testing. You may @@ -236,7 +236,7 @@ See [rewire-webpack](https://github.com/jhnns/rewire-webpack) CoffeeScript ------------ -Good news to all caffeine-addicts: rewire works also with [Coffee-Script](http://coffeescript.org/). Note that in this case CoffeeScript needs to be listed in your devDependencies. +Good news to all caffeine-addicts: rewire works also with [Coffee-Script](http://coffeescript.org/). Note that in this case you need to install the `coffeescript` package.
diff --git a/lib/moduleEnv.js b/lib/moduleEnv.js index 688401e..599e332 100644 --- a/lib/moduleEnv.js +++ b/lib/moduleEnv.js @@ -133,6 +133,10 @@ function jsExtension(module, filename) { } function coffeeExtension(module, filename) { + if (!coffee) { + throw new Error("Cannot rewire module written in CoffeeScript: Please install 'coffeescript' package first."); + } + var content = stripBOM(fs.readFileSync(filename, "utf8")); restoreExtensions(); @@ -157,9 +161,14 @@ function stripBOM(content) { } try { - coffee = require("coffee-script"); + coffee = require("coffeescript"); } catch (err) { - // We are not able to provide coffee-script support, but that's ok as long as the user doesn't want it. + try { + // Trying to load deprecated package + coffee = require("coffee-script"); + } catch (err) { + // We are not able to provide CoffeeScript support, but that's ok as long as the user doesn't want it. + } } exports.load = load; diff --git a/package-lock.json b/package-lock.json index e5fdf17..f33b507 100644 --- a/package-lock.json +++ b/package-lock.json @@ -176,10 +176,10 @@ "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=" }, - "coffee-script": { - "version": "1.12.7", - "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.12.7.tgz", - "integrity": "sha512-fLeEhqwymYat/MpTPUjSKHVYYl0ec2mOyALEMLmzr5i1isuG+6jfI2j2d5oBO3VIzgUXgBVIcOT9uH1TFxBckw==", + "coffeescript": { + "version": "2.2.4", + "resolved": "http://registry.npmjs.org/coffeescript/-/coffeescript-2.2.4.tgz", + "integrity": "sha1-QnwDjhehJeUqef2zEGdhdTuFhdI=", "dev": true }, "color-convert": { diff --git a/package.json b/package.json index 436dbf0..c06ad61 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "url": "git://github.com/jhnns/rewire.git" }, "devDependencies": { - "coffee-script": "^1.8.0", + "coffeescript": "^2.1.1", "expect.js": "^0.3.1", "mocha": "^4.0.1" },