Skip to content

Commit

Permalink
feat: Add new CLI name of js-compute which matches the published pa…
Browse files Browse the repository at this point in the history
…ckage name `@fastly/js-compute` (fastly#869)
  • Loading branch information
JakeChampion authored Aug 1, 2024
1 parent 08a1e5d commit 60d1d20
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 25 deletions.
4 changes: 2 additions & 2 deletions integration-tests/cli/build-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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`);
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cli/custom-input-path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cli/custom-output-path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cli/disable-starlingmonkey.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions integration-tests/cli/help.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cli/input-path-is-not-a-file.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cli/invalid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cli/non-existent-input-path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cli/output-path-is-not-a-file.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cli/valid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/cli/version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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, [])
});

Expand All @@ -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, [])
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
4 changes: 3 additions & 1 deletion src/printHelp.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/printVersion.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
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() {
const packageJson = await readFile(join(__dirname, "../package.json"), {
encoding: "utf-8",
});
const version = JSON.parse(packageJson).version;
console.log(`js-compute-runtime ${version}`);
console.log(`${basename(argv[1])} ${version}`);
}

0 comments on commit 60d1d20

Please sign in to comment.