duojs / duo

A next-generation package manager for the front-end
3.42k stars 117 forks source link

duo hangs when encountering a `require` outside of --root #206

Open lancejpollard opened 10 years ago

lancejpollard commented 10 years ago

I figure this is something we'd say we shouldn't support, but wanted to document/write about it anyways because other people are bound to run into it too.

Say you have a setup like this:

./client/login
./client/blog
./client/dashboard
./lib/model/user
./lib/model/post
./lib/model/comment
./server/login
./server/blog
./server/dashboard

You have that ./lib folder to share reusable code between client and server. But, each of the sub-folders under ./client/ and ./server/ are separate projects, with their own build/build.js and components. So in the end you have folders like this:

./client/login
./client/login/build/build.js
./client/login/components
./client/dashboard/build/build.js
./client/dashboard/components

The problem happens in the following situation. Say you have a file here:

./client/login/index.js

And it looks like this:

var User = require('../../lib/user');

And then you build like this:

duo index.js --root client/login -o client/login/build/build.js

That should give you this:

./client/login/build/build.js
./client/login/components

But instead it just hangs here:

     building : index.js

Haven't had time yet to dig into why this might be, but for some reason it hangs.

It seems like we should support resolving it. But it's technically outside of the root, so not sure.

Thoughts?

matthewmueller commented 10 years ago

oh interesting, it's probably hanging here:

https://github.com/component/duo/blob/master/lib/duo.js#L679-L681

I've run into that situation before (that's why I added path != '.'), but there's probably another case I'm missing.

lancejpollard commented 10 years ago

Ok cool, yeah it hangs at that method for some reason. In Duo.prototype.recurse, here is the path before and after the resolve call in the for loop:

../user/index.js
/Users/lancejpollard/dev/org/repo/client/user/index.js

and this is the root:

/Users/lancejpollard/dev/org/repo/client/login

Yeah, so the while loop is just going infinitely, so that's it.

lancejpollard commented 10 years ago

Not sure what the logic is supposed to do, any thoughts? It seems like if we try to modify that findroot function, it will then require changing file, since the whole idea of root is changing. Could get complex maybe.

matthewmueller commented 10 years ago

so it's supposed to find the root, or error out. in this case it should error out, but the path resolves to .. or something and doesn't satisfy the path == '.' condition

matthewmueller commented 10 years ago

whatever the path ends up looping on indefinitely, we should probably handle that case

micky2be commented 10 years ago

Oh! That's the problem I'm running on now. I was wondering what was wrong in my app.

This thread is a month old, any update?

dominicbarnes commented 10 years ago

Yeah, I just came across this myself, really would like to see this supported.