Skip to content

Commit

Permalink
fix(rust): remove RUNTIME_PATH (#274)
Browse files Browse the repository at this point in the history
<!-- Thank you for contributing! -->

### Description

Now if users want to have a module called `\0rolldown-runtime.js`, that's totally fine.
<!-- Please insert your description here and provide especially info about the "what" this PR is solving -->

### Test Plan

<!-- e.g. is there anything you'd like reviewers to focus on? -->

---
  • Loading branch information
hyf0 committed Nov 15, 2023
1 parent 131e16b commit c93a2fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
29 changes: 13 additions & 16 deletions crates/rolldown/src/bundler/module_loader/module_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::bundler::module::{Module, ModuleVec};
use crate::bundler::module_loader::module_task_context::ModuleTaskCommonData;
use crate::bundler::options::input_options::SharedInputOptions;
use crate::bundler::plugin_driver::SharedPluginDriver;
use crate::bundler::runtime::{Runtime, RUNTIME_PATH};
use crate::bundler::runtime::Runtime;
use crate::bundler::utils::ast_symbol::AstSymbol;
use crate::bundler::utils::resolve_id::ResolvedRequestInfo;
use crate::bundler::utils::symbols::Symbols;
Expand All @@ -31,6 +31,7 @@ pub struct ModuleLoader<T: FileSystem + Default> {
#[derive(Debug, Default)]
pub struct ModuleLoaderContext {
visited: FxHashMap<FilePath, ModuleId>,
runtime_id: Option<ModuleId>,
remaining: u32,
intermediate_modules: IndexVec<ModuleId, Option<Module>>,
}
Expand Down Expand Up @@ -91,21 +92,17 @@ impl<T: FileSystem + 'static + Default> ModuleLoader<T> {
}

pub fn try_spawn_runtime_module_task(&mut self) -> ModuleId {
match self.ctx.visited.entry(RUNTIME_PATH.to_string().into()) {
std::collections::hash_map::Entry::Occupied(visited) => *visited.get(),
std::collections::hash_map::Entry::Vacant(not_visited) => {
let id = self.ctx.intermediate_modules.push(None);
not_visited.insert(id);
self.ctx.remaining += 1;
let task = RuntimeNormalModuleTask::new(
// safety: Data in `ModuleTaskContext` are alive as long as the `NormalModuleTask`, but rustc doesn't know that.
unsafe { self.common_data.assume_static() },
id,
);
tokio::spawn(async move { task.run() });
id
}
}
*self.ctx.runtime_id.get_or_insert_with(|| {
let id = self.ctx.intermediate_modules.push(None);
self.ctx.remaining += 1;
let task = RuntimeNormalModuleTask::new(
// safety: Data in `ModuleTaskContext` are alive as long as the `NormalModuleTask`, but rustc doesn't know that.
unsafe { self.common_data.assume_static() },
id,
);
tokio::spawn(async move { task.run() });
id
})
}

pub async fn fetch_all_modules(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use super::{module_task_context::ModuleTaskCommonData, Msg};
use crate::bundler::{
module::normal_module_builder::NormalModuleBuilder,
module_loader::NormalModuleTaskResult,
runtime::RUNTIME_PATH,
utils::{ast_scope::AstScope, ast_symbol::AstSymbol},
visitors::scanner::{self, ScanResult},
};
Expand Down Expand Up @@ -54,7 +53,9 @@ impl<'task, T: FileSystem + Default + 'static> RuntimeNormalModuleTask<'task, T>
builder.id = Some(self.module_id);
builder.ast = Some(ast);
builder.unique_name = Some(unique_name);
builder.path = Some(ResourceId::new(RUNTIME_PATH.to_string().into()));
builder.path = Some(ResourceId::new(
"TODO: Runtime module should not have FilePath as source id".to_string().into(),
));
builder.named_imports = Some(named_imports);
builder.named_exports = Some(named_exports);
builder.stmt_infos = Some(stmt_infos);
Expand All @@ -65,7 +66,7 @@ impl<'task, T: FileSystem + Default + 'static> RuntimeNormalModuleTask<'task, T>
builder.scope = Some(scope);
builder.exports_kind = exports_kind;
builder.namespace_symbol = Some(namespace_symbol);
builder.pretty_path = Some("rolldown-runtime.js".to_string());
builder.pretty_path = Some("<runtime>".to_string());

self
.common_data
Expand Down
2 changes: 0 additions & 2 deletions crates/rolldown/src/bundler/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use rustc_hash::FxHashMap;

use super::module::NormalModule;

pub static RUNTIME_PATH: &str = "rolldown-runtime.js";

#[derive(Debug)]
pub struct Runtime {
id: ModuleId,
Expand Down

0 comments on commit c93a2fb

Please sign in to comment.