It started with the Chinese Exclusion Act of 1882, but 10 years later it then came to the US opening Ellis Island in which immigrates had spent time before being able to actually enter the US.
The Congress´s power implied through the "necessary and proper clause", also known as the "elastic clause" is to pass any legislation relating to the "express powers" granted though the Constitution. Alexander Hamilton was the main supporter of this interpretation.
They can both digest but in different ways.