Is it possible to check if JavaScript file is being run directly or if it was required as part of an es6 module import.
for example a main script is included.
The solution I see there is just to define the variable in the script you're importing. I.e. you define mainTest in main.js, and then use your existing if block.
mainTest
main.js