Skip to content
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

I have a module, now what? #145

Open
justinmchase opened this issue Mar 29, 2022 · 5 comments
Open

I have a module, now what? #145

justinmchase opened this issue Mar 29, 2022 · 5 comments

Comments

@justinmchase
Copy link

justinmchase commented Mar 29, 2022

Ok suppose I've got parseModule/createGraph resolving modules correctly. How can I now execute the module?

const m = await denoGraph.parseModule("http://example.ts", "export default { foo: true }")

const { foo } = // ??
console.log(foo)
@bartlomieju
Copy link
Member

deno_graph is used for static analysis of the code, it doesn't have functionality to execute code. If you want to execute modules you need to use deno_core crate with ModuleLoader

@justinmchase
Copy link
Author

Does deno_core not have a typescript module? https://deno.land/x/deno_core

Or, how would one use deno_core.load?

I am looking for something such as:

const specifier = "http://example.foo"
const graph = await denoGraph.createGraph(specifier, {
  load: // custom graph loading, emits js...
})

const { foo } = Deno.load(graph)

@justinmchase
Copy link
Author

What I'm trying to do is to essentially import a file which is not typescript or javascript and transpile it on the fly. It seems like that ModuleLoader.load function could handle that but that I'm going to have to make a rust executable and essentially embed deno_core to do it...

I'm wondering are there plans to make this load api available in typescript? Are you open to a PR for the above? It looks like, without really digging into it, that implementing the above Deno.load to be a function which just imlements a ModuleLoader for a createGraph result wouldn't be too hard...

@bartlomieju
Copy link
Member

What I'm trying to do is to essentially import a file which is not typescript or javascript and transpile it on the fly. It seems like that ModuleLoader.load function could handle that but that I'm going to have to make a rust executable and essentially embed deno_core to do it...

I see, there were proposals for JavaScript APIs for loader in deno but they didn't go anywhere: denoland/deno#1739

I'm wondering are there plans to make this load api available in typescript?

Currently not, it's considered low priority at the moment.

Are you open to a PR for the above? It looks like, without really digging into it, that implementing the above Deno.load to be a function which just imlements a ModuleLoader for a createGraph result wouldn't be too hard...

I don't agree, this is going to be very hard to implement, but PRs are always welcome; maybe it will spark another conversation about custom loaders.

@kitsonk
Copy link
Contributor

kitsonk commented Mar 30, 2022

Don't forget, there is a built in module loading functionality that loads code in its own context and is part of the web platform called web workers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants