Skip to content

Commit

Permalink
Move method to proper file.
Browse files Browse the repository at this point in the history
  • Loading branch information
pahen committed Dec 19, 2014
1 parent f15fbb6 commit f17a64a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
22 changes: 22 additions & 0 deletions lib/parse/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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
Expand Down
23 changes: 1 addition & 22 deletions lib/parse/cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand Down

0 comments on commit f17a64a

Please sign in to comment.