diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-10-14 20:48:39 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-14 20:48:39 -0400 |
commit | 1a0cb5b5312941521ab021cfe9eaed498f35900b (patch) | |
tree | 2e5c58e25e8506b993ac678e83ba0c2feac37d75 /cli/args/mod.rs | |
parent | ee7d4501435f0ebd655c8b50bd6e41ca19e71abc (diff) |
feat(unstable): `--unstable-detect-cjs` for respecting explicit `"type": "commonjs"` (#26149)
When using the `--unstable-detect-cjs` flag or adding `"unstable":
["detect-cjs"]` to a deno.json, it will make a JS file CJS if the
closest package.json contains `"type": "commonjs"` and the file is not
an ESM module (no TLA, no `import.meta`, no `import`/`export`).
Diffstat (limited to 'cli/args/mod.rs')
-rw-r--r-- | cli/args/mod.rs | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 07906a86a..f905e186b 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1576,6 +1576,11 @@ impl CliOptions { || self.workspace().has_unstable("bare-node-builtins") } + pub fn unstable_detect_cjs(&self) -> bool { + self.flags.unstable_config.detect_cjs + || self.workspace().has_unstable("detect-cjs") + } + fn byonm_enabled(&self) -> bool { // check if enabled via unstable self.node_modules_dir().ok().flatten() == Some(NodeModulesDirMode::Manual) @@ -1620,21 +1625,17 @@ impl CliOptions { }); if !from_config_file.is_empty() { - // collect unstable granular flags - let mut all_valid_unstable_flags: Vec<&str> = - crate::UNSTABLE_GRANULAR_FLAGS - .iter() - .map(|granular_flag| granular_flag.name) - .collect(); - - let mut another_unstable_flags = Vec::from([ - "sloppy-imports", - "byonm", - "bare-node-builtins", - "fmt-component", - ]); - // add more unstable flags to the same vector holding granular flags - all_valid_unstable_flags.append(&mut another_unstable_flags); + let all_valid_unstable_flags: Vec<&str> = crate::UNSTABLE_GRANULAR_FLAGS + .iter() + .map(|granular_flag| granular_flag.name) + .chain([ + "sloppy-imports", + "byonm", + "bare-node-builtins", + "fmt-component", + "detect-cjs", + ]) + .collect(); // check and warn if the unstable flag of config file isn't supported, by // iterating through the vector holding the unstable flags |