From 1a0904f49fde085f4a2177038aa4c8e93bf7f7d5 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 6 Mar 2024 04:07:40 +0900 Subject: [PATCH 01/28] prioritizing `--help` arg handling --- jscomp/build_tests/cli_help/input.js | 26 +++-------- rescript | 70 ++++++++++++++-------------- scripts/rescript_bsb.js | 4 ++ 3 files changed, 44 insertions(+), 56 deletions(-) diff --git a/jscomp/build_tests/cli_help/input.js b/jscomp/build_tests/cli_help/input.js index d2ebcde3c7..693b63f6ae 100755 --- a/jscomp/build_tests/cli_help/input.js +++ b/jscomp/build_tests/cli_help/input.js @@ -81,35 +81,21 @@ assert.equal(out.stdout, buildHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); -// FIXME: Help works incorrectly in watch mode out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], { encoding: "utf8", cwd: __dirname, }); -// FIXME: Shouldn't have "Start compiling" for help -assert.equal(out.stdout, ">>>> Start compiling\n" + buildHelp); -// FIXME: Don't run the watcher when showing help -assert.match( - out.stderr, - new RegExp( - "Uncaught Exception Error: ENOENT: no such file or directory, watch 'bsconfig.json'\n" - ) -); -// FIXME: Should be 0 -assert.equal(out.status, 1); +assert.equal(out.stdout, buildHelp); +assert.equal(out.stderr, ""); +assert.equal(out.status, 0); -// FIXME: Has the same problem with `rescript -w` out = child_process.spawnSync(`../../../rescript`, ["-w", "--help"], { encoding: "utf8", cwd: __dirname, }); -assert.equal(out.stdout, ">>>> Start compiling\n" + buildHelp); -assert.match( - out.stderr, - new RegExp( - "Uncaught Exception Error: ENOENT: no such file or directory, watch 'bsconfig.json'\n" - ) -); +assert.equal(out.stdout, cliHelp); +assert.equal(out.stderr, ""); +assert.equal(out.status, 0); // Shows cli help with --help arg even if there are invalid arguments after it out = child_process.spawnSync(`../../../rescript`, ["--help", "-w"], { diff --git a/rescript b/rescript index a0ba2963a1..b48eca7f35 100755 --- a/rescript +++ b/rescript @@ -67,66 +67,64 @@ process.on("SIGUSR2", exitProcess); process.on("SIGTERM", exitProcess); process.on("SIGHUP", exitProcess); -const process_argv = process.argv; -const maybeSubcommand = process_argv[2]; +const args = process.argv.slice(2); +const helpArgIndex = args.findIndex(arg => /help|-h|-help|--help/.test(arg)); +const firstPositionalArgIndex = args.findIndex(arg => !arg.startsWith("-")); -if (!maybeSubcommand) { - bsb.build([]); -} else { - switch (maybeSubcommand) { +if (helpArgIndex !== -1 && (firstPositionalArgIndex === -1 || helpArgIndex <= firstPositionalArgIndex)) { + console.log(helpMessage); + +} else if (/version|-v|-version|--version/.test(args[0])) { + console.log(require("./package.json").version); + +} else if (firstPositionalArgIndex !== -1) { + const subcmd = args[firstPositionalArgIndex]; + const subcmdArgs = args.slice(firstPositionalArgIndex + 1); + + switch (subcmd) { case "info": { - bsb.info(process_argv.slice(3)); + bsb.info(subcmdArgs); break; } case "clean": { - bsb.clean(process_argv.slice(3)); + bsb.clean(subcmdArgs); break; } case "build": { - bsb.build(process_argv.slice(3)); + bsb.build(subcmdArgs); break; } - case "format": + case "format": { require("./scripts/rescript_format.js").main( - process.argv.slice(3), + subcmdArgs, rescript_exe, bsc_exe ); break; - case "dump": + } + case "dump": { require("./scripts/rescript_dump.js").main( - process.argv.slice(3), + subcmdArgs, rescript_exe, bsc_exe ); break; - case "convert": + } + case "convert": { require("./scripts/rescript_convert.js").main( - process.argv.slice(3), + subcmdArgs, rescript_exe, bsc_exe ); break; - case "-h": - case "-help": - case "--help": - case "help": - console.log(helpMessage); - break; - case "-v": - case "-version": - case "--version": - case "version": - console.log(require("./package.json").version); - break; - default: - if (maybeSubcommand.startsWith("-")) { - bsb.build(process_argv.slice(2)); - } else { - console.error( - `Error: Unknown command "${maybeSubcommand}".\n${helpMessage}` - ); - process.exit(2); - } + } + default: { + console.error( + `Error: Unknown command "${subcmd}".\n${helpMessage}` + ); + process.exit(2); + } } +} else { + bsb.build(args); } diff --git a/scripts/rescript_bsb.js b/scripts/rescript_bsb.js index a64415ffe4..8015770274 100644 --- a/scripts/rescript_bsb.js +++ b/scripts/rescript_bsb.js @@ -493,6 +493,10 @@ function build(args) { }); return; } + if (args.some(arg => /-h|-help|--help/.test(arg))) { + delegate(["build", "-h"]); + return; + } if (args.includes("-w")) { watch(args); return; From 5f0cd480838d823e8a82c9270ecfb3d8dd673397 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 6 Mar 2024 04:43:56 +0900 Subject: [PATCH 02/28] exit on build error --- scripts/rescript_bsb.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/scripts/rescript_bsb.js b/scripts/rescript_bsb.js index 8015770274..1718c8fc21 100644 --- a/scripts/rescript_bsb.js +++ b/scripts/rescript_bsb.js @@ -55,23 +55,20 @@ function acquireBuild() { * @param {(code: number) => void} [maybeOnClose] */ function delegate(args, maybeOnClose) { - /** - * @type {child_process.ChildProcess} - */ - let p; if (acquireBuild()) { - try { - p = child_process.spawn(rescript_exe, args, { - stdio: "inherit", - }); - } catch (e) { - if (e.code === "ENOENT") { - // when bsb is actually not found - console.error(String(e)); - } + /** + * @type {child_process.ChildProcess} + */ + const p = child_process.spawn(rescript_exe, args, { + stdio: "inherit", + }); + + p.on("error", e => { + console.error(String(e)); releaseBuild(); process.exit(2); - } + }); + // The 'close' event will always emit after 'exit' was already emitted, or // 'error' if the child failed to spawn. p.on("close", code => { From ee76c2fd0de96f50365cc32bdb41709616393564 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 6 Mar 2024 05:25:34 +0900 Subject: [PATCH 03/28] how about this? --- scripts/rescript_bsb.js | 66 +++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/scripts/rescript_bsb.js b/scripts/rescript_bsb.js index 1718c8fc21..031dd5172d 100644 --- a/scripts/rescript_bsb.js +++ b/scripts/rescript_bsb.js @@ -6,47 +6,47 @@ var os = require("os"); const child_process = require("child_process"); const rescript_exe = require("./bin_path").rescript_exe; -/** - * @typedef {Object} ProjectFiles - * @property {Array} dirs - * @property {Array} generated - */ - -/** - * @typedef {Object} WatcherRef - * @property {string} dir - * @property {fs.FSWatcher} watcher - */ - const cwd = process.cwd(); const lockFileName = path.join(cwd, ".bsb.lock"); -let isBuilding = false; +/** + * @type {child_process.ChildProcess | null} + */ +let ownerProcess = null; function releaseBuild() { - if (isBuilding) { + if (ownerProcess) { try { + ownerProcess.kill(); fs.unlinkSync(lockFileName); - } catch (err) {} - isBuilding = false; + } catch {} + ownerProcess = null; } } -// We use [~perm:0o664] rather than our usual default perms, [0o666], because -// lock files shouldn't rely on the umask to disallow tampering by other. -function acquireBuild() { - if (isBuilding) { - return false; +/** + * We use [~perm:0o664] rather than our usual default perms, [0o666], because + * lock files shouldn't rely on the umask to disallow tampering by other. + * + * @param {Array} args + */ +function acquireBuild(args) { + if (ownerProcess) { + return null; } else { try { - const fid = fs.openSync(lockFileName, "wx", 0o664); - fs.closeSync(fid); - isBuilding = true; + ownerProcess = child_process.spawn(rescript_exe, args, { + stdio: "inherit", + }); + fs.writeFileSync(lockFileName, ownerProcess.pid.toString(), { + encoding: "utf8", + mode: 0o664, + }); } catch (err) { if (err.code === "EEXIST") { console.warn(lockFileName, "already exists, try later"); } else console.log(err); } - return isBuilding; + return ownerProcess; } } @@ -55,15 +55,9 @@ function acquireBuild() { * @param {(code: number) => void} [maybeOnClose] */ function delegate(args, maybeOnClose) { - if (acquireBuild()) { - /** - * @type {child_process.ChildProcess} - */ - const p = child_process.spawn(rescript_exe, args, { - stdio: "inherit", - }); - - p.on("error", e => { + let p; + if ((p = acquireBuild(args))) { + p.once("error", e => { console.error(String(e)); releaseBuild(); process.exit(2); @@ -71,7 +65,7 @@ function delegate(args, maybeOnClose) { // The 'close' event will always emit after 'exit' was already emitted, or // 'error' if the child failed to spawn. - p.on("close", code => { + p.once("close", code => { releaseBuild(); const exitCode = code === null ? 1 : code; if (maybeOnClose) { @@ -376,7 +370,7 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); } else { dlog(`Rebuilding since ${reasonsToRebuild}`); } - if (acquireBuild()) { + if (acquireBuild(args)) { logStartCompiling(); child_process .spawn(rescript_exe, rescriptWatchBuildArgs, { From 2d98261a8504a457e72e53b42207af5c0150545b Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 6 Mar 2024 05:43:02 +0900 Subject: [PATCH 04/28] tmp: lets find out --- jscomp/build_tests/cli_help/input.js | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/jscomp/build_tests/cli_help/input.js b/jscomp/build_tests/cli_help/input.js index 693b63f6ae..2e247046b2 100755 --- a/jscomp/build_tests/cli_help/input.js +++ b/jscomp/build_tests/cli_help/input.js @@ -73,6 +73,7 @@ const dumpHelp = "`rescript dump` dumps the information for the target\n"; // Shows build help with --help arg +console.group("build --help"); let out = child_process.spawnSync(`../../../rescript`, ["build", "--help"], { encoding: "utf8", cwd: __dirname, @@ -80,7 +81,9 @@ let out = child_process.spawnSync(`../../../rescript`, ["build", "--help"], { assert.equal(out.stdout, buildHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); +console.group("build -w --help"); out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], { encoding: "utf8", cwd: __dirname, @@ -88,7 +91,9 @@ out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], { assert.equal(out.stdout, buildHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); +console.group("-w --help"); out = child_process.spawnSync(`../../../rescript`, ["-w", "--help"], { encoding: "utf8", cwd: __dirname, @@ -96,8 +101,10 @@ out = child_process.spawnSync(`../../../rescript`, ["-w", "--help"], { assert.equal(out.stdout, cliHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); // Shows cli help with --help arg even if there are invalid arguments after it +console.group("--help -w"); out = child_process.spawnSync(`../../../rescript`, ["--help", "-w"], { encoding: "utf8", cwd: __dirname, @@ -105,8 +112,10 @@ out = child_process.spawnSync(`../../../rescript`, ["--help", "-w"], { assert.equal(out.stdout, cliHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); // Shows build help with -h arg +console.group("build -h"); out = child_process.spawnSync(`../../../rescript`, ["build", "-h"], { encoding: "utf8", cwd: __dirname, @@ -114,8 +123,10 @@ out = child_process.spawnSync(`../../../rescript`, ["build", "-h"], { assert.equal(out.stdout, buildHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); // Exits with build help with unknown arg +console.group("build -foo"); out = child_process.spawnSync(`../../../rescript`, ["build", "-foo"], { encoding: "utf8", cwd: __dirname, @@ -123,8 +134,10 @@ out = child_process.spawnSync(`../../../rescript`, ["build", "-foo"], { assert.equal(out.stdout, ""); assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); assert.equal(out.status, 2); +console.groupEnd(); // Shows cli help with --help arg +console.group("--help"); out = child_process.spawnSync(`../../../rescript`, ["--help"], { encoding: "utf8", cwd: __dirname, @@ -132,8 +145,10 @@ out = child_process.spawnSync(`../../../rescript`, ["--help"], { assert.equal(out.stdout, cliHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); // Shows cli help with -h arg +console.group("-h"); out = child_process.spawnSync(`../../../rescript`, ["-h"], { encoding: "utf8", cwd: __dirname, @@ -141,8 +156,10 @@ out = child_process.spawnSync(`../../../rescript`, ["-h"], { assert.equal(out.stdout, cliHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); // Shows cli help with help command +console.group("help"); out = child_process.spawnSync(`../../../rescript`, ["help"], { encoding: "utf8", cwd: __dirname, @@ -150,8 +167,10 @@ out = child_process.spawnSync(`../../../rescript`, ["help"], { assert.equal(out.stdout, cliHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); // Exits with cli help with unknown command +console.group("built"); out = child_process.spawnSync(`../../../rescript`, ["built"], { encoding: "utf8", cwd: __dirname, @@ -159,8 +178,10 @@ out = child_process.spawnSync(`../../../rescript`, ["built"], { assert.equal(out.stdout, ""); assert.equal(out.stderr, `Error: Unknown command "built".\n` + cliHelp); assert.equal(out.status, 2); +console.groupEnd(); // Exits with build help with unknown args +console.group("-foo"); out = child_process.spawnSync(`../../../rescript`, ["-foo"], { encoding: "utf8", cwd: __dirname, @@ -168,8 +189,10 @@ out = child_process.spawnSync(`../../../rescript`, ["-foo"], { assert.equal(out.stdout, ""); assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); assert.equal(out.status, 2); +console.groupEnd(); // Shows clean help with --help arg +console.group("clean --help"); out = child_process.spawnSync(`../../../rescript`, ["clean", "--help"], { encoding: "utf8", cwd: __dirname, @@ -177,8 +200,10 @@ out = child_process.spawnSync(`../../../rescript`, ["clean", "--help"], { assert.equal(out.stdout, cleanHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); // Shows clean help with -h arg +console.group("clean -h"); out = child_process.spawnSync(`../../../rescript`, ["clean", "-h"], { encoding: "utf8", cwd: __dirname, @@ -186,8 +211,10 @@ out = child_process.spawnSync(`../../../rescript`, ["clean", "-h"], { assert.equal(out.stdout, cleanHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); // Exits with clean help with unknown arg +console.group("clean -foo"); out = child_process.spawnSync(`../../../rescript`, ["clean", "-foo"], { encoding: "utf8", cwd: __dirname, @@ -195,8 +222,10 @@ out = child_process.spawnSync(`../../../rescript`, ["clean", "-foo"], { assert.equal(out.stdout, ""); assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + cleanHelp); assert.equal(out.status, 2); +console.groupEnd(); // Shows format help with --help arg +console.group("format --help"); out = child_process.spawnSync(`../../../rescript`, ["format", "--help"], { encoding: "utf8", cwd: __dirname, @@ -204,8 +233,10 @@ out = child_process.spawnSync(`../../../rescript`, ["format", "--help"], { assert.equal(out.stdout, formatHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); // Shows format help with -h arg +console.group("format -h"); out = child_process.spawnSync(`../../../rescript`, ["format", "-h"], { encoding: "utf8", cwd: __dirname, @@ -213,8 +244,10 @@ out = child_process.spawnSync(`../../../rescript`, ["format", "-h"], { assert.equal(out.stdout, formatHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); // Shows convert help with --help arg +console.group("convert --help"); out = child_process.spawnSync(`../../../rescript`, ["convert", "--help"], { encoding: "utf8", cwd: __dirname, @@ -222,8 +255,10 @@ out = child_process.spawnSync(`../../../rescript`, ["convert", "--help"], { assert.equal(out.stdout, convertHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); // Shows convert help with -h arg +console.group("convert -h"); out = child_process.spawnSync(`../../../rescript`, ["convert", "-h"], { encoding: "utf8", cwd: __dirname, @@ -231,8 +266,10 @@ out = child_process.spawnSync(`../../../rescript`, ["convert", "-h"], { assert.equal(out.stdout, convertHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); // Shows dump help with --help arg +console.group("dump --help"); out = child_process.spawnSync(`../../../rescript`, ["dump", "--help"], { encoding: "utf8", cwd: __dirname, @@ -240,8 +277,10 @@ out = child_process.spawnSync(`../../../rescript`, ["dump", "--help"], { assert.equal(out.stdout, dumpHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); // Shows dump help with -h arg +console.group("dump -h"); out = child_process.spawnSync(`../../../rescript`, ["dump", "-h"], { encoding: "utf8", cwd: __dirname, @@ -249,3 +288,4 @@ out = child_process.spawnSync(`../../../rescript`, ["dump", "-h"], { assert.equal(out.stdout, dumpHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.groupEnd(); From f57c4b75d5b9386063d631a63670028b9dd2d0ea Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 6 Mar 2024 22:23:44 +0900 Subject: [PATCH 05/28] fix watch build --- scripts/rescript_bsb.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/scripts/rescript_bsb.js b/scripts/rescript_bsb.js index 031dd5172d..04c5010e52 100644 --- a/scripts/rescript_bsb.js +++ b/scripts/rescript_bsb.js @@ -28,14 +28,16 @@ function releaseBuild() { * lock files shouldn't rely on the umask to disallow tampering by other. * * @param {Array} args + * @param {child_process.SpawnOptions} [options] */ -function acquireBuild(args) { +function acquireBuild(args, options) { if (ownerProcess) { return null; } else { try { ownerProcess = child_process.spawn(rescript_exe, args, { stdio: "inherit", + ...options, }); fs.writeFileSync(lockFileName, ownerProcess.pid.toString(), { encoding: "utf8", @@ -370,17 +372,17 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); } else { dlog(`Rebuilding since ${reasonsToRebuild}`); } - if (acquireBuild(args)) { + let p; + if ( + (p = acquireBuild(rescriptWatchBuildArgs, { + stdio: ["inherit", "inherit", "pipe"], + })) + ) { logStartCompiling(); - child_process - .spawn(rescript_exe, rescriptWatchBuildArgs, { - stdio: ["inherit", "inherit", "pipe"], - }) - // @ts-ignore - .on("data", function (s) { - outputError(s, "ninja: error"); - }) - .on("exit", buildFinishedCallback) + p.on("data", function (s) { + outputError(s, "ninja: error"); + }) + .once("exit", buildFinishedCallback) .stderr.setEncoding("utf8"); // This is important to clean up all // previous queued events From 3fc254a46d058d0daf1f1e18f1cceb9d083b4dfc Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Thu, 7 Mar 2024 01:41:09 +0900 Subject: [PATCH 06/28] match via `Array.prototype.includes` --- rescript | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rescript b/rescript index b48eca7f35..20c3557ff5 100755 --- a/rescript +++ b/rescript @@ -68,13 +68,18 @@ process.on("SIGTERM", exitProcess); process.on("SIGHUP", exitProcess); const args = process.argv.slice(2); -const helpArgIndex = args.findIndex(arg => /help|-h|-help|--help/.test(arg)); +const argPatterns = { + help: ['help', '-h', '-help', '--help'], + version: ['version', '-v', '-version', '--version'], +}; + +const helpArgIndex = args.findIndex(arg => argPatterns.help.includes(arg)); const firstPositionalArgIndex = args.findIndex(arg => !arg.startsWith("-")); if (helpArgIndex !== -1 && (firstPositionalArgIndex === -1 || helpArgIndex <= firstPositionalArgIndex)) { console.log(helpMessage); -} else if (/version|-v|-version|--version/.test(args[0])) { +} else if (argPatterns.version.includes(args[0])) { console.log(require("./package.json").version); } else if (firstPositionalArgIndex !== -1) { From ac6bd751fa36f928c4aea988a9a458c9226bc068 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Thu, 7 Mar 2024 02:03:31 +0900 Subject: [PATCH 07/28] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5556ddf4a6..3ece1e0846 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,10 @@ - Build with OCaml 5.1.1. https://github.com/rescript-lang/rescript-compiler/pull/6641 +#### :nail_care: Polish + +- Make the `--help` arg be prioritized in the CLI, so correctly prints help message and skip other commands. https://github.com/rescript-lang/rescript-compiler/pull/6667 + # 11.1.0-rc.3 #### :nail_care: Polish From e4069e101588f4aebcc78aec3886eedbdb70828d Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Thu, 7 Mar 2024 02:26:59 +0900 Subject: [PATCH 08/28] tmp: bump node version --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c38f78433..19b421003c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,7 +82,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 - name: Copy exes to platform bin dirs run: node ./scripts/copyExes.js From 609890277a5c1d3232583f56c9494d54077e0c54 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Thu, 7 Mar 2024 02:50:53 +0900 Subject: [PATCH 09/28] tmp: no buffer --- scripts/ciTest.js | 55 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/scripts/ciTest.js b/scripts/ciTest.js index 9716c139b6..cbde058d49 100644 --- a/scripts/ciTest.js +++ b/scripts/ciTest.js @@ -37,7 +37,7 @@ if (all) { formatTest = true; } -function runTests() { +async function runTests() { if (ounitTest) { cp.execSync(path.join(duneBinDir, "ounit_tests"), { stdio: [0, 1, 2], @@ -56,7 +56,13 @@ function runTests() { console.log("Doing build_tests"); var buildTestDir = path.join(__dirname, "..", "jscomp", "build_tests"); var files = fs.readdirSync(buildTestDir); - files.forEach(function (file) { + var tasks = files.map(async function (file) { + // @ts-ignore + let resolve, reject; + let promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); var testDir = path.join(buildTestDir, file); if (file === "node_modules" || !fs.lstatSync(testDir).isDirectory()) { return; @@ -65,23 +71,38 @@ function runTests() { console.warn(`input.js does not exist in ${testDir}`); } else { console.log(`testing ${file}`); + // note existsSync test already ensure that it is a directory - cp.exec( - `node input.js`, - { cwd: testDir, encoding: "utf8" }, - function (error, stdout, stderr) { - console.log(stdout); - - if (error !== null) { - console.log(`❌ error in ${file} with stderr:\n`, stderr); - throw error; - } else { - console.log("✅ success in", file); - } + let p = cp.spawn(`node`, ["input.js"], { cwd: testDir }); + + p.stdout.setEncoding("utf8").on("data", line => { + console.log(line); + }); + + let stderr = ""; + p.stderr.setEncoding("utf8").on("data", line => { + stderr += line + "\n"; + }); + + p.once("error", err => { + console.log(`❌ error in ${file} with stderr:\n`, stderr); + // @ts-ignore + reject(err); + }); + + p.once("close", () => { + if (!stderr) { + console.log("✅ success in", file); } - ); + // @ts-ignore + resolve(); + }); } + + return promise; }); + + await Promise.all(tasks); } if (formatTest) { @@ -92,9 +113,9 @@ function runTests() { } } -function main() { +async function main() { try { - runTests(); + await runTests(); } catch (err) { console.error(err); process.exit(2); From fa228cfce0f43fe5a18d39dbde0da8dd4a25857a Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Thu, 7 Mar 2024 03:44:39 +0900 Subject: [PATCH 10/28] tmp --- jscomp/build_tests/cli_help/input.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/jscomp/build_tests/cli_help/input.js b/jscomp/build_tests/cli_help/input.js index 2e247046b2..5543a26c80 100755 --- a/jscomp/build_tests/cli_help/input.js +++ b/jscomp/build_tests/cli_help/input.js @@ -94,6 +94,7 @@ assert.equal(out.status, 0); console.groupEnd(); console.group("-w --help"); +console.log("@@ begin "); out = child_process.spawnSync(`../../../rescript`, ["-w", "--help"], { encoding: "utf8", cwd: __dirname, @@ -101,10 +102,12 @@ out = child_process.spawnSync(`../../../rescript`, ["-w", "--help"], { assert.equal(out.stdout, cliHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.log("@@ done"); console.groupEnd(); // Shows cli help with --help arg even if there are invalid arguments after it console.group("--help -w"); +console.log("@@ begin "); out = child_process.spawnSync(`../../../rescript`, ["--help", "-w"], { encoding: "utf8", cwd: __dirname, @@ -112,10 +115,12 @@ out = child_process.spawnSync(`../../../rescript`, ["--help", "-w"], { assert.equal(out.stdout, cliHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.log("@@ done"); console.groupEnd(); // Shows build help with -h arg console.group("build -h"); +console.log("@@ begin "); out = child_process.spawnSync(`../../../rescript`, ["build", "-h"], { encoding: "utf8", cwd: __dirname, @@ -123,10 +128,12 @@ out = child_process.spawnSync(`../../../rescript`, ["build", "-h"], { assert.equal(out.stdout, buildHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); +console.log("@@ done "); console.groupEnd(); // Exits with build help with unknown arg console.group("build -foo"); +console.log("@@ begin "); out = child_process.spawnSync(`../../../rescript`, ["build", "-foo"], { encoding: "utf8", cwd: __dirname, @@ -134,6 +141,7 @@ out = child_process.spawnSync(`../../../rescript`, ["build", "-foo"], { assert.equal(out.stdout, ""); assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); assert.equal(out.status, 2); +console.log("@@ done "); console.groupEnd(); // Shows cli help with --help arg From 321013cfe1e8c50cde9c0ae49874d413f3d7833c Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Thu, 7 Mar 2024 04:13:23 +0900 Subject: [PATCH 11/28] match via Array.prototype.includes --- scripts/rescript_bsb.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/rescript_bsb.js b/scripts/rescript_bsb.js index 04c5010e52..6c059ccbe5 100644 --- a/scripts/rescript_bsb.js +++ b/scripts/rescript_bsb.js @@ -486,7 +486,11 @@ function build(args) { }); return; } - if (args.some(arg => /-h|-help|--help/.test(arg))) { + if ( + args.includes("-h") || + args.includes("-help") || + args.includes("--help") + ) { delegate(["build", "-h"]); return; } From 9f2b57995f6703f869e7c949e55cec3660ae05cd Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Thu, 7 Mar 2024 04:50:56 +0900 Subject: [PATCH 12/28] tmp: is it watching? --- jscomp/build_tests/cli_help/input.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/jscomp/build_tests/cli_help/input.js b/jscomp/build_tests/cli_help/input.js index 5543a26c80..33a97330a7 100755 --- a/jscomp/build_tests/cli_help/input.js +++ b/jscomp/build_tests/cli_help/input.js @@ -83,15 +83,15 @@ assert.equal(out.stderr, ""); assert.equal(out.status, 0); console.groupEnd(); -console.group("build -w --help"); -out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out.stdout, buildHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); -console.groupEnd(); +// console.group("build -w --help"); +// out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], { +// encoding: "utf8", +// cwd: __dirname, +// }); +// assert.equal(out.stdout, buildHelp); +// assert.equal(out.stderr, ""); +// assert.equal(out.status, 0); +// console.groupEnd(); console.group("-w --help"); console.log("@@ begin "); From 09f67410ebd0e91695ff040bd5aa1a3a163758c6 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Thu, 7 Mar 2024 05:09:10 +0900 Subject: [PATCH 13/28] tmp: is it building? --- jscomp/build_tests/cli_help/input.js | 67 ++++++++++++++-------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/jscomp/build_tests/cli_help/input.js b/jscomp/build_tests/cli_help/input.js index 33a97330a7..515c3c325b 100755 --- a/jscomp/build_tests/cli_help/input.js +++ b/jscomp/build_tests/cli_help/input.js @@ -73,15 +73,16 @@ const dumpHelp = "`rescript dump` dumps the information for the target\n"; // Shows build help with --help arg -console.group("build --help"); -let out = child_process.spawnSync(`../../../rescript`, ["build", "--help"], { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out.stdout, buildHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); -console.groupEnd(); +// console.group("build --help"); +let out; +// let out = child_process.spawnSync(`../../../rescript`, ["build", "--help"], { +// encoding: "utf8", +// cwd: __dirname, +// }); +// assert.equal(out.stdout, buildHelp); +// assert.equal(out.stderr, ""); +// assert.equal(out.status, 0); +// console.groupEnd(); // console.group("build -w --help"); // out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], { @@ -119,30 +120,30 @@ console.log("@@ done"); console.groupEnd(); // Shows build help with -h arg -console.group("build -h"); -console.log("@@ begin "); -out = child_process.spawnSync(`../../../rescript`, ["build", "-h"], { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out.stdout, buildHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); -console.log("@@ done "); -console.groupEnd(); - -// Exits with build help with unknown arg -console.group("build -foo"); -console.log("@@ begin "); -out = child_process.spawnSync(`../../../rescript`, ["build", "-foo"], { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out.stdout, ""); -assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); -assert.equal(out.status, 2); -console.log("@@ done "); -console.groupEnd(); +// console.group("build -h"); +// console.log("@@ begin "); +// out = child_process.spawnSync(`../../../rescript`, ["build", "-h"], { +// encoding: "utf8", +// cwd: __dirname, +// }); +// assert.equal(out.stdout, buildHelp); +// assert.equal(out.stderr, ""); +// assert.equal(out.status, 0); +// console.log("@@ done "); +// console.groupEnd(); +// +// // Exits with build help with unknown arg +// console.group("build -foo"); +// console.log("@@ begin "); +// out = child_process.spawnSync(`../../../rescript`, ["build", "-foo"], { +// encoding: "utf8", +// cwd: __dirname, +// }); +// assert.equal(out.stdout, ""); +// assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); +// assert.equal(out.status, 2); +// console.log("@@ done "); +// console.groupEnd(); // Shows cli help with --help arg console.group("--help"); From d0c40b0304a2a44971b20252569d7fdba5553227 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Thu, 7 Mar 2024 05:53:12 +0900 Subject: [PATCH 14/28] tmp: but why? --- jscomp/build_tests/cli_help/input.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/jscomp/build_tests/cli_help/input.js b/jscomp/build_tests/cli_help/input.js index 515c3c325b..3be82de55b 100755 --- a/jscomp/build_tests/cli_help/input.js +++ b/jscomp/build_tests/cli_help/input.js @@ -132,18 +132,18 @@ console.groupEnd(); // console.log("@@ done "); // console.groupEnd(); // -// // Exits with build help with unknown arg -// console.group("build -foo"); -// console.log("@@ begin "); -// out = child_process.spawnSync(`../../../rescript`, ["build", "-foo"], { -// encoding: "utf8", -// cwd: __dirname, -// }); -// assert.equal(out.stdout, ""); -// assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); -// assert.equal(out.status, 2); -// console.log("@@ done "); -// console.groupEnd(); +// Exits with build help with unknown arg +console.group("build -foo"); +console.log("@@ begin "); +out = child_process.spawnSync(`../../../rescript`, ["build", "-foo"], { + encoding: "utf8", + cwd: __dirname, +}); +assert.equal(out.stdout, ""); +assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); +assert.equal(out.status, 2); +console.log("@@ done "); +console.groupEnd(); // Shows cli help with --help arg console.group("--help"); From b0c6124972c3eaf658baed9e1cd0bcab1ed3566c Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sat, 9 Mar 2024 02:12:13 +0900 Subject: [PATCH 15/28] tmp: check again --- jscomp/build_tests/cli_help/input.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/jscomp/build_tests/cli_help/input.js b/jscomp/build_tests/cli_help/input.js index 3be82de55b..2996eb0edf 100755 --- a/jscomp/build_tests/cli_help/input.js +++ b/jscomp/build_tests/cli_help/input.js @@ -73,16 +73,17 @@ const dumpHelp = "`rescript dump` dumps the information for the target\n"; // Shows build help with --help arg -// console.group("build --help"); let out; -// let out = child_process.spawnSync(`../../../rescript`, ["build", "--help"], { -// encoding: "utf8", -// cwd: __dirname, -// }); -// assert.equal(out.stdout, buildHelp); -// assert.equal(out.stderr, ""); -// assert.equal(out.status, 0); -// console.groupEnd(); + +console.group("build --help"); +out = child_process.spawnSync(`../../../rescript`, ["build", "--help"], { + encoding: "utf8", + cwd: __dirname, +}); +assert.equal(out.stdout, buildHelp); +assert.equal(out.stderr, ""); +assert.equal(out.status, 0); +console.groupEnd(); // console.group("build -w --help"); // out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], { From b1c1f1395a6f3287bbeb54ec579c99647c7b38a4 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sat, 9 Mar 2024 02:31:53 +0900 Subject: [PATCH 16/28] tmp: only when spawning subprocesses? --- jscomp/build_tests/cli_help/input.js | 66 ++++++++++------------------ 1 file changed, 22 insertions(+), 44 deletions(-) diff --git a/jscomp/build_tests/cli_help/input.js b/jscomp/build_tests/cli_help/input.js index 2996eb0edf..a7887f13bd 100755 --- a/jscomp/build_tests/cli_help/input.js +++ b/jscomp/build_tests/cli_help/input.js @@ -76,13 +76,11 @@ const dumpHelp = let out; console.group("build --help"); -out = child_process.spawnSync(`../../../rescript`, ["build", "--help"], { +out = child_process.execSync(`../../../rescript build --help`, { encoding: "utf8", cwd: __dirname, }); -assert.equal(out.stdout, buildHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); +assert.equal(out, buildHelp); console.groupEnd(); // console.group("build -w --help"); @@ -97,26 +95,22 @@ console.groupEnd(); console.group("-w --help"); console.log("@@ begin "); -out = child_process.spawnSync(`../../../rescript`, ["-w", "--help"], { +out = child_process.execSync(`../../../rescript -w --help`, { encoding: "utf8", cwd: __dirname, }); -assert.equal(out.stdout, cliHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); +assert.equal(out, cliHelp); console.log("@@ done"); console.groupEnd(); // Shows cli help with --help arg even if there are invalid arguments after it console.group("--help -w"); console.log("@@ begin "); -out = child_process.spawnSync(`../../../rescript`, ["--help", "-w"], { +out = child_process.execSync(`../../../rescript --help -w`, { encoding: "utf8", cwd: __dirname, }); -assert.equal(out.stdout, cliHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); +assert.equal(out, cliHelp); console.log("@@ done"); console.groupEnd(); @@ -203,24 +197,20 @@ console.groupEnd(); // Shows clean help with --help arg console.group("clean --help"); -out = child_process.spawnSync(`../../../rescript`, ["clean", "--help"], { +out = child_process.execSync(`../../../rescript clean --help`, { encoding: "utf8", cwd: __dirname, }); -assert.equal(out.stdout, cleanHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); +assert.equal(out, cleanHelp); console.groupEnd(); // Shows clean help with -h arg console.group("clean -h"); -out = child_process.spawnSync(`../../../rescript`, ["clean", "-h"], { +out = child_process.execSync(`../../../rescript clean -h`, { encoding: "utf8", cwd: __dirname, }); -assert.equal(out.stdout, cleanHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); +assert.equal(out, cleanHelp); console.groupEnd(); // Exits with clean help with unknown arg @@ -236,66 +226,54 @@ console.groupEnd(); // Shows format help with --help arg console.group("format --help"); -out = child_process.spawnSync(`../../../rescript`, ["format", "--help"], { +out = child_process.execSync(`../../../rescript format --help`, { encoding: "utf8", cwd: __dirname, }); -assert.equal(out.stdout, formatHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); +assert.equal(out, formatHelp); console.groupEnd(); // Shows format help with -h arg console.group("format -h"); -out = child_process.spawnSync(`../../../rescript`, ["format", "-h"], { +out = child_process.execSync(`../../../rescript format -h`, { encoding: "utf8", cwd: __dirname, }); -assert.equal(out.stdout, formatHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); +assert.equal(out, formatHelp); console.groupEnd(); // Shows convert help with --help arg console.group("convert --help"); -out = child_process.spawnSync(`../../../rescript`, ["convert", "--help"], { +out = child_process.execSync(`../../../rescript convert --help`, { encoding: "utf8", cwd: __dirname, }); -assert.equal(out.stdout, convertHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); +assert.equal(out, convertHelp); console.groupEnd(); // Shows convert help with -h arg console.group("convert -h"); -out = child_process.spawnSync(`../../../rescript`, ["convert", "-h"], { +out = child_process.execSync(`../../../rescript convert -h`, { encoding: "utf8", cwd: __dirname, }); -assert.equal(out.stdout, convertHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); +assert.equal(out, convertHelp); console.groupEnd(); // Shows dump help with --help arg console.group("dump --help"); -out = child_process.spawnSync(`../../../rescript`, ["dump", "--help"], { +out = child_process.execSync(`../../../rescript dump --help`, { encoding: "utf8", cwd: __dirname, }); -assert.equal(out.stdout, dumpHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); +assert.equal(out, dumpHelp); console.groupEnd(); // Shows dump help with -h arg console.group("dump -h"); -out = child_process.spawnSync(`../../../rescript`, ["dump", "-h"], { +out = child_process.execSync(`../../../rescript dump -h`, { encoding: "utf8", cwd: __dirname, }); -assert.equal(out.stdout, dumpHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); +assert.equal(out, dumpHelp); console.groupEnd(); From 3d47b8764d639b082e73ca6b26ff4431ce405d71 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 15 Mar 2024 21:29:23 +0900 Subject: [PATCH 17/28] avoid using spawnSync --- jscomp/build_tests/cli_help/input.js | 367 ++++++++++++--------------- jscomp/build_tests/utils.js | 46 ++++ 2 files changed, 207 insertions(+), 206 deletions(-) create mode 100644 jscomp/build_tests/utils.js diff --git a/jscomp/build_tests/cli_help/input.js b/jscomp/build_tests/cli_help/input.js index a7887f13bd..a975c6860f 100755 --- a/jscomp/build_tests/cli_help/input.js +++ b/jscomp/build_tests/cli_help/input.js @@ -1,7 +1,7 @@ // @ts-check const assert = require("assert"); -const child_process = require("child_process"); +const { exec } = require("../utils.js"); const cliHelp = "Usage: rescript \n" + @@ -72,208 +72,163 @@ const dumpHelp = "Usage: rescript dump [target]\n" + "`rescript dump` dumps the information for the target\n"; -// Shows build help with --help arg -let out; - -console.group("build --help"); -out = child_process.execSync(`../../../rescript build --help`, { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out, buildHelp); -console.groupEnd(); - -// console.group("build -w --help"); -// out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], { -// encoding: "utf8", -// cwd: __dirname, -// }); -// assert.equal(out.stdout, buildHelp); -// assert.equal(out.stderr, ""); -// assert.equal(out.status, 0); -// console.groupEnd(); - -console.group("-w --help"); -console.log("@@ begin "); -out = child_process.execSync(`../../../rescript -w --help`, { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out, cliHelp); -console.log("@@ done"); -console.groupEnd(); - -// Shows cli help with --help arg even if there are invalid arguments after it -console.group("--help -w"); -console.log("@@ begin "); -out = child_process.execSync(`../../../rescript --help -w`, { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out, cliHelp); -console.log("@@ done"); -console.groupEnd(); - -// Shows build help with -h arg -// console.group("build -h"); -// console.log("@@ begin "); -// out = child_process.spawnSync(`../../../rescript`, ["build", "-h"], { -// encoding: "utf8", -// cwd: __dirname, -// }); -// assert.equal(out.stdout, buildHelp); -// assert.equal(out.stderr, ""); -// assert.equal(out.status, 0); -// console.log("@@ done "); -// console.groupEnd(); -// -// Exits with build help with unknown arg -console.group("build -foo"); -console.log("@@ begin "); -out = child_process.spawnSync(`../../../rescript`, ["build", "-foo"], { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out.stdout, ""); -assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); -assert.equal(out.status, 2); -console.log("@@ done "); -console.groupEnd(); - -// Shows cli help with --help arg -console.group("--help"); -out = child_process.spawnSync(`../../../rescript`, ["--help"], { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out.stdout, cliHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); -console.groupEnd(); - -// Shows cli help with -h arg -console.group("-h"); -out = child_process.spawnSync(`../../../rescript`, ["-h"], { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out.stdout, cliHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); -console.groupEnd(); - -// Shows cli help with help command -console.group("help"); -out = child_process.spawnSync(`../../../rescript`, ["help"], { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out.stdout, cliHelp); -assert.equal(out.stderr, ""); -assert.equal(out.status, 0); -console.groupEnd(); - -// Exits with cli help with unknown command -console.group("built"); -out = child_process.spawnSync(`../../../rescript`, ["built"], { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out.stdout, ""); -assert.equal(out.stderr, `Error: Unknown command "built".\n` + cliHelp); -assert.equal(out.status, 2); -console.groupEnd(); - -// Exits with build help with unknown args -console.group("-foo"); -out = child_process.spawnSync(`../../../rescript`, ["-foo"], { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out.stdout, ""); -assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); -assert.equal(out.status, 2); -console.groupEnd(); - -// Shows clean help with --help arg -console.group("clean --help"); -out = child_process.execSync(`../../../rescript clean --help`, { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out, cleanHelp); -console.groupEnd(); - -// Shows clean help with -h arg -console.group("clean -h"); -out = child_process.execSync(`../../../rescript clean -h`, { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out, cleanHelp); -console.groupEnd(); - -// Exits with clean help with unknown arg -console.group("clean -foo"); -out = child_process.spawnSync(`../../../rescript`, ["clean", "-foo"], { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out.stdout, ""); -assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + cleanHelp); -assert.equal(out.status, 2); -console.groupEnd(); - -// Shows format help with --help arg -console.group("format --help"); -out = child_process.execSync(`../../../rescript format --help`, { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out, formatHelp); -console.groupEnd(); - -// Shows format help with -h arg -console.group("format -h"); -out = child_process.execSync(`../../../rescript format -h`, { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out, formatHelp); -console.groupEnd(); - -// Shows convert help with --help arg -console.group("convert --help"); -out = child_process.execSync(`../../../rescript convert --help`, { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out, convertHelp); -console.groupEnd(); - -// Shows convert help with -h arg -console.group("convert -h"); -out = child_process.execSync(`../../../rescript convert -h`, { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out, convertHelp); -console.groupEnd(); - -// Shows dump help with --help arg -console.group("dump --help"); -out = child_process.execSync(`../../../rescript dump --help`, { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out, dumpHelp); -console.groupEnd(); - -// Shows dump help with -h arg -console.group("dump -h"); -out = child_process.execSync(`../../../rescript dump -h`, { - encoding: "utf8", - cwd: __dirname, -}); -assert.equal(out, dumpHelp); -console.groupEnd(); +async function test() { + { + // Shows build help with --help arg + const out = await exec(`../../../rescript`, ["build", "--help"]); + assert.equal(out.stdout, buildHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + const out = await exec(`../../../rescript`, ["build", "-w", "--help"]); + assert.equal(out.stdout, buildHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + const out = await exec(`../../../rescript`, ["-w", "--help"]); + assert.equal(out.stdout, cliHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + // Shows cli help with --help arg even if there are invalid arguments after it + const out = await exec(`../../../rescript`, ["--help", "-w"]); + assert.equal(out.stdout, cliHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + // Shows build help with -h arg + const out = await exec(`../../../rescript`, ["build", "-h"]); + assert.equal(out.stdout, buildHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + // Exits with build help with unknown arg + const out = await exec(`../../../rescript`, ["build", "-foo"]); + assert.equal(out.stdout, ""); + assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); + assert.equal(out.status, 2); + } + + { + // Shows cli help with --help arg + const out = await exec(`../../../rescript`, ["--help"]); + assert.equal(out.stdout, cliHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + // Shows cli help with -h arg + const out = await exec(`../../../rescript`, ["-h"]); + assert.equal(out.stdout, cliHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + // Shows cli help with -h arg + const out = await exec(`../../../rescript`, ["help"]); + assert.equal(out.stdout, cliHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + const out = await exec(`../../../rescript`, ["built"]); + assert.equal(out.stdout, ""); + assert.equal(out.stderr, `Error: Unknown command "built".\n` + cliHelp); + assert.equal(out.status, 2); + } + + { + // Exits with build help with unknown args + const out = await exec(`../../../rescript`, ["-foo"]); + assert.equal(out.stdout, ""); + assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); + assert.equal(out.status, 2); + } + + { + // Shows clean help with --help arg + const out = await exec(`../../../rescript`, ["clean", "--help"]); + assert.equal(out.stdout, cleanHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + // Shows clean help with -h arg + const out = await exec(`../../../rescript`, ["clean", "-h"]); + assert.equal(out.stdout, cleanHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + // Exits with clean help with unknown arg + const out = await exec(`../../../rescript`, ["clean", "-foo"]); + assert.equal(out.stdout, ""); + assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + cleanHelp); + assert.equal(out.status, 2); + } + + { + // Shows format help with --help arg + const out = await exec(`../../../rescript format`, ["--help"]); + assert.equal(out.stdout, formatHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + // Shows format help with -h arg + const out = await exec(`../../../rescript format`, ["-h"]); + assert.equal(out.stdout, formatHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + // Shows convert help with --help arg + const out = await exec(`../../../rescript convert`, ["--help"]); + assert.equal(out.stdout, convertHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + // Shows convert help with -h arg + const out = await exec(`../../../rescript convert`, ["-h"]); + assert.equal(out.stdout, convertHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + // Shows dump help with --help arg + const out = await exec(`../../../rescript dump`, ["--help"]); + assert.equal(out.stdout, dumpHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } + + { + // Shows dump help with -h arg + const out = await exec(`../../../rescript dump`, ["-h"]); + assert.equal(out.stdout, dumpHelp); + assert.equal(out.stderr, ""); + assert.equal(out.status, 0); + } +} + +void test(); diff --git a/jscomp/build_tests/utils.js b/jscomp/build_tests/utils.js new file mode 100644 index 0000000000..8201c950f7 --- /dev/null +++ b/jscomp/build_tests/utils.js @@ -0,0 +1,46 @@ +const child_process = require("child_process"); + +const signals = { + SIGINT: 2, + SIGQUIT: 3, + SIGKILL: 9, + SIGTERM: 15, +}; + +async function exec(command, args) { + const stdoutChunks = []; + const stderrChunks = []; + + const subprocess = child_process.spawn(command, args, { + stdio: ["ignore", "pipe", "pipe"], + cwd: __dirname, + }); + + subprocess.stdout.on("data", chunk => { + stdoutChunks.push(chunk); + }); + + subprocess.stderr.on("data", chunk => { + stderrChunks.push(chunk); + }); + + return await new Promise((resolve, reject) => { + subprocess.on("error", err => { + reject(err); + }); + + subprocess.on("close", (exitCode, signal) => { + const stdout = Buffer.concat(stdoutChunks).toString("utf8"); + const stderr = Buffer.concat(stderrChunks).toString("utf8"); + + let code = exitCode ?? 1; + if (signals[signal]) { + code = signals[signal] + 128; + } + + resolve({ code, stdout, stderr }); + }); + }); +} + +exports.exec = exec; From cf616c3212f735db9a62a5fc4c39cdef483f1a0e Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 15 Mar 2024 22:02:45 +0900 Subject: [PATCH 18/28] clean ciTest script --- jscomp/build_tests/utils.js | 8 ++--- scripts/ciTest.js | 58 +++++++++---------------------------- 2 files changed, 17 insertions(+), 49 deletions(-) diff --git a/jscomp/build_tests/utils.js b/jscomp/build_tests/utils.js index 8201c950f7..c367ea06ec 100644 --- a/jscomp/build_tests/utils.js +++ b/jscomp/build_tests/utils.js @@ -7,13 +7,13 @@ const signals = { SIGTERM: 15, }; -async function exec(command, args) { +async function exec(command, args, options = { cwd: __dirname }) { const stdoutChunks = []; const stderrChunks = []; const subprocess = child_process.spawn(command, args, { stdio: ["ignore", "pipe", "pipe"], - cwd: __dirname, + cwd: options.cwd, }); subprocess.stdout.on("data", chunk => { @@ -25,11 +25,11 @@ async function exec(command, args) { }); return await new Promise((resolve, reject) => { - subprocess.on("error", err => { + subprocess.once("error", err => { reject(err); }); - subprocess.on("close", (exitCode, signal) => { + subprocess.once("close", (exitCode, signal) => { const stdout = Buffer.concat(stdoutChunks).toString("utf8"); const stderr = Buffer.concat(stderrChunks).toString("utf8"); diff --git a/scripts/ciTest.js b/scripts/ciTest.js index cbde058d49..66b250e253 100644 --- a/scripts/ciTest.js +++ b/scripts/ciTest.js @@ -5,6 +5,8 @@ var fs = require("fs"); var duneBinDir = require("./dune").duneBinDir; +const { exec } = require("../jscomp/build_tests/utils.js"); + var ounitTest = false; var mochaTest = false; var bsbTest = false; @@ -56,13 +58,7 @@ async function runTests() { console.log("Doing build_tests"); var buildTestDir = path.join(__dirname, "..", "jscomp", "build_tests"); var files = fs.readdirSync(buildTestDir); - var tasks = files.map(async function (file) { - // @ts-ignore - let resolve, reject; - let promise = new Promise((res, rej) => { - resolve = res; - reject = rej; - }); + for (const file of files) { var testDir = path.join(buildTestDir, file); if (file === "node_modules" || !fs.lstatSync(testDir).isDirectory()) { return; @@ -73,36 +69,16 @@ async function runTests() { console.log(`testing ${file}`); // note existsSync test already ensure that it is a directory - let p = cp.spawn(`node`, ["input.js"], { cwd: testDir }); - - p.stdout.setEncoding("utf8").on("data", line => { - console.log(line); - }); - - let stderr = ""; - p.stderr.setEncoding("utf8").on("data", line => { - stderr += line + "\n"; - }); - - p.once("error", err => { - console.log(`❌ error in ${file} with stderr:\n`, stderr); - // @ts-ignore - reject(err); - }); - - p.once("close", () => { - if (!stderr) { - console.log("✅ success in", file); - } - // @ts-ignore - resolve(); - }); + const out = await exec(`node`, ["input.js"], { cwd: testDir }); + console.log(out.stdout); + + if (out.status === 0) { + console.log("✅ success in", file); + } else { + console.log(`❌ error in ${file} with stderr:\n`, out.stderr); + } } - - return promise; - }); - - await Promise.all(tasks); + } } if (formatTest) { @@ -113,12 +89,4 @@ async function runTests() { } } -async function main() { - try { - await runTests(); - } catch (err) { - console.error(err); - process.exit(2); - } -} -main(); +runTests(); From 89e523bddce1170a198702aade7f63a7cdeedcdb Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 15 Mar 2024 22:03:11 +0900 Subject: [PATCH 19/28] Revert "tmp: bump node version" This reverts commit e4069e101588f4aebcc78aec3886eedbdb70828d. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19b421003c..9c38f78433 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,7 +82,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 18 - name: Copy exes to platform bin dirs run: node ./scripts/copyExes.js From a8096d7d312a853628b8b77740944371fb479c13 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 15 Mar 2024 22:04:00 +0900 Subject: [PATCH 20/28] Revert "match via Array.prototype.includes" This reverts commit 321013cfe1e8c50cde9c0ae49874d413f3d7833c. --- scripts/rescript_bsb.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/rescript_bsb.js b/scripts/rescript_bsb.js index 6c059ccbe5..04c5010e52 100644 --- a/scripts/rescript_bsb.js +++ b/scripts/rescript_bsb.js @@ -486,11 +486,7 @@ function build(args) { }); return; } - if ( - args.includes("-h") || - args.includes("-help") || - args.includes("--help") - ) { + if (args.some(arg => /-h|-help|--help/.test(arg))) { delegate(["build", "-h"]); return; } From 1a62cbacb5b37ecd4189555e24ee9c55171d0b71 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 15 Mar 2024 22:06:00 +0900 Subject: [PATCH 21/28] match via includes --- scripts/rescript_bsb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/rescript_bsb.js b/scripts/rescript_bsb.js index 04c5010e52..077cb71955 100644 --- a/scripts/rescript_bsb.js +++ b/scripts/rescript_bsb.js @@ -486,7 +486,7 @@ function build(args) { }); return; } - if (args.some(arg => /-h|-help|--help/.test(arg))) { + if (args.some(arg => ["help", "-h", "-help", "--help"].includes(arg))) { delegate(["build", "-h"]); return; } From 10b1c1304119c2da5e4f65e615bb79e0ae40270e Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 15 Mar 2024 22:08:59 +0900 Subject: [PATCH 22/28] rollback JSDoc definitions --- scripts/rescript_bsb.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/rescript_bsb.js b/scripts/rescript_bsb.js index 077cb71955..d5e34047a7 100644 --- a/scripts/rescript_bsb.js +++ b/scripts/rescript_bsb.js @@ -9,6 +9,18 @@ const rescript_exe = require("./bin_path").rescript_exe; const cwd = process.cwd(); const lockFileName = path.join(cwd, ".bsb.lock"); +/** + * @typedef {Object} ProjectFiles + * @property {Array} dirs + * @property {Array} generated + */ + +/** + * @typedef {Object} WatcherRef + * @property {string} dir + * @property {fs.FSWatcher} watcher + */ + /** * @type {child_process.ChildProcess | null} */ From 4cb889b8ba719bb27474250bd589627116939e2c Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 15 Mar 2024 22:15:45 +0900 Subject: [PATCH 23/28] fix acquire & release --- scripts/rescript_bsb.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/rescript_bsb.js b/scripts/rescript_bsb.js index d5e34047a7..a6f91332c9 100644 --- a/scripts/rescript_bsb.js +++ b/scripts/rescript_bsb.js @@ -27,9 +27,9 @@ const lockFileName = path.join(cwd, ".bsb.lock"); let ownerProcess = null; function releaseBuild() { if (ownerProcess) { + ownerProcess.kill('SIGHUP'); try { - ownerProcess.kill(); - fs.unlinkSync(lockFileName); + fs.rmSync(lockFileName); } catch {} ownerProcess = null; } @@ -53,6 +53,7 @@ function acquireBuild(args, options) { }); fs.writeFileSync(lockFileName, ownerProcess.pid.toString(), { encoding: "utf8", + flag: "wx", mode: 0o664, }); } catch (err) { From f3bbcb72bae2156061f2f2ee2016d5d261d24068 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 15 Mar 2024 22:26:45 +0900 Subject: [PATCH 24/28] type error --- scripts/ciTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ciTest.js b/scripts/ciTest.js index 66b250e253..4c55996805 100644 --- a/scripts/ciTest.js +++ b/scripts/ciTest.js @@ -72,7 +72,7 @@ async function runTests() { const out = await exec(`node`, ["input.js"], { cwd: testDir }); console.log(out.stdout); - if (out.status === 0) { + if (out.code === 0) { console.log("✅ success in", file); } else { console.log(`❌ error in ${file} with stderr:\n`, out.stderr); From 2ee2a25d313833ef070e536e1ecc16498ee195f9 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 15 Mar 2024 22:44:58 +0900 Subject: [PATCH 25/28] add signature for exec util --- jscomp/build_tests/cli_help/input.js | 80 +++++++++++++++++++++------- jscomp/build_tests/utils.js | 9 +++- 2 files changed, 67 insertions(+), 22 deletions(-) diff --git a/jscomp/build_tests/cli_help/input.js b/jscomp/build_tests/cli_help/input.js index a975c6860f..b643e97cee 100755 --- a/jscomp/build_tests/cli_help/input.js +++ b/jscomp/build_tests/cli_help/input.js @@ -75,21 +75,27 @@ const dumpHelp = async function test() { { // Shows build help with --help arg - const out = await exec(`../../../rescript`, ["build", "--help"]); + const out = await exec(`../../../rescript`, ["build", "--help"], { + cwd: __dirname, + }); assert.equal(out.stdout, buildHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); } { - const out = await exec(`../../../rescript`, ["build", "-w", "--help"]); + const out = await exec(`../../../rescript`, ["build", "-w", "--help"], { + cwd: __dirname, + }); assert.equal(out.stdout, buildHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); } { - const out = await exec(`../../../rescript`, ["-w", "--help"]); + const out = await exec(`../../../rescript`, ["-w", "--help"], { + cwd: __dirname, + }); assert.equal(out.stdout, cliHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); @@ -97,7 +103,9 @@ async function test() { { // Shows cli help with --help arg even if there are invalid arguments after it - const out = await exec(`../../../rescript`, ["--help", "-w"]); + const out = await exec(`../../../rescript`, ["--help", "-w"], { + cwd: __dirname, + }); assert.equal(out.stdout, cliHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); @@ -105,7 +113,9 @@ async function test() { { // Shows build help with -h arg - const out = await exec(`../../../rescript`, ["build", "-h"]); + const out = await exec(`../../../rescript`, ["build", "-h"], { + cwd: __dirname, + }); assert.equal(out.stdout, buildHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); @@ -113,7 +123,9 @@ async function test() { { // Exits with build help with unknown arg - const out = await exec(`../../../rescript`, ["build", "-foo"]); + const out = await exec(`../../../rescript`, ["build", "-foo"], { + cwd: __dirname, + }); assert.equal(out.stdout, ""); assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); assert.equal(out.status, 2); @@ -121,7 +133,9 @@ async function test() { { // Shows cli help with --help arg - const out = await exec(`../../../rescript`, ["--help"]); + const out = await exec(`../../../rescript`, ["--help"], { + cwd: __dirname, + }); assert.equal(out.stdout, cliHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); @@ -129,7 +143,9 @@ async function test() { { // Shows cli help with -h arg - const out = await exec(`../../../rescript`, ["-h"]); + const out = await exec(`../../../rescript`, ["-h"], { + cwd: __dirname, + }); assert.equal(out.stdout, cliHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); @@ -137,14 +153,18 @@ async function test() { { // Shows cli help with -h arg - const out = await exec(`../../../rescript`, ["help"]); + const out = await exec(`../../../rescript`, ["help"], { + cwd: __dirname, + }); assert.equal(out.stdout, cliHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); } { - const out = await exec(`../../../rescript`, ["built"]); + const out = await exec(`../../../rescript`, ["built"], { + cwd: __dirname, + }); assert.equal(out.stdout, ""); assert.equal(out.stderr, `Error: Unknown command "built".\n` + cliHelp); assert.equal(out.status, 2); @@ -152,7 +172,9 @@ async function test() { { // Exits with build help with unknown args - const out = await exec(`../../../rescript`, ["-foo"]); + const out = await exec(`../../../rescript`, ["-foo"], { + cwd: __dirname, + }); assert.equal(out.stdout, ""); assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); assert.equal(out.status, 2); @@ -160,7 +182,9 @@ async function test() { { // Shows clean help with --help arg - const out = await exec(`../../../rescript`, ["clean", "--help"]); + const out = await exec(`../../../rescript`, ["clean", "--help"], { + cwd: __dirname, + }); assert.equal(out.stdout, cleanHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); @@ -168,7 +192,9 @@ async function test() { { // Shows clean help with -h arg - const out = await exec(`../../../rescript`, ["clean", "-h"]); + const out = await exec(`../../../rescript`, ["clean", "-h"], { + cwd: __dirname, + }); assert.equal(out.stdout, cleanHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); @@ -176,7 +202,9 @@ async function test() { { // Exits with clean help with unknown arg - const out = await exec(`../../../rescript`, ["clean", "-foo"]); + const out = await exec(`../../../rescript`, ["clean", "-foo"], { + cwd: __dirname, + }); assert.equal(out.stdout, ""); assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + cleanHelp); assert.equal(out.status, 2); @@ -184,7 +212,9 @@ async function test() { { // Shows format help with --help arg - const out = await exec(`../../../rescript format`, ["--help"]); + const out = await exec(`../../../rescript format`, ["--help"], { + cwd: __dirname, + }); assert.equal(out.stdout, formatHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); @@ -192,7 +222,9 @@ async function test() { { // Shows format help with -h arg - const out = await exec(`../../../rescript format`, ["-h"]); + const out = await exec(`../../../rescript format`, ["-h"], { + cwd: __dirname, + }); assert.equal(out.stdout, formatHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); @@ -200,7 +232,9 @@ async function test() { { // Shows convert help with --help arg - const out = await exec(`../../../rescript convert`, ["--help"]); + const out = await exec(`../../../rescript convert`, ["--help"], { + cwd: __dirname, + }); assert.equal(out.stdout, convertHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); @@ -208,7 +242,9 @@ async function test() { { // Shows convert help with -h arg - const out = await exec(`../../../rescript convert`, ["-h"]); + const out = await exec(`../../../rescript convert`, ["-h"], { + cwd: __dirname, + }); assert.equal(out.stdout, convertHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); @@ -216,7 +252,9 @@ async function test() { { // Shows dump help with --help arg - const out = await exec(`../../../rescript dump`, ["--help"]); + const out = await exec(`../../../rescript dump`, ["--help"], { + cwd: __dirname, + }); assert.equal(out.stdout, dumpHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); @@ -224,7 +262,9 @@ async function test() { { // Shows dump help with -h arg - const out = await exec(`../../../rescript dump`, ["-h"]); + const out = await exec(`../../../rescript dump`, ["-h"], { + cwd: __dirname, + }); assert.equal(out.stdout, dumpHelp); assert.equal(out.stderr, ""); assert.equal(out.status, 0); diff --git a/jscomp/build_tests/utils.js b/jscomp/build_tests/utils.js index c367ea06ec..fedbe8023e 100644 --- a/jscomp/build_tests/utils.js +++ b/jscomp/build_tests/utils.js @@ -7,13 +7,18 @@ const signals = { SIGTERM: 15, }; -async function exec(command, args, options = { cwd: __dirname }) { +/** + * @param {string} command + * @param {Array} args + * @param {child_process.SpawnOptions} [options] + */ +async function exec(command, args, options) { const stdoutChunks = []; const stderrChunks = []; const subprocess = child_process.spawn(command, args, { stdio: ["ignore", "pipe", "pipe"], - cwd: options.cwd, + ...options, }); subprocess.stdout.on("data", chunk => { From 00adc0e30005129ee6065f0162d904a982723732 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 15 Mar 2024 22:45:51 +0900 Subject: [PATCH 26/28] format --- scripts/rescript_bsb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/rescript_bsb.js b/scripts/rescript_bsb.js index a6f91332c9..7b79cb1ce4 100644 --- a/scripts/rescript_bsb.js +++ b/scripts/rescript_bsb.js @@ -27,7 +27,7 @@ const lockFileName = path.join(cwd, ".bsb.lock"); let ownerProcess = null; function releaseBuild() { if (ownerProcess) { - ownerProcess.kill('SIGHUP'); + ownerProcess.kill("SIGHUP"); try { fs.rmSync(lockFileName); } catch {} From 033714f10128c2f4b78f2c341c4106df3714281a Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 15 Mar 2024 22:55:48 +0900 Subject: [PATCH 27/28] [skip ci] missing comment --- jscomp/build_tests/cli_help/input.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jscomp/build_tests/cli_help/input.js b/jscomp/build_tests/cli_help/input.js index b643e97cee..a92edbf4b3 100755 --- a/jscomp/build_tests/cli_help/input.js +++ b/jscomp/build_tests/cli_help/input.js @@ -162,6 +162,7 @@ async function test() { } { + // Exits with cli help with unknown command const out = await exec(`../../../rescript`, ["built"], { cwd: __dirname, }); From ba01088e59bb3723256c5df161e27b9d0fde3545 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 20 Mar 2024 00:38:46 +0900 Subject: [PATCH 28/28] Update jscomp/build_tests/utils.js --- jscomp/build_tests/utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jscomp/build_tests/utils.js b/jscomp/build_tests/utils.js index fedbe8023e..0b18871321 100644 --- a/jscomp/build_tests/utils.js +++ b/jscomp/build_tests/utils.js @@ -40,6 +40,7 @@ async function exec(command, args, options) { let code = exitCode ?? 1; if (signals[signal]) { + // + 128 is standard POSIX practice, see also https://nodejs.org/api/process.html#exit-codes code = signals[signal] + 128; }