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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,18 @@ jobs:
- name: Run tests
run: npm run cli@test

- name: Pack CLI for smoke tests
id: pack-cli
working-directory: cli
run: |
set -euo pipefail
PACK_JSON="$(npm pack --pack-destination "$RUNNER_TEMP" --json)"
TARBALL="$(node -e 'process.stdout.write(JSON.parse(process.argv[1])[0].filename)' "$PACK_JSON")"
echo "tarball=$RUNNER_TEMP/$TARBALL" >> "$GITHUB_OUTPUT"

- name: Smoke test Foundry counter base
env:
COMPOSE_CLI_DEPENDENCY_SPEC: file:${{ steps.pack-cli.outputs.tarball }}
run: |
set -euo pipefail
rm -rf ci-foundry
Expand All @@ -84,6 +95,8 @@ jobs:
forge build

- name: Smoke test Hardhat counter base (ethers)
env:
COMPOSE_CLI_DEPENDENCY_SPEC: file:${{ steps.pack-cli.outputs.tarball }}
run: |
set -euo pipefail
rm -rf ci-hardhat
Expand Down
4 changes: 2 additions & 2 deletions cli/src/adapters/IFrameworkAdapter/foundryAdapter/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { withComposeProjectScripts } from "../../../modules/init/projectScripts";
import { CLI_DEV_DEPENDENCY_VERSION, CLI_PACKAGE_NAME } from "../../../utils/metadata";
import { CLI_DEV_DEPENDENCY_SPEC, CLI_PACKAGE_NAME } from "../../../utils/metadata";

/** Adds missing settings to a TOML section without overwriting existing values. */
export function ensureTomlSectionSettings(
Expand Down Expand Up @@ -53,7 +53,7 @@ export function buildFoundryPackageJson(projectName: string): string {
fmt: "forge fmt",
}),
devDependencies: {
[CLI_PACKAGE_NAME]: CLI_DEV_DEPENDENCY_VERSION,
[CLI_PACKAGE_NAME]: CLI_DEV_DEPENDENCY_SPEC,
},
};

Expand Down
4 changes: 2 additions & 2 deletions cli/src/adapters/IFrameworkAdapter/hardhatAdapter/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from "../types";
import { toPosixPath, writeFileIfMissing } from "../../../utils/files";
import { runCommand } from "../../../utils/exec";
import { CLI_DEV_DEPENDENCY_VERSION, CLI_PACKAGE_NAME } from "../../../utils/metadata";
import { CLI_DEV_DEPENDENCY_SPEC, CLI_PACKAGE_NAME } from "../../../utils/metadata";
import {
composePackageSubpath,
isComposePackagePath,
Expand Down Expand Up @@ -81,7 +81,7 @@ function updatePackageManifest(
},
devDependencies: {
...currentDevDependencies,
[CLI_PACKAGE_NAME]: CLI_DEV_DEPENDENCY_VERSION,
[CLI_PACKAGE_NAME]: CLI_DEV_DEPENDENCY_SPEC,
},
scripts: withComposeProjectScripts({
...currentScripts,
Expand Down
6 changes: 3 additions & 3 deletions cli/src/modules/init/frameworkDeps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CLI_DEV_DEPENDENCY_VERSION, CLI_PACKAGE_NAME } from "../../utils/metadata";
import { CLI_DEV_DEPENDENCY_SPEC, CLI_PACKAGE_NAME } from "../../utils/metadata";
import { FrameworkDependencies } from "./types";

/** Hardhat release line used by Compose's generated Hardhat 3 projects. */
Expand Down Expand Up @@ -40,7 +40,7 @@ export function getFrameworkDependencies(
{ name: "Perfect-Abstractions/Compose", version: "(git submodule)" },
{
name: CLI_PACKAGE_NAME,
version: `${CLI_DEV_DEPENDENCY_VERSION} (npm dev dependency)`,
version: `${CLI_DEV_DEPENDENCY_SPEC} (npm dev dependency)`,
},
],
packageType: "packages",
Expand All @@ -58,7 +58,7 @@ export function getFrameworkDependencies(
"@nomicfoundation/hardhat-toolbox-mocha-ethers": "^3.0.7",
};

devDeps[CLI_PACKAGE_NAME] = CLI_DEV_DEPENDENCY_VERSION;
devDeps[CLI_PACKAGE_NAME] = CLI_DEV_DEPENDENCY_SPEC;

return {
deps: [
Expand Down
12 changes: 10 additions & 2 deletions cli/src/utils/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ export const LOCK_FILE_NAME = "compose.lock";
/** npm package that provides the `compose` binary. */
export const CLI_PACKAGE_NAME = "@perfect-abstractions/compose-cli";

/** Version range written into generated projects so they run the CLI locally. */
export const CLI_DEV_DEPENDENCY_VERSION = `^${VERSION}`;
/** Resolves the CLI dependency written into generated projects. */
export function getCliDependencySpec(version: string, override?: string): string {
return override || `^${version}`;
}

/** Dependency spec written into generated projects so they run the CLI locally. */
export const CLI_DEV_DEPENDENCY_SPEC = getCliDependencySpec(
VERSION,
process.env.COMPOSE_CLI_DEPENDENCY_SPEC,
);

export const COMPOSE_HEADER = `
_____ ____ __ __ _____ ____ _____ ______ _____ _ _____
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { CLI_DEV_DEPENDENCY_VERSION, CLI_PACKAGE_NAME } from "../../../../src/utils/metadata";
import { CLI_DEV_DEPENDENCY_SPEC, CLI_PACKAGE_NAME } from "../../../../src/utils/metadata";

const { runCommand } = vi.hoisted(() => ({ runCommand: vi.fn(async () => undefined) }));

Expand Down Expand Up @@ -61,7 +61,7 @@ describe("foundryAdapter project scaffolding", () => {
validate: "compose validate",
});
expect(packageJson.devDependencies).toEqual({
[CLI_PACKAGE_NAME]: CLI_DEV_DEPENDENCY_VERSION,
[CLI_PACKAGE_NAME]: CLI_DEV_DEPENDENCY_SPEC,
});
expect(runCommand).toHaveBeenCalledWith("forge", ["init", "."], { cwd: projectRoot });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { resolveHardhatAstSourcePath } from "../../../../src/adapters/IFrameworkAdapter/hardhatAdapter/helpers";
import { Context } from "../../../../src/context/context";
import { ConfigModule } from "../../../../src/modules/config/module";
import { CLI_DEV_DEPENDENCY_VERSION, CLI_PACKAGE_NAME } from "../../../../src/utils/metadata";
import { CLI_DEV_DEPENDENCY_SPEC, CLI_PACKAGE_NAME } from "../../../../src/utils/metadata";
import { canonicalizeAst } from "../canonicalAst";
import {
createHardhatAdapterFixtureHarness,
Expand Down Expand Up @@ -208,7 +208,7 @@ describe("hardhatAdapter.writeConfig", () => {
expect(config).toContain("npmFilesToBuild:");

const packageJson = JSON.parse(await fs.readFile(path.join(projectRoot, "package.json"), "utf8"));
expect(packageJson.devDependencies[CLI_PACKAGE_NAME]).toBe(CLI_DEV_DEPENDENCY_VERSION);
expect(packageJson.devDependencies[CLI_PACKAGE_NAME]).toBe(CLI_DEV_DEPENDENCY_SPEC);
expect(packageJson.dependencies["@perfect-abstractions/compose"]).toBe("latest");
expect(packageJson.devDependencies["@nomicfoundation/hardhat-toolbox-mocha-ethers"]).toBe("^3.0.7");
expect(packageJson.engines.node).toBe(">=22.13.0");
Expand Down
21 changes: 21 additions & 0 deletions cli/test/utils/metadata.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
import {
getCliDependencySpec,
VERSION,
} from "../../src/utils/metadata";

describe("CLI metadata", () => {
it("uses the CLI package.json version as its version source", async () => {
const packageJson = JSON.parse(
await readFile(new URL("../../package.json", import.meta.url), "utf8"),
) as { version: string };

expect(VERSION).toBe(packageJson.version);
expect(getCliDependencySpec(VERSION)).toBe(`^${packageJson.version}`);
});

it("allows smoke tests to install the CLI from the checkout", () => {
expect(getCliDependencySpec("0.4.0", "file:../cli")).toBe("file:../cli");
});
});
Loading