1 |
|
2 | (function() {
|
3 | var CoffeeScript, Module, binary, child_process, ext, findExtension, fork, helpers, i, len, loadFile, path, ref;
|
4 |
|
5 | CoffeeScript = require('./coffee-script');
|
6 |
|
7 | child_process = require('child_process');
|
8 |
|
9 | helpers = require('./helpers');
|
10 |
|
11 | path = require('path');
|
12 |
|
13 | loadFile = function(module, filename) {
|
14 | var answer;
|
15 | answer = CoffeeScript._compileFile(filename, false);
|
16 | return module._compile(answer, filename);
|
17 | };
|
18 |
|
19 | if (require.extensions) {
|
20 | ref = CoffeeScript.FILE_EXTENSIONS;
|
21 | for (i = 0, len = ref.length; i < len; i++) {
|
22 | ext = ref[i];
|
23 | require.extensions[ext] = loadFile;
|
24 | }
|
25 | Module = require('module');
|
26 | findExtension = function(filename) {
|
27 | var curExtension, extensions;
|
28 | extensions = path.basename(filename).split('.');
|
29 | if (extensions[0] === '') {
|
30 | extensions.shift();
|
31 | }
|
32 | while (extensions.shift()) {
|
33 | curExtension = '.' + extensions.join('.');
|
34 | if (Module._extensions[curExtension]) {
|
35 | return curExtension;
|
36 | }
|
37 | }
|
38 | return '.js';
|
39 | };
|
40 | Module.prototype.load = function(filename) {
|
41 | var extension;
|
42 | this.filename = filename;
|
43 | this.paths = Module._nodeModulePaths(path.dirname(filename));
|
44 | extension = findExtension(filename);
|
45 | Module._extensions[extension](this, filename);
|
46 | return this.loaded = true;
|
47 | };
|
48 | }
|
49 |
|
50 | if (child_process) {
|
51 | fork = child_process.fork;
|
52 | binary = require.resolve('../../bin/coffee');
|
53 | child_process.fork = function(path, args, options) {
|
54 | if (helpers.isCoffee(path)) {
|
55 | if (!Array.isArray(args)) {
|
56 | options = args || {};
|
57 | args = [];
|
58 | }
|
59 | args = [path].concat(args);
|
60 | path = binary;
|
61 | }
|
62 | return fork(path, args, options);
|
63 | };
|
64 | }
|
65 |
|
66 | }).call(this);
|