Skip to content

feat(bundle): runtime API for deno bundle - #29949

Merged
nathanwhit merged 34 commits into
denoland:mainfrom
nathanwhit:bundle-runtime-api2
Sep 4, 2025
Merged

nathanwhit merged 34 commits into
denoland:mainfrom
nathanwhit:bundle-runtime-api2

Conversation

@nathanwhit

@nathanwhit nathanwhit commented Jul 1, 2025 •

Copy link
Copy Markdown
Member

In its current state, it works, but it isn't pretty and has rough edges just about all over

@nathanwhit
nathanwhit force-pushed the bundle-runtime-api2 branch from dd83789 to 84cf2b6 Compare July 1, 2025 02:26

@lucacasonato lucacasonato left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Still needs an unstable flag

@nathanwhit
nathanwhit force-pushed the bundle-runtime-api2 branch from d827f21 to d9b55ad Compare July 1, 2025 16:19
@bartlomieju bartlomieju added this to the 2.5.0 milestone Aug 22, 2025
@nathanwhit
nathanwhit force-pushed the bundle-runtime-api2 branch from 57ac076 to 4409779 Compare August 27, 2025 02:00
@nathanwhit
nathanwhit marked this pull request as ready for review September 2, 2025 21:13
Comment thread runtime/ops/bundle.rs Outdated
self,
scope: &mut v8::HandleScope<'s>,
) -> Result<Vec<v8::Local<'s, v8::Value>>, PluginExecError> {
let mut v8_args = Vec::new();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
let mut v8_args = Vec::new();
let mut v8_args = Vec::with_capacity(5);

Comment thread runtime/worker.rs Outdated
/// V8 code cache for module and script source code.
pub v8_code_cache: Option<Arc<dyn CodeCache>>,

pub bundle_provider: Option<Arc<dyn crate::ops::bundle::BundleProvider>>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it actually optional? What happens if it's None?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It falls back to a default implementation that errors out when you call it

Comment thread runtime/worker.rs Outdated
ops::permissions::deno_permissions::init(),
ops::tty::deno_tty::init(),
ops::http::deno_http_runtime::init(),
ops::bundle::deno_bundle_runtime::lazy_init(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is it lazy_init() here but init() in web_worker.rs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not entirely sure, I was matching the rest of the extensions that have args (for instance deno_node and a bunch of others are the same)

Comment thread runtime/Cargo.toml Resolved
Comment thread libs/resolver/emit.rs
TranspileResult::Owned(source) => source,
TranspileResult::Cloned(source) => {
debug_assert!(false, "Transpile owned failed.");
// debug_assert!(false, "Transpile owned failed.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be reverted I think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This assertion was failing during bundling and I'm not sure why


/** **UNSTABLE**: New API, yet to be vetted.
*
* Bundle Typescript/Javascript code

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can be done in a follow up, but please open an issue about it to improve these JS docks

Comment thread cli/tsc/dts/lib.deno.unstable.d.ts Resolved
Comment on lines +153 to +154
let flags = Arc::new(flags_clone);
let bundler = match super::bundle_init(flags, &bundle_flags).await {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ooof, this feels super hacky - are we sure that all the permissions are upheld? Feels like it would use permissions defined in flags, not the current permission set after Deno.permissions.request()/revoke()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider factoring out a higher level function that doesn't work off of flags

@nathanwhit nathanwhit Sep 3, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The issue isn't that bundle_init needs flags, it's that the CliFactory needs flags. For instance, the resolver and other things change based on the subcommand on the Flags. For the main clifactory the resolver and the rest are made for the run subcommand, so we need a new CliFactory with the bundle subcommand. That means making new flags

Comment thread cli/tools/bundle/provider.rs Resolved
Comment thread cli/tools/bundle/mod.rs Resolved
Comment thread cli/tools/bundle/mod.rs Resolved

@bartlomieju bartlomieju left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

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.

3 participants