Using -D js-flatten for subpackage components, lots of other fixes