From e0ea17d2e13ef4fb054980c1c5c62edcfd10632f Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Sun, 13 Aug 2023 22:32:39 +0200 Subject: [PATCH] Remove CoffeeScript support --- README.md | 7 ------ lib/moduleEnv.js | 51 +------------------------------------------ package-lock.json | 14 ------------ package.json | 1 - test/rewire.test.js | 14 +----------- testLib/module.coffee | 3 --- 6 files changed, 2 insertions(+), 88 deletions(-) delete mode 100644 testLib/module.coffee diff --git a/README.md b/README.md index 8b88842..46db786 100644 --- a/README.md +++ b/README.md @@ -233,13 +233,6 @@ 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 you need to install the `coffeescript` package. - -
- ## License MIT diff --git a/lib/moduleEnv.js b/lib/moduleEnv.js index b1efad1..77c20d0 100644 --- a/lib/moduleEnv.js +++ b/lib/moduleEnv.js @@ -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], @@ -85,7 +83,6 @@ 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; @@ -93,12 +90,8 @@ function registerExtensions() { if (originalTsExtension) { originalExtensions.ts = originalTsExtension; } - if (originalCoffeeExtension) { - originalExtensions.coffee = originalCoffeeExtension; - } require.extensions[".js"] = jsExtension; require.extensions[".ts"] = tsExtension; - require.extensions[".coffee"] = coffeeExtension; } function restoreExtensions() { @@ -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) { @@ -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; diff --git a/package-lock.json b/package-lock.json index 7b75bd9..a013707 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,6 @@ }, "devDependencies": { "@types/node": "^17.0.35", - "coffeescript": "^2.1.1", "expect.js": "^0.3.1", "mocha": "^10.0.0", "nyc": "^15.1.0", @@ -1132,19 +1131,6 @@ "wrap-ansi": "^7.0.0" } }, - "node_modules/coffeescript": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-2.7.0.tgz", - "integrity": "sha512-hzWp6TUE2d/jCcN67LrW1eh5b/rSDKQK6oD6VMLlggYVUUFexgTH9z3dNYihzX4RMhze5FTUsUmOXViJKFQR/A==", - "dev": true, - "bin": { - "cake": "bin/cake", - "coffee": "bin/coffee" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", diff --git a/package.json b/package.json index 3e116d3..becd9da 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/rewire.test.js b/test/rewire.test.js index 77cee77..e217f0d 100644 --- a/test/rewire.test.js +++ b/test/rewire.test.js @@ -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"); diff --git a/testLib/module.coffee b/testLib/module.coffee deleted file mode 100644 index 5487878..0000000 --- a/testLib/module.coffee +++ /dev/null @@ -1,3 +0,0 @@ -fs = require "fs" - -exports.readFileSync = () -> fs.readFileSync() \ No newline at end of file