From 6202b700822e050dcdcbf37883f6f696d4f05691 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sat, 3 Jan 2026 16:16:48 +0100 Subject: [PATCH 1/2] execBuild -> execBuildLegacy etc. --- lib_dev/process.js | 40 +++++++++---------- scripts/test.js | 18 ++++----- .../build_tests/build_warn_as_error/input.js | 10 ++--- tests/build_tests/case/input.js | 4 +- tests/build_tests/case2/input.js | 4 +- tests/build_tests/case3/input.js | 4 +- tests/build_tests/cli_compile_status/input.js | 8 ++-- tests/build_tests/cli_help/input.js | 4 +- tests/build_tests/custom_namespace/input.js | 6 +-- tests/build_tests/cycle/input.js | 4 +- tests/build_tests/cycle1/input.js | 6 +-- .../deprecated-package-specs/input.js | 4 +- tests/build_tests/devonly/input.js | 4 +- .../duplicated_symlinked_packages/input.js | 6 +-- tests/build_tests/exports/input.js | 4 +- tests/build_tests/gpr_978/input.js | 4 +- tests/build_tests/hyphen2/input.js | 4 +- tests/build_tests/in_source/input.js | 4 +- tests/build_tests/install/input.js | 10 ++--- .../jsx_settings_inheritance/input.js | 6 +-- tests/build_tests/nested/input.js | 4 +- tests/build_tests/nnest/input.js | 4 +- .../not_undefined_attribute/input.js | 4 +- tests/build_tests/ns/input.js | 4 +- tests/build_tests/post-build/input.js | 4 +- tests/build_tests/react_ppx/input.js | 4 +- tests/build_tests/rerror/input.js | 6 +-- tests/build_tests/scoped_ppx/input.js | 6 +-- .../transitive_dependency/input.js | 6 +-- .../unboxed_bool_with_const/input.js | 4 +- tests/build_tests/uncurried-always/input.js | 6 +-- tests/build_tests/unicode/input.js | 4 +- tests/build_tests/warn_legacy_config/input.js | 4 +- tests/build_tests/weird_deps/input.js | 4 +- tests/build_tests/weird_devdeps/input.js | 4 +- tests/build_tests/weird_names/input.js | 4 +- .../weird_names_not_found_bug/input.js | 4 +- tests/build_tests/x-y/input.js | 4 +- tests/build_tests/xpkg/input.js | 4 +- tests/build_tests/zerocycle/input.js | 4 +- 40 files changed, 121 insertions(+), 121 deletions(-) diff --git a/lib_dev/process.js b/lib_dev/process.js index ac24088871..af57fd2315 100644 --- a/lib_dev/process.js +++ b/lib_dev/process.js @@ -29,10 +29,10 @@ export const { yarn, mocha, bsc, - rescript, execBin, - execBuild, - execClean, + rescriptLegacy, + execBuildLegacy, + execCleanLegacy, } = setup(); /** @@ -157,7 +157,18 @@ export function setup(cwd = process.cwd()) { }, /** - * `rescript` CLI + * `bsc` CLI + * + * @param {string[]} [args] + * @param {ExecOptions} [options] + * @return {Promise} + */ + bsc(args = [], options = {}) { + return exec(bsc_exe, args, options); + }, + + /** + * `rescript` legacy CLI * * @param {( * | "build" @@ -170,7 +181,7 @@ export function setup(cwd = process.cwd()) { * @param {ExecOptions} [options] * @return {Promise} */ - rescript(command, args = [], options = {}) { + rescriptLegacy(command, args = [], options = {}) { const cliPath = path.join( import.meta.dirname, "../cli/rescript-legacy.js", @@ -179,35 +190,24 @@ export function setup(cwd = process.cwd()) { }, /** - * `bsc` CLI - * - * @param {string[]} [args] - * @param {ExecOptions} [options] - * @return {Promise} - */ - bsc(args = [], options = {}) { - return exec(bsc_exe, args, options); - }, - - /** - * Execute ReScript `build` command directly + * Execute ReScript legacy `build` command directly * * @param {string[]} [args] * @param {ExecOptions} [options] * @return {Promise} */ - execBuild(args = [], options = {}) { + execBuildLegacy(args = [], options = {}) { return exec(rescript_legacy_exe, ["build", ...args], options); }, /** - * Execute ReScript `clean` command directly + * Execute ReScript legacy `clean` command directly * * @param {string[]} [args] * @param {ExecOptions} [options] * @return {Promise} */ - execClean(args = [], options = {}) { + execCleanLegacy(args = [], options = {}) { return exec(rescript_legacy_exe, ["clean", ...args], options); }, diff --git a/scripts/test.js b/scripts/test.js index 5434d803f9..ff6dc405b3 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -13,11 +13,11 @@ import { import { execBin, - execBuild, - execClean, + execBuildLegacy, + execCleanLegacy, mocha, node, - rescript, + rescriptLegacy, shell, } from "#dev/process"; @@ -73,12 +73,12 @@ if (ounitTest) { } if (mochaTest) { - await execClean([], { + await execCleanLegacy([], { cwd: compilerTestDir, stdio: "inherit", }); - await execBuild([], { + await execBuildLegacy([], { cwd: compilerTestDir, stdio: "inherit", }); @@ -159,12 +159,12 @@ if (runtimeDocstrings) { "generated_mocha_test.res", ); - await execClean([], { + await execCleanLegacy([], { cwd: docstringTestDir, stdio: "inherit", }); - await execBuild([], { + await execBuildLegacy([], { cwd: docstringTestDir, stdio: "inherit", }); @@ -176,14 +176,14 @@ if (runtimeDocstrings) { }); // Build again to check if generated_mocha_test.res has syntax or type erros - await execBuild([], { + await execBuildLegacy([], { cwd: docstringTestDir, stdio: "inherit", }); // Format generated_mocha_test.res console.log("Formatting generated_mocha_test.res"); - await rescript("format", [generated_mocha_test_res], { + await rescriptLegacy("format", [generated_mocha_test_res], { cwd: projectDir, stdio: "inherit", }); diff --git a/tests/build_tests/build_warn_as_error/input.js b/tests/build_tests/build_warn_as_error/input.js index 17a0bdd42b..ca00be7ca8 100644 --- a/tests/build_tests/build_warn_as_error/input.js +++ b/tests/build_tests/build_warn_as_error/input.js @@ -1,9 +1,9 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; -const { execBuild, execClean } = setup(import.meta.dirname); +const { execBuildLegacy, execCleanLegacy } = setup(import.meta.dirname); -const o1 = await execBuild(); +const o1 = await execBuildLegacy(); const first_message = o1.stdout .split("\n") @@ -15,7 +15,7 @@ if (!first_message) { } // Second build using -warn-error +110 -const o2 = await execBuild(["-warn-error", "+110"]); +const o2 = await execBuildLegacy(["-warn-error", "+110"]); const second_message = o2.stdout .split("\n") @@ -28,7 +28,7 @@ if (!second_message) { // Third build, without -warn-error +110 // The result should not be a warning as error -const o3 = await execBuild(); +const o3 = await execBuildLegacy(); const third_message = o3.stdout .split("\n") @@ -39,4 +39,4 @@ if (!third_message) { assert.fail(o3.stdout); } -await execClean(); +await execCleanLegacy(); diff --git a/tests/build_tests/case/input.js b/tests/build_tests/case/input.js index 52187b7a34..21f0c94547 100644 --- a/tests/build_tests/case/input.js +++ b/tests/build_tests/case/input.js @@ -2,9 +2,9 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -const { stderr } = await execBuild(); +const { stderr } = await execBuildLegacy(); if ( ![ diff --git a/tests/build_tests/case2/input.js b/tests/build_tests/case2/input.js index 6daed5d4ee..1a44c8a5ec 100644 --- a/tests/build_tests/case2/input.js +++ b/tests/build_tests/case2/input.js @@ -4,9 +4,9 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -const { stderr } = await execBuild(); +const { stderr } = await execBuildLegacy(); if ( ![ diff --git a/tests/build_tests/case3/input.js b/tests/build_tests/case3/input.js index 45d78e684a..a95d2a5faa 100644 --- a/tests/build_tests/case3/input.js +++ b/tests/build_tests/case3/input.js @@ -5,9 +5,9 @@ import fs from "node:fs/promises"; import path from "node:path"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -await execBuild(); +await execBuildLegacy(); const o = await fs.readFile(path.join("src", "hello.res.js"), "ascii"); assert.ok(/HelloGen\.f/.test(o)); diff --git a/tests/build_tests/cli_compile_status/input.js b/tests/build_tests/cli_compile_status/input.js index c26e567862..b736a3129a 100755 --- a/tests/build_tests/cli_compile_status/input.js +++ b/tests/build_tests/cli_compile_status/input.js @@ -4,17 +4,17 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { rescript } = setup(import.meta.dirname); +const { rescriptLegacy } = setup(import.meta.dirname); // Shows compile time for `rescript build` command -let out = await rescript("build"); +let out = await rescriptLegacy("build"); assert.match( normalizeNewlines(out.stdout), />>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/, ); // Shows compile time for `rescript` command -out = await rescript("build"); +out = await rescriptLegacy("build"); assert.match( normalizeNewlines(out.stdout), />>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/, @@ -24,7 +24,7 @@ assert.match( // Because we can't be sure that -verbose is a valid argument // And bsb won't fail with a usage message. // It works this way not only for -verbose, but any other arg, including -h/--help/-help -out = await rescript("build", ["-verbose"]); +out = await rescriptLegacy("build", ["-verbose"]); assert.match( normalizeNewlines(out.stdout), diff --git a/tests/build_tests/cli_help/input.js b/tests/build_tests/cli_help/input.js index facfbecf2b..6e0068e2a8 100755 --- a/tests/build_tests/cli_help/input.js +++ b/tests/build_tests/cli_help/input.js @@ -4,7 +4,7 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { rescript } = setup(import.meta.dirname); +const { rescriptLegacy } = setup(import.meta.dirname); const cliHelp = "Usage: rescript \n" + @@ -69,7 +69,7 @@ const dumpHelp = * @param {{ stdout: string; stderr: string; status: number; }} expected */ async function test(params, expected) { - const out = await rescript("", params); + const out = await rescriptLegacy("", params); assert.equal(normalizeNewlines(out.stdout), expected.stdout); assert.equal(normalizeNewlines(out.stderr), expected.stderr); diff --git a/tests/build_tests/custom_namespace/input.js b/tests/build_tests/custom_namespace/input.js index 718d172356..35a776cda4 100644 --- a/tests/build_tests/custom_namespace/input.js +++ b/tests/build_tests/custom_namespace/input.js @@ -1,10 +1,10 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; -const { execClean, execBuild } = setup(import.meta.dirname); +const { execCleanLegacy, execBuildLegacy } = setup(import.meta.dirname); -await execClean(); -await execBuild(); +await execCleanLegacy(); +await execBuildLegacy(); const x = await import("./src/demo.res.js"); assert.equal(x.v, 42); diff --git a/tests/build_tests/cycle/input.js b/tests/build_tests/cycle/input.js index a35f908978..52d30d646b 100644 --- a/tests/build_tests/cycle/input.js +++ b/tests/build_tests/cycle/input.js @@ -5,9 +5,9 @@ import * as fs from "node:fs/promises"; import * as path from "node:path"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -const output = await execBuild(); +const output = await execBuildLegacy(); assert.match(output.stdout, /dependency cycle/); diff --git a/tests/build_tests/cycle1/input.js b/tests/build_tests/cycle1/input.js index 83e04e104e..91e21111aa 100644 --- a/tests/build_tests/cycle1/input.js +++ b/tests/build_tests/cycle1/input.js @@ -5,10 +5,10 @@ import * as fs from "node:fs/promises"; import * as path from "node:path"; import { setup } from "#dev/process"; -const { execBuild, execClean } = setup(import.meta.dirname); +const { execBuildLegacy, execCleanLegacy } = setup(import.meta.dirname); -await execClean(); -const output = await execBuild(); +await execCleanLegacy(); +const output = await execBuildLegacy(); assert.match(output.stdout, /is dangling/); diff --git a/tests/build_tests/deprecated-package-specs/input.js b/tests/build_tests/deprecated-package-specs/input.js index a4a4ed69d1..053f2177b8 100644 --- a/tests/build_tests/deprecated-package-specs/input.js +++ b/tests/build_tests/deprecated-package-specs/input.js @@ -3,9 +3,9 @@ import assert from "node:assert"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -const out = await execBuild(); +const out = await execBuildLegacy(); assert.match( out.stderr, /deprecated: Option "es6-global" is deprecated\. Use "esmodule" instead\./, diff --git a/tests/build_tests/devonly/input.js b/tests/build_tests/devonly/input.js index 50a4ceabd1..8300ab09a5 100644 --- a/tests/build_tests/devonly/input.js +++ b/tests/build_tests/devonly/input.js @@ -2,6 +2,6 @@ import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -await execBuild(); +await execBuildLegacy(); diff --git a/tests/build_tests/duplicated_symlinked_packages/input.js b/tests/build_tests/duplicated_symlinked_packages/input.js index f15c2adcb9..a3871d23e0 100644 --- a/tests/build_tests/duplicated_symlinked_packages/input.js +++ b/tests/build_tests/duplicated_symlinked_packages/input.js @@ -3,7 +3,7 @@ import * as fs from "node:fs/promises"; import { setup } from "#dev/process"; -const { execBuild, execClean } = setup(import.meta.dirname); +const { execBuildLegacy, execCleanLegacy } = setup(import.meta.dirname); const expectedFilePath = "./out.expected"; @@ -22,8 +22,8 @@ if (process.platform === "win32") { process.exit(0); } -await execClean(); -const { stderr } = await execBuild(); +await execCleanLegacy(); +const { stderr } = await execBuildLegacy(); const actualErrorOutput = postProcessErrorOutput(stderr.toString()); if (updateTests) { diff --git a/tests/build_tests/exports/input.js b/tests/build_tests/exports/input.js index 50a4ceabd1..8300ab09a5 100644 --- a/tests/build_tests/exports/input.js +++ b/tests/build_tests/exports/input.js @@ -2,6 +2,6 @@ import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -await execBuild(); +await execBuildLegacy(); diff --git a/tests/build_tests/gpr_978/input.js b/tests/build_tests/gpr_978/input.js index 384a36e77a..da8924057d 100644 --- a/tests/build_tests/gpr_978/input.js +++ b/tests/build_tests/gpr_978/input.js @@ -5,9 +5,9 @@ import * as fs from "node:fs/promises"; import * as path from "node:path"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -const output = await execBuild(); +const output = await execBuildLegacy(); assert.match(output.stdout, /M is exported twice/); const compilerLogFile = path.join("lib", "bs", ".compiler.log"); diff --git a/tests/build_tests/hyphen2/input.js b/tests/build_tests/hyphen2/input.js index 50a4ceabd1..8300ab09a5 100644 --- a/tests/build_tests/hyphen2/input.js +++ b/tests/build_tests/hyphen2/input.js @@ -2,6 +2,6 @@ import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -await execBuild(); +await execBuildLegacy(); diff --git a/tests/build_tests/in_source/input.js b/tests/build_tests/in_source/input.js index f29b5a2e37..7b5a81ea09 100644 --- a/tests/build_tests/in_source/input.js +++ b/tests/build_tests/in_source/input.js @@ -3,7 +3,7 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -const output = await execBuild(["-regen"]); +const output = await execBuildLegacy(["-regen"]); assert.match(output.stderr, /detected two module formats/); diff --git a/tests/build_tests/install/input.js b/tests/build_tests/install/input.js index 4c7df0215d..3cb39bb44e 100644 --- a/tests/build_tests/install/input.js +++ b/tests/build_tests/install/input.js @@ -5,16 +5,16 @@ import { existsSync } from "node:fs"; import * as path from "node:path"; import { setup } from "#dev/process"; -const { execBuild, execClean } = setup(import.meta.dirname); +const { execBuildLegacy, execCleanLegacy } = setup(import.meta.dirname); -await execClean(); -await execBuild(["-install"]); +await execCleanLegacy(); +await execBuildLegacy(["-install"]); let fooExists = existsSync(path.join("lib", "ocaml", "Foo.cmi")); assert.ok(!fooExists); -await execBuild(); -await execBuild(["-install"]); +await execBuildLegacy(); +await execBuildLegacy(["-install"]); fooExists = existsSync(path.join("lib", "ocaml", "Foo.cmi")); assert.ok(fooExists); diff --git a/tests/build_tests/jsx_settings_inheritance/input.js b/tests/build_tests/jsx_settings_inheritance/input.js index 6d8beddd22..03decbf153 100644 --- a/tests/build_tests/jsx_settings_inheritance/input.js +++ b/tests/build_tests/jsx_settings_inheritance/input.js @@ -2,7 +2,7 @@ import { setup } from "#dev/process"; -const { execBuild, execClean } = setup(import.meta.dirname); +const { execBuildLegacy, execCleanLegacy } = setup(import.meta.dirname); -await execClean(); -await execBuild(); +await execCleanLegacy(); +await execBuildLegacy(); diff --git a/tests/build_tests/nested/input.js b/tests/build_tests/nested/input.js index 68b05999ce..ccd0bce50d 100644 --- a/tests/build_tests/nested/input.js +++ b/tests/build_tests/nested/input.js @@ -5,9 +5,9 @@ import * as fs from "node:fs/promises"; import * as path from "node:path"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -await execBuild(); +await execBuildLegacy(); const content = await fs.readFile(path.join("src", "demo.js"), "utf8"); diff --git a/tests/build_tests/nnest/input.js b/tests/build_tests/nnest/input.js index 98da456f4d..3d346a4475 100644 --- a/tests/build_tests/nnest/input.js +++ b/tests/build_tests/nnest/input.js @@ -5,9 +5,9 @@ import * as fs from "node:fs/promises"; import * as path from "node:path"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -await execBuild(); +await execBuildLegacy(); const content = await fs.readFile(path.join("src", "demo.js"), "utf8"); diff --git a/tests/build_tests/not_undefined_attribute/input.js b/tests/build_tests/not_undefined_attribute/input.js index b57b72d111..98455836ac 100644 --- a/tests/build_tests/not_undefined_attribute/input.js +++ b/tests/build_tests/not_undefined_attribute/input.js @@ -4,9 +4,9 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -const out = await execBuild(); +const out = await execBuildLegacy(); assert.equal( normalizeNewlines(out.stdout.slice(out.stdout.indexOf("input.res:2:1-12"))), diff --git a/tests/build_tests/ns/input.js b/tests/build_tests/ns/input.js index 50a4ceabd1..8300ab09a5 100755 --- a/tests/build_tests/ns/input.js +++ b/tests/build_tests/ns/input.js @@ -2,6 +2,6 @@ import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -await execBuild(); +await execBuildLegacy(); diff --git a/tests/build_tests/post-build/input.js b/tests/build_tests/post-build/input.js index 83fd43098f..078bbb811a 100644 --- a/tests/build_tests/post-build/input.js +++ b/tests/build_tests/post-build/input.js @@ -3,14 +3,14 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); if (process.platform === "win32") { console.log("Skipping test on Windows"); process.exit(0); } -const out = await execBuild(); +const out = await execBuildLegacy(); if (out.status !== 0) { assert.fail(out.stdout + out.stderr); diff --git a/tests/build_tests/react_ppx/input.js b/tests/build_tests/react_ppx/input.js index 50a4ceabd1..8300ab09a5 100644 --- a/tests/build_tests/react_ppx/input.js +++ b/tests/build_tests/react_ppx/input.js @@ -2,6 +2,6 @@ import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -await execBuild(); +await execBuildLegacy(); diff --git a/tests/build_tests/rerror/input.js b/tests/build_tests/rerror/input.js index 70a81c8dba..ddcbd1ad7d 100644 --- a/tests/build_tests/rerror/input.js +++ b/tests/build_tests/rerror/input.js @@ -3,10 +3,10 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; -const { execBuild, execClean } = setup(import.meta.dirname); +const { execBuildLegacy, execCleanLegacy } = setup(import.meta.dirname); -await execClean(); -const output = await execBuild([]); +await execCleanLegacy(); +const output = await execBuildLegacy([]); // verify the output is in reason syntax const u = output.stdout.match(/=>/g); diff --git a/tests/build_tests/scoped_ppx/input.js b/tests/build_tests/scoped_ppx/input.js index d3e3f06ee7..ff1426845f 100644 --- a/tests/build_tests/scoped_ppx/input.js +++ b/tests/build_tests/scoped_ppx/input.js @@ -3,15 +3,15 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); if (process.platform === "win32") { console.log("Skipping test on Windows"); process.exit(0); } -await execBuild(); -const output = await execBuild(["--", "-t", "commands", "src/hello.ast"]); +await execBuildLegacy(); +const output = await execBuildLegacy(["--", "-t", "commands", "src/hello.ast"]); assert.match( output.stdout, diff --git a/tests/build_tests/transitive_dependency/input.js b/tests/build_tests/transitive_dependency/input.js index c04b7e3dc5..d13102583a 100644 --- a/tests/build_tests/transitive_dependency/input.js +++ b/tests/build_tests/transitive_dependency/input.js @@ -4,9 +4,9 @@ import * as assert from "node:assert"; import { existsSync } from "node:fs"; import { setup } from "#dev/process"; -const { execBuild, execClean } = setup("./a"); -await execClean(); -const output = await execBuild(); +const { execBuildLegacy, execCleanLegacy } = setup("./a"); +await execCleanLegacy(); +const output = await execBuildLegacy(); console.log(output); assert.ok( diff --git a/tests/build_tests/unboxed_bool_with_const/input.js b/tests/build_tests/unboxed_bool_with_const/input.js index dd2470e600..337065eed9 100644 --- a/tests/build_tests/unboxed_bool_with_const/input.js +++ b/tests/build_tests/unboxed_bool_with_const/input.js @@ -4,9 +4,9 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -const out = await execBuild(); +const out = await execBuildLegacy(); assert.equal( normalizeNewlines(out.stdout.slice(out.stdout.indexOf("Main.res:3:3-14"))), diff --git a/tests/build_tests/uncurried-always/input.js b/tests/build_tests/uncurried-always/input.js index 6d8beddd22..03decbf153 100644 --- a/tests/build_tests/uncurried-always/input.js +++ b/tests/build_tests/uncurried-always/input.js @@ -2,7 +2,7 @@ import { setup } from "#dev/process"; -const { execBuild, execClean } = setup(import.meta.dirname); +const { execBuildLegacy, execCleanLegacy } = setup(import.meta.dirname); -await execClean(); -await execBuild(); +await execCleanLegacy(); +await execBuildLegacy(); diff --git a/tests/build_tests/unicode/input.js b/tests/build_tests/unicode/input.js index 4723a8f55c..44f701627d 100644 --- a/tests/build_tests/unicode/input.js +++ b/tests/build_tests/unicode/input.js @@ -5,14 +5,14 @@ import * as fs from "node:fs/promises"; import * as path from "node:path"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); if (process.platform === "win32") { console.log("Skipping test on Windows"); process.exit(0); } -await execBuild(); +await execBuildLegacy(); const content = await fs.readFile( path.join("lib", "bs", ".sourcedirs.json"), "utf-8", diff --git a/tests/build_tests/warn_legacy_config/input.js b/tests/build_tests/warn_legacy_config/input.js index e079332080..caa8c1e192 100644 --- a/tests/build_tests/warn_legacy_config/input.js +++ b/tests/build_tests/warn_legacy_config/input.js @@ -3,9 +3,9 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -const output = await execBuild(); +const output = await execBuildLegacy(); assert.match( output.stdout, /^Warning: bsconfig.json is deprecated. Migrate it to rescript.json/, diff --git a/tests/build_tests/weird_deps/input.js b/tests/build_tests/weird_deps/input.js index a2b1f4a5e0..6e6f7a4cc5 100644 --- a/tests/build_tests/weird_deps/input.js +++ b/tests/build_tests/weird_deps/input.js @@ -4,9 +4,9 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -const out = await execBuild(); +const out = await execBuildLegacy(); if (out.stdout !== "") { assert.fail(out.stdout); } else { diff --git a/tests/build_tests/weird_devdeps/input.js b/tests/build_tests/weird_devdeps/input.js index 46371e50bb..cc30a015b8 100644 --- a/tests/build_tests/weird_devdeps/input.js +++ b/tests/build_tests/weird_devdeps/input.js @@ -4,9 +4,9 @@ import * as assert from "node:assert"; import * as os from "node:os"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -const out = await execBuild(); +const out = await execBuildLegacy(); if (out.stdout !== "") { assert.fail(out.stdout); } else { diff --git a/tests/build_tests/weird_names/input.js b/tests/build_tests/weird_names/input.js index 56347603ae..92fcaf7f26 100644 --- a/tests/build_tests/weird_names/input.js +++ b/tests/build_tests/weird_names/input.js @@ -4,9 +4,9 @@ import * as assert from "node:assert"; import * as path from "node:path"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -const out = await execBuild(); +const out = await execBuildLegacy(); if (out.stderr !== "") { assert.fail(out.stderr); diff --git a/tests/build_tests/weird_names_not_found_bug/input.js b/tests/build_tests/weird_names_not_found_bug/input.js index 078fb29aed..9861ed7731 100644 --- a/tests/build_tests/weird_names_not_found_bug/input.js +++ b/tests/build_tests/weird_names_not_found_bug/input.js @@ -1,9 +1,9 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; -const { execBuild } = await setup(import.meta.dirname); +const { execBuildLegacy } = await setup(import.meta.dirname); -const out = await execBuild(); +const out = await execBuildLegacy(); if (out.stderr !== "") { assert.fail(out.stderr); diff --git a/tests/build_tests/x-y/input.js b/tests/build_tests/x-y/input.js index 50a4ceabd1..8300ab09a5 100644 --- a/tests/build_tests/x-y/input.js +++ b/tests/build_tests/x-y/input.js @@ -2,6 +2,6 @@ import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuildLegacy } = setup(import.meta.dirname); -await execBuild(); +await execBuildLegacy(); diff --git a/tests/build_tests/xpkg/input.js b/tests/build_tests/xpkg/input.js index 664cb16cd1..2d745b93b8 100644 --- a/tests/build_tests/xpkg/input.js +++ b/tests/build_tests/xpkg/input.js @@ -3,7 +3,7 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; -const { execBuild } = await setup(import.meta.dirname); +const { execBuildLegacy } = await setup(import.meta.dirname); -const output = await execBuild(["-regen"]); +const output = await execBuildLegacy(["-regen"]); assert.match(output.stderr, /reserved package name/); diff --git a/tests/build_tests/zerocycle/input.js b/tests/build_tests/zerocycle/input.js index c81430b7c7..4d76b38648 100644 --- a/tests/build_tests/zerocycle/input.js +++ b/tests/build_tests/zerocycle/input.js @@ -3,6 +3,6 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); -const output = await execBuild(); +const { execBuildLegacy } = setup(import.meta.dirname); +const output = await execBuildLegacy(); assert.ok(output.status === 0); From 8b2028e343c131371a15ee9e491a24d4d98e4842 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sat, 3 Jan 2026 16:29:03 +0100 Subject: [PATCH 2/2] Build tests/tests with rewatch --- lib_dev/process.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- scripts/test.js | 25 +++++++++++-------------- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/lib_dev/process.js b/lib_dev/process.js index af57fd2315..8f0173ad39 100644 --- a/lib_dev/process.js +++ b/lib_dev/process.js @@ -1,7 +1,7 @@ import * as child_process from "node:child_process"; import * as fs from "node:fs/promises"; import * as path from "node:path"; -import { bsc_exe, rescript_legacy_exe } from "#cli/bins"; +import { bsc_exe, rescript_exe, rescript_legacy_exe } from "#cli/bins"; /** * @typedef {{ @@ -30,6 +30,9 @@ export const { mocha, bsc, execBin, + rescript, + execBuild, + execClean, rescriptLegacy, execBuildLegacy, execCleanLegacy, @@ -167,6 +170,46 @@ export function setup(cwd = process.cwd()) { return exec(bsc_exe, args, options); }, + /** + * `rescript` CLI + * + * @param {( + * | "build" + * | "clean" + * | "format" + * | (string & {}) + * )} command + * @param {string[]} [args] + * @param {ExecOptions} [options] + * @return {Promise} + */ + rescript(command, args = [], options = {}) { + const cliPath = path.join(import.meta.dirname, "../cli/rescript.js"); + return exec("node", [cliPath, command, ...args].filter(Boolean), options); + }, + + /** + * Execute ReScript `build` command directly + * + * @param {string[]} [args] + * @param {ExecOptions} [options] + * @return {Promise} + */ + execBuild(args = [], options = {}) { + return exec(rescript_exe, ["build", ...args], options); + }, + + /** + * Execute ReScript `clean` command directly + * + * @param {string[]} [args] + * @param {ExecOptions} [options] + * @return {Promise} + */ + execClean(args = [], options = {}) { + return exec(rescript_exe, ["clean", ...args], options); + }, + /** * `rescript` legacy CLI * diff --git a/scripts/test.js b/scripts/test.js index ff6dc405b3..1f69ab5528 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -13,11 +13,11 @@ import { import { execBin, - execBuildLegacy, - execCleanLegacy, + execBuild, + execClean, mocha, node, - rescriptLegacy, + rescript, shell, } from "#dev/process"; @@ -73,12 +73,9 @@ if (ounitTest) { } if (mochaTest) { - await execCleanLegacy([], { - cwd: compilerTestDir, - stdio: "inherit", - }); - - await execBuildLegacy([], { + // No need to clean beforehand, rewatch detects changes to the compiler binary + // and rebuilds automatically in that case. + await execBuild([], { cwd: compilerTestDir, stdio: "inherit", }); @@ -87,7 +84,7 @@ if (mochaTest) { [ "-t", "10000", - "tests/tests/**/*_test.mjs", + "tests/tests/src/**/*_test.mjs", // Ignore the preserve_jsx_test.mjs file. // I can't run because Mocha doesn't support jsx. // We also want to keep the output as is. @@ -159,12 +156,12 @@ if (runtimeDocstrings) { "generated_mocha_test.res", ); - await execCleanLegacy([], { + await execClean([], { cwd: docstringTestDir, stdio: "inherit", }); - await execBuildLegacy([], { + await execBuild([], { cwd: docstringTestDir, stdio: "inherit", }); @@ -176,14 +173,14 @@ if (runtimeDocstrings) { }); // Build again to check if generated_mocha_test.res has syntax or type erros - await execBuildLegacy([], { + await execBuild([], { cwd: docstringTestDir, stdio: "inherit", }); // Format generated_mocha_test.res console.log("Formatting generated_mocha_test.res"); - await rescriptLegacy("format", [generated_mocha_test_res], { + await rescript("format", [generated_mocha_test_res], { cwd: projectDir, stdio: "inherit", });