summaryrefslogtreecommitdiff
path: root/cli/node.rs
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/node.rs
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/node.rs')
-rw-r--r--cli/node.rs12
1 files changed, 2 insertions, 10 deletions
diff --git a/cli/node.rs b/cli/node.rs
index 1d410a726..8235745a9 100644
--- a/cli/node.rs
+++ b/cli/node.rs
@@ -62,10 +62,6 @@ pub struct CliCjsCodeAnalyzer {
cjs_tracker: Arc<CjsTracker>,
fs: deno_fs::FileSystemRc,
parsed_source_cache: Option<Arc<ParsedSourceCache>>,
- // todo(dsherret): hack, remove in https://github.com/denoland/deno/pull/26439
- // For example, this does not properly handle if cjs analysis was already done
- // and has been cached.
- is_npm_main: bool,
}
impl CliCjsCodeAnalyzer {
@@ -74,14 +70,12 @@ impl CliCjsCodeAnalyzer {
cjs_tracker: Arc<CjsTracker>,
fs: deno_fs::FileSystemRc,
parsed_source_cache: Option<Arc<ParsedSourceCache>>,
- is_npm_main: bool,
) -> Self {
Self {
cache,
cjs_tracker,
fs,
parsed_source_cache,
- is_npm_main,
}
}
@@ -106,9 +100,7 @@ impl CliCjsCodeAnalyzer {
}
let cjs_tracker = self.cjs_tracker.clone();
- let is_npm_main = self.is_npm_main;
- let is_maybe_cjs =
- cjs_tracker.is_maybe_cjs(specifier, media_type)? || is_npm_main;
+ let is_maybe_cjs = cjs_tracker.is_maybe_cjs(specifier, media_type)?;
let analysis = if is_maybe_cjs {
let maybe_parsed_source = self
.parsed_source_cache
@@ -135,7 +127,7 @@ impl CliCjsCodeAnalyzer {
parsed_source.specifier(),
media_type,
is_script,
- )? || is_script && is_npm_main;
+ )?;
if is_cjs {
let analysis = parsed_source.analyze_cjs();
Ok(CliCjsAnalysis::Cjs {