summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-11-13 10:10:09 -0500
committerGitHub <noreply@github.com>2024-11-13 15:10:09 +0000
commitf091d1ad69b4e5217ae3272b641171781a372c4f (patch)
tree4ef4f90ec8a6b5c977efb187449f8c59c45de5e1 /cli/tools
parent6a4c6d83bacf5f03628a494778a30bce970f7cbc (diff)
feat(node): stabilize detecting if CJS via `"type": "commonjs"` in a package.json (#26439)
This will respect `"type": "commonjs"` in a package.json to determine if `.js`/`.jsx`/`.ts`/.tsx` files are CJS or ESM. If the file is found to be ESM it will be loaded as ESM though.
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/coverage/mod.rs2
-rw-r--r--cli/tools/installer.rs1
-rw-r--r--cli/tools/jupyter/mod.rs2
-rw-r--r--cli/tools/lint/mod.rs2
-rw-r--r--cli/tools/lint/rules/no_sloppy_imports.rs1
-rw-r--r--cli/tools/repl/session.rs17
-rw-r--r--cli/tools/run/hmr.rs7
7 files changed, 16 insertions, 16 deletions
diff --git a/cli/tools/coverage/mod.rs b/cli/tools/coverage/mod.rs
index f59333247..2a554c133 100644
--- a/cli/tools/coverage/mod.rs
+++ b/cli/tools/coverage/mod.rs
@@ -480,7 +480,7 @@ fn filter_coverages(
.filter(|e| {
let is_internal = e.url.starts_with("ext:")
|| e.url.ends_with("__anonymous__")
- || e.url.ends_with("$deno$test.js")
+ || e.url.ends_with("$deno$test.mjs")
|| e.url.ends_with(".snap")
|| is_supported_test_path(Path::new(e.url.as_str()))
|| doc_test_re.is_match(e.url.as_str())
diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs
index ed86e86c7..1655f0a32 100644
--- a/cli/tools/installer.rs
+++ b/cli/tools/installer.rs
@@ -1396,6 +1396,7 @@ mod tests {
.env_clear()
// use the deno binary in the target directory
.env("PATH", test_util::target_dir())
+ .env("RUST_BACKTRACE", "1")
.spawn()
.unwrap()
.wait()
diff --git a/cli/tools/jupyter/mod.rs b/cli/tools/jupyter/mod.rs
index 0ffd0da1e..732f95c49 100644
--- a/cli/tools/jupyter/mod.rs
+++ b/cli/tools/jupyter/mod.rs
@@ -61,7 +61,7 @@ pub async fn kernel(
let factory = CliFactory::from_flags(flags);
let cli_options = factory.cli_options()?;
let main_module =
- resolve_url_or_path("./$deno$jupyter.ts", cli_options.initial_cwd())
+ resolve_url_or_path("./$deno$jupyter.mts", cli_options.initial_cwd())
.unwrap();
// TODO(bartlomieju): should we run with all permissions?
let permissions =
diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs
index e096b486e..d8edf2404 100644
--- a/cli/tools/lint/mod.rs
+++ b/cli/tools/lint/mod.rs
@@ -63,7 +63,7 @@ pub use rules::LintRuleProvider;
const JSON_SCHEMA_VERSION: u8 = 1;
-static STDIN_FILE_NAME: &str = "$deno$stdin.ts";
+static STDIN_FILE_NAME: &str = "$deno$stdin.mts";
pub async fn lint(
flags: Arc<Flags>,
diff --git a/cli/tools/lint/rules/no_sloppy_imports.rs b/cli/tools/lint/rules/no_sloppy_imports.rs
index 2f6087588..94bf9a7c6 100644
--- a/cli/tools/lint/rules/no_sloppy_imports.rs
+++ b/cli/tools/lint/rules/no_sloppy_imports.rs
@@ -87,6 +87,7 @@ impl LintRule for NoSloppyImportsRule {
captures: Default::default(),
};
+ // fill this and capture the sloppy imports in the resolver
deno_graph::parse_module_from_ast(deno_graph::ParseModuleFromAstOptions {
graph_kind: deno_graph::GraphKind::All,
specifier: context.specifier().clone(),
diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs
index 23b0f11ac..8e05c4abb 100644
--- a/cli/tools/repl/session.rs
+++ b/cli/tools/repl/session.rs
@@ -7,7 +7,7 @@ use crate::cdp;
use crate::colors;
use crate::lsp::ReplLanguageServer;
use crate::npm::CliNpmResolver;
-use crate::resolver::CliGraphResolver;
+use crate::resolver::CliResolver;
use crate::tools::test::report_tests;
use crate::tools::test::reporters::PrettyTestReporter;
use crate::tools::test::reporters::TestReporter;
@@ -44,12 +44,12 @@ use deno_core::url::Url;
use deno_core::LocalInspectorSession;
use deno_core::PollEventLoopOptions;
use deno_graph::source::ResolutionMode;
-use deno_graph::source::Resolver;
use deno_graph::Position;
use deno_graph::PositionRange;
use deno_graph::SpecifierWithRange;
use deno_runtime::worker::MainWorker;
use deno_semver::npm::NpmPackageReqReference;
+use node_resolver::NodeModuleKind;
use once_cell::sync::Lazy;
use regex::Match;
use regex::Regex;
@@ -180,7 +180,7 @@ struct ReplJsxState {
pub struct ReplSession {
npm_resolver: Arc<dyn CliNpmResolver>,
- resolver: Arc<CliGraphResolver>,
+ resolver: Arc<CliResolver>,
pub worker: MainWorker,
session: LocalInspectorSession,
pub context_id: u64,
@@ -199,7 +199,7 @@ impl ReplSession {
pub async fn initialize(
cli_options: &CliOptions,
npm_resolver: Arc<dyn CliNpmResolver>,
- resolver: Arc<CliGraphResolver>,
+ resolver: Arc<CliResolver>,
mut worker: MainWorker,
main_module: ModuleSpecifier,
test_event_receiver: TestEventReceiver,
@@ -245,7 +245,7 @@ impl ReplSession {
assert_ne!(context_id, 0);
let referrer =
- deno_core::resolve_path("./$deno$repl.ts", cli_options.initial_cwd())
+ deno_core::resolve_path("./$deno$repl.mts", cli_options.initial_cwd())
.unwrap();
let cwd_url =
@@ -712,7 +712,12 @@ impl ReplSession {
.flat_map(|i| {
self
.resolver
- .resolve(i, &referrer_range, ResolutionMode::Execution)
+ .resolve(
+ i,
+ &referrer_range,
+ NodeModuleKind::Esm,
+ ResolutionMode::Execution,
+ )
.ok()
.or_else(|| ModuleSpecifier::parse(i).ok())
})
diff --git a/cli/tools/run/hmr.rs b/cli/tools/run/hmr.rs
index 6cebedd01..373c207d6 100644
--- a/cli/tools/run/hmr.rs
+++ b/cli/tools/run/hmr.rs
@@ -4,8 +4,6 @@ use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
-use deno_ast::MediaType;
-use deno_ast::ModuleKind;
use deno_core::error::generic_error;
use deno_core::error::AnyError;
use deno_core::futures::StreamExt;
@@ -18,7 +16,6 @@ use tokio::select;
use crate::cdp;
use crate::emit::Emitter;
-use crate::resolver::CjsTracker;
use crate::util::file_watcher::WatcherCommunicator;
use crate::util::file_watcher::WatcherRestartMode;
@@ -63,7 +60,6 @@ pub struct HmrRunner {
session: LocalInspectorSession,
watcher_communicator: Arc<WatcherCommunicator>,
script_ids: HashMap<String, String>,
- cjs_tracker: Arc<CjsTracker>,
emitter: Arc<Emitter>,
}
@@ -146,7 +142,6 @@ impl crate::worker::HmrRunner for HmrRunner {
let source_code = self.emitter.load_and_emit_for_hmr(
&module_url,
- ModuleKind::from_is_cjs(self.cjs_tracker.is_maybe_cjs(&module_url, MediaType::from_specifier(&module_url))?),
).await?;
let mut tries = 1;
@@ -179,14 +174,12 @@ impl crate::worker::HmrRunner for HmrRunner {
impl HmrRunner {
pub fn new(
- cjs_tracker: Arc<CjsTracker>,
emitter: Arc<Emitter>,
session: LocalInspectorSession,
watcher_communicator: Arc<WatcherCommunicator>,
) -> Self {
Self {
session,
- cjs_tracker,
emitter,
watcher_communicator,
script_ids: HashMap::new(),