Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 1 addition & 48 deletions lib_dev/process.js
Original file line number Diff line number Diff line change
@@ -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_exe, rescript_legacy_exe } from "#cli/bins";
import { bsc_exe, rescript_exe } from "#cli/bins";

/**
* @typedef {{
Expand Down Expand Up @@ -33,9 +33,6 @@ export const {
rescript,
execBuild,
execClean,
rescriptLegacy,
execBuildLegacy,
execCleanLegacy,
} = setup();

/**
Expand Down Expand Up @@ -210,50 +207,6 @@ export function setup(cwd = process.cwd()) {
return exec(rescript_exe, ["clean", ...args], options);
},

/**
* `rescript` legacy CLI
*
* @param {(
* | "build"
* | "clean"
* | "format"
* | "dump"
* | (string & {})
* )} command
* @param {string[]} [args]
* @param {ExecOptions} [options]
* @return {Promise<ExecResult>}
*/
rescriptLegacy(command, args = [], options = {}) {
const cliPath = path.join(
import.meta.dirname,
"../cli/rescript-legacy.js",
);
return exec("node", [cliPath, command, ...args].filter(Boolean), options);
},

/**
* Execute ReScript legacy `build` command directly
*
* @param {string[]} [args]
* @param {ExecOptions} [options]
* @return {Promise<ExecResult>}
*/
execBuildLegacy(args = [], options = {}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment, but I would not remove this just yet.

return exec(rescript_legacy_exe, ["build", ...args], options);
},

/**
* Execute ReScript legacy `clean` command directly
*
* @param {string[]} [args]
* @param {ExecOptions} [options]
* @return {Promise<ExecResult>}
*/
execCleanLegacy(args = [], options = {}) {
return exec(rescript_legacy_exe, ["clean", ...args], options);
},

/**
* Execute any binary or wrapper.
* It should support Windows as well
Expand Down
8 changes: 3 additions & 5 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,14 @@ if (bsbTest) {
if (!fs.existsSync(path.join(testDir, "input.js"))) {
console.warn(`input.js does not exist in ${testDir}`);
} else {
console.log(`testing ${file}`);

// note existsSync test already ensure that it is a directory
const out = await node("input.js", [], { cwd: testDir });
console.log(out.stdout);
process.stdout.write(out.stdout);

if (out.status === 0) {
console.log("✅ success in", file);
console.log(`✅ success in ${file}`);
} else {
console.log(`❌ error in ${file} with stderr:\n`, out.stderr);
console.log(`❌ error in ${file} with stderr:\n${out.stderr}`);
hasError = true;
}
}
Expand Down
10 changes: 4 additions & 6 deletions tests/build_tests/build_warn_as_error/input.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import * as assert from "node:assert";
import { stripVTControlCharacters } from "node:util";
import { setup } from "#dev/process";

const { execBuild, execClean } = setup(import.meta.dirname);

const o1 = await execBuild();

// biome-ignore lint/suspicious/noControlCharactersInRegex: strip ANSI color codes from output
const stripAnsi = s => s.replace(/\x1b\[[0-9;]*m/g, "");

const first_message = stripAnsi(o1.stderr)
const first_message = stripVTControlCharacters(o1.stderr)
.split("\n")
.map(s => s.trim())
.find(s => s === "Warning number 110");
Expand All @@ -20,7 +18,7 @@ if (!first_message) {
// Second build using --warn-error +110
const o2 = await execBuild(["--warn-error", "+110"]);

const second_message = stripAnsi(o2.stderr)
const second_message = stripVTControlCharacters(o2.stderr)
.split("\n")
.map(s => s.trim())
.find(s => s === "Warning number 110 (configured as error)");
Expand All @@ -33,7 +31,7 @@ if (!second_message) {
// The result should not be a warning as error
const o3 = await execBuild();

const third_message = stripAnsi(o3.stderr)
const third_message = stripVTControlCharacters(o3.stderr)
.split("\n")
.map(s => s.trim())
.find(s => s === "Warning number 110 (configured as error)");
Expand Down
5 changes: 3 additions & 2 deletions tests/build_tests/case3/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import fs from "node:fs/promises";
import path from "node:path";
import { setup } from "#dev/process";

const { execBuildLegacy } = setup(import.meta.dirname);
const { execBuild, execClean } = setup(import.meta.dirname);

await execBuildLegacy();
await execClean();
await execBuild();

const o = await fs.readFile(path.join("src", "hello.res.js"), "ascii");
assert.ok(/HelloGen\.f/.test(o));
32 changes: 16 additions & 16 deletions tests/build_tests/cli_compile_status/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ import * as assert from "node:assert";
import { setup } from "#dev/process";
import { normalizeNewlines } from "#dev/utils";

const { rescriptLegacy } = setup(import.meta.dirname);
const { rescript } = setup(import.meta.dirname);

// Shows compile time for `rescript build` command
let out = await rescriptLegacy("build");
// Shows build output for `rescript build` command
let out = await rescript("build");
// Timing text only appears with TTY/progress output; plain output omits it.
assert.match(
normalizeNewlines(out.stdout),
/>>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/,
/Parsed \d+ source files( in [0-9.]+s)?/,
);

// Shows compile time for `rescript` command
out = await rescriptLegacy("build");
assert.match(
normalizeNewlines(out.stdout),
/>>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/,
/Compiled \d+ modules( in [0-9.]+s)?/,
);

// Doesn't show compile time for `rescript build -verbose` command
// 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 rescriptLegacy("build", ["-verbose"]);

// Shows build output for `rescript` command
out = await rescript("");
assert.match(
normalizeNewlines(out.stdout),
/Parsed \d+ source files( in [0-9.]+s)?/,
);
assert.match(
normalizeNewlines(out.stdout),
/Package stack: test {2}\nDependency Finished\n/,
/Compiled \d+ modules( in [0-9.]+s)?/,
);
assert.match(normalizeNewlines(out.stdout), /ninja.exe"? -C lib[\\/]bs ?\n/);

out = await rescript("build", ["-v"]);
assert.match(normalizeNewlines(out.stdout), /Created project context/);
Loading
Loading