From f17a64ae0f1c1e506a99fe739b2bc4a6ef2013cc Mon Sep 17 00:00:00 2001 From: Patrik Henningsson Date: Fri, 19 Dec 2014 22:18:40 +0100 Subject: [PATCH] Move method to proper file. --- lib/parse/base.js | 22 ++++++++++++++++++++++ lib/parse/cjs.js | 23 +---------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/parse/base.js b/lib/parse/base.js index 15d475cb..ff4f6fc6 100644 --- a/lib/parse/base.js +++ b/lib/parse/base.js @@ -6,6 +6,7 @@ var fs = require('fs'), path = require('path'), util = require('util'), + resolve = require('resolve'), EventEmitter = require('events').EventEmitter, commondir = require('commondir'), finder = require('walkdir'), @@ -42,6 +43,27 @@ var Base = module.exports = function(src, opts, parent) { util.inherits(Base, EventEmitter); +/** + * Resolve the given `id` to a filename. + * @param {String} dir + * @param {String} id + * @return {String} + */ +Base.prototype.resolve = function (dir, id) { + try { + return resolve.sync(id, { + basedir: dir, + paths: this.opts.paths + }); + } catch (e) { + if (this.opts.breakOnError) { + console.log(String('\nError while resolving module from: ' + id).red); + throw e; + } + return id; + } +}; + /** * Get the most common dir from the `src`. * @param {Array} src diff --git a/lib/parse/cjs.js b/lib/parse/cjs.js index bfda3384..19b6e358 100644 --- a/lib/parse/cjs.js +++ b/lib/parse/cjs.js @@ -6,7 +6,6 @@ var fs = require('fs'), path = require('path'), util = require('util'), - resolve = require('resolve'), detective = require('detective'), colors = require('colors'), Base = require('./base'); @@ -25,33 +24,13 @@ var CJS = module.exports = function () { */ util.inherits(CJS, Base); -/** - * Resolve the given `id` to a filename. - * @param {String} dir - * @param {String} id - * @return {String} - */ -Base.prototype.resolve = function (dir, id) { - try { - return resolve.sync(id, { - basedir: dir, - paths: this.opts.paths - }); - } catch (e) { - if (this.opts.breakOnError) { - console.log(String('\nError while resolving module from: ' + id).red); - throw e; - } - return id; - } -}; - /** * Normalize a module file path and return a proper identificator. * @param {String} filename * @return {String} */ CJS.prototype.normalize = function (filename) { + console.log(filename.charAt(0), filename); if (filename.charAt(0) !== '/') { // a core module (not mapped to a file) return this.replaceBackslashInPath(filename);