build import set of used / duplicate components prior to printing direct...

...ives so that we can filter duplicates

This fixes a bug where duplicate imports are written: 1 based on the
component link (or extend tag) and the 2nd copied as an existing
directive.  We filter out the existing directive, because that is
invalid (it is an import of the original libray rather than of the
processed component, which is what we want).

Note that this submit does not change the order of printing at all.  It simply builds the import set prior to printing the existing directives in order to filter, but the printing of the imports still occurs after the existing directives are printed (same as before).