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

refactor: upgrade to deno_graph 0.64 #158

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rs-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "MIT"
anyhow = { workspace = true }
base64 = { workspace = true }
deno_ast = { version = "0.32.0", features = ["bundler", "codegen", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "visit", "transpiling"] }
deno_graph = { version = "0.63.5", default-features = true }
deno_graph = { version = "0.64.1", default-features = true }
escape8259 = "0.5.2"
futures = "0.3.17"
import_map = "0.18.1"
Expand Down
13 changes: 7 additions & 6 deletions rs-lib/src/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ impl swc::bundler::Load for BundleLoader<'_> {
match file_name {
swc::common::FileName::Url(specifier) => {
let (source, media_type) = match self.graph.get(specifier) {
Some(Module::Esm(m)) => (&m.source, m.media_type),
Some(Module::Js(m)) => (&m.source, m.media_type),
Some(Module::Json(m)) => (&m.source, m.media_type),
Some(_) => {
Some(Module::Npm(_) | Module::Node(_) | Module::External(_)) => {
return Err(anyhow!(
"Module \"{}\" was an unsupported module kind.",
specifier
Expand All @@ -98,7 +98,7 @@ impl swc::bundler::Load for BundleLoader<'_> {
};
let (fm, module) = transpile_module(
specifier,
source,
source.as_ref(),
media_type,
self.emit_options,
self.cm.clone(),
Expand Down Expand Up @@ -177,7 +177,7 @@ pub fn bundle_graph(
Module::External(_) | Module::Node(_) | Module::Npm(_) => {
Some(JsWord::from(m.specifier().to_string()))
}
Module::Esm(_) | Module::Json(_) => None,
Module::Js(_) | Module::Json(_) => None,
})
.collect(),
..Default::default()
Expand Down Expand Up @@ -259,8 +259,9 @@ pub fn bundle_graph(
}

fn shebang_file(graph: &deno_graph::ModuleGraph) -> Option<String> {
let module = graph.get(graph.roots.get(0)?)?.esm()?;
let first_line = module.source.lines().next()?;
let module = graph.get(graph.roots.get(0)?)?.js()?;
let source = &module.source;
let first_line = source.lines().next()?;
if first_line.starts_with("#!") {
Some(first_line.to_string())
} else {
Expand Down
9 changes: 6 additions & 3 deletions rs-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub async fn transpile(

let mut map = HashMap::new();

for module in graph.modules().filter_map(|m| m.esm()) {
for module in graph.modules().filter_map(|m| m.js()) {
if let Some(parsed_source) = analyzer.get_parsed_source(&module.specifier) {
let transpiled_source = parsed_source.transpile(&options.emit_options)?;

Expand Down Expand Up @@ -131,8 +131,11 @@ async fn get_import_map_from_input(
specifier,
maybe_headers: _,
} => {
let import_map =
import_map::parse_from_json(&specifier, &content)?.import_map;
let import_map = import_map::parse_from_json(
&specifier,
&String::from_utf8(content.to_vec())?,
)?
.import_map;
Ok(Some(import_map))
}
}
Expand Down
Loading