-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #3208. You now have to require 'coffee-script/extensions' in or…
…der to be able to auto-require CoffeeScript files.
- Loading branch information
Showing
5 changed files
with
138 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
CoffeeScript = require './coffee-script' | ||
child_process = require 'child_process' | ||
helpers = require './helpers' | ||
path = require 'path' | ||
|
||
# Load and run a CoffeeScript file for Node, stripping any `BOM`s. | ||
loadFile = (module, filename) -> | ||
answer = CoffeeScript._compileFile filename, false | ||
module._compile answer, filename | ||
|
||
# If the installed version of Node supports `require.extensions`, register | ||
# CoffeeScript as an extension. | ||
if require.extensions | ||
for ext in CoffeeScript.FILE_EXTENSIONS | ||
require.extensions[ext] = loadFile | ||
|
||
# Patch Node's module loader to be able to handle mult-dot extensions. | ||
# This is a horrible thing that should not be required. Perhaps, one day, | ||
# when a truly benevolent dictator comes to rule over the Republik of Node, | ||
# it won't be. | ||
Module = require 'module' | ||
|
||
findExtension = (filename) -> | ||
extensions = path.basename(filename).split '.' | ||
# Remove the initial dot from dotfiles. | ||
extensions.shift() if extensions[0] is '' | ||
# Start with the longest possible extension and work our way shortwards. | ||
while extensions.shift() | ||
curExtension = '.' + extensions.join '.' | ||
return curExtension if Module._extensions[curExtension] | ||
'.js' | ||
|
||
Module::load = (filename) -> | ||
@filename = filename | ||
@paths = Module._nodeModulePaths path.dirname filename | ||
extension = findExtension filename | ||
Module._extensions[extension](this, filename) | ||
@loaded = true | ||
|
||
# If we're on Node, patch `child_process.fork` so that Coffee scripts are able | ||
# to fork both CoffeeScript files, and JavaScript files, directly. | ||
if child_process | ||
{fork} = child_process | ||
binary = require.resolve '../../bin/coffee' | ||
child_process.fork = (path, args = [], options = {}) -> | ||
execPath = if helpers.isCoffee(path) then binary else null | ||
if not Array.isArray args | ||
args = [] | ||
options = args or {} | ||
options.execPath or= execPath | ||
fork path, args, options |
b173a37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great 👍
b173a37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍