This practice started just after 9/11/01. At first it was unorganized and took a long time, especially when people didn't think it applied to them and they didn't show up.
The cruise lines seem to have perfected this process in the last few years.
This past March, we stopped at Princess Cays in the Bahamas first, and then to St. Thomas and there was NO immigration process in St. Thomas. This was on the Emerald Princess. Not sure if this rule has changed or why it did not happen this last cruise.