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

Publish standalone binaries #28

Closed
hayd opened this issue Jan 2, 2021 · 11 comments
Closed

Publish standalone binaries #28

hayd opened this issue Jan 2, 2021 · 11 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@hayd
Copy link

hayd commented Jan 2, 2021

Given denoland/deno#8539 it would be nice to have lume binaries published (by CI) on each release.

@shadowtime2000
Copy link
Contributor

1 to this

@shadowtime2000
Copy link
Contributor

This would be great for projects in other languages that want to use Lume for technical documentation. I am wondering though, will a standalone binary still be able to import the config and the ((JS|TS)X?) templates (sorry just had to make a regex).

@oscarotero
Copy link
Member

This is a fantastic idea and definitively I want that.
Unfortunally, seems like it doesn't work fine. After execute the emitted binary, I get the following error:

error: ReferenceError: __default is not defined
    at file://$deno$/bundle.js:5935:16

@oscarotero
Copy link
Member

It looks like is a bundler bug: denoland/deno#8970

@JordanShurmer
Copy link
Contributor

Looks like that bug may have been fixed now. Worth a try again?

@oscarotero
Copy link
Member

oscarotero commented Jan 31, 2021

It keeps failing:

➜  deno -V
deno 1.7.1
➜  deno compile --unstable -A cli.js
Check file:///Users/oscarotero/lumeland/lume/cli.js
Bundle file:///Users/oscarotero/lumeland/lume/cli.js
Compile file:///Users/oscarotero/lumeland/lume/cli.js
Emit lume
➜  ./lume -v
error: ReferenceError: exports is not defined
    at file://$deno$/bundle.js:7740:37

@oscarotero
Copy link
Member

Bug reported here: denoland/deno#9346

@shadowtime2000
Copy link
Contributor

Actually as I was doing more research into it, it turns out we would have to rewrite some of our code so we can support binaries. Because we can't dynamically import files relative to binaries we will have to rewrite it to read the file and then convert it to base64 and then dynamically import that, and we would have to wait for support for base64 data urls in binaries denoland/deno#9397.

Don't forget to upvote the feature request!

@oscarotero
Copy link
Member

In lume we don't have this problem (I think) but yep, looks like having to bundle the entire code to generate a self container binary generates some issues and reduce the flexibility. I'd like to have a different approach, for example, only transpile the typescript code but maintaining the ESM under a specific protocol. For example: import myModule from "bin://src/my-module.js". But perhaps it's too complicated, I don't know.

@shadowtime2000
Copy link
Contributor

@oscarotero How does Lume import the config file if it doesn't use dynamic imports? I think really that feature request may be the only way if we were to support binaries because of how you can't dynamically import files external to the binary.

@oscarotero
Copy link
Member

oscarotero commented Feb 13, 2021

@shadowtime2000 Mmmm, you're right. I thought dynamic imports couln't load modules from the bundled library (Lume in my case), but they could load modules from the user's cwd. Something like this:

async function cli() {
    const file = Deno.cwd()   './_config.js';
    const mod = await import(file);
    console.log(mod);
}
cli();

But now I can see that this is not available neither (TypeError: Self-contained binaries don't support module loading).
I hope dynamic imports are enabled soon or, at least, base64 data urls as you have suggested.

I guess that ATM, the only way to create executable binaries with Lume is using the _config.js file as the entry point. For example:

import lume from "https://deno.land/x/lume/mod.js";
import cli from "https://deno.land/x/lume/cli.js";
  
const site = lume();

cli(Deno.args, site);

But I need to edit the cli module to accept the site instance in the second argument.

@oscarotero oscarotero added the enhancement New feature or request label Mar 4, 2021
@oscarotero oscarotero added the wontfix This will not be worked on label May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants