From 412ef5587039e66a5c61c33359991e84b6bb745f Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 19 Jan 2026 09:25:45 +0100 Subject: [PATCH 1/2] Use rescript.json working dir. --- docs/docson/build-schema.json | 4 ++-- rewatch/src/build/compile.rs | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/docson/build-schema.json b/docs/docson/build-schema.json index 0e3155343a..34c307d97e 100644 --- a/docs/docson/build-schema.json +++ b/docs/docson/build-schema.json @@ -125,7 +125,7 @@ "properties": { "cmd": { "type": "string", - "description": "Shell command to run after each JS file is compiled. The absolute path to the output JS file is appended as an argument. The path respects the `in-source` setting." + "description": "Shell command to run after each JS file is compiled. The absolute path to the output JS file is appended as an argument. The path respects the `in-source` setting. The command runs in the directory containing the rescript.json where it is defined." } } }, @@ -454,7 +454,7 @@ }, "js-post-build": { "$ref": "#/definitions/js-post-build", - "description": "Post-processing hook. The build system will invoke `cmd ` after each JS file is compiled. The path respects the `in-source` setting: when true, the path is next to the source file; when false, the path is in the `lib//` directory. The command runs with the same working directory as the build process (typically the project root)." + "description": "Post-processing hook. The build system will invoke `cmd ` after each JS file is compiled. The path respects the `in-source` setting: when true, the path is next to the source file; when false, the path is in the `lib//` directory. The command runs in the directory containing the rescript.json where it is defined." }, "package-specs": { "$ref": "#/definitions/package-specs", diff --git a/rewatch/src/build/compile.rs b/rewatch/src/build/compile.rs index 25f9b661fc..bda22e12d4 100644 --- a/rewatch/src/build/compile.rs +++ b/rewatch/src/build/compile.rs @@ -22,16 +22,27 @@ use std::sync::OnceLock; use std::time::SystemTime; /// Execute js-post-build command for a compiled JavaScript file. -/// Unlike bsb which passes relative paths, rewatch passes absolute paths for clarity. -fn execute_post_build_command(cmd: &str, js_file_path: &Path) -> Result<()> { +/// The command runs in the directory containing the rescript.json that defines it. +/// The absolute path to the JS file is passed as an argument. +fn execute_post_build_command(cmd: &str, js_file_path: &Path, working_dir: &Path) -> Result<()> { let full_command = format!("{} {}", cmd, js_file_path.display()); - debug!("Executing js-post-build: {}", full_command); + debug!( + "Executing js-post-build: {} (in {})", + full_command, + working_dir.display() + ); let output = if cfg!(target_os = "windows") { - Command::new("cmd").args(["/C", &full_command]).output() + Command::new("cmd") + .args(["/C", &full_command]) + .current_dir(working_dir) + .output() } else { - Command::new("sh").args(["-c", &full_command]).output() + Command::new("sh") + .args(["-c", &full_command]) + .current_dir(working_dir) + .output() }; match output { @@ -886,7 +897,8 @@ fn compile_file( if js_file.exists() { // Fail the build if post-build command fails (matches bsb behavior with &&) - execute_post_build_command(&js_post_build.cmd, &js_file)?; + // Run in the package's directory (where rescript.json is defined) + execute_post_build_command(&js_post_build.cmd, &js_file, &package.path)?; } } } From 1eb1c9d608124a26489a396e635def519bab9040 Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 19 Jan 2026 09:28:19 +0100 Subject: [PATCH 2/2] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f08f867bb7..1ddebb640f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - `Int.fromString` and `Float.fromString` use stricter number parsing and no longer uses an explicit radix argument, but instead supports parsing hexadecimal, binary and exponential notation. - Remove `external-stdlib` configuration option from `rescript.json`. This option was rarely used and is no longer supported. - `js-post-build` now passes the correct output file path based on `in-source` configuration: when `in-source: true`, the path next to the source file is passed; when `in-source: false`, the path in the `lib//` directory is passed. Additionally, stdout and stderr from the post-build command are now logged. https://github.com/rescript-lang/rescript/pull/8190 +- `js-post-build` command now runs in the directory containing the `rescript.json` where it is defined, instead of the unpredictable build invocation directory. This provides consistent behavior in monorepos. https://github.com/rescript-lang/rescript/pull/8195 #### :eyeglasses: Spec Compliance