From a2ce7c305b06a8444a33e8f78280c3fe8eca3463 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 9 Nov 2011 11:22:26 +0100 Subject: [PATCH] make text module regexp configurable since e.g. ace and dojo use custom text modules --- lib/dryice/index.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/dryice/index.js b/lib/dryice/index.js index ab5dc99..898ffa1 100644 --- a/lib/dryice/index.js +++ b/lib/dryice/index.js @@ -283,6 +283,7 @@ NullModule.prototype.toString = function() { function CommonJsProject(opts) { this.roots = opts.roots; this.ignoreRequires = opts.ignores || []; + this.textPluginPattern = opts.textPluginPattern || /^text!/; this.currentFiles = {}; this.ignoredFiles = {}; @@ -373,7 +374,11 @@ function CommonJsProject(opts) { }; CommonJsProject.prototype.clone = function() { - var clone = new CommonJsProject(this.roots); + var clone = new CommonJsProject({ + roots: this.roots, + ignores: this.ignoreRequires, + textPluginPattern: this.textPluginPattern + }); Object.keys(this.currentFiles).forEach(function(module) { clone.currentFiles[module] = this.currentFiles[module]; @@ -493,8 +498,6 @@ function CommonJsProject(opts) { return reply; } - var textPluginPattern = /^text!/; - CommonJsProject.prototype.require = function(module) { var baseObj = this.currentFiles[module]; if (baseObj) { @@ -513,14 +516,15 @@ function CommonJsProject(opts) { // Find which of the packages it is in this.roots.forEach(function(root) { var base = ensureTrailingSlash(root); - if (textPluginPattern.test(module)) { - baseObj = findModuleAt(baseObj, base, module.replace(textPluginPattern, '')); + if (this.textPluginPattern.test(module)) { + baseObj = findModuleAt(baseObj, base, module.replace(this.textPluginPattern, '')); if (baseObj) { baseObj.isText = true; } } else { baseObj = findModuleAt(baseObj, base, module + '.js'); - baseObj = findModuleAt(baseObj, base, module + '/index.js'); + if (!baseObj) + baseObj = findModuleAt(baseObj, base, module + '/index.js'); } }, this);