For example, say I have a component "Comp" that specifies it needs the "CompJS" asset, and is used on pages "Page1" and "Page2". If Page1 doesn't have much more to it and only needs CompJS then that's what should be included by Tapestry, since Comp @Import's CompJS. All well and good.
Now, if Page2 has a lot of other components with their own JS files which are then combined into a T5 stack and requested by the page's @Import then I would not expect CompJS to be referenced on the page since it's already included in the stack file. It seems to be in T5.2.0 with my testing.
Unless I'm mistaken about how this is working, then I fail to see how this stack mechanism provides much benefit over simply putting all my projects' JS into a single file and referencing that in each page. The only advantage is to split it up into easily editable chunks, I still have to manage the aggregation. I think it's going to be very easy to get duplicate JS in the rendered html page with this system.
If a stack is imported which contains CompJS, and another component imports CompJS individually, just output the reference to the stack, and not CompJS.
There are two ways to implement the remaining behaviour:
1) If the stack is not imported, and a component imports CompJS individually, just output the reference to CompJS.
2) If the stack is not imported, and a component imports CompJS individually, output a reference to the stack containing CompJS. This is more difficult and may be tricky if the component has been defined as being part of more than one stack.