#How to get `require.main.filename` like Node as Deno

10 messages · Page 1 of 1 (latest)

dark sundial
#

I am making a module to be published on deno.land/x.
I want the user to put a file describing the configuration for the module on the same level as the entrypoint file.
I could not figure out how to get the entrypoint filename from the module side.
In Node.js, require.main.filename seems to solve this.
How would this be appropriate to write in Deno?

signal geode
#

import.meta.main is a boolean

dark sundial
#

Thanks @signal geode san
However, A does not satisfy the requirement.
What we want to know is not whether the script we are running is main, but the path of the main file.

signal geode
#

Say more about what you're trying to accomplish?

dark sundial
#

@signal geode
I will list examples of what I would like to do. I hope this gets the message across.

  • User imports my public module from deno.land/x into app.ts
  • When executed, the module will explore the expansion directory in the same hierarchy as app.tsx.
  • If the expansion directory does not contain the desired file, the module will provide functionality with default parameters.

We want to get the path to app.ts to make this work.

signal geode
#

Thank you, that makes sense. I will think about this some (maybe someone else can help as well)

dark sundial
#

Thankyou @signal geode san.

This will be an extension mainly for Fresh.
So the goal is to get the exact path of main.ts.

fast garnet
crisp yarrow
#

(I wonder what Deno.mainModule returns in the Jupyter kernel… 🤔 )