Skip to content

Commit

Permalink
update, lint, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
doowb committed Jun 26, 2018
1 parent 021cdda commit 4a46cae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
23 changes: 11 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

'use strict';

var path = require('path');
var clone = require('clone-deep');
var relative = require('relative');
var red = require('ansi-red');
var bold = require('ansi-bold');
const path = require('path');
const clone = require('clone-deep');
const relative = require('relative');
const red = require('ansi-red');
const bold = require('ansi-bold');

/**
* Asynchronously get the resolved path to "main" file for
Expand All @@ -30,10 +30,9 @@ var bold = require('ansi-bold');

function resolve(name, next) {
try {
return next(null, resolveSync(name));
} catch(err) {
next(null, resolveSync(name));
} catch (err) {
next(err);
return;
}
}

Expand All @@ -52,10 +51,10 @@ function resolve(name, next) {
*/

function resolveSync(name) {
var base = path.resolve(process.cwd(), 'node_modules', name);
var pkg = tryResolve(path.join(base, 'package.json'));
const base = path.resolve(process.cwd(), 'node_modules', name);
const pkg = tryResolve(path.join(base, 'package.json'));

var res = clone(pkg);
const res = clone(pkg);
res.main = relative(path.join(base, pkg && pkg.main));
return res;
}
Expand All @@ -73,7 +72,7 @@ function tryResolve(fp) {
}
try {
return require(path.resolve(fp));
} catch(err) {
} catch (err) {
console.error(red('helper-resolve cannot find'), bold(fp), err);
}
return {};
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],
"main": "index.js",
"engines": {
"node": ">=0.10.0"
"node": ">=4.0"
},
"scripts": {
"test": "mocha"
Expand All @@ -28,8 +28,7 @@
"devDependencies": {
"handlebars": "^4.0.11",
"jquery": "^3.3.1",
"mocha": "*",
"should": "*"
"mocha": "^5.2.0"
},
"keywords": [
"helper",
Expand Down
17 changes: 8 additions & 9 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
'use strict';

/* deps:mocha jquery */
require('should');
var handlebars = require('handlebars');
var resolve = require('./');
var template;
const assert = require('assert');
const handlebars = require('handlebars');
const resolve = require('./');

describe('resolve helper', function () {
it('should work as a handlebars helper:', function () {
var str = '{{resolve "jquery"}}';
handlebars.registerHelper('resolve', function (fp, key) {
describe('resolve helper', function() {
it('should work as a handlebars helper:', function() {
const str = '{{resolve "jquery"}}';
handlebars.registerHelper('resolve', function(fp, key) {
return resolve.sync(fp)[typeof key === 'string' ? key : 'main'];
});
handlebars.compile(str)().should.equal('node_modules/jquery/dist/jquery.js');
assert.equal(handlebars.compile(str)(), 'node_modules/jquery/dist/jquery.js');
});
});

0 comments on commit 4a46cae

Please sign in to comment.