Skip to content

Commit

Permalink
Fix package resolution when DocumentJS is run globally (#279)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chasenlehara authored Sep 7, 2017
1 parent 45e8ae1 commit de8d0dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions site/default/static/build.js
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit de8d0dd

Please sign in to comment.