From 119b80d4499202836f54467ac8a3d25d851a8a6c Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Mon, 15 Mar 2010 20:39:46 -0700 Subject: [PATCH] removing fiddling with require.paths from CoffeeScript --- Cakefile | 2 +- bin/cake | 3 +-- bin/coffee | 3 +-- lib/cake.js | 4 ++-- lib/coffee-script.js | 6 +++--- lib/command.js | 6 +++--- lib/lexer.js | 4 ++-- lib/nodes.js | 4 ++-- lib/repl.js | 2 +- lib/rewriter.js | 2 +- src/cake.coffee | 4 ++-- src/coffee-script.coffee | 6 +++--- src/command.coffee | 6 +++--- src/lexer.coffee | 4 ++-- src/nodes.coffee | 4 ++-- src/repl.coffee | 2 +- src/rewriter.coffee | 2 +- 17 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Cakefile b/Cakefile index 49b9550c..e1e71de8 100644 --- a/Cakefile +++ b/Cakefile @@ -1,5 +1,5 @@ fs: require 'fs' -CoffeeScript: require 'coffee-script' +CoffeeScript: require './lib/coffee-script' # Run a CoffeeScript through our node/coffee interpreter. run: (args) -> diff --git a/bin/cake b/bin/cake index dabdfa99..da7419e0 100755 --- a/bin/cake +++ b/bin/cake @@ -5,5 +5,4 @@ var path = require('path'); var fs = require('fs'); var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib'); -require.paths.unshift(lib); -require('cake').run(); +require('./../lib/cake').run(); diff --git a/bin/coffee b/bin/coffee index 521db04d..2d026f52 100755 --- a/bin/coffee +++ b/bin/coffee @@ -5,5 +5,4 @@ var path = require('path'); var fs = require('fs'); var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib'); -require.paths.unshift(lib); -require('command').run(); +require('./../lib/command').run(); diff --git a/lib/cake.js b/lib/cake.js index e8664d54..641673aa 100755 --- a/lib/cake.js +++ b/lib/cake.js @@ -10,8 +10,8 @@ // External dependencies. fs = require('fs'); path = require('path'); - optparse = require('optparse'); - CoffeeScript = require('coffee-script'); + optparse = require('./optparse'); + CoffeeScript = require('./coffee-script'); // Keep track of the list of defined tasks, the accepted options, and so on. tasks = {}; options = {}; diff --git a/lib/coffee-script.js b/lib/coffee-script.js index 016917b8..a6787691 100644 --- a/lib/coffee-script.js +++ b/lib/coffee-script.js @@ -8,10 +8,10 @@ // execute all scripts present in `text/coffeescript` tags. // Set up dependencies correctly for both the server and the browser. if ((typeof process !== "undefined" && process !== null)) { - process.mixin(require('nodes')); + process.mixin(require('./nodes')); path = require('path'); - Lexer = require('lexer').Lexer; - parser = require('parser').parser; + Lexer = require('./lexer').Lexer; + parser = require('./parser').parser; } else { this.exports = (this.CoffeeScript = {}); Lexer = this.Lexer; diff --git a/lib/command.js b/lib/command.js index 050ff050..dce89920 100644 --- a/lib/command.js +++ b/lib/command.js @@ -8,8 +8,8 @@ // External dependencies. fs = require('fs'); path = require('path'); - optparse = require('optparse'); - CoffeeScript = require('coffee-script'); + optparse = require('./optparse'); + CoffeeScript = require('./coffee-script'); // The help banner that is printed when `coffee` is called without arguments. BANNER = "coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee"; // The list of all the valid option flags that `coffee` knows how to handle. @@ -31,7 +31,7 @@ return version(); } if (options.interactive) { - return require('repl'); + return require('./repl'); } if (options.stdio) { return compile_stdio(); diff --git a/lib/lexer.js b/lib/lexer.js index 70dcb836..e8990d72 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -8,8 +8,8 @@ // Which is a format that can be fed directly into [Jison](http://github.com/zaach/jison). // Set up the Lexer for both Node.js and the browser, depending on where we are. if ((typeof process !== "undefined" && process !== null)) { - Rewriter = require('rewriter').Rewriter; - helpers = require('helpers').helpers; + Rewriter = require('./rewriter').Rewriter; + helpers = require('./helpers').helpers; } else { this.exports = this; Rewriter = this.Rewriter; diff --git a/lib/nodes.js b/lib/nodes.js index 324389fb..970d00a6 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -14,8 +14,8 @@ // Set up for both **Node.js** and the browser, by // including the [Scope](scope.html) class. if ((typeof process !== "undefined" && process !== null)) { - Scope = require('scope').Scope; - helpers = require('helpers').helpers; + Scope = require('./scope').Scope; + helpers = require('./helpers').helpers; } else { this.exports = this; } diff --git a/lib/repl.js b/lib/repl.js index fd751be0..0cc489c0 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -5,7 +5,7 @@ // Using it looks like this: // coffee> puts "$num bottles of beer" for num in [99..1] // Require the **coffee-script** module to get access to the compiler. - CoffeeScript = require('coffee-script'); + CoffeeScript = require('./coffee-script'); // Our prompt. prompt = 'coffee> '; // Quick alias for quitting the REPL. diff --git a/lib/rewriter.js b/lib/rewriter.js index 5b763afb..682955b4 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -9,7 +9,7 @@ // add implicit indentation and parentheses, balance incorrect nestings, and // generally clean things up. // Set up exported variables for both Node.js and the browser. - (typeof process !== "undefined" && process !== null) ? (helpers = require('helpers').helpers) : (this.exports = this); + (typeof process !== "undefined" && process !== null) ? (helpers = require('./helpers').helpers) : (this.exports = this); // Import the helpers we need. include = helpers.include; // The **Rewriter** class is used by the [Lexer](lexer.html), directly against diff --git a/src/cake.coffee b/src/cake.coffee index 07dec7d1..180acd9b 100644 --- a/src/cake.coffee +++ b/src/cake.coffee @@ -9,8 +9,8 @@ # External dependencies. fs: require 'fs' path: require 'path' -optparse: require 'optparse' -CoffeeScript: require 'coffee-script' +optparse: require './optparse' +CoffeeScript: require './coffee-script' # Keep track of the list of defined tasks, the accepted options, and so on. tasks: {} diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index 9a8639a7..a592ca09 100644 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -8,10 +8,10 @@ # Set up dependencies correctly for both the server and the browser. if process? - process.mixin require 'nodes' + process.mixin require './nodes' path: require 'path' - Lexer: require('lexer').Lexer - parser: require('parser').parser + Lexer: require('./lexer').Lexer + parser: require('./parser').parser else this.exports: this.CoffeeScript: {} Lexer: this.Lexer diff --git a/src/command.coffee b/src/command.coffee index 0e87b2b2..8eb26bfd 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -7,8 +7,8 @@ # External dependencies. fs: require 'fs' path: require 'path' -optparse: require 'optparse' -CoffeeScript: require 'coffee-script' +optparse: require './optparse' +CoffeeScript: require './coffee-script' # The help banner that is printed when `coffee` is called without arguments. BANNER: ''' @@ -47,7 +47,7 @@ exports.run: -> parse_options() return usage() if options.help return version() if options.version - return require 'repl' if options.interactive + return require './repl' if options.interactive return compile_stdio() if options.stdio return compile_script 'console', sources[0] if options.eval return usage() unless sources.length diff --git a/src/lexer.coffee b/src/lexer.coffee index 170c8adf..9e654c56 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -9,8 +9,8 @@ # Set up the Lexer for both Node.js and the browser, depending on where we are. if process? - Rewriter: require('rewriter').Rewriter - helpers: require('helpers').helpers + Rewriter: require('./rewriter').Rewriter + helpers: require('./helpers').helpers else this.exports: this Rewriter: this.Rewriter diff --git a/src/nodes.coffee b/src/nodes.coffee index 06927897..32f91efc 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -6,8 +6,8 @@ # Set up for both **Node.js** and the browser, by # including the [Scope](scope.html) class. if process? - Scope: require('scope').Scope - helpers: require('helpers').helpers + Scope: require('./scope').Scope + helpers: require('./helpers').helpers else this.exports: this diff --git a/src/repl.coffee b/src/repl.coffee index f2f789cf..c7adcbef 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -5,7 +5,7 @@ # coffee> puts "$num bottles of beer" for num in [99..1] # Require the **coffee-script** module to get access to the compiler. -CoffeeScript: require 'coffee-script' +CoffeeScript: require './coffee-script' # Our prompt. prompt: 'coffee> ' diff --git a/src/rewriter.coffee b/src/rewriter.coffee index fa69cd2a..2611ce5e 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -8,7 +8,7 @@ # Set up exported variables for both Node.js and the browser. if process? - helpers: require('helpers').helpers + helpers: require('./helpers').helpers else this.exports: this