Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use 'coffeescript' package #134

Merged
merged 3 commits into from Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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