summaryrefslogtreecommitdiff
path: root/cli/standalone
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-10-14 20:48:39 -0400
committerGitHub <noreply@github.com>2024-10-14 20:48:39 -0400
commit1a0cb5b5312941521ab021cfe9eaed498f35900b (patch)
tree2e5c58e25e8506b993ac678e83ba0c2feac37d75 /cli/standalone
parentee7d4501435f0ebd655c8b50bd6e41ca19e71abc (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/standalone')
-rw-r--r--cli/standalone/binary.rs1
-rw-r--r--cli/standalone/mod.rs5
2 files changed, 5 insertions, 1 deletions
diff --git a/cli/standalone/binary.rs b/cli/standalone/binary.rs
index 1290a238f..6e747bed4 100644
--- a/cli/standalone/binary.rs
+++ b/cli/standalone/binary.rs
@@ -622,6 +622,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
unstable_config: UnstableConfig {
legacy_flag_enabled: false,
bare_node_builtins: cli_options.unstable_bare_node_builtins(),
+ detect_cjs: cli_options.unstable_detect_cjs(),
sloppy_imports: cli_options.unstable_sloppy_imports(),
features: cli_options.unstable_features(),
},
diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs
index 258de0dad..60018228b 100644
--- a/cli/standalone/mod.rs
+++ b/cli/standalone/mod.rs
@@ -586,6 +586,7 @@ pub async fn run(
node_analysis_cache,
fs.clone(),
cli_node_resolver.clone(),
+ None,
);
let node_code_translator = Arc::new(NodeCodeTranslator::new(
cjs_esm_code_analyzer,
@@ -651,7 +652,7 @@ pub async fn run(
workspace_resolver,
node_resolver: cli_node_resolver.clone(),
npm_module_loader: Arc::new(NpmModuleLoader::new(
- cjs_resolutions,
+ cjs_resolutions.clone(),
node_code_translator,
fs.clone(),
cli_node_resolver,
@@ -696,6 +697,7 @@ pub async fn run(
});
let worker_factory = CliMainWorkerFactory::new(
Arc::new(BlobStore::default()),
+ cjs_resolutions,
// Code cache is not supported for standalone binary yet.
None,
feature_checker,
@@ -738,6 +740,7 @@ pub async fn run(
node_ipc: None,
serve_port: None,
serve_host: None,
+ unstable_detect_cjs: metadata.unstable_config.detect_cjs,
},
);