summaryrefslogtreecommitdiff
path: root/cli/emit.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/emit.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/emit.rs')
-rw-r--r--cli/emit.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/cli/emit.rs b/cli/emit.rs
index 8c4f2091c..3cd23b7ab 100644
--- a/cli/emit.rs
+++ b/cli/emit.rs
@@ -181,7 +181,6 @@ impl Emitter {
pub async fn load_and_emit_for_hmr(
&self,
specifier: &ModuleSpecifier,
- module_kind: deno_ast::ModuleKind,
) -> Result<String, AnyError> {
let media_type = MediaType::from_specifier(specifier);
let source_code = tokio::fs::read_to_string(
@@ -203,11 +202,16 @@ impl Emitter {
// this statement is probably wrong)
let mut options = self.transpile_and_emit_options.1.clone();
options.source_map = SourceMapOption::None;
+ let is_cjs = self.cjs_tracker.is_cjs_with_known_is_script(
+ specifier,
+ media_type,
+ parsed_source.compute_is_script(),
+ )?;
let transpiled_source = parsed_source
.transpile(
&self.transpile_and_emit_options.0,
&deno_ast::TranspileModuleOptions {
- module_kind: Some(module_kind),
+ module_kind: Some(ModuleKind::from_is_cjs(is_cjs)),
},
&options,
)?