Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove addPath/addFile/dontAddClosureForModule/ignoreModule functiona…

…lity. If custom module search paths are required then use the NODE_PATH environment variable instead (require does take NODE_PATH into account).
  • Loading branch information...
commit 997e00ca624ac2d6451bb3ccee86cb11777920e8 1 parent 176aec8
@marcuswestin authored
Showing with 9 additions and 105 deletions.
  1. +6 −53 compiler.js
  2. +1 −34 lib/resolve.js
  3. +1 −4 lib/util.js
  4. +1 −14 server.js
View
59 compiler.js
@@ -7,33 +7,7 @@ var resolve = require('./lib/resolve')
module.exports = {
compile: compileFile,
compileHTML: compileHTMLFile,
- compileCode: compileCode,
- dontAddClosureForModule: dontAddClosureForModule,
- dontIncludeModule: dontIncludeModule,
- addPath: addPath,
- addFile: addFile
-}
-
-var _ignoreClosuresFor = []
-function dontAddClosureForModule(searchFor) {
- _ignoreClosuresFor.push(searchFor)
- return module.exports
-}
-
-var _ignoreModules = []
-function dontIncludeModule(module) {
- _ignoreModules.push(module)
- return module.exports
-}
-
-function addPath() {
- util.addPath.apply(util, arguments)
- return module.exports
-}
-
-function addFile() {
- util.addFile.apply(util, arguments)
- return module.exports
+ compileCode: compileCode
}
/* api
@@ -105,8 +79,6 @@ var _minifyRequireStatements = function(code, modules) {
return code
}
-var _nodePaths = process.env.NODE_PATH.split(':')
-var _pathnameGroupingRegex = /require\s*\(['"]([\w\/\.-]*)['"]\)/
var _replaceRequireStatements = function(modulePath, code, modules, pathBase) {
var requireStatements = util.getRequireStatements(code)
@@ -137,40 +109,21 @@ var _replaceRequireStatements = function(modulePath, code, modules, pathBase) {
}
var _concatModules = function(modules) {
- var code = function(modulePath) {
- for (var i=0; i<_ignoreModules.length; i++) {
- if (modulePath.match(_ignoreModules[i])) {
- return ''
- }
- }
-
- var ignoreClosure = false
- for (var i=0; i<_ignoreClosuresFor.length; i++) {
- if (modulePath.match(_ignoreClosuresFor[i])) {
- ignoreClosure = true
- break
- }
- }
-
+ var getClosuredModule = function(modulePath) {
return [
- ignoreClosure ? '' : ';(function() {',
+ ';(function() {',
' // ' + modulePath,
' var module = __require__["'+modulePath+'"] = {exports:{}}, exports = module.exports;',
modules[modulePath],
- ignoreClosure ? '' : '})()'
+ '})()'
].join('\n')
}
var moduleDefinitions = []
for (var i=1, modulePath; modulePath = modules[i]; i++) {
- moduleDefinitions.push(code(modulePath))
+ moduleDefinitions.push(getClosuredModule(modulePath))
}
- moduleDefinitions.push(code(modules[0])) // __main__
+ moduleDefinitions.push(getClosuredModule(modules[0])) // __main__
return moduleDefinitions.join('\n\n')
}
-
-var _repeat = function(str, times) {
- if (times < 0) { return '' }
- return new Array(times + 1).join(str)
-}
View
35 lib/resolve.js
@@ -4,30 +4,7 @@ var existsSync = fs.existsSync || path.existsSync
module.exports = {
path: resolvePath,
- requireStatement: resolveRequireStatement,
- addPath: addPath,
- addFile: addFile,
- hasAddedPath: hasAddedPath
-}
-
-var _paths = []
-function addPath(name, namedPath) {
- _paths.push({ name:name, path:path.resolve(namedPath) })
-}
-
-var _files = []
-function addFile(name, namedPath) {
- _files.push({ name:name, path:path.resolve(namedPath) })
-}
-
-function hasAddedPath(name) {
- for (var i=0, addedPath; addedPath=_paths[i]; i++) {
- if (addedPath.name == name) { return true }
- }
- for (var i=0, addedPath; addedPath=_files[i]; i++) {
- if (addedPath.name == name) { return true }
- }
- return false
+ requireStatement: resolveRequireStatement
}
function resolvePath(searchPath, pathBase) {
@@ -40,16 +17,6 @@ function resolvePath(searchPath, pathBase) {
var componentName = searchParts[searchParts.length - 1]
var name = searchParts.shift()
var rest = searchParts.join('/')
- for (var i=0, addedPath; addedPath=_paths[i]; i++) {
- if (addedPath.name != name) { continue }
- var modulePath = _findModuleMain(path.resolve(addedPath.path, rest), componentName)
- if (modulePath) { return modulePath }
- }
-
- for (var i=0, addedFile; addedFile = _files[i]; i++) {
- if (addedFile.name != searchPath) { continue }
- return addedFile.path
- }
// npm-style path, e.g. require("npm").
// Climb parent directories in search for "node_modules"
View
5 lib/util.js
@@ -8,10 +8,7 @@ module.exports = {
getRequireStatements: require('./getRequireStatements'),
getCode: require('./getCode'),
resolvePath: resolve.path,
- resolveRequireStatement: resolve.requireStatement,
- addPath: resolve.addPath,
- addFile: resolve.addFile,
- hasAddedPath: resolve.hasAddedPath
+ resolveRequireStatement: resolve.requireStatement
}
function extend(target, extendWith) {
View
15 server.js
@@ -8,22 +8,10 @@ module.exports = {
mount: mount,
connect: connect,
isRequireRequest: isRequireRequest,
- addPath: addPath,
- addFile: addFile,
setOpts: setOpts,
handleRequest: handleRequest
}
-function addPath() {
- util.addPath.apply(util, arguments)
- return module.exports
-}
-
-function addFile() {
- util.addFile.apply(util, arguments)
- return module.exports
-}
-
function listen(port, _opts) {
if (!_opts) { _opts = { port:port }}
else if(port) { _opts.port= port }
@@ -85,8 +73,7 @@ function handleRequest(req, res) {
}
function _handleMainModuleRequest(reqPath, req, res) {
- var prefix = util.hasAddedPath(reqPath.split('/')[0]) ? '' : './'
- var modulePath = util.resolvePath(prefix + reqPath, opts.path)
+ var modulePath = util.resolvePath('./' + reqPath, opts.path)
if (!modulePath) { return _sendError(res, 'Could not find module "'+reqPath+'" from "'+opts.path+'"') }
Please sign in to comment.
Something went wrong with that request. Please try again.