Skip to content

Commit de8d0dd

Browse files
authored
Fix package resolution when DocumentJS is run globally (#279)
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 #275
1 parent 45e8ae1 commit de8d0dd

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"md5": "^2.0.0",
4848
"minimatch": "~1.0.0",
4949
"q": "~1.0.1",
50+
"resolve": "^1.4.0",
5051
"steal": "0.16.X",
5152
"steal-stache": "^3.0.7",
5253
"steal-tools": "0.16.X",

site/default/static/build.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var assign = require("can-util/js/assign/assign");
22
var fs = require('fs');
33
var map = require('./map');
4+
var resolve = require('resolve');
45
var stealTools = require("steal-tools"),
56
fsx = require('../../../../lib/fs_extras'),
67
Q = require('q'),
@@ -38,8 +39,10 @@ module.exports = function(options, folders){
3839
// map[packageName] can either be just a string (e.g. jquery) or
3940
// an object, so we want the path for the module, not an object
4041
var resolvePath = (typeof map[packageName] === 'object') ? map[packageName][packageName] : map[packageName];
41-
if (!resolvePath) {// Fall back to Node’s resolution for npm 3+
42-
resolvePath = require.resolve(packageName);
42+
if (!resolvePath) {
43+
// Fall back to Node’s resolution for npm 3+
44+
// …or the “resolve” package’s resolution implementation
45+
resolvePath = require.resolve(packageName) || resolve.sync(packageName, {basedir: process.cwd()});
4346
}
4447

4548
// Get the path relative to the build folder

0 commit comments

Comments
 (0)