Skip to content

Commit

Permalink
Remove CoffeeScript support
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnns committed Aug 13, 2023
1 parent a183ba7 commit e0ea17d
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 88 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,6 @@ See [rewire-webpack](https://github.com/jhnns/rewire-webpack)

<br />

CoffeeScript
------------

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 />

## License

MIT
51 changes: 1 addition & 50 deletions lib/moduleEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// TODO: Use https://www.npmjs.com/package/pirates here?

var Module = require("module"),
fs = require("fs"),
eslint = require("eslint"),
coffee;
eslint = require("eslint");

var moduleWrapper0 = Module.wrapper[0],
moduleWrapper1 = Module.wrapper[1],
Expand Down Expand Up @@ -85,20 +83,15 @@ function requireProxy(path) {
function registerExtensions() {
var originalJsExtension = require.extensions[".js"];
var originalTsExtension = require.extensions[".ts"];
var originalCoffeeExtension = require.extensions[".coffee"];

if (originalJsExtension) {
originalExtensions.js = originalJsExtension;
}
if (originalTsExtension) {
originalExtensions.ts = originalTsExtension;
}
if (originalCoffeeExtension) {
originalExtensions.coffee = originalCoffeeExtension;
}
require.extensions[".js"] = jsExtension;
require.extensions[".ts"] = tsExtension;
require.extensions[".coffee"] = coffeeExtension;
}

function restoreExtensions() {
Expand All @@ -108,9 +101,6 @@ function restoreExtensions() {
if ("ts" in originalExtensions) {
require.extensions[".ts"] = originalExtensions.ts;
}
if ("coffee" in originalExtensions) {
require.extensions[".coffee"] = originalExtensions.coffee;
}
}

function isNoConstAssignMessage(message) {
Expand Down Expand Up @@ -170,44 +160,5 @@ function tsExtension(module, filename) {
originalExtensions.ts(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();
content = coffee.compile(content, {
filename: filename,
bare: true
});
module._compile(content, filename);
}

/**
* @see https://github.com/joyent/node/blob/master/lib/module.js
*/
function stripBOM(content) {
// Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
// because the buffer-to-string conversion in `fs.readFileSync()`
// translates it to FEFF, the UTF-16 BOM.
if (content.charCodeAt(0) === 0xFEFF) {
content = content.slice(1);
}
return content;
}

try {
coffee = require("coffeescript");
} catch (err) {
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;
exports.inject = inject;
14 changes: 0 additions & 14 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
},
"devDependencies": {
"@types/node": "^17.0.35",
"coffeescript": "^2.1.1",
"expect.js": "^0.3.1",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
Expand Down
14 changes: 1 addition & 13 deletions test/rewire.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,7 @@ describe("rewire", function () {
}
});
require("../testLib/sharedTestCases.js")();
it("should also work with CoffeeScript", function () {
var coffeeModule;

rewire = require("../");
coffeeModule = rewire("../testLib/module.coffee");
coffeeModule.__set__("fs", {
readFileSync: function () {
return "It works!";
}
});
expect(coffeeModule.readFileSync()).to.be("It works!");
});
it('should work with typescript', function () {
it("should work with TypeScript", function () {
var tsModule;
rewire = require("../");
tsModule = rewire("../testLib/module.ts");
Expand Down
3 changes: 0 additions & 3 deletions testLib/module.coffee

This file was deleted.

0 comments on commit e0ea17d

Please sign in to comment.