node-theseus icon indicating copy to clipboard operation
node-theseus copied to clipboard

Detecting of activation mode fails under node-theseus

Open ishahak opened this issue 10 years ago • 2 comments

We use this to detect activation mode: if (require.main === module) { //started directly } else { //started by 'require' }

it works fine under 'node' but fails under node-theseus

ishahak avatar Sep 29 '14 12:09 ishahak

Hmm, yes, that would happen since node-theseus launches your script with require(scriptPath).

Two ideas come to mind:

  1. Change it to require.main = require(scriptPath). (I'm pretty sure this won't work, but it's easy. :)
  2. Maybe require() has an argument for setting require.main?
  3. Modify beginInstrumentation to detect the main script and prepend require.main = module.

Thanks for the report! I hadn't even known about require.main. :) Sorry that node-theseus didn't just work.

alltom avatar Sep 29 '14 15:09 alltom

Hi Tom, Thank you very much. I will try. Well done for the excellent tool, and for the prompt response! Best regards, -Itay

2014-09-29 18:34 GMT+03:00 Tom Lieber [email protected]:

Hmm, yes, that would happen since node-theseus launches your script with require(scriptPath) https://github.com/adobe-research/node-theseus/blob/master/node-theseus.js#L91 .

Two ideas come to mind:

  1. Change it to require.main = require(scriptPath). (I'm pretty sure this won't work, but it's easy. :)
  2. Maybe require() has an argument for setting require.main?
  3. Modify beginInstrumentation https://github.com/adobe-research/node-theseus/blob/master/node-theseus.js#L137-L165 to detect the main script and prepend require.main = module.

Thanks for the report! I hadn't even known about require.main. :) Sorry that this didn't just work.

— Reply to this email directly or view it on GitHub https://github.com/adobe-research/node-theseus/issues/24#issuecomment-57179428 .

ishahak avatar Sep 30 '14 06:09 ishahak