From de8d0dd08832e9e01249c849918c93b8a8771424 Mon Sep 17 00:00:00 2001 From: Chasen Le Hara Date: Thu, 7 Sep 2017 11:59:10 -0700 Subject: [PATCH] Fix package resolution when DocumentJS is run globally (#279) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, when DocumentJS was installed globally and run, it wouldn’t be able to find packages in the project where the user was running the command. This adds a fallback to using [resolve](https://www.npmjs.com/package/resolve)’s implementation of Node’s algorithm in the user’s current working directory. Fixes https://github.com/bitovi/documentjs/issues/275 --- package.json | 1 + site/default/static/build.js | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b70bd60d5..673b4e841 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "md5": "^2.0.0", "minimatch": "~1.0.0", "q": "~1.0.1", + "resolve": "^1.4.0", "steal": "0.16.X", "steal-stache": "^3.0.7", "steal-tools": "0.16.X", diff --git a/site/default/static/build.js b/site/default/static/build.js index d1c247e2f..f7f92b20d 100644 --- a/site/default/static/build.js +++ b/site/default/static/build.js @@ -1,6 +1,7 @@ var assign = require("can-util/js/assign/assign"); var fs = require('fs'); var map = require('./map'); +var resolve = require('resolve'); var stealTools = require("steal-tools"), fsx = require('../../../../lib/fs_extras'), Q = require('q'), @@ -38,8 +39,10 @@ module.exports = function(options, folders){ // map[packageName] can either be just a string (e.g. jquery) or // an object, so we want the path for the module, not an object var resolvePath = (typeof map[packageName] === 'object') ? map[packageName][packageName] : map[packageName]; - if (!resolvePath) {// Fall back to Node’s resolution for npm 3+ - resolvePath = require.resolve(packageName); + if (!resolvePath) { + // Fall back to Node’s resolution for npm 3+ + // …or the “resolve” package’s resolution implementation + resolvePath = require.resolve(packageName) || resolve.sync(packageName, {basedir: process.cwd()}); } // Get the path relative to the build folder