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

Conversation

2 participants
@kitsonk
Copy link
Contributor

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/deno_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
Show resolved Hide resolved cli/main.rs Outdated
Show resolved Hide resolved cli/state.rs Outdated

@ry ry referenced this pull request Jun 7, 2019

Open

Major features necessary for 1.0 #2473

4 of 19 tasks complete
@ry

This comment has been minimized.

Copy link
Collaborator

commented Jun 7, 2019

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

kitsonk added some commits Jun 7, 2019

@kitsonk kitsonk force-pushed the kitsonk:bundler branch from 28c2b5a to eb2cc00 Jun 8, 2019

@kitsonk kitsonk marked this pull request as ready for review Jun 8, 2019

@kitsonk kitsonk changed the title [WIP] Add 'bundle' subcommand. Add 'bundle' subcommand. Jun 8, 2019

@kitsonk kitsonk referenced this pull request Jun 8, 2019

Open

Bundling V2 #2475

@ry
Copy link
Collaborator

left a comment

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.
"

This comment has been minimized.

Copy link
@ry

ry Jun 8, 2019

Collaborator

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
@ry

ry approved these changes Jun 8, 2019

Copy link
Collaborator

left a comment

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

@ry
Copy link
Collaborator

left a comment

red

@ry

This comment has been minimized.

Copy link
Collaborator

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.

ry added some commits Jun 8, 2019

fmt
@ry

ry approved these changes Jun 8, 2019

Copy link
Collaborator

left a comment

LGTM - this is huge

@ry ry merged commit 307e092 into denoland:master Jun 8, 2019

3 checks passed

Travis CI - Pull Request Build Passed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
license/cla Contributor License Agreement is signed.
Details
@kitsonk

This comment has been minimized.

Copy link
Contributor Author

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
You can’t perform that action at this time.