Skip to content

Commit

Permalink
Merge pull request #134 from jhnns/pr/origin/127
Browse files Browse the repository at this point in the history
Use 'coffeescript' package
  • Loading branch information
jhnns committed Apr 9, 2018
2 parents e9437cc + d124260 commit 999dd1d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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
Expand Down Expand Up @@ -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.

<br />

Expand Down
13 changes: 11 additions & 2 deletions lib/moduleEnv.js
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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"
},
Expand Down

0 comments on commit 999dd1d

Please sign in to comment.