From 60d1d2067d846aa15a76820e666004cf56d1df99 Mon Sep 17 00:00:00 2001 From: Jake Champion Date: Thu, 1 Aug 2024 10:37:43 +0100 Subject: [PATCH] feat: Add new CLI name of `js-compute` which matches the published package name `@fastly/js-compute` (#869) --- integration-tests/cli/build-config.test.js | 4 ++-- integration-tests/cli/custom-input-path.test.js | 2 +- integration-tests/cli/custom-output-path.test.js | 2 +- .../cli/disable-starlingmonkey.test.js | 2 +- .../cli/engine-wasm-path-is-not-a-file.test.js | 2 +- integration-tests/cli/help.test.js | 14 +++++++------- .../cli/input-path-is-not-a-file.test.js | 2 +- integration-tests/cli/invalid.test.js | 2 +- .../cli/non-existent-engine-wasm-path.test.js | 2 +- .../cli/non-existent-input-path.test.js | 2 +- .../cli/output-path-is-not-a-file.test.js | 2 +- integration-tests/cli/valid.test.js | 2 +- integration-tests/cli/version.test.js | 6 +++--- package.json | 1 + src/printHelp.js | 4 +++- src/printVersion.js | 5 +++-- 16 files changed, 29 insertions(+), 25 deletions(-) diff --git a/integration-tests/cli/build-config.test.js b/integration-tests/cli/build-config.test.js index 77f19a28ee..839d2439f7 100644 --- a/integration-tests/cli/build-config.test.js +++ b/integration-tests/cli/build-config.test.js @@ -2,7 +2,7 @@ import test from 'brittle'; import { getBinPath } from 'get-bin-path' import { prepareEnvironment } from '@jakechampion/cli-testing-library'; -const cli = await getBinPath() +const cli = await getBinPath({name:"js-compute"}) test('should build the fastly condition', async function (t) { const { execute, cleanup, writeFile, exists, path } = await prepareEnvironment(); @@ -13,7 +13,7 @@ test('should build the fastly condition', async function (t) { await writeFile('./index.js', `import '#test';`) await writeFile('./test.js', `addEventListener('fetch', function(){})`) await writeFile('./package.json', `{ "type": "module", "imports": { "#test": { "fastly": "./test.js" } } }`) - + t.is(await exists('./app.wasm'), false) const { code, stdout, stderr } = await execute(process.execPath, `${cli} ${path}/index.js ${path}/app.wasm`); diff --git a/integration-tests/cli/custom-input-path.test.js b/integration-tests/cli/custom-input-path.test.js index 148e516338..17ebb3abf8 100644 --- a/integration-tests/cli/custom-input-path.test.js +++ b/integration-tests/cli/custom-input-path.test.js @@ -2,7 +2,7 @@ import test from 'brittle'; import { getBinPath } from 'get-bin-path' import { prepareEnvironment } from '@jakechampion/cli-testing-library'; -const cli = await getBinPath() +const cli = await getBinPath({name:"js-compute"}) test('should create wasm file and return zero exit code', async function (t) { const { execute, cleanup, writeFile, exists, path } = await prepareEnvironment(); diff --git a/integration-tests/cli/custom-output-path.test.js b/integration-tests/cli/custom-output-path.test.js index 004ba3ba83..060715a3df 100644 --- a/integration-tests/cli/custom-output-path.test.js +++ b/integration-tests/cli/custom-output-path.test.js @@ -2,7 +2,7 @@ import test from 'brittle'; import { getBinPath } from 'get-bin-path' import { prepareEnvironment } from '@jakechampion/cli-testing-library'; -const cli = await getBinPath() +const cli = await getBinPath({name:"js-compute"}) test('should create output directory, wasm file and return zero exit code', async function (t) { const { execute, cleanup, writeFile, exists, path } = await prepareEnvironment(); diff --git a/integration-tests/cli/disable-starlingmonkey.test.js b/integration-tests/cli/disable-starlingmonkey.test.js index a0a2968ab7..27b7d6c77b 100644 --- a/integration-tests/cli/disable-starlingmonkey.test.js +++ b/integration-tests/cli/disable-starlingmonkey.test.js @@ -2,7 +2,7 @@ import test from 'brittle'; import { getBinPath } from 'get-bin-path' import { prepareEnvironment } from '@jakechampion/cli-testing-library'; -const cli = await getBinPath() +const cli = await getBinPath({name:"js-compute"}) test('should create wasm file and return zero exit code for StarlingMonkey', async function (t) { const { execute, cleanup, writeFile, exists } = await prepareEnvironment(); diff --git a/integration-tests/cli/engine-wasm-path-is-not-a-file.test.js b/integration-tests/cli/engine-wasm-path-is-not-a-file.test.js index 69ada4bf34..9bf5df6b79 100644 --- a/integration-tests/cli/engine-wasm-path-is-not-a-file.test.js +++ b/integration-tests/cli/engine-wasm-path-is-not-a-file.test.js @@ -2,7 +2,7 @@ import test from 'brittle'; import { getBinPath } from 'get-bin-path' import { prepareEnvironment } from '@jakechampion/cli-testing-library'; -const cli = await getBinPath() +const cli = await getBinPath({name:"js-compute"}) test('should return non-zero exit code', async function (t) { const { execute, cleanup, makeDir, writeFile, path} = await prepareEnvironment(); diff --git a/integration-tests/cli/help.test.js b/integration-tests/cli/help.test.js index 829138e30a..e4258e12f8 100644 --- a/integration-tests/cli/help.test.js +++ b/integration-tests/cli/help.test.js @@ -11,20 +11,20 @@ const packageJson = readFileSync(join(__dirname, "../../package.json"), { }); const version = JSON.parse(packageJson).version; -const cli = await getBinPath() +const cli = await getBinPath({name:"js-compute"}) test('--help should return help on stdout and zero exit code', async function (t) { const { execute, cleanup } = await prepareEnvironment(); t.teardown(async function () { await cleanup(); }); - const { code, stdout, stderr } = await execute(process.execPath, `${cli} --help`); + const { code, stdout, stderr } = await execute(cli, `--help`); t.is(code, 0); t.alike(stdout, [ - `js-compute-runtime ${version}`, + `js-compute-runtime-cli.js ${version}`, 'USAGE:', - 'js-compute-runtime [FLAGS] [OPTIONS] [ARGS]', + 'js-compute-runtime-cli.js [FLAGS] [OPTIONS] [ARGS]', 'FLAGS:', '-h, --help Prints help information', '-V, --version Prints version information', @@ -44,13 +44,13 @@ test('-h should return help on stdout and zero exit code', async function (t) { t.teardown(async function () { await cleanup(); }); - const { code, stdout, stderr } = await execute(process.execPath, `${cli} -h`); + const { code, stdout, stderr } = await execute(cli, `-h`); t.is(code, 0); t.alike(stdout, [ - `js-compute-runtime ${version}`, + `js-compute-runtime-cli.js ${version}`, 'USAGE:', - 'js-compute-runtime [FLAGS] [OPTIONS] [ARGS]', + 'js-compute-runtime-cli.js [FLAGS] [OPTIONS] [ARGS]', 'FLAGS:', '-h, --help Prints help information', '-V, --version Prints version information', diff --git a/integration-tests/cli/input-path-is-not-a-file.test.js b/integration-tests/cli/input-path-is-not-a-file.test.js index bb5ac20319..331780467a 100644 --- a/integration-tests/cli/input-path-is-not-a-file.test.js +++ b/integration-tests/cli/input-path-is-not-a-file.test.js @@ -2,7 +2,7 @@ import test from 'brittle'; import { getBinPath } from 'get-bin-path' import { prepareEnvironment } from '@jakechampion/cli-testing-library'; -const cli = await getBinPath() +const cli = await getBinPath({name:"js-compute"}) test('should return non-zero exit code', async function (t) { const { execute, cleanup, makeDir} = await prepareEnvironment(); diff --git a/integration-tests/cli/invalid.test.js b/integration-tests/cli/invalid.test.js index bacb7c9acf..4786dd15d7 100644 --- a/integration-tests/cli/invalid.test.js +++ b/integration-tests/cli/invalid.test.js @@ -2,7 +2,7 @@ import test from 'brittle'; import { getBinPath } from 'get-bin-path' import { prepareEnvironment } from '@jakechampion/cli-testing-library'; -const cli = await getBinPath() +const cli = await getBinPath({name:"js-compute"}) test('should return non-zero exit code on syntax errors', async function (t) { const { execute, cleanup, writeFile } = await prepareEnvironment(); diff --git a/integration-tests/cli/non-existent-engine-wasm-path.test.js b/integration-tests/cli/non-existent-engine-wasm-path.test.js index 3c7c79ec4a..5ba0f70bbc 100644 --- a/integration-tests/cli/non-existent-engine-wasm-path.test.js +++ b/integration-tests/cli/non-existent-engine-wasm-path.test.js @@ -2,7 +2,7 @@ import test from 'brittle'; import { getBinPath } from 'get-bin-path' import { prepareEnvironment } from '@jakechampion/cli-testing-library'; -const cli = await getBinPath() +const cli = await getBinPath({name:"js-compute"}) test('should return non-zero exit code', async function (t) { const { execute, cleanup, writeFile,path} = await prepareEnvironment(); diff --git a/integration-tests/cli/non-existent-input-path.test.js b/integration-tests/cli/non-existent-input-path.test.js index 7e6033e8a2..717878402a 100644 --- a/integration-tests/cli/non-existent-input-path.test.js +++ b/integration-tests/cli/non-existent-input-path.test.js @@ -2,7 +2,7 @@ import test from 'brittle'; import { getBinPath } from 'get-bin-path' import { prepareEnvironment } from '@jakechampion/cli-testing-library'; -const cli = await getBinPath() +const cli = await getBinPath({name:"js-compute"}) test('should return non-zero exit code', async function (t) { const { execute, cleanup} = await prepareEnvironment(); diff --git a/integration-tests/cli/output-path-is-not-a-file.test.js b/integration-tests/cli/output-path-is-not-a-file.test.js index 31a3792d49..1987e61e25 100644 --- a/integration-tests/cli/output-path-is-not-a-file.test.js +++ b/integration-tests/cli/output-path-is-not-a-file.test.js @@ -2,7 +2,7 @@ import test from 'brittle'; import { getBinPath } from 'get-bin-path' import { prepareEnvironment } from '@jakechampion/cli-testing-library'; -const cli = await getBinPath() +const cli = await getBinPath({name:"js-compute"}) test('should return non-zero exit code', async function (t) { const { execute, cleanup, makeDir, writeFile} = await prepareEnvironment(); diff --git a/integration-tests/cli/valid.test.js b/integration-tests/cli/valid.test.js index eb3df4f155..a61f654cfa 100644 --- a/integration-tests/cli/valid.test.js +++ b/integration-tests/cli/valid.test.js @@ -2,7 +2,7 @@ import test from 'brittle'; import { getBinPath } from 'get-bin-path' import { prepareEnvironment } from '@jakechampion/cli-testing-library'; -const cli = await getBinPath() +const cli = await getBinPath({name:"js-compute"}) test('should create wasm file and return zero exit code', async function (t) { const { execute, cleanup, writeFile, exists } = await prepareEnvironment(); diff --git a/integration-tests/cli/version.test.js b/integration-tests/cli/version.test.js index 59bff8f238..67823839d8 100644 --- a/integration-tests/cli/version.test.js +++ b/integration-tests/cli/version.test.js @@ -11,7 +11,7 @@ const packageJson = readFileSync(join(__dirname, "../../package.json"), { }); const version = JSON.parse(packageJson).version; -const cli = await getBinPath() +const cli = await getBinPath({name:"js-compute"}) test('--version should return version number on stdout and zero exit code', async function (t) { const { execute, cleanup } = await prepareEnvironment(); @@ -21,7 +21,7 @@ test('--version should return version number on stdout and zero exit code', asyn const { code, stdout, stderr } = await execute(process.execPath, `${cli} --version`); t.is(code, 0); - t.alike(stdout, [`js-compute-runtime ${version}`]) + t.alike(stdout, [`js-compute-runtime-cli.js ${version}`]) t.alike(stderr, []) }); @@ -33,6 +33,6 @@ test('-V should return version number on stdout and zero exit code', async funct const { code, stdout, stderr } = await execute(process.execPath, `${cli} -V`); t.is(code, 0); - t.alike(stdout, [`js-compute-runtime ${version}`]) + t.alike(stdout, [`js-compute-runtime-cli.js ${version}`]) t.alike(stderr, []) }); diff --git a/package.json b/package.json index 969274de93..075c6c14fd 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "url": "https://github.com/fastly/js-compute-runtime" }, "bin": { + "js-compute": "js-compute-runtime-cli.js", "js-compute-runtime": "js-compute-runtime-cli.js" }, "files": [ diff --git a/src/printHelp.js b/src/printHelp.js index 1fb150e484..ef3b286a7a 100644 --- a/src/printHelp.js +++ b/src/printHelp.js @@ -1,10 +1,12 @@ +import { basename } from "node:path"; +import { argv } from "node:process"; import { printVersion } from "./printVersion.js"; export async function printHelp() { await printVersion(); console.log(` USAGE: - js-compute-runtime [FLAGS] [OPTIONS] [ARGS] + ${basename(argv[1])} [FLAGS] [OPTIONS] [ARGS] FLAGS: -h, --help Prints help information diff --git a/src/printVersion.js b/src/printVersion.js index 7463e3910e..7a70f11ed5 100644 --- a/src/printVersion.js +++ b/src/printVersion.js @@ -1,6 +1,7 @@ import { readFile } from "node:fs/promises"; +import { basename, dirname, join } from "node:path"; +import { argv } from "node:process"; import { fileURLToPath } from "node:url"; -import { dirname, join } from "node:path"; const __dirname = dirname(fileURLToPath(import.meta.url)); export async function printVersion() { @@ -8,5 +9,5 @@ export async function printVersion() { encoding: "utf-8", }); const version = JSON.parse(packageJson).version; - console.log(`js-compute-runtime ${version}`); + console.log(`${basename(argv[1])} ${version}`); }