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?
#How to get `require.main.filename` like Node as Deno
10 messages · Page 1 of 1 (latest)
import.meta.main is a boolean
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.
Say more about what you're trying to accomplish?
@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.
Thank you, that makes sense. I will think about this some (maybe someone else can help as well)
Thankyou @signal geode san.
This will be an extension mainly for Fresh.
So the goal is to get the exact path of main.ts.
Does this fulfill your requirements https://deno.land/[email protected]?s=Deno.mainModule
Deno.mainModule
The URL of the entrypoint module entered from the command-line. It requires read permission to the CWD.
oh this is nice! I like const isRepl = Deno.mainModule.split('/').slice(-1)[0] === '$deno$repl.ts' to detect the repl
(I wonder what Deno.mainModule returns in the Jupyter kernel… 🤔 )