Skip to content

Commit 8870423

Browse files
committed
Respect Deno config when bundling
Refactor bundling to build the Command before executing and add support for passing a Deno config file to deno bundle. Introduces a find_deno_config helper (checks EXO_DENO_CONFIG, DENO_CONFIG, cwd deno.json/deno.jsonc and parent dirs) in both deno-graphql-builder and postgres-core-builder and, when present, adds --config <path> to the deno bundle invocation. Also adjusts the postgres bundling invocation (removes the previous --target=esnext arg) as part of the command restructure.
1 parent 9812229 commit 8870423

2 files changed

Lines changed: 102 additions & 11 deletions

File tree

crates/deno-subsystem/deno-graphql-builder/src/system_builder.rs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,19 @@ const DENO_BUNDLE_WARNING: &[u8] = b"is experimental and subject to changes";
4343
async fn bundle_source(module_fs_path: &Path) -> Result<String, ModelBuildingError> {
4444
let deno_path = download_deno_if_needed().await?;
4545

46-
let output = tokio::process::Command::new(deno_path)
46+
let mut command = tokio::process::Command::new(deno_path);
47+
command
4748
.arg("bundle")
4849
.arg("--allow-import")
4950
.arg("--quiet")
5051
.arg("--node-modules-dir=auto")
51-
.arg(module_fs_path.to_string_lossy().as_ref())
52-
.output()
53-
.await;
52+
.arg(module_fs_path.to_string_lossy().as_ref());
53+
54+
if let Some(config_path) = find_deno_config(module_fs_path) {
55+
command.arg("--config").arg(config_path);
56+
}
57+
58+
let output = command.output().await;
5459

5560
fn simplify_error(output: &[u8]) -> String {
5661
// remove the "experimental" warning by looking for DENO_BUNDLE_WARNING and stripping that out
@@ -94,6 +99,48 @@ async fn bundle_source(module_fs_path: &Path) -> Result<String, ModelBuildingErr
9499
}
95100
}
96101

102+
fn find_deno_config(module_fs_path: &Path) -> Option<PathBuf> {
103+
if let Ok(explicit) = std::env::var("EXO_DENO_CONFIG") {
104+
let path = PathBuf::from(explicit);
105+
if path.exists() {
106+
return Some(path);
107+
}
108+
}
109+
if let Ok(explicit) = std::env::var("DENO_CONFIG") {
110+
let path = PathBuf::from(explicit);
111+
if path.exists() {
112+
return Some(path);
113+
}
114+
}
115+
116+
if let Ok(cwd) = std::env::current_dir() {
117+
let json = cwd.join("deno.json");
118+
if json.exists() {
119+
return Some(json);
120+
}
121+
let jsonc = cwd.join("deno.jsonc");
122+
if jsonc.exists() {
123+
return Some(jsonc);
124+
}
125+
}
126+
127+
let mut current = module_fs_path.parent()?.to_path_buf();
128+
loop {
129+
let json = current.join("deno.json");
130+
if json.exists() {
131+
return Some(json);
132+
}
133+
let jsonc = current.join("deno.jsonc");
134+
if jsonc.exists() {
135+
return Some(jsonc);
136+
}
137+
if !current.pop() {
138+
break;
139+
}
140+
}
141+
None
142+
}
143+
97144
async fn download_deno_if_needed() -> Result<PathBuf, ModelBuildingError> {
98145
let deno_executable = if env::consts::OS == "windows" {
99146
"deno.exe"

crates/postgres-subsystem/postgres-core-builder/src/computed_script.rs

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,20 @@ async fn bundle_source(module_fs_path: &Path) -> Result<String, ModelBuildingErr
7676
))
7777
})?;
7878

79-
let output = Command::new(deno_path)
79+
let mut command = Command::new(deno_path);
80+
command
8081
.arg("bundle")
8182
.arg("--allow-import")
82-
// Preserve tagged template literals (e.g. sql`...`) to avoid runtime NOT_TAGGED_CALL errors
83-
// caused by downlevel transforms.
84-
.arg("--target=esnext")
8583
.arg("--quiet")
8684
.arg("--node-modules-dir=auto")
8785
.arg(module_fs_path.to_string_lossy().as_ref())
88-
.current_dir(module_dir)
89-
.output()
90-
.await;
86+
.current_dir(module_dir);
87+
88+
if let Some(config_path) = find_deno_config(module_fs_path) {
89+
command.arg("--config").arg(config_path);
90+
}
91+
92+
let output = command.output().await;
9193

9294
fn simplify_error(output: &[u8]) -> String {
9395
let output = output
@@ -127,6 +129,48 @@ async fn bundle_source(module_fs_path: &Path) -> Result<String, ModelBuildingErr
127129
}
128130
}
129131

132+
fn find_deno_config(module_fs_path: &Path) -> Option<PathBuf> {
133+
if let Ok(explicit) = std::env::var("EXO_DENO_CONFIG") {
134+
let path = PathBuf::from(explicit);
135+
if path.exists() {
136+
return Some(path);
137+
}
138+
}
139+
if let Ok(explicit) = std::env::var("DENO_CONFIG") {
140+
let path = PathBuf::from(explicit);
141+
if path.exists() {
142+
return Some(path);
143+
}
144+
}
145+
146+
if let Ok(cwd) = std::env::current_dir() {
147+
let json = cwd.join("deno.json");
148+
if json.exists() {
149+
return Some(json);
150+
}
151+
let jsonc = cwd.join("deno.jsonc");
152+
if jsonc.exists() {
153+
return Some(jsonc);
154+
}
155+
}
156+
157+
let mut current = module_fs_path.parent()?.to_path_buf();
158+
loop {
159+
let json = current.join("deno.json");
160+
if json.exists() {
161+
return Some(json);
162+
}
163+
let jsonc = current.join("deno.jsonc");
164+
if jsonc.exists() {
165+
return Some(jsonc);
166+
}
167+
if !current.pop() {
168+
break;
169+
}
170+
}
171+
None
172+
}
173+
130174
async fn download_deno_if_needed() -> Result<PathBuf, ModelBuildingError> {
131175
let deno_executable = if env::consts::OS == "windows" {
132176
"deno.exe"

0 commit comments

Comments
 (0)