You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
add support for $/require string literals of relative racketscript modules #278
Right now the intents seems to just use $/require for javascript modules wether installed or relative, but support could be added to catch literals ending in .rkt, replace their extension to .rkt.js and add them to the dependency tree.
You are right that since it's part of the ffi it shouldn't know about Racket, but I think there should be then some form/procedure to tell the compiler to load certain modules.
My use case it has to do with this, evobot handling of command loading, it loads all the commands in a file, so one does not have to reference each one of the names.
Now, I realize now that I know a bit more of racketscript and nodejs with ES modules, that this might just not work at all (because the require function is not used in ES modules and if I recall correctly $/require is for the syntax require not the function).
I still think an easy way to do the same should be provided, but I realize that it may be outside the scope of the project.
I would support adding something like $/require/rkt, but could you fill in some more use case details? I still have a disconnect between the js use case and what the analogous racket would look like.
From what I understand, the result of calling (require "command.js") in js is an exports object that gets explicitly constructed in command.js?
So if I call ($/require/rkt "commands.rkt"), what does commands.rkt look like? Is there an explicit exports object? Or is exports generated as part of the call/compilation (and gets implicitly populated with all the provides)? Or something else?
I would implement it as just a compilation hook that add the dependency of that file into the process, and it just translates in javascript to require("<name-of-file>.js").
Activity
stchang commentedon Dec 8, 2021
Anything in the
interoplibrary (with a$prefix) is equivalent to directly writing plain js. It shouldnt know anything about Racket.So if something like this were to be added, it should be a new form I think, rather than a change to
$/require.But in this case, is there a reason why the
.rkt.jsfile could not be directly imported? (Is the use case to improve compile time?)kurinoku commentedon Dec 8, 2021
You are right that since it's part of the ffi it shouldn't know about Racket, but I think there should be then some form/procedure to tell the compiler to load certain modules.
My use case it has to do with this, evobot handling of command loading, it loads all the commands in a file, so one does not have to reference each one of the names.
I got this
And it works perfectly fine, I was just wondering if a more straighforward way of doing this was worth implementing.
For example
Now, I realize now that I know a bit more of racketscript and nodejs with ES modules, that this might just not work at all (because the
requirefunction is not used in ES modules and if I recall correctly$/requireis for the syntaxrequirenot the function).I still think an easy way to do the same should be provided, but I realize that it may be outside the scope of the project.
stchang commentedon Dec 8, 2021
$/requireshould correspond to nodejsrequirefunction, so it should be possible to write that js code snippet directly using the ffi.But is the issue that the files in the directory will now be racket files so they would need to be compiled first?
kurinoku commentedon Dec 8, 2021
Yes, that would be the issue, since the compiler does not consider usages of
$/requirewith racket files to be a dependency that has to compile.stchang commentedon Dec 16, 2021
I would support adding something like
$/require/rkt, but could you fill in some more use case details? I still have a disconnect between the js use case and what the analogous racket would look like.From what I understand, the result of calling
(require "command.js")in js is anexportsobject that gets explicitly constructed incommand.js?So if I call
($/require/rkt "commands.rkt"), what doescommands.rktlook like? Is there an explicitexportsobject? Or isexportsgenerated as part of the call/compilation (and gets implicitly populated with all theprovides)? Or something else?kurinoku commentedon Dec 16, 2021
I would implement it as just a compilation hook that add the dependency of that file into the process, and it just translates in javascript to
require("<name-of-file>.js").stchang commentedon Dec 16, 2021
Ok that's pretty straightforward then
start to add $/require/rkt; for pr racketscript#278
stchang commentedon Dec 17, 2021
I tried to add the requested
$/require/rkt, see #286But I think I'm running into the problem I alluded to above, which is that the required library doesn't have the expected exports?
The specific error I'm getting is
SyntaxError: The requested module './rktlib.rkt.js' does not provide an export named 'default'@kurinoku If you have a chance, could you try out that branch and see if it does what you want? If not feel free to modify
vishesh commentedon Dec 17, 2021
Seems like its doing something like
import default from mod.jswhich is probably not right?