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

Add 'bundle' subcommand. #2467

Merged
merged 8 commits into from
Jun 8, 2019
Merged

Add 'bundle' subcommand. #2467

merged 8 commits into from
Jun 8, 2019

Conversation

kitsonk
Copy link
Contributor

@kitsonk kitsonk commented Jun 7, 2019

Resolves #2357

This PR adds the subcommand "bundle" to allow the output of a single file JavaScript file which can then be run by Deno without further dependencies.

This works by using the --outFile feature of TypeScript along with the AMD module format. AMD modules allow single file concatenation, which is not possible via ES Modules (or CommonJS). This means the bundle is fully valid JavaScript and just needs to be loaded via an AMD loader. There is a minimalistic loader in deno_std (see: denoland/std#480).

So to utilise this in action, you would do something like this:

$ deno bundle https://deno.land/x/oak/examples/server.ts oak_server.js

Which will output the source module to ./oak_server.js, which can then be run like:

$ deno -A https://deno.land/std/bundle/run.ts ./oak_server.js

I still need to:

  • write tests

cli/main.rs Outdated Show resolved Hide resolved
cli/state.rs Outdated Show resolved Hide resolved
@ry ry mentioned this pull request Jun 7, 2019
43 tasks
@ry
Copy link
Member

ry commented Jun 7, 2019

Very nice - I'm able to run it - works great.

@kitsonk kitsonk marked this pull request as ready for review June 8, 2019 04:07
@kitsonk kitsonk changed the title [WIP] Add 'bundle' subcommand. Add 'bundle' subcommand. Jun 8, 2019
@kitsonk kitsonk mentioned this pull request Jun 8, 2019
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a section to the manual describing the bundling operation briefly? (Maybe an example?)

.about("Bundle module and dependnecies into single file")
.long_about(
"Fetch, compile, and output to a single file a module and its dependencies.
"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give an example command here that can be copied and pasted, so people can try it out quickly?

Maybe use a remote URL, like

deno bundle https://deno.land/std/examples/colors.ts colors_bundle.js

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks!

The real problematic block_on usage is here:

deno/cli/ops.rs

Lines 530 to 533 in 5960e39

// WARNING: Here we use tokio_util::block_on() which starts a new Tokio
// runtime for executing the future. This is so we don't inadvernently run
// out of threads in the main runtime.
Box::new(futures::future::result(tokio_util::block_on(fut)))

sorry wrong tab

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

red

@ry
Copy link
Member

ry commented Jun 8, 2019

This would be a cool feature for later:

default output filename

> deno bundle https://deno.land/std/examples/colors.ts
[1/1] Downloading https://deno.land/std/colors/mod.ts
Emitting bundle to "colors.bundle.js"...
9.2 kB emitted.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - this is huge

@kitsonk
Copy link
Contributor Author

kitsonk commented Jun 8, 2019

Yeah, sorry, I went to bed. Thanks for the cleanup and stuff!

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

Successfully merging this pull request may close these issues.

"deno bundle" to produce a dependency-less single file version of a module
2 participants