Skip to content

Commit

Permalink
refactor: remove old Node compat code (#16142)
Browse files Browse the repository at this point in the history
This code was introduced in 808f797 and
was needed for "compat mode". Since "compat mode" was removed in v1.26, this
code is no longer needed.
  • Loading branch information
bartlomieju authored Oct 4, 2022
1 parent 569287b commit b312503
Showing 1 changed file with 9 additions and 34 deletions.
43 changes: 9 additions & 34 deletions cli/proc_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ use deno_graph::create_graph;
use deno_graph::source::CacheInfo;
use deno_graph::source::LoadFuture;
use deno_graph::source::Loader;
use deno_graph::source::ResolveResponse;
use deno_graph::ModuleKind;
use deno_graph::Resolved;
use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel;
Expand Down Expand Up @@ -293,41 +292,11 @@ impl ProcState {
dynamic_permissions: Permissions,
reload_on_watch: bool,
) -> Result<(), AnyError> {
let maybe_resolver: Option<&dyn deno_graph::source::Resolver> =
if let Some(resolver) = &self.maybe_resolver {
Some(resolver.as_ref())
} else {
None
};

// NOTE(@bartlomieju):
// Even though `roots` are fully resolved at this point, we are going
// to resolve them through `maybe_resolver` to get module kind for the graph
// or default to ESM.
//
// One might argue that this is a code smell, and I would agree. However
// due to flux in "Node compatibility" it's not clear where it should be
// decided what `ModuleKind` is decided for root specifier.
let roots: Vec<(deno_core::url::Url, deno_graph::ModuleKind)> = roots
let roots = roots
.into_iter()
.map(|r| {
if let Some(resolver) = &maybe_resolver {
let response =
resolver.resolve(r.as_str(), &Url::parse("unused:").unwrap());
// TODO(bartlomieju): this should be implemented in `deno_graph`
match response {
ResolveResponse::CommonJs(_) => (r, ModuleKind::CommonJs),
ResolveResponse::Err(_) => unreachable!(),
_ => (r, ModuleKind::Esm),
}
} else {
(r, ModuleKind::Esm)
}
})
.collect();
.map(|s| (s, ModuleKind::Esm))
.collect::<Vec<_>>();

// TODO(bartlomieju): this is very make-shift, is there an existing API
// that we could include it like with "maybe_imports"?
if !reload_on_watch {
let graph_data = self.graph_data.read();
if self.options.type_check_mode() == TypeCheckMode::None
Expand All @@ -350,6 +319,12 @@ impl ProcState {
);
let maybe_locker = as_maybe_locker(self.lockfile.clone());
let maybe_imports = self.options.to_maybe_imports()?;
let maybe_resolver: Option<&dyn deno_graph::source::Resolver> =
if let Some(resolver) = &self.maybe_resolver {
Some(resolver.as_ref())
} else {
None
};

struct ProcStateLoader<'a> {
inner: &'a mut cache::FetchCacher,
Expand Down

0 comments on commit b312503

Please sign in to comment.