-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for $/require string literals of relative racketscript modules #278
Comments
Anything in the So if something like this were to be added, it should be a new form I think, rather than a change to But in this case, is there a reason why the |
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. const commandFiles = readdirSync(join(__dirname, "commands")).filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(join(__dirname, "commands", `${file}`));
client.commands.set(command.name, command);
} I got this #lang racketscript/base
(require (for-syntax racket/base
racket/syntax
racket/path
syntax/parse))
(define-syntax (require+save-commands stx)
(syntax-parse stx
[(_ path:string save-to:id)
#:with name-bind (format-id this-syntax "command")
(let ([base-src (syntax-source #'path)]
[path/string (syntax-e #'path)])
(let-values ([(base _name _dir?) (split-path base-src)])
(with-syntax*
([(mod-paths ...)
(for/list ([p (in-list (directory-list (build-path base path/string)))]
#:when (path-has-extension? p #".rkt"))
(path->string (build-path path/string p)))]
[(tmp ...) (generate-temporaries #'(mod-paths ...))])
#'(begin
(require (only-in mod-paths [name-bind tmp]) ...)
(provide save-to)
(define save-to
($/array tmp ...))))))]))
(require+save-commands "commands" commands) And it works perfectly fine, I was just wondering if a more straighforward way of doing this was worth implementing. (define-syntax (require+save-commands stx)
(syntax-parse stx
[(_ path:string save-to:id)
#:with (mod-paths ...) (for/list ([p (in-list (directory-list (syntax-e #'path)))]
#:when (path-has-extension? p #".rkt"))
(path->string p))
#'(begin
(provide save-to)
(define save-to
($/array ($/require mod-paths) ...)))]))
require+save-commands "commands" commands) 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 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. |
But is the issue that the files in the directory will now be racket files so they would need to be compiled first? |
Yes, that would be the issue, since the compiler does not consider usages of |
I would support adding something like From what I understand, the result of calling So if I call |
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 |
Ok that's pretty straightforward then |
I tried to add the requested But 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 @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 |
Seems like its doing something like |
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.The text was updated successfully, but these errors were encountered: