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
71 changes: 57 additions & 14 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_legacy_exe } from "#cli/bins";
import { bsc_exe, rescript_exe, rescript_legacy_exe } from "#cli/bins";

/**
* @typedef {{
Expand Down Expand Up @@ -29,10 +29,13 @@ export const {
yarn,
mocha,
bsc,
rescript,
execBin,
rescript,
execBuild,
execClean,
rescriptLegacy,
execBuildLegacy,
execCleanLegacy,
} = setup();

/**
Expand Down Expand Up @@ -156,58 +159,98 @@ export function setup(cwd = process.cwd()) {
return exec("npx", ["mocha", ...args], options);
},

/**
* `bsc` CLI
*
* @param {string[]} [args]
* @param {ExecOptions} [options]
* @return {Promise<ExecResult>}
*/
bsc(args = [], options = {}) {
return exec(bsc_exe, args, options);
},

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

/**
* `bsc` CLI
* Execute ReScript `build` command directly
*
* @param {string[]} [args]
* @param {ExecOptions} [options]
* @return {Promise<ExecResult>}
*/
bsc(args = [], options = {}) {
return exec(bsc_exe, args, options);
execBuild(args = [], options = {}) {
return exec(rescript_exe, ["build", ...args], options);
},

/**
* Execute ReScript `build` command directly
* Execute ReScript `clean` command directly
*
* @param {string[]} [args]
* @param {ExecOptions} [options]
* @return {Promise<ExecResult>}
*/
execBuild(args = [], options = {}) {
execClean(args = [], options = {}) {
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 = {}) {
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<ExecResult>}
*/
execClean(args = [], options = {}) {
execCleanLegacy(args = [], options = {}) {
return exec(rescript_legacy_exe, ["clean", ...args], options);
},

Expand Down
9 changes: 3 additions & 6 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ if (ounitTest) {
}

if (mochaTest) {
await execClean([], {
cwd: compilerTestDir,
stdio: "inherit",
});

// No need to clean beforehand, rewatch detects changes to the compiler binary
// and rebuilds automatically in that case.
await execBuild([], {
cwd: compilerTestDir,
stdio: "inherit",
Expand All @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions tests/build_tests/build_warn_as_error/input.js
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -39,4 +39,4 @@ if (!third_message) {
assert.fail(o3.stdout);
}

await execClean();
await execCleanLegacy();
4 changes: 2 additions & 2 deletions tests/build_tests/case/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
![
Expand Down
4 changes: 2 additions & 2 deletions tests/build_tests/case2/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
![
Expand Down
4 changes: 2 additions & 2 deletions tests/build_tests/case3/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
8 changes: 4 additions & 4 deletions tests/build_tests/cli_compile_status/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/,
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions tests/build_tests/cli_help/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <options> <subcommand>\n" +
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/build_tests/custom_namespace/input.js
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 2 additions & 2 deletions tests/build_tests/cycle/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);

Expand Down
6 changes: 3 additions & 3 deletions tests/build_tests/cycle1/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);

Expand Down
4 changes: 2 additions & 2 deletions tests/build_tests/deprecated-package-specs/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\./,
Expand Down
4 changes: 2 additions & 2 deletions tests/build_tests/devonly/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
6 changes: 3 additions & 3 deletions tests/build_tests/duplicated_symlinked_packages/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions tests/build_tests/exports/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
4 changes: 2 additions & 2 deletions tests/build_tests/gpr_978/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions tests/build_tests/hyphen2/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
4 changes: 2 additions & 2 deletions tests/build_tests/in_source/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Loading
Loading